1 | initial version |
Hi,
It is just because of the modulo operation which returns you not an integer but an element of the quotient Z/nZ.
sage: type(5)
<type 'sage.rings.integer.Integer'>
sage: type(mod(5,2))
<type 'sage.rings.finite_rings.integer_mod.IntegerMod_int'>
This is documented in the function mod.
Now comes the question what should be the comparison of an element of Z with an element of Z/nZ. The Sage's answer is that as there exists a natural coercion from Z to Z/nZ we first convert the element of Z to Z/nZ and then make the test. Notice that if you want the remainder and not the number modulo an other number you may use the symbol % as in
sage: for n in (0..50):
....: m = n % 8
....: if m == 3 or m == -3: print n,m
....:
3 3
11 3
19 3
27 3
35 3
43 3