Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

How to iterate over finite fields

asked 6 years ago

sagemathuser gravatar image

In my current code I have to iterate over GF(27) 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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 6 years ago

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))
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 6 years ago

Seen: 598 times

Last updated: Jun 13 '18