Magma function for modulo irreducible polynomial So, I am trying to make a program in Magma which returns the value table of a given function F over a field $GF(2^n)$. To do so I need a irreducible polyomial. For example, I've considered $GF(2^3)$ and the irreducible polynomial $p(x)=x^3+x+1$.

My program started like this:

F&lt;a&gt;:=GF(2^3);
for i in F do
i mod a^3+a+1;
end for;


The 'mod' apperantly only works with integers, is there a polynomial version for this?
The mod function works for polynomials, provided they are recognized by Magma as being elements in a polynomial ring. For example, put F := GF(2); and P&lt;a&gt; := PolynomialRing(F); and you will get the results you want if you ask for a^i mod a^3+a+1;.

Alternately, specific for your finite field example, you can put F&lt;a&gt; := GF(2^3); which you can verify is constructed with $x^3+x+1$ as the minimal polynomial for a (ask for DefiningPolynomial(F);). By default, Magma will print elements of F as powers of a, but if you put in the command SetPowerPrinting(F,false); it will give you a reduced polynomial in a instead. So then you can just type a^i; and it will return this field element as the remainder when divided by $a^3+a+1$.

(Note that if you type both F&lt;a&gt; := GF(2^3); and P&lt;a&gt; := PolynomialRing(F); then you have introduced some confusion as to whether a is a finite field element, or an indeterminate in your polynomial ring. You should really avoid doing this.)
I managed to make the program.

F&lt;a&gt;:=GF(2^3);
P&lt;a&gt;:=PolynomialRing(F);

function f(x)
return x^5;
end function;

A:=[];
for i in [1..6] do
Append(~A, (a^i mod (a^3+a+1)));
end for;

A:=Reverse(A);
A:=Append(A,1);
A:=Append(A,0);

A:=Reverse(A);

F:=[];
for i in [1..6] do
Append(~F,((f(a))^i mod (a^3+a+1)));
end for;


F:=Reverse(F);
F:=Append(F,1);
F:=Append(F,0);

F:=Reverse(F);

BinA:=[];
for i in A do
for j in [a^2,a,1] do
if j in Terms(i) then
Append(~BinA,1);
else
Append(~BinA,0);
end if;
end for;
end for;

BinA:=Matrix(3,BinA);

BinF:=[];
for i in F do
for j in [a^2,a,1] do
if j in Terms(i) then
Append(~BinF,1);
else
Append(~BinF,0);
end if;
end for;
end for;


print BinF;