Ask Your Question
0

Define function in GF(q)

asked 2012-04-06 11:08:12 +0100

Arczi84 gravatar image

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 flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2012-04-07 03:30:29 +0100

fidbc gravatar image

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.

edit flag offensive delete link more
1

answered 2012-04-10 10:55:54 +0100

DSM gravatar image

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)
edit flag offensive delete link more
0

answered 2012-04-09 17:13:10 +0100

Arczi84 gravatar image

Hi,

Thanks for the answer. Yes, it helps:)

Regards

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-04-06 11:08:12 +0100

Seen: 1,551 times

Last updated: Apr 10 '12