p-Adic Capped Relative Element
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]
Bases: sage.rings.padics.padic_base_generic_element.pAdicBaseGenericElement
Constructs new element with given parent and value.
INPUT:
EXAMPLES:
sage: R = Zp(5, 10, 'capped-rel')
Construct from integers:
sage: R(3)
3 + O(5^10)
sage: R(75)
3*5^2 + O(5^12)
sage: R(0)
0
sage: R(-1)
4 + 4*5 + 4*5^2 + 4*5^3 + 4*5^4 + 4*5^5 + 4*5^6 + 4*5^7 + 4*5^8 + 4*5^9 + O(5^10)
sage: R(-5)
4*5 + 4*5^2 + 4*5^3 + 4*5^4 + 4*5^5 + 4*5^6 + 4*5^7 + 4*5^8 + 4*5^9 + 4*5^10 + O(5^11)
sage: R(-7*25)
3*5^2 + 3*5^3 + 4*5^4 + 4*5^5 + 4*5^6 + 4*5^7 + 4*5^8 + 4*5^9 + 4*5^10 + 4*5^11 + O(5^12)
Construct from rationals:
sage: R(1/2)
3 + 2*5 + 2*5^2 + 2*5^3 + 2*5^4 + 2*5^5 + 2*5^6 + 2*5^7 + 2*5^8 + 2*5^9 + O(5^10)
sage: R(-7875/874)
3*5^3 + 2*5^4 + 2*5^5 + 5^6 + 3*5^7 + 2*5^8 + 3*5^10 + 3*5^11 + 3*5^12 + O(5^13)
sage: R(15/425)
Traceback (most recent call last):
...
ValueError: p divides the denominator
Construct from IntegerMod:
sage: R(Integers(125)(3))
3 + O(5^3)
sage: R(Integers(5)(3))
3 + O(5)
sage: R(Integers(5^30)(3))
3 + O(5^10)
sage: R(Integers(5^30)(1+5^23))
1 + O(5^10)
sage: R(Integers(49)(3))
Traceback (most recent call last):
...
TypeError: cannot coerce from the given integer mod ring (not a power of the same prime)
# todo: should the above TypeError be another type of error?
sage: R(Integers(48)(3))
Traceback (most recent call last):
...
TypeError: cannot coerce from the given integer mod ring (not a power of the same prime)
# todo: the error message for the above TypeError is not quite accurate
Some other conversions:
sage: R(R(5))
5 + O(5^11)
Construct from Pari objects:
sage: R = Zp(5)
sage: x = pari(123123) ; R(x)
3 + 4*5 + 4*5^2 + 4*5^3 + 5^4 + 4*5^5 + 2*5^6 + 5^7 + O(5^20)
sage: R(pari(R(5252)))
2 + 2*5^3 + 3*5^4 + 5^5 + O(5^20)
sage: R = Zp(5,prec=5)
sage: R(pari(-1))
4 + 4*5 + 4*5^2 + 4*5^3 + 4*5^4 + O(5^5)
sage: pari(R(-1))
4 + 4*5 + 4*5^2 + 4*5^3 + 4*5^4 + O(5^5)
sage: pari(R(0))
0
sage: R(pari(R(0) + O(5^5)))
O(5^5)
# todo: doctests for converting from other types of p-adic rings
Test that trac ticket #3865 is fixed:
sage: ZpCR(7, 10)(gp('7 + O(7^2)'))
7 + O(7^2)
Returns a new element with absolute precision decreased to absprec.
INPUT:
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 .
if absprec is None, returns True if self and right are equal to the minimum of their precisions.
INPUT:
OUTPUT:
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)
Traceback (most recent call last):
...
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)
Traceback (most recent call last):
...
PrecisionError: Elements not known to enough precision
sage: b.is_equal_to(b, 5)
Traceback (most recent call last):
...
PrecisionError: Elements not known to enough precision
sage: b.is_equal_to(bb, 3)
True
sage: b.is_equal_to(bb, 4)
Traceback (most recent call last):
...
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)
Traceback (most recent call last):
...
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)
Traceback (most recent call last):
...
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)
Traceback (most recent call last):
...
PrecisionError: Elements not known to enough precision
sage: bb.is_equal_to(b, 3)
True
sage: bb.is_equal_to(b, 4)
Traceback (most recent call last):
...
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)
Traceback (most recent call last):
...
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 .
If absprec is None, returns True if this element is indistinguishable from zero.
INPUT:
OUTPUT:
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)
Traceback (most recent call last):
...
PrecisionError: Not enough precision to determine if element is zero
TESTS:
Check that trac ticket #12549 is fixed:
sage: a = Zp(5)(1) + Zp(5)(-1)
sage: a.is_zero()
True
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:
OUTPUT:
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 this one modulo the known precision.
INPUT:
Note
If setting absprec that high would violate the precision cap, raises a precision error. If self is an inexact zero and absprec is greater than the maximum allowed valuation, raises an error.
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)
Traceback (most recent call last):
...
PrecisionError: Precision higher than allowed by the precision cap.
sage: c.lift_to_precision().precision_relative() == R.precision_cap()
True
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:
OUTPUT:
Note
Use slice operators to get a particular range.
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)]
TESTS:
Check to see that #10292 is resolved:
sage: E = EllipticCurve('37a')
sage: R = E.padic_regulator(7)
sage: R._is_normalized()
False
sage: len(R.list())
19
Returns a list of coefficients of p starting with up to
exclusive (padded with zeros if needed). If a field
element, starts at p^val instead.
INPUT:
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.
INPUT:
self – a p-adic element
OUTPUT:
integer – the relative precision of self
EXAMPLES:
sage: R = Zp(7,3,'capped-rel'); a = R(7); a.precision_relative()
3
sage: R = Qp(7,3); a = R(7); a.precision_relative()
3
sage: a = R(7^-2, -1); a.precision_relative()
1
sage: a
7^-2 + O(7^-1)
Reduces this element modulo .
INPUT:
OUTPUT:
Element of – 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)
Traceback (most recent call last):
...
PrecisionError: Not enough precision known in order to compute residue.
sage: b = a/7
sage: b.residue(1)
Traceback (most recent call last):
...
ValueError: Element must have non-negative valuation in order to compute residue.
Returns the unit part of self.
INPUT:
OUTPUT:
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)