Modular Arithmetic

Ths chapter covers notes on modular arithmetic.

Remark: In the notes below, we often use the term "division" for ease of communication alongside writing expressions like a/b.{a/b.} This is an abuse of notation and language. When we use the word division, we mean the following:

division. Let a,b∈Z.{a,b \in \uint.} Then a/b{a/b} is defined if and only if there exists a q∈Z{q \in \uint} such that a=bq+r{a = bq + r} with 0≀r<b.{0 \le r \lt b.}

We state this definition because at a formal level, the operation of division that we usually think of does not exist in the world of integers. The standard definition of division is a/b=c⇔a=bβ‹…c.{a/b = c \iff a = b \by c.} There is no integer that satisfies 2c=1,{2c = 1,} so there's no such thing as "division" in the usual sense. In fact, the very lack of division is why we have a seperate set of numbers, Q,{\rat,} called the rationals.

Divisors

We begin this section by defining a few special sets.

divisors. Let n∈Z.{n \in \uint.} Then the poset ( ∣ n){(\dv_n)} denotes the set of all divisors of n.{n.}

Example. ( ∣ 9)={ 1,3,9 }.{(\dv_{9}) = \set{1,3,9}.}

Example. ( ∣ 36)={ 1,2,3,4,6,9,12,18,36 }.{(\dv_{36}) = \set{1,2,3,4,6,9,12,18,36}.}

Following the definition above, all sets of divisors ( ∣ n){(\dv_n)} are non-empty. They will always contain the integer 1{1} and n{n} itself.

common divisors. Let n,m∈Z.{n,m \in \uint.} Given the sets of divisors ( ∣ n){(\dv_n)} and ( ∣ m),{(\dv_m),} then the set ( ∣ n∩ ∣ m){(\dv_n \cap \dv_m)} is the set of all common divisors of n{n} and m.{m.} Given an integer x∈( ∣ n∩ ∣ m),{x \in (\dv_n \cap \dv_m),} we say that x{x} is a common divisor of n{n} and m.{m.}

example. ( ∣ 12∩ ∣ 8)={ 1,2,3,4,6,12 }∩{ 1,2,4,8 }={ 1,2,4 }.{(\dv_{12} \cap \dv_{8}) = \set{1,2,3,4,6,12} \cap \set{1,2,4,8} = \set{1,2,4}.}

Since all sets of divisors contain the integer 1,{1,} all intersections of divisor sets are non-empty β€” they all contain the integer 1.{1.} There is, however, a special case where the intersection consists of only 1.{1.}

coprimality. Let n,m∈Z.{n,m \in \uint.} If ( ∣ n∩ ∣ m)={1},{(\dv_n \cap \dv_m) = \lset{1},} then we say that n{n} and m{m} are coprime or relatively prime.

Example. The integers 13{13} and 8{8} are coprime, since ( ∣ 13)={ 1,13 },{(\dv_{13}) = \set{1,13},} ( ∣ 8)={ 1,2,4,8 }{(\dv_{8}) = \set{1,2,4,8}} and ( ∣ 13∩ ∣ 8)={ 1 }.{(\dv_{13} \cap \dv_{8}) = \set{1}.}

We're often interested in the largest element of a common divisor set, called the greatest common divisor.

greatest common divisor. Let n,m∈Z{n,m \in \uint} and x∈( ∣ n∩ ∣ m).{x \in (\dv_n \cap \dv_m).} If x{x} is the maximum element of ( ∣ n∩ ∣ m),{(\dv_n \cap \dv_m),} then x{x} is the greatest common divisor of n{n} and m,{m,} and we write gcd(n,m)=x.{\gcd{{n,m}} = x.}

Example. gcd(12,18)=16.{\gcd{12,18} = 16.}

Example. gcd(16,8)=4.{\gcd{16,8} = 4.}

Multiples

multiples. Let n{n} be an integer and ZβŠ†Z{\Z \subseteq \uint}. Then the set nZ{n \Z} denotes the set of multiples of n.{n.} If x∈nZ,{x \in n \Z,} then we say that x{x} is a multiple of n.{n.}

Example. 2N={ 0,2,4,6,8,10,12,14,16,… }{2 \nat = \set{0,2,4,6,8,10,12,14,16,\ldots}}

Example. 2Z+={ 2,4,6,8,10,12,14,16,… }{2 \uint^+ = \set{2,4,6,8,10,12,14,16,\ldots}}

Example. 3Z={ …,βˆ’9,βˆ’6,βˆ’3,0,3,6,9,… }{3 \uint = \set{\ldots, -9, -6, -3, 0, 3, 6, 9, \ldots}}

From the definition of a multiple, we can determine that the sum of any two multiples of kn{kn} is also a multiple of n.{n.} Suppose a{a} and b{b} are integers, and an{an} and bn{bn} are multiples of n.{n.} It follows that:

an+bn=(a+b)n an + bn = (a + b)n

Since addition is closed on the integers, it follows that a+b{a + b} is an integer. Thus, (an+bn=(a+b)n)∈nZ.{(an + bn = (a+b)n) \in n \uint.} The same idea extends to subtraction: The difference between any two multiples of n{n} is also a multiple of n.{n.} Given the n{n}-multiples an{an} and bn,{bn,} it follows that anβˆ’bn=(aβˆ’b)n.{an - bn = (a-b)n.} And since subtraction is closed on the integers, the term (aβˆ’b){(a-b)} is an integer. Thus, (aβˆ’b)n{(a-b)n} is also a multiple of n.{n.}

This leads to an alternative reading of the relation a ∣ b.{a \dv b.} When we write a ∣ b,{a \dv b,} we're effectively implying that b{b} is a multiple of a.{a.} Thus, another way of viewing the "divides" relation is that it's the "multiple of" relation.

a ∣ b{a \dv b} β‡’{\nc} "b{b} is a multiple of a.{a.}"

We thus have the following lemma:

lemma. Given a,b,c∈Z,{a,b,c \in \uint,} if c ∣ a{c \dv a} and c ∣ b,{c \dv b,} then c ∣ (a+b){c \dv (a + b)} and c ∣ (aβˆ’b).{c \dv (a - b).}

It's helpful to know an alternative framing of the lemma above. Suppose a,b,c∈Z,{a,b,c \in \uint,} and c ∣ aβˆ’b{c \dv a - b} and c ∣ b.{c \dv b.} Then c ∣ (aβˆ’b+b=a),{c \dv (a - b + b = a),} following our previous lemma. Thus, we have:

lemma. Given a,b,c∈Z,{a,b,c \in \uint,} if c ∣ (aβˆ’b){c \dv (a - b)} and c ∣ b,{c \dv b,} then c ∣ a.{c \dv a.}

This leads us to the notion of common multiples:

common multiples. Let n{n} and m{m} be integers, nZ{n \Z} the set of all multiples of n{n} and mZ{m \Z} the set of all multiples of m.{m.} Then nZ∩mZ{n \Z \cap m \Z} denotes the set of all common multiples of n{n} and m.{m.} Given an integer x∈nZ∩mZ,{x \in n \Z \cap m \Z,} we call x{x} a common multiple of n{n} and m.{m.}

Example. 4Z+∩6Z+={ 12,24,36,48,60,72,84,… }.{4 \uint^+ \cap 6 \uint^+ = \set{12,24,36,48,60,72,84,\ldots}.}

There's a particularly special multiple when we work with positive multiples. Because the positive integers are just the natural numbers without 0,{0,} they have the special property of being well-ordered. That is, there's always a least element in any set of positive integers. This means that, the intersection nZ+∩mZ+{n \uint^+ \cap m \uint^+} where n{n} and m{m} are positive integers always contains a least element called the least common multiple.

least common multiple. Let n,m∈Z+,{n,m \in \uint^+,} and the sets nZ+{n \uint^+} and the mZ+{m \uint^+} denoting the positive multiples of n{n} and m{m} respectively. Then the least element of nZ+∩mZ+{n \uint^+ \cap m \uint^+} is called the least common multiple of n{n} and m,{m,} which we denote as lcm(n,m).{\df{lcm}(n,m).}

Example. lcm(4,6)=12,{\df{lcm}(4,6) = 12,} since 4Z+∩6Z+={ 12,24,36,48,…. }{4\uint^+ \cap 6 \uint^+ = \set{12,24,36,48,\ldots.}}

The link between multiples and common divisors is encapsulated in the following theorem.

euclid's theorem. For all m,n∈N{m,n \in \nat} with m>n,{m \gt n,} it follows that gcd(m,n)=gcd(mβˆ’n,n).{\gcd{m,n} = \gcd{m-n,n}.}

The proof is fairly straightfoward. Given m,n,c∈N{m,n,c \in \nat} with m>n,{m \gt n,} if c ∣ (mβˆ’n){c \dv (m - n)} and c ∣ n,{c \dv n,} then c ∣ m.{c \dv m.} Similarly, if c ∣ m{c \dv m} and c ∣ n,{c \dv n,} then c ∣ (mβˆ’n).{c \dv (m - n).} These are merely the two lemmas we proved earlier. If it were instead the case that c ∣ (mβˆ’n){c \dv (m - n)} and c ∣ n{c \dv n} but c{c} was not a common divisor of both m{m} and n,{n,} then it must be the case that c{c} is not a divisor of m.{m.} But this would contradict the lemma we just proved. If it were instead the case that c ∣ n{c \dv n} and c ∣ m{c \dv m} but c∀(mβˆ’n){c \ndv (m-n)} and c∀n,{c \ndv n,} then it must be the case that c{c} is not a divisor of mβˆ’n.{m - n.} But this would contradict another lemma we just proved β€” that ((c ∣ m)∧(c ∣ n))β‡’(c ∣ (mβˆ’n)).{((c \dv m) \land (c \dv n)) \nc (c \dv (m - n)).} Thus, it must be the case that set of all the common divisors of m{m} and n{n} and the common divisors of mβˆ’n{m-n} and n{n} are the exact same sets. And since they're the exact same sets, it follows that their maximum element is also the same.

The theorem above is a particularly useful theorem because it's almost always the case that finding the greatest common divisor of two integers m{m} and n{n} is much easier for smaller integers than it is for larger integers. This is particularly true for computers; they can only handle integers so large.

Remainders

Consider the following equations:

10=3a+b11=3a+b12=3a+b13=3a+b14=3a+b15=3a+b16=3a+b \eqs{ 10 &= 3a + b \\ 11 &= 3a + b \\ 12 &= 3a + b \\ 13 &= 3a + b \\ 14 &= 3a + b \\ 15 &= 3a + b \\ 16 &= 3a + b \\ }

If a∈Z{a \in \uint} and b∈{ 0,1,2 },{b \in \set{0,1,2},} what are the pairs of (a,b){(a,b)} that satisfy the equations respectively? Well, let's lay them out:

equationa{a}b{b}(a,b){(a,b)}
10=3a+b{10 = 3a + b}3{3}1{1}(3,1){(3,1)}
11=3a+b{11 = 3a + b}3{3}2{2}(3,2){(3,2)}
12=3a+b{12 = 3a + b}4{4}0{0}(4,0){(4,0)}
13=3a+b{13 = 3a + b}4{4}1{1}(4,1){(4,1)}
14=3a+b{14 = 3a + b}4{4}2{2}(4,2){(4,2)}
15=3a+b{15 = 3a + b}5{5}0{0}(5,0){(5,0)}
16=3a+b{16 = 3a + b}5{5}1{1}(5,1){(5,1)}

Question: Given a∈Z{a \in \uint} and b∈{ 0,1,2 },{b \in \set{0,1,2},} is there an integer n{n} such that no pair (a,b){(a,b)} satisfies the equation n=3a+b?{n = 3a + b?} Well, let's think about the integer 3a{3a} for a moment. If a∈Z,{a \in \uint,} then 3a∈3Z.{3a \in 3 \uint.} That is, 3a{3a} is a multiple of 3.{3.} We can think of a multiple of some integer n{n} as long-jumping along the integer number line by kn{kn} places, where k{k} is the multiple. In this case, 3n{3n} means that there are certain places that we land on by default:

-6-5-4-3-2-1012345
∘{\circ}∘{\circ}∘{\circ}∘{\circ}

If we want to land on an integer other outside of 3Z,{3\uint,} that is, an integer that is not a multiple of 3,{3,} then we must add either 1{1} or 2.{2.} For example, to go from βˆ’6{-6} to βˆ’5,{-5,} must add 1.{1.} To go from 3{3} to 5,{5,} must add 2.{2.}

If we think of addition as moving along the number line, this phenomenon is intuitive. If we start at the integer 0{0} and want to get to the integer 6,{6,} we take 6{6} steps, where each step is one.

01=0+12=1+13=2+14=3+15=4+16=5+1 \eqs{ 0 & \\ 1 &= 0 + 1 \\ 2 &= 1 + 1 \\ 3 &= 2 + 1 \\ 4 &= 3 + 1 \\ 5 &= 4 + 1 \\ 6 &= 5 + 1 \\ }

Thus, to get from point n{n} to a destination d,{d,} we perform +m{+ m} to get to d,{d,} where m{m} is the number of steps. That is, d=n+m.{d = n + m.} If we start at a point kn,{kn,} then that means we took n{n} steps from 0{0} a total of k{k} times. And if we start from kn{kn} and want to get to a destination d,{d,} then we have d=kn+m.{d = kn + m.} If we rearrange this equation, we get dβˆ’m=kn.{d - m = kn.} We can read this as "Take m{m} steps back to return to kn.{kn.}" And since dβˆ’m=kn,{d - m = kn,} it must be the case that m<k.{m \lt k.} And since m{m} stands for the number of steps, it's a nonnegative quantity, so we can be even more specific: 0≀m≀k.{0 \le m \le k.} As it turns out, this is leads to an extremely important theorem in number theory called the Division Theorem.

division theorem. Let a,b∈Z.{a,b \in \uint.} Then there is exactly one pair of integers (q,r){(q,r)} with 0≀r<b,{0 \le r \lt b,} such that a=bq+r.{a = bq + r.} Given a=bq+r,{a = bq + r,} we call a{a} the dividend, b{b} the divisor, q{q} the quotient, and r{r} the remainder.

The division theorem leads to a natural extension of a theorem we've seen before.

euclid's theorem ii. Let m,n,q,r∈Z{m,n,q,r \in \uint} with 0≀r<n{0 \le r \lt n} such that m=qn+r.{m = qn + r.} Then gcd(m,n)=gcd(r,n).{\gcd{m,n} = \gcd{r,n}.}

Floors and Ceilings

We begin by defining the floors and ceilings of real numbers. The definitions below are presented formally to ensure we aren't sweeping anything under the rug or hiding the ball. For our purposes, the floor function returns the closest integer to a real number x{x} that is less than x.{x.} Its sibling is the ceiling function, which returns the closest integer to a real number x{x} that is greater than x.{x.}

floor. Given a real number x,{x,} there exists a function f:Rβ†’Z{f: \reals \to \uint} whose image under R{\reals} is an integer n{n} satisfying the relation n≀x<n+1.{n \le x \lt n + 1.} We call n{n} the floor of x,{x,} denoted ⌊xβŒ‹,{\floor{x},} and f{f} the floor function.

Example. ⌊2.1βŒ‹=2.{\floor{2.1} = 2.}

Example. ⌊3.9βŒ‹=3.{\floor{3.9} = 3.}

Example. ⌊2.99999βŒ‹=2.{\floor{2.99999} = 2.}

Example. βŒŠβˆ’8.9βŒ‹=βˆ’9.{\floor{-8.9} = -9.} (Remember that the floor returns the closest integer less than its argument).

ceiling. Let x{x} be a real number. Then there exists a function f:Rβ†’Z{f: \reals \to \uint} whose image under R{\reals} is an integer n{n} satisfying the relation nβˆ’1<x≀n.{n - 1 \lt x \le n.} We call n{n} the ceiling of x,{x,} denoted ⌈xβŒ‰,{\ceil{x},} and f{f} the ceiling function.

Example. ⌈2.9βŒ‰=3.{\ceil{2.9} = 3.}

Example. ⌈6.1βŒ‰=7.{\ceil{6.1} = 7.}

Example. ⌈0.009βŒ‰=1.{\ceil{0.009} = 1.}

Example. βŒˆβˆ’3.1βŒ‰=βˆ’2.{\ceil{-3.1} = -2.} (The ceiling function returns the closest integer greater than its argument).

Remainders and Quotients

Having defined the floor and ceiling functions, we can now define the remainder operation. Informally, the remainder operation returns the remainder after division.

remainder operation. Let a,b∈Z{a,b \in \uint} and b>0.{b \gt 0.} Then

aΒ remΒ b=aβˆ’b(⌊a/bβŒ‹). a \rem b = a - b \ar{ \floor{a/b} }.

Example. 25Β remΒ 3=25βˆ’3(⌊25/3βŒ‹)=25βˆ’3(8)=25βˆ’24=1.{25 \rem 3 = 25 - 3(\floor{25/3}) = 25 - 3(8) = 25 - 24 = 1.}

Example. 18Β remΒ 3=18βˆ’3(⌊18/3βŒ‹)=18βˆ’3(6)=18βˆ’18=0.{18 \rem 3 = 18 - 3(\floor{18/3}) = 18 - 3(6) = 18 - 18 = 0.}

Example. βˆ’12Β remΒ 7=βˆ’12βˆ’7(βŒŠβˆ’12/7βŒ‹)=βˆ’12βˆ’7(βˆ’2)=βˆ’12+14=2.{-12 \rem 7 = -12 - 7(\floor{-12/7}) = -12 - 7(-2) = -12 + 14 = 2.}

The remainder operation's partner is the integer division operation. Informally, it returns the integer quotient after division.

integer division. Let a,b∈Z{a,b \in \uint} and b>0.{b \gt 0.} Then

aΒ divΒ b=⌊a/bβŒ‹. a \quo b = \floor{a/b}.

As an aside, many programming languages (e.g., Python) use % for the remainder operation and // for integer division. These operations behave differently from the mathematical definitions. Some languages, for example, may return a negative result given some expression a % b where a and b are integers. This stems from two rules that many computer architects and software engineers want:

(1) a=b(aΒ divΒ b)+(aΒ remΒ b).{a = b(a \quo b) + (a \rem b).}

(2) (βˆ’a)Β divΒ b=βˆ’(aΒ divΒ b).{(-a) \quo b = -(a \quo b).}

The first rule is sensible. It's exactly how normal division works. The second rule, however, is suspect. As we saw, the floor should return the closest integer to a real number a/b{a/b} that is less than a/b.{a/b.} Thus, the expression (βˆ’a)Β divΒ b{(-a) \quo b} is most certainly a very different expression from βˆ’(aΒ divΒ b).{-(a \quo b).} So if the second rule is mathematically silly (some mathematicians, rather unkindly, go so far as to call it "dirty"), why is its implementation incentivized? Because the vast majority of programmers β€” and arguably, the vast majority of integer division applications β€” do not use integer division the way its mathematically defined. If a language did use the mathematically correct definition, then the line of code

(βˆ’a)Β //Β b=βˆ’(aΒ //Β b) (-a) ~\texttt{//}~ b = -(a ~\texttt{//}~ b)

must be false.

There are two significant problems with this result from an engineering standpoint. First, it's a breeding ground for bugs. Anyone who's had experience designing products β€” e.g., a programming language β€” knows that the first rule of design is to never make the user think. This nuance to parentheses and integer division won't just make the user think; it may very well make them smash their keyboards. Those who leave their keyboards intact will either move to another language or try to "fix" the language with various hacks and publishing them β€” the designer's worst nightmare.

The second major problem is that implementing the mathematically correct definition requires a separate parsing rule for parentheses and integer division. That incurs a time and space cost for likely very little reward β€” most users do not expect a rule (βˆ’a)⋆bβ‰ βˆ’(a⋆b),{(-a) \star b \neq -(a \star b),} where ⋆{\star} is a binary operator on a number type. This also means that the designers have to decide how they'd like to parse βˆ’aΒ //Β b.{-a~\texttt{//}~b.} Is it (βˆ’a)Β //Β b{(-a) ~ \texttt{//} ~ b} or βˆ’(aΒ //Β b)?{-(a ~ \texttt{//}~ b)?} All of this translates to time, money, and labor; things that we don't have to worry about with mathematical definitions.

Congruence

Suppose we had the following, somewhat strange, clock. The cock only has one hand, and it moves around the clock from 0{0} to 1,{1,} then from 1{1} to 2,{2,} then from 3{3} to 4,{4,} and finally from 4{4} to 0.{0.} Assume it moves only in that order.

01234

If the clock ticks by 1, then the hand lands on 1. If the clock ticks by 2, then the hand lands on 2. Let's take a look at some of the patterns:

tick012345678910111213141516171819hand01234012340123401234 \ax{ \df{tick} & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 \\ \df{hand} & 0 & 1 & 2 & 3 & 4 & 0 & 1 & 2 & 3 & 4 & 0 & 1 & 2 & 3 & 4 & 0 & 1 & 2 & 3 & 4 \\ }

Here's another way to look at the pattern:

01234012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 \ax{ 0 & 1 & 2 & 3 & 4 \\ \hline 0 & 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 & 9 \\ 10 & 11 & 12 & 13 & 14 \\ 15 & 16 & 17 & 18 & 19 \\ 20 & 21 & 22 & 23 & 24 \\ 25 & 26 & 27 & 28 & 29 \\ 30 & 31 & 32 & 33 & 34 \\ 35 & 36 & 37 & 38 & 39 \\ 40 & 41 & 42 & 43 & 44 \\ 45 & 46 & 47 & 48 & 49 \\ }

The first row, separated from all the others, corresponds to a number on the clock. The integers beneath each clock number correspond to the number of ticks. Thus, at 5 clicks, we land on 0. At 19 clicks, we land on 4. At 46 clicks, we land on 1. Counting with only 0,1,2,3,4{0,1,2,3,4} is called counting modulo 5. It's an example of a broader notion called arithmetic modulo-n{n}, where n{n} is the set { 0,1,2,3,…,nβˆ’1 }{\set{0,1,2,3,\ldots,n-1}} with n∈N.{n \in \nat.} In general, we call the set { 0,1,2,3,…,nβˆ’1 }{\set{0,1,2,3,\ldots,n-1}} the integers modulo-n{n}, and we call n{n} the modulus. We aren't limited to just counting forwards β€” we can count backwards as well:

βˆ’50βˆ’49βˆ’48βˆ’47βˆ’46βˆ’45βˆ’44βˆ’43βˆ’42βˆ’41βˆ’40βˆ’39βˆ’38βˆ’37βˆ’36βˆ’35βˆ’34βˆ’33βˆ’32βˆ’31βˆ’30βˆ’29βˆ’28βˆ’27βˆ’26βˆ’25βˆ’24βˆ’23βˆ’22βˆ’21βˆ’20βˆ’19βˆ’18βˆ’17βˆ’16βˆ’15βˆ’14βˆ’13βˆ’12βˆ’11βˆ’10βˆ’9βˆ’8βˆ’7βˆ’6βˆ’5βˆ’4βˆ’3βˆ’2βˆ’1012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 \ax{ -50 & -49 & -48 & -47 & -46 \\ -45 & -44 & -43 & -42 & -41 \\ -40 & -39 & -38 & -37 & -36 \\ -35 & -34 & -33 & -32 & -31 \\ -30 & -29 & -28 & -27 & -26 \\ -25 & -24 & -23 & -22 & -21 \\ -20 & -19 & -18 & -17 & -16 \\ -15 & -14 & -13 & -12 & -11 \\ -10 & -9 & -8 & -7 & -6 \\ -5 & -4 & -3 & -2 & -1 \\ 0 & 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 & 9 \\ 10 & 11 & 12 & 13 & 14 \\ 15 & 16 & 17 & 18 & 19 \\ 20 & 21 & 22 & 23 & 24 \\ 25 & 26 & 27 & 28 & 29 \\ 30 & 31 & 32 & 33 & 34 \\ 35 & 36 & 37 & 38 & 39 \\ 40 & 41 & 42 & 43 & 44 \\ 45 & 46 & 47 & 48 & 49 \\ }

Given c{c} clock numbers, is there a way to determine which clock number β„“{\ell} we land on after t{t} ticks? Yes: β„“=cΒ remΒ t.{\ell = c \rem t.} For example, for our sample clock, there are t=5{t = 5} clock numbers. After c=8{c=8} ticks, we land on 8Β remΒ 5=8βˆ’5(⌊8/5βŒ‹)=8βˆ’5(1)=3,{8 \rem 5 = 8 - 5(\floor{8/5}) = 8 - 5(1) = 3,} which is what our pattern indicates. At this point, we can now introduction some notation.

congruence. Let a,b,m∈Z{a,b,m \in \uint} and m>0.{m \gt 0.} If, and only if, a rem m=b rem m,{a \rem m = b \rem m,} we say that a{a} is congruent to b{b} modulo m{m} and write

a≑b(modm). a \equiv b \pmod m.

We call the proposition a≑b(modm){a \equiv b \pmod m} a congruence and call m{m} its modulus. If a{a} and b{b} are not congruent modulo m{m}, then we write a≑̸b(modm).{a \not\equiv b \pmod m.}

Let's iron out some wrinkles with this definition. First, the notation

a≑b(modm) a \equiv b \pmod m

is akin to saying "a{a} is equivalent to b{b} ... (modm){\pmod m}-wise, that is." The (modΒ Β m){(\text{mod} ~~ m)} is like an adjective. "Pope Francis and Marilyn Manson are equivalent ... human-wise, that is." A more consistent notation for the same idea would've been

a ≑modΒ Β cΒ b. a ~\equiv_{\text{mod}~~c}~ b.

The symbol mod{\text{mod}} is another symbol for the remainder operation, which, in these materials, we denoted Β remΒ .{\rem.} We avoid using mod{\text{mod}} for the remainder operation because it causes unnecessary confusion. However, now that we know that mod{\text{mod}} is just another symbol for the remainder operation, we can conjecture as to why the notation is the way it is. It's not too difficult to imagine a lecturer writing

a≑b a \equiv b

on a chalkboard, then, just to make sure things are clear, writing

a≑b(modm). a \equiv b \pmod m.

This would also explain why there's that irregular spacing (again, just conjecture).

Second, in the expression a≑b(modm),{a \equiv b \pmod m,} the notation (modΒ m){(\text{mod} ~ m)} denotes a set of integers. This is another reason why we avoid using mod{\text{mod}} for the remainder operation.