Ticket #12988: trac_12988.patch

File trac_12988.patch, 9.4 KB (added by saraedum, 8 years ago)

move characteristic() to the category of rings and check that it is in ZZ

  • sage/categories/algebras_with_basis.py

    # HG changeset patch
    # User Julian Rueth <julian.rueth@gmail.com>
    Trac 12988: move characteristic() to the category of rings and check that it is in ZZ
    
    diff --git a/sage/categories/algebras_with_basis.py b/sage/categories/algebras_with_basis.py
    index b36808c..88d4fd9 100644
    a b class AlgebrasWithBasis(Category_over_base_ring): 
    6262        running ._test_an_element() . . . pass
    6363        running ._test_associativity() . . . pass
    6464        running ._test_category() . . . pass
     65        running ._test_characteristic() . . . pass
    6566        running ._test_distributivity() . . . pass
    6667        running ._test_elements() . . .
    6768          Running the test suite of self.an_element()
  • sage/categories/fields.py

    diff --git a/sage/categories/fields.py b/sage/categories/fields.py
    index 8759b37..dde4419 100644
    a b class Fields(Category_singleton): 
    181181            """
    182182            return True
    183183
     184        def _test_characteristic_fields(self, **options):
     185            """
     186            Run generic tests on the method :meth:`.characteristic`.
     187
     188            EXAMPLES::
     189
     190                sage: QQ._test_characteristic_fields()
     191
     192            .. NOTE::
     193
     194                We cannot call this method ``_test_characteristic`` since that
     195                would overwrite the method in the super category, and for
     196                cython classes just calling
     197                ``super(sage.categories.fields.Fields().parent_class,
     198                self)._test_characteristic`` doesn't have the desired effect.
     199
     200            .. SEEALSO::
     201
     202                :meth:`sage.categories.rings.Rings.ParentMethods._test_characteristic`
     203            """
     204            tester = self._tester(**options)
     205            try:
     206                char = self.characteristic()
     207                tester.assertTrue(char.is_zero() or char.is_prime())
     208            except AttributeError:
     209                return
     210                # raised when self.one() does not have a additive_order() [or when char is an int and not an Integer which is already checked by _test_characteristic for rings]
     211            except NotImplementedError:
     212                return
     213
    184214    class ElementMethods:
    185215        # Fields are unique factorization domains, so, there is gcd and lcm
    186216        # Of course, in general gcd and lcm in a field are not very interesting.
  • sage/categories/hopf_algebras_with_basis.py

    diff --git a/sage/categories/hopf_algebras_with_basis.py b/sage/categories/hopf_algebras_with_basis.py
    index e4c170f..ba5f464 100644
    a b class HopfAlgebrasWithBasis(Category_over_base_ring): 
    7171        running ._test_an_element() . . . pass
    7272        running ._test_associativity() . . . pass
    7373        running ._test_category() . . . pass
     74        running ._test_characteristic() . . . pass
    7475        running ._test_distributivity() . . . pass
    7576        running ._test_elements() . . .
    7677          Running the test suite of self.an_element()
  • sage/categories/rings.py

    diff --git a/sage/categories/rings.py b/sage/categories/rings.py
    index 4dd2eea..8ea5be3 100644
    a b class Rings(Category_singleton): 
    216216                from sage.rings.noncommutative_ideals import IdealMonoid_nc
    217217                return IdealMonoid_nc(self)           
    218218
     219        def characteristic(self):
     220            """
     221            Return the characteristic of this ring.
     222
     223            EXAMPLES::
     224
     225                sage: QQ.characteristic()
     226                0
     227                sage: GF(19).characteristic()
     228                19
     229                sage: Integers(8).characteristic()
     230                8
     231                sage: Zp(5).characteristic()
     232                0
     233            """
     234            from sage.rings.infinity import infinity
     235            from sage.rings.integer_ring import ZZ
     236            order_1 = self.one().additive_order()
     237            return ZZ.zero() if order_1 is infinity else order_1
     238
     239        def _test_characteristic(self, **options):
     240            """
     241            Run generic tests on the method :meth:`characteristic`.
     242
     243            See also: :class:`TestSuite`.
     244
     245            EXAMPLES::
     246
     247                sage: ZZ._test_characteristic()
     248            """
     249            tester = self._tester(**options)
     250            try:
     251                characteristic = self.characteristic()
     252            except AttributeError:
     253                return # raised when self.one() does not have a additive_order()
     254            except NotImplementedError:
     255                return
     256
     257            # test that #12988 is fixed
     258            tester.assertEqual(type(characteristic),sage.rings.integer.Integer)
     259
    219260        def ideal(self, *args, **kwds):
    220261            """
    221262            Create an ideal of this ring.
  • sage/rings/integer_ring.pyx

    diff --git a/sage/rings/integer_ring.pyx b/sage/rings/integer_ring.pyx
    index 303bc47..90cdac5 100644
    a b cdef class IntegerRing_class(PrincipalIdealDomain): 
    230230        19
    231231        sage: ZZ(2 + 3*5 + O(5^3))
    232232        17
     233
     234    TESTS::
     235
     236        sage: TestSuite(ZZ).run()
    233237    """
    234238
    235239    def __init__(self):
    cdef class IntegerRing_class(PrincipalIdealDomain): 
    883887   
    884888    def characteristic(self):
    885889        """
    886         Return the characteristic of the integers, which is 0
     890        Return the characteristic of the integers, which is 0.
    887891       
    888892        EXAMPLE::
    889893       
    890894            sage: ZZ.characteristic()
    891895            0
    892896        """
    893         return 0
     897        return ZZ.zero()
    894898
    895899    def krull_dimension(self):
    896900        """
  • 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
    index 9a084b8..afef188 100644
    a b class NumberField_generic(number_field_base.NumberField): 
    28672867            sage: k.characteristic()
    28682868            0
    28692869        """
    2870         return 0
     2870        return ZZ.zero()
    28712871
    28722872    def class_group(self, proof=None, names='c'):
    28732873        r"""
  • sage/rings/real_double.pyx

    diff --git a/sage/rings/real_double.pyx b/sage/rings/real_double.pyx
    index b1de83f..b5459d2 100644
    a b cdef class RealDoubleField_class(Field): 
    395395            sage: RDF.characteristic()
    396396            0
    397397        """
    398         return 0
     398        return Integer(0)
    399399
    400400    cdef _new_c(self, double value):
    401401        cdef RealDoubleElement x
  • sage/rings/real_mpfi.pyx

    diff --git a/sage/rings/real_mpfi.pyx b/sage/rings/real_mpfi.pyx
    index 631225a..01035f2 100644
    a b cdef class RealIntervalField_class(sage.rings.ring.Field): 
    754754            sage: RealIntervalField(10).characteristic()
    755755            0
    756756        """
    757         return 0
     757        return Integer(0)
    758758   
    759759    def name(self):
    760760        return "IntervalRealIntervalField%s"%(self.__prec)
  • sage/rings/real_mpfr.pyx

    diff --git a/sage/rings/real_mpfr.pyx b/sage/rings/real_mpfr.pyx
    index 582a9e6..d80b202 100644
    a b cdef class RealField_class(sage.rings.ring.Field): 
    719719            sage: RealField(10).characteristic()
    720720            0
    721721        """
    722         return 0
     722        return Integer(0)
    723723   
    724724    def name(self):
    725725        """
  • sage/rings/ring.pyx

    diff --git a/sage/rings/ring.pyx b/sage/rings/ring.pyx
    index 2d24c9c..1c0e55f 100644
    a b cdef class Ring(ParentWithGens): 
    109109        running ._test_an_element() . . . pass
    110110        running ._test_associativity() . . . pass
    111111        running ._test_category() . . . pass
     112        running ._test_characteristic() . . . pass
    112113        running ._test_distributivity() . . . pass
    113114        running ._test_elements() . . .
    114115          Running the test suite of self.an_element()
    cdef class Ring(ParentWithGens): 
    11421143        """
    11431144        raise NotImplementedError
    11441145
    1145     def characteristic(self):
    1146         """
    1147         Return the characteristic of this ring.
    1148 
    1149         EXAMPLES::
    1150 
    1151             sage: QQ.characteristic()
    1152             0
    1153             sage: GF(19).characteristic()
    1154             19
    1155             sage: Integers(8).characteristic()
    1156             8
    1157             sage: Zp(5).characteristic()
    1158             0
    1159         """
    1160         from sage.rings.infinity import infinity
    1161         from sage.rings.integer_ring import ZZ
    1162         order_1 = self.one_element().additive_order()
    1163         return ZZ.zero_element() if order_1 is infinity else order_1
    1164 
    11651146    def order(self):
    11661147        """
    11671148        The number of elements of self.
  • sage/structure/parent.pyx

    diff --git a/sage/structure/parent.pyx b/sage/structure/parent.pyx
    index fc21077..05a1db4 100644
    a b cdef class Parent(category_object.CategoryObject): 
    832832            running ._test_an_element() . . . pass
    833833            running ._test_associativity() . . . pass
    834834            running ._test_category() . . . pass
     835            running ._test_characteristic() . . . pass
    835836            running ._test_distributivity() . . . pass
    836837            running ._test_elements() . . .
    837838              Running the test suite of self.an_element()
    cdef class Parent(category_object.CategoryObject): 
    894895            _test_an_element
    895896            _test_associativity
    896897            _test_category
     898            _test_characteristic
    897899            _test_distributivity
    898900            _test_elements
    899901            _test_elements_eq