# 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


260  260  5/3*a^2 + 5/3*a  1/6 
261  261  sage: K(pari("x^5/17")) 
262  262  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 
263  267  
264  268  This example illustrates save and load:: 
265  269  
… 
… 

308  312  for i from 0 <= i <= fmod.poldegree(): 
309  313  if fmod.polcoeff(i).type() in ["t_POL", "t_POLMOD"]: 
310  314  # Convert relative element to absolute 
 315  # This returns a polynomial, not a polmod 
311  316  f = parent.pari_rnf().rnfeltreltoabs(f) 
312  317  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() 
314  328  else: 
315   f = self.number_field().pari_nf().nfbasistoalg_lift(f) 
 329  f = parent.pari_nf().nfbasistoalg_lift(f) 
316  330  f = ppr(f) 
317  331  if f.degree() >= parent.absolute_degree(): 
318  332  from sage.rings.number_field import number_field_rel 
… 
… 

3315  3329  Mod(y*x, x^4 + y*x + 2) 
3316  3330  sage: L(e) # Conversion from PARI relative number field element 
3317  3331  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 
3318  3336  
3319  3337  We test a relative number field element created "by hand":: 
3320  3338  
3321  3339  sage: e = pari("Mod(Mod(y, y^2 + y + 1)*x^2 + Mod(1, y^2 + y + 1), x^4 + y*x + 2)") 
3322  3340  sage: L(e) 
3323  3341  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 
3324  3347  """ 
3325  3348  NumberFieldElement.__init__(self, parent, f) 
3326  3349  