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

AUTHORS:

  • David Roe

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

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
class sage.rings.padics.pow_computer.PowComputer_base#

Bases: PowComputer_class

Initialization.

class sage.rings.padics.pow_computer.PowComputer_class#

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
pow_Integer_Integer(n)#

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