Ask Your Question

How to iterate over finite fields

asked 2018-06-13 17:13:24 +0200

sagemathuser gravatar image

In my current code I have to iterate over $GF(2^7)$ four times:

en1 = enumerate(gf)
en2 = enumerate(gf)
en3 = enumerate(gf)
en4 = enumerate(gf)

for i,x0 in en1:
    for j,x1 in en2:
        for k,x2 in en3:
            for m,x3 in en4:

In the loop I evaluate some multivariate polynomial. But this is very memory hungry. Is there any better way to do this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-06-13 17:28:54 +0200

tmonteil gravatar image

You can use the itertools Python module and make the product of enumerate(GF(2^7)) with itself four times as follows:

sage: from itertools import product
sage: for ((i0,a0),(i1,a1),(i2,a2),(i3,a3)) in product(enumerate(GF(2^7)), repeat=4):
....:     print ((i0,a0),(i1,a1),(i2,a2),(i3,a3))
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


Asked: 2018-06-13 16:03:09 +0200

Seen: 384 times

Last updated: Jun 13 '18