# character table of a finite field I am trying to calculate the character table of a finite field. The following is my code:

def character_table(q,n):
k=GF(q^n)
tr(x)=sum(x^(q^i) for i in [0..n-1])
ksi = e^(2*pi*I/n)
chi(x)=ksi^(tr(x))
for a in k:
L_a = [chi(a*x) for x in k]
print L_a


And the TypeError is "free variable 'x' referenced before assignment in enclosing scope". Can somebody help me how to fix the code?

Thanks

Blockquote

edit retag close merge delete

Beyond the error that you are getting, here are some comments.

1. The function definition's body (everything below the first line) should be indented four spaces.

2. You define L but never use it.

3. Are k and K supposed to be the same?

You are aware that Sage has finite group character tables via GAP as well, correct?

@slelievre I fixed all your suggestions. Now I get "free variable 'x' referenced before assignment in enclosing scope". @kcrisman I tried that but I couldn't get the right syntax. Could you please help? It seems that character_table() does not have an attribute for abelian groups. Also, since I am new in sage, I thought it was worth it to try and define a function from scratch. I also having difficulties on using only the additive group of a finite field.

Sort by » oldest newest most voted

Some tips:

• Instead of sum[...] you want sum(...).
• Instead of tr(x) = ..., use def tr(x): return ...

This might be what you were trying to write:

def character_table(q, n):
k = GF(q^n)
def tr(x):
return sum(x^(q^i) for i in [0..n-1])
ksi = e^(2*pi*I/n)
def chi(x):
return ksi^(tr(x))
for a in k:
L_a = [chi(a*x) for x in k]
print L_a


Calling this function prints something:

sage: character_table(3, 2)
[1, 1, 1, 1, 1, 1, 1, 1, 1]
[1, 1, -1, -1, 1, 1, 1, 1, -1]
[1, -1, -1, 1, 1, 1, 1, -1, 1]
[1, -1, 1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, -1, -1]
[1, 1, 1, 1, -1, 1, -1, -1, 1]
[1, 1, 1, -1, 1, -1, -1, 1, 1]
[1, 1, -1, 1, -1, -1, 1, 1, 1]
[1, -1, 1, -1, -1, 1, 1, 1, 1]

more

Alternately, see the solution at this question.

more

@kcrisman Could you explain why the very same code does not work is I change the group $g$, say with, AdditiveAbelianGroup([2,2,2])? Thanks