[sagemath] 01/01: Apply pari 2.9 patch from sage trac #21756.

Tobias Hansen thansen at moszumanska.debian.org
Sat Nov 5 13:36:11 UTC 2016


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository sagemath.

commit 3a6e3794b95e7162923ab0c8aed68e024480eaa4
Author: Tobias Hansen <thansen at broeselmaschine.fc.up.pt>
Date:   Sat Nov 5 10:42:14 2016 +0000

    Apply pari 2.9 patch from sage trac #21756.
---
 debian/patches/series                 |    1 +
 debian/patches/version-pari-2.9.patch | 1104 +++++++++++++++++++++++++++++++++
 2 files changed, 1105 insertions(+)

diff --git a/debian/patches/series b/debian/patches/series
index f2f35ea..492f8f6 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -21,6 +21,7 @@ version-singular-4.patch
 version-cddlib-094h.patch
 version-glpk-4.60.patch
 version-pari-2.9-trac-21765.patch
+version-pari-2.9.patch
 #version-planarity-3.patch #breaks tests
 
 # due to Debian's inherent differences with upstream;
diff --git a/debian/patches/version-pari-2.9.patch b/debian/patches/version-pari-2.9.patch
new file mode 100644
index 0000000..dcb5933
--- /dev/null
+++ b/debian/patches/version-pari-2.9.patch
@@ -0,0 +1,1104 @@
+From 313b785064eb21e16d55855c4c2216fa26ca8df0 Mon Sep 17 00:00:00 2001
+From: Jeroen Demeyer <jdemeyer at cage.ugent.be>
+Date: Fri, 14 Oct 2016 13:30:20 +0200
+Subject: Interface PARI precision in bits
+
+---
+ src/sage/libs/pari/pari_instance.pxd |   1 -
+ src/sage/libs/pari/pari_instance.pyx | 353 ++++++++++++++++++++++-------------
+ 2 files changed, 225 insertions(+), 129 deletions(-)
+
+--- a/sage/src/sage/libs/pari/pari_instance.pxd
++++ b/sage/src/sage/libs/pari/pari_instance.pxd
+@@ -14,7 +14,6 @@
+ 
+ @cython.final
+ cdef class PariInstance(PariInstance_auto):
+-    cdef long _real_precision
+     cdef readonly gen PARI_ZERO, PARI_ONE, PARI_TWO
+     cpdef gen zero(self)
+     cpdef gen one(self)
+--- a/sage/src/sage/libs/pari/pari_instance.pyx
++++ b/sage/src/sage/libs/pari/pari_instance.pyx
+@@ -49,85 +49,61 @@
+     sage: type(1 + pari(1))
+     <type 'sage.libs.pari.gen.gen'>
+ 
+-GUIDE TO REAL PRECISION AND THE PARI LIBRARY
++Guide to real precision in the PARI interface
++=============================================
+ 
+-The default real precision in communicating with the PARI library
+-is the same as the default Sage real precision, which is 53 bits.
+-Inexact Pari objects are therefore printed by default to 15 decimal
+-digits (even if they are actually more precise).
+-
+-Default precision example (53 bits, 15 significant decimals)::
+-
+-    sage: a = pari(1.23); a
+-    1.23000000000000
+-    sage: a.sin()
+-    0.942488801931698
+-
+-Example with custom precision of 200 bits (60 significant
+-decimals)::
+-
+-    sage: R = RealField(200)
+-    sage: a = pari(R(1.23)); a   # only 15 significant digits printed
+-    1.23000000000000
+-    sage: R(a)         # but the number is known to precision of 200 bits
+-    1.2300000000000000000000000000000000000000000000000000000000
+-    sage: a.sin()      # only 15 significant digits printed
+-    0.942488801931698
+-    sage: R(a.sin())   # but the number is known to precision of 200 bits
+-    0.94248880193169751002382356538924454146128740562765030213504
+-
+-It is possible to change the number of printed decimals::
+-
+-    sage: R = RealField(200)    # 200 bits of precision in computations
+-    sage: old_prec = pari.set_real_precision(60)  # 60 decimals printed
+-    sage: a = pari(R(1.23)); a
+-    1.23000000000000000000000000000000000000000000000000000000000
+-    sage: a.sin()
+-    0.942488801931697510023823565389244541461287405627650302135038
+-    sage: pari.set_real_precision(old_prec)  # restore the default printing behavior
+-    60
+-
+-Unless otherwise indicated in the docstring, most Pari functions
+-that return inexact objects use the precision of their arguments to
+-decide the precision of the computation. However, if some of these
+-arguments happen to be exact numbers (integers, rationals, etc.),
+-an optional parameter indicates the precision (in bits) to which
+-these arguments should be converted before the computation. If this
+-precision parameter is missing, the default precision of 53 bits is
+-used. The following first converts 2 into a real with 53-bit
+-precision::
+-
+-    sage: R = RealField()
+-    sage: R(pari(2).sin())
+-    0.909297426825682
+-
+-We can ask for a better precision using the optional parameter::
+-
+-    sage: R = RealField(150)
+-    sage: R(pari(2).sin(precision=150))
+-    0.90929742682568169539601986591174484270225497
+-
+-Warning regarding conversions Sage - Pari - Sage: Some care must be
+-taken when juggling inexact types back and forth between Sage and
+-Pari. In theory, calling p=pari(s) creates a Pari object p with the
+-same precision as s; in practice, the Pari library's precision is
+-word-based, so it will go up to the next word. For example, a
+-default 53-bit Sage real s will be bumped up to 64 bits by adding
+-bogus 11 bits. The function p.python() returns a Sage object with
+-exactly the same precision as the Pari object p. So
+-pari(s).python() is definitely not equal to s, since it has 64 bits
+-of precision, including the bogus 11 bits. The correct way of
+-avoiding this is to convert pari(s).python() back into a domain with
+-the right precision. This has to be done by the user (or by Sage
+-functions that use Pari library functions in gen.pyx). For
+-instance, if we want to use the Pari library to compute sqrt(pi)
+-with a precision of 100 bits::
++In the PARI interface, "real precision" refers to the precision of real
++numbers, so it is the floating-point precision. This is a non-trivial
++issue, since there are various interfaces for different things.
++
++Internal representation and conversion between Sage and PARI
++------------------------------------------------------------
++
++Real numbers in PARI have a precision associated to them, which is
++always a multiple of the CPU wordsize. So, it is a multiple of 32
++of 64 bits. When converting from Sage to PARI, the precision is rounded
++up to the nearest multiple of the wordsize::
++
++    sage: x = 1.0
++    sage: x.precision()
++    53
++    sage: pari(x)
++    1.00000000000000
++    sage: pari(x).bitprecision()
++    64
++
++With a higher precision::
++
++    sage: x = RealField(100).pi()
++    sage: x.precision()
++    100
++    sage: pari(x).bitprecision()
++    128
++
++When converting back to Sage, the precision from PARI is taken::
++
++    sage: x = RealField(100).pi()
++    sage: y = pari(x).sage()
++    sage: y
++    3.1415926535897932384626433832793333156
++    sage: parent(y)
++    Real Field with 128 bits of precision
++
++So ``pari(x).sage()`` is definitely not equal to ``x`` since it has
++28 bogus bits.
++
++Therefore, some care must be taken when juggling reals back and forth
++between Sage and PARI. The correct way of avoiding this is to convert
++``pari(x).sage()`` back into a domain with the right precision. This has
++to be done by the user (or by Sage functions that use PARI library
++functions). For instance, if we want to use the PARI library to compute
++``sqrt(pi)`` with a precision of 100 bits::
+ 
+     sage: R = RealField(100)
+     sage: s = R(pi); s
+     3.1415926535897932384626433833
+     sage: p = pari(s).sqrt()
+-    sage: x = p.python(); x  # wow, more digits than I expected!
++    sage: x = p.sage(); x    # wow, more digits than I expected!
+     1.7724538509055160272981674833410973484
+     sage: x.prec()           # has precision 'improved' from 100 to 128?
+     128
+@@ -138,8 +114,99 @@
+     sage: R(x) == s.sqrt()
+     True
+ 
+-Elliptic curves and precision: If you are working with elliptic
+-curves, you should set the precision for each method::
++Output precision for printing
++-----------------------------
++
++Even though PARI reals have a precision, not all significant bits are
++printed by default. The maximum number of digits when printing a PARI
++real can be set using the methods
++:meth:`PariInstance.set_real_precision_bits` or
++:meth:`PariInstance.set_real_precision`.
++
++We create a very precise approximation of pi and see how it is printed
++in PARI::
++
++    sage: pi = pari(RealField(1000).pi())
++
++The default precision is 15 digits::
++
++    sage: pi
++    3.14159265358979
++
++With a different precision::
++
++    sage: _ = pari.set_real_precision(50)
++    sage: pi
++    3.1415926535897932384626433832795028841971693993751
++
++Back to the default::
++
++    sage: _ = pari.set_real_precision(15)
++    sage: pi
++    3.14159265358979
++
++Input precision for function calls
++----------------------------------
++
++When we talk about precision for PARI functions, we need to distinguish
++three kinds of calls:
++
++1. Using the string interface, for example ``pari("sin(1)")``.
++
++2. Using the library interface with exact inputs, for example
++   ``pari(1).sin()``.
++
++3. Using the library interface with inexact inputs, for example
++   ``pari(1.0).sin()``.
++
++In the first case, the relevant precision is the one set by the methods
++:meth:`PariInstance.set_real_precision_bits` or
++:meth:`PariInstance.set_real_precision`::
++
++    sage: pari.set_real_precision_bits(150)
++    sage: pari("sin(1)")
++    0.841470984807896506652502321630298999622563061
++    sage: pari.set_real_precision_bits(53)
++    sage: pari("sin(1)")
++    0.841470984807897
++
++In the second case, the precision can be given as the argument
++``precision`` in the function call, with a default of 53 bits.
++The real precision set by
++:meth:`PariInstance.set_real_precision_bits` or
++:meth:`PariInstance.set_real_precision` is irrelevant.
++
++In these examples, we convert to Sage to ensure that PARI's real
++precision is not used when printing the numbers. As explained before,
++this artificically increases the precision to a multiple of the
++wordsize. ::
++
++    sage: s = pari(1).sin(precision=180).sage(); print(s); print(parent(s))
++    0.841470984807896506652502321630298999622563060798371065673
++    Real Field with 192 bits of precision
++    sage: s = pari(1).sin(precision=40).sage(); print(s); print(parent(s))
++    0.841470984807896507
++    Real Field with 64 bits of precision
++    sage: s = pari(1).sin().sage(); print(s); print(parent(s))
++    0.841470984807896507
++    Real Field with 64 bits of precision
++
++In the third case, the precision is determined only by the inexact
++inputs and the ``precision`` argument is ignored::
++
++    sage: pari(1.0).sin(precision=180).sage()
++    0.841470984807896507
++    sage: pari(1.0).sin(precision=40).sage()
++    0.841470984807896507
++    sage: pari(RealField(100).one()).sin().sage()
++    0.84147098480789650665250232163029899962
++
++Elliptic curve functions
++------------------------
++
++An elliptic curve given with exact `a`-invariants is considered an
++exact object. Therefore, you should set the precision for each method
++call individually::
+ 
+     sage: e = pari([0,0,0,-82,0]).ellinit()
+     sage: eta1 = e.elleta(precision=100)[0]
+@@ -149,8 +216,6 @@
+     sage: eta1.sage()
+     3.60546360143265208591582056420772677481026899659802474544
+ 
+-Number fields and precision: TODO
+-
+ TESTS:
+ 
+ Check that output from PARI's print command is actually seen by
+@@ -215,33 +280,15 @@
+ from sage.misc.superseded import deprecation, deprecated_function_alias
+ from sage.env import CYGWIN_VERSION
+ 
+-# real precision in decimal digits: see documentation for
+-# get_real_precision() and set_real_precision().  This variable is used
+-# in gp to set the precision of input quantities (e.g. sqrt(2)), and for
+-# determining the number of digits to be printed.  It is *not* used as
+-# a "default precision" for internal computations, which always use
+-# the actual precision of arguments together (where relevant) with a
+-# "prec" parameter.  In ALL cases (for real computations) the prec
+-# parameter is a WORD precision and NOT decimal precision.  Pari reals
+-# with word precision w have bit precision (of the mantissa) equal to
+-# 32*(w-2) or 64*(w-2).
+-#
+-# Hence the only relevance of this parameter in Sage is (1) for the
+-# output format of components of objects of type
+-# 'sage.libs.pari.gen.gen'; (2) for setting the precision of pari
+-# variables created from strings (e.g. via sage: pari('1.2')).
+-#
+-# WARNING: Many pari library functions take a last parameter "prec"
+-# which should be a words precision.  In many cases this is redundant
+-# and is simply ignored.  In our wrapping of these functions we use
+-# the variable prec here for convenience only.
+-cdef long prec
++# Default precision (in PARI words) for the PARI library interface,
++# when no explicit precision is given and the inputs are exact.
++cdef long prec = prec_bits_to_words(53)
+ 
+ #################################################################
+ # conversions between various real precision models
+ #################################################################
+ 
+-def prec_bits_to_dec(unsigned long prec_in_bits):
++def prec_bits_to_dec(long prec_in_bits):
+     r"""
+     Convert from precision expressed in bits to precision expressed in
+     decimal.
+@@ -261,10 +308,9 @@
+         (224, 67),
+         (256, 77)]
+     """
+-    cdef double log_2 = 0.301029995663981
+-    return int(prec_in_bits*log_2)
++    return nbits2ndec(prec_in_bits)
+ 
+-def prec_dec_to_bits(unsigned long prec_in_dec):
++def prec_dec_to_bits(long prec_in_dec):
+     r"""
+     Convert from precision expressed in decimal to precision expressed
+     in bits.
+@@ -273,20 +319,20 @@
+ 
+         sage: from sage.libs.pari.pari_instance import prec_dec_to_bits
+         sage: prec_dec_to_bits(15)
+-        49
++        50
+         sage: [(n, prec_dec_to_bits(n)) for n in range(10, 100, 10)]
+-        [(10, 33),
+-        (20, 66),
+-        (30, 99),
+-        (40, 132),
+-        (50, 166),
+-        (60, 199),
+-        (70, 232),
+-        (80, 265),
+-        (90, 298)]
++        [(10, 34),
++        (20, 67),
++        (30, 100),
++        (40, 133),
++        (50, 167),
++        (60, 200),
++        (70, 233),
++        (80, 266),
++        (90, 299)]
+     """
+     cdef double log_10 = 3.32192809488736
+-    return int(prec_in_dec*log_10)
++    return int(prec_in_dec*log_10 + 1.0)  # Add one to round up
+ 
+ cpdef long prec_bits_to_words(unsigned long prec_in_bits):
+     r"""
+@@ -392,6 +438,7 @@
+ pari = pari_instance
+ 
+ 
++
+ # Callbacks from PARI to print stuff using sys.stdout.write() instead
+ # of C library functions like puts().
+ cdef PariOUT sage_pariOut
+@@ -430,6 +477,8 @@
+         -  ``maxprime`` -- unsigned long, upper limit on a
+            precomputed prime number table (default: 500000)
+ 
++        For more information about how precision works in the PARI
++        interface, see :mod:`sage.libs.pari.pari_instance`.
+ 
+         .. note::
+ 
+@@ -440,9 +489,7 @@
+            Python/PARI object is computed, it it copied to its own
+            space in the Python heap, and the memory it occupied on the
+            PARI stack is freed. Thus it is not necessary to make the
+-           stack very large. Also, unlike in PARI, if the stack does
+-           overflow, in most cases the PARI stack is automatically
+-           increased and the relevant step of the computation rerun.
++           stack very large.
+ 
+            This design obviously involves some performance penalties
+            over the way PARI works, but it scales much better and is
+@@ -508,12 +555,8 @@
+         pariOut.puts = sage_puts
+         pariOut.flush = sage_flush
+ 
+-        # Use 15 decimal digits as default precision
+-        self.set_real_precision(15)
+-
+-        # Init global prec variable with the precision in words
+-        global prec
+-        prec = prec_bits_to_words(64)
++        # Use 53 bits as default precision
++        self.set_real_precision_bits(53)
+ 
+         # Disable pretty-printing
+         GP_DATA.fmt.prettyp = 0
+@@ -596,6 +639,59 @@
+         """
+         return int(self.default('debug'))
+ 
++    def set_real_precision_bits(self, n):
++        """
++        Sets the PARI default real precision in bits.
++
++        This is used both for creation of new objects from strings and
++        for printing. It determines the number of digits in which real
++        numbers numbers are printed. It also determines the precision
++        of objects created by parsing strings (e.g. pari('1.2')), which
++        is *not* the normal way of creating new pari objects in Sage.
++        It has *no* effect on the precision of computations within the
++        PARI library.
++
++        .. seealso:: :meth:`set_real_precision` to set the
++           precision in decimal digits.
++
++        EXAMPLES::
++
++            sage: pari.set_real_precision_bits(200)
++            sage: pari('1.2')
++            1.20000000000000000000000000000000000000000000000000000000000
++            sage: pari.set_real_precision_bits(53)
++        """
++        cdef bytes strn = str(n).encode("ascii")
++        sig_on()
++        sd_realbitprecision(strn, d_SILENT)
++        sig_off()
++
++    def get_real_precision_bits(self):
++        """
++        Return the current PARI default real precision in bits.
++
++        This is used both for creation of new objects from strings and
++        for printing. It determines the number of digits in which real
++        numbers numbers are printed. It also determines the precision
++        of objects created by parsing strings (e.g. pari('1.2')), which
++        is *not* the normal way of creating new pari objects in Sage.
++        It has *no* effect on the precision of computations within the
++        PARI library.
++
++        .. seealso:: :meth:`get_real_precision` to get the
++           precision in decimal digits.
++
++        EXAMPLES::
++
++            sage: pari.get_real_precision_bits()
++            53
++        """
++        cdef long r
++        sig_on()
++        r = itos(sd_realbitprecision(NULL, d_RETURN))
++        sig_off()
++        return r
++
+     def set_real_precision(self, long n):
+         """
+         Sets the PARI default real precision in decimal digits.
+@@ -609,6 +705,9 @@
+ 
+         Returns the previous PARI real precision.
+ 
++        .. seealso:: :meth:`set_real_precision_bits` to set the
++           precision in bits.
++
+         EXAMPLES::
+ 
+             sage: pari.set_real_precision(60)
+@@ -618,13 +717,9 @@
+             sage: pari.set_real_precision(15)
+             60
+         """
+-        prev = self._real_precision
+-        cdef bytes strn = str(n)
+-        sig_on()
+-        sd_realprecision(strn, d_SILENT)
+-        sig_off()
+-        self._real_precision = n
+-        return prev
++        old = self.get_real_precision()
++        self.set_real_precision_bits(prec_dec_to_bits(n))
++        return old
+ 
+     def get_real_precision(self):
+         """
+@@ -637,12 +732,19 @@
+         normal way of creating new pari objects in Sage. It has *no*
+         effect on the precision of computations within the pari library.
+ 
++        .. seealso:: :meth:`get_real_precision_bits` to get the
++           precision in bits.
++
+         EXAMPLES::
+ 
+             sage: pari.get_real_precision()
+             15
+         """
+-        return self._real_precision
++        cdef long r
++        sig_on()
++        r = itos(sd_realprecision(NULL, d_RETURN))
++        sig_off()
++        return r
+ 
+     def set_series_precision(self, long n):
+         global precdl
+--- a/sage/src/sage/libs/pari/tests.py
++++ b/sage/src/sage/libs/pari/tests.py
+@@ -1457,7 +1457,7 @@
+     sage: x = pari('[1, -1, 2]~')
+     sage: y = pari('[1, -1, 3]~')
+     sage: nf.idealcoprime(x, y)
+-    [1, 0, 0]~
++    1
+ 
+     sage: y = pari('[2, -2, 4]~')
+     sage: nf.idealcoprime(x, y)
+@@ -1489,7 +1489,7 @@
+     sage: nf = F._pari_()
+     sage: I = pari('[1, -1, 2]~')
+     sage: nf.idealstar(I)
+-    [[[43, 9, 5; 0, 1, 0; 0, 0, 1], [0]], [42, [42]], Mat([[43, [9, 1, 0]~, 1, 1, [-5, 2, -18; -9, -5, 2; 1, -9, -5]], 1]), [[[[42], [3], [3], [Vecsmall([])], 1]], [[], [], []]], Mat(1)]
++    [[[43, 9, 5; 0, 1, 0; 0, 0, 1], [0]], [42, [42]], Mat([[43, [9, 1, 0]~, 1, 1, [-5, 2, -18; -9, -5, 2; 1, -9, -5]], 1]), [[[[[42], [3], [3], [Vecsmall([])], 1, [43, 9, 5; 0, 1, 0; 0, 0, 1]]]], [[], [], [], Vecsmall([])], Vecsmall([0])], Mat(1)]
+ 
+     sage: x = polygen(QQ)
+     sage: K.<a> = NumberField(x^3 - 17)
+@@ -1520,7 +1520,7 @@
+ 
+     sage: x = QQ['x'].0; nf = pari(x^2 + 2).nfinit()
+     sage: nf.nfgaloisconj()
+-    [-x, x]~
++    [x, -x]~
+     sage: nf = pari(x^3 + 2).nfinit()
+     sage: nf.nfgaloisconj()
+     [x]~
+--- a/sage/src/sage/modular/cusps_nf.py
++++ b/sage/src/sage/modular/cusps_nf.py
+@@ -142,19 +142,17 @@
+         sage: N = k.ideal(713, a + 208)
+         sage: L = list_of_representatives(N); L
+         (Fractional ideal (1),
+-        Fractional ideal (37, a + 12),
+-        Fractional ideal (47, a - 9))
++         Fractional ideal (47, a - 9),
++         Fractional ideal (53, a - 16))
+ 
+-    The output of ``list_of_representatives`` has been cached:
+-
+-    ::
++    The output of ``list_of_representatives`` has been cached::
+ 
+         sage: sage.modular.cusps_nf._list_reprs_cache.keys()
+         [Fractional ideal (713, a + 208)]
+         sage: sage.modular.cusps_nf._list_reprs_cache[N]
+         (Fractional ideal (1),
+-        Fractional ideal (37, a + 12),
+-        Fractional ideal (47, a - 9))
++         Fractional ideal (47, a - 9),
++         Fractional ideal (53, a - 16))
+     """
+     if N in _list_reprs_cache:
+         lreps = _list_reprs_cache[N]
+@@ -1255,9 +1253,9 @@
+         sage: from sage.modular.cusps_nf import NFCusps_ideal_reps_for_levelN
+         sage: NFCusps_ideal_reps_for_levelN(N)
+         [(Fractional ideal (1),
+-          Fractional ideal (13, a - 2),
+-          Fractional ideal (43, a - 1),
+-          Fractional ideal (67, a + 17))]
++          Fractional ideal (67, a + 17),
++          Fractional ideal (127, a + 48),
++          Fractional ideal (157, a - 19))]
+         sage: L = NFCusps_ideal_reps_for_levelN(N, 5)
+         sage: all([len(L[i])==k.class_number() for i in range(len(L))])
+         True
+--- a/sage/src/sage/rings/number_field/bdd_height.py
++++ b/sage/src/sage/rings/number_field/bdd_height.py
+@@ -71,7 +71,7 @@
+         sage: bdd_pr_ideals[4]
+         [2]
+         sage: bdd_pr_ideals[5]
+-        [g + 2, g - 2]
++        [-g - 2, -g + 2]
+         sage: bdd_pr_ideals[7]
+         []
+ 
+--- a/sage/src/sage/rings/number_field/class_group.py
++++ b/sage/src/sage/rings/number_field/class_group.py
+@@ -470,7 +470,7 @@
+             sage: CK = K.class_group()
+             sage: CL = L.class_group()
+             sage: [CL(I).exponents() for I in CK]
+-            [(0,), (2,), (4,)]
++            [(0,), (4,), (2,)]
+         """
+         if isinstance(args[0], FractionalIdealClass):
+             return self.element_class(self, None, self._number_field.ideal(args[0].ideal()))
+--- a/sage/src/sage/rings/number_field/number_field.py
++++ b/sage/src/sage/rings/number_field/number_field.py
+@@ -3868,7 +3868,7 @@
+             sage: K.unit_group()
+             Unit group with structure C6 of Number Field in a with defining polynomial x^2 + 3
+             sage: K.S_units([])
+-            [-1/2*a + 1/2]
++            [1/2*a + 1/2]
+             sage: K.S_units([])[0].multiplicative_order()
+             6
+ 
+@@ -3939,14 +3939,13 @@
+ 
+             sage: K.<a> = NumberField(x^3 - 381 * x + 127)
+             sage: K._S_class_group_and_units(tuple(K.primes_above(13)))
+-            ([-7/13*a^2 - 140/13*a + 36/13,
+-              14/13*a^2 + 267/13*a - 85/13,
+-              7/13*a^2 + 127/13*a - 49/13,
++            ([2/13*a^2 + 1/13*a - 677/13,
++              1/13*a^2 + 7/13*a - 332/13,
++              -1/13*a^2 + 6/13*a + 345/13,
+               -1,
+-              1/13*a^2 - 19/13*a + 6/13,
++              2/13*a^2 + 1/13*a - 755/13,
+               1/13*a^2 - 19/13*a - 7/13],
+-             [(Fractional ideal (11, a - 2), 2),
+-              (Fractional ideal (19, 1/13*a^2 - 45/13*a - 332/13), 2)])
++             [(Fractional ideal (11, a - 2), 2), (Fractional ideal (19, a + 7), 2)])
+ 
+         Number fields defined by non-monic and non-integral
+         polynomials are supported (:trac:`252`)::
+@@ -4065,13 +4064,13 @@
+             sage: K.selmer_group([P2], 2)
+             [2, -1]
+             sage: K.selmer_group((P2,P3), 4)
+-            [2, a + 1, -1]
++            [2, -a - 1, -1]
+             sage: K.selmer_group((P2,P3), 4, orders=True)
+-            ([2, a + 1, -1], [4, 4, 2])
++            ([2, -a - 1, -1], [4, 4, 2])
+             sage: K.selmer_group([P2], 3)
+             [2]
+             sage: K.selmer_group([P2, P3], 3)
+-            [2, a + 1]
++            [2, -a - 1]
+             sage: K.selmer_group([P2, P3, K.ideal(a)], 3)  # random signs
+             [2, a + 1, a]
+ 
+@@ -4092,14 +4091,21 @@
+             sage: P3 = K.ideal(3, a+1)
+             sage: P5 = K.ideal(a)
+             sage: S = K.selmer_group([P2, P3, P5], 3)
+-            sage: S == [2, a + 1, a] or S == [2, a + 1, -a]
++            sage: S in ([2, a + 1, a], [2, a + 1, -a], [2, -a - 1, a], [2, -a - 1, -a]) or S
+             True
+ 
+         Verify that :trac:`14489` is fixed::
+ 
+             sage: K.<a> = NumberField(x^3 - 381 * x + 127)
+             sage: K.selmer_group(K.primes_above(13), 2)
+-            [-7/13*a^2 - 140/13*a + 36/13, 14/13*a^2 + 267/13*a - 85/13, 7/13*a^2 + 127/13*a - 49/13, -1, 1/13*a^2 - 19/13*a + 6/13, 1/13*a^2 - 19/13*a - 7/13, 2/13*a^2 + 53/13*a - 92/13, 10/13*a^2 + 44/13*a - 4555/13]
++            [2/13*a^2 + 1/13*a - 677/13,
++             1/13*a^2 + 7/13*a - 332/13,
++             -1/13*a^2 + 6/13*a + 345/13,
++             -1,
++             2/13*a^2 + 1/13*a - 755/13,
++             1/13*a^2 - 19/13*a - 7/13,
++             2/13*a^2 + 53/13*a - 92/13,
++             2/13*a^2 + 40/13*a - 27/13]
+ 
+         Verify that :trac:`16708` is fixed::
+ 
+@@ -4181,7 +4187,7 @@
+             sage: list(K.selmer_group_iterator([K.ideal(2, -a+1)], 2))
+             [1, -1, 2, -2]
+             sage: list(K.selmer_group_iterator([K.ideal(2, -a+1), K.ideal(3, a+1)], 2))
+-            [1, -1, a + 1, -a - 1, 2, -2, 2*a + 2, -2*a - 2]
++            [1, -1, -a - 1, a + 1, 2, -2, -2*a - 2, 2*a + 2]
+ 
+         Examples over `\QQ` (as a number field)::
+ 
+@@ -4709,7 +4715,7 @@
+             sage: K.elements_of_norm(3)
+             []
+             sage: K.elements_of_norm(50)
+-            [-7*a + 1, -5*a - 5, 7*a + 1]
++            [-7*a + 1, 5*a - 5, 7*a + 1]
+ 
+         TESTS:
+ 
+@@ -5890,7 +5896,7 @@
+             sage: A = x^4 - 10*x^3 + 20*5*x^2 - 15*5^2*x + 11*5^3
+             sage: K = NumberField(A, 'a')
+             sage: K.units()
+-            (7/275*a^3 - 1/11*a^2 + 9/11*a + 2,)
++            (1/275*a^3 + 4/55*a^2 - 5/11*a + 3,)
+ 
+         For big number fields, provably computing the unit group can
+         take a very long time.  In this case, one can ask for the
+@@ -5976,7 +5982,7 @@
+             sage: U.gens()
+             (u0, u1)
+             sage: U.gens_values()
+-            [-7/275*a^3 + 1/11*a^2 - 9/11*a - 1, 7/275*a^3 - 1/11*a^2 + 9/11*a + 2]
++            [-1/275*a^3 + 7/55*a^2 - 6/11*a + 4, 1/275*a^3 + 4/55*a^2 - 5/11*a + 3]
+             sage: U.invariants()
+             (10, 0)
+             sage: [u.multiplicative_order() for u in U.gens()]
+@@ -6046,7 +6052,7 @@
+             sage: U.gens()
+             (u0, u1, u2, u3)
+             sage: U.gens_values()
+-            [-7/275*a^3 + 1/11*a^2 - 9/11*a - 1, 7/275*a^3 - 1/11*a^2 + 9/11*a + 2, 1/275*a^3 + 4/55*a^2 - 5/11*a + 5, -14/275*a^3 + 21/55*a^2 - 29/11*a + 6]
++            [-1/275*a^3 + 7/55*a^2 - 6/11*a + 4, 1/275*a^3 + 4/55*a^2 - 5/11*a + 3, 1/275*a^3 + 4/55*a^2 - 5/11*a + 5, -14/275*a^3 + 21/55*a^2 - 29/11*a + 6]
+             sage: U.invariants()
+             (10, 0, 0, 0)
+             sage: [u.multiplicative_order() for u in U.gens()]
+@@ -6345,10 +6351,10 @@
+ 
+             sage: K.<f> = QuadraticField(-3)
+             sage: K.primitive_root_of_unity()
+-            -1/2*f + 1/2
++            1/2*f + 1/2
+             sage: UK = K.unit_group()
+             sage: K.primitive_root_of_unity()
+-            -1/2*f + 1/2
++            1/2*f + 1/2
+ 
+         Number fields defined by non-monic and non-integral
+         polynomials are supported (:trac:`252`)::
+--- a/sage/src/sage/rings/number_field/number_field_element.pyx
++++ b/sage/src/sage/rings/number_field/number_field_element.pyx
+@@ -1610,7 +1610,7 @@
+             sage: t[0].norm(K)
+             -a
+             sage: t = K(3)._rnfisnorm(L); t
+-            ((a^2 + 1)*b^3 - b^2 - a*b - a^2, -3*a^2 + 3*a - 3)
++            (-b^3 - a*b^2 - a^2*b + 1, 3*a^2 - 3*a + 6)
+             sage: t[0].norm(K)*t[1]
+             3
+ 
+--- a/sage/src/sage/rings/number_field/number_field_ideal_rel.py
++++ b/sage/src/sage/rings/number_field/number_field_ideal_rel.py
+@@ -506,7 +506,7 @@
+             sage: K.<c> = F.extension(Y^2 - (1 + a)*(a + b)*a*b)
+             sage: I = K.ideal(3, c)
+             sage: J = I.ideal_below(); J
+-            Fractional ideal (b)
++            Fractional ideal (-b)
+             sage: J.number_field() == F
+             True
+ 
+@@ -535,12 +535,12 @@
+ 
+             sage: K.<a, b> = QQ.extension([x^2 + 11, x^2 - 5])
+             sage: K.factor(5)
+-            (Fractional ideal (5, (1/4*b - 1/4)*a - 1/4*b - 3/4))^2 * (Fractional ideal (5, (1/4*b - 1/4)*a - 1/4*b - 7/4))^2
++            (Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 3/4))^2 * (Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 7/4))^2
+             sage: K.ideal(5).factor()
+-            (Fractional ideal (5, (1/4*b - 1/4)*a - 1/4*b - 3/4))^2 * (Fractional ideal (5, (1/4*b - 1/4)*a - 1/4*b - 7/4))^2
++            (Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 3/4))^2 * (Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 7/4))^2
+             sage: K.ideal(5).prime_factors()
+-            [Fractional ideal (5, (1/4*b - 1/4)*a - 1/4*b - 3/4),
+-             Fractional ideal (5, (1/4*b - 1/4)*a - 1/4*b - 7/4)]
++            [Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 3/4),
++             Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 7/4)]
+ 
+             sage: PQ.<X> = QQ[]
+             sage: F.<a, b> = NumberFieldTower([X^2 - 2, X^2 - 3])
+--- a/sage/src/sage/rings/number_field/number_field_rel.py
++++ b/sage/src/sage/rings/number_field/number_field_rel.py
+@@ -1769,7 +1769,7 @@
+ 
+             sage: K.<a, b> = NumberField( [x^2 + x + 1, x^4 + 1] )
+             sage: K.roots_of_unity()[:5]
+-            [b*a, -b^2*a - b^2, b^3, -a, b*a + b]
++            [b*a + b, b^2*a, -b^3, a + 1, b*a]
+         """
+         abs = self.absolute_field('a')
+         from_abs, _ = abs.structure()
+--- a/sage/src/sage/rings/number_field/unit_group.py
++++ b/sage/src/sage/rings/number_field/unit_group.py
+@@ -15,12 +15,12 @@
+     sage: UK.gens_values()  # random
+     [-1/12*a^3 + 1/6*a, 1/24*a^3 + 1/4*a^2 - 1/12*a - 1]
+     sage: UK.gen(0).value()
+-    -1/12*a^3 + 1/6*a
++    1/12*a^3 - 1/6*a
+ 
+     sage: UK.gen(0)
+     u0
+     sage: UK.gen(0) + K.one()   # coerce abstract generator into number field
+-    -1/12*a^3 + 1/6*a + 1
++    1/12*a^3 - 1/6*a + 1
+ 
+     sage: [u.multiplicative_order() for u in UK.gens()]
+     [4, +Infinity]
+@@ -37,18 +37,18 @@
+     sage: UK(-1)
+     u0^2
+     sage: [UK(u) for u in (x^4-1).roots(K,multiplicities=False)]
+-    [1, u0^2, u0^3, u0]
++    [1, u0^2, u0, u0^3]
+ 
+     sage: UK.fundamental_units() # random
+     [1/24*a^3 + 1/4*a^2 - 1/12*a - 1]
+     sage: torsion_gen = UK.torsion_generator();  torsion_gen
+     u0
+     sage: torsion_gen.value()
+-    -1/12*a^3 + 1/6*a
++    1/12*a^3 - 1/6*a
+     sage: UK.zeta_order()
+     4
+     sage: UK.roots_of_unity()
+-    [-1/12*a^3 + 1/6*a, -1, 1/12*a^3 - 1/6*a, 1]
++    [1/12*a^3 - 1/6*a, -1, -1/12*a^3 + 1/6*a, 1]
+ 
+ Exp and log functions provide maps between units as field elements and exponent
+ vectors with respect to the generators::
+@@ -100,7 +100,30 @@
+     sage: UL.zeta_order()
+     24
+     sage: UL.roots_of_unity()
+-    [b*a, -b^2*a - b^2, b^3, -a, b*a + b, -b^2, -b^3*a, -a - 1, b, b^2*a, -b^3*a - b^3, -1, -b*a, b^2*a + b^2, -b^3, a, -b*a - b, b^2, b^3*a, a + 1, -b, -b^2*a, b^3*a + b^3, 1]
++    [-b*a,
++     -b^2*a - b^2,
++     -b^3,
++     -a,
++     -b*a - b,
++     -b^2,
++     b^3*a,
++     -a - 1,
++     -b,
++     b^2*a,
++     b^3*a + b^3,
++     -1,
++     b*a,
++     b^2*a + b^2,
++     b^3,
++     a,
++     b*a + b,
++     b^2,
++     -b^3*a,
++     a + 1,
++     b,
++     -b^2*a,
++     -b^3*a - b^3,
++     1]
+ 
+ A relative extension example, which worked thanks to the code review by F.W.Clarke::
+ 
+@@ -229,7 +252,7 @@
+             sage: UK.gens()
+             (u,)
+             sage: UK.gens_values()
+-            [-1/2*a + 1/2]
++            [1/2*a + 1/2]
+ 
+             sage: K.<z> = CyclotomicField(13)
+             sage: UK = K.unit_group(); UK
+--- a/sage/src/sage/rings/polynomial/polynomial_quotient_ring.py
++++ b/sage/src/sage/rings/polynomial/polynomial_quotient_ring.py
+@@ -1081,7 +1081,21 @@
+             sage: R.<x> = K[]
+             sage: S.<xbar> = R.quotient((x^2 + 23)*(x^2 + 31))
+             sage: S.S_class_group([])
+-            [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, -1/16*a*xbar^3 + (1/16*a + 1/8)*xbar^2 - 31/16*a*xbar + 31/16*a + 31/8), 6), ((-1/4*xbar^2 - 23/4, (1/8*a - 1/8)*xbar^2 + 23/8*a - 23/8, -1/16*xbar^3 - 1/16*xbar^2 - 23/16*xbar - 23/16, 1/16*a*xbar^3 + (-1/16*a - 1/8)*xbar^2 + 23/16*a*xbar - 23/16*a - 23/8), 6), ((-5/4*xbar^2 - 115/4, 5/4*a*xbar^2 + 115/4*a, -5/16*xbar^3 + 5/16*xbar^2 - 115/16*xbar + 115/16, 1/16*a*xb [...]
++            [((1/4*xbar^2 + 31/4,
++               (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8,
++               1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16,
++               -1/16*a*xbar^3 + (1/16*a + 1/8)*xbar^2 - 31/16*a*xbar + 31/16*a + 31/8),
++              6),
++             ((-1/4*xbar^2 - 23/4,
++               (1/8*a - 1/8)*xbar^2 + 23/8*a - 23/8,
++               -1/16*xbar^3 - 1/16*xbar^2 - 23/16*xbar - 23/16,
++               1/16*a*xbar^3 + (-1/16*a - 1/8)*xbar^2 + 23/16*a*xbar - 23/16*a - 23/8),
++              6),
++             ((-5/4*xbar^2 - 115/4,
++               1/4*a*xbar^2 + 23/4*a,
++               -1/16*xbar^3 - 7/16*xbar^2 - 23/16*xbar - 161/16,
++               1/16*a*xbar^3 - 1/16*a*xbar^2 + 23/16*a*xbar - 23/16*a),
++              2)]
+ 
+         By using the ideal `(a)`, we cut the part of the class group coming from
+         `x^2 + 31` from 12 to 2, i.e. we lose a generator of order 6 (this was
+@@ -1200,7 +1214,21 @@
+             sage: R.<x> = K[]
+             sage: S.<xbar> = R.quotient((x^2 + 23)*(x^2 + 31))
+             sage: S.class_group()
+-            [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, -1/16*a*xbar^3 + (1/16*a + 1/8)*xbar^2 - 31/16*a*xbar + 31/16*a + 31/8), 6), ((-1/4*xbar^2 - 23/4, (1/8*a - 1/8)*xbar^2 + 23/8*a - 23/8, -1/16*xbar^3 - 1/16*xbar^2 - 23/16*xbar - 23/16, 1/16*a*xbar^3 + (-1/16*a - 1/8)*xbar^2 + 23/16*a*xbar - 23/16*a - 23/8), 6), ((-5/4*xbar^2 - 115/4, 5/4*a*xbar^2 + 115/4*a, -5/16*xbar^3 + 5/16*xbar^2 - 115/16*xbar + 115/16, 1/16*a*xb [...]
++            [((1/4*xbar^2 + 31/4,
++               (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8,
++               1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16,
++               -1/16*a*xbar^3 + (1/16*a + 1/8)*xbar^2 - 31/16*a*xbar + 31/16*a + 31/8),
++              6),
++             ((-1/4*xbar^2 - 23/4,
++               (1/8*a - 1/8)*xbar^2 + 23/8*a - 23/8,
++               -1/16*xbar^3 - 1/16*xbar^2 - 23/16*xbar - 23/16,
++               1/16*a*xbar^3 + (-1/16*a - 1/8)*xbar^2 + 23/16*a*xbar - 23/16*a - 23/8),
++              6),
++             ((-5/4*xbar^2 - 115/4,
++               1/4*a*xbar^2 + 23/4*a,
++               -1/16*xbar^3 - 7/16*xbar^2 - 23/16*xbar - 161/16,
++               1/16*a*xbar^3 - 1/16*a*xbar^2 + 23/16*a*xbar - 23/16*a),
++              2)]
+ 
+         Note that all the returned values live where we expect them to::
+ 
+@@ -1238,13 +1266,13 @@
+             Unit group with structure C6 of Number Field in a with defining polynomial x^2 + 3
+             sage: K.<a> = QQ['x'].quotient(x^2 + 3)
+             sage: u,o = K.S_units([])[0]; u, o
+-            (-1/2*a + 1/2, 6)
++            (1/2*a + 1/2, 6)
+             sage: u^6
+             1
+             sage: u^3
+             -1
+             sage: u^2
+-            -1/2*a - 1/2
++            1/2*a - 1/2
+ 
+         ::
+ 
+@@ -1253,11 +1281,21 @@
+             sage: L.<b> = K['y'].quotient(y^3 + 5); L
+             Univariate Quotient Polynomial Ring in b over Number Field in a with defining polynomial x^2 + 3 with modulus y^3 + 5
+             sage: L.S_units([])
+-            [(-1/2*a + 1/2, 6), ((1/3*a - 1)*b^2 + 4/3*a*b + 5/6*a + 7/2, +Infinity), ((-1/3*a + 1)*b^2 + (2/3*a - 2)*b - 5/6*a + 7/2, +Infinity)]
++            [(1/2*a + 1/2, 6),
++             ((-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, +Infinity),
++             (2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2, +Infinity)]
+             sage: L.S_units([K.ideal(1/2*a - 3/2)])
+-            [((-1/6*a - 1/2)*b^2 + (1/3*a - 1)*b + 4/3*a, +Infinity), (-1/2*a + 1/2, 6), ((1/3*a - 1)*b^2 + 4/3*a*b + 5/6*a + 7/2, +Infinity), ((-1/3*a + 1)*b^2 + (2/3*a - 2)*b - 5/6*a + 7/2, +Infinity)]
++            [((-1/6*a - 1/2)*b^2 + (1/3*a - 1)*b + 4/3*a, +Infinity),
++             (1/2*a + 1/2, 6),
++             ((-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, +Infinity),
++             (2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2, +Infinity)]
+             sage: L.S_units([K.ideal(2)])
+-            [((-1/2*a + 1/2)*b^2 + (-a - 1)*b - 3, +Infinity), ((-1/6*a - 1/2)*b^2 + (1/3*a - 1)*b + 5/6*a - 1/2, +Infinity), ((1/6*a + 1/2)*b^2 + (-1/3*a + 1)*b - 5/6*a - 1/2, +Infinity), (-1/2*a + 1/2, 6), ((1/3*a - 1)*b^2 + 4/3*a*b + 5/6*a + 7/2, +Infinity), ((-1/3*a + 1)*b^2 + (2/3*a - 2)*b - 5/6*a + 7/2, +Infinity)]
++            [((1/2*a - 1/2)*b^2 + (a + 1)*b + 3, +Infinity),
++             ((1/6*a + 1/2)*b^2 + (-1/3*a + 1)*b - 5/6*a + 1/2, +Infinity),
++             ((1/6*a + 1/2)*b^2 + (-1/3*a + 1)*b - 5/6*a - 1/2, +Infinity),
++             (1/2*a + 1/2, 6),
++             ((-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, +Infinity),
++             (2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2, +Infinity)]
+ 
+         Note that all the returned values live where we expect them to::
+ 
+@@ -1315,13 +1353,13 @@
+             Unit group with structure C6 of Number Field in a with defining polynomial x^2 + 3
+             sage: K.<a> = QQ['x'].quotient(x^2 + 3)
+             sage: u = K.units()[0][0]; u
+-            -1/2*a + 1/2
++            1/2*a + 1/2
+             sage: u^6
+             1
+             sage: u^3
+             -1
+             sage: u^2
+-            -1/2*a - 1/2
++            1/2*a - 1/2
+             sage: K.<a> = QQ['x'].quotient(x^2 + 5)
+             sage: K.units(())
+             [(-1, 2)]
+@@ -1333,14 +1371,16 @@
+             sage: L.<b> = K['y'].quotient(y^3 + 5); L
+             Univariate Quotient Polynomial Ring in b over Number Field in a with defining polynomial x^2 + 3 with modulus y^3 + 5
+             sage: L.units()
+-            [(-1/2*a + 1/2, 6), ((1/3*a - 1)*b^2 + 4/3*a*b + 5/6*a + 7/2, +Infinity), ((-1/3*a + 1)*b^2 + (2/3*a - 2)*b - 5/6*a + 7/2, +Infinity)]
++            [(1/2*a + 1/2, 6),
++             ((-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, +Infinity),
++             (2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2, +Infinity)]
+             sage: L.<b> = K.extension(y^3 + 5)
+             sage: L.unit_group()
+             Unit group with structure C6 x Z x Z of Number Field in b with defining polynomial x^3 + 5 over its base field
+             sage: L.unit_group().gens()    # abstract generators
+             (u0, u1, u2)
+             sage: L.unit_group().gens_values()
+-            [-1/2*a + 1/2, (1/3*a - 1)*b^2 + 4/3*a*b + 5/6*a + 7/2, (-1/3*a + 1)*b^2 + (2/3*a - 2)*b - 5/6*a + 7/2]
++            [1/2*a + 1/2, (-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, 2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2]
+ 
+         Note that all the returned values live where we expect them to::
+ 
+@@ -1387,15 +1427,15 @@
+             sage: D.selmer_group([K.ideal(2, -a+1)], 2)
+             [2, -1]
+             sage: D.selmer_group([K.ideal(2, -a+1), K.ideal(3, a+1)], 2)
+-            [2, -a - 1, -1]
++            [2, a + 1, -1]
+             sage: D.selmer_group((K.ideal(2, -a+1),K.ideal(3, a+1)), 4)
+-            [2, -a - 1, -1]
++            [2, a + 1, -1]
+             sage: D.selmer_group([K.ideal(2, -a+1)], 3)
+             [2]
+             sage: D.selmer_group([K.ideal(2, -a+1), K.ideal(3, a+1)], 3)
+-            [2, -a - 1]
++            [2, a + 1]
+             sage: D.selmer_group([K.ideal(2, -a+1), K.ideal(3, a+1), K.ideal(a)], 3)
+-            [2, -a - 1, a]
++            [2, a + 1, a]
+ 
+         """
+         fields, isos, iso_classes = self._S_decomposition(tuple(S))
+--- a/sage/src/sage/schemes/elliptic_curves/ell_number_field.py
++++ b/sage/src/sage/schemes/elliptic_curves/ell_number_field.py
+@@ -246,21 +246,19 @@
+               C = Mod(y, y^2 + 7)
+             <BLANKLINE>
+               Computing L(S,2)
+-              L(S,2) = [Mod(Mod(-1, y^2 + 7)*x^2 + Mod(-1/2*y + 1/2, y^2 + 7)*x + 1, x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7)), Mod(Mod(-1, y^2 + 7)*x^2 + Mod(-1/2*y - 1/2, y^2 + 7)*x + 1, x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7)), Mod(-1, x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7)), Mod(x^2 + 2, x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7)), Mod(Mod(1, y^2 + 7)*x + Mod(1/2*y + 3/2, y^2 + 7), x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7)), Mod(Mod(1, y^2 + 7)*x + Mod(1/2*y - 3/2, y^2 + 7), x^ [...]
++              L(S,2) = [Mod(Mod(-1/2*y + 1/2, y^2 + 7)*x^2 + Mod(-1/2*y - 1/2, y^2 + 7)*x + Mod(-y - 1, y^2 + 7), x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7)), Mod(Mod(-1, y^2 + 7)*x^2 + Mod(-1/2*y - 1/2, y^2 + 7)*x + 1, x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7)), Mod(-1, x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7)), Mod(x^2 + 2, x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7)), Mod(Mod(1, y^2 + 7)*x + Mod(1/2*y + 3/2, y^2 + 7), x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7)), Mod(Mod(1, y^2 + 7)*x +  [...]
+             <BLANKLINE>
+               Computing the Selmer group
+               #LS2gen = 2
+-               LS2gen = [Mod(Mod(-5, y^2 + 7)*x^2 + Mod(-3*y, y^2 + 7)*x + Mod(8, y^2 + 7), x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7)), Mod(Mod(1, y^2 + 7)*x^2 + Mod(1/2*y - 1/2, y^2 + 7)*x - 1, x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7))]
++               LS2gen = [Mod(Mod(-1/2*y + 1/2, y^2 + 7)*x^2 + Mod(-1/2*y - 1/2, y^2 + 7)*x + Mod(-y - 1, y^2 + 7), x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7)), Mod(Mod(1, y^2 + 7)*x^2 + Mod(1/2*y + 1/2, y^2 + 7)*x - 1, x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7))]
+               Search for trivial points on the curve
+              Trivial points on the curve = [[Mod(1/2*y + 3/2, y^2 + 7), Mod(-y - 2, y^2 + 7)], [1, 1, 0], [Mod(1/2*y + 3/2, y^2 + 7), Mod(-y - 2, y^2 + 7), 1]]
+-              zc = Mod(Mod(-5, y^2 + 7)*x^2 + Mod(-3*y, y^2 + 7)*x + Mod(8, y^2 + 7), x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7))
+-              Hilbert symbol (Mod(2, y^2 + 7),Mod(-5, y^2 + 7)) =
+-              zc = Mod(Mod(1, y^2 + 7)*x^2 + Mod(1/2*y - 1/2, y^2 + 7)*x + Mod(-1, y^2 + 7), x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7))
+-              Hilbert symbol (Mod(-2*y + 2, y^2 + 7),Mod(1, y^2 + 7)) =
+-              sol of quadratic equation = [1, 0, 1]~
+-              zc*z1^2 = Mod(Mod(2*y - 2, y^2 + 7)*x + Mod(2*y + 10, y^2 + 7), x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7))
+-              quartic: (-1/2*y + 1/2)*Y^2 = x^4 + (-3*y - 15)*x^2 + (-8*y - 16)*x + (-11/2*y - 15/2)
+-              reduced: Y^2 = (-1/2*y + 1/2)*x^4 - 4*x^3 + (-3*y + 3)*x^2 + (2*y - 2)*x + (1/2*y + 3/2)
++              zc = Mod(Mod(-1/2*y + 1/2, y^2 + 7)*x^2 + Mod(-1/2*y - 1/2, y^2 + 7)*x + Mod(-y - 1, y^2 + 7), x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7))
++              Hilbert symbol (Mod(1, y^2 + 7),Mod(-2*y + 2, y^2 + 7)) =
++              sol of quadratic equation = [1, 1, 0]~
++              zc*z1^2 = Mod(Mod(4, y^2 + 7)*x + Mod(-2*y + 6, y^2 + 7), x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7))
++              quartic: (-1)*Y^2 = x^4 + (3*y - 9)*x^2 + (-8*y + 16)*x + (9/2*y - 11/2)
++              reduced: Y^2 = -x^4 + (-3*y + 9)*x^2 + (-8*y + 16)*x + (-9/2*y + 11/2)
+               not ELS at [2, [0, 1]~, 1, 1, [1, -2; 1, 0]]
+               zc = Mod(Mod(1, y^2 + 7)*x^2 + Mod(1/2*y + 1/2, y^2 + 7)*x + Mod(-1, y^2 + 7), x^3 + Mod(1, y^2 + 7)*x + Mod(y, y^2 + 7))
+               comes from the trivial point [Mod(1/2*y + 3/2, y^2 + 7), Mod(-y - 2, y^2 + 7)]
+@@ -300,7 +298,10 @@
+             sage: K = CyclotomicField(43).subfields(3)[0][0]
+             sage: E = EllipticCurve(K, '37')
+             sage: E.simon_two_descent()  # long time (4s on sage.math, 2013)
+-            (3, 3, [(0 : 0 : 1), (-1/4*zeta43_0^2 - 1/2*zeta43_0 + 3 : -3/8*zeta43_0^2 - 3/4*zeta43_0 + 4 : 1)])
++            (3,
++             3,
++             [(0 : 0 : 1),
++              (-1/2*zeta43_0^2 - 1/2*zeta43_0 + 7 : -3/2*zeta43_0^2 - 5/2*zeta43_0 + 18 : 1)])
+         """
+         verbose = int(verbose)
+         if known_points is None:
+@@ -2465,8 +2466,9 @@
+             sage: E = EllipticCurve(K, [1, 0, 5*y^2 + 16, 0, 0])
+             sage: E.gens(lim1=1, lim3=1)
+             []
+-            sage: E.rank(), E.gens()  # long time (about 3 s)
+-            (1, [(9/25*y^2 + 26/25 : -229/125*y^3 - 67/25*y^2 - 731/125*y - 213/25 : 1)])
++            sage: E.rank(), E.gens(lim3=12)  # long time (about 4s)
++            (1,
++             [(369/25*y^3 + 539/25*y^2 + 1178/25*y + 1718/25 : -29038/125*y^3 - 43003/125*y^2 - 92706/125*y - 137286/125 : 1)])
+ 
+         Here is a curve of rank 2, yet the list contains many points::
+ 
+--- a/sage/src/sage/schemes/elliptic_curves/ell_rational_field.py
++++ b/sage/src/sage/schemes/elliptic_curves/ell_rational_field.py
+@@ -1805,7 +1805,7 @@
+             sage: E = EllipticCurve('389a1')
+             sage: E._known_points = []  # clear cached points
+             sage: E.simon_two_descent()
+-            (2, 2, [(5/4 : 5/8 : 1), (-3/4 : 7/8 : 1)])
++            (2, 2, [(1 : 0 : 1), (-11/9 : 28/27 : 1)])
+             sage: E = EllipticCurve('5077a1')
+             sage: E.simon_two_descent()
+             (3, 3, [(1 : 0 : 1), (2 : 0 : 1), (0 : 2 : 1)])
+@@ -1829,7 +1829,7 @@
+             (4, 4, [(6 : -1 : 1), (4 : 3 : 1), (5 : -2 : 1), (8 : 7 : 1)])
+             sage: E = EllipticCurve([0, 0, 1, -79, 342])
+             sage: E.simon_two_descent()  # long time (9s on sage.math, 2011)
+-            (5, 5, [(7 : 11 : 1), (-1 : 20 : 1), (0 : 18 : 1), (3 : 11 : 1), (-3 : 23 : 1)])
++            (5, 5, [(5 : 8 : 1), (10 : 23 : 1), (3 : 11 : 1), (-3 : 23 : 1), (0 : 18 : 1)])
+             sage: E = EllipticCurve([1, 1, 0, -2582, 48720])
+             sage: r, s, G = E.simon_two_descent(); r,s
+             (6, 6)
+--- a/sage/src/sage/schemes/elliptic_curves/gp_simon.py
++++ b/sage/src/sage/schemes/elliptic_curves/gp_simon.py
+@@ -57,7 +57,7 @@
+         sage: import sage.schemes.elliptic_curves.gp_simon
+         sage: E=EllipticCurve('389a1')
+         sage: sage.schemes.elliptic_curves.gp_simon.simon_two_descent(E)
+-        (2, 2, [(5/4 : 5/8 : 1), (-3/4 : 7/8 : 1)])
++        (2, 2, [(1 : 0 : 1), (-11/9 : 28/27 : 1)])
+ 
+     TESTS::
+ 
+--- a/sage/src/sage/schemes/elliptic_curves/period_lattice.py
++++ b/sage/src/sage/schemes/elliptic_curves/period_lattice.py
+@@ -1559,7 +1559,7 @@
+ 
+         TESTS:
+ 
+-        (see :trac:`10026` and :trac:`11767`)::
++        See :trac:`10026` and :trac:`11767`::
+ 
+             sage: K.<w> = QuadraticField(2)
+             sage: E = EllipticCurve([ 0, -1, 1, -3*w -4, 3*w + 4 ])
+@@ -1567,7 +1567,7 @@
+             sage: P,Q = T[2]
+             sage: embs = K.embeddings(CC)
+             sage: Lambda = E.period_lattice(embs[0])
+-            sage: Lambda.elliptic_logarithm(P,100)
++            sage: Lambda.elliptic_logarithm(P+3*Q, 100)
+             4.7100131126199672766973600998
+             sage: R.<x> = QQ[]
+             sage: K.<a> = NumberField(x^2 + x + 5)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/sagemath.git



More information about the debian-science-commits mailing list