Ask Your Question

# Ring conversion, finite to infinite

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 close merge delete

## 2 Answers

Sort by ยป oldest newest most voted

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

more

## Comments

Thanks, That makes sense too.

( 2018-06-13 14:14:32 +0200 )edit

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

more

## Comments

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

( 2018-06-08 17:04:09 +0200 )edit

## Your Answer

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

Add Answer

## Stats

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

Seen: 323 times

Last updated: Jun 08 '18