Ask Your Question

Easiest way to work in the multiplicative group of Zmod(n)

asked 2015-09-28 18:24:45 +0100

B r u n o gravatar image

updated 2023-01-09 23:59:42 +0100

tmonteil gravatar image

Given an integer $n$, one can define in SageMath the additive group $\mathbb Z/n\mathbb Z$ by

sage: Zn = Zmod(n) # or Integers(n)

Now, I would like to work in the multiplicative group $(\mathbb Z/n\mathbb Z)^*$. Of course, I can write

sage: G = [a for a in Zn if gcd(a,n) == 1]
sage: Zn(4).multiplicative_order()

What I would like is an easier way of writing such a thing, such as:

sage: G = Zn.multiplicative_group() # does not exist!
sage: G(4).order() 

Does there exist something in SageMath to perform such kind of computations?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-09-28 19:02:58 +0100

tmonteil gravatar image

updated 2015-09-29 15:35:21 +0100

You can use the unit group of your ring:

sage: n = 10
sage: Zn = Zmod(n)
sage: G = Zn.unit_group()
sage: G
Multiplicative Abelian group isomorphic to C4
sage: G.order()
sage: G.inject_variables()
Defining f
sage: f^2
sage: f.order()
sage: (f^2).order()

This group G comes with and embedding into Zn:

sage: Zn(f)
sage: Zn(f^2)
sage: Zn(f^3)
sage: Zn(f^4)
sage: Zn(f^5)
edit flag offensive delete link more


Do you think there needs to be better documentation in Zmod() of this? Maybe a note about multiplicative group? Or an alias for tab-completion? Just wondering what you think.

kcrisman gravatar imagekcrisman ( 2015-09-28 20:53:46 +0100 )edit

Apparently I am not the only one who did not find that unit_group is the right method for this (cf this sage-devel thread). Another point: Though I understand that "the" G defined by unit_group is indeed the multiplicative group of Zn, I am still disturbed by the fact that its elements are not represented as integers. In particular, this implies that G(4) does not work, not G(Zn(4)).

B r u n o gravatar imageB r u n o ( 2015-09-29 10:57:25 +0100 )edit

In your example, 4 is not invertible in $\mathbb{Z}/10\mathbb{Z}$, so the map is not well defined. However you can go on the other way, from G to Zn. I edited the end of my answer to give an example.

tmonteil gravatar imagetmonteil ( 2015-09-29 15:33:09 +0100 )edit

Right, I chose a bad example, though of course it does not work with G(7) either. Well, thanks for the answer and its edition!

B r u n o gravatar imageB r u n o ( 2015-09-29 17:32:45 +0100 )edit
kcrisman gravatar imagekcrisman ( 2015-10-01 20:54:55 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-09-28 18:24:45 +0100

Seen: 7,434 times

Last updated: Sep 29 '15