ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 10 Feb 2014 17:11:12 +0100List members of each subgroup of integers modulo nhttps://ask.sagemath.org/question/11019/list-members-of-each-subgroup-of-integers-modulo-n/Hi - I am new to Sage so apologies if this is a dumb question.
For a given n, I would like to print out the list of subgroups of the multiplicative group modulo n as a list of the members of the subgroup. Here's one of the things I have tried so far:
R = Zmod(20)
grouplist = R.multiplicative_subgroups()
for subgroup in grouplist:
print subgroup
(11, 17)
(9, 11)
(3,)
(11,)
(19,)
(17,)
(9,)
()
As you can see, this gives me the generators of the sub-groups, but what I'd like is the complete list of members of the subgroup for each subgroup. Something along these lines - where members() is the method I would like, but don't know if it exists!:
R = Zmod(20)
grouplist = R.multiplicative_subgroups()
for subgroup in grouplist:
print subgroup.members()
(1, 3, 7, 9, 11, 13, 17, 19)
(1, 9, 11, 19)
(1, 3, 7, 9)
(1, 11)
(1, 19)
(1, 9, 13, 17)
(1, 9)
(1)
Thanks for any help, Martin
Mon, 10 Feb 2014 14:31:48 +0100https://ask.sagemath.org/question/11019/list-members-of-each-subgroup-of-integers-modulo-n/Answer by Luca for <p>Hi - I am new to Sage so apologies if this is a dumb question.</p>
<p>For a given n, I would like to print out the list of subgroups of the multiplicative group modulo n as a list of the members of the subgroup. Here's one of the things I have tried so far:</p>
<p>R = Zmod(20)
grouplist = R.multiplicative_subgroups()
for subgroup in grouplist:
print subgroup
(11, 17)
(9, 11)
(3,)
(11,)
(19,)
(17,)
(9,)
()</p>
<p>As you can see, this gives me the generators of the sub-groups, but what I'd like is the complete list of members of the subgroup for each subgroup. Something along these lines - where members() is the method I would like, but don't know if it exists!:</p>
<p>R = Zmod(20)
grouplist = R.multiplicative_subgroups()
for subgroup in grouplist:
print subgroup.members()
(1, 3, 7, 9, 11, 13, 17, 19)
(1, 9, 11, 19)
(1, 3, 7, 9)
(1, 11)
(1, 19)
(1, 9, 13, 17)
(1, 9)
(1)</p>
<p>Thanks for any help, Martin</p>
https://ask.sagemath.org/question/11019/list-members-of-each-subgroup-of-integers-modulo-n/?answer=16030#post-id-16030`multiplicative_subgroups` returns only lists of generators, rather than proper group objects. This is, in my opinion, unfortunate. You can work it around with a bit of code. This function returns the list of elements spanned by a list `G` of generators
def list_elts(G):
exps = [xrange(g.multiplicative_order()) for g in G]
return [prod(g^e for g, e in zip(G, exp)) for exp in CartesianProduct(*exps)]
So, you may call
sage: R = Zmod(20)
sage: map(list_elts, R.multiplicative_subgroups())
[[1, 17, 9, 13, 11, 7, 19, 3],
[1, 11, 9, 19],
[1, 3, 9, 7],
[1, 11],
[1, 19],
[1, 17, 9, 13],
[1, 9],
[1]]
Mon, 10 Feb 2014 15:48:53 +0100https://ask.sagemath.org/question/11019/list-members-of-each-subgroup-of-integers-modulo-n/?answer=16030#post-id-16030Comment by Martin for <p><code>multiplicative_subgroups</code> returns only lists of generators, rather than proper group objects. This is, in my opinion, unfortunate. You can work it around with a bit of code. This function returns the list of elements spanned by a list <code>G</code> of generators</p>
<pre><code>def list_elts(G):
exps = [xrange(g.multiplicative_order()) for g in G]
return [prod(g^e for g, e in zip(G, exp)) for exp in CartesianProduct(*exps)]
</code></pre>
<p>So, you may call</p>
<pre><code>sage: R = Zmod(20)
sage: map(list_elts, R.multiplicative_subgroups())
[[1, 17, 9, 13, 11, 7, 19, 3],
[1, 11, 9, 19],
[1, 3, 9, 7],
[1, 11],
[1, 19],
[1, 17, 9, 13],
[1, 9],
[1]]
</code></pre>
https://ask.sagemath.org/question/11019/list-members-of-each-subgroup-of-integers-modulo-n/?comment=16288#post-id-16288Thank you - that did the trick!Mon, 10 Feb 2014 17:11:12 +0100https://ask.sagemath.org/question/11019/list-members-of-each-subgroup-of-integers-modulo-n/?comment=16288#post-id-16288