Elements of p-Adic Rings with Capped Relative Precision
AUTHORS:
TESTS:
sage: M = MatrixSpace(pAdicField(3,100),2)
sage: (M([1,0,0,90]) - (1+O(3^100)) * M(1)).left_kernel()
Vector space of degree 2 and dimension 1 over 3-adic Field with capped relative precision 100
Basis matrix:
[1 + O(3^100) 0]
Returns a copy of self.
EXAMPLES:
sage: a = Zp(5,6)(17); b = copy(a)
sage: a == b
True
sage: a is b
False
If a,b are p-adic integers, then floordiv (//) satisfies the following equation: a%b + b*(a//b) == a
sage: r = Zp(19) sage: a = r(1+19+17*19^3+5*19^4); b = r(19^3); a/b 19^-3 + 19^-2 + 17 + 5*19 + O(19^17) sage: a//b 17 + 5*19 + O(19^17)
sage: R = Zp(19, 5, ‘capped-rel’,’series’) sage: a = R(-1); a 18 + 18*19 + 18*19^2 + 18*19^3 + 18*19^4 + O(19^5) sage: b=R(-2*19^3); b 17*19^3 + 18*19^4 + 18*19^5 + 18*19^6 + 18*19^7 + O(19^8) sage: a//b # indirect doctest 9 + 9*19 + O(19^2)
Returns the multiplicative inverse of self.
Multiplies self by p^shift.
EXAMPLES:
sage: R = Zp(5); a = R(1000); a
3*5^3 + 5^4 + O(5^23)
Shifting to the right is the same as dividing by a power of
the uniformizer $p$ of the $p$-adic ring.
sage: a >> 1
3*5^2 + 5^3 + O(5^22)
Shifting to the left is the same as multiplying by a power of $p$:
sage: a << 2
3*5^5 + 5^6 + O(5^25)
sage: a*5^2
3*5^5 + 5^6 + O(5^25)
Shifting by a negative integer to the left is the same as right shifting
by the absolute value:
sage: a << -3
3 + 5 + O(5^20)
sage: a >> 3
3 + 5 + O(5^20)
sage: a = Zp(5)(17); a
2 + 3*5 + O(5^20)
sage: a << 2 #indirect doctest
2*5^2 + 3*5^3 + O(5^22)
sage: a << -2
O(5^18)
Pickling.
TESTS:
sage: a = ZpCR(5)(-3)
sage: type(a)
<type 'sage.rings.padics.padic_capped_relative_element.pAdicCappedRelativeElement'>
sage: loads(dumps(a)) == a
True
Divides self by p^shift. If self is a ring element, throws away the non-integral part.
EXAMPLES:
sage: a = Zp(5)(17); a
2 + 3*5 + O(5^20)
sage: a >> 1 #indirect doctest
3 + O(5^19)
sage: a = Qp(5)(17); a >> 1
2*5^-1 + 3 + O(5^19)
Adds self and right.
Divides self by right.
EXAMPLES:
sage: R = Zp(5,6)
sage: R(17) / R(21) #indirect doctest
2 + 4*5^2 + 3*5^3 + 4*5^4 + O(5^6)
sage: a = R(50) / R(5); a
2*5 + O(5^7)
sage: R(5) / R(50)
3*5^-1 + 2 + 2*5 + 2*5^2 + 2*5^3 + 2*5^4 + O(5^5)
sage: ~a
3*5^-1 + 2 + 2*5 + 2*5^2 + 2*5^3 + 2*5^4 + O(5^5)
sage: 1 / a
3*5^-1 + 2 + 2*5 + 2*5^2 + 2*5^3 + 2*5^4 + O(5^5)
Implementation of floordiv.
TESTS:
sage: R = Zp(5,5)
sage: R(28937) // R(75) # indirect doctest
4 + 3*5 + 3*5^2 + O(5^3)
Converts self to an integer
TESTS:
sage: R = Zp(5, prec = 4); a = R(642); a
2 + 3*5 + O(5^4)
sage: Integer(a) #indirect doctest
17
Returns true if this element is exactly zero.
EXAMPLES:
sage: R = Zp(5)
sage: R(0)._is_exact_zero()
True
sage: R(0,5)._is_exact_zero()
False
sage: R(17)._is_exact_zero()
False
Returns True if this element is indistinguishable from zero but has finite precision.
EXAMPLES:
sage: R = Zp(5)
sage: R(0)._is_inexact_zero()
False
sage: R(0,5)._is_inexact_zero()
True
sage: R(17)._is_inexact_zero()
False
Multiplies self by right.
EXAMPLES:
sage: R = Zp(5)
sage: a = R(2385,11); a
2*5 + 4*5^3 + 3*5^4 + O(5^11)
sage: b = R(2387625, 16); b
5^3 + 4*5^5 + 2*5^6 + 5^8 + 5^9 + O(5^16)
sage: a * b # indirect doctest
2*5^4 + 2*5^6 + 4*5^7 + 2*5^8 + 3*5^10 + 5^11 + 3*5^12 + 4*5^13 + O(5^14)
Negation.
Converts this element to an equivalent pari element.
EXAMPLES:
sage: R = Zp(17, 10); a = ~R(14); pari(a) #indirect doctest
11 + 3*17 + 17^2 + 6*17^3 + 13*17^4 + 15*17^5 + 10*17^6 + 3*17^7 + 17^8 + 6*17^9 + O(17^10)
sage: pari(R(0))
0
sage: pari(R(0,5))
O(17^5)
Sets self to be the Teichmuller representative with the same residue as self.
WARNING: This function modifies self, which is not safe. Elements are supposed to be immutable.
EXAMPLES:
sage: R = Zp(17,5); a = R(11)
sage: a
11 + O(17^5)
sage: a._teichmuller_set(); a
11 + 14*17 + 2*17^2 + 12*17^3 + 15*17^4 + O(17^5)
sage: a.list('teichmuller')
[11 + 14*17 + 2*17^2 + 12*17^3 + 15*17^4 + O(17^5)]
Returns a new element with absolute precision decreased to absprec.
INPUT:
self -- a p-adic element
absprec -- an integer
OUTPUT:
element -- self with precision set to the minimum of
self's precision and absprec
EXAMPLE:
sage: R = Zp(7,4,'capped-rel','series'); a = R(8); a.add_bigoh(1)
1 + O(7)
sage: b = R(0); b.add_bigoh(3)
O(7^3)
sage: R = Qp(7,4); a = R(8); a.add_bigoh(1)
1 + O(7)
sage: b = R(0); b.add_bigoh(3)
O(7^3)
The precision never increases::
sage: R(4).add_bigoh(2).add_bigoh(4)
4 + O(7^2)
Another example that illustrates that the precision does
not increase::
sage: k = Qp(3,5)
sage: a = k(1234123412/3^70); a
2*3^-70 + 3^-69 + 3^-68 + 3^-67 + O(3^-65)
sage: a.add_bigoh(2)
2*3^-70 + 3^-69 + 3^-68 + 3^-67 + O(3^-65)
sage: k = Qp(5,10)
sage: a = k(1/5^3 + 5^2); a
5^-3 + 5^2 + O(5^7)
sage: a.add_bigoh(2)
5^-3 + O(5^2)
sage: a.add_bigoh(-1)
5^-3 + O(5^-1)
Returns whether self is equal to right modulo $p^{mbox{absprec}}$.
if absprec is None, returns True if self and right are equal to the minimum of their precisions.
INPUT:
- self -- a p-adic element
- right -- a p-addic element
- absprec -- an integer or None
OUTPUT:
- boolean -- whether self is equal to right (modulo $p^{\mbox{absprec}}$)
EXAMPLES:
sage: R = Zp(5, 10); a = R(0); b = R(0, 3); c = R(75, 5)
sage: aa = a + 625; bb = b + 625; cc = c + 625
sage: a.is_equal_to(aa), a.is_equal_to(aa, 4), a.is_equal_to(aa, 5)
(False, True, False)
sage: a.is_equal_to(aa, 15)
...
PrecisionError: Elements not known to enough precision
sage: a.is_equal_to(a, 50000)
True
sage: a.is_equal_to(b), a.is_equal_to(b, 2)
(True, True)
sage: a.is_equal_to(b, 5)
...
PrecisionError: Elements not known to enough precision
sage: b.is_equal_to(b, 5)
...
PrecisionError: Elements not known to enough precision
sage: b.is_equal_to(bb, 3)
True
sage: b.is_equal_to(bb, 4)
...
PrecisionError: Elements not known to enough precision
sage: c.is_equal_to(b, 2), c.is_equal_to(b, 3)
(True, False)
sage: c.is_equal_to(b, 4)
...
PrecisionError: Elements not known to enough precision
sage: c.is_equal_to(cc, 2), c.is_equal_to(cc, 4), c.is_equal_to(cc, 5)
(True, True, False)
TESTS:
sage: aa.is_equal_to(a), aa.is_equal_to(a, 4), aa.is_equal_to(a, 5)
(False, True, False)
sage: aa.is_equal_to(a, 15)
...
PrecisionError: Elements not known to enough precision
sage: b.is_equal_to(a), b.is_equal_to(a, 2)
(True, True)
sage: b.is_equal_to(a, 5)
...
PrecisionError: Elements not known to enough precision
sage: bb.is_equal_to(b, 3)
True
sage: bb.is_equal_to(b, 4)
...
PrecisionError: Elements not known to enough precision
sage: b.is_equal_to(c, 2), b.is_equal_to(c, 3)
(True, False)
sage: b.is_equal_to(c, 4)
...
PrecisionError: Elements not known to enough precision
sage: cc.is_equal_to(c, 2), cc.is_equal_to(c, 4), cc.is_equal_to(c, 5)
(True, True, False)
Returns whether self is zero modulo $p^{mbox{absprec}}$.
If absprec is None, returns True if this element is indistinguishable from zero.
INPUT:
- self -- a p-adic element
- absprec -- an integer or None
OUTPUT:
- boolean -- whether self is zero
EXAMPLES:
sage: R = Zp(5); a = R(0); b = R(0,5); c = R(75)
sage: a.is_zero(), a.is_zero(6)
(True, True)
sage: b.is_zero(), b.is_zero(5)
(True, True)
sage: c.is_zero(), c.is_zero(2), c.is_zero(3)
(False, True, False)
sage: b.is_zero(6)
...
PrecisionError: Not enough precision to determine if element is zero
Return an integer or rational congruent to self modulo self’s precision. If a rational is returned, its denominator will eqaul p^ordp(self).
INPUT:
- self -- a p-adic element
OUTPUT:
- integer -- a integer congruent to self mod $p^{\mbox{prec}}$
EXAMPLES:
sage: R = Zp(7,4,'capped-rel'); a = R(8); a.lift()
8
sage: R = Qp(7,4); a = R(8); a.lift()
8
sage: R = Qp(7,4); a = R(8/7); a.lift()
8/7
Returns another element of the same parent, with absolute precision at least absprec, congruent to self modulo self’s precision.
If such lifting would yield an element with precision greater than allowed by the precision cap of self’s parent, an error is raised.
EXAMPLES:
sage: R = Zp(5); a = R(0); b = R(0,5); c = R(17,3)
sage: a.lift_to_precision(5)
0
sage: b.lift_to_precision(4)
O(5^5)
sage: b.lift_to_precision(8)
O(5^8)
sage: b.lift_to_precision(40)
O(5^40)
sage: c.lift_to_precision(1)
2 + 3*5 + O(5^3)
sage: c.lift_to_precision(8)
2 + 3*5 + O(5^8)
sage: c.lift_to_precision(40)
...
PrecisionError: Precision higher than allowed by the precision cap.
Returns a list of coefficients in a power series expansion of self in terms of p. If self is a field element, they start at p^valuation, if a ring element at p^0.
INPUT:
- self -- a p-adic element
- lift_mode - 'simple', 'smallest' or 'teichmuller'
OUTPUT:
- list -- the list of coefficients of self. These will be integers if lift_mode is 'simple' or 'smallest', and elements of self.parent() if lift_mode is 'teichmuller'
EXAMPLES:
sage: R = Zp(7,6); a = R(12837162817); a
3 + 4*7 + 4*7^2 + 4*7^4 + O(7^6)
sage: L = a.list(); L
[3, 4, 4, 0, 4]
sage: sum([L[i] * 7^i for i in range(len(L))]) == a
True
sage: L = a.list('smallest'); L
[3, -3, -2, 1, -3, 1]
sage: sum([L[i] * 7^i for i in range(len(L))]) == a
True
sage: L = a.list('teichmuller'); L
[3 + 4*7 + 6*7^2 + 3*7^3 + 2*7^5 + O(7^6),
0,
5 + 2*7 + 3*7^3 + O(7^4),
1 + O(7^3),
3 + 4*7 + O(7^2),
5 + O(7)]
sage: sum([L[i] * 7^i for i in range(len(L))])
3 + 4*7 + 4*7^2 + 4*7^4 + O(7^6)
sage: R = Qp(7,4); a = R(6*7+7**2); a.list()
[6, 1]
sage: a.list('smallest')
[-1, 2]
sage: a.list('teichmuller')
[6 + 6*7 + 6*7^2 + 6*7^3 + O(7^4),
2 + 4*7 + 6*7^2 + O(7^3),
3 + 4*7 + O(7^2),
3 + O(7)]
NOTE:
use slice operators to get a particular range
Returns a list of coefficients of p starting with $p^0$ up to $p^n$ exclusive (padded with zeros if needed). If a field element, starts at p^val instead.
INPUT:
self -- a p-adic element
n - an integer
lift_mode - 'simple', 'smallest' or 'teichmuller'
OUTPUT:
list -- the list of coefficients of self
EXAMPLES:
sage: R = Zp(7,3,'capped-rel'); a = R(2*7+7**2); a.padded_list(5)
[0, 2, 1, 0, 0]
sage: R = Qp(7,3); a = R(2*7+7**2); a.padded_list(5)
[2, 1, 0, 0]
sage: a.padded_list(3)
[2, 1]
NOTE:
the slice operators throw an error if asked for a slice above the precision
Returns the absolute precision of self.
This is the power of the maximal ideal modulo which this element is defined.
INPUT:
self -- a p-adic element
OUTPUT:
integer -- the absolute precision of self
EXAMPLES:
sage: R = Zp(7,3,'capped-rel'); a = R(7); a.precision_absolute()
4
sage: R = Qp(7,3); a = R(7); a.precision_absolute()
4
sage: R(7^-3).precision_absolute()
0
Returns the relative precision of self.
This is the power of the maximal ideal modulo which the unit part of self is defined.
Reduces this element modulo $p^absprec$.
INPUT:
- self -- a p-adic element
- absprec - an integer (defaults to 1)
OUTPUT:
- element of $Z/(p^{absprec} Z)$ -- self reduced mod p^absprec
EXAMPLES:
sage: R = Zp(7,4,'capped-rel'); a = R(8); a.residue(1)
1
sage: R = Qp(7,4,'capped-rel'); a = R(8); a.residue(1)
1
sage: a.residue(6)
...
PrecisionError: Not enough precision known in order to compute residue.
sage: b = a/7
sage: b.residue(1)
...
ValueError: Element must have non-negative valuation in order to compute residue.
Returns the unit part of self.
INPUT:
- self -- a p-adic element
OUTPUT:
- p-adic element -- the unit part of self
EXAMPLES:
sage: R = Zp(17,4,'capped-rel')
sage: a = R(18*17)
sage: a.unit_part()
1 + 17 + O(17^4)
sage: type(a)
<type 'sage.rings.padics.padic_capped_relative_element.pAdicCappedRelativeElement'>
sage: R = Qp(17,4,'capped-rel')
sage: a = R(18*17)
sage: a.unit_part()
1 + 17 + O(17^4)
sage: type(a)
<type 'sage.rings.padics.padic_capped_relative_element.pAdicCappedRelativeElement'>
sage: a = R(2*17^2); a
2*17^2 + O(17^6)
sage: a.unit_part()
2 + O(17^4)
sage: b=1/a; b
9*17^-2 + 8*17^-1 + 8 + 8*17 + O(17^2)
sage: b.unit_part()
9 + 8*17 + 8*17^2 + 8*17^3 + O(17^4)
sage: Zp(5)(75).unit_part()
3 + O(5^20)
Returns a pair (self.valuation(), self.unit_part()).
EXAMPLES:
sage: R = Zp(5); a = R(75, 20); a
3*5^2 + O(5^20)
sage: a.val_unit()
(2, 3 + O(5^18))
sage: R(0).val_unit()
(+Infinity, O(5^0))
sage: R(0, 10).val_unit()
(10, O(5^0))
Unpickles a capped relative element.
EXAMPLES:
sage: from sage.rings.padics.padic_capped_relative_element import unpickle_pcre_v1
sage: R = Zp(5)
sage: a = unpickle_pcre_v1(R, 17, 2, 5); a
2*5^2 + 3*5^3 + O(5^7)