Skip to content

Mathematics · Ch 12 — Discrete Mathematics

Modular Arithmetic

12.2.4

Modular Arithmetic

Modular arithmetic replaces an integer aa by the remainder bb it leaves on division by a fixed modulus n>1n>1, written a≡b(modn)a\equiv b\pmod n ("aa is congruent to bb modulo nn").

Definition (congruence). a≡b(modn)a\equiv b\pmod n means a−b=nka-b=nk for some integer kk, where bb is the least non-negative remainder (0≤b≤n−10\le b\le n-1) when aa is divided by nn. Examples: 25≡4(mod7)25\equiv4\pmod7 (since 25−4=21=7×325-4=21=7\times3), −20≡1(mod3)-20\equiv1\pmod3, 15≡0(mod5)15\equiv0\pmod5.

Residue classes. Dividing the integers by nn sorts every integer into exactly one of nn classes [0],[1],…,[n−1][0],[1],\ldots,[n-1]. For n=5n=5: [0]={…,−10,−5,0,5,10,…}[0]=\{\ldots,-10,-5,0,5,10,\ldots\}, [1]={…,−9,−4,1,6,11,…}[1]=\{\ldots,-9,-4,1,6,11,\ldots\}, [2]={…,−8,−3,2,7,12,…}[2]=\{\ldots,-8,-3,2,7,12,\ldots\}, [3]={…,−7,−2,3,8,13,…}[3]=\{\ldots,-7,-2,3,8,13,\ldots\}, [4]={…,−6,−1,4,9,14,…}[4]=\{\ldots,-6,-1,4,9,14,\ldots\}; any two numbers in the same class are congruent modulo 55. This is written Z5={[0],[1],[2],[3],[4]}\mathbb Z_5=\{[0],[1],[2],[3],[4]\}.

A real application: ISBN check digits. Before 2007, the 10-digit ISBN used modulo-1111 arithmetic for its final check digit (drawn from {0,1,…,9,X}\{0,1,\ldots,9,X\}, XX standing for 1010): weighting the first nine digits by 1,2,…,91,2,\ldots,9, summing, and reducing mod 1111 gives the check digit -- e.g. for 81-7808-755-381\text{-}7808\text{-}755\text{-}3, the weighted sum 1(8)+2(1)+3(7)+4(8)+5(0)+6(8)+7(7)+8(5)+9(5)=245≡3(mod11)1(8)+2(1)+3(7)+4(8)+5(0)+6(8)+7(7)+8(5)+9(5)=245\equiv3\pmod{11}, matching the printed check digit 33. Since 2007, the 13-digit ISBN uses modulo-1010 arithmetic instead: the first 12 digits are weighted alternately 3,1,3,1,…3,1,3,1,\ldots from the right, summed, rounded up to the next multiple of 1010, and the difference (the additive inverse mod 1010 of the sum) becomes the 13th digit -- e.g. for 978-81-931995-6978\text{-}81\text{-}931995\text{-}6, the weighted sum is 155155, the next multiple of 1010 is 160160, and 160−155=5160-155=5 is indeed the printed 13th digit.

Two new binary operations on Zn={0,1,…,n−1}\mathbb Z_n=\{0,1,\ldots,n-1\}.

Definition 12.6. For a,b∈Zna,b\in\mathbb Z_n:

  1. Addition modulo nn: a+nba+_nb = the remainder of a+ba+b on division by nn.
  2. Multiplication modulo nn: a×nba\times_nb = the remainder of a×ba\times b on division by nn. Worked pattern -- +5+_5 on Z5\mathbb Z_5. The Cayley table for +5+_5:
+5+_501234
001234
112340
223401
334012
440123