# Iterating over finite structures

I am trying to use sage for some algebra computations involving finite rings. Since the structures are finite, I would like to iterate over all the elements of the structure. I know how to iterate in some cases for polynomials in polynomial rings of a certain degree (not necessarily finite):

S.<x> = PolynomialRing(Zmod(9))

Then I could do

for i in S.polynomials(of_degree = 2):

To iterate over all quadratics. What I'd like to do is iterate over all elements of a structure like the finite ring:

R = GroupAlgebra( GL(2, Zmod(2)), Zmod(2))

Is there a way to do this in Sage easily?

edit retag close merge delete

Sort by » oldest newest most voted

"Easily"? I don't know if this counts, but it works:

sage: R = GroupAlgebra( GL(2, Zmod(2)), Zmod(2))
sage: V = GF(2)**6  # R is 6-dimensional as a vector space
sage: [R.from_vector(v) for v in V]
[0, [0 1]
[1 0], [0 1]
[1 1], [0 1]
[1 0] + [0 1]
[1 1], [1 0]
...


So you could do

sage: for r in (R.from_vector(v) for v in V): ...


(Or just iterate over V, calling R.from_vector(...) each time.)

more

Thank you for the answer. What you do works for V = GF(2)**6, but I already can do that because "for v in V" works here. "for v in V" does not work if "V = GroupAlgebra( GL(2, Zmod(2)), Zmod(2))". My question is precisely for those structures that are finite, and yet don't work with "for v in V".

( 2017-06-14 22:40:47 -0500 )edit

The second line in my Sage block involves precisely your R. The point is that it converts between elements of V, where you can iterate, to elements of R.

( 2017-06-15 10:37:41 -0500 )edit

I've edited it to make the definition of R explicit.

( 2017-06-15 10:38:16 -0500 )edit

Thank you John. I didn't understand your answer at first but I get it now. It works well seems to be the easiest way to do computations of this nature!

( 2017-07-05 02:58:47 -0500 )edit