# 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".

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.

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

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!
{"ft_lang_label":"__label__en","ft_lang_prob":0.90315217,"math_prob":0.8989983,"size":615,"snap":"2019-51-2020-05","text_gpt3_token_len":148,"char_repetition_ratio":0.14402619,"word_repetition_ratio":0.0,"special_character_ratio":0.23414634,"punctuation_ratio":0.09836066,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.988204,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-22T11:01:32Z\",\"WARC-Record-ID\":\"<urn:uuid:6126d884-fe03-4179-bf26-015d217d7685>\",\"Content-Length\":\"61890\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:267d8c91-3817-4dfc-bb17-9edb9e67a76f>\",\"WARC-Concurrent-To\":\"<urn:uuid:9da90118-6660-449b-b69e-9215c6624e8e>\",\"WARC-IP-Address\":\"140.254.118.68\",\"WARC-Target-URI\":\"https://ask.sagemath.org/question/37903/iterating-over-finite-structures/\",\"WARC-Payload-Digest\":\"sha1:ZYQCSHK4AWDMSMLAR2WW74SA6SFA2E4J\",\"WARC-Block-Digest\":\"sha1:N43OTZ5GUKREE3N2P2D43W7XLVEKECPB\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579250606975.49_warc_CC-MAIN-20200122101729-20200122130729-00100.warc.gz\"}"}