# HG changeset patch
# User Peter Bruin <peter.bruin@math.uzh.ch>
# Date 1375736213 7200
# Node ID cebb1a7b1d5b752fb15b4cae6a8140f51ca029ca
# Parent c207130fe25465501d8bcb45b7751a346751c0a1
Trac 11239: fix coercion of polynomials over finite fields
diff git a/sage/rings/polynomial/polynomial_zz_pex.pyx b/sage/rings/polynomial/polynomial_zz_pex.pyx
a

b


89  89  sage: R([3,'12e34']) 
90  90  Traceback (most recent call last): 
91  91  ... 
92   TypeError: unable to convert '12e34' into the base ring 
 92  TypeError: unable to convert x (=12e34) to an integer 
93  93  sage: R([3,x]) 
94  94  Traceback (most recent call last): 
95  95  ... 
96   TypeError: unable to convert x into the base ring 
 96  TypeError: not a constant polynomial 
97  97  
 98  Check that :trac:`11239` is fixed:: 
 99  
 100  sage: Fq.<a> = GF(2^4); Fqq.<b> = GF(3^7) 
 101  sage: PFq.<x> = Fq[]; PFqq.<y> = Fqq[] 
 102  sage: f = x^3 + (a^3 + 1)*x 
 103  sage: sage.rings.polynomial.polynomial_zz_pex.Polynomial_ZZ_pEX(PFqq, f) 
 104  Traceback (most recent call last): 
 105  ... 
 106  TypeError: unable to coerce from a finite field other than the prime subfield 
98  107  """ 
99  108  cdef ntl_ZZ_pE d 
100  109  try: 
… 
… 

108  117  except AttributeError: 
109  118  pass 
110  119  
 120  if isinstance(x, Polynomial): 
 121  x = x.list() 
 122  
111  123  if PY_TYPE_CHECK(x, list) or PY_TYPE_CHECK(x, tuple): 
112  124  Polynomial.__init__(self, parent, is_gen=is_gen) 
113  125  (<Polynomial_template>self)._cparent = get_cparent(parent) 
114  126  celement_construct(&self.x, (<Polynomial_template>self)._cparent) 
115  127  K = parent.base_ring() 
116  128  for i,e in enumerate(x): 
117   try: 
118   e_polynomial = e.polynomial() 
119   except (AttributeError, TypeError): 
120   # A type error may occur, since sometimes 
121   # e.polynomial expects an additional argument 
122   try: 
123   # self(x) is supposed to be a conversion, 
124   # not necessarily a coercion. So, we must 
125   # not do K.coerce(e) but K(e). 
126   e = K(e) # K.coerce(e) 
127   e_polynomial = e.polynomial() 
128   except TypeError: 
129   raise TypeError("unable to convert %s into the base ring"%repr(e)) 
130   d = parent._modulus.ZZ_pE(list(e_polynomial)) 
 129  # self(x) is supposed to be a conversion, 
 130  # not necessarily a coercion. So, we must 
 131  # not do K.coerce(e) but K(e). 
 132  e = K(e) 
 133  d = parent._modulus.ZZ_pE(list(e.polynomial())) 
131  134  ZZ_pEX_SetCoeff(self.x, i, d.x) 
132  135  return 
133  136  