File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
src/sage/groups/abelian_gps Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -1301,10 +1301,27 @@ def __iter__(self):
13011301 (1,)
13021302 sage: list(G)
13031303 [1]
1304+
1305+ We can also iterate over infinite groups::
1306+
1307+ sage: A = AbelianGroup([3,0,5,0])
1308+ sage: for a in A:
1309+ ....: if a^2 == A([1, 2, 3, 4]):
1310+ ....: print(a, a^2)
1311+ ....: break
1312+ f0^2*f1*f2^4*f3^2 f0*f1^2*f2^3*f3^4
13041313 """
13051314 invs = self .gens_orders ()
1306- for t in mrange (invs ):
1307- yield self (t )
1315+ if 0 not in invs :
1316+ # The group is finite
1317+ for t in mrange (invs ):
1318+ yield self (t )
1319+ else :
1320+ # A similar approach works for infinite groups.
1321+ # (This would also work for finite groups, but is more complicated.)
1322+ from sage .misc .mrange import cantor_product
1323+ for t in cantor_product (* [range (n ) if n > 0 else ZZ for n in invs ]):
1324+ yield self (t )
13081325
13091326 def number_of_subgroups (self , order = None ):
13101327 r"""
You can’t perform that action at this time.
0 commit comments