Modular Arithmetic
Introduction
Throughout this lesson, all variables are integers. Modular arithmetic is a number system based on integers with an additional component called a modulus. Usually when we do arithmetic, integers can get infinitely big. However in modular arithmetic, every integer is reduced to its remainder upon division by the modulus.
In general, any integer can be written as for some quotient and remainder . Then mod . Then we say is congruent or equivalent to modulo . Often "modulo" is shortened to "mod".
Example: is the same as mod because leaves a remainder of when divided by . So , which means mod .
Consider the general case where we are working mod , then we can simplify any integer mod to its remainder upon dividing by , which we call its least positive residue.
As with the previous example, is the least positive residue for and so on.
Visualizing Modular Arithmetic
Because of the circular nature of residues, modular arithmetic operations can be thought of as mappings performed on points around a circle, where each least positive residue corresponds with a point. Notice that if the modulus is , this looks just like the face of a clock.
Modulus: |
Properties
Modular arithmetic is an integer system, so it inherits properties from the integers like addition and multiplication. Modular arithmetic also inherits 0 as the additive identity and 1 as the multiplicative identity. In other words, mod and mod for any . We will see that additive inverses are always defined, but multiplicative inverses are not defined in general.
Addition
Similar to a clock, we can perform operations like addition and multiplication. We will consider each operation as a map that transforms the remainders to their result when the operation is applied. First, we look at an example of addition.
Example: hours after o'clock is the same as hours after o'clock, which is o'clock. In other words, mod .
Adjust the numbers for modulus and additive mapping to see more examples of addition in modular arithmetic.
Modulus: | |||
Additive mapping: |
Notice that each number maps to exactly one other number and every number is mapped to by exactly one other number. This shows that the inverse of addition is defined for every residue, so the additive inverse, subtraction, always exists. This means that for any integer and modulus , we can always write the additive inverse of as , with mod .
Multiplication
Another operation of modular arithmetic is multiplication.
Example: repeated -hour time periods, the clock will read the same. This is because mod , which is represented on the circle below.
In this visual, arrows of the same color belong to a cycle that starts with some number that is consecutively by another number until the pattern eventually repeats with again. Just like before, adjust the numbers for modulus and multiplicative mapping to see more examples of multiplication in modular arithmetic.
Modulus: | |||
Multiplicative mapping: |
In normal arithmetic, the multiplicative inverse of a number is its reciprocal. To avoid using division, we instead write the multiplicative inverse of as . The inverse of mod is denoted . However, some numbers get mapped to another number more than once, so you can't "undo" that multiplicative mapping.
Example: mod . In this sense, we can't "undo" multiplication by mod , so the multiplicative inverse of isn't always defined.
In fact, the multiplicative inverse of some integer modulo is only defined when .
Modular Arithmetic Lessons
Number Orders
A description of number orders in modular arithmetic.
Reciprocity
A description of quadratic reciprocity in modular arithmetic and an introduction to generalized reciprocity.
Operations
Properties of addition, multiplication, and generalized operations in different settings.
Totient Function
Definition and description of Euler's totient (phi) function.