# Define function in GF(q)

Hi,

First of all I say that these are my first steps in SAGE. I want to define a function f(x,y), where x,y in GF(q), q=2^3 and next check all possible values of this function (for all x,y in GF(q)). If it will be necessary I'll write more details about function f.

Could you give me some advices how can I do it in SAGE? Any help will be highly appreciated.

I wish you a very happy Easter!

Best regards,

Artur

edit retag close merge delete

Sort by ยป oldest newest most voted

Hi,

First we can try defining the function, say we want to calculate $xy+x^2+y^3$ for all $x,y\in GF(2^3)$. This can be done as follows

def f(x,y):
return x*y+x^2+y^3


Now, to check all possible values we can try the following

FFq.<a> = GF( 2^3, 'a' ) # Note: a is the name of the generator
for x in FFq:
for y in FFq:
print f(x,y)


As a final comment, now that a has been defined to be the generator we can use it to evaluate f at particular points, say

f(a^3+1,a^2+1)


Hope it helped.

more

Another approach would be to build a 2-dimensional vector space.

First build the base field:

sage: FFq.<a> = GF(2^3)
sage: FFq
Finite Field in a of size 2^3


We could make a list from this:

sage: list(FFq)
[0, a, a^2, a + 1, a^2 + a, a^2 + a + 1, a^2 + 1, 1]


And we can square the field to get a vector space:

sage: FFq^2
Vector space of dimension 2 over Finite Field in a of size 2^3


This can be listed too:

sage: list(FFq^2)
[(0, 0), (a, 0), (a^2, 0), (a + 1, 0), (a^2 + a, 0), (a^2 + a + 1, 0), (a^2 + 1, 0), (1, 0), (0, a), (a, a), (a^2, a), (a + 1, a), (a^2 + a, a), (a^2 + a + 1, a), (a^2 + 1, a), (1, a), (0, a^2), (a, a^2), (a^2, a^2), (a + 1, a^2), (a^2 + a, a^2), (a^2 + a + 1, a^2), (a^2 + 1, a^2), (1, a^2), (0, a + 1), (a, a + 1), (a^2, a + 1), (a + 1, a + 1), (a^2 + a, a + 1), (a^2 + a + 1, a + 1), (a^2 + 1, a + 1), (1, a + 1), (0, a^2 + a), (a, a^2 + a), (a^2, a^2 + a), (a + 1, a^2 + a), (a^2 + a, a^2 + a), (a^2 + a + 1, a^2 + a), (a^2 + 1, a^2 + a), (1, a^2 + a), (0, a^2 + a + 1), (a, a^2 + a + 1), (a^2, a^2 + a + 1), (a + 1, a^2 + a + 1), (a^2 + a, a^2 + a + 1), (a^2 + a + 1, a^2 + a + 1), (a^2 + 1, a^2 + a + 1), (1, a^2 + a + 1), (0, a^2 + 1), (a, a^2 + 1), (a^2, a^2 + 1), (a + 1, a^2 + 1), (a^2 + a, a^2 + 1), (a^2 + a + 1, a^2 + 1), (a^2 + 1, a^2 + 1), (1, a^2 + 1), (0, 1), (a, 1), (a^2, 1), (a + 1, 1), (a^2 + a, 1), (a^2 + a + 1, 1), (a^2 + 1, 1), (1, 1)]


So now we can define the function:

sage: def f(x,y):
....:     return x*y+x^2+y^3
....:


And then apply it to each coordinate pair:

sage: [f(*coords) for coords in FFq^2]
[0, a^2, a^2 + a, a^2 + 1, a, a + 1, a^2 + a + 1, 1, a + 1, a + 1, a^2 + a, 0, a^2 + a, a^2 + 1, a^2 + 1, 0, a^2 + 1, a, a^2 + 1, a^2 + a + 1, a, a^2 + a + 1, 0, 0, a^2, a^2 + a, a^2 + 1, a^2, a^2 + a + 1, a^2 + 1, a^2 + a + 1, a^2 + a, a^2 + a + 1, a^2, a^2, a + 1, a^2 + a + 1, 0, a + 1, 0, a, a + 1 ...
more

Hi,

Thanks for the answer. Yes, it helps:)

Regards

more