Ticket #14497: trac_14497-zero_conversion-cs.patch

File trac_14497-zero_conversion-cs.patch, 1.9 KB (added by stumpc5, 7 years ago)
  • sage/rings/universal_cyclotomic_field/universal_cyclotomic_field.py

    # HG changeset patch
    # User Christian Stump <christian.stump at gmail.com>
    # Date 1367571881 -7200
    # Node ID 98e9365aefcbde9114ff1355722d40413d2763ab
    # Parent  1077314f416653b28e199c382667a1f11e444bdd
    Trac 14497: fixes bug to convert zero to rationals
    
    diff --git a/sage/rings/universal_cyclotomic_field/universal_cyclotomic_field.py b/sage/rings/universal_cyclotomic_field/universal_cyclotomic_field.py
    a b class UniversalCyclotomicField(UniqueRep 
    12431243                4/5
    12441244                sage: x.parent()
    12451245                Rational Field
     1246
     1247                sage: UCF(0)._rational_()
     1248                0
     1249
     1250                sage: UCF.gen(5)._rational_()
     1251                Traceback (most recent call last):
     1252                ...
     1253                TypeError:  No conversion of E(5) to the rational field QQ.
    12461254            """
    1247             if self.is_rational():
     1255            if self.is_zero():
     1256                return QQ.zero()
     1257            elif self.is_rational():
    12481258                return self.value._monomial_coefficients[(1,0)]
    1249             raise TypeError("No conversion of %s to the rational field QQ."%str(self))
     1259            else:
     1260                raise TypeError("No conversion of %s to the rational field QQ."%str(self))
    12501261
    12511262        def _integer_(self):
    12521263            r"""
    class UniversalCyclotomicField(UniqueRep 
    14951506                return self.parent().one()
    14961507            elif k == 1:
    14971508                return self
     1509            elif self.is_zero():
     1510                return self.parent().zero()
    14981511            elif self.is_rational():
    14991512                return self.parent()._from_dict({ (1,0) : self.value._monomial_coefficients[(1,0)]**k }, remove_zeros=False)
    15001513            elif len(self.value._monomial_coefficients) == 1: