# Function in GF(16)

Hi,

I've one problem in the following task. My calculations:

I'm defining following function:

def custom_divide(x,y):
if x==0:
return 0
return y/x


Next, I'm calculating all possible values in GF(16) for the function T:

F.<a>=GF(16)
for a,b in F^2:
print "x=",a,"y=",b, "T:",a*custom_divide((c+1)*((custom_divide(a,b))^3+1)+(c^3+c)*((custom_divide(a,b))^2+custom_divide(a,b)),(custom_divide(a,b))^4+(c+1)*(custom_divide(a,b))^2+1)+(a*b).nth_root(2)


I know that c is not defined in that code but I wrote it there because it helps me with describing my problem. c+1 and c^3+c are constants and I don't know how can I write them in my code. If I'll write:

F.<a>=GF(16)
for a,b in F^2:
print "x=",a,"y=",b, "T:",a*custom_divide((a+1)*((custom_divide(a,b))^3+1)+(a^3+a)*((custom_divide(a,b))^2+custom_divide(a,b)),(custom_divide(a,b))^4+(a+1)*(custom_divide(a,b))^2+1)+(a*b).nth_root(2)


then this constants will be equal to the variable a and will be change in every steps, but they should be the same in all cases.

How can I correct my code?

I'll be grateful for any help in this task.

edit retag close merge delete

Sort by » oldest newest most voted

I have no idea of what you are asking or what you are trying to compute. But if you define a to be the generator of your field then it is very confusing to use a as the loop variable. For example:

sage: F.<a>=GF(16)
sage: 1+3*a
a + 1
sage: 16*a
0


Using a as a loop variable overwrites it:

sage: for a in range(3): print a
0
1
2
sage: a
2

more

sage: F.<a>=GF(16)
sage: def T(x,y,c):
...      return ((y/x + y^3/x^3)*(c^2 + c + 1)*c^2 + (y/x + y^4/x^4)*c^2)*x/(c*y^2/x^2 + y^4/x^4 + 1) + sqrt(x*y)
sage: for x,y in CartesianProduct(list(F),list(F)):
...   try:
...       print x, '\t', y, '\t', T(x, y, c=1)
...   except Exception, e:
...       print e
0   0   division by zero in finite field.
0   a   division by zero in finite field.
0   a^2     division by zero in finite field.
0   a^3     division by zero in finite field.
0   a + 1   division by zero in finite field.
0   a^2 + a     division by zero in finite field.
0   a^3 + a^2   division by zero in finite field.
0   a^3 + a + 1     division by zero in finite field.
0   a^2 + 1     division by zero in finite field.
0   a^3 + a     division by zero in finite field.
0   a^2 + a + 1     division by zero in finite field.
0   a^3 + a^2 + a   division by zero in finite field.
0   a^3 + a^2 + a + 1   division by zero in finite field.
0   a^3 + a^2 + 1   division by zero in finite field.
0   a^3 + 1     division by zero in finite field.
0   1   division by zero in finite field.
a   0   0
a   a   a
a   a^2     a
a   a^3     a
a   a + 1   a
a   a^2 + a     a
a   a^3 + a^2   division by zero in finite field.
a   a^3 + a + 1     a
a   a^2 + 1     a^3 + a
a   a^3 + a     a
a   a^2 + a + 1     a
a   a^3 + a^2 + a   division by zero in finite field.
a   a^3 + a^2 + a + 1   a^2 + a
a   a^3 + a^2 + 1   a
a   a^3 + 1     a^3
a   1   a^2
a^2     0   0
a^2     a   a^3
a^2     a^2     a^2
a^2     a^3     a^2
a^2     a + 1   a^2
a^2     a^2 + a     a^2
a^2     a^3 + a^2   a^2
a^2     a^3 + a + 1     division by zero in finite field.
a^2     a^2 + 1     a^2
a^2     a^3 + a     a^2 + a + 1
a^2     a^2 + a + 1     a^2
a^2     a^3 + a^2 + a   a^2
a^2     a^3 + a^2 + a + 1   division by zero in finite field.
a^2     a^3 + a^2 + 1   a^3 + a^2
a^2     a^3 + 1     a^2
a^2     1   a + 1
a^3     0   0
a^3     a   a^2 + a
a^3     a^2     a + 1
a^3     a^3     a^3
a^3     a + 1   a^3
a^3 ...
more

Maybe You are right, so I'll write it more clearly (I hope).

Let GF(2^4)={0, 1, a, a+1, a^2, a^2+1, a^2+a, a^2+a+1, a^3, a^3+1, a^3+a, a^3+a+1, a^3+a^2, a^3+a^2+1, a^3+a^2+a, a^3+a^2+a+1} and a^4+a+1=0.

Let T:= x*([c^2((y/x)^4+(y/x))+c^2(1+c+c^2)((y/x)^3+(y/x))]/[(y/x)^4+c(y/x)^2+1])+(xy)^(1/2),

where c is constant in GF(16) (for example c=a^2+a). Convention: if x=0 then y/x=0 (custom_divide).

Now I want to calculate all values of the function T:

x=0            y=0            T=...
x=0            y=1            T=...
x=0            y=a            T=...
...
x=a^3+a^2+a+1  y=a^3+a^2+1    T=...
x=a^3+a^2+a+1  y=a^3+a^2+a    T=...
x=a^3+a^2+a+1  y=a^3+a^2+a+1  T=...


I've to define this function T with this constant c.

more

Thank You for help:) I'll do this exercise.

more