PowComputer#

A class for computing and caching powers of the same integer.

This class is designed to be used as a field of p-adic rings and fields. Since elements of p-adic rings and fields need to use powers of p over and over, this class precomputes and stores powers of p. There is no reason that the base has to be prime however.

EXAMPLES:

sage: X = PowComputer(3, 4, 10)
sage: X(3)
27
sage: X(10) == 3^10
True
>>> from sage.all import *
>>> X = PowComputer(Integer(3), Integer(4), Integer(10))
>>> X(Integer(3))
27
>>> X(Integer(10)) == Integer(3)**Integer(10)
True

AUTHORS:

  • David Roe

sage.rings.padics.pow_computer.PowComputer(m, cache_limit, prec_cap, in_field=False, prec_type=None)[source]#

Returns a PowComputer that caches the values \(1, m, m^2, \ldots, m^{C}\), where \(C\) is cache_limit.

Once you create a PowComputer, merely call it to get values out.

You can input any integer, even if it’s outside of the precomputed range.

INPUT:

  • m – An integer, the base that you want to exponentiate.

  • cache_limit – A positive integer that you want to cache powers up to.

EXAMPLES:

sage: PC = PowComputer(3, 5, 10)
sage: PC
PowComputer for 3
sage: PC(4)
81
sage: PC(6)
729
sage: PC(-1)
1/3
>>> from sage.all import *
>>> PC = PowComputer(Integer(3), Integer(5), Integer(10))
>>> PC
PowComputer for 3
>>> PC(Integer(4))
81
>>> PC(Integer(6))
729
>>> PC(-Integer(1))
1/3
class sage.rings.padics.pow_computer.PowComputer_base[source]#

Bases: PowComputer_class

Initialization.

class sage.rings.padics.pow_computer.PowComputer_class[source]#

Bases: SageObject

Initializes self.

INPUT:

  • prime – the prime that is the base of the exponentials stored in this pow_computer.

  • cache_limit – how high to cache powers of prime.

  • prec_cap – data stored for p-adic elements using this pow_computer (so they have C-level access to fields common to all elements of the same parent).

  • ram_prec_cap – prec_cap * e

  • in_field – same idea as prec_cap

  • poly – same idea as prec_cap

  • shift_seed – same idea as prec_cap

EXAMPLES:

sage: PC = PowComputer(3, 5, 10)
sage: PC.pow_Integer_Integer(2)
9
>>> from sage.all import *
>>> PC = PowComputer(Integer(3), Integer(5), Integer(10))
>>> PC.pow_Integer_Integer(Integer(2))
9
pow_Integer_Integer(n)[source]#

Tests the pow_Integer function.

EXAMPLES:

sage: PC = PowComputer(3, 5, 10)
sage: PC.pow_Integer_Integer(4)
81
sage: PC.pow_Integer_Integer(6)
729
sage: PC.pow_Integer_Integer(0)
1
sage: PC.pow_Integer_Integer(10)
59049

sage: # needs sage.libs.ntl
sage: PC = PowComputer_ext_maker(3, 5, 10, 20, False, ntl.ZZ_pX([-3,0,1], 3^10), 'big','e',ntl.ZZ_pX([1],3^10))
sage: PC.pow_Integer_Integer(4)
81
sage: PC.pow_Integer_Integer(6)
729
sage: PC.pow_Integer_Integer(0)
1
sage: PC.pow_Integer_Integer(10)
59049
>>> from sage.all import *
>>> PC = PowComputer(Integer(3), Integer(5), Integer(10))
>>> PC.pow_Integer_Integer(Integer(4))
81
>>> PC.pow_Integer_Integer(Integer(6))
729
>>> PC.pow_Integer_Integer(Integer(0))
1
>>> PC.pow_Integer_Integer(Integer(10))
59049

>>> # needs sage.libs.ntl
>>> PC = PowComputer_ext_maker(Integer(3), Integer(5), Integer(10), Integer(20), False, ntl.ZZ_pX([-Integer(3),Integer(0),Integer(1)], Integer(3)**Integer(10)), 'big','e',ntl.ZZ_pX([Integer(1)],Integer(3)**Integer(10)))
>>> PC.pow_Integer_Integer(Integer(4))
81
>>> PC.pow_Integer_Integer(Integer(6))
729
>>> PC.pow_Integer_Integer(Integer(0))
1
>>> PC.pow_Integer_Integer(Integer(10))
59049