Ticket #1183: trac-1183-step5.patch

File trac-1183-step5.patch, 4.6 KB (added by was, 15 years ago)
  • sage/modules/quotient_module.py

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1197632483 28800
    # Node ID 77b659019e2f7a7c940012f278683c0214ab3806
    # Parent  10855f8c76c12b6ccc037fb4bb9b801b74f06c27
    Trac #1183 -- More work on residue class fields. (not done yet)
    
    diff -r 10855f8c76c1 -r 77b659019e2f sage/modules/quotient_module.py
    a b class FreeModule_ambient_field_quotient( 
    173173
    174174        An element coerces in if it can be coerced into V, or if not at least if
    175175        if it can be made sense of as a list of length the dimension of self.
    176        
    177        
     176               
    178177        EXAMPLES:
    179178        We create a 2-dimensional quotient of a 3-dimension ambient vector space.
    180179            sage: M = QQ^3 / [[1,2,3]]
    class FreeModule_ambient_field_quotient( 
    193192            (1, 2)
    194193        """
    195194        try:
    196             return self._coerce_impl(x)
    197         except TypeError:
     195            if x.parent() is self:
     196                return x
     197        except AttributeError:
    198198            pass
    199199        try:
    200200            return FreeModule_ambient_field.__call__(self, x)
  • sage/rings/residue_field.pyx

    diff -r 10855f8c76c1 -r 77b659019e2f sage/rings/residue_field.pyx
    a b from sage.rings.polynomial.polynomial_ri 
    5555
    5656residue_field_cache = {}
    5757
    58 def ResidueField(p, names = None, check = True):
     58def ResidueField(p, names = None, check = True, trygen=False):
    5959    """
    6060    A function that returns the residue class field of a prime ideal p
    6161    of the ring of integers of a number field.
    6262
    6363    INPUT:
    64         p -- a prime integer or prime ideal of an order in a number
    65              field.
     64        p -- a prime ideal of an order in a number field.
    6665        names -- the variable name for the finite field created.
    6766                 Defaults to the name of the number field variable but
    6867                 with bar placed after it.
    def ResidueField(p, names = None, check  
    7675        sage: P = K.ideal(29).factor()[0][0]
    7776        sage: ResidueField(P)
    7877        Residue field in abar of Fractional ideal (2*a^2 + 3*a - 10)
     78
     79    The result is cached:
     80        sage: ResidueField(P) is ResidueField(P)
     81        True
    7982        sage: k = K.residue_field(P); k
    8083        Residue field in abar of Fractional ideal (2*a^2 + 3*a - 10)
    8184        sage: k.order()
    def ResidueField(p, names = None, check  
    123126            names = str(names[0])
    124127        else:
    125128            names = None
    126     key = (p, names)
     129    key = (p, names, trygen)
    127130    if residue_field_cache.has_key(key):
    128131        k = residue_field_cache[key]()
    129132        if k is not None:
    def ResidueField(p, names = None, check  
    148151    n = p.residue_class_degree()
    149152    gen_ok = False
    150153    from sage.matrix.constructor import matrix
    151     try:
    152         x = K.gen()
    153         M = matrix(k, n+1, n, [to_vs(x**i).list() for i in range(n+1)])
    154         W = M.transpose().echelon_form()
    155         if M.rank() == n:
    156             PB = M.matrix_from_rows(range(n))
    157             gen_ok = True
    158             f = R((-W.column(n)).list() + [1])
    159     except TypeError:
    160         pass
     154    if trygen:
     155        # This optimization not ready yet.
     156        try:
     157            x = K.gen()
     158            M = matrix(k, n+1, n, [to_vs(x**i).list() for i in range(n+1)])
     159            print M
     160            W = M.transpose().echelon_form()
     161            if M.rank() == n:
     162                PB = M.matrix_from_rows(range(n))
     163                gen_ok = True
     164                f = R((-W.column(n)).list() + [1])
     165        except (TypeError, ZeroDivisionError):
     166            pass
    161167    if not gen_ok:
    162168        bad = True
    163169        for u in U: # using this iterator may not be optimal, we may get a long string of non-generators
    class ResidueFiniteField_prime_modn(Resi 
    419425           intp -- the rational prime that p lies over.
    420426
    421427        EXAMPLES:
    422             sage: k = ResidueField(17); k
    423             Residue field of 17
    424             sage: type(k)
    425             <class 'sage.rings.residue_field.ResidueFiniteField_prime_modn'>
     428            sage: K.<i> = QuadraticField(-1)
     429            sage: kk = ResidueField(K.factor_integer(5)[0][0])
     430            sage: type(kk)
     431            <class 'sage.rings.residue_field.ResidueFiniteField_prime_modn'>       
    426432        """
    427433        self.p = p # Here because we have to create a NFResidueFieldHomomorphism before calling ResidueField_generic.__init__(self,...)
    428434        if im_gen is None: