Ticket #13256: trac_13256_details-review.patch

File trac_13256_details-review.patch, 7.5 KB (added by chapoton, 9 years ago)
  • sage/rings/number_field/number_field_element_quadratic.pyx

    # HG changeset patch
    # User Frederic Chapoton <chapoton at math.univ-lyon1.fr>
    # Date 1369939497 -7200
    # Node ID ab4a0ad7b817b20a5ec40af45489d5d89ea2b476
    # Parent  f8a5df7397e8d17d57640dbb6c4c379edfa402b9
    trac 13256 review patch with links to trac
    
    diff --git a/sage/rings/number_field/number_field_element_quadratic.pyx b/sage/rings/number_field/number_field_element_quadratic.pyx
    a b AUTHORS: 
    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),
    13   abs, floor and ceil functions (#13256)
     12- Vincent Delecroix (2012-07): comparisons for quadratic number fields
     13  (:trac:`13213`), abs, floor and ceil functions (:trac:`13256`)
    1414
    15 TODO:
     15.. TODO::
    1616
    1717    The ``_new()`` method should be overridden in this class to copy the ``D``
    1818    and ``standard_embedding`` attributes
    def __make_NumberFieldElement_quadratic1 
    7878        sage: loads(dumps(a)) == a # indirect doctest
    7979        True
    8080
    81     We test that #6462 is fixed::
     81    We test that :trac:`6462` is fixed::
    8282
    8383        sage: L = QuadraticField(-11,'a'); OL = L.maximal_order(); w = OL.0
    8484        sage: loads(dumps(w)) == w # indirect doctest
    cdef class NumberFieldElement_quadratic( 
    202202            self._ntl_coeff_as_mpz(&self.a, 0)
    203203            self._ntl_coeff_as_mpz(&self.b, 1)
    204204            if mpz_cmp_ui(self.a, 0) or mpz_cmp_ui(self.b, 0):
    205                 gen = parent.gen() # should this be cached?
     205                gen = parent.gen()  # should this be cached?
    206206                self._ntl_denom_as_mpz(&self.denom)
    207207                if mpz_cmp_ui(self.b, 0):
    208208                    mpz_mul(self.a, self.a, gen.denom)
    cdef class NumberFieldElement_quadratic( 
    227227                    pass
    228228            else:
    229229                raise ValueError("A parent of NumberFieldElement_quadratic with "
    230                       "a canonical embedding should have an attribute "
    231                       "_standard_embedding (used for comparisons of elements)")
     230                                 "a canonical embedding should have an attribute "
     231                                 "_standard_embedding (used for comparisons of elements)")
    232232
    233233    cdef _new(self):
    234234        """
    cdef class NumberFieldElement_quadratic( 
    426426        if check:
    427427            if not isinstance(self.number_field(), number_field.NumberField_cyclotomic) \
    428428                   or not isinstance(new_parent, number_field.NumberField_cyclotomic):
    429                 raise TypeError, "The field and the new parent field must both be cyclotomic fields."
     429                raise TypeError("The field and the new parent field must both be cyclotomic fields.")
    430430
    431431        if rel == 0:
    432432            small_order = self.number_field()._n()
    cdef class NumberFieldElement_quadratic( 
    435435            try:
    436436                rel = ZZ(large_order / small_order)
    437437            except TypeError:
    438                 raise TypeError, "The zeta_order of the new field must be a multiple of the zeta_order of the original."
     438                raise TypeError("The zeta_order of the new field must be a multiple of the zeta_order of the original.")
    439439
    440440        cdef NumberFieldElement_quadratic x2
    441441        cdef int n = self._parent._n()
    cdef class NumberFieldElement_quadratic( 
    731731
    732732        The following is tested because of the implementation of
    733733        func:`Q_to_quadratic_field_element` which was the cause of some problems
    734         with #13213::
     734        with :trac:`13213`::
    735735
    736736            sage: K.<sqrt2> = QuadraticField(2,name='sqrt2')
    737737            sage: 1/2 + sqrt2 > 0
    cdef class NumberFieldElement_quadratic( 
    11791179            sage: (3*a-2)/7 * b
    11801180            1
    11811181
    1182         This fixes ticket #9357::
     1182        This fixes ticket :trac:`9357`::
    11831183
    11841184            sage: K.<a> = NumberField(x^2+1)
    11851185            sage: d = K(0)
    cdef class NumberFieldElement_quadratic( 
    12791279        """
    12801280        cdef Integer res
    12811281        if mpz_cmp_ui(self.b, 0) != 0 or mpz_cmp_ui(self.denom, 1) != 0:
    1282             raise TypeError, "Unable to coerce %s to an integer"%self
     1282            raise TypeError("Unable to coerce %s to an integer" % self)
    12831283        else:
    12841284            res = PY_NEW(Integer)
    12851285            mpz_set(res.value, self.a)
    cdef class NumberFieldElement_quadratic( 
    12991299        """
    13001300        cdef Rational res
    13011301        if mpz_cmp_ui(self.b, 0)!=0:
    1302             raise TypeError, "Unable to coerce %s to a rational"%self
     1302            raise TypeError("Unable to coerce %s to a rational" % self)
    13031303        else:
    13041304            res = <Rational>PY_NEW(Rational)
    13051305            mpz_set(mpq_numref(res.value), self.a)
    cdef class NumberFieldElement_quadratic( 
    13331333        """
    13341334        cdef Rational res
    13351335        if mpz_sgn(self.D.value) > 0:
    1336             return self # totally real
     1336            return self  # totally real
    13371337        else:
    13381338            res = <Rational>PY_NEW(Rational)
    13391339            mpz_set(mpq_numref(res.value), self.a)
    cdef class NumberFieldElement_quadratic( 
    13791379
    13801380        """
    13811381        if mpz_sgn(self.D.value) > 0:
    1382             return PY_NEW(Rational) # = 0
     1382            return PY_NEW(Rational)  # = 0
    13831383        embedding =  self._parent.coerce_embedding()
    13841384        cdef Integer negD = -self.D
    13851385        cdef NumberFieldElement_quadratic q = <NumberFieldElement_quadratic>self._new()
    cdef class NumberFieldElement_quadratic( 
    13901390        if mpz_cmp_ui(negD.value, 1) == 0 or negD.is_square():
    13911391            # D = -1 is the most common case we'll see here
    13921392            if embedding is None:
    1393                 raise ValueError, "Embedding must be specified."
     1393                raise ValueError("Embedding must be specified.")
    13941394            res = <Rational>PY_NEW(Rational)
    13951395            if mpz_cmp_ui(negD.value, 1) == 0:
    13961396                mpz_set(mpq_numref(res.value), self.b)
    cdef class NumberFieldElement_quadratic( 
    14331433            [1/5, 3]
    14341434        """
    14351435        # In terms of the generator...
    1436         cdef NumberFieldElement_quadratic gen = self.number_field().gen() # should this be cached?
     1436        cdef NumberFieldElement_quadratic gen = self.number_field().gen()  # should this be cached?
    14371437        cdef Rational const = <Rational>PY_NEW(Rational), lin = <Rational>PY_NEW(Rational)
    14381438        ad, bd = self.parts()
    14391439        if not self:
    cdef class NumberFieldElement_quadratic( 
    14761476            True
    14771477        """
    14781478        # In terms of the generator...
    1479         cdef NumberFieldElement_quadratic gen = self.number_field().gen() # should this be cached?
     1479        cdef NumberFieldElement_quadratic gen = self.number_field().gen()  # should this be cached?
    14801480        cdef Integer denom
    14811481        if gen.is_sqrt_disc():
    14821482            denom = PY_NEW(Integer)
    cdef class NumberFieldElement_quadratic( 
    15961596        if K is None or K == QQ:
    15971597        # norm = (a^2 - d b^2) / self.denom^2
    15981598            mpz_pow_ui(mpq_numref(res.value), self.a, 2)
    1599             mpz_pow_ui(mpq_denref(res.value), self.b, 2) # use as temp
     1599            mpz_pow_ui(mpq_denref(res.value), self.b, 2)  # use as temp
    16001600            mpz_mul(mpq_denref(res.value), mpq_denref(res.value), self.D.value)
    16011601            mpz_sub(mpq_numref(res.value), mpq_numref(res.value), mpq_denref(res.value))
    16021602            mpz_pow_ui(mpq_denref(res.value), self.denom, 2)