Informal introduction

Note:

Informal discussions are inadequate for these notes.

The ring of congruences modulo

Definition.

Let and . I say and are congruent modulo , in symbols, or , if .

Exercise.

Prove that is an equivalence relation on . Remind yourself of the definitions of equivalence class and quotient before you continue reading.

Instead of writing to denote a class, I write in this chapter. I also denote by the quotient . Prove any of the examples below if you do not find them obvious.

Examples.

  1. is the set of even numbers, and contains all odd numbers.
  2. The set has two elements.
  3. In general, and has exactly elements.
  4. is divisible by if and only if .

The algebra of classes is straightforward to define. I leave to the reader proving that these are well-defined. Moreover, the reader should play around with these operations and convince themselves that the basic rules of arithmetic (associativity, commutativity, existence of an additive and multiplicative inverses, etc.) translate to this new structure as well. Instead of memorizing a long list of properties, the best way to learn to use this tool is to, well, use it.

Definition.

As an example, I compute the multiplication table modulo 5.

Multiplication Table Modulo 5

× mod 501234
000000
101234
202413
303142
404321

Note:

An informal discussion is presented during the lectures that compares different multiplication tables and highlights insights about major theorems in the field.

Having addition and multiplication, exponentiation follows.

Proposition.

For every natural , if , then .

Exercise.

Use the above to compute mod .

The following is proved as part of the above discussion in the lectures.

Proposition.

Let and be integers. There exists such that if and only if for every , there is a such that .

Such a , when it exists, is unique modulo and is called the inverse of modulo . I denote this element by . When this exists I also say that is invertible modulo .

Applications of modular arithmetic: divisibility criteria

A fact known to you since learning to write numbers in the decimal system is that any natural number can be represented by its decimal positional notation . Formally, this is means that

I do not prove that this exists, but with the number-theoretic tools I have developed so far, it should be straightforward. For example, the number (i.e., “four thousand five hundred and seventy-four”) really is .

In this section, I show you how to quickly check if a number is divisible by a small integer based on its decimal representation.

Reflect.

Other numeral systems exist. For example binary, or hexadecimal. In your head, try rewriting this section in a different numeral system. How do the criteria change?

For the rest of the section, suppose that

When is even?

Claim.

is even (i.e. ) if and only if its unit digit, is even.

Indeed, reducing mod cancels out all positive powers of , since is even and thus . Concretely,

and the result follows.

When is divisible by ?

Proceed exactly as above, only this time the powers of do not cancel out. Instead, they become ‘s since . Hence,

Claim.

is divisible by if and only if the sum of its digits is divisible by .

Moreover, notice that once you computed the sum of digits, you get a new, smaller number you want to check if it’s divisible by , so you can keep applying the same procedure over and over again until you have a single digit number, in which case this digit has to be either , , or .


I leave the rest to you.

When is divisible by ?

When the number obtained from the last two digits, i.e. is divisible by 4.

When is divisible by ?

When the last digit, , is either zero or .

When is divisible by ?

When it is divisible by and by .

When is divisible by ?

You need one more digit than for .

When is divisible by ?

If you understood the one for , this one should be clear.

When is divisible by ?

You probably know this one intuitively already. As a hint, only the last digit matters.

Solving linear congruences

Consider the equation . In the integers, this almost never has a solution, since the integers have no division. In the rationals, this almost always has a solution, namely the fraction . The equation in however is much more interesting. I now show you how to solve it. Consider

Where to begin? A common technique in mathematics is to assume that a solution exists, and try to derive properties from it. This either

  • produces enough properties so that you can narrow down and eventually find the solution; or
  • yields a contradiction, in which case you can guarantee no solution exists.

Note:

In the lectures, I guide students through this process interactively. Here I just spoil the whole solution for the sake of completeness.

Solution criterion

Theorem.

The congruence has a solution if and only if .

Proof:

Suppose that is a solution. Since and , linearity gives us .

Now suppose that . By Bézout’s identity, there are integers and such that

The fact that is (an integer and) a solution is left to the reader.

Notice that, by the above discussion, the congruence always has a solution when is invertible. Moreover, a solution is , where is the inverse of mod .

Corollary.

The integer is invertible modulo if and only if it is relatively prime with .

You now have a criterion to decide if a solution exists or not. But from the argument above, it is not immediately obvious how to find it explicitly.

Finding a solution in five easy steps

  1. Use the extended Euclidean algorithm to compute .
  2. Check if it divides .
  3. If it doesn’t, there is no solution; if it does, proceed to Step 4.
  4. Continue with the extended Euclidean algorithm and find and such that . Discard , as you don’t need it.
  5. If you understand the part of the proof above, you should now know how to find a solution .

Exercise.

Find the inverse of mod .

Solving linear systems

A must-know technique for modular arithmetic is presented in this section. I first show you how to solve two congruences simultaneously, then it is your job to use induction to generalize this to multiple congruences. If you have made it this far, you should find this task straightforward.

Lemma.

Let and be integers. There exists an integer such that both and if and only if . Moreover, if exists, then it is unique modulo .

In particular, if , then such an always exists, regardless of and , and is unique modulo .

Proof:

Suppose there is such an . Then, there must be such that , from where . The latter is a linear combination of and , thus by linearity . This is the definition of .

Now suppose that , that is, for some integer . By Bézout’s identity, there are integers and such that . Thus, , from where ; let me call this integer . Reducing mod and mod , it is clear that is a solution to the system of congruences.

An example

I will solve the system

using two different techniques.

Technique: brute force

First, use FTA to compute and notice that , so there is a unique solution mod .

I really want to find an element in the intersection , so I can list out representatives until there is a match:

Therefore, is a solution to the system if and only if for some integer . Or, in other words,

Technique: substitution

Start by picking the congruence with the largest modulus (why?) and rewrite it as for some integer . Reducing mod , we have . The final step is left to the reader.

The Chinese remainder theorem

For the scope of this course, it is important that you know that this theorem exists and that you can prove it with the material covered so far. For more applications, details and variations, you can consult my notes for MAT315.

Chinese remainder theorem (CRT).

If are pairwise coprime and , then there is an integer , unique mod such that for all , .

Proof idea:

Use induction on and apply the above lemma.

Warning:

Careful when using online calculators (or worse, AI) to compute these solutions. They are often wrong or incomplete. In the lectures, I show how the top 3 Google searchable calculators give wrong answers.