1 | initial version |
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