summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Caruso <xavier.caruso@univ-rennes1.fr>2017-12-20 18:02:54 +0100
committerXavier Caruso <xavier.caruso@univ-rennes1.fr>2017-12-20 18:02:54 +0100
commitf06603b350f2e3daedaf742f438db206b14e162f (patch)
tree3fac4d7a16545085800e01975eb0d8e88eee3245
parentMore doctests in lattice_precision.py (diff)
Doctest in padic_base_leaves.py
-rw-r--r--src/sage/rings/padics/lattice_precision.py30
-rw-r--r--src/sage/rings/padics/padic_base_leaves.py421
2 files changed, 430 insertions, 21 deletions
diff --git a/src/sage/rings/padics/lattice_precision.py b/src/sage/rings/padics/lattice_precision.py
index 4041d97..da3c168 100644
--- a/src/sage/rings/padics/lattice_precision.py
+++ b/src/sage/rings/padics/lattice_precision.py
@@ -198,7 +198,7 @@ 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`
+ This is an helper function for the methods :meth:`precision_lattice`
TESTS::
@@ -226,7 +226,7 @@ def format_history(tme, status, timings):
"""
Return a formated output for the history.
- This is an helper function for the methods meth:`history`.
+ This is an helper function for the methods :meth:`history`.
TESTS::
@@ -451,7 +451,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
If ``dx_mode`` is ``values``, the dictionary ``dx`` directly
specifies the entries that have to stored in the precision lattice.
This mode is only used for multiple conversion between different
- parents (see meth:`multiple_conversion`).
+ parents (see :meth:`multiple_conversion`).
TESTS::
@@ -524,7 +524,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
NOTE::
This method does not update the precision lattice.
- The actual update is performed when the method meth:`del_elements`
+ 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.
@@ -647,7 +647,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
NOTE:
This function is not meant to be called directly.
- You should prefer call the method meth:`lift_to_precision`
+ You should prefer call the method :meth:`lift_to_precision`
of ``x`` instead.
EXAMPLES::
@@ -726,7 +726,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
NOTE:
This function is not meant to be called directly.
- You should prefer call the method meth:`precision_absolute`
+ You should prefer call the method :meth:`precision_absolute`
of ``x`` instead.
EXAMPLES::
@@ -997,7 +997,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
"""
Enable history.
- We refer to the documentation of the method meth:`history` for
+ We refer to the documentation of the method :meth:`history` for
a complete documentation (including examples) about history.
TESTS::
@@ -1017,7 +1017,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
.. SEEALSO::
- meth:`history`, meth:`history_disable`, meth:`history_clear`
+ :meth:`history`, :meth:`history_disable`, :meth:`history_clear`
"""
if self._history is None:
self._history_init = ( len(self._elements), list(self._marked_for_deletion) )
@@ -1027,7 +1027,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
"""
Disable history.
- We refer to the documentation of the method meth:`history` for
+ We refer to the documentation of the method :meth:`history` for
a complete documentation (including examples) about history.
TESTS::
@@ -1053,7 +1053,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
.. SEEALSO::
- meth:`history`, meth:`history_enable`, meth:`history_clear`
+ :meth:`history`, :meth:`history_enable`, :meth:`history_clear`
"""
self._history = self._history_init = None
@@ -1061,7 +1061,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
"""
Clear history
- We refer to the documentation of the method meth:`history` for
+ We refer to the documentation of the method :meth:`history` for
a complete documentation (including examples) about history.
TESTS::
@@ -1092,7 +1092,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
.. SEEALSO::
- meth:`history`, meth:`history_enable`, meth:`history_disable`
+ :meth:`history`, :meth:`history_enable`, :meth:`history_disable`
"""
if self._history is None:
raise ValueError("History is not tracked")
@@ -1123,7 +1123,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
IMPORTANT NOTE:
History is disabled by default.
- It should then be enabled (through a call to the method meth:`history_enable`)
+ It should then be enabled (through a call to the method :meth:`history_enable`)
before use.
EXAMPLES::
@@ -1164,7 +1164,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
- 2nd line: elements at prime positions were marked for deletion
(this corresponds to the ``for`` loop)
- 3rd line: the above elements are indeed deleted
- (this corresponds to the call of the method meth:`del_elements`
+ (this corresponds to the call of the method :meth:`del_elements`
Here are some variants::
@@ -1210,7 +1210,7 @@ class PrecisionLattice(UniqueRepresentation, SageObject):
.. SEEALSO::
- meth:`history_enable`, meth:`history_disable`, meth:`history_clear`
+ :meth:`history_enable`, :meth:`history_disable`, :meth:`history_clear`
"""
if self._history is None:
diff --git a/src/sage/rings/padics/padic_base_leaves.py b/src/sage/rings/padics/padic_base_leaves.py
index cab6236..07a0de8 100644
--- a/src/sage/rings/padics/padic_base_leaves.py
+++ b/src/sage/rings/padics/padic_base_leaves.py
@@ -872,15 +872,112 @@ class pAdicLatticeGeneric(pAdicGeneric):
self._element_class = pAdicLatticeElement
def _prec_type(self):
+ """
+ Return the precision handling type
+
+ EXAMPLES::
+
+ sage: ZpLP(5)._prec_type()
+ 'lattice'
+ """
return 'lattice'
def precision(self):
+ """
+ Return the lattice precision object attached to this parent
+
+ EXAMPLES::
+
+ sage: R = ZpLP(5,label='precision')
+ sage: R.precision()
+ Precision Lattice on 0 object (label: precision)
+
+ sage: x = R(1,10); y = R(1,5)
+ sage: R.precision()
+ Precision Lattice on 2 objects (label: precision)
+
+ .. SEEALSO::
+
+ :class:`sage.rings.padics.lattice_precision.PrecisionLattice`
+ """
+
return self._precision
def label(self):
+ """
+ Return the label of this parent
+
+ NOTE:
+
+ Labels can be used to distinguish between parents with
+ the same defining data.
+
+ They are useful in the lattice precision framework in order
+ to limit the size of the lattice modeling the precision (which
+ is roughly the number of elements having this parent).
+
+ Elements of a parent with some label do not coerse to aparent
+ with a different label. However conversions are allowed.
+
+ EXAMPLES:
+
+ sage: R = ZpLP(5)
+ sage: R.label() # no label by default
+
+ sage: R = ZpLP(5, label='mylabel')
+ sage: R.label()
+ 'mylabel'
+
+ Labels are typically useful to isolate computations.
+ For example, assume that we first want to do some calculations
+ with matrices::
+
+ sage: R = ZpLP(5, label='matrices')
+ sage: M = random_matrix(R, 4, 4)
+ sage: M.determinant() # somewhat random
+
+ Now, if we want to do another unrelated computations, we can
+ use a different label::
+
+ sage: R = ZpLP(5, label='polynomials')
+ sage: S.<x> = PolynomialRing(R)
+ sage: P = (x-1)*(x-2)*(x-3)*(x-4)*(x-5)
+
+ If we have not used labels, the software would have modeled the
+ precision on the matrices and on the polynomials using the same
+ lattice (resulting then in manipulating a lattice of higher
+ dimension, having then a significant impact on performances).
+ """
return self._label
def _element_constructor_(self, x, prec=None):
+ """
+ Create an element of this parent
+
+ INPUT:
+
+ - ``x``: the datum from which the element is created
+
+ - ``prec`` -- an integer or ``None`` (the default); the
+ absolute precision of the created element
+
+ NOTE:
+
+ This function tries to be sharp on precision as much as
+ possible.
+ For instance, if the datum ``x`` is itself an element of the
+ same parent, the software remembers that the created element
+ is actually equal to ``x`` (at infinite precision)::
+
+ sage: R = ZpLP(2, prec=50)
+ sage: x = R(1,10); x
+ 1 + O(2^10)
+ sage: y = R(x) # indirect doctest
+ sage: y
+ 1 + O(2^10)
+ sage: x - y
+ O(2^50)
+ """
# We first try the __copy__ method which is sharp on precision
try:
if prec is None:
@@ -892,6 +989,60 @@ class pAdicLatticeGeneric(pAdicGeneric):
return self._element_class(self, x, prec)
def convert_multiple(self, *elts):
+ """
+ Convert a list of elements to this parent
+
+ NOTE:
+
+ This function tries to be sharp on precision as much as
+ possible.
+ In particular, if the precision of the input elements are
+ handled by a lattice, diffused digits of precision are
+ preserved during the conversion.
+
+ EXAMPLES::
+
+ sage: R = ZpLP(2)
+ sage: x = R(1,10); y = R(1,5)
+ sage: x,y = x+y, x-y
+
+ Remark that the pair `(x,y)` has diffused digits of precision::
+
+ sage: x
+ 2 + O(2^5)
+ sage: y
+ O(2^5)
+ sage: x + y
+ 2 + O(2^11)
+
+ sage: R.precision().number_of_diffused_digits([x,y])
+ 6
+
+ As a consequence, if we convert ``x`` and ``y`` separately, we
+ loose some precision::
+
+ sage: R2 = ZpLP(2, label='copy')
+ sage: x2 = R2(x); y2 = R2(y)
+ sage: x2
+ 2 + O(2^5)
+ sage: y2
+ O(2^5)
+ sage: x2 + y2
+ 2 + O(2^5)
+
+ sage: R2.precision().number_of_diffused_digits([x2,y2])
+ 0
+
+ On the other hand, this issue dissapears when we use multiple
+ conversion::
+
+ sage: x2,y2 = R2.convert_multiple(x,y)
+ sage: x2 + y2
+ 2 + O(2^11)
+
+ sage: R2.precision().number_of_diffused_digits([x2,y2])
+ 6
+ """
p = self.prime()
# We sort elements by precision lattice
@@ -950,11 +1101,49 @@ class pAdicLatticeGeneric(pAdicGeneric):
class pAdicRingLattice(pAdicLatticeGeneric, pAdicRingBaseGeneric):
- def __init__(self, p, prec, print_mode, name, label=None, proof=False):
+ """
+ An implementation of the `p`-adic integers with lattice precision
+ """
+ def __init__(self, p, prec, print_mode, names, label=None, proof=False):
+ """
+ Initialization.
+
+ INPUT:
+
+ - ``p`` -- prime
+ - ``prec`` -- precision cap
+ - ``print_mode`` -- dictionary with print options
+ - ``names`` -- how to print the prime
+ - ``label`` -- the label of this ring
+
+ EXAMPLES::
+
+ sage: R = ZpLP(next_prime(10^60)) # indirect doctest
+ sage: type(R)
+ <class 'sage.rings.padics.padic_base_leaves.pAdicRingLattice_with_category'>
+
+ sage: R = ZpLP(2,label='init') # indirect doctest
+ sage: R
+ 2-adic Ring with lattice precision (label: init)
+
+ .. SEEALSO::
+
+ :meth:`label`
+ """
pAdicLatticeGeneric.__init__(self, p, prec, label, proof)
- pAdicRingBaseGeneric.__init__(self, p, prec, print_mode, str(p), None)
+ pAdicRingBaseGeneric.__init__(self, p, prec, print_mode,