# How to access serial number corresponding to each element in $GF(2^3)$?

I would like to access serial number corresponding to each element in $GF(2^3)$? Corresponding to each serial number, I can access the element in $G(2^3)$ as follows:

F.<x> = GF(2^3, name='x', modulus=x^3 + x^2 + 1)
for i in range(2^3):
print i,'=>',F.fetch_int(i)


This provides :

0 => 0
1 => 1
2 => x
3 => x + 1
4 => x^2
5 => x^2 + 1
6 => x^2 + x
7 => x^2 + x + 1


I would like to get the reverse process which will provide seral number corresponding to each element in $(2^3)$, that is,

0 => 0
1 => 1
x => 2
x + 1 => 3
x^2 => 4
x^2 + 1 => 5
x^2 + x => 6
x^2 + x + 1 => 7


Is there any such way?

edit retag close merge delete

Sort by » oldest newest most voted Note that the mapping is just taking the binary digits of the integer and using them as coefficients w.r.t. the basis $1,x,x^2,\ldots$

You can use the built-in integer_representation() method, or do the job manually:

sage: a = F.fetch_int(3)
sage: a.integer_representation()
3
sage: ZZ(list(vector(a)), base=2)
3

more

What you can do is a dictionary:

sage: d = dict()
sage: for i in range(2^3):
....:     d[F.fetch_int(i)] = i

sage: d
{0: 0, 1: 1, x: 2, x + 1: 3, x^2: 4, x^2 + 1: 5, x^2 + x: 6, x^2 + x + 1: 7}
sage: d[x^2]
4
sage: d[x+1]
3

more