As the title suggest, this is the fifth in a series of articles on introductory Number Theory. Today’s the day that we learn about fancy arithmetic called modular arithmetic or clock algebra.

A Motivating Mystery

Can you see why you will never find integer solutions to x^2 + y^2 = N when N = 3,\;43,\; 103, \;207,\;248?

We’ll spend some time today developing some tools that might seem strange and potentially not very useful… however, you’ll be pleasantly surprised. There are many problems that become obvious due to the use of modular arithmetic. The above problem is one of them!

Clock Counting (aka Modular Arithmetic)

Fun Fundamentals

Do you remember way back when you first learned how to divide two integers (I know I know you don’t like division)? You were supposed to answer with a remainder. Something like 30 divided by 4 equals 7 remainder 2 or simply 30 \div 4 = 7 \;\mathrm{R}2 . Just in case let’s dust off those skills because we are going to need them today!

For no other reason than because we can, we are going to focus on remainders. By this, we mean situations like, “What’s 23’s remainder when dividing by 10?” Well, 23 divided by 10 is 2 R3 or, 23 has a remainder 3 when divided by 10. Similarly, 45 has a remainder of 5 when divided by 10. And if you recall The Division Algorithm from Newbie at

Number Theory (Part 1) you know that we can always find a remainder.

The phrase “# has a remainder of # when divided by #” is very clunky and long. And I’m lazy. So, we will adopt the language of congruence and mod. Instead of saying: 23 has a remainder 3 when divided by 10 we will now say 23 is congruent to 3 (mod 10). Where congruent means “has a remainder” and mod means “when divided by”.

23 has a remainder 3 when divided by 10 \iff 23 is congruent to 3 (mod 10).

45 has a remainder of 5 when divided by 10 \iff 45 is congruent to 5 (mod 10).

12 has a remainder 0 when divided by 6 \iff 12 is congruent to 0 (mod 6).

2000 has a remainder 43 when divided by 103 \iff 2000 is congruent to (43 mod 103).1

Now that we have new language, let’s introduce some new symbols too. OOOoooo

Usually, when we say 5 times 2 equals 10 we don’t write out “times” and “equals” we use symbols like \times and = . Introducing these symbols is a good idea because they have great utility, since our sentences become short expressions. And we can then manipulate the expressions, like we learn in algebra.

5 times 2 equals 10 \iff 5\times 2=10 .

But, we aren’t talking about equality, we are talking about congruency. As we will see they are similar to one another and to highlight this we use similar symbols. When we say 23 is congruent to 3 (mod 10) we’ll write: 23 \equiv 3 \pmod{10} .

23 is congruent to 3 (mod 10) \iff 23 \equiv 3 \pmod{10} .

45 is congruent to 5 (mod 10) \iff 45 \equiv 5 \pmod{10} .

12 is congruent to 0 (mod 6) \iff 12 \equiv 0 \pmod{6} .

2000 is congruent to 43 (mod 103) \iff 2000 \equiv 43 \pmod{103} .

I think the use of strange notation is a big challenge people have with reading and learning math on their own. Such as the three-lined “equal to” symbol \equiv we are now using. When you see \equiv with (mod #) it’ll likely mean what we have outlined above: congruency (mod #).

The idea of thinking of congruency as short-hand for remainders is intuitive and quick (sometimes!). However, there is a more formal definition of congruency that captures this intuition and more. We will need this later, so let’s get it out now!

Definition (Congruency): Two integers a and b are congruent \pmod{n} if, a-b is a multiple of n . Or if you prefer, when n divides a-b .

a\equiv b \pmod{n} \iff n\mid (a-b) \iff (a-b) = nk.

for some integer k.

Applying this to our running examples,

23 \equiv 3 \pmod{10} \iff\;\;\; (23-3=20 and 10\mid 20 )\iff 23-3=20\times 1 .

45 \equiv 5 \pmod{10} \iff\;\;\; (45-5=40 and 10\mid 40 )\iff 45-5=10\times 4 .

12 \equiv 0 \pmod{6} \iff\;\;\; (12-0=12 and 6\mid 12 )\iff 12 - 0 =6\times 2 .

2000 \equiv 43 \pmod{103} \iff\;\;\; (2000-43=1957 and 103\mid 1957 )\iff 2000 - 43=103\times 9 .

The reason why this definition was chosen is multifold. One advantage is that we don’t need to focus on remainders that come out of the division algorithm. The algorithm forces us to have the remainder such that: 0\leq r < n when we are working (mod n) and this is unnecessary. We can consider other numbers congruent to 3 (mod 10) and this definition helps us see more of the numbers congruent to 3\pmod{10} other than 23. For example, 123 - 3 = 120 and 10 divides 120. We also have,

\cdots \equiv 123 \equiv 113 \equiv 103 \equiv\cdots\equiv 23 \equiv 13\equiv 3 \pmod{10} .

And you don’t need to stop before you get to negative numbers either:

\cdots \cdots\equiv -27 \equiv -17\equiv -7 \equiv 3 \equiv 13 \equiv 23 \equiv \cdots\;\;\;\pmod{10} .

Since, for example, 3- (-27) = 30 and 10 divides 30.

We sometimes use the language of reducing, like with fractions. For example, since 23 is congruent to 3, and 23>3\geq 0 we could say that we reduced 23 (mod 10) to get 3. Or, we could say, that we reduced 123 to 23 (mod 10), since 123>23.

Another word that you might see is: residue mod n. Just like there is a simplest form of a fraction, there is a `simplest form’ of an integer mod n. But what’s simplest form mean for reducing? We define residue to be the integer we get when we’ve reduced enough to be in the range 0 to n-1 when reducing (mod n). For example, when working (mod 10), we say 3 is the residue of: -27 ,\;-17,\; -7 ,\;3,\;13 ,\;23\;\;\;\pmod{10} .

Oh, and if you are wondering why modular arithmetic is sometimes called clock algebra, it’s because you already do this when you are reading a clock (when it’s past noon)! For example, 15 hours after midnight, is 3:00pm. Not 15:00, unless you are in the military. So in a way, 3:00pm is the same as 15:00. This is the same as the statement 15 \equiv 3 \pmod{12}. So, when you are reading a clock, you are doing modular arithmetic mod 12.

Tricks of the Trade (mod n)

Now that we have some of the basics down, we might wonder if we can add, subtract, multiply, or divide congruences like we do with integers. For example, we already know that 23 \equiv 3 \pmod{10} and 45 \equiv 5 \pmod{10} . Is it true that:

23 + 45 \overset{?}{\equiv} 3 + 5\pmod{10}

or,

23 + 45 \overset{?}{\equiv} 23 + 5 \overset{?}{\equiv} 3 + 45 \pmod{10}

or,

23 \times 45 \overset{?}{\equiv} 23 \times 5 \overset{?}{\equiv} 3 \times 45 \pmod{10}

But since it doesn’t make sense to combine congruences that use a different mod number (or moduli) we don’t ask any questions regarding changing (mod 10) to some other (mod n) mid calculation (this is akin to how you can’t add fractions when the denominators are not the same). But if we stick to \pmod{10} we can try the addition situation. Well, 23+45 =68. And 68 has a remainder of 8 when divided by 10. Similarly, 3+5 = 8, which also has a remainder of 8 when divided by 10. So, it seems to work with addition. For the same reason, congruence works with subtraction and multiplication. Division, however, that’s… more tricky. We save that for later!

Aggravating Addition

What exactly are we aiming to do here?

We want to show that we can reduce before we add or after we add, either way we get the “same sum”, that is, up to congruence.

Modular Addition: If a\equiv  A \pmod{n} and b\equiv B  \pmod{n} , then a+b \equiv  A+B \pmod{n} .

Proof: (Click in the Discovery)

Let,

a\equiv  A \pmod{n} and b\equiv B  \pmod{n} .

How do we get a foot hold here? How do we compare remainders? This is why we went through the formal definition of congruence. Applying the definition we deduce:

a-A  = nk_a and b-B = nk_b,

for some integers k_a and k_b . Since we want to show that a+b \equiv  A+B \pmod{n} , we must show that (a+b) - (A+B) =nK, for some integer K. This is indeed the case! If we add the expressions: a-A  = nk_a and b-B = nk_b, we see,

a-A +b-B = nk_a + nk_b.

With some rearranging,

(a+b) - (A+B) = nk_a + nk_b = n(k_a+k_b).

And since k_a and k_b are integers their sum (k_a+k_b) is an integer too! We’ve found our integer K that we wanted. Namely, K:=(k_a+k_b). We’re done!

(a+b) - (A+B) = nK implies a+b \equiv  A+B \pmod{n} .

\square

By the way, since we did not assume a,A,b,B were positive, this proof is valid for subtraction too!

Corollary (Modular Subtraction): If a\equiv  A \pmod{n} and b\equiv B  \pmod{n} , then a-b \equiv  A-B \pmod{n} .

Problematic Products

We want to do the same thing we did with addition, but with multiplication:

Modular Multiplication: If a\equiv  A \pmod{n} and b\equiv B  \pmod{n} , then ab \equiv  AB \pmod{n} .

Proof: (Click in the Discovery)

We employ the same strategy! We know by definition,

a-A  = nk_a and b-B = nk_b,

and thus,

a  = A+ nk_a and b = B+nk_b.

Since we want to show ab \equiv  AB \pmod{n} , let’s multiply a and b and see we get.

ab = (A+nk_a)(B+nk_b) = AB + Ank_b +Bnk_a+ nk_ank_b.

Do you see why we’re finished? Take a look,

ab = AB + n\underbrace{\Big(Ak_b +Bk_a+ nk_ak_b\Big)}_{\mathrm{an}\;\mathrm{integer}}.

Recall the definition of congruence and observe that we’ve just shown ab - AB = n\Big(\mathrm{Integer}\Big) , we conclude ab \equiv AB \pmod{n}.

\square

What about division? Is there a division corollary?

Delicate Division

What does it mean?

Division is a tricky one to manage. Since we are only concerning ourself with whole numbers, what would 5 \div 2  \pmod{7} even mean? Well, with normal division, 5 \div 2  = \frac{5}{2} because 2 \times \frac{5}{2} = 5. So maybe since we understand multiplication using mod, we should think of division in terms of undoing multiplication?

So let’s think of 5 \div 2  as 5 \times \frac{1}{2}, where we think of \frac{1}{2} as the number that gets you back to 1 when you multiply by 2. Likewise 24 \div 6 = 24 \times \frac{1}{6} where \frac{1}{6} is such that 6\times\frac{1}{6}=1.

So maybe we interpret: 5 \div 2  \pmod{7} as 5 \times ``\frac{1}{2}"  \pmod{7} where ``\frac{1}{2}"  \pmod{7} is the number such that:

2 \times ``\frac{1}{2}"  \equiv 1\pmod{7}.

Well, 2\times 4 =8 \equiv 1  \pmod{7}. So I guess ``\frac{1}{2}" \equiv 4  \pmod{7}? Indeed! This is how we choose to define division, we define it in terms of undoing multiplication.

Quick recap:

5 \div 2  \pmod{7} becomes 5 \times ``\frac{1}{2}"  \pmod{7}, and since 2\times 4 =8 \equiv 1  \pmod{7} we identify ``\frac{1}{2}" \equiv 4  \pmod{7} . Thus, 5\div 2 \overset{def}{=} 5 \times 4 = 20 \equiv 6  \pmod{7}.

One bit of notation. Since we only care about integers, writing ``\frac{1}{2}" \pmod{7} is clunky and potentially confusing. So, we write ``\frac{1}{2}" as 2^{-1}. More generally,

``\frac{1}{k}" \Leftrightarrow k^{-1}  .

Division: We define a \div b  \pmod{n} to be a \times b^{-1}  \pmod{n}. Where we identify b^{-1} as the integer such that b\times b^{-1}  \equiv 1  \pmod{n}.

Does it work?

Ok, so now we know what division means using mods. Is it always true if a\equiv  A \pmod{n} and b\equiv B  \pmod{n} , then a\div b \equiv  A\div B \pmod{n} ? Or, more accurately, a (b^{-1}) \equiv  A ( B^{-1}) \pmod{n} . Let’s do a numerical experiment.

Example 1: (mod 11)

Consider 15\equiv  4 \pmod{11} and 24\equiv 2  \pmod{11} , is it true 15\div 24 \equiv  4\div 2 \pmod{11} . Or, more accurately, 15 (24^{-1}) \overset{?}{\equiv}  4 ( 2^{-1}) \pmod{11} .

Step 1: Find \mathbf{24^{-1}} (mod 11 ) and \mathbf{2^{-1}} (mod 11).

Ok, so we need two integers a,b such that 24a\equiv 1  \pmod{11} and 2b\equiv 1  \pmod{11} 2. There’s no easy way in general to find these numbers. Trial and error yield a possible solution:

24(17)\equiv 1  \pmod{11} and 2(6)\equiv 12 \equiv 1  \pmod{11} ,

Check the 24 case here. Thus, 24^{-1} = a = 17 and 2^{-1} = b=6 .

Step 2: “Divide”

Plugging 24^{-1} = a = 17 and 2^{-1} = b=6 into our “division” problem we get:

15\div 24 \equiv  15 \times 24^{-1} \equiv 15 \times 17 \equiv 255 \equiv 2 \pmod{11}

and

4\div 2 \equiv  4 \times 2^{-1} \equiv 4 \times 6 \equiv 24 \equiv 2 \pmod{11} .

So, they do match! Nice!

Let’s try another one.

Example 2: (mod 10)

Very similar to before, but now (mod 10): 15\equiv  5 \pmod{10} and 24\equiv 4  \pmod{10} . Now let’s try 15\div  24 \pmod{10} 5\div  4 \pmod{10} ..

Step 1: Find \mathbf{24^{-1}} mod 10 and \mathbf{4^{-1}} mod 10.

Ok, what number times 24a\equiv 1  \pmod{10} ? Hint: If you guess and check some numbers, you might get disappointed. Let’s instead ask a similar question we know how to answer:

What number satisfies 24a - 1 = 10k equivalently,

24a - 10k = 1 .

Recall all the work we did in part 3 to find integer solutions to equations of the form: ax +  by = N .

Can you see the issue here? We showed that there is no integer solution to ax +  by = N if the greatest common divisor \gcd{(a,b)}=d (in this case \gcd{(24,10)}=2 ) doesn’t divide the right and side N, (in this case 1). And 2\nmid 1, so there is no integer solution. (For those who didn’t read part 3, which you should, to get more traffic to my website, notice how the left-hand side is always even, but the right-hand side, 1, is odd. We know EVEN \neq ODD and hence there is no integer solution!)

What?!?!??? NO solution?

Yup, and as a consequence there is no 24^{-1} \pmod{10} so there is no way to divide by 24 \pmod{10} . This means that some division problems don’t make sense to ask.

What failed (mod 10) and didn’t fail (mod 11)?

What failed (mod 10) was that 24 and 10 share a factor of 2. This then meant that 24x +  10y = 1 had no integer solution. And as a consequence, there is no 24^{-1} \pmod{10}, and no way to divide by 24. This wasn’t a problem working (mod 11). Since 11 is prime, we know all non-multiples of 11 are such that \gcd{(a,11)}=1 . So dividing by 24 and 2 was fine to do.

Remark: By the same logic, you cannot divide by any multiple of 11 (mod 11), such as 11, 22, 33, 44, 55, etc. This is equivalent to dividing by 0, since all these have a residue of 0 (mod 11).

Moral: In order to be able to divide a by b working (mod n) it must be that \gcd{(b,n)}=1 .

Now we can write a lemma and the division corollary.

Lemma: Let a and n be integers. Then, there exists a^{-1} \pmod{n} if and only if \gcd{(a,n)}=1 .

Proof Idea: Use the connection between the existence of a^{-1} \pmod{n} and there being solutions to ax + ny = 1. Then use Bézout’s Identity from (part 3) to finish, just as we did in the example (mod 10).


Corollary (Modular Division): If a\equiv  A \pmod{n} and b\equiv B  \pmod{n} , then a\div b \equiv  A\div B \pmod{n} or, better yet,

a b^{-1} \equiv  A B^{-1} \pmod{n}

Proof Idea: We know by the lemma that division makes sense, and by converting division to multiplication we can use modular multiplication.

A Motivating Mystery (The Solution)

Recall the question from the beginning:

Can you see why you will never find integer solution to x^2 + y^2 = N with N = 3,\;43,\; 103, \;207,\;248?

Key Idea: If we had no tools at our disposal, we might guess and check different x and y to see what might happen. When N = 3 it’s not too bad to show that there is no integer solution. It becomes unreasonable when N gets large. However, our guess and check method has merit. All we need to do is minimize our set of numbers we need to guess and check for x and y.

Consider that if x^2 + y^2 = N then x^2 + y^2 \equiv N \pmod{n}. This is because we can reduce before or after we multiply and add. Now we don’t have so many numbers to check for x and y, we only have (n – 1) integers to guess and check from: 0,\; 1,\; 2,\; 3,\; . . . ,\; n-1 \pmod{n}. This is better!

Solution: With the hindsight of knowing the answer let n=4.3 This means that x and y will be congruent to 0, 1, 2, or 3 (mod 4). Consider the possible values for x^2 and y^2 (mod 4).

0^2 \equiv 0\pmod{4}

1^2 \equiv 1\pmod{4}

2^2 \equiv 0\pmod{4}

3^2 \equiv 1\pmod{4}

Observe that x^2 and y^2 can only be 0 or 1 (mod 4). Thus, x^2 + y^2 \equiv 0,\;1,\;2 \pmod{4} but not 3 \pmod{4}. (Why?)

Now take a look at N \pmod{4} with N = 3,\;43,\; 103, \;207,\;248. For all these values of N notice N \equiv 3\pmod{4}, but we just showed that there is no way x^2 + y^2 \equiv 3 \pmod{4}! Since there is no way to solve the equation (mod 4), there is no way to solve it in general. Hence: there is no solution! WOWWWW!

Closing Remarks

Modular arithmetic is a very useful tool to have at your disposal. You’d be surprised to see how many times focusing on remainders simplifies life! (Life in general, not just math problems!)

You’re finally ready to learn about Fermat’s little theorem! It’s a beautiful little theorem! We will cover it next time, but I want you to have a chance for a kick in the discovery! So, consider the following:

1^{5-1}  \pmod{5} .

2^{5-1} \pmod{5} .

3^{5-1}  \pmod{5} .

4^{5-1} \pmod{5} .

1^{7-1}  \pmod{7} .

2^{7-1} \pmod{7} .

3^{7-1}  \pmod{7} .

4^{7-1} \pmod{7} .

5^{7-1}  \pmod{7} .

6^{7-1} \pmod{7} .

2^{11-1}\pmod{11} .

5^{11-1}  \pmod{11} .

Notice anything? If so, make a conjecture! Then try to prove it!

Hint: 5, 7, and 11 are primes and that the exponents are (PRIME) – 1. Try these with composite modulus.

Footnote:

  1. You can check this one here because I sure didn’t do this one by hand! ↩︎
  2. Two b or not two b that is the question… ↩︎
  3. The other way to get at n=4 is to try other n’s and realize 4 is the best!. ↩︎

 

3 responses to “Newbie at Number Theory (Part 5): Modular Arithmetic”

  1. Newbie Number Theory (Part 6): Fermat’s Fantastic Little Theorem – A Kick in the Discovery Avatar

    […] sure would be nice if we could divide both sides by , but we both know that division doesn’t play nice with modular arithmetic. Unless… what we divide by is relatively prime with the mod number (aka p). But p is […]

    Like

  2. Newbie at Number Theory (Part 7): Euler’s Totient function – A Kick in the Discovery Avatar

    […] recall that we have , so we know that we can safely divide by and […]

    Like

  3. Interesting Group Isomorphisms – A Kick in the Discovery Avatar

    […] the binary operation of addition modulo and we get the group . For those who are familiar with modular arithmetic can you show that this is indeed a group? And for those have not yet had the opportunity to learn […]

    Like

Leave a comment