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.Fri, 25 Jun 2021 10:06:48 +0200how can I manipulate a multiplicative group of Zmod(n)https://ask.sagemath.org/question/57703/how-can-i-manipulate-a-multiplicative-group-of-zmodn/Hi,
I want to create the multiplicative group $(\mathbb{Z}/7\mathbb{Z})^*=\\{1,2,3,4,5,6\\}$.
I did these steps:
sage: n = 7
sage: Zn = Zmod(n)
sage: G = Zn.unit_group()
sage: list(G)
[1, f, f^2, f^3, f^4, f^5]
Then I want to create the subgroups generated by $2=f^2$ which is $\\{1,2,4\\}$.
I did the following steps:
sage: f = G.gen()
sage: H = G.subgroup([f^2])
sage: list(H)
[1, f, f^2]
My problem is when I did
sage: Zn(f)
3
But here `f` needs to be 2. How can I solve this? Replace `f` by value?Wed, 23 Jun 2021 17:50:29 +0200https://ask.sagemath.org/question/57703/how-can-i-manipulate-a-multiplicative-group-of-zmodn/Comment by tmonteil for <p>Hi,</p>
<p>I want to create the multiplicative group $(\mathbb{Z}/7\mathbb{Z})^*=\{1,2,3,4,5,6\}$.</p>
<p>I did these steps:</p>
<pre><code>sage: n = 7
sage: Zn = Zmod(n)
sage: G = Zn.unit_group()
sage: list(G)
[1, f, f^2, f^3, f^4, f^5]
</code></pre>
<p>Then I want to create the subgroups generated by $2=f^2$ which is $\{1,2,4\}$.</p>
<p>I did the following steps:</p>
<pre><code>sage: f = G.gen()
sage: H = G.subgroup([f^2])
sage: list(H)
[1, f, f^2]
</code></pre>
<p>My problem is when I did</p>
<pre><code>sage: Zn(f)
3
</code></pre>
<p>But here <code>f</code> needs to be 2. How can I solve this? Replace <code>f</code> by value?</p>
https://ask.sagemath.org/question/57703/how-can-i-manipulate-a-multiplicative-group-of-zmodn/?comment=57719#post-id-57719For those interested, there is a parallel discussion on that topic on sage-devel : https://groups.google.com/g/sage-devel/c/D3zdWqswrFoThu, 24 Jun 2021 02:42:53 +0200https://ask.sagemath.org/question/57703/how-can-i-manipulate-a-multiplicative-group-of-zmodn/?comment=57719#post-id-57719Comment by slelievre for <p>Hi,</p>
<p>I want to create the multiplicative group $(\mathbb{Z}/7\mathbb{Z})^*=\{1,2,3,4,5,6\}$.</p>
<p>I did these steps:</p>
<pre><code>sage: n = 7
sage: Zn = Zmod(n)
sage: G = Zn.unit_group()
sage: list(G)
[1, f, f^2, f^3, f^4, f^5]
</code></pre>
<p>Then I want to create the subgroups generated by $2=f^2$ which is $\{1,2,4\}$.</p>
<p>I did the following steps:</p>
<pre><code>sage: f = G.gen()
sage: H = G.subgroup([f^2])
sage: list(H)
[1, f, f^2]
</code></pre>
<p>My problem is when I did</p>
<pre><code>sage: Zn(f)
3
</code></pre>
<p>But here <code>f</code> needs to be 2. How can I solve this? Replace <code>f</code> by value?</p>
https://ask.sagemath.org/question/57703/how-can-i-manipulate-a-multiplicative-group-of-zmodn/?comment=57706#post-id-57706Welcome to Ask Sage! Thank you for your question.Wed, 23 Jun 2021 19:11:08 +0200https://ask.sagemath.org/question/57703/how-can-i-manipulate-a-multiplicative-group-of-zmodn/?comment=57706#post-id-57706Answer by slelievre for <p>Hi,</p>
<p>I want to create the multiplicative group $(\mathbb{Z}/7\mathbb{Z})^*=\{1,2,3,4,5,6\}$.</p>
<p>I did these steps:</p>
<pre><code>sage: n = 7
sage: Zn = Zmod(n)
sage: G = Zn.unit_group()
sage: list(G)
[1, f, f^2, f^3, f^4, f^5]
</code></pre>
<p>Then I want to create the subgroups generated by $2=f^2$ which is $\{1,2,4\}$.</p>
<p>I did the following steps:</p>
<pre><code>sage: f = G.gen()
sage: H = G.subgroup([f^2])
sage: list(H)
[1, f, f^2]
</code></pre>
<p>My problem is when I did</p>
<pre><code>sage: Zn(f)
3
</code></pre>
<p>But here <code>f</code> needs to be 2. How can I solve this? Replace <code>f</code> by value?</p>
https://ask.sagemath.org/question/57703/how-can-i-manipulate-a-multiplicative-group-of-zmodn/?answer=57742#post-id-57742### Going through the group of units
This implementation suffers from the defect that
- elements of `H` have `G` as their parent
- but they display in terms of a generator of `H`
Here is a slightly convoluted way to work around this.
Define `G` and `H`:
sage: n = 7
sage: Zn = Zmod(n)
sage: G = Zn.unit_group()
sage: f = G.gen()
sage: H = G.subgroup([f^2])
List the elements of `H` (this displays using a different `f`):
sage: Hlist = list(H)
sage: Hlist
[1, f, f^2]
List the elements of `H` expressed in `G`:
sage: HlistG = list(prod((a^b for a, b in zip(H.gens(), h.list())), G.one()) for h in H)
sage: HlistG
[1, f^2, f^4]
Get their values in `Zn`:
sage: HlistZn = [h.value() for h in HlistG]
sage: HlistZn
[1, 2, 4]
I opened a ticket to make this happen more naturally:
- [Sage Trac ticket 32064: Improve unit groups of rings Z/nZ and their subgroups](https://trac.sagemath.org/ticket/32064)
### Direct access to generating sets for subgroups
The cyclic ring also has a method `multiplicative_subgroups`.
That method lists generating tuples for its multiplicative subgroups:
sage: n = 7
sage: Zn = Zmod(n)
sage: Sub = Zn.multiplicative_subgroups()
sage: Sub
((3,), (2,), (6,), ())
Sadly they do not give a hold on the subgroups as such.
sage: H = Sub[1]
sage: H
(2,)
sage: parent(H)
<class 'tuple'>
Neither do the generators for these subgroups have these
subgroups as parents.
Instead, they are simply elements of the initial cyclic ring.
sage: h = H[0]
sage: parent(h)
Ring of integers modulo 7Fri, 25 Jun 2021 10:06:48 +0200https://ask.sagemath.org/question/57703/how-can-i-manipulate-a-multiplicative-group-of-zmodn/?answer=57742#post-id-57742