Ticket #2329: 2329_reviewer.patch

File 2329_reviewer.patch, 12.2 KB (added by jdemeyer, 11 years ago)

Apply on top of previous patch

  • sage/libs/pari/gen.pyx

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1295884659 -3600
    # Node ID 47706148fc6e35526079a006ebefb084008ca9f8
    # Parent  a86897d86c3b5410023e6b529e753e42da7bc920
    #2329: Reviewer patch
    - Rename Pari to PARI in documentation
    - Make bnfisnorm() and rnfisnorm() private by prepending underscore
    - Clean up conversion from PARI GEN to number field elements
    - Add certify flag to pari_rnfnorm_data()
    - Avoid explicit bnfinit() call in pari_rnfnorm_data()
    - Change various Copyright statements to match the developer documentation
    
    diff -r a86897d86c3b -r 47706148fc6e sage/libs/pari/gen.pyx
    a b  
    66206620    def bnfisnorm(self, x, long flag=0):
    66216621        t0GEN(x)
    66226622        sig_on()
    6623         return self.new_gen(bnfisnorm(t0, self.g, flag))
     6623        return self.new_gen(bnfisnorm(self.g, t0, flag))
    66246624
    66256625    def bnfisprincipal(self, x, long flag=1):
    66266626        t0GEN(x)
  • sage/rings/integer.pyx

    diff -r a86897d86c3b -r 47706148fc6e sage/rings/integer.pyx
    a b  
    116116#
    117117#  Distributed under the terms of the GNU General Public License (GPL)
    118118#  as published by the Free Software Foundation; either version 2 of
    119 #  the License, or (at your option) any later version. 
    120 #                  http://www.gnu.org/licenses/ 
     119#  the License, or (at your option) any later version.
     120#                  http://www.gnu.org/licenses/
    121121#*****************************************************************************
    122122
    123123doc="""
     
    43724372        from sage.rings.rational_field import QQ
    43734373        return QQ(self).is_norm(K, element=element, proof=proof)
    43744374
    4375     def bnfisnorm(self, K, certify=True, extra_primes=0):
     4375    def _bnfisnorm(self, K, certify=True, extra_primes=0):
    43764376        r"""
    4377         See ``QQ(self).bnfisnorm()``.
     4377        See ``QQ(self)._bnfisnorm()``.
    43784378       
    43794379        EXAMPLES::
    43804380       
    4381             sage: 3.bnfisnorm(QuadraticField(-1, 'i'))
     4381            sage: 3._bnfisnorm(QuadraticField(-1, 'i'))
    43824382            (1, 3)
    4383             sage: 7.bnfisnorm(CyclotomicField(7))
     4383            sage: 7._bnfisnorm(CyclotomicField(7))
    43844384            (-zeta7^2 + zeta7, 1)
    43854385        """
    43864386        from sage.rings.rational_field import QQ
    4387         return QQ(self).bnfisnorm(K, certify=certify, extra_primes=extra_primes)
     4387        return QQ(self)._bnfisnorm(K, certify=certify, extra_primes=extra_primes)
    43884388
    43894389     
    43904390    def jacobi(self, b):
  • sage/rings/number_field/number_field.py

    diff -r a86897d86c3b -r 47706148fc6e sage/rings/number_field/number_field.py
    a b  
    25872587            self.__pari_bnf_certified = True
    25882588        return self.__pari_bnf_certified
    25892589
    2590     def pari_rnfnorm_data(self, L):
    2591         """
    2592         Return the pari rnfisnorminit data corresponding to the
     2590    def pari_rnfnorm_data(self, L, certify=True):
     2591        """
     2592        Return the PARI rnfisnorminit() data corresponding to the
    25932593        extension L/self.
    25942594
    25952595        EXAMPLES::
    25962596       
    2597             sage: K = NumberField(x**2-2,'alpha')
    2598             sage: L = K.extension(x**2+5, 'gamma')
     2597            sage: x = polygen(QQ)
     2598            sage: K = NumberField(x^2 - 2, 'alpha')
     2599            sage: L = K.extension(x^2 + 5, 'gamma')
    25992600            sage: ls = K.pari_rnfnorm_data(L) ; len(ls)
    26002601            8
    26012602
     
    26092610            raise ValueError, "L must be an extension of self"
    26102611       
    26112612        relpoly = L.defining_polynomial()
    2612         Kbnf = self.absolute_polynomial()._pari_with_name('y').bnfinit()
    2613         coeffs = [ a._pari_('y') for a in relpoly.coeffs() ]
    2614 
    2615         polrel = sage.libs.pari.gen.pari(coeffs).Polrev()
     2613        # Substitute the variable y in the defining polynomial of the
     2614        # bnf structure.  The syntax "'y" refers to the *variable* y
     2615        # as opposed to whatever value happens to be assigned to y.
     2616        Kbnf = self.pari_bnf(certify=certify).nf_subst("'y")
     2617        coeffs = [ a._pari_("y") for a in relpoly.coeffs() ]
     2618        polrel = pari(coeffs).Polrev()
    26162619        return Kbnf.rnfisnorminit(polrel)
    26172620
    26182621    def _gap_init_(self):
     
    29482951            sage: K.selmer_group([K.ideal(2, -a+1), K.ideal(3, a+1)], 3)
    29492952            [2, a + 1]
    29502953            sage: K.selmer_group([K.ideal(2, -a+1), K.ideal(3, a+1), K.ideal(a)], 3)
    2951             [2, a + 1, a]
     2954            [2, a + 1, -a]  # 32-bit
     2955            [2, a + 1, a]   # 64-bit
    29522956            sage: K.<a> = NumberField(polygen(QQ))
    29532957            sage: K.selmer_group([],5)
    29542958            []
  • sage/rings/number_field/number_field_element.pyx

    diff -r a86897d86c3b -r 47706148fc6e sage/rings/number_field/number_field_element.pyx
    a b  
    965965       
    966966        ALGORITHM:
    967967       
    968         Uses Pari's rnfisnorm. See self.rnfisnorm().
     968        Uses PARI's rnfisnorm. See self._rnfisnorm().
    969969
    970970        EXAMPLES::
    971971
     
    10331033        if L.relative_degree() == 1 or self.is_zero():
    10341034            return True, L(self)
    10351035
    1036         a, b = self.rnfisnorm(L, certify=proof)
     1036        a, b = self._rnfisnorm(L, certify=proof)
    10371037        if b == 1:
    10381038            assert a.norm(K) == self
    10391039            return True, a
     
    10471047        from sage.functions.log import log
    10481048        from sage.functions.other import floor
    10491049        extra_primes = floor(12*log(abs(M.discriminant()))**2)
    1050         a, b = self.rnfisnorm(L, certify=proof, extra_primes=extra_primes)
     1050        a, b = self._rnfisnorm(L, certify=proof, extra_primes=extra_primes)
    10511051        if b == 1:
    10521052            assert a.norm(K) == self
    10531053            return True, a
     
    10561056            raise NotImplementedError, "is_norm is not implemented unconditionally for norms from non-Galois number fields"
    10571057        return False, None
    10581058
    1059     def rnfisnorm(self, L, certify=True, extra_primes=0):
     1059    def _rnfisnorm(self, L, certify=True, extra_primes=0):
    10601060        r"""
    1061         Gives the output of the Pari function rnfisnorm.
     1061        Gives the output of the PARI function rnfisnorm.
    10621062       
    10631063        This tries to decide whether the number field element self is
    10641064        the norm of some x in the extension L/K (with K = self.parent()).
     
    10811081        INPUT:
    10821082       
    10831083         - L -- a relative number field with base field self.parent()
    1084          - certify -- whether to certify outputs of Pari init functions.
     1084         - certify -- whether to certify outputs of PARI init functions.
    10851085           If false, truth of the output depends on GRH.
    10861086         - extra_primes -- an integer as explained above.
    10871087
     
    10921092       
    10931093        ALGORITHM:
    10941094       
    1095         Uses Pari's rnfisnorm.
     1095        Uses PARI's rnfisnorm.
    10961096       
    10971097        EXAMPLES::
    10981098       
    10991099            sage: K.<a> = NumberField(x^3 + x^2 - 2*x - 1, 'a')
    11001100            sage: P.<X> = K[]
    11011101            sage: L = NumberField(X^2 + a^2 + 2*a + 1, 'b')
    1102             sage: K(17).rnfisnorm(L)
     1102            sage: K(17)._rnfisnorm(L)
    11031103            ((a^2 - 2)*b - 4, 1)
    11041104           
    11051105            sage: K.<a> = NumberField(x^3 + x + 1)
    11061106            sage: Q.<X> = K[]
    11071107            sage: L.<b> = NumberField(X^4 + a)
    1108             sage: t = (-a).rnfisnorm(L); t
     1108            sage: t = (-a)._rnfisnorm(L); t
    11091109            (b^3 + 1, 1)
    11101110            sage: t[0].norm(K)
    11111111            -a
    1112             sage: t = K(3).rnfisnorm(L); t
     1112            sage: t = K(3)._rnfisnorm(L); t
    11131113            ((-a^2 - 1)*b^3 + b^2 + a*b + a^2 + 1, -3*a)
    11141114            sage: t[0].norm(K)*t[1]
    11151115            3
     
    11181118
    11191119            sage: K.<a, b> = NumberField([x^2 - 2, x^2 - 3])
    11201120            sage: L.<c> = K.extension(x^3 + 2)
    1121             sage: t = (2*a + b).rnfisnorm(L); t[1]
     1121            sage: t = (2*a + b)._rnfisnorm(L); t[1]
    11221122            (b - 2)*a + 2*b - 3
    11231123            sage: t[0].norm(K)*t[1]
    11241124            2*a + b
     
    11361136        if (not is_RelativeNumberField(L)) or L.base_field() != K:
    11371137            raise ValueError, "L (=%s) must be a relative number field with base field K (=%s) in rnfisnorm" % (L, K)
    11381138
    1139         if certify:
    1140             K.pari_bnf_certify()
    1141 
    1142         rnf_data = K.pari_rnfnorm_data(L)
     1139        rnf_data = K.pari_rnfnorm_data(L, certify=certify)
    11431140        x, q = self._pari_('y').rnfisnorm(rnf_data)
    1144 
    1145         degL = L.relative_degree()
    1146         repx = [K(x.lift().polcoeff(i).lift()) for i in range(degL)]
    1147         x = L(repx)
    1148 
    1149         from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
    1150         degK = K.absolute_degree()
    1151         coeffsq = [q.lift().polcoeff(i)._sage_() for i in range(degK)]
    1152         q = PolynomialRing(QQ, 't')(coeffsq)(K.absolute_generator())
    1153 
    1154         return x, q
     1141        return L(x), K(q)
    11551142
    11561143    def _mpfr_(self, R):
    11571144        """
  • sage/rings/rational.pyx

    diff -r a86897d86c3b -r 47706148fc6e sage/rings/rational.pyx
    a b  
    3434#       Copyright (C) 2004, 2006 William Stein <wstein@gmail.com>
    3535#
    3636#  Distributed under the terms of the GNU General Public License (GPL)
     37#  as published by the Free Software Foundation; either version 2 of
     38#  the License, or (at your option) any later version.
    3739#                  http://www.gnu.org/licenses/
    38 ###########################################################################
     40#*****************************************************************************
    3941
    4042include "../ext/interrupt.pxi"  # ctrl-c interrupt block support
    4143include "../ext/gmp.pxi"
     
    11961198       
    11971199        ALGORITHM:
    11981200       
    1199         Uses Pari's bnfisnorm. See self.bnfisnorm().
     1201        Uses PARI's bnfisnorm. See self._bnfisnorm().
    12001202
    12011203        EXAMPLES::
    12021204
     
    12561258            if b:
    12571259                x = M_to_L(x)
    12581260            return b, x
    1259         a, b = self.bnfisnorm(L, certify=proof)
     1261        a, b = self._bnfisnorm(L, certify=proof)
    12601262        if b == 1:
    12611263            assert a.norm() == self
    12621264            return True, a
     
    12661268        from sage.functions.log import log
    12671269        from sage.functions.other import floor
    12681270        extra_primes = floor(12*log(abs(M.discriminant()))**2)
    1269         a, b = self.bnfisnorm(L, certify=proof, extra_primes=extra_primes)
     1271        a, b = self._bnfisnorm(L, certify=proof, extra_primes=extra_primes)
    12701272        if b == 1:
    12711273            assert a.norm() == self
    12721274            return True, a
     
    12741276            raise NotImplementedError, "is_norm is not implemented unconditionally for norms from non-Galois number fields"
    12751277        return False, None
    12761278
    1277     def bnfisnorm(self, K, certify=True, extra_primes=0):
     1279    def _bnfisnorm(self, K, certify=True, extra_primes=0):
    12781280        r"""
    1279         This gives the output of the Pari function bnfisnorm.
     1281        This gives the output of the PARI function bnfisnorm.
    12801282       
    12811283        Tries to tell whether the rational number self is the norm of some
    12821284        element y in K. Returns a pair (a, b) where self = Norm(a)*b. Looks for
     
    13091311       
    13101312        ALGORITHM:
    13111313       
    1312         Uses Pari's bnfisnorm.
     1314        Uses PARI's bnfisnorm.
    13131315       
    13141316        EXAMPLES::
    13151317       
    1316             sage: QQ(2).bnfisnorm(QuadraticField(-1, 'i'))
     1318            sage: QQ(2)._bnfisnorm(QuadraticField(-1, 'i'))
    13171319            (i + 1, 1)
    1318             sage: 7.bnfisnorm(NumberField(x^3-2, 'b'))
     1320            sage: 7._bnfisnorm(NumberField(x^3-2, 'b'))
    13191321            (1, 7)
    13201322       
    13211323        AUTHORS:
     
    13271329        from sage.rings.number_field.all import is_NumberField
    13281330        if not is_NumberField(K):
    13291331            raise ValueError, "K must be a NumberField in bnfisnorm"
    1330         if certify:
    1331             K.pari_bnf_certify()
    13321332
    1333         a, b = self._pari_().bnfisnorm(K.pari_bnf(), flag=extra_primes)
    1334         deg = K.degree()
    1335         coeffs = [ a.lift().polcoeff(i)._sage_() for i in range(deg) ]
    1336         from sage.rings.rational_field import QQ
    1337         return K(coeffs), QQ(b._sage_())
     1333        a, b = K.pari_bnf(certify=certify).bnfisnorm(self, flag=extra_primes)
     1334        return K(a), Rational(b)
    13381335
    13391336
    13401337    def is_perfect_power(self, expected_value=False):