Ticket #10677: 10677_check.patch

File 10677_check.patch, 3.2 KB (added by jdemeyer, 11 years ago)

Apply on top of previous patch

  • sage/rings/number_field/number_field_element.pyx

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1296916819 -3600
    # Node ID 434161ed8de2e3ef7ca13a4726408f3a61cd053a
    # Parent  55491f82f29f2567749b944b43e9e847727d6e73
    #10677: Check conversion of PARI absolute number field elements to Sage
    
    diff -r 55491f82f29f -r 434161ed8de2 sage/rings/number_field/number_field_element.pyx
    a b  
    260260            -5/3*a^2 + 5/3*a - 1/6
    261261            sage: K(pari("x^5/17"))
    262262            a^2
     263            sage: K(pari("Mod(-5/3*q^2 + 5/3*q - 1/6, q^3 - 999)"))  # Wrong modulus
     264            Traceback (most recent call last):
     265            ...
     266            ValueError: Coercion of PARI polmod with modulus x^3 - 999 into number field with defining polynomial x^3 - 17 failed
    263267
    264268        This example illustrates save and load::
    265269       
     
    308312                    for i from 0 <= i <= fmod.poldegree():
    309313                        if fmod.polcoeff(i).type() in ["t_POL", "t_POLMOD"]:
    310314                            # Convert relative element to absolute
     315                            # This returns a polynomial, not a polmod
    311316                            f = parent.pari_rnf().rnfeltreltoabs(f)
    312317                            break
    313                 f = f.lift()
     318                # Check that the modulus is actually the defining polynomial
     319                # of the number field.
     320                # Unfortunately, this check only works for absolute elements
     321                # since the rnfeltreltoabs() destroys all information about
     322                # the number field.
     323                if f.type() == "t_POLMOD":
     324                    fpol = parent.polynomial_ring()(f.mod())
     325                    if fpol != parent.absolute_polynomial():
     326                        raise ValueError("Coercion of PARI polmod with modulus %s into number field with defining polynomial %s failed"%(fpol,parent.absolute_polynomial()))
     327                    f = f.lift()
    314328            else:
    315                 f = self.number_field().pari_nf().nfbasistoalg_lift(f)
     329                f = parent.pari_nf().nfbasistoalg_lift(f)
    316330        f = ppr(f)
    317331        if f.degree() >= parent.absolute_degree():
    318332            from sage.rings.number_field import number_field_rel
     
    33153329            Mod(y*x, x^4 + y*x + 2)
    33163330            sage: L(e)  # Conversion from PARI relative number field element
    33173331            a*b
     3332            sage: e = pari('Mod(0, x^8 + 1)'); L(e)  # Wrong modulus
     3333            Traceback (most recent call last):
     3334            ...
     3335            ValueError: Coercion of PARI polmod with modulus x^8 + 1 into number field with defining polynomial x^8 - x^5 + 4*x^4 + x^2 - 2*x + 4 failed
    33183336
    33193337        We test a relative number field element created "by hand"::
    33203338
    33213339            sage: e = pari("Mod(Mod(y, y^2 + y + 1)*x^2 + Mod(1, y^2 + y + 1), x^4 + y*x + 2)")
    33223340            sage: L(e)
    33233341            a*b^2 + 1
     3342
     3343        Currently, conversions of PARI relative number fields are not checked::
     3344
     3345            sage: e = pari('Mod(y*x, x^4 + y^2*x + 2)'); L(e)  # Wrong modulus, but succeeds anyway
     3346            a*b
    33243347        """
    33253348        NumberFieldElement.__init__(self, parent, f)
    33263349