Ticket #12877: trac_12877-category-for_more_rings_and_schemes-nt.patch

File trac_12877-category-for_more_rings_and_schemes-nt.patch, 15.0 KB (added by nthiery, 7 years ago)
  • sage/rings/padics/factory.py

    # HG changeset patch
    # User Nicolas M. Thiery <nthiery@users.sf.net>
    # Date 1335305173 -7200
    # Node ID cf45bedb04737276222e8d039ad7230fc319967a
    # Parent  e624c08f1f6b9f428134d62f6b2c64eda130b925
    #12877: Categories for more rings and schemes
    
    
    This patch fixes the following classes to use categories:
    
    - padics
    - RealLazyField, ComplexLazyField
    - AlgebraicScheme's and subclasses
    
    diff --git a/sage/rings/padics/factory.py b/sage/rings/padics/factory.py
    a b class pAdicExtension_class(UniqueFactory 
    22692269        polytype = key[0]
    22702270        if polytype == 'u' or polytype == 'e':
    22712271            polytype, base, premodulus, modulus, names, prec, halt, print_mode, print_pos, print_sep, print_alphabet, print_max_ram_terms, print_max_unram_terms, print_max_terse_terms = key
    2272             return ext_table[polytype, type(base.ground_ring_of_tower())](premodulus, modulus, prec, halt, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet, 'max_ram_terms': print_max_ram_terms, 'max_unram_terms': print_max_unram_terms, 'max_terse_terms': print_max_terse_terms}, shift_seed, names)
     2272            return ext_table[polytype, type(base.ground_ring_of_tower()).__base__](premodulus, modulus, prec, halt, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet, 'max_ram_terms': print_max_ram_terms, 'max_unram_terms': print_max_unram_terms, 'max_terse_terms': print_max_terse_terms}, shift_seed, names)
    22732273        elif polytype == 'p':
    22742274            polytype, base, premodulus, upoly, epoly, names, prec, halt, print_mode, print_pos, print_sep, print_alphabet, print_max_ram_terms, print_max_unram_terms, print_max_terse_terms = key
    22752275            precmult = epoly.degree()
    2276             return ext_table['p', type(base.ground_ring_of_tower())](premodulus, upoly, epoly, prec*precmult, halt, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet, 'max_ram_terms': print_max_ram_terms, 'max_unram_terms': print_max_unram_terms, 'max_terse_terms': print_max_terse_terms}, names)
     2276            return ext_table['p', type(base.ground_ring_of_tower()).__base__](premodulus, upoly, epoly, prec*precmult, halt, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet, 'max_ram_terms': print_max_ram_terms, 'max_unram_terms': print_max_unram_terms, 'max_terse_terms': print_max_terse_terms}, names)
    22772277
    22782278ExtensionFactory = pAdicExtension = pAdicExtension_class("pAdicExtension")
    22792279   
  • sage/rings/padics/local_generic.py

    diff --git a/sage/rings/padics/local_generic.py b/sage/rings/padics/local_generic.py
    a b AUTHORS: 
    1717#                  http://www.gnu.org/licenses/
    1818#*****************************************************************************
    1919
     20from sage.categories.commutative_rings import CommutativeRings
    2021from sage.rings.ring import CommutativeRing
    2122from sage.structure.parent import Parent
    2223from sage.rings.integer import Integer
    class LocalGeneric(CommutativeRing): 
    3334            20
    3435        """
    3536        self._prec = prec
    36         Parent.__init__(self, base, element_constructor=element_class, names=(names,), normalize=False)
     37        Parent.__init__(self, base, element_constructor=element_class, names=(names,), normalize=False, category=CommutativeRings())
    3738
    3839    def is_capped_relative(self):
    3940        """
  • sage/rings/padics/padic_base_leaves.py

    diff --git a/sage/rings/padics/padic_base_leaves.py b/sage/rings/padics/padic_base_leaves.py
    a b TESTS:: 
    165165    True
    166166    sage: repr(S(2777))[3:]
    167167    '4&2&1&0&2'
     168    sage: TestSuite(R).run()
    168169
    169170    sage: R = Zp(5, 15, print_mode='bars', print_sep='&'); S = loads(dumps(R))
    170171    sage: R == S
    171172    True
    172173    sage: repr(S(2777))[3:]
    173174    '4&2&1&0&2'
     175    sage: TestSuite(R).run()
    174176
    175177    sage: R = ZpCA(5, 15, print_mode='bars', print_sep='&'); S = loads(dumps(R))
    176178    sage: R == S
    177179    True
    178180    sage: repr(S(2777))[3:]
    179181    '4&2&1&0&2'
     182    sage: TestSuite(R).run()
    180183
     184.. todo:: remove the loads tests above; the TestSuite should be sufficient
    181185"""
    182186
    183187from generic_nodes import pAdicFieldBaseGeneric, \
  • sage/rings/real_lazy.pxd

    diff --git a/sage/rings/real_lazy.pxd b/sage/rings/real_lazy.pxd
    a b from sage.structure.element cimport Ring 
    44cdef class LazyField(Field):
    55    cpdef interval_field(self, prec=*)
    66
    7 cdef class RealLazyField_class(LazyField):
    8     pass
    9    
    10 cdef class ComplexLazyField_class(LazyField):
    11     pass
    12 
    137cdef class LazyFieldElement(FieldElement):
    148    cdef LazyFieldElement _new_wrapper(self, value)
    159    cdef LazyFieldElement _new_binop(self, LazyFieldElement left, LazyFieldElement right, op)
  • sage/rings/real_lazy.pyx

    diff --git a/sage/rings/real_lazy.pyx b/sage/rings/real_lazy.pyx
    a b cdef named_constants = [ 'pi', 'e', 
    6161cdef class LazyField(Field):
    6262    """
    6363    The base class for lazy real fields.
     64
     65    .. WARNING::
     66
     67        LazyField uses :meth:`__getattr__`, to implement::
     68
     69            sage: CLF.pi
     70            3.141592653589794?
     71
     72        I (NT, 20/04/2012) did not manage to have __getattr__ call
     73        :meth:`Parent.__getattr__` in case of failure; hence we can't
     74        use this ``__getattr__`` trick for extension types to recover
     75        the methods from categories. Therefore, at this point, no
     76        concrete subclass of this class should be an extension type
     77        (which is probably just fine)::
     78
     79            sage: RLF.__class__
     80            <class 'sage.rings.real_lazy.RealLazyField_class_with_category'>
     81            sage: CLF.__class__
     82            <class 'sage.rings.real_lazy.ComplexLazyField_class_with_category'>
    6483    """
    6584    def __init__(self, base=None, names=None, normalize=True, category=None):
    6685        Field.__init__(self,base or self, names=names, normalize=normalize, category=category)
     86
    6787    def __getattr__(self, name):
    6888        """
    6989        Simulates a list of methods found on the real/complex rings.
    cdef class LazyField(Field): 
    135155        raise NotImplementedError, "subclasses must override this method"
    136156               
    137157
    138 cdef class RealLazyField_class(LazyField):
     158class RealLazyField_class(LazyField):
    139159    """
    140160    This class represents the set of real numbers to unspecified precision.
    141161    For the most part it simply wraps exact elements and defers evaluation
    cdef class RealLazyField_class(LazyField 
    161181        5.333333333333334?
    162182        sage: RealField(100)(a+5)
    163183        5.3333333333333333333333333333
     184
     185    TESTS::
     186
     187        sage: TestSuite(RLF).run()
    164188    """
    165189
    166190    def __init__(self):
    cdef class RealLazyField_class(LazyField 
    172196            sage: ComplexField(200).0 + RLF(1/3)
    173197            0.33333333333333333333333333333333333333333333333333333333333 + 1.0000000000000000000000000000000000000000000000000000000000*I
    174198        """
     199        LazyField.__init__(self)
    175200        self._populate_coercion_lists_(element_constructor=LazyWrapper)
    176201       
    177     cpdef interval_field(self, prec=None):
     202    def interval_field(self, prec=None):
    178203        """
    179204        Returns the interval field that represents the same mathematical
    180205        field as self.
    def RealLazyField(): 
    277302    return RLF
    278303
    279304
    280 cdef class ComplexLazyField_class(LazyField):
     305class ComplexLazyField_class(LazyField):
    281306    """
    282307    This class represents the set of real numbers to unspecified precision.
    283308    For the most part it simply wraps exact elements and defers evaluation
    cdef class ComplexLazyField_class(LazyFi 
    294319        1.0*I
    295320        sage: ComplexField(200)(a)
    296321        1.0000000000000000000000000000000000000000000000000000000000*I
     322
     323    TESTS::
     324
     325        sage: TestSuite(CLF).run(skip=["_test_prod"])
     326
     327    .. NOTE::
     328
     329        The following TestSuite failure::
     330
     331            sage: CLF._test_prod()
     332            Traceback (most recent call last):
     333            ...
     334            AssertionError: False is not true
     335
     336        is due to (acceptable?) numerical noise::
     337
     338            sage: x = CLF.I
     339            sage: x*x == x^2
     340            False
     341            sage: x*x
     342            -1
     343            sage: x^2
     344            -0.9999999999999999? + 0.?e-15*I
    297345    """
    298346
    299347    def __init__(self):
    cdef class ComplexLazyField_class(LazyFi 
    310358        LazyField.__init__(self, base=RLF)
    311359        self._populate_coercion_lists_(coerce_list=[LazyWrapperMorphism(RLF, self)], element_constructor=LazyWrapper)
    312360
    313     cpdef interval_field(self, prec=None):
     361    def interval_field(self, prec=None):
    314362        """
    315363        Returns the interval field that represents the same mathematical
    316364        field as self.
  • sage/schemes/elliptic_curves/constructor.py

    diff --git a/sage/schemes/elliptic_curves/constructor.py b/sage/schemes/elliptic_curves/constructor.py
    a b def EllipticCurve(x=None, y=None, j=None 
    101101        Elliptic Curve defined by y^2 = x^3 + 2*x + 3 over Ring of integers modulo 101
    102102        sage: E = EllipticCurve([F(2), F(3)])
    103103        sage: type(E)
    104         <class 'sage.schemes.elliptic_curves.ell_finite_field.EllipticCurve_finite_field'>
    105            
     104        <class 'sage.schemes.elliptic_curves.ell_finite_field.EllipticCurve_finite_field_with_category'>
     105        sage: E.category()
     106        Category of schemes over Ring of integers modulo 101
     107
    106108    In contrast, elliptic curves over `\ZZ/N\ZZ` with `N` composite
    107109    are of type "generic elliptic curve"::
    108110
    def EllipticCurve(x=None, y=None, j=None 
    111113        Elliptic Curve defined by y^2 = x^3 + 2*x + 3 over Ring of integers modulo 95
    112114        sage: E = EllipticCurve([F(2), F(3)])
    113115        sage: type(E)
    114         <class 'sage.schemes.elliptic_curves.ell_generic.EllipticCurve_generic'>
    115    
     116        <class 'sage.schemes.elliptic_curves.ell_generic.EllipticCurve_generic_with_category'>
     117        sage: E.category()
     118        Category of schemes over Ring of integers modulo 95
     119
    116120    The following is a curve over the complex numbers::
    117121   
    118122        sage: E = EllipticCurve(CC, [0,0,1,-1,0])
    def EllipticCurve(x=None, y=None, j=None 
    193197        sage: E = EllipticCurve([QQbar(1),3]); E
    194198        Elliptic Curve defined by y^2 = x^3 + x + 3 over Algebraic Field
    195199        sage: type(E)
    196         <class 'sage.schemes.elliptic_curves.ell_field.EllipticCurve_field'>
     200        <class 'sage.schemes.elliptic_curves.ell_field.EllipticCurve_field_with_category'>
    197201
    198202        sage: E = EllipticCurve([RR(1),3]); E
    199203        Elliptic Curve defined by y^2 = x^3 + 1.00000000000000*x + 3.00000000000000 over Real Field with 53 bits of precision
    200204        sage: type(E)
    201         <class 'sage.schemes.elliptic_curves.ell_field.EllipticCurve_field'>
     205        <class 'sage.schemes.elliptic_curves.ell_field.EllipticCurve_field_with_category'>
    202206
    203207        sage: E = EllipticCurve([i,i]); E
    204208        Elliptic Curve defined by y^2 = x^3 + I*x + I over Symbolic Ring
    205209        sage: type(E)
    206         <class 'sage.schemes.elliptic_curves.ell_field.EllipticCurve_field'>
     210        <class 'sage.schemes.elliptic_curves.ell_field.EllipticCurve_field_with_category'>
     211        sage: E.category()
     212        Category of schemes over Symbolic Ring
    207213        sage: is_field(SR)
    208214        True
    209215
    def EllipticCurve(x=None, y=None, j=None 
    212218        sage: E = EllipticCurve([t,0]); E
    213219        Elliptic Curve defined by y^2 = x^3 + t*x over Fraction Field of Univariate Polynomial Ring in t over Rational Field
    214220        sage: type(E)
    215         <class 'sage.schemes.elliptic_curves.ell_field.EllipticCurve_field'>
     221        <class 'sage.schemes.elliptic_curves.ell_field.EllipticCurve_field_with_category'>
     222        sage: E.category()
     223        Category of schemes over Fraction Field of Univariate Polynomial Ring in t over Rational Field
    216224
    217     See trac #12517::
     225    See :trac:`12517`::
    218226
    219227        sage: E = EllipticCurve([1..5])
    220228        sage: EllipticCurve(E.a_invariants())
  • sage/schemes/elliptic_curves/ell_finite_field.py

    diff --git a/sage/schemes/elliptic_curves/ell_finite_field.py b/sage/schemes/elliptic_curves/ell_finite_field.py
    a b class EllipticCurve_finite_field(Ellipti 
    7474            Elliptic Curve defined by y^2 = x^3 + 2*x + 3 over Ring of integers modulo 101
    7575            sage: E = EllipticCurve([F(2), F(3)])
    7676            sage: type(E)
    77             <class 'sage.schemes.elliptic_curves.ell_finite_field.EllipticCurve_finite_field'>
    78            
     77            <class 'sage.schemes.elliptic_curves.ell_finite_field.EllipticCurve_finite_field_with_category'>
     78            sage: E.category()
     79            Category of schemes over Ring of integers modulo 101
     80
    7981        Elliptic curves over `\ZZ/N\ZZ` with `N` composite are of type
    8082        "generic elliptic curve"::
    8183
    class EllipticCurve_finite_field(Ellipti 
    8486            Elliptic Curve defined by y^2 = x^3 + 2*x + 3 over Ring of integers modulo 95
    8587            sage: E = EllipticCurve([F(2), F(3)])
    8688            sage: type(E)
    87             <class 'sage.schemes.elliptic_curves.ell_generic.EllipticCurve_generic'>
     89            <class 'sage.schemes.elliptic_curves.ell_generic.EllipticCurve_generic_with_category'>
     90            sage: E.category()
     91            Category of schemes over Ring of integers modulo 95
     92            sage: TestSuite(E).run(skip=["_test_elements"])
    8893        """
    8994        if isinstance(x, list):
    9095            seq = Sequence(x)
  • sage/schemes/generic/algebraic_scheme.py

    diff --git a/sage/schemes/generic/algebraic_scheme.py b/sage/schemes/generic/algebraic_scheme.py
    a b class AlgebraicScheme(scheme.Scheme): 
    227227
    228228            sage: from sage.schemes.generic.algebraic_scheme import AlgebraicScheme
    229229            sage: P = ProjectiveSpace(3, ZZ)
     230            sage: P.category()
     231            Category of schemes over Integer Ring
    230232            sage: S = AlgebraicScheme(P); S
    231233            Subscheme of Projective Space of dimension 3 over Integer Ring
     234            sage: S.category()
     235            Category of schemes over Integer Ring
    232236        """
    233237        if not ambient_space.is_AmbientSpace(A):
    234238            raise TypeError, "A (=%s) must be an ambient space"
    235239        self.__A = A
    236240        self.__divisor_group = {}
     241        scheme.Scheme.__init__(self, A.base_scheme())
    237242
    238243    def _latex_(self):
    239244        """
  • sage/schemes/generic/projective_space.py

    diff --git a/sage/schemes/generic/projective_space.py b/sage/schemes/generic/projective_space.py
    a b class ProjectiveSpace_ring(AmbientSpace) 
    525525              x*y^2
    526526              To:   Spectrum of Rational Field
    527527              Defn: Structure map
     528
     529            sage: TestSuite(X).run(skip=["_test_an_element", "_test_elements", "_test_elements_eq", "_test_some_elements"])
    528530        """
    529531        from algebraic_scheme import AlgebraicScheme_subscheme_projective
    530532        return AlgebraicScheme_subscheme_projective(self, X)