Ask Your Question
2

Ring conversion, finite to infinite

asked 2018-06-08 04:56:24 -0500

rb57cat gravatar image

updated 2018-06-08 09:46:59 -0500

tmonteil gravatar image

Hello,

In the snippet below, how can I turn m into an integer or real so that the division results in 222?

m=mod(7, 5)
print m
  2
print type(m)
  <type 'sage.rings.finite_rings.integer_mod.IntegerMod_int'>
print 444/m
2

Regards, Rob.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2018-06-08 11:47:41 -0500

slelievre gravatar image

Note that the function mod used in the question returns a result in a finite ring of the type ZZ/n, which might not have been wanted.

The operation which returns the remainder modulo n as an integer is denoted in Python and in Sage by %.

Compare:

sage: a = mod(7, 5)
sage: a
2
sage: a.parent()
Ring of integers modulo 5
sage: a * 4
3

with

sage: b = 7 % 5
sage: b
2
sage: b.parent()
Integer Ring
sage: b * 4
8

Related to these, the operator // gives the quotient in the euclidean division, skipping the remainder; and the quo_rem method gives both the quotient and the remainder.

sage: c, d = 7.quo_rem(5)
sage: c, d
(1, 2)
sage: c * 5 + d
7

sage: cc = 7 // 5
sage: dd = 7 % 5
sage: cc, dd
(1, 2)
sage: cc * 5 + dd
7
edit flag offensive delete link more

Comments

Thanks, That makes sense too.

rb57cat gravatar imagerb57cat ( 2018-06-13 07:14:32 -0500 )edit
2

answered 2018-06-08 09:47:57 -0500

tmonteil gravatar image

updated 2018-06-08 09:55:09 -0500

You can convert it into an integer as follows:

sage: m.parent()
Ring of integers modulo 5
sage: n = ZZ(m)
sage: n
2
sage: n.parent()
Integer Ring
sage: 444/n
222
edit flag offensive delete link more

Comments

Thanks, I tried various ideas but I didn't think of that.

rb57cat gravatar imagerb57cat ( 2018-06-08 10:04:09 -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: 2018-06-08 04:56:24 -0500

Seen: 53 times

Last updated: Jun 08