ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 09 Mar 2017 19:40:59 +0100Trace function over GF(q)https://ask.sagemath.org/question/8891/trace-function-over-gfq/Hi,
I understand the idea of defining functions over GF(q) which You explained me very precisely.
Now I have following problem:
I want to define the function:
`f(x,y)=Tr(x*g(y/x))`, where `Tr(x)=x+x^2+x^4` (`Tr:GF(8)-->GF(2)`) and
x*g(y/x)=[(y*[d^2*[(y/x)^3+1]+d^2*(1+d+d^2)*[(y/x)^2+(y/x)]])/((y/x)^4+d^2*(y/x)^2+1)]+(y/x)^(1/2).
Let (for example) d=3.
With convention that 1/0=0 (y/0=0), I want to see what values this function f receives. How can I do this in SAGE?
What I did (with Yours help):
def custom_divide(x,y):
if y==0:
return 0
return x/y
F.<a>=GF(8)
for a,b in F^2:
print "x: ",a,"y: ",b,"x/y: ",custom_divide(a,b)
F.<a>=GF(8)
for a,b in F^2:
print "x*y: ",a*b,"(x*y)^2: ",(a*b)^2,"(x*y)^(1/2): ",(a*b).nth_root(2)
I'm stopped here because I'm not sure how can I define such function f.
Any help/advices will be highly appreciated.
I could write more details if something is not clear.
Best regards,
ArcziSun, 15 Apr 2012 17:11:14 +0200https://ask.sagemath.org/question/8891/trace-function-over-gfq/Answer by dan_fulea for <p>Hi,</p>
<p>I understand the idea of defining functions over GF(q) which You explained me very precisely.
Now I have following problem:</p>
<p>I want to define the function:</p>
<p><code>f(x,y)=Tr(x*g(y/x))</code>, where <code>Tr(x)=x+x^2+x^4</code> (<code>Tr:GF(8)-->GF(2)</code>) and</p>
<pre><code>x*g(y/x)=[(y*[d^2*[(y/x)^3+1]+d^2*(1+d+d^2)*[(y/x)^2+(y/x)]])/((y/x)^4+d^2*(y/x)^2+1)]+(y/x)^(1/2).
</code></pre>
<p>Let (for example) d=3.</p>
<p>With convention that 1/0=0 (y/0=0), I want to see what values this function f receives. How can I do this in SAGE? </p>
<p>What I did (with Yours help):</p>
<pre><code>def custom_divide(x,y):
if y==0:
return 0
return x/y
F.<a>=GF(8)
for a,b in F^2:
print "x: ",a,"y: ",b,"x/y: ",custom_divide(a,b)
F.<a>=GF(8)
for a,b in F^2:
print "x*y: ",a*b,"(x*y)^2: ",(a*b)^2,"(x*y)^(1/2): ",(a*b).nth_root(2)
</code></pre>
<p>I'm stopped here because I'm not sure how can I define such function f.
Any help/advices will be highly appreciated.</p>
<p>I could write more details if something is not clear.</p>
<p>Best regards,
Arczi</p>
https://ask.sagemath.org/question/8891/trace-function-over-gfq/?answer=36883#post-id-36883The following code is doing the job. (I hope the formula was retyped in an equivalent manner. For instance, `(y/x)^(1/2)` was replaced for our purposes by `(y/x)^4` .)
F8 = GF(8)
F2 = GF(2)
def f( x, y, field=F8, d=3 ):
if x == field(0): y_by_x = field(0)
else : y_by_x = y / x
return d^2 * ( y * ( y_by_x^3 + 1 ) + ( 1 + d + d^2 ) * y_by_x * ( y_by_x + 1 ) ) \
/ \
( y_by_x^4 + d^2 * y_by_x^2 + 1 ) \
+ \
y_by_x^4
print matrix( F2, 8, 8, [ [ f( x, y, F8, 3 ).trace() for y in F8 ] for x in F8 ] )
We get:
[0 0 0 1 0 1 1 1]
[0 1 1 1 0 0 1 0]
[0 0 1 0 1 1 1 0]
[0 0 1 1 0 0 1 1]
[0 1 0 1 1 1 0 0]
[0 1 0 1 0 1 0 1]
[0 0 0 0 1 1 1 1]
[0 1 1 0 1 0 0 1]
N.B. Which is the meaning of the above result?Thu, 09 Mar 2017 19:40:59 +0100https://ask.sagemath.org/question/8891/trace-function-over-gfq/?answer=36883#post-id-36883