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()

Returns a PowComputer that caches the values $1, m, m^2, ldots, m^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
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__reduce__()

Pickling.

EXAMPLES:

sage: P = PowComputer(5, 7, 10)
sage: R = loads(dumps(P))
sage: P == R
True
class sage.rings.padics.pow_computer.PowComputer_class
__call__()

Returns self.prime^n.

EXAMPLES:

sage: P = PowComputer(3, 4, 6)
sage: P(3)
27
sage: P(6)
729
sage: P(5)
243
sage: P(7)
2187
sage: P(0)
1
sage: P(-2)
1/9
__cmp__()
x.__cmp__(y) <==> cmp(x,y)
__init__()
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__repr__()

Returns a string representation of self.

EXAMPLES:

sage: PC = PowComputer(3, 5, 10); PC
PowComputer for 3
_cache_limit()

Returns the limit to which powers of prime are computed.

EXAMPLES:

sage: P = PowComputer(3, 5, 10)
sage: P._cache_limit()
5
_in_field()

Returns whether or not self is attached to a field.

EXAMPLES:

sage: P = PowComputer(3, 5, 10)
sage: P._in_field()
False
_pow_mpz_t_tmp_demo()

This function demonstrates a danger in using pow_mpz_t_tmp.

EXAMPLES:

sage: PC = PowComputer(5, 5, 10)

When you cal pow_mpz_t_tmp with an input that is not stored
(ie n > self.cache_limit and n != self.prec_cap),
it stores the result in self.temp_m and returns a pointer
to that mpz_t.  So if you try to use the results of two
calls at once, things will break.
sage: PC._pow_mpz_t_tmp_demo(6, 8) # 244140625 on some architectures and 152587890625 on others: random
244140625
sage: 5^6*5^8
6103515625
sage: 5^6*5^6
244140625

Note that this does not occur if you try a stored value,
because the result of one of the calls points to that
stored value.
sage: PC._pow_mpz_t_tmp_demo(6, 10)
152587890625
sage: 5^6*5^10
152587890625        
_pow_mpz_t_tmp_test()

Tests the pow_mpz_t_tmp function.

EXAMPLES:

sage: PC = PowComputer(3, 5, 10)
sage: PC._pow_mpz_t_tmp_test(4)
81
sage: PC._pow_mpz_t_tmp_test(6)
729
sage: PC._pow_mpz_t_tmp_test(0)
1
sage: PC._pow_mpz_t_tmp_test(10)
59049
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_mpz_t_tmp_test(4)
81
sage: PC._pow_mpz_t_tmp_test(6)
729
sage: PC._pow_mpz_t_tmp_test(0)
1
sage: PC._pow_mpz_t_tmp_test(10)
59049
_pow_mpz_t_top_test()

Tests the pow_mpz_t_top function.

EXAMPLES:

sage: PC = PowComputer(3, 5, 10)
sage: PC._pow_mpz_t_top_test()
59049
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_mpz_t_top_test()
59049
_prec_cap()

Returns prec_cap, a single value that for which self._prime()^prec_cap is stored

EXAMPLES:

sage: P = PowComputer(3, 5, 10)
sage: P._prec_cap()
10
_prime()

Returns the base that the PowComputer is exponentiating.

EXAMPLES:

sage: P = PowComputer(6, 10, 15)
sage: P._prime()
6
_top_power()

Returns self._prime()^self._prec_cap()

EXAMPLES:

sage: P = PowComputer(3, 4, 6)
sage: P._top_power()
729
pow_Integer_Integer()

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: 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
sage.rings.padics.pow_computer.clear_mpz_globals()
sage.rings.padics.pow_computer.gmp_randrange()
sage.rings.padics.pow_computer.init_mpz_globals()

Previous topic

p-Adic ZZ_pX FM Element.

Next topic

PowComputer_ext.

This Page