Mathematics · Ch 12 — Discrete Mathematics
Modular Arithmetic
Modular Arithmetic
Modular arithmetic replaces an integer by the remainder it leaves on division by a fixed modulus , written (" is congruent to modulo ").
Definition (congruence). means for some integer , where is the least non-negative remainder () when is divided by . Examples: (since ), , .
Residue classes. Dividing the integers by sorts every integer into exactly one of classes . For : , , , , ; any two numbers in the same class are congruent modulo . This is written .
A real application: ISBN check digits. Before 2007, the 10-digit ISBN used modulo- arithmetic for its final check digit (drawn from , standing for ): weighting the first nine digits by , summing, and reducing mod gives the check digit -- e.g. for , the weighted sum , matching the printed check digit . Since 2007, the 13-digit ISBN uses modulo- arithmetic instead: the first 12 digits are weighted alternately from the right, summed, rounded up to the next multiple of , and the difference (the additive inverse mod of the sum) becomes the 13th digit -- e.g. for , the weighted sum is , the next multiple of is , and is indeed the printed 13th digit.
Two new binary operations on .
Definition 12.6. For :
- Addition modulo : = the remainder of on division by .
- Multiplication modulo : = the remainder of on division by . Worked pattern -- on . The Cayley table for :
| 0 | 1 | 2 | 3 | 4 | |
|---|---|---|---|---|---|
| 0 | 0 | 1 | 2 | 3 | 4 |
| 1 | 1 | 2 | 3 | 4 | 0 |
| 2 | 2 | 3 | 4 | 0 | 1 |
| 3 | 3 | 4 | 0 | 1 | 2 |
| 4 | 4 | 0 | 1 | 2 | 3 |