Ticket #778 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

[with patch, positive review] Finite Field __call__ doesn't accept polynomials over F_p

Reported by: roed Owned by: somebody
Priority: major Milestone: sage-3.0
Component: basic arithmetic Keywords: finite fields
Cc: AlexGhitza Author(s):
Report Upstream: Reviewer(s):
Merged in: Work issues:

Description

Neither Givaro nor pari finite fields accept polynomial arguments.

Attachments

trac778.patch Download (6.4 KB) - added by cremona 2 years ago.

Change History

Changed 2 years ago by mabshoff

  • milestone changed from sage-2.9 to sage-2.8.11

Changed 2 years ago by roed

Sorry, should have given an example.

sage: Q.<q> = GF(57) sage: L = GF(5) sage: LL.<xx> = L[] sage: Q(xx2 + 2*xx + 4)


<type 'exceptions.TypeError?'> Traceback (most recent call last)

/Users/roed/<ipython console> in <module>()

/Users/roed/Math/sage/local/lib/python2.5/site-packages/sage/rings/finite_field.py in call(self, x)

624 return self(x.constant_coefficient()) 625 else:

--> 626 raise TypeError?, "no coercion defined"

627 628 elif isinstance(x, str):

<type 'exceptions.TypeError?'>: no coercion defined

Changed 2 years ago by was

Sorry.
sage: Q.<q> = GF(5^7)
sage: L = GF(5)
sage: LL.<xx> = L[]
sage: Q(xx^2 + 2*xx + 4)
---------------------------------------------------------------------------
<type 'exceptions.TypeError '>             Traceback (most recent call last)

/Users/roed/<ipython console> in <module>()

/Users/roed/Math/sage/local/lib/python2.5/site-packages/sage/rings/finite_field.py in __call__(self, x)
    624                 return self(x.constant_coefficient())
    625             else:
--> 626                 raise TypeError, "no coercion defined"
    627
    628         elif isinstance(x, str):

<type 'exceptions.TypeError'>: no coercion defined
- Show quoted text -

Changed 2 years ago by cremona

I don't understamd what you expect to be done here. How can you coerce a polynomial over GF(5) into the field GF(5**7)? If you mean to coerce it into a polynomial over GF(5**7) then do this:

sage: PolynomialRing(Q,x)(xx^2 + 2*xx + 4)
x^2 + 2*x + 4

or this:

sage: f=LL.base_extend(Q)(xx^2 + 2*xx + 4)
sage: f
xx^2 + 2*xx + 4
sage: f.parent()
Univariate Polynomial Ring in xx over Finite Field in q of size 5^7

Can roed explain? Otherwise I vote for this to be closed.

Changed 2 years ago by was

David wants something like one has with quotients of polynomial rings, since finite extension fields can be thought of as polynomial quotient rings. E.g.,:

sage: R.<x> = GF(5)[]
sage: Q.<q> = R.quotient(x^7 + 3*x + 3)
sage: Q(x^2 + 2*x + 4)
q^2 + 2*q + 4

I think this is a reasonable request, since there is a natural ring homomorphism from GF(5)x? to GF(57), when the GF(57) is presented as an explicit quotient of a polynomial ring modulo an irred. polynomial, as our are.

-- William

Changed 2 years ago by cremona

Now I understand. In that case you can just evaluate the polynomial at the generator of the extension field:

sage: Q.<q> = GF(5^7)
sage: L = GF(5)
sage: LL.<xx> = L[]
sage: (xx^2 + 2*xx + 4)(q)
q^2 + 2*q + 4

So what roed wants is for Q(f) to evaluate as f(Q.gen()), where f is a polynomial over the base ring of Q. That is now understandable, and reasonable, and presumably not hard to implement!

Changed 2 years ago by AlexGhitza

  • cc AlexGhitza added

Changed 2 years ago by cremona

Changed 2 years ago by cremona

  • summary changed from Finite Field __call__ doesn't accept polynomials over F_p to [with patch, needs review] Finite Field __call__ doesn't accept polynomials over F_p

Attached patch (trac778.patch, based on 2.11) adds coercion of univariate polynomials into finite field elements, for all three finite field classes, with extra doctests.

Changed 2 years ago by mhansen

  • summary changed from [with patch, needs review] Finite Field __call__ doesn't accept polynomials over F_p to [with patch, positive review] Finite Field __call__ doesn't accept polynomials over F_p

Looks good to me.

Changed 2 years ago by mabshoff

  • status changed from new to closed
  • resolution set to fixed

Merged in Sage 3.0.alpha1

Note: See TracTickets for help on using tickets.