Ticket #8446: trac_8446.patch

File trac_8446.patch, 5.1 KB (added by Robert Miller, 13 years ago)
  • sage/rings/number_field/number_field.py

    # HG changeset patch
    # User Robert L. Miller <rlm@rlmiller.org>
    # Date 1267991902 28800
    # Node ID e1cf80406e872e0508a70115d6bd258ef63b6d22
    # Parent  4191262c2f22897f39820f1e45ce205d97b1b1f0
    #8446: Avoid 0^0 in Selmer groups of number fields
    
    diff -r 4191262c2f22 -r e1cf80406e87 sage/rings/number_field/number_field.py
    a b  
    974974        r"""
    975975        Make x into an element of this number field, possibly not canonically.
    976976
    977         EXAMPLES:
     977        INPUT:
     978       
     979            - ``x`` - the element
     980         
     981        OUTPUT:
     982       
     983            ``x``, as an element of this number field
     984
     985        TESTS::
     986
    978987            sage: K.<a> = NumberField(x^3 + 17)
    979988            sage: K(a) is a
    980989            True
     
    983992            sage: K('1').parent()
    984993            Number Field in a with defining polynomial x^3 + 17
    985994            sage: K(3/5).parent()
    986             Number Field in a with defining polynomial x^3 + 17       
     995            Number Field in a with defining polynomial x^3 + 17
     996            sage: K.<a> = NumberField(polygen(QQ)^2 - 5)
     997            sage: F.<b> = K.extension(polygen(K))
     998            sage: F([a])
     999            a
    9871000        """
    9881001        if isinstance(x, number_field_element.NumberFieldElement):
    9891002            K = x.parent()
     
    10061019                 self.base_ring().has_coerce_map_from(x.parent().base_ring())):
    10071020            if len(x) != self.relative_degree():
    10081021                raise ValueError, "Length must be equal to the degree of this number field"
    1009             return sum([ x[i]*self.gen(0)**i for i in range(self.relative_degree()) ])
     1022            result = x[0]
     1023            for i in xrange(1,self.relative_degree()):
     1024                result += x[i]*self.gen(0)**i
     1025            return result
    10101026        return self._coerce_non_number_field_element_in(x)
    10111027
    10121028    def _coerce_from_str(self, x):
     
    26742690        ###############################################################
    26752691        # The following line computes S-class gp and S-units in Pari, #
    26762692        # assuming the Generalized Riemann Hypothesis + other         #
    2677         # "heuristic" assumptions (GRH++).                            #
     2693        # "heuristic" assumptions (GRH++), or nothing if certify.     #
    26782694        ###############################################################
    2679         D_gp = gp(self.pari_bnf())
    2680         if proof:
    2681             ################################################
    2682             # The following line attempts to remove GRH++. #
    2683             # If the result is not provable, may output an #
    2684             # error message, or loop indefinitely.         #
    2685             ################################################
    2686             assert D_gp.bnfcertify() == 1
     2695        D_gp = gp(self.pari_bnf(certify=proof))
    26872696       
    26882697        S_gp = [convert_to_idealprimedec_form(self, p) for p in S]
    26892698        units = []
     
    26912700        result = D_gp.bnfsunit(S_gp)
    26922701        x = self.gen()
    26932702        for unit in result[1]:
    2694             sage_unit = 0
    2695             for i in xrange(unit.poldegree()+1):
     2703            sage_unit = QQ(unit.polcoeff(0))
     2704            for i in xrange(1, unit.poldegree()+1):
    26962705                sage_unit += QQ(unit.polcoeff(i))*x**i
    26972706            units.append(sage_unit)
    26982707        units += self.unit_group().gens()
    26992708
    27002709        IB = []
    27012710        for f_gp in D_gp[7][7]:
    2702             f = 0
    2703             for i in xrange(f_gp.length()):
     2711            f = QQ(f_gp.polcoeff(0))
     2712            for i in xrange(1, f_gp.length()):
    27042713                f += QQ(f_gp.polcoeff(i))*x**i
    27052714            IB.append(f)
    27062715        clgp_gens = []
     
    27562765            [2, a + 1]
    27572766            sage: K.selmer_group([K.ideal(2, -a+1), K.ideal(3, a+1), K.ideal(a)], 3)
    27582767            [2, a + 1, -a]
     2768            sage: K.<a> = NumberField(polygen(QQ))
     2769            sage: K.selmer_group([],5)
     2770            []
    27592771
    27602772        """
    27612773        units, clgp_gens = self._S_class_group_and_units(tuple(S), proof=proof)
  • sage/rings/residue_field.pyx

    diff -r 4191262c2f22 -r e1cf80406e87 sage/rings/residue_field.pyx
    a b  
    184184        Residue field of Fractional ideal (1/2*a^2 - 1/2*a + 1)
    185185        sage: F.degree()
    186186        1
     187   
     188    TESTS::
     189
     190        sage: K.<a> = NumberField(polygen(QQ))
     191        sage: K.residue_field(K.ideal(3))
     192        Residue field of Fractional ideal (3)
     193
    187194    """
    188195    if isinstance(names, tuple):
    189196        if len(names) > 0:
     
    233240    from sage.matrix.constructor import matrix
    234241    try:
    235242        x = K.gen()
    236         M = matrix(k, n+1, n, [to_vs(x**i).list() for i in range(n+1)])
     243        if not x:
     244            LL = [to_vs(1).list()] + [to_vs(x**i).list() for i in range(1,n+1)]
     245            M = matrix(k, n+1, n, LL)
     246        else:
     247            M = matrix(k, n+1, n, [to_vs(x**i).list() for i in range(n+1)])
    237248        W = M.transpose().echelon_form()
    238249        if M.rank() == n:
    239250            PB = M.matrix_from_rows(range(n))