# Finite field extension

How can one recover the coefficients of the polynomial representation of a number field element when the number field is not prime?

In the following example,

F = GF(p)
R.<x> = F[]
K.<t>  = GF(p^2, modulus=x^2 + 1)
a = K.random_element()


say the value of a obtained is 364*t + 214.

How can I read from Sage the integer values (364, 214), I need them for manipulation, I do not want the t there.

edit retag close merge delete

Sort by » oldest newest most voted
sage: P=127
sage: F = GF(P)
sage: R.<x> = F[]
sage: K.<t> = GF(P^2, modulus = x^2 + 1)
sage: a = K.random_element()
sage: a.polynomial().coeffs()
[5, 42]

more

This updates the answer by @achrzesz, as coeffs is no longer available.

The polynomial method of a number field element gives the associated polynomial. The list method of that polynomial gives its coefficients.

Beware that polynomials also have a coefficients method but by default it only gives the nonzero coefficients, so one should prefer list.

Define the number field:

sage: p = 127
sage: x = polygen(GF(p))
sage: K.<t> = GF(p^2, modulus=x^2 + 1)


Find the coefficients of some elements expressed as polynomials in the number field generator:

sage: a = 364*t + 214
sage: a
110*t + 87
sage: a.polynomial()
110*t + 87
sage: a.polynomial().list()
[87, 110]

sage: b = 16*t
sage: b
16*t
sage: b.polynomial()
16*t
sage: b.polynomial().list()
[0, 16]

sage: c = K(16)
sage: c
sage: c.polynomial()
16
sage: c.polynomial().list()



The coefficients method is error-prone:

sage: a.polynomial().coefficients()  # also works here
[87, 110]
sage: b.polynomial().coefficients()

sage: c.polynomial().coefficients()



unless one is specific about including zeros:

sage: b.polynomial().coefficients(sparse=False)
[0, 16]
sage: c.polynomial().coefficients(sparse=False)



Another option is to go through the integer representation:

sage: ZZ(a.integer_representation()).digits(base=p)
[87, 110]
sage: ZZ(b.integer_representation()).digits(base=p)
[0, 16]
sage: ZZ(c.integer_representation()).digits(base=p)



There, one can also pad with zeros so that the number of "p-adic digits" matches the degree:

sage: ZZ(c.integer_representation()).digits(base=p, padto=2)
[16, 0]


I answered the question with p = 127 as @achrzesz did, but the value of p the original poster had in mind was likely greater than 364.

When trying the above with p = 367, the integer_representation method is not available. Making it available independent of the finite field implementation is now tracked at

more