summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Caruso <xavier.caruso@univ-rennes1.fr>2017-12-20 15:33:05 +0100
committerXavier Caruso <xavier.caruso@univ-rennes1.fr>2017-12-20 15:33:05 +0100
commitb70227bcec8cb6d841c2e157f1f1c08179254ef2 (patch)
tree8e8e039d575f42c49f39a7ae10b925ae355fadb6
parentSome doctests in lattice_precision.py (diff)
More doctests in lattice_precision.py
-rw-r--r--src/sage/rings/padics/lattice_precision.py400
1 files changed, 350 insertions, 50 deletions
diff --git a/src/sage/rings/padics/lattice_precision.py b/src/sage/rings/padics/lattice_precision.py
index 5180800..4041d97 100644
--- a/src/sage/rings/padics/lattice_precision.py
+++ b/src/sage/rings/padics/lattice_precision.py
@@ -194,6 +194,24 @@ class pRational:
########################
def list_of_padics(elements):
+ """
+ Convert a list of p-adic composed elements (as polynomials, matrices)
+ to a list of weak refererences of their p-adic coefficients.
+
+ This is an helper function for the methods meth:`precision_lattice`
+
+ TESTS::
+
+ sage: from sage.rings.padics.lattice_precision import list_of_padics
+ sage: R = ZpLP(2)
+ sage: M = random_matrix(R,2,2)
+ sage: list_of_padics(M)
+ [<weakref at 0x...; to 'pAdicLatticeElement' at 0x...>,
+ <weakref at 0x...; to 'pAdicLatticeElement' at 0x...>,
+ <weakref at 0x...; to 'pAdicLatticeElement' at 0x...>,
+ <weakref at 0x...; to 'pAdicLatticeElement' at 0x...>]
+
+ """
from sage.rings.padics.padic_lattice_element import pAdicLatticeElement
if isinstance(elements, pAdicLatticeElement):
return [ weakref.ref(elements) ]
@@ -205,9 +223,31 @@ def list_of_padics(elements):
return ans
def format_history(tme, status, timings):
+ """
+ Return a formated output for the history.
+
+ This is an helper function for the methods meth:`history`.
+
+ TESTS::
+
+ sage: from sage.rings.padics.lattice_precision import format_history
+ sage: format_history(1.23456789, ['o','o','o','o','o','o','~','o','o'], true)
+ '1.234568s oooooo~oo'
+ sage: format_history(1.23456789, ['o','o','o','o','o','o','~','o','o'], false)
+ 'oooooo~oo'
+
+ sage: format_history(12.3456789, ['o','o','o','o','o','o','~','o','o'], true)
+ ' >= 10s oooooo~oo'
+ sage: format_history(10^(-10), ['o','o','o','o','o','o','~','o','o'], true)
+ ' --- oooooo~oo'
+ sage: format_history(-1, ['o','o','o','o','o','o','~','o','o'], true)
+ ' Timings oooooo~oo'
+ """
status = ''.join(status)
if timings:
- if tme < 0.000001:
+ if tme < 0:
+ s = " Timings "
+ elif tme < 0.000001:
s = " --- "
elif tme >= 10:
s = " >= 10s "
@@ -271,7 +311,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
sage: R = ZpLP(2)
sage: R.precision()
- Precision Lattice on 0 object
+ Precision Lattice on ... objects
If a label has been specified, it is included in the representation
@@ -305,8 +345,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
def reduce(self, index=0, partial=False):
"""
- Perform a row reduction of the matrix representating this precision
- lattice
+ Reduce the size of the entries above the diagonal of the precision matrix
INPUT:
@@ -461,22 +500,20 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
if self._history is not None:
self._history.append(('add', None, walltime(tme)))
- def _set_precision(self, x, column={}):
- """
- """
- p = self._p
- x_ref = weakref.ref(x)
- index = len(self._lattice[x_ref]) - 1
- n = len(self._elements)
- col = n * [self._approx_zero]
- self._lattice[x_ref] = col
- self._absolute_precisions[x_ref] = min([ c.valuation() for c in col ])
+ #def _set_precision(self, x, column={}):
+ # p = self._p
+ # x_ref = weakref.ref(x)
+ # index = len(self._lattice[x_ref]) - 1
+ # n = len(self._elements)
+ # col = n * [self._approx_zero]
+ # self._lattice[x_ref] = col
+ # self._absolute_precisions[x_ref] = min([ c.valuation() for c in col ])
def mark_for_deletion(self, ref):
"""
Mark an element for deletion.
- It is not meant to be called manually.
+ This function is not meant to be called manually.
It is automatically called by the garbage collection when
an element is collected.
@@ -490,6 +527,20 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
The actual update is performed when the method meth:`del_elements`
is called. This is automatically done at the creation of a new
element but can be done manually as well.
+
+ EXAMPLES::
+
+ sage: R = ZpLP(2, label='markdel')
+ sage: prec = R.precision()
+ sage: x = R(1,10)
+ sage: prec
+ Precision Lattice on 1 object (label: markdel)
+ sage: del x # indirect doctest: x is here marked for deletion
+ sage: prec
+ Precision Lattice on 1 object (label: markdel)
+ sage: prec.del_elements() # x is indeed deleted
+ sage: prec
+ Precision Lattice on 0 object (label: markdel)
"""
tme = walltime()
try:
@@ -707,7 +758,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
EXAMPLES::
- sage: R = ZpLP(2)
+ sage: R = ZpLP(2, label='preclattice')
sage: prec = R.precision()
sage: x = R(1,10); y = R(1,5)
sage: u = x + y
@@ -792,7 +843,8 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
jagged precision (that is a precision which is split over
all variables).