summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Caruso <xavier.caruso@univ-rennes1.fr>2017-12-23 07:40:50 +0100
committerXavier Caruso <xavier.caruso@univ-rennes1.fr>2017-12-23 07:40:50 +0100
commit5ef1735186f642f81c8a335f07b3f6f05b0a2821 (patch)
treeb638da0a382689bd38b1ee9be3b582c8e20395f3
parentDoctest in padic_base_leaves.py (diff)
Doctest in padic_lattice_element.py
-rw-r--r--src/sage/rings/padics/lattice_precision.py2
-rw-r--r--src/sage/rings/padics/padic_base_leaves.py10
-rw-r--r--src/sage/rings/padics/padic_lattice_element.py691
3 files changed, 680 insertions, 23 deletions
diff --git a/src/sage/rings/padics/lattice_precision.py b/src/sage/rings/padics/lattice_precision.py
index da3c168..d4f7cd5 100644
--- a/src/sage/rings/padics/lattice_precision.py
+++ b/src/sage/rings/padics/lattice_precision.py
@@ -545,7 +545,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
tme = walltime()
try:
index = len(self._lattice[ref]) - 1
- except IndexError:
+ except (IndexError, KeyError):
return
self._marked_for_deletion.append(index)
if self._history is not None:
diff --git a/src/sage/rings/padics/padic_base_leaves.py b/src/sage/rings/padics/padic_base_leaves.py
index 07a0de8..f57e7b1 100644
--- a/src/sage/rings/padics/padic_base_leaves.py
+++ b/src/sage/rings/padics/padic_base_leaves.py
@@ -978,12 +978,12 @@ class pAdicLatticeGeneric(pAdicGeneric):
sage: x - y
O(2^50)
"""
- # We first try the __copy__ method which is sharp on precision
+ # We first try the copy method which is sharp on precision
try:
if prec is None:
- return x.__copy__(parent=self)
+ return x.copy(parent=self)
else:
- return x.__copy__(parent=self).add_bigoh(prec)
+ return x.copy(parent=self).add_bigoh(prec)
except (TypeError, ValueError, AttributeError):
pass
return self._element_class(self, x, prec)
@@ -1072,10 +1072,10 @@ class pAdicLatticeGeneric(pAdicGeneric):
# First the elements with precision lattice
for (prec, L) in elt_by_prec.iteritems():
if prec is selfprec:
- # Here, we use the __copy__ method in order
+ # Here, we use the copy method in order
# to be sharp on precision
for x in L:
- y = x.__copy__(parent=self)
+ y = x.copy(parent=self)
for i in indices[id(x)]:
ans[i] = y
else:
diff --git a/src/sage/rings/padics/padic_lattice_element.py b/src/sage/rings/padics/padic_lattice_element.py
index 18a19f7..dd99b5a 100644
--- a/src/sage/rings/padics/padic_lattice_element.py
+++ b/src/sage/rings/padics/padic_lattice_element.py
@@ -8,8 +8,13 @@ from sage.rings.padics.generic_nodes import pAdicRingBaseGeneric
from sage.rings.padics.padic_generic_element import pAdicGenericElement
from sage.rings.padics.lattice_precision import pRational
+from sage.rings.padics.precision_error import PrecisionError
+
class pAdicLatticeElement(pAdicGenericElement):
+ """
+ Constructs new element with given parent and value.
+ """
def __init__(self, parent, x, prec=None, dx=[], dx_mode='linear_combinaison', valuation=None, check=True, reduce=True):
self._parent = parent
pAdicGenericElement.__init__(self, parent)
@@ -22,10 +27,7 @@ class pAdicLatticeElement(pAdicGenericElement):
prec = x.precision_absolute()
else:
prec = min(prec, x.precision_absolute())
- if isinstance(parent, pAdicRingBaseGeneric):
- x = ZZ(x)
- else:
- x = QQ(x)
+ x = QQ(x)
cap = parent.precision_cap()
if prec is None or prec > cap:
prec = cap
@@ -40,26 +42,146 @@ class pAdicLatticeElement(pAdicGenericElement):
self._approx_minusone = pRational(parent.prime(), -1)
def __hash__(self):
+ """
+ Return a hash of this element
+
+ TESTS::
+
+ sage: R = ZpLP(2)
+ sage: x = R(1,10)
+ sage: hash(x) # somewhat random
+ """
return id(self)
+ # This doesn't work apparently (I don't know why)
+ # Deletion is currently handled in PrecisionLattice
+ # def __del__(self):
+ # self._precision.mark_for_deletion(weakref.ref(self))
+
def _is_base_elt(self, p):
return p == self._parent.prime()
def approximation(self):
+ """
+ Return an approximation of this element at
+ its absolute precision
+
+ EXAMPLES::
+
+ sage: R = ZpLP(2, print_mode='terse')
+ sage: x = R(1234,10); x
+ 210 + O(2^10)
+ sage: x.approximation()
+ 210
+ """
prec = self.precision_absolute()
app = self._value.reduce(prec)
return app.value()
def value(self):
+ """
+ Return the actual approximation of this element
+ stored in memory.
+ In presence of diffused digits of precision, it can
+ have more precision than the absolute precision of
+ the element.
+
+ EXAMPLES::<