### 7.1.9 Integer Euclidean remainder

The irem or remain command finds the remainder of two integers (see Section 7.1.8).

- irem takes two arguments: a and b, integers.
- irem(a,b) returns the remainder r of a divided by b.

#### Examples

irem(148,5)

3 |  |  |  |  |  |  |  |  |  |

irem(factorial(148),factorial(45)+2)

111615339728229933018338917803008301992120942047239639312 |  |  |  |  |  |  |  |  |  |

irem(25+12*i,5+7*i)

−4+i |  |  |  |  |  |  |  |  |  |

Here r=a−b q=−4+i and |−4+i|2=17<|5+7 i|2/2=74/2=37.

The smod or mods command finds the symmetric remainder of two (ordinary) integers.

- smod takes two arguments: a and b, integers.
- smod(a,b) returns the symmetric remainder s of the Euclidean division of a and b; namely, the value s with a=b q+s and −b/2<s ≤ b/2.

#### Example

smod(148,5)

−2 |  |  |  |  |  |  |  |  |  |

The mod or % operator is an infixed operator which takes an integer to a modular integer.

- mod has two operands: a and b, ordinary integers.
- a mod b returns r % b in ℤ/bℤ, where r is the remainder of the Euclidean division of the arguments a and b.

#### Example

148 mod 5

or:

148 % 5

| ⎛ ⎝ | −2 | ⎞ ⎠ | %5

Note that the result -2 % 5 is not an integer (−2) but an element of Z/5Z (see Section 11.8 for the possible operations in Z/5Z).