Ask Your Question
3

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

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

B r u n o gravatar image

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

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

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

tmonteil gravatar image

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

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 20:53:46 +0200 )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 10:57:25 +0200 )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 +0200 )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 +0200 )edit
kcrisman gravatar imagekcrisman ( 2015-10-01 20:54:55 +0200 )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 18:24:45 +0200

Seen: 7,599 times

Last updated: Sep 29 '15