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()
[16]
The coefficients
method is error-prone:
sage: a.polynomial().coefficients() # also works here
[87, 110]
sage: b.polynomial().coefficients()
[16]
sage: c.polynomial().coefficients()
[16]
unless one is specific about including zeros:
sage: b.polynomial().coefficients(sparse=False)
[0, 16]
sage: c.polynomial().coefficients(sparse=False)
[16]
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)
[16]
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