# 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

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

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

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