Ticket #13213: trac_13213-quadratic_field_comparison.patch

File trac_13213-quadratic_field_comparison.patch, 55.1 KB (added by vdelecroix, 6 years ago)
  • doc/de/tutorial/tour_advanced.rst

    # HG changeset patch
    # User Vincent Delecroix <20100.delecroix at gmail.com>
    # Date 1342612563 -32400
    # Node ID 837b06a5a0ecf085e1d6848b4ce2ac04808936f9
    # Parent  75a1095ab5b4f6bcb7c8467bb37256d4b1841ae3
    trac 13213
    Comparisons in quadratic number field
    
    This patch implements comparisons of elements of quadratic number fields
    compatible with their (real or complex) embedding. The main modification
    is in sage/rings/number_field/number_field_element_quadratic.pyx but it
    affects many tests as it modifies some output order.
    
    diff --git a/doc/de/tutorial/tour_advanced.rst b/doc/de/tutorial/tour_advanced.rst
    a b  
    481481    Modular Symbols space of dimension 4 and level 13, weight 2, character
    482482    [zeta6], sign 0, over Cyclotomic Field of order 6 and degree 2
    483483    sage: M.T(2).charpoly('x').factor()
    484     (x - 2*zeta6 - 1) * (x - zeta6 - 2) * (x + zeta6 + 1)^2
     484    (x - zeta6 - 2) * (x - 2*zeta6 - 1) * (x + zeta6 + 1)^2
    485485    sage: S = M.cuspidal_submodule(); S
    486486    Modular Symbols subspace of dimension 2 of Modular Symbols space of
    487487    dimension 4 and level 13, weight 2, character [zeta6], sign 0, over
  • doc/en/tutorial/tour_advanced.rst

    diff --git a/doc/en/tutorial/tour_advanced.rst b/doc/en/tutorial/tour_advanced.rst
    a b  
    478478    Modular Symbols space of dimension 4 and level 13, weight 2, character
    479479    [zeta6], sign 0, over Cyclotomic Field of order 6 and degree 2
    480480    sage: M.T(2).charpoly('x').factor()
    481     (x - 2*zeta6 - 1) * (x - zeta6 - 2) * (x + zeta6 + 1)^2
     481    (x - zeta6 - 2) * (x - 2*zeta6 - 1) * (x + zeta6 + 1)^2
    482482    sage: S = M.cuspidal_submodule(); S
    483483    Modular Symbols subspace of dimension 2 of Modular Symbols space of
    484484    dimension 4 and level 13, weight 2, character [zeta6], sign 0, over
  • doc/fr/tutorial/tour_advanced.rst

    diff --git a/doc/fr/tutorial/tour_advanced.rst b/doc/fr/tutorial/tour_advanced.rst
    a b  
    478478    Modular Symbols space of dimension 4 and level 13, weight 2, character
    479479    [zeta6], sign 0, over Cyclotomic Field of order 6 and degree 2
    480480    sage: M.T(2).charpoly('x').factor()
    481     (x - 2*zeta6 - 1) * (x - zeta6 - 2) * (x + zeta6 + 1)^2
     481    (x - zeta6 - 2) * (x - 2*zeta6 - 1) * (x + zeta6 + 1)^2
    482482    sage: S = M.cuspidal_submodule(); S
    483483    Modular Symbols subspace of dimension 2 of Modular Symbols space of
    484484    dimension 4 and level 13, weight 2, character [zeta6], sign 0, over
  • doc/ru/tutorial/tour_advanced.rst

    diff --git a/doc/ru/tutorial/tour_advanced.rst b/doc/ru/tutorial/tour_advanced.rst
    a b  
    439439    Modular Symbols space of dimension 4 and level 13, weight 2, character
    440440    [zeta6], sign 0, over Cyclotomic Field of order 6 and degree 2
    441441    sage: M.T(2).charpoly('x').factor()
    442     (x - 2*zeta6 - 1) * (x - zeta6 - 2) * (x + zeta6 + 1)^2
     442    (x - zeta6 - 2) * (x - 2*zeta6 - 1) * (x + zeta6 + 1)^2
    443443    sage: S = M.cuspidal_submodule(); S
    444444    Modular Symbols subspace of dimension 2 of Modular Symbols space of
    445445    dimension 4 and level 13, weight 2, character [zeta6], sign 0, over
  • sage/calculus/calculus.py

    diff --git a/sage/calculus/calculus.py b/sage/calculus/calculus.py
    a b  
    379379
    380380    sage: k = var("k")
    381381    sage: sum(1/(1+k^2), k, -oo, oo)
    382     -1/2*I*psi(I + 1) - 1/2*I*psi(I) + 1/2*I*psi(-I) + 1/2*I*psi(-I + 1)
     382    1/2*I*psi(-I) - 1/2*I*psi(I) + 1/2*I*psi(-I + 1) - 1/2*I*psi(I + 1)
    383383
    384384Ensure that ticket #8624 is fixed::
    385385
  • sage/calculus/tests.py

    diff --git a/sage/calculus/tests.py b/sage/calculus/tests.py
    a b  
    109109    sage: integrate(exp(1-x^2),x)
    110110    1/2*sqrt(pi)*e*erf(x)
    111111    sage: integrate(sin(x^2),x)
    112     1/8*((I + 1)*sqrt(2)*erf((1/2*I + 1/2)*sqrt(2)*x) + (I - 1)*sqrt(2)*erf((1/2*I - 1/2)*sqrt(2)*x))*sqrt(pi)
     112    1/8*((I - 1)*sqrt(2)*erf((1/2*I - 1/2)*sqrt(2)*x) + (I + 1)*sqrt(2)*erf((1/2*I + 1/2)*sqrt(2)*x))*sqrt(pi)
    113113
    114114    sage: integrate((1-x^2)^n,x)
    115115    integrate((-x^2 + 1)^n, x)
  • sage/functions/other.py

    diff --git a/sage/functions/other.py b/sage/functions/other.py
    a b  
    15221522        The result is symbolic if exact input is given::
    15231523
    15241524            sage: beta(2,1+5*I)
    1525             beta(2, 5*I + 1)
     1525            beta(5*I + 1, 2)
    15261526            sage: beta(2, 2.)
    15271527            0.166666666666667
    15281528            sage: beta(I, 2.)
  • sage/modular/modform/constructor.py

    diff --git a/sage/modular/modform/constructor.py b/sage/modular/modform/constructor.py
    a b  
    214214        sage: f = M.T(2).charpoly('x'); f
    215215        x^3 + (-2*zeta6 - 2)*x^2 - 2*zeta6*x + 14*zeta6 - 7
    216216        sage: f.factor()
    217         (x - 2*zeta6 - 1) * (x - zeta6 - 2) * (x + zeta6 + 1)
    218    
    219     We can also create spaces corresponding to the groups `\Gamma_H(N)` intermediate 
     217        (x - zeta6 - 2) * (x - 2*zeta6 - 1) * (x + zeta6 + 1)
     218
     219    We can also create spaces corresponding to the groups `\Gamma_H(N)` intermediate
    220220    between `\Gamma_0(N)` and `\Gamma_1(N)`::
    221    
     221
    222222        sage: G = GammaH(30, [11])
    223223        sage: M = ModularForms(G, 2); M
    224224        Modular Forms space of dimension 20 for Congruence Subgroup Gamma_H(30) with H generated by [11] of weight 2 over Rational Field
    225225        sage: M.T(7).charpoly().factor()  # long time (7s on sage.math, 2011)
    226226        (x + 4) * x^2 * (x - 6)^4 * (x + 6)^4 * (x - 8)^7 * (x^2 + 4)
    227        
     227
    228228    More examples of spaces with character::
    229    
     229
    230230        sage: e = DirichletGroup(5, RationalField()).gen(); e
    231231        Dirichlet character modulo 5 of conductor 5 mapping 2 |--> -1
    232232
     
    257257        sage: M = ModularForms(Gamma1(11), 1); M
    258258        Modular Forms space of dimension 5 for Congruence Subgroup Gamma1(11) of weight 1 over Rational Field
    259259        sage: M.basis()
    260         [                                                                                           
    261         1 + 22*q^5 + O(q^6),                                                                       
    262         q + 4*q^5 + O(q^6),                                                                         
    263         q^2 - 4*q^5 + O(q^6),                                                                       
    264         q^3 - 5*q^5 + O(q^6),                                                                       
    265         q^4 - 3*q^5 + O(q^6)                                                                       
    266         ]                                                                                           
     260        [
     261        1 + 22*q^5 + O(q^6),
     262        q + 4*q^5 + O(q^6),
     263        q^2 - 4*q^5 + O(q^6),
     264        q^3 - 5*q^5 + O(q^6),
     265        q^4 - 3*q^5 + O(q^6)
     266        ]
    267267        sage: M.cuspidal_subspace().basis()
    268268        [
    269269        ]
  • sage/modular/modform/eisenstein_submodule.py

    diff --git a/sage/modular/modform/eisenstein_submodule.py b/sage/modular/modform/eisenstein_submodule.py
    a b  
    543543        q + (-zeta6 - 1)*q^2 + (zeta6 + 2)*q^4 + (zeta6 - 5)*q^5 + O(q^6)
    544544        ]
    545545        sage: M.eisenstein_subspace().T(2).matrix().fcp()
    546         (x + zeta3 + 2) * (x + 2*zeta3 + 1) * (x - 2*zeta3 - 1)^2 * (x - zeta3 - 2)^2
     546        (x + 2*zeta3 + 1) * (x + zeta3 + 2) * (x - zeta3 - 2)^2 * (x - 2*zeta3 - 1)^2
    547547        sage: ModularSymbols(e,2).eisenstein_subspace().T(2).matrix().fcp()
    548         (x + zeta3 + 2) * (x + 2*zeta3 + 1) * (x - 2*zeta3 - 1)^2 * (x - zeta3 - 2)^2
     548        (x + 2*zeta3 + 1) * (x + zeta3 + 2) * (x - zeta3 - 2)^2 * (x - 2*zeta3 - 1)^2
    549549
    550550        sage: M.basis()
    551551        [
  • sage/modular/modsym/modsym.py

    diff --git a/sage/modular/modsym/modsym.py b/sage/modular/modsym/modsym.py
    a b  
    250250        sage: f = M.T(2).charpoly('x'); f
    251251        x^4 + (-zeta6 - 1)*x^3 - 8*zeta6*x^2 + (10*zeta6 - 5)*x + 21*zeta6 - 21
    252252        sage: f.factor()
    253         (x - 2*zeta6 - 1) * (x - zeta6 - 2) * (x + zeta6 + 1)^2
    254    
     253        (x - zeta6 - 2) * (x - 2*zeta6 - 1) * (x + zeta6 + 1)^2
     254
    255255    We create a space with character over a larger base ring than the values of the character::
    256256
    257257        sage: ModularSymbols(e, 2, base_ring = CyclotomicField(24))
    258258        Modular Symbols space of dimension 4 and level 13, weight 2, character [zeta24^4], sign 0, over Cyclotomic Field of order 24 and degree 8
    259259
    260260    More examples of spaces with character::
    261    
     261
    262262        sage: e = DirichletGroup(5, RationalField()).gen(); e
    263263        Dirichlet character modulo 5 of conductor 5 mapping 2 |--> -1
    264264
    265265        sage: m = ModularSymbols(e, 2); m
    266266        Modular Symbols space of dimension 2 and level 5, weight 2, character [-1], sign 0, over Rational Field
    267    
     267
    268268    ::
    269    
     269
    270270        sage: m.T(2).charpoly('x')
    271271        x^2 - 1
    272272        sage: m = ModularSymbols(e, 6); m.dimension()
    273273        6
    274274        sage: m.T(2).charpoly('x')
    275275        x^6 - 873*x^4 - 82632*x^2 - 1860496
    276    
     276
    277277    We create a space of modular symbols with nontrivial character in
    278278    characteristic 2.
    279    
     279
    280280    ::
    281    
     281
    282282        sage: G = DirichletGroup(13,GF(4,'a')); G
    283283        Group of Dirichlet characters of modulus 13 over Finite Field in a of size 2^2
    284284        sage: e = G.list()[2]; e
  • sage/rings/arith.py

    diff --git a/sage/rings/arith.py b/sage/rings/arith.py
    a b  
    24182418        -1
    24192419        sage: factor(2^(2^7)+1)
    24202420        59649589127497217 * 5704689200685129054721
    2421    
    2422     Sage calls PARI's factor, which has proof False by default. 
     2421
     2422    Sage calls PARI's factor, which has proof False by default.
    24232423    Sage has a global proof flag, set to True by default (see
    2424     :mod:`sage.structure.proof.proof`, or proof.[tab]). To override 
     2424    :mod:`sage.structure.proof.proof`, or proof.[tab]). To override
    24252425    the default, call this function with proof=False.
    2426    
     2426
    24272427    ::
    2428    
     2428
    24292429        sage: factor(3^89-1, proof=False)
    24302430        2 * 179 * 1611479891519807 * 5042939439565996049162197
    2431    
     2431
    24322432    ::
    2433    
     2433
    24342434        sage: factor(2^197 + 1)  # long time (2s)
    24352435        3 * 197002597249 * 1348959352853811313 * 251951573867253012259144010843
    2436    
     2436
    24372437    Any object which has a factor method can be factored like this::
    24382438
    24392439        sage: K.<i> = QuadraticField(-1)
    24402440        sage: factor(122 - 454*i)
    2441         (-1) * (-3*i - 2) * (-i - 4) * (i + 1)^3 * (-i - 2)^3
     2441        (-1) * (-i - 4) * (-3*i - 2) * (-i - 2)^3 * (i + 1)^3
    24422442
    24432443    To access the data in a factorization::
    2444    
     2444
    24452445        sage: f = factor(420); f
    24462446        2^2 * 3 * 5 * 7
    24472447        sage: [x for x in f]
  • sage/rings/number_field/number_field.py

    diff --git a/sage/rings/number_field/number_field.py b/sage/rings/number_field/number_field.py
    a b  
    76717671            self.__zeta_order = n
    76727672        ## quadratic number fields require this:
    76737673        if f.degree() == 2:
     7674            # define a boolean flag as for NumberField_quadratic to know, which
     7675            # square root we choose (True means no embedding or positive
     7676            # imaginary value).
     7677            # Note that the test is done with NumberFieldElement and not with
     7678            # NumberFieldElement_quadratic which requires somehow this flag.
     7679            self._standard_embedding = not CDF.has_coerce_map_from(self) or CDF(self.gen()).imag() > 0
     7680
    76747681            self._element_class = number_field_element_quadratic.NumberFieldElement_quadratic
    76757682            if n == 4:
    76767683                self._D = ZZ(-1)
     
    88558862        NumberField_absolute.__init__(self, polynomial, name=name, check=check,
    88568863                                      embedding=embedding, latex_name=latex_name,
    88578864                                      assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes)
     8865        self._standard_embedding = True
    88588866        self._element_class = number_field_element_quadratic.NumberFieldElement_quadratic
    88598867        c, b, a = [rational.Rational(t) for t in self.defining_polynomial().list()]
    88608868        # set the generator
     
    88648872        parts = -b/(2*a), (Dpoly/D).sqrt()/(2*a)
    88658873        self._NumberField_generic__gen = self._element_class(self, parts)
    88668874
    8867         # NumberField_absolute.__init__(...) set _zero_element and
    8868         # _one_element to NumberFieldElement_absolute values, which is
    8869         # wrong (and dangerous; such elements can actually be used to
    8870         # crash Sage: see #5316).  Overwrite them with correct values.
    8871         self._zero_element = self(0)
    8872         self._one_element =  self(1)
    8873 
     8875        # we must set the flag _standard_embedding *before* any element creation
     8876        # Note that in the following code, no element is built.
    88748877        emb = self.coerce_embedding()
    8875         if emb is None:
    8876             self._standard_embedding = True
    8877         else:
     8878        if emb is not None:
    88788879            rootD = number_field_element_quadratic.NumberFieldElement_quadratic(self, (QQ(0),QQ(1)))
    88798880            if D > 0:
    88808881                from sage.rings.real_double import RDF
     
    88838884                from sage.rings.complex_double import CDF
    88848885                self._standard_embedding = CDF.has_coerce_map_from(self) and CDF(rootD).imag() > 0
    88858886
     8887        # we reset _NumberField_generic__gen has the flag standard_embedding
     8888        # might be modified
     8889        self._NumberField_generic__gen = self._element_class(self, parts)
     8890
     8891
     8892        # NumberField_absolute.__init__(...) set _zero_element and
     8893        # _one_element to NumberFieldElement_absolute values, which is
     8894        # wrong (and dangerous; such elements can actually be used to
     8895        # crash Sage: see #5316).  Overwrite them with correct values.
     8896        self._zero_element = self(0)
     8897        self._one_element =  self(1)
     8898
     8899
    88868900    def _coerce_map_from_(self, K):
    88878901        """
    88888902        EXAMPLES::
  • sage/rings/number_field/number_field_element.pyx

    diff --git a/sage/rings/number_field/number_field_element.pyx b/sage/rings/number_field/number_field_element.pyx
    a b  
    14111411       
    14121412            sage: K.<a> = NumberField(x^2-10)
    14131413            sage: factor(169*a + 531)
    1414             (-6*a - 19) * (-2*a + 9) * (-3*a - 1)
     1414            (-6*a - 19) * (-3*a - 1) * (-2*a + 9)
    14151415            sage: factor(K(3))
    14161416            Traceback (most recent call last):
    14171417            ...
  • sage/rings/number_field/number_field_element_quadratic.pxd

    diff --git a/sage/rings/number_field/number_field_element_quadratic.pxd b/sage/rings/number_field/number_field_element_quadratic.pxd
    a b  
    1111from number_field_element cimport NumberFieldElement, NumberFieldElement_absolute
    1212
    1313cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute):
    14     # (a + b sqrt(D)) / denom 
     14    # (a + b sqrt(D)) / denom
    1515    cdef mpz_t a, b, denom
    1616    cdef Integer D
     17    cdef bint standard_embedding
    1718    cdef NumberFieldElement conjugate_c(self)
    1819    cdef bint is_sqrt_disc(self)
    1920
    2021    cdef int _randomize(self, num_bound, den_bound, distribution) except -1
    2122
     23
    2224cdef class OrderElement_quadratic(NumberFieldElement_quadratic):
    2325    pass
  • sage/rings/number_field/number_field_element_quadratic.pyx

    diff --git a/sage/rings/number_field/number_field_element_quadratic.pyx b/sage/rings/number_field/number_field_element_quadratic.pyx
    a b  
    99- Robert Bradshaw (2007-09): Initial version
    1010- David Harvey (2007-10): fix up a few bugs, polish around the edges
    1111- David Loeffler (2009-05): add more documentation and tests
     12- Vincent Delecroix (2012-07): comparisons for quadratic number fields (#13213)
    1213
    1314TODO:
    1415
    1516    The ``_new()`` method should be overridden in this class to copy the ``D``
    16     attribute
    17 
     17    and ``standard_embedding`` attributes
    1818"""
    1919#*****************************************************************************
    2020#     Copyright (C) 2007 Robert Bradshaw <robertwb@math.washington.edu>
     
    3131#                  http://www.gnu.org/licenses/
    3232#*****************************************************************************
    3333
    34 include '../../ext/interrupt.pxi'
     34include "../../ext/interrupt.pxi"
    3535include "../../ext/stdsage.pxi"
    36    
    37 cdef object QQ, ZZ
     36
     37from sage.structure.element cimport Element
     38
     39from sage.rings.integer_ring import ZZ
    3840from sage.rings.rational_field import QQ
    39 from sage.rings.integer_ring import ZZ
     41from sage.rings.real_double import RDF
     42from sage.rings.complex_double import CDF
    4043from sage.categories.morphism cimport Morphism
    4144from sage.rings.number_field.number_field_element import _inverse_mod_generic
    4245
     
    8285    return cls(parent, (a, b, denom))
    8386
    8487
    85 
    8688cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute):
    8789    r"""
    8890    A NumberFieldElement_quadratic object gives an efficient representation of
     
    209211                mpz_set_ui(self.denom, 1)
    210212            self._reduce_c_()
    211213
     214        # set the attribute standard embedding which is used in the method
     215        # __cmp__
     216        try:
     217            self.standard_embedding = parent._standard_embedding
     218        except AttributeError:
     219            emb = parent.coerce_embedding()
     220            if emb is None:
     221                self.standard_embedding = True
     222                try:
     223                    parent._standard_embedding = True
     224                except AttributeError:
     225                    pass
     226            else:
     227                raise ValueError("A parent of NumberFieldElement_quadratic with "
     228                      "a canonical embedding should have an attribute "
     229                      "_standard_embedding (used for comparisons of elements)")
     230
    212231    cdef _new(self):
    213232        """
    214         Quickly creates a new initialized NumberFieldElement with the same
    215         parent as self.
     233        Quickly creates a new initialized NumberFieldElement_quadratic with the
     234        same parent as self.
    216235
    217236        EXAMPLE::
    218237
     
    223242        cdef NumberFieldElement_quadratic x
    224243        x = <NumberFieldElement_quadratic>PY_NEW_SAME_TYPE(self)
    225244        x._parent = self._parent
     245        x.standard_embedding = self.standard_embedding
    226246        x.D = self.D
    227247        return x
    228248
     
    564584            1
    565585        """
    566586        return mpz_cmp_ui(self.denom, 1)==0 and mpz_cmp_ui(self.a, 0)==0 and mpz_cmp_ui(self.b, 1)==0
    567                
    568                
     587
     588#########################################################
     589# Comparisons
     590#########################################################
     591
     592    def sign(self):
     593        r"""
     594        Returns the sign of self (0 if zero, +1 if positive and -1 if negative).
     595
     596        EXAMPLES::
     597
     598            sage: K.<sqrt2> = QuadraticField(2, name='sqrt2')
     599            sage: K(0).sign()
     600            0
     601            sage: sqrt2.sign()
     602            1
     603            sage: (sqrt2+1).sign()
     604            1
     605            sage: (sqrt2-1).sign()
     606            1
     607            sage: (sqrt2-2).sign()
     608            -1
     609            sage: (-sqrt2).sign()
     610            -1
     611            sage: (-sqrt2+1).sign()
     612            -1
     613            sage: (-sqrt2+2).sign()
     614            1
     615
     616            sage: K.<a> = QuadraticField(2, embedding=-1.4142)
     617            sage: K(0).sign()
     618            0
     619            sage: a.sign()
     620            -1
     621            sage: (a+1).sign()
     622            -1
     623            sage: (a+2).sign()
     624            1
     625            sage: (a-1).sign()
     626            -1
     627            sage: (-a).sign()
     628            1
     629            sage: (-a-1).sign()
     630            1
     631            sage: (-a-2).sign()
     632            -1
     633
     634            sage: K.<b> = NumberField(x^2 + 2*x + 7, 'b', embedding=CC(-1,-sqrt(6)))
     635            sage: b.sign()
     636            Traceback (most recent call last):
     637            ...
     638            ValueError: a complex number has no sign!
     639            sage: K(1).sign()
     640            1
     641            sage: K(0).sign()
     642            0
     643            sage: K(-2/3).sign()
     644            -1
     645        """
     646        cdef mpz_t i, j
     647        cdef int s = 1, test
     648
     649        if mpz_sgn(self.b) == 0:
     650            return mpz_sgn(self.a)
     651
     652        if mpz_sgn(self.D.value) == -1:
     653            raise ValueError("a complex number has no sign!")
     654
     655        if not self.standard_embedding:
     656            s = -1
     657
     658        if mpz_sgn(self.a) == 0:
     659            return s*mpz_sgn(self.b)
     660
     661        if mpz_sgn(self.a) == 1:
     662            if mpz_sgn(self.b) == s:
     663                return 1
     664
     665        elif mpz_sgn(self.b) == -s:
     666            return -1
     667
     668        mpz_init_set(i,self.a)
     669        mpz_mul(i,i,i)
     670        mpz_init_set(j,self.b)
     671        mpz_mul(j,j,j)
     672        mpz_mul(j,j,self.D.value)
     673        test = mpz_cmp(i,j)
     674        mpz_clear(i)
     675        mpz_clear(j)
     676        if mpz_sgn(self.a) == 1 and mpz_sgn(self.b) == -s:
     677            return test
     678        return -test
     679
     680    def __richcmp__(left, right, int op):
     681        r"""
     682        Note: we may implement a more direct way of comparison for integer,
     683        float and quadratic numbers input (ie avoiding coercion).
     684
     685        TESTS::
     686
     687            sage: K.<i> = QuadraticField(-1)
     688            sage: sorted([5*i+1, 2, 3*i+1, 2-i])
     689            [3*i + 1, 5*i + 1, -i + 2, 2]
     690        """
     691        return (<Element>left)._richcmp(right, op)
     692
     693    cdef _richcmp_c_impl(left, Element _right, int op):
     694        r"""
     695        C implementation of comparison.
     696
     697        TESTS:
     698
     699        Make some random tests to check that the order is compatible with the
     700        ones of the real field (RR) and complex field (CC)::
     701
     702            sage: K1 = NumberField(x^2 - 2, 'a', embedding=RR(1.4))
     703            sage: K2 = NumberField(x^2 - 2, 'a', embedding=RR(-1.4))
     704            sage: for _ in xrange(500):
     705            ...       for K in K1, K2:
     706            ...           a = K.random_element()
     707            ...           b = K.random_element()
     708            ...           assert (a < b) == (RR(a) < RR(b))
     709            ...           assert (a > b) == (RR(a) > RR(b))
     710            ...           assert (a == b) == (RR(a) == RR(b))
     711            ...           assert (a != b) == (RR(a) != RR(b))
     712            ...           assert (a >= b) == (RR(a) >= RR(b))
     713            ...           assert (a <= b) == (RR(a) <= RR(b))
     714
     715        ::
     716
     717            sage: K1 = NumberField(x^2 + 2, 'a', embedding=CC(0,1))
     718            sage: K2 = NumberField(x^2 + 2, 'a', embedding=CC(0,-1))
     719            sage: for _ in xrange(500):
     720            ...       for K in K1, K2:
     721            ...           a = K.random_element()
     722            ...           b = K.random_element()
     723            ...           assert (a < b) == (CC(a) < CC(b))
     724            ...           assert (a > b) == (CC(a) > CC(b))
     725            ...           assert (a == b) == (CC(a) == CC(b))
     726            ...           assert (a != b) == (CC(a) != CC(b))
     727            ...           assert (a >= b) == (CC(a) >= CC(b))
     728            ...           assert (a <= b) == (CC(a) <= CC(b))
     729
     730        The following is tested because of the implementation of
     731        func:`Q_to_quadratic_field_element` which was the cause of some problems
     732        with #13213::
     733
     734            sage: K.<sqrt2> = QuadraticField(2,name='sqrt2')
     735            sage: 1/2 + sqrt2 > 0
     736            True
     737        """
     738        # When D > 0 and standard embedding, we compare (a + b * sqrt(D)) / d and (aa +
     739        # bb * sqrt(D)) / dd using the comparison of (dd*a - d * aa)^2 and (d*bb - dd*b)^2 * D
     740        # mpz_sgn: returns 1 if > 0, 0 if 0 and -1 if < 0
     741        cdef mpz_t i, j
     742        cdef NumberFieldElement_quadratic right = <NumberFieldElement_quadratic> _right
     743        cdef int test
     744
     745        # inequality and equality
     746        if mpz_cmp(left.a, right.a) or mpz_cmp(left.b, right.b) or mpz_cmp(left.denom, right.denom):
     747            if op == Py_EQ:
     748                return False
     749            elif op == Py_NE:
     750                return True
     751        else: # equality
     752            if op == Py_EQ or op == Py_LE or op == Py_GE:
     753                return True
     754            if op == Py_NE or op == Py_LT or op == Py_GT:
     755                return False
     756
     757        # comparisons are valid only in *real* quadratic number field
     758        # when no embedding is specified or in the case of complex embeddings we
     759        # use a lexicographic order.
     760        if mpz_sgn(left.D.value) == -1:
     761            mpz_init(i)
     762            mpz_init(j)
     763            mpz_mul(i, left.a, right.denom)
     764            mpz_mul(j, right.a, left.denom)
     765            test = mpz_cmp(i,j)
     766            if test:
     767                mpz_clear(i)
     768                mpz_clear(j)
     769                return (<Element>left)._rich_to_bool(op, test)
     770            mpz_mul(i, left.b, right.denom)
     771            mpz_mul(j, right.b, left.denom)
     772            test = mpz_cmp(i,j)
     773            if test:
     774                if not left.standard_embedding:
     775                    test = -test
     776                mpz_clear(i)
     777                mpz_clear(j)
     778                return (<Element>left)._rich_to_bool(op, test)
     779            test = mpz_cmp(left.denom, right.denom)
     780            mpz_clear(i)
     781            mpz_clear(j)
     782            return (<Element>left)._rich_to_bool(op, test)
     783
     784        # comparison in the real case
     785        mpz_init(i)
     786        mpz_mul(i,  right.denom, left.a)
     787        mpz_submul(i, left.denom, right.a)
     788
     789        mpz_init(j)
     790        mpz_mul(j, left.denom, right.b)
     791        mpz_submul(j, right.denom, left.b)
     792
     793        if not left.standard_embedding:
     794            mpz_neg(j, j)
     795
     796        if mpz_sgn(i) == 1:
     797            if mpz_sgn(j) == 1:
     798                mpz_mul(i, i, i)
     799                mpz_mul(j, j, j)
     800                mpz_mul(j, j, left.D.value)
     801                test = mpz_cmp(i, j)
     802            else:
     803                test = 1
     804
     805        else:
     806            if mpz_sgn(j) == -1:
     807                mpz_mul(i, i, i)
     808                mpz_mul(j, j, j)
     809                mpz_mul(j, j, left.D.value)
     810                test = mpz_cmp(j, i)
     811            else:
     812                test = -1
     813
     814        mpz_clear(i)
     815        mpz_clear(j)
     816        return (<Element>left)._rich_to_bool(op, test)
     817
     818    def __cmp__(left, right):
     819        r"""
     820        Comparisons of elements.
     821
     822        When there is a real embedding defined, the comparisons uses comparison
     823        induced from the reals. Otherwise, comparison is a lexicographic
     824        comparison on coefficients.
     825
     826        EXAMPLES:
     827
     828        Two examples from the same number field with its two possible real
     829        embeddings::
     830
     831            sage: K.<phi> = NumberField(x^2-x-1, 'phi', embedding=1.618)
     832            sage: phi > 0
     833            True
     834            sage: -phi > 0
     835            False
     836            sage: phi - 3 == 2*phi + 1
     837            False
     838            sage: fibonacci(10)*phi < fibonacci(11)
     839            True
     840            sage: RDF(fibonacci(10)*phi)
     841            88.9918693812
     842            sage: fibonacci(11)
     843            89
     844            sage: l = [-2, phi+3, 2*phi-1, 2*phi-5, 0, -phi+2, fibonacci(20)*phi - fibonacci(21)]
     845            sage: l.sort()
     846            sage: l
     847            [-2, 2*phi - 5, 6765*phi - 10946, 0, -phi + 2, 2*phi - 1, phi + 3]
     848            sage: map(RDF, l)
     849            [-2.0, -1.7639320225, -6.61069607304e-05, 0.0, 0.38196601125, 2.2360679775, 4.61803398875]
     850
     851            sage: L.<psi> = NumberField(x^2-x-1, 'psi', embedding=-0.618)
     852            sage: psi < 0
     853            True
     854            sage: 2*psi + 3 == 2*psi + 3
     855            True
     856            sage: fibonacci(10)*psi < -fibonacci(9)
     857            False
     858            sage: RDF(fibonacci(10)*psi)
     859            -33.9918693812
     860            sage: fibonacci(9)
     861            34
     862            sage: l = [-1, psi, 0, fibonacci(20)*psi + fibonacci(19), 3*psi+2]
     863            sage: l.sort()
     864            sage: l
     865            [-1, psi, 0, 6765*psi + 4181, 3*psi + 2]
     866            sage: map(RDF, l)
     867            [-1.0, -0.61803398875, 0.0, 6.61069607304e-05, 0.14589803375]
     868
     869        For a field with no specified embedding the comparison uses the standard
     870        embedding::
     871
     872            sage: K.<sqrt2> = NumberField(x^2-2, 'sqrt2')
     873            sage: sqrt2 > 1 and sqrt2 < 2
     874            True
     875
     876        The following examples illustrate the same behavior for a complex
     877        quadratic field::
     878
     879            sage: K.<i> = QuadraticField(-1)
     880            sage: l = [-2, i-3, 2*i-2, 2*i+2, 5*i, 1-3*i, -1+i, 1]
     881            sage: l.sort()
     882            sage: l
     883            [i - 3, -2, 2*i - 2, i - 1, 5*i, -3*i + 1, 1, 2*i + 2]
     884            sage: map(CDF, l)
     885            [-3.0 + 1.0*I, -2.0, -2.0 + 2.0*I, -1.0 + 1.0*I, 5.0*I, 1.0 - 3.0*I, 1.0, 2.0 + 2.0*I]
     886            sage: map(CDF, l) == sorted(map(CDF, l))
     887            True
     888        """
     889        return (<Element>left)._cmp(right)
     890
     891    cdef int _cmp_c_impl(left, Element _right) except -2:
     892        """
     893        C implementation of comparison.
     894        """
     895        cdef NumberFieldElement_quadratic right = <NumberFieldElement_quadratic> _right
     896        cdef int test
     897
     898        if left == right:
     899             return 0
     900        if left > right:
     901            return 1
     902        return -1
     903
    569904#########################################################
    570905# Arithmetic
    571906#########################################################
     
    9151250        """
    9161251        return hash(self.polynomial())
    9171252
    918     def __richcmp__(left, right, int op):
    919         r"""
    920         EXAMPLE::
    921        
    922             sage: K.<a> = NumberField(x^2+163)
    923             sage: K(1/2) < K(2/3) # indirect doctest
    924             False
    925             sage: K(1/2) > K(1/3) # indirect doctest
    926             True
    927         """
    928         return (<Element>left)._richcmp(right, op)
    929 
    930     cdef int _cmp_c_impl(self, Element _right) except -2:
    931         """
    932         EXAMPLES:
    933             sage: K.<a> = NumberField(x^2+163)
    934             sage: K(1/2)==1/2
    935             True
    936             sage: a == 1/2
    937             False
    938             sage: 2+a == a+2
    939             True
    940         """
    941         cdef NumberFieldElement_quadratic right = _right
    942         return not mpz_cmp(self.a, right.a)==0  \
    943             or not mpz_cmp(self.b, right.b)==0  \
    944             or not mpz_cmp(self.denom, right.denom) == 0
    945 
    9461253
    9471254    def __nonzero__(self):
    9481255        """
     
    10771384        mpz_set_ui(q.b, 1)
    10781385        mpz_set_ui(q.denom, 1)
    10791386        from sage.rings.complex_double import CDF
    1080         cdef bint standard_embedding = embedding is None or self._parent._standard_embedding
    10811387        cdef Rational res
    10821388        if mpz_cmp_ui(negD.value, 1) == 0 or negD.is_square():
    10831389            # D = -1 is the most common case we'll see here
     
    10911397                mpz_mul(mpq_numref(res.value), mpq_numref(res.value), self.b)
    10921398            mpz_set(mpq_denref(res.value), self.denom)
    10931399            mpq_canonicalize(res.value)
    1094             if not standard_embedding:
     1400            if not self.standard_embedding:
    10951401                mpq_neg(res.value, res.value)
    10961402            return res
    10971403        else:
     
    11041410                K = QuadraticField(negD, 'sqrt%s' % negD)
    11051411            q = K(0)
    11061412            mpz_set(q.denom, self.denom)
    1107             if standard_embedding:
     1413            if self.standard_embedding:
    11081414                mpz_set(q.b, self.b)
    11091415            else:
    11101416                mpz_neg(q.b, self.b)
     
    11181424            sage: abs(a+1)
    11191425            sqrt(2)
    11201426        """
    1121         from sage.functions.all import sqrt
    1122         return sqrt(self.imag()**2 + self.real()**2)
     1427        return (self.imag()**2 + self.real()**2).sqrt()
    11231428
    11241429    def _coefficients(self):
    11251430        """
    1126         EXAMPLES:
     1431        EXAMPLES::
     1432
    11271433            sage: K.<a> = NumberField(x^2+41)
    11281434            sage: a._coefficients()
    11291435            [0, 1]
     
    16371943        """
    16381944        import sage.categories.homset
    16391945        Morphism.__init__(self, sage.categories.homset.Hom(QQ, K))
    1640         self.zero_element = PY_NEW(NumberFieldElement_quadratic)
    1641         self.zero_element._parent = K
    1642         self.zero_element.D = K._D
    1643        
     1946        self.zero_element = K.zero_element()
    16441947
    16451948    cpdef Element _call_(self, x):
    16461949        r"""
  • sage/rings/number_field/order.py

    diff --git a/sage/rings/number_field/order.py b/sage/rings/number_field/order.py
    a b  
    10221022
    10231023        if K.degree() == 2:
    10241024            self._element_type = OrderElement_quadratic
     1025            # adding the following attribute makes the comparison of elements
     1026            # faster.
     1027            self._standard_embedding = K._standard_embedding
    10251028        else:
    10261029            self._element_type = OrderElement_absolute
    10271030           
  • sage/rings/number_field/totallyreal_rel.py

    diff --git a/sage/rings/number_field/totallyreal_rel.py b/sage/rings/number_field/totallyreal_rel.py
    a b  
    125125
    126126        sage: v = sage.rings.number_field.totallyreal_rel.integral_elements_in_box(K, C)
    127127        sage: sorted(v)
    128         [-alpha + 3, -alpha + 2, 5, 4, 3, 2, 1, 0, alpha + 6, alpha + 5, alpha + 4, alpha + 3, alpha + 2, 2*alpha + 7, 2*alpha + 6, 2*alpha + 5, 2*alpha + 4, 2*alpha + 3, 3*alpha + 5]
    129 
     128         [0, -alpha + 2, 1, -alpha + 3, 2, 3, alpha + 2, 4, alpha + 3, 5, alpha + 4, 2*alpha + 3, alpha + 5, 2*alpha + 4, alpha + 6, 2*alpha + 5, 2*alpha + 6, 3*alpha + 5, 2*alpha + 7]
    130129
    131130    A cubic field::
    132131
    133132        sage: x = polygen(QQ)
    134133        sage: K.<a> = NumberField(x^3 - 16*x +16)
    135134        sage: eps = 10e-6
    136         sage: C = [[0-eps,5+eps]]*3 
     135        sage: C = [[0-eps,5+eps]]*3
    137136        sage: v = sage.rings.number_field.totallyreal_rel.integral_elements_in_box(K, C)
    138137
    139138    Note that the output is platform dependent (sometimes a 5 is listed below, and
    140139    sometimes it isn't)::
    141    
    142         sage: sorted(v) 
     140
     141        sage: sorted(v)
    143142        [-1/2*a + 2, 1/4*a^2 + 1/2*a, 0, 1, 2, 3, 4,...-1/4*a^2 - 1/2*a + 5, 1/2*a + 3, -1/4*a^2 + 5]
    144        
    145143    """
    146144    d = K.degree()
    147145    Z_F = K.maximal_order()
  • sage/schemes/elliptic_curves/cm.py

    diff --git a/sage/schemes/elliptic_curves/cm.py b/sage/schemes/elliptic_curves/cm.py
    a b  
    158158    Return a list of all CM `j`-invariants in the field `K`.
    159159
    160160    INPUT:
    161    
     161
    162162    - ``K`` -- a number field
    163163    - ``proof`` -- (default: proof.number_field())
    164164
    165165    OUTPUT:
    166    
     166
    167167    (list) -- A list of CM `j`-invariants in the field `K`.
    168168
    169169    EXAMPLE::
    170    
     170
    171171        sage: cm_j_invariants(QQ)
    172172        [-262537412640768000, -147197952000, -884736000, -12288000, -884736, -32768, -3375, 0, 1728, 8000, 54000, 287496, 16581375]
    173173
    174174    Over imaginary quadratic fields there are no more than over `QQ`::
    175    
    176         sage: cm_j_invariants(QuadraticField(-1, 'i'))   # sorted differently since QQ[i] sorts funny
    177         [-12288000, 54000, 0, 287496, 1728, 16581375, -3375, 8000, -32768, -884736, -884736000, -147197952000, -262537412640768000]
    178        
     175
     176        sage: cm_j_invariants(QuadraticField(-1, 'i'))
     177        [-262537412640768000, -147197952000, -884736000, -12288000, -884736, -32768, -3375, 0, 1728, 8000, 54000, 287496, 16581375]
     178
    179179    Over real quadratic fields there may be more, for example::
    180    
     180
    181181        sage: len(cm_j_invariants(QuadraticField(5, 'a')))
    182182        31
    183        
     183
    184184    Over number fields K of many higher degrees this also works::
    185    
     185
    186186        sage: K.<a> = NumberField(x^3 - 2)
    187187        sage: cm_j_invariants(K)
    188188        [-12288000, 54000, 0, 287496, 1728, 16581375, -3375, 8000, -32768, -884736, -884736000, -147197952000, -262537412640768000, 31710790944000*a^2 + 39953093016000*a + 50337742902000]
  • sage/schemes/elliptic_curves/ell_curve_isogeny.py

    diff --git a/sage/schemes/elliptic_curves/ell_curve_isogeny.py b/sage/schemes/elliptic_curves/ell_curve_isogeny.py
    a b  
    738738        sage: phi.codomain() == phi.domain()
    739739        True
    740740        sage: phi.rational_maps()
    741         (((-4/25*i - 3/25)*x^5 + (-4/5*i + 2/5)*x^3 + x)/(x^4 + (-4/5*i + 2/5)*x^2 + (-4/25*i - 3/25)),
    742         ((2/125*i - 11/125)*x^6*y + (64/125*i + 23/125)*x^4*y + (162/125*i - 141/125)*x^2*y + (-4/25*i - 3/25)*y)/(x^6 + (-6/5*i + 3/5)*x^4 + (-12/25*i - 9/25)*x^2 + (2/125*i - 11/125)))
    743 
     741        (((4/25*i + 3/25)*x^5 + (4/5*i - 2/5)*x^3 - x)/(x^4 + (-4/5*i + 2/5)*x^2 + (-4/25*i - 3/25)),
     742         ((11/125*i + 2/125)*x^6*y + (-23/125*i + 64/125)*x^4*y + (141/125*i + 162/125)*x^2*y + (3/25*i - 4/25)*y)/(x^6 + (-6/5*i + 3/5)*x^4 + (-12/25*i - 9/25)*x^2 + (2/125*i - 11/125)))
    744743    """
    745744
    746745    ####################
     
    45134512        [Isogeny of degree 5 from Elliptic Curve defined by y^2 = x^3 + x over Number Field in i with defining polynomial x^2 + 1 to Elliptic Curve defined by y^2 = x^3 + x over Number Field in i with defining polynomial x^2 + 1,
    45144513        Isogeny of degree 5 from Elliptic Curve defined by y^2 = x^3 + x over Number Field in i with defining polynomial x^2 + 1 to Elliptic Curve defined by y^2 = x^3 + x over Number Field in i with defining polynomial x^2 + 1]
    45154514        sage: _[0].rational_maps()
    4516         (((-4/25*i - 3/25)*x^5 + (-4/5*i + 2/5)*x^3 + x)/(x^4 + (-4/5*i + 2/5)*x^2 + (-4/25*i - 3/25)),
    4517         ((2/125*i - 11/125)*x^6*y + (64/125*i + 23/125)*x^4*y + (162/125*i - 141/125)*x^2*y + (-4/25*i - 3/25)*y)/(x^6 + (-6/5*i + 3/5)*x^4 + (-12/25*i - 9/25)*x^2 + (2/125*i - 11/125)))
     4515        (((4/25*i + 3/25)*x^5 + (4/5*i - 2/5)*x^3 - x)/(x^4 + (-4/5*i + 2/5)*x^2 + (-4/25*i - 3/25)),
     4516         ((11/125*i + 2/125)*x^6*y + (-23/125*i + 64/125)*x^4*y + (141/125*i + 162/125)*x^2*y + (3/25*i - 4/25)*y)/(x^6 + (-6/5*i + 3/5)*x^4 + (-12/25*i - 9/25)*x^2 + (2/125*i - 11/125)))
    45184517
    45194518    An example of 5-isogenies over a number field::
    45204519
     
    47744773        [Isogeny of degree 13 from Elliptic Curve defined by y^2 = x^3 + r over Number Field in r with defining polynomial x^2 + 3 to Elliptic Curve defined by y^2 = x^3 + r over Number Field in r with defining polynomial x^2 + 3,
    47754774        Isogeny of degree 13 from Elliptic Curve defined by y^2 = x^3 + r over Number Field in r with defining polynomial x^2 + 3 to Elliptic Curve defined by y^2 = x^3 + r over Number Field in r with defining polynomial x^2 + 3]
    47764775        sage: isogenies_13_0(E)[0].rational_maps()
    4777         (((-4/169*r - 11/169)*x^13 + (-128/13*r - 456/13)*x^10 + (-1224/13*r - 2664/13)*x^7 + (-2208/13*r + 5472/13)*x^4 + (1152/13*r - 8064/13)*x)/(x^12 + (4*r - 36)*x^9 + (-1080/13*r + 3816/13)*x^6 + (2112/13*r + 5184/13)*x^3 + (17280/169*r - 1152/169)), ((18/2197*r - 35/2197)*x^18*y + (-23142/2197*r + 35478/2197)*x^15*y + (-1127520/2197*r + 1559664/2197)*x^12*y + (87744/2197*r + 5992704/2197)*x^9*y + (-6625152/2197*r + 9085824/2197)*x^6*y + (28919808/2197*r - 2239488/2197)*x^3*y + (-1990656/2197*r + 3870720/2197)*y)/(x^18 + (6*r - 54)*x^15 + (-3024/13*r + 11808/13)*x^12 + (31296/13*r - 51840/13)*x^9 + (-487296/169*r - 2070144/169)*x^6 + (-940032/169*r - 248832/169)*x^3 + (-1990656/2197*r + 3870720/2197)))
     4776        (((7/338*r + 23/338)*x^13 + (-164/13*r - 420/13)*x^10 + (720/13*r + 3168/13)*x^7 + (3840/13*r - 576/13)*x^4 + (4608/13*r + 2304/13)*x)/(x^12 + (4*r + 36)*x^9 + (1080/13*r + 3816/13)*x^6 + (2112/13*r - 5184/13)*x^3 + (-17280/169*r - 1152/169)), ((18/2197*r + 35/2197)*x^18*y + (23142/2197*r + 35478/2197)*x^15*y + (-1127520/2197*r - 1559664/2197)*x^12*y + (-87744/2197*r + 5992704/2197)*x^9*y + (-6625152/2197*r - 9085824/2197)*x^6*y + (-28919808/2197*r - 2239488/2197)*x^3*y + (-1990656/2197*r - 3870720/2197)*y)/(x^18 + (6*r + 54)*x^15 + (3024/13*r + 11808/13)*x^12 + (31296/13*r + 51840/13)*x^9 + (487296/169*r - 2070144/169)*x^6 + (-940032/169*r + 248832/169)*x^3 + (1990656/2197*r + 3870720/2197)))
    47784777
    47794778    An example of endomorphisms over a finite field::
    47804779   
  • sage/schemes/elliptic_curves/ell_field.py

    diff --git a/sage/schemes/elliptic_curves/ell_field.py b/sage/schemes/elliptic_curves/ell_field.py
    a b  
    939939            Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x + (-6) over Number Field in e with defining polynomial x^2 - 2
    940940            sage: E.isogenies_prime_degree(2)
    941941            [Isogeny of degree 2 from Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x + (-6) over Number Field in e with defining polynomial x^2 - 2 to Elliptic Curve defined by y^2 + x*y + y = x^3 + (-36)*x + (-70) over Number Field in e with defining polynomial x^2 - 2]
    942             sage: E.isogenies_prime_degree(3)           
    943             [Isogeny of degree 3 from Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x + (-6) over Number Field in e with defining polynomial x^2 - 2 to Elliptic Curve defined by y^2 + x*y + y = x^3 + (-171)*x + (-874) over Number Field in e with defining polynomial x^2 - 2, Isogeny of degree 3 from Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x + (-6) over Number Field in e with defining polynomial x^2 - 2 to Elliptic Curve defined by y^2 + x*y + y = x^3 + (-128/3)*x + 5662/27 over Number Field in e with defining polynomial x^2 - 2]
    944 
    945 
     942            sage: E.isogenies_prime_degree(3)
     943            [Isogeny of degree 3 from Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x + (-6) over Number Field in e with defining polynomial x^2 - 2 to Elliptic Curve defined by y^2 + x*y + y = x^3 + (-128/3)*x + 5662/27 over Number Field in e with defining polynomial x^2 - 2, Isogeny of degree 3 from Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x + (-6) over Number Field in e with defining polynomial x^2 - 2 to Elliptic Curve defined by y^2 + x*y + y = x^3 + (-171)*x + (-874) over Number Field in e with defining polynomial x^2 - 2]
    946944        """
    947945        F = self.base_ring()
    948946        if rings.is_RealField(F):
  • sage/schemes/elliptic_curves/ell_generic.py

    diff --git a/sage/schemes/elliptic_curves/ell_generic.py b/sage/schemes/elliptic_curves/ell_generic.py
    a b  
    22602260            sage: K.<a> = NumberField(x^2+3) # adjoin roots of unity
    22612261            sage: E.automorphisms(K)
    22622262            [Generic endomorphism of Abelian group of points on Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
    2263             Via:  (u,r,s,t) = (1, 0, 0, 0),
     2263            Via:  (u,r,s,t) = (-1, 0, 0, -1),
    22642264            ...
    22652265            Generic endomorphism of Abelian group of points on Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
    2266             Via:  (u,r,s,t) = (-1/2*a - 1/2, 0, 0, 0)]
     2266            Via:  (u,r,s,t) = (1, 0, 0, 0)]
    22672267       
    22682268        ::
    22692269       
  • sage/schemes/elliptic_curves/ell_number_field.py

    diff --git a/sage/schemes/elliptic_curves/ell_number_field.py b/sage/schemes/elliptic_curves/ell_number_field.py
    a b  
    13481348            sage: [(p.norm(), e) for p, e in E.conductor().factor()]
    13491349            [(9, 1), (5, 1)]
    13501350            sage: [(p.norm(), e) for p, e in E.discriminant().factor()]
    1351             [(9, 1), (-5, 2)]
     1351            [(-5, 2), (9, 1)]
    13521352
    13531353        See :trac:`14472`, this used not to work over a relative extension::
    13541354
     
    15781578        except AttributeError:
    15791579            self.__torsion_order = self.torsion_subgroup().order()
    15801580            return self.__torsion_order
    1581  
     1581
    15821582    def torsion_points(self):
    15831583        r"""
    15841584        Returns a list of the torsion points of this elliptic curve.
     
    15951595            sage: K.<t> = NumberField(x^4 + x^3 + 11*x^2 + 41*x + 101)
    15961596            sage: EK = E.base_extend(K)
    15971597            sage: EK.torsion_points()
    1598             [(16 : 60 : 1), 
    1599              (5 : 5 : 1), 
     1598            [(16 : 60 : 1),
     1599             (5 : 5 : 1),
    16001600             (5 : -6 : 1),
    16011601             (16 : -61 : 1),
    1602              (t : 1/11*t^3 + 6/11*t^2 + 19/11*t + 48/11 : 1), 
    1603              (-3/55*t^3 - 7/55*t^2 - 2/55*t - 133/55 : 6/55*t^3 + 3/55*t^2 + 25/11*t + 156/55 : 1), 
    1604              (-9/121*t^3 - 21/121*t^2 - 127/121*t - 377/121 : -7/121*t^3 + 24/121*t^2 + 197/121*t + 16/121 : 1), 
     1602             (t : 1/11*t^3 + 6/11*t^2 + 19/11*t + 48/11 : 1),
     1603             (-3/55*t^3 - 7/55*t^2 - 2/55*t - 133/55 : 6/55*t^3 + 3/55*t^2 + 25/11*t + 156/55 : 1),
     1604             (-9/121*t^3 - 21/121*t^2 - 127/121*t - 377/121 : -7/121*t^3 + 24/121*t^2 + 197/121*t + 16/121 : 1),
    16051605             (5/121*t^3 - 14/121*t^2 - 158/121*t - 453/121 : -49/121*t^3 - 129/121*t^2 - 315/121*t - 207/121 : 1),
    1606              (10/121*t^3 + 49/121*t^2 + 168/121*t + 73/121 : 32/121*t^3 + 60/121*t^2 - 261/121*t - 807/121 : 1), 
    1607              (1/11*t^3 - 5/11*t^2 + 19/11*t - 40/11 : -6/11*t^3 - 3/11*t^2 - 26/11*t - 321/11 : 1), 
    1608              (14/121*t^3 - 15/121*t^2 + 90/121*t + 232/121 : 16/121*t^3 - 69/121*t^2 + 293/121*t - 46/121 : 1), 
    1609              (3/55*t^3 + 7/55*t^2 + 2/55*t + 78/55 : 7/55*t^3 - 24/55*t^2 + 9/11*t + 17/55 : 1), 
     1606             (10/121*t^3 + 49/121*t^2 + 168/121*t + 73/121 : 32/121*t^3 + 60/121*t^2 - 261/121*t - 807/121 : 1),
     1607             (1/11*t^3 - 5/11*t^2 + 19/11*t - 40/11 : -6/11*t^3 - 3/11*t^2 - 26/11*t - 321/11 : 1),
     1608             (14/121*t^3 - 15/121*t^2 + 90/121*t + 232/121 : 16/121*t^3 - 69/121*t^2 + 293/121*t - 46/121 : 1),
     1609             (3/55*t^3 + 7/55*t^2 + 2/55*t + 78/55 : 7/55*t^3 - 24/55*t^2 + 9/11*t + 17/55 : 1),
    16101610             (-5/121*t^3 + 36/121*t^2 - 84/121*t + 24/121 : 34/121*t^3 - 27/121*t^2 + 305/121*t + 708/121 : 1),
    1611              (-26/121*t^3 + 20/121*t^2 - 219/121*t - 995/121 : 15/121*t^3 + 156/121*t^2 - 232/121*t + 2766/121 : 1), 
    1612              (1/11*t^3 - 5/11*t^2 + 19/11*t - 40/11 : 6/11*t^3 + 3/11*t^2 + 26/11*t + 310/11 : 1), 
    1613              (-26/121*t^3 + 20/121*t^2 - 219/121*t - 995/121 : -15/121*t^3 - 156/121*t^2 + 232/121*t - 2887/121 : 1), 
    1614              (-5/121*t^3 + 36/121*t^2 - 84/121*t + 24/121 : -34/121*t^3 + 27/121*t^2 - 305/121*t - 829/121 : 1), 
    1615              (3/55*t^3 + 7/55*t^2 + 2/55*t + 78/55 : -7/55*t^3 + 24/55*t^2 - 9/11*t - 72/55 : 1), 
    1616              (14/121*t^3 - 15/121*t^2 + 90/121*t + 232/121 : -16/121*t^3 + 69/121*t^2 - 293/121*t - 75/121 : 1), 
     1611             (-26/121*t^3 + 20/121*t^2 - 219/121*t - 995/121 : 15/121*t^3 + 156/121*t^2 - 232/121*t + 2766/121 : 1),
     1612             (1/11*t^3 - 5/11*t^2 + 19/11*t - 40/11 : 6/11*t^3 + 3/11*t^2 + 26/11*t + 310/11 : 1),
     1613             (-26/121*t^3 + 20/121*t^2 - 219/121*t - 995/121 : -15/121*t^3 - 156/121*t^2 + 232/121*t - 2887/121 : 1),
     1614             (-5/121*t^3 + 36/121*t^2 - 84/121*t + 24/121 : -34/121*t^3 + 27/121*t^2 - 305/121*t - 829/121 : 1),
     1615             (3/55*t^3 + 7/55*t^2 + 2/55*t + 78/55 : -7/55*t^3 + 24/55*t^2 - 9/11*t - 72/55 : 1),
     1616             (14/121*t^3 - 15/121*t^2 + 90/121*t + 232/121 : -16/121*t^3 + 69/121*t^2 - 293/121*t - 75/121 : 1),
    16171617             (t : -1/11*t^3 - 6/11*t^2 - 19/11*t - 59/11 : 1),
    1618              (10/121*t^3 + 49/121*t^2 + 168/121*t + 73/121 : -32/121*t^3 - 60/121*t^2 + 261/121*t + 686/121 : 1), 
    1619              (5/121*t^3 - 14/121*t^2 - 158/121*t - 453/121 : 49/121*t^3 + 129/121*t^2 + 315/121*t + 86/121 : 1), 
    1620              (-9/121*t^3 - 21/121*t^2 - 127/121*t - 377/121 : 7/121*t^3 - 24/121*t^2 - 197/121*t - 137/121 : 1), 
    1621              (-3/55*t^3 - 7/55*t^2 - 2/55*t - 133/55 : -6/55*t^3 - 3/55*t^2 - 25/11*t - 211/55 : 1), 
     1618             (10/121*t^3 + 49/121*t^2 + 168/121*t + 73/121 : -32/121*t^3 - 60/121*t^2 + 261/121*t + 686/121 : 1),
     1619             (5/121*t^3 - 14/121*t^2 - 158/121*t - 453/121 : 49/121*t^3 + 129/121*t^2 + 315/121*t + 86/121 : 1),
     1620             (-9/121*t^3 - 21/121*t^2 - 127/121*t - 377/121 : 7/121*t^3 - 24/121*t^2 - 197/121*t - 137/121 : 1),
     1621             (-3/55*t^3 - 7/55*t^2 - 2/55*t - 133/55 : -6/55*t^3 - 3/55*t^2 - 25/11*t - 211/55 : 1),
    16221622             (0 : 1 : 0)]
    16231623
    16241624        ::
    1625    
     1625
    16261626            sage: E = EllipticCurve('15a1')
    16271627            sage: K.<t> = NumberField(x^2 + 2*x + 10)
    16281628            sage: EK = E.base_extend(K)
    16291629            sage: EK.torsion_points()
    1630             [(8 : 18 : 1),
    1631              (3 : -2 : 1),
    1632              (8 : -27 : 1),
    1633              (t : t - 5 : 1),
    1634              (1/2 : 5/4*t + 1/2 : 1),
    1635              (-t - 2 : 2*t + 8 : 1),
    1636              (-7 : -5*t - 2 : 1),
    1637              (-1 : 0 : 1),
    1638              (-2 : 3 : 1),
    1639              (-13/4 : 9/8 : 1),
    1640              (-2 : -2 : 1),
     1630            [(-7 : -5*t - 2 : 1),
     1631             (-7 : 5*t + 8 : 1),
     1632             (-13/4 : 9/8 : 1),
     1633             (-2 : -2 : 1),
     1634             (-2 : 3 : 1),
     1635             (-t - 2 : -t - 7 : 1),
     1636             (-t - 2 : 2*t + 8 : 1),
     1637             (-1 : 0 : 1),
     1638             (t : t - 5 : 1),
    16411639             (t : -2*t + 4 : 1),
    1642              (-7 : 5*t + 8 : 1),
    1643              (-t - 2 : -t - 7 : 1),
     1640             (0 : 1 : 0),
    16441641             (1/2 : -5/4*t - 2 : 1),
    1645              (0 : 1 : 0)]
     1642             (1/2 : 5/4*t + 1/2 : 1),
     1643             (3 : -2 : 1),
     1644             (8 : -27 : 1),
     1645             (8 : 18 : 1)]
    16461646
    16471647        ::
    1648    
     1648
    16491649            sage: K.<i> = QuadraticField(-1)
    16501650            sage: EK = EllipticCurve(K,[0,0,0,0,-1])
    16511651            sage: EK.torsion_points ()
    1652             [(-2 : -3*i : 1), (0 : -i : 1), (1 : 0 : 1), (0 : i : 1), (-2 : 3*i : 1), (0 : 1 : 0)]
     1652             [(-2 : -3*i : 1), (-2 : 3*i : 1), (0 : -i : 1), (0 : i : 1), (0 : 1 : 0), (1 : 0 : 1)]
    16531653         """
    16541654        T = self.torsion_subgroup() # make sure it is cached
    16551655        return sorted(T.points())           # these are also cached in T
  • sage/schemes/elliptic_curves/ell_point.py

    diff --git a/sage/schemes/elliptic_curves/ell_point.py b/sage/schemes/elliptic_curves/ell_point.py
    a b  
    842842            sage: tor = E.torsion_points(); len(tor)
    843843            8
    844844            sage: [T.order() for T in tor]
    845             [4, 2, 4, 2, 4, 2, 4, 1]
     845            [2, 4, 4, 2, 1, 2, 4, 4]
    846846            sage: all([T.is_divisible_by(3) for T in tor])
    847847            True
    848848            sage: Set([T for T in tor if T.is_divisible_by(2)])
     
    25092509            sage: K.<i> = NumberField(x^2+1)
    25102510            sage: E = EllipticCurve(K, [0,0,4,6*i,0])
    25112511            sage: Q = E.lift_x(-9/4); Q
    2512             (-9/4 : 27/8*i - 4 : 1)
     2512            (-9/4 : -27/8*i : 1)
    25132513            sage: Q.height()
    25142514            2.69518560017909
    25152515            sage: (15*Q).height() / Q.height()
     
    26292629            0.510184995162373
    26302630
    26312631            sage: Q = E.lift_x(-9/4); Q
    2632             (-9/4 : 27/8*i - 4 : 1)
     2632            (-9/4 : -27/8*i : 1)
    26332633            sage: Q.archimedian_local_height(K.places()[0]) / 2
    26342634            0.654445619529600
    26352635        """
     
    27382738            0
    27392739           
    27402740            sage: Q = E.lift_x(-9/4); Q
    2741             (-9/4 : 27/8*i - 4 : 1)
     2741            (-9/4 : -27/8*i : 1)
    27422742            sage: Q.nonarchimedian_local_height(K.ideal(1+i))
    27432743            2*log(2)
    27442744            sage: Q.nonarchimedian_local_height(K.ideal(3))
  • sage/schemes/elliptic_curves/ell_torsion.py

    diff --git a/sage/schemes/elliptic_curves/ell_torsion.py b/sage/schemes/elliptic_curves/ell_torsion.py
    a b  
    108108        sage: T.ngens()
    109109        1
    110110        sage: T.gen(0)
    111         (16 : 60 : 1)
     111        (5 : -6 : 1)
    112112
    113113    Note: this class is normally constructed indirectly as follows::
    114114
     
    276276            sage: E = EllipticCurve(K,[0,0,0,1,0])
    277277            sage: tor = E.torsion_subgroup()
    278278            sage: tor.points()
    279             [(0 : 1 : 0), (0 : 0 : 1), (i : 0 : 1), (-i : 0 : 1)]
     279            [(0 : 1 : 0), (-i : 0 : 1), (0 : 0 : 1), (i : 0 : 1)]
    280280        """
    281281        return [x.element() for x in self]
  • sage/schemes/elliptic_curves/heegner.py

    diff --git a/sage/schemes/elliptic_curves/heegner.py b/sage/schemes/elliptic_curves/heegner.py
    a b  
    14331433            sage: G = K3.galois_group(K1)
    14341434            sage: orb = sorted([g.alpha() for g in G]); orb # random (the sign depends on the database being installed or not)
    14351435            [1, 1/2*sqrt_minus_52 + 1, -1/2*sqrt_minus_52, 1/2*sqrt_minus_52 - 1]
    1436             sage: [x^2 for x in orb] # this is just for testing
    1437             [1, sqrt_minus_52 - 12, -13, -sqrt_minus_52 - 12]
     1436            sage: sorted([x^2 for x in orb]) # this is just for testing
     1437            [-13, -sqrt_minus_52 - 12, sqrt_minus_52 - 12, 1]
    14381438
    14391439            sage: K5 = heegner_points(389,-52,5).ring_class_field()
    14401440            sage: K1 = heegner_points(389,-52,1).ring_class_field()
    14411441            sage: G = K5.galois_group(K1)
    14421442            sage: orb = sorted([g.alpha() for g in G]); orb # random (the sign depends on the database being installed or not)
    14431443            [1, -1/2*sqrt_minus_52, 1/2*sqrt_minus_52 + 1, 1/2*sqrt_minus_52 - 1, 1/2*sqrt_minus_52 - 2, -1/2*sqrt_minus_52 - 2]
    1444             sage: [x^2 for x in orb] # just for testing
    1445             [1, -13, sqrt_minus_52 - 12, -sqrt_minus_52 - 12, -2*sqrt_minus_52 - 9, 2*sqrt_minus_52 - 9]
     1444            sage: sorted([x^2 for x in orb]) # just for testing
     1445            [-13, -sqrt_minus_52 - 12, sqrt_minus_52 - 12, -2*sqrt_minus_52 - 9, 2*sqrt_minus_52 - 9, 1]
    14461446
    14471447        """
    14481448        if self.__alpha is None:
     
    61856185        sage: P.curve()
    61866186        Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
    61876187        sage: P = E.heegner_point(-40).point_exact(); P
    6188         (a : a - 2 : 1)
     6188        (a : -a + 1 : 1)
    61896189        sage: P = E.heegner_point(-47).point_exact(); P
    61906190        (a : a^4 + a - 1 : 1)
    61916191        sage: P[0].parent()
  • sage/stats/basic_stats.py

    diff --git a/sage/stats/basic_stats.py b/sage/stats/basic_stats.py
    a b  
    165165        sage: std([])
    166166        NaN
    167167        sage: std([I, sqrt(2), 3/5])
    168         sqrt(1/450*(-5*sqrt(2) - 5*I + 6)^2 + 1/450*(10*sqrt(2) - 5*I - 3)^2 + 1/450*(-5*sqrt(2) + 10*I - 3)^2)
     168        sqrt(1/450*(5*sqrt(2) + 5*I - 6)^2 + 1/450*(5*sqrt(2) - 10*I + 3)^2 + 1/450*(10*sqrt(2) - 5*I - 3)^2)
    169169        sage: std([RIF(1.0103, 1.0103), RIF(2)])
    170170        0.6998235813403261?
    171171        sage: import numpy
     
    225225        7/2
    226226        sage: variance([1..6], bias=True)
    227227        35/12
    228         sage: variance([e, pi])                 
     228        sage: variance([e, pi])
    229229        1/2*(pi - e)^2
    230         sage: variance([])                     
     230        sage: variance([])
    231231        NaN
    232         sage: variance([I, sqrt(2), 3/5])       
    233         1/450*(-5*sqrt(2) - 5*I + 6)^2 + 1/450*(10*sqrt(2) - 5*I - 3)^2 + 1/450*(-5*sqrt(2) + 10*I - 3)^2
     232        sage: variance([I, sqrt(2), 3/5])
     233        1/450*(5*sqrt(2) + 5*I - 6)^2 + 1/450*(5*sqrt(2) - 10*I + 3)^2 + 1/450*(10*sqrt(2) - 5*I - 3)^2
    234234        sage: variance([RIF(1.0103, 1.0103), RIF(2)])
    235235        0.4897530450000000?
    236236        sage: import numpy
  • sage/symbolic/integration/integral.py

    diff --git a/sage/symbolic/integration/integral.py b/sage/symbolic/integration/integral.py
    a b  
    456456                 x y  + Sqrt[--] FresnelS[Sqrt[--] x]
    457457                             2                 Pi
    458458        sage: print f.integral(x)
    459         y^z*x + 1/8*((I + 1)*sqrt(2)*erf((1/2*I + 1/2)*sqrt(2)*x) + (I - 1)*sqrt(2)*erf((1/2*I - 1/2)*sqrt(2)*x))*sqrt(pi)
     459        y^z*x + 1/8*((I - 1)*sqrt(2)*erf((1/2*I - 1/2)*sqrt(2)*x) + (I + 1)*sqrt(2)*erf((1/2*I + 1/2)*sqrt(2)*x))*sqrt(pi)
    460460
    461461    Alternatively, just use algorithm='mathematica_free' to integrate via Mathematica
    462462    over the internet (does NOT require a Mathematica license!)::
     
    527527    see #3013::
    528528
    529529        sage: integrate(sin(x)*cos(10*x)*log(x), x)
    530         1/198*(11*cos(9*x) - 9*cos(11*x))*log(x) + 1/44*Ei(-11*I*x) + 1/44*Ei(11*I*x) - 1/36*Ei(-9*I*x) - 1/36*Ei(9*I*x)
     530        1/198*(11*cos(9*x) - 9*cos(11*x))*log(x) + 1/44*Ei(-11*I*x) - 1/36*Ei(-9*I*x) - 1/36*Ei(9*I*x) + 1/44*Ei(11*I*x)
    531531
    532532    It is no longer possible to use certain functions without an
    533533    explicit variable.  Instead, evaluate the function at a variable,