'How to define Field of 16 elements in sagemath?

I'm trying to define the field with 16 elements that is F_2(x) modulus x^4+x+1. I mean, the elements are polynomials with coefficient 1 or 0 and a base is {x^³, x^2, x, 1}. Then, I need to define matrixes with elements of this field and be abble to multiply them as usual.

I'm trying to to do this in sagemath since it is supposed to be easier.

How can this be done?

I've tried

F.<xi>=GF(2^4, modulus=GF(2)[x](x^4+x+1))

but it doesn't work.



Solution 1:[1]

First make sure that x or some other letter used in the optional parameter modulus=... is a generator of a polynomial ring over the field with two elements, GF(2). I will use X but any other letter would do instead. Then just use it.

R.<X> = PolynomialRing(GF(2))
F.<a> = GF(2^4, modulus=X^4 + X + 1)
print(f'F is {F}')
print(f'a has minimal polynomial {a.minpoly()}')

Results:

F is Finite Field in a of size 2^4
a has minimal polynomial x^4 + x + 1

Let us multiply some simple matrices defined over this field.

A = matrix(2, 2, [1, a, a, a^2])
B = matrix(2, 2, [1, a, a, a^3])
AB = A*B

print(f'AB is the matrix\n{AB}')

This gives:

AB is the matrix
[a^2 + 1       1]
[a^3 + a       a]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dan_fulea