ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 05 Jul 2017 02:58:47 -0500Iterating over finite structureshttp://ask.sagemath.org/question/37903/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?Sat, 10 Jun 2017 02:33:41 -0500http://ask.sagemath.org/question/37903/iterating-over-finite-structures/Answer by John Palmieri for <p>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):</p>
<p><code>S.<x> = PolynomialRing(Zmod(9))</code></p>
<p>Then I could do</p>
<p><code>for i in S.polynomials(of_degree = 2):</code></p>
<p>To iterate over all quadratics. What I'd like to do is iterate over all elements of a structure like the finite ring:</p>
<p><code>R = GroupAlgebra( GL(2, Zmod(2)), Zmod(2))</code></p>
<p>Is there a way to do this in Sage easily?</p>
http://ask.sagemath.org/question/37903/iterating-over-finite-structures/?answer=37905#post-id-37905"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.)Sat, 10 Jun 2017 10:00:16 -0500http://ask.sagemath.org/question/37903/iterating-over-finite-structures/?answer=37905#post-id-37905Comment by Jason Polak for <p>"Easily"? I don't know if this counts, but it works:</p>
<pre><code>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]
...
</code></pre>
<p>So you could do</p>
<pre><code>sage: for r in (R.from_vector(v) for v in V): ...
</code></pre>
<p>(Or just iterate over <code>V</code>, calling <code>R.from_vector(...)</code> each time.)</p>
http://ask.sagemath.org/question/37903/iterating-over-finite-structures/?comment=38182#post-id-38182Thank 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!Wed, 05 Jul 2017 02:58:47 -0500http://ask.sagemath.org/question/37903/iterating-over-finite-structures/?comment=38182#post-id-38182Comment by John Palmieri for <p>"Easily"? I don't know if this counts, but it works:</p>
<pre><code>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]
...
</code></pre>
<p>So you could do</p>
<pre><code>sage: for r in (R.from_vector(v) for v in V): ...
</code></pre>
<p>(Or just iterate over <code>V</code>, calling <code>R.from_vector(...)</code> each time.)</p>
http://ask.sagemath.org/question/37903/iterating-over-finite-structures/?comment=37952#post-id-37952I've edited it to make the definition of `R` explicit.Thu, 15 Jun 2017 10:38:16 -0500http://ask.sagemath.org/question/37903/iterating-over-finite-structures/?comment=37952#post-id-37952Comment by John Palmieri for <p>"Easily"? I don't know if this counts, but it works:</p>
<pre><code>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]
...
</code></pre>
<p>So you could do</p>
<pre><code>sage: for r in (R.from_vector(v) for v in V): ...
</code></pre>
<p>(Or just iterate over <code>V</code>, calling <code>R.from_vector(...)</code> each time.)</p>
http://ask.sagemath.org/question/37903/iterating-over-finite-structures/?comment=37951#post-id-37951The 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`.Thu, 15 Jun 2017 10:37:41 -0500http://ask.sagemath.org/question/37903/iterating-over-finite-structures/?comment=37951#post-id-37951Comment by Jason Polak for <p>"Easily"? I don't know if this counts, but it works:</p>
<pre><code>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]
...
</code></pre>
<p>So you could do</p>
<pre><code>sage: for r in (R.from_vector(v) for v in V): ...
</code></pre>
<p>(Or just iterate over <code>V</code>, calling <code>R.from_vector(...)</code> each time.)</p>
http://ask.sagemath.org/question/37903/iterating-over-finite-structures/?comment=37947#post-id-37947Thank 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".Wed, 14 Jun 2017 22:40:47 -0500http://ask.sagemath.org/question/37903/iterating-over-finite-structures/?comment=37947#post-id-37947