Ask Your Question
2

Ring conversion, finite to infinite

asked 2018-06-08 11:56:24 +0100

rb57cat gravatar image

updated 2018-06-08 16:46:59 +0100

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 18:47:41 +0100

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 14:14:32 +0100 )edit
2

answered 2018-06-08 16:47:57 +0100

tmonteil gravatar image

updated 2018-06-08 16:55:09 +0100

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 17:04:09 +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

Stats

Asked: 2018-06-08 11:56:24 +0100

Seen: 347 times

Last updated: Jun 08 '18