Ticket #1183: trac-1183-step6.patch

File trac-1183-step6.patch, 16.9 KB (added by was, 15 years ago)
  • sage/modules/free_module_element.pyx

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1197713024 28800
    # Node ID 1099ef89b418560ff29c107c4292c0a1d929ed10
    # Parent  77b659019e2f7a7c940012f278683c0214ab3806
    Trac #1183 -- residue class fields (finish).
    
    diff -r 77b659019e2f -r 1099ef89b418 sage/modules/free_module_element.pyx
    a b cdef class FreeModuleElement_generic_den 
    908908                raise TypeError, "entries (=%s) must be a list"%(entries, )
    909909           
    910910            if len(entries) != self.degree():
    911                 raise ArithmeticError, "entries must be a list of length %s"%\
     911                raise TypeError, "entries must be a list of length %s"%\
    912912                            self.degree()
    913913            if coerce:
    914914                try:
  • sage/rings/finite_field.py

    diff -r 77b659019e2f -r 1099ef89b418 sage/rings/finite_field.py
    a b class FiniteField_prime_modn(FiniteField 
    418418        return self.__char
    419419
    420420    def gen(self, n=0):
     421        """
     422        Return generator of this finite field.
     423       
     424        EXAMPLES:
     425            sage: k = GF(13)
     426            sage: k.gen()
     427            1
     428            sage: k.gen(1)
     429            Traceback (most recent call last):
     430            ...
     431            IndexError: only one generator
     432        """
     433        if n != 0:
     434            raise IndexError, "only one generator"
    421435        return self.__gen
    422436
    423437    def __iter__(self):
  • sage/rings/finite_field_givaro.pyx

    diff -r 77b659019e2f -r 1099ef89b418 sage/rings/finite_field_givaro.pyx
    a b cdef class FiniteField_givaro(FiniteFiel 
    595595
    596596        EXAMPLES:
    597597            sage: k = GF(3^4, 'b'); k.gen()
    598             b       
     598            b
     599            sage: k.gen(1)
     600            Traceback (most recent call last):
     601            ...
     602            IndexError: only one generator
    599603        """
    600604        cdef int r
    601605        from sage.rings.arith import primitive_root
  • sage/rings/number_field/number_field.py

    diff -r 77b659019e2f -r 1099ef89b418 sage/rings/number_field/number_field.py
    a b class NumberField_cyclotomic(NumberField 
    41614161            sage: O = K.maximal_order()
    41624162            sage: K(O.1)
    41634163            z
    4164             sage: sage: K(O.1^2 + O.1 - 2)
     4164            sage: K(O.1^2 + O.1 - 2)
    41654165            z^2 + z - 2
    41664166        """
    41674167        if isinstance(x, number_field_element.NumberFieldElement):
  • sage/rings/number_field/number_field_ideal.py

    diff -r 77b659019e2f -r 1099ef89b418 sage/rings/number_field/number_field_ideal.py
    a b class NumberFieldIdeal(Ideal_fractional) 
    848848            sage: quo
    849849            Partially defined quotient map from Number Field in i with defining polynomial x^2 + 1 to an explicit vector space representation for the quotient of the ring of integers by (p,I) for the ideal I=Fractional ideal (-i - 2).
    850850            sage: lift
    851             Lifting map to Order in Number Field in i with defining polynomial x^2 + 1 from quotient of integers by Fractional ideal (-i - 2)
     851            Lifting map to Maximal Order in Number Field in i with defining polynomial x^2 + 1 from quotient of integers by Fractional ideal (-i - 2)
    852852        """
    853853        return quotient_char_p(self, p)
    854854
    def basis_to_module(B, K): 
    10201020    """
    10211021    V, from_V, to_V = K.absolute_vector_space()
    10221022    M = ZZ**(V.dimension())
    1023     C = [to_V(K(b.list())) for b in B]
     1023    C = [to_V(K(b)) for b in B]
    10241024    return M.span_of_basis(C)
    10251025       
    10261026
  • sage/rings/residue_field.pyx

    diff -r 77b659019e2f -r 1099ef89b418 sage/rings/residue_field.pyx
    a b EXAMPLES: 
    1212    sage: k.order()
    1313    841
    1414
     15We reduce mod a prime for which the ring of integers is not
     16monogenic (i.e., 2 is an essential discriminant divisor):
     17    sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 8)
     18    sage: F = K.factor_integer(2); F
     19    (Fractional ideal (1/2*a^2 - 1/2*a + 1)) * (Fractional ideal (a^2 - 2*a + 3)) * (Fractional ideal (3/2*a^2 - 5/2*a + 4))
     20    sage: F[0][0].residue_field()
     21    Residue field of Fractional ideal (1/2*a^2 - 1/2*a + 1)
     22    sage: F[1][0].residue_field()
     23    Residue field of Fractional ideal (a^2 - 2*a + 3)
     24    sage: F[2][0].residue_field()
     25    Residue field of Fractional ideal (3/2*a^2 - 5/2*a + 4)
     26
    1527AUTHORS:
    1628    -- David Roe (2007-10-3): initial version
    1729    -- William Stein (2007-12): bug fixes
    TESTS: 
    2335    sage: a = ff(z)
    2436    sage: parent(a*a)
    2537    Residue field in zbar of Fractional ideal (17)
     38
     39Reducing a curve modulo a prime:
     40    sage: K.<s> = NumberField(x^2+23)
     41    sage: OK = K.ring_of_integers()
     42    sage: E = EllipticCurve([0,0,0,K(1),K(5)])
     43    sage: pp = K.factor_integer(13)[0][0]
     44    sage: Fpp = OK.residue_field(pp)
     45    sage: E.base_extend(Fpp)
     46    Elliptic Curve defined by y^2  = x^3 + x + 5 over Residue field of Fractional ideal (13, s - 4)
    2647"""
    2748
    2849#*****************************************************************************
    from sage.rings.polynomial.polynomial_ri 
    5576
    5677residue_field_cache = {}
    5778
    58 def ResidueField(p, names = None, check = True, trygen=False):
     79def ResidueField(p, names = None, check = True):
    5980    """
    6081    A function that returns the residue class field of a prime ideal p
    6182    of the ring of integers of a number field.
    def ResidueField(p, names = None, check  
    126147            names = str(names[0])
    127148        else:
    128149            names = None
    129     key = (p, names, trygen)
     150    key = (p, names)
    130151    if residue_field_cache.has_key(key):
    131152        k = residue_field_cache[key]()
    132153        if k is not None:
    def ResidueField(p, names = None, check  
    151172    n = p.residue_class_degree()
    152173    gen_ok = False
    153174    from sage.matrix.constructor import matrix
    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
     175    try:
     176        x = K.gen()
     177        M = matrix(k, n+1, n, [to_vs(x**i).list() for i in range(n+1)])
     178        W = M.transpose().echelon_form()
     179        if M.rank() == n:
     180            PB = M.matrix_from_rows(range(n))
     181            gen_ok = True
     182            f = R((-W.column(n)).list() + [1])
     183    except (TypeError, ZeroDivisionError):
     184        pass
    167185    if not gen_ok:
    168186        bad = True
    169187        for u in U: # using this iterator may not be optimal, we may get a long string of non-generators
    class ResidueField_generic(Field): 
    199217class ResidueField_generic(Field):
    200218    """
    201219    The class representing a generic residue field.
     220
     221    EXAMPLES:
     222        sage: I = QQ[i].factor_integer(2)[0][0]; I
     223        Fractional ideal (I + 1)
     224        sage: k = I.residue_field(); k
     225        Residue field of Fractional ideal (I + 1)
     226        sage: type(k)
     227        <class 'sage.rings.residue_field.ResidueFiniteField_prime_modn'>
    202228    """
    203229    def __init__(self, p, f, intp):
    204230        """
    class ResidueField_generic(Field): 
    232258
    233259    def lift(self, x):
    234260        """
    235         Returns a lift of x to the Order, returning a "polynomial" in the generator with coefficients between 0 and p-1.
    236        
     261        Returns a lift of x to the Order, returning a "polynomial" in the
     262        generator with coefficients between 0 and $p-1$.
     263
    237264        EXAMPLES:
    238265            sage: K.<a> = NumberField(x^3-7)
    239266            sage: P = K.ideal(29).factor()[0][0]
    class ResidueField_generic(Field): 
    251278        else:
    252279            return self.f.lift(x)
    253280
     281    def reduction_map(self):
     282        """
     283        Return the partially defined reduction map from the number
     284        field to this residue class field.
     285
     286        EXAMPLES:
     287            sage: I = QQ[2^(1/3)].factor_integer(2)[0][0]; I
     288            Fractional ideal (-a)
     289            sage: k = I.residue_field(); k
     290            Residue field of Fractional ideal (-a)
     291            sage: pi = k.reduction_map(); pi
     292            Partially defined reduction map from Number Field in a with defining polynomial x^3 - 2 to Residue field of Fractional ideal (-a)
     293            sage: pi.domain()
     294            Number Field in a with defining polynomial x^3 - 2
     295            sage: pi.codomain()
     296            Residue field of Fractional ideal (-a)
     297        """
     298        return self._structure[0]
     299
     300    def lift_map(self):
     301        """
     302        EXAMPLES:
     303            sage: I = QQ[3^(1/3)].factor_integer(5)[1][0]; I
     304            Fractional ideal (-a + 2)
     305            sage: k = I.residue_field(); k
     306            Residue field of Fractional ideal (-a + 2)
     307            sage: f = k.lift_map(); f
     308            Lifting map from Residue field of Fractional ideal (-a + 2) to Number Field in a with defining polynomial x^3 - 3
     309            sage: f.domain()
     310            Residue field of Fractional ideal (-a + 2)
     311            sage: f.codomain()
     312            Number Field in a with defining polynomial x^3 - 3
     313            sage: f(k.0)
     314            1
     315        """
     316        return self._structure[1]
     317
    254318    def __cmp__(self, x):
    255319        """
    256         Compares two residue fields: they are equal iff the primes defining them are equal.
     320        Compares two residue fields: they are equal iff the primes
     321        defining them are equal.
    257322       
    258323        EXAMPLES:
    259324            sage: K.<a> = NumberField(x^3-11)
    class ResidueField_generic(Field): 
    272337        return cmp(type(self), type(x))
    273338
    274339class ReductionMap:
     340    """
     341    A reduction map from a (subset) of a number field to this residue
     342    class field.
     343
     344    EXAMPLES:
     345        sage: I = QQ[sqrt(17)].factor_integer(5)[0][0]; I
     346        Fractional ideal (5)
     347        sage: k = I.residue_field(); k
     348        Residue field in sqrt17bar of Fractional ideal (5)
     349        sage: R = k.reduction_map(); R
     350        Partially defined reduction map from Number Field in sqrt17 with defining polynomial x^2 - 17 to Residue field in sqrt17bar of Fractional ideal (5)
     351    """
    275352    def __init__(self, K, F, to_vs, PBinv):
     353        """
     354        Create a reduction map.
     355
     356        EXAMPLES:
     357            sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 8)
     358            sage: F = K.factor_integer(2)[0][0].residue_field()
     359            sage: F.reduction_map()
     360            Partially defined reduction map from Number Field in a with defining polynomial x^3 + x^2 - 2*x + 8 to Residue field of Fractional ideal (1/2*a^2 - 1/2*a + 1)
     361        """
    276362        self.__K = K
    277363        self.__F = F   # finite field
    278364        self.__to_vs = to_vs
    279365        self.__PBinv = PBinv
    280366
     367    def domain(self):
     368        """
     369        Return the domain of this reduction map.
     370
     371        EXAMPLES:
     372            sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 32)
     373            sage: F = K.factor_integer(2)[0][0].residue_field()
     374            sage: F.reduction_map().domain()
     375            Number Field in a with defining polynomial x^3 + x^2 - 2*x + 32
     376        """
     377        return self.__K
     378
     379    def codomain(self):
     380        """
     381        Return the codomain of this reduction map.
     382
     383        EXAMPLES:
     384            sage: K.<a> = NumberField(x^3 + 128)
     385            sage: F = K.factor_integer(2)[0][0].residue_field()
     386            sage: F.reduction_map().codomain()
     387            Residue field of Fractional ideal (-1/4*a)       
     388        """
     389        return self.__F
     390
    281391    def __call__(self, x):
     392        """
     393        Apply this reduction map to an element that coerces into the number field.
     394
     395        If x doesn't map because the denominator is not coprime to the
     396        prime ideal, then a ZeroDivisionError exception is raised.
     397
     398        EXAMPLES:
     399            sage: K.<a> = NumberField(x^2 + 1)
     400            sage: F = K.factor_integer(2)[0][0].residue_field()
     401            sage: r = F.reduction_map(); r
     402            Partially defined reduction map from Number Field in a with defining polynomial x^2 + 1 to Residue field of Fractional ideal (a + 1)
     403            sage: r(2 + a)
     404            1
     405            sage: r(a/2)
     406            Traceback (most recent call last):
     407            ...
     408            ZeroDivisionError: Inverse does not exist.
     409        """
    282410        # The reduction map is just x |--> F(to_vs(x) * (PB**(-1)))
    283411        x = self.__K(x)
    284412        return self.__F(self.__to_vs(x) * self.__PBinv)
    285413
    286414    def __repr__(self):
     415        """
     416        EXAMPLES:
     417            sage: K.<theta_5> = CyclotomicField(5)
     418            sage: F = K.factor_integer(7)[0][0].residue_field()
     419            sage: F.reduction_map().__repr__()
     420            'Partially defined reduction map from Cyclotomic Field of order 5 and degree 4 to Residue field in theta_5bar of Fractional ideal (7)'
     421        """
    287422        return "Partially defined reduction map from %s to %s"%(self.__K, self.__F)
    288423
    289424class LiftingMap:
     425    """
     426    Lifting map from residue class field to number field.
     427
     428    EXAMPLES:
     429        sage: K.<a> = NumberField(x^3 + 2)
     430        sage: F = K.factor_integer(5)[0][0].residue_field()
     431        sage: F.degree()
     432        2
     433        sage: L = F.lift_map(); L
     434        Lifting map from Residue field in abar of Fractional ideal (a^2 + 2*a - 1) to Number Field in a with defining polynomial x^3 + 2
     435        sage: L(F.0^2)
     436        3*a + 1
     437        sage: L(3*a + 1) == F.0^2
     438        True
     439    """
    290440    def __init__(self, K, F, to_order, PB):
     441        """
     442        Create a lifting map.
     443
     444        EXAMPLES:
     445            sage: K.<theta_5> = CyclotomicField(5)
     446            sage: F = K.factor_integer(7)[0][0].residue_field()
     447            sage: F.lift_map()
     448            Lifting map from Residue field in theta_5bar of Fractional ideal (7) to Cyclotomic Field of order 5 and degree 4
     449        """
    291450        self.__K = K
    292451        self.__F = F   # finite field
    293452        self.__to_order = to_order
    294453        self.__PB = PB
    295454
     455    def domain(self):
     456        """
     457        Return the domain of this lifting map.
     458
     459        EXAMPLES:
     460            sage: K.<a> = NumberField(x^5 + 2)
     461            sage: F = K.factor_integer(7)[0][0].residue_field()
     462            sage: L = F.lift_map(); L
     463            Lifting map from Residue field in abar of Fractional ideal (-2*a^4 + a^3 - 4*a^2 + 2*a - 1) to Number Field in a with defining polynomial x^5 + 2
     464            sage: L.domain()
     465            Residue field in abar of Fractional ideal (-2*a^4 + a^3 - 4*a^2 + 2*a - 1)
     466        """
     467        return self.__F
     468
     469    def codomain(self):
     470        """
     471        Return the codomain of this lifting map.
     472
     473        EXAMPLES:
     474            sage: K.<a> = CyclotomicField(7)
     475            sage: F = K.factor_integer(5)[0][0].residue_field()
     476            sage: L = F.lift_map(); L
     477            Lifting map from Residue field in abar of Fractional ideal (5) to Cyclotomic Field of order 7 and degree 6
     478            sage: L.codomain()
     479            Cyclotomic Field of order 7 and degree 6       
     480        """
     481        return self.__K
     482
    296483    def __call__(self, x):
     484        """
     485        Lift from this residue class field to the number field.
     486
     487        EXAMPLES:
     488            sage: K.<a> = CyclotomicField(7)
     489            sage: F = K.factor_integer(5)[0][0].residue_field()
     490            sage: L = F.lift_map(); L
     491            Lifting map from Residue field in abar of Fractional ideal (5) to Cyclotomic Field of order 7 and degree 6
     492            sage: L(F.0)
     493            a
     494            sage: F(a)
     495            abar
     496        """
    297497        # The lifting map is just x |--> to_order(x * PB)
    298498        x = self.__F(x)
    299499        v = x.polynomial().padded_list(self.__F.degree())
    300500        return self.__to_order(self.__PB.linear_combination_of_rows(v))
    301501
    302502    def __repr__(self):
     503        """
     504        EXAMPLES:
     505            sage: K.<theta_12> = CyclotomicField(12)
     506            sage: F.<tmod> = K.factor_integer(7)[0][0].residue_field()
     507            sage: F.lift_map().__repr__()
     508            'Lifting map from Residue field in tmod of Fractional ideal (-3*theta_12^2 + 1) to Cyclotomic Field of order 12 and degree 4'
     509        """
    303510        return "Lifting map from %s to %s"%(self.__F, self.__K)
    304511
    305512cdef class NFResidueFieldHomomorphism(ResidueFieldHomomorphism):
    class ResidueFiniteField_givaro(ResidueF 
    585792            except:
    586793                raise TypeError
    587794
    588         #try:
    589         #    return self.coerce_map_from(self.f.domain())(self.f.domain()(x))
    590         #except (AttributeError, TypeError):
    591         #    return FiniteField_givaro.__call__(self, x)
    592795
    593796