15.6 $ p$ -adic Numbers

Module: sage.rings.padic

We represent a $ p$ -adic number as a product $ p^r \cdot u$ , where $ r$ is an integer or $ \infty$ and $ u$ is a $ p$ -adic unit known to some precision. If $ r = \infty$ , then $ p^r \cdot u$ is the 0 element.

Binary operations on two elements of $ \mathbf{Q}_p$ reduce the precision of the unit part of the argument with larger precision to that of the one with lesser precision. This applies to all operations, including equality testing, so, e.g., the element $ O(p)$ is equal to every $ p$ -adic integer, since comparison will truncate the other $ p$ -adic integer to precision $ O(p)$ .

Author Log:

Class: pAdic

class pAdic
A $ p$ -adic numbers of either finite or infinite precision.

sage: a = 1 + 17 + 3*17^2 + O(17^3)
sage: a
1 + 17 + 3*17^2 + O(17^3)
sage: loads(a.dumps()) == a
True
pAdic( self, parent, x, [big_oh=False], [ordp=None], [construct=Infinity])

INPUT:
    parent -- a p-adic field.
    x -- anything that can be coerced to a p-adic number.
    big_oh -- is such that, e.g. 3^(-1) + 1 + 2 * 3 + (3^2)
               has big_oh equal to 2.

Functions: additive_order,$  $ big_oh,$  $ copy,$  $ denominator,$  $ is_unit,$  $ is_zero,$  $ lift,$  $ log,$  $ multiplicative_order,$  $ ordp,$  $ rational_reconstruction,$  $ unit_part,$  $ valuation

additive_order( self)

The additive order of self as an element of the additive group.

sage: K = Qp(11)
sage: a = K(1); a
1
sage: a.additive_order()
Infinity
sage: b = zero(K); b
0
sage: b.additive_order()
1

denominator( self)

Return the denominator of this p-adic number, which is an integer that is a power of $ p$ .

sage: K = Qp(11); K.prec(10)
sage: a = K(211/17); a
4 + 4*11 + 11^2 + 7*11^3 + 9*11^5 + 5*11^6 + 4*11^7 + 8*11^8 + 7*11^9 +
O(11^10)
sage: a.denominator()
1
sage: b = K(3211/11^2); b
10*11^-2 + 5*11^-1 + 4 + 2*11 + O(11^Infinity)
sage: b.denominator()
121

is_unit( self)

sage: K = Qp(11)
sage: a = K(2); a
2 + O(11^Infinity)
sage: a.is_unit()
True
sage: K(121).is_unit()
False
sage: K(0).is_unit()
False

is_zero( self)

sage: K = Qp(11)
sage: a = K(2); a
2 + O(11^Infinity)
sage: a.is_zero()
False

sage: K = Qp(11)
sage: K(0).is_zero()
True

lift( self)

Return rational number with denominator only divisible by $ p$ that lifts this $ p$ -adic number, to the given precision.

sage: a = 4596/7^2 + O(7^4); a
4*7^-2 + 5*7^-1 + 2 + 6*7 + 7^2 + O(7^4)
sage: a.lift()
4596/49

sage: K = Qp(19)
sage: K.prec(5)

sage: a = K(-1); a
18 + 18*19 + 18*19^2 + 18*19^3 + 18*19^4 + O(19^Infinity)
sage: a.lift()
-1

sage: a = 4596/18 + O(7^4); a
1 + 6*7 + 2*7^2 + 5*7^3 + O(7^4)
sage: a.lift()
40747250655980528766

log( self)

Compute the p-adic logarithm of a unit in $ \mathbf{Z}_p$ .

The usual power series for log with values in the additive group of $ \mathbf{Q}_p$ only converges for 1-units (units congruent to 1 modulo p). However, there is a unique extension of log to a homomorphism defined on all the units. If u = a*v is a unit with v = 1 (mod p), then we define log(u) = log(v). This is the correct extension because the units U of Z_p splits as a product U = V x <w>, where V is the subgroup of 1-units and w is a (p-1)st root of unity. The <w> factor is torsion, so must go to 0 under any homomorphism to the torsion free group $ (\mathbf{Q}_p, +)$ .

Notes - What some other systems do: PARI: Seems to define log the same way as we do. MAGMA: Gives an error when unit is not a 1-unit.

Algorithm: Input: Some p-adic unit u. 1. Check that the input p-adic number is really a unit (i.e., valuation 0) 2. Let $ 1-x = u^{p-1}$ , which is a 1-unit. 3. Use the series expansion

$\displaystyle \log(1-x) = F(x) = -x - 1/2*x^2 - 1/3*x^3 - 1/4*x^4 - 1/5*x^5 - ...
$

to compute the logarithm log(u**(p-1)). Use enough terms so that terms added on are zero (to the default precision, if the input has infinite precision). 4. Then

$\displaystyle \log(u) = log(u^{p-1})/(p-1) = F(1-u^{p-1})/(p-1).$

sage: Q13 = Qp(13)
sage: Q13.prec(10)
sage: a = Q13(14); a
1 + 13 + O(13^Infinity)
sage: a.log()
13 + 6*13^2 + 2*13^3 + 5*13^4 + 10*13^6 + 13^7 + 11*13^8 + 8*13^9 +
O(13^10)

multiplicative_order( self)

The multiplicative order of this as an element, if defined.

If the element is known to infinite precision, then it is truncated to the parent default precision before the order is computed.

sage: K = Qp(13)
sage: a = K(-1)
sage: a.multiplicative_order()
2

We immediately know that 13 has infinite order, since it is 0 modulo 13.

sage: b = K(13)
sage: b.multiplicative_order()
Infinity

The following element has finite multiplicative order modulo $ 5^2$ :

sage: c = 3 + 3*5 + 2*5**2 + O(5**3)
sage: c.multiplicative_order()
4

ordp( self)

Return the $ p$ -adic valuation at this $ p$ -adic number, normalized so that the valuation of $ p$ is $ 1$ .

sage: K = Qp(11)
sage: a = K(211/17); a
4 + 4*11 + 11^2 + 7*11^3 + 9*11^5 + 5*11^6 + 4*11^7 + 8*11^8 + 7*11^9 +
9*11^10 + 3*11^11 + 10*11^12 + 11^13 + 5*11^14 + 6*11^15 + 2*11^16 +
3*11^17 + 11^18 + 7*11^19 + O(11^20)
sage: a.ordp()
0
sage: b = K(3211/11^2); b
10*11^-2 + 5*11^-1 + 4 + 2*11 + O(11^Infinity)
sage: b.ordp()
-2

rational_reconstruction( self)

Try to lift the p-adic number to the rationals using rational reconstruction, as follows: Suppose the p-adic number is $ p^{r}\cdot (u+O(p^n))$ , where u is a unit. Using rational reconstruction, try to find the unique rational number a/b such that a/b is congruent to u modulo $ p^n$ , and abs(a), abs(b) are both at most $ \sqrt{p/2}$ . If such $ a/b$ exists, return $ p^r \cdot (a/b)$ .

sage: K = Qp(11); K.prec(10); K.print_prec(10)
sage: a = K(-1); a
10 + 10*11 + 10*11^2 + 10*11^3 + 10*11^4 + 10*11^5 + 10*11^6 + 10*11^7 +
10*11^8 + 10*11^9 + O(11^Infinity)
sage: a.rational_reconstruction()
-1
sage: a = K(2); a
2 + O(11^Infinity)
sage: a.rational_reconstruction()
2

unit_part( self)

Return the unit part of $ p^r \cdot u$ , which is simply u.

sage: x = 9*(2+3+O(3**7))
sage: x.unit_part()
2 + 3 + O(3^7)
sage: K = Qp(19)
sage: K.prec(5)
sage: a = K(2)/19; a
2*19^-1 + O(19^4)
sage: a.unit_part()
2 + O(19^5)

valuation( self)

Same as ordp.

Special Functions: __cmp__,$  $ __invert__,$  $ __mod__,$  $ __neg__,$  $ __pos__,$  $ __pow__,$  $ _add_,$  $ _div_,$  $ _integer_,$  $ _mul_,$  $ _pari_init_,$  $ _repr_,$  $ _sub_

__cmp__( self, other)

First compare valuations, then compare normalized residue of unit part.

sage: K = Qp(19)
sage: K.prec(5)
sage: a = K(2); a
2 + O(19^Infinity)
sage: b = K(3); b
3 + O(19^Infinity)
sage: a < b
True

__invert__( self)

sage: K = Qp(19)
sage: K.prec(5)
sage: a = K(20); a
1 + 19 + O(19^Infinity)
sage: b = ~a    # calls __invert__
sage: b
1 + 18*19 + 18*19^3 + O(19^5)
sage: a*b
1 + O(19^5)

__pow__( self, right)

sage: K = Qp(19)
sage: K.prec(5)
sage: a = K(-1); a
18 + 18*19 + 18*19^2 + 18*19^3 + 18*19^4 + O(19^Infinity)
sage: a^2
1
sage: a^3
18 + 18*19 + 18*19^2 + 18*19^3 + 18*19^4 + O(19^Infinity)
sage: K(5)^30
11 + 14*19 + 19^2 + 7*19^3 + O(19^Infinity)

_add_( self, right)

sage: K = Qp(11); K.prec(10); K.print_prec(5)
sage: a = K(-1); a
10 + 10*11 + 10*11^2 + 10*11^3 + 10*11^4 + O(11^Infinity)
sage: b = K(1); b
1
sage: a+b
0

_div_( self, right)

sage: K = Qp(19)
sage: K.prec(5)
sage: a = K(2/19); a
2*19^-1 + O(19^Infinity)
sage: b = K(3/19); b
3*19^-1 + O(19^Infinity)
sage: a/b
7 + 6*19 + 6*19^2 + 6*19^3 + 6*19^4 + O(19^5)

_mul_( self, right)

sage: K = Qp(19)
sage: K.prec(5)
sage: (-1)*one(K)
18 + 18*19 + 18*19^2 + 18*19^3 + 18*19^4 + O(19^Infinity)
sage: a = K(2/19); a
2*19^-1 + O(19^Infinity)
sage: b = K(3/19); b
3*19^-1 + O(19^Infinity)
sage: a*b
6*19^-2 + O(19^Infinity)

_pari_init_( self)

PARI representation of a p-adic is the same as in SAGE.

_sub_( self, right)

sage: K = Qp(19)
sage: K.prec(5)
sage: zero(K) - one(K)
18 + 18*19 + 18*19^2 + 18*19^3 + 18*19^4 + O(19^Infinity)

See About this document... for information on suggesting changes.