Ask Your Question
2

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

asked 2015-09-28 11:24:45 -0500

B r u n o gravatar image

updated 2017-01-08 05:03:22 -0500

FrédéricC 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()
6

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() 
6

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
3

answered 2015-09-28 12:02:58 -0500

tmonteil gravatar image

updated 2015-09-29 08:35:21 -0500

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()
4
sage: G.inject_variables()
Defining f
sage: f^2
f^2
sage: f.order()
4
sage: (f^2).order()
2

This group G comes with and embedding into Zn:

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

Comments

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 13:53:46 -0500 )edit
1

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 03:57:25 -0500 )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 08:33:09 -0500 )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 10:32:45 -0500 )edit
kcrisman gravatar imagekcrisman ( 2015-10-01 13:54:55 -0500 )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

Stats

Asked: 2015-09-28 11:24:45 -0500

Seen: 1,023 times

Last updated: Sep 29 '15