12
11
Modular
Arithmetic
Operations · Negative numbers · Division and
equations · Binary operations
1
10
2
mod 12
9
3
8
4
7
5
6
15 o’clock ≡ 3 o’clock
OVERVIEW
What We Will Cover
1
2
3
4
Operations
Negative
numbers
Division and
equations
Binary
operations
Add, subtract,
multiply and take
powers mod n
Turn any integer into
a remainder from 0
to n − 1
Inverses and solving
linear congruences
Closure, identity and
inverses in modular
sets
2
INTRODUCTION
The Big Idea: Clock Arithmetic
12
DEFINITION
11
a ≡ b (mod n)
means n divides (a − b): a and b leave the same
remainder when divided by n.
EXAMPLES
17 ≡ 5 (mod 12)
38 ≡ 3 (mod 7), since 7 divides 35
1
10
2
mod 12
9
3
8
4
7
5
6
15 ≡ 3 (mod 12): the clock wraps around
3
1 · OPERATIONS
Addition and Subtraction
ADDITION
SUBTRACTION
(5 + 4) mod 7
(12 − 5) mod 7
= 9 mod 7 = 2
= 7 mod 7 = 0
Add as usual, then take the remainder
Subtract as usual, then take the remainder
SHORTCUT: REDUCE FIRST, THEN OPERATE
(23 + 19) mod 7 = (2 + 5) mod 7 = 0
4
1 · OPERATIONS
Multiplication and Powers
MULTIPLICATION
(6 × 5) mod 7
= 30 mod 7 = 2
Multiply as usual, then take the remainder
POWERS REPEAT IN CYCLES (mod 7)
2¹
2²
2³
2⁴
2⁵
2⁶
2
4
1
2
4
1
10 = 3 × 3 + 1, so 2¹⁰ ≡ 2¹ = 2
WHY THE SHORTCUTS WORK
If a ≡ b and c ≡ d (mod n), then a + c ≡ b + d and ac ≡ bd (mod n)
5
1 · OPERATIONS
Operation Tables (mod 5)
ADDITION MOD 5
MULTIPLICATION MOD 5
+
0
1
2
3
4
×
0
1
2
3
4
0
0
1
2
3
4
0
0
0
0
0
0
1
1
2
3
4
0
1
0
1
2
3
4
2
2
3
4
0
1
2
0
2
4
1
3
3
3
4
0
1
2
3
0
3
1
4
2
4
4
0
1
2
3
4
0
4
3
2
1
Amber cells in the × table equal 1: those pairs are inverses, which we use for division.
6
2 · NEGATIVE NUMBERS
Negative Numbers in mod n
Top row: the integer. Bottom row: its value mod 5.
−7
−6
−5
−4
−3
−2
−1
0
1
2
3
4
5
6
7
3
4
0
1
2
3
4
0
1
2
3
4
0
1
2
ADD MULTIPLES OF n
SHORTCUT RULE
−17 + 20 = 3
−a ≡ n − a (mod n)
so −17 ≡ 3 (mod 5)
−3 ≡ 5 − 3 = 2 (mod 5)
7
3 · DIVISION AND EQUATIONS
Division Using Inverses
THE IDEA
INVERSES MOD 7
a ÷ b ≡ a × b⁻¹ (mod n)
x
1
2
3
4
5
6
b⁻¹ is the number with b × b⁻¹ ≡ 1 (mod n).
x⁻¹
1
4
5
2
3
6
An inverse exists only when gcd(b, n) = 1. Mod 7
is prime, so every non-zero number has one.
EXAMPLE: 5 ÷ 3 (mod 7)
3⁻¹ = 5, so 5 × 5 = 25 ≡ 4
Check: 3 × 4 = 12 ≡ 5 ✓
8
3 · DIVISION AND EQUATIONS
Solving Linear Congruences
1
Isolate the x-term
Move constants across and
reduce mod n
2
Multiply by the
inverse
Use the inverse of the
coefficient of x
3
Reduce and check
Substitute back into the
original equation
EXAMPLE: SOLVE 3x + 2 ≡ 4 (mod 7)
3x ≡ 4 − 2 = 2
3⁻¹ ≡ 5, so x ≡ 5 × 2 = 10
x ≡ 3 (mod 7)
Check: 3(3) + 2 = 11 ≡ 4 ✓
9
3 · DIVISION AND EQUATIONS
When There Is No Inverse
THE RULE
EXAMPLE: 4x ≡ 2 (mod 6)
For ax ≡ b (mod n), let g = gcd(a, n)
gcd(4, 6) = 2 divides 2, so there are 2 solutions.
•
g does not divide b: no solution
•
g divides b: exactly g solutions mod n
Example: 4x ≡ 3 (mod 6) has no solution,
because gcd(4, 6) = 2 does not divide 3.
x
0
1
2
3
4
5
4x mod 6
0
4
2
0
4
2
Solutions: x ≡ 2 and x ≡ 5 (mod 6)
10
4 · BINARY OPERATIONS
Binary Operations mod n
DEFINITION
A binary operation ∗ combines two
elements of a set to give one element.
EXAMPLE
✓
Closed
every result stays in S
✓
Commutative
a⊕b=b⊕a
✓
Associative
(a ⊕ b) ⊕ c = a ⊕ (b ⊕ c)
✓
Identity
0, since a ⊕ 0 = a
✓
Inverses
5 − a, e.g. 2 ⊕ 3 = 0
S = {0, 1, 2, 3, 4}
a ⊕ b = (a + b) mod 5
3 ⊕ 4 = 7 mod 5 = 2
11
4 · BINARY OPERATIONS
Example: Multiplication mod 4
a ⊗ b = (a × b) mod 4 on {0, 1, 2, 3}
⊗
0
1
2
3
0
0
0
0
0
1
0
1
2
3
2
0
2
0
2
3
0
3
2
1
✓
Closed
all entries are in the set
✓
Commutative
the table is symmetric
✓
Identity is 1
its row and column repeat the headers
✗
Not every element has an inverse
1 and 3 do; 0 and 2 do not
Amber cells = 1: the inverse pairs.
12
WRAP-UP
Key Takeaways
1
Operations
Operate as usual, then take the remainder mod n
2
Negative numbers
Add multiples of n until the result is 0 to n − 1
3
Division and equations
Multiply by the inverse; it needs gcd(b, n) = 1
4
Binary operations
Check closure, identity and inverses in the table
13
WRAP-UP
Practice Questions
Q1
Q3
Evaluate (47 + 38) mod 9.
Solve 5x ≡ 3 (mod 8).
Q2
Find the value of −23 mod 6.
Q4
On {0, 1, 2, 3, 4, 5}, a ⊗ b = (a × b)
mod 6. Which elements have
inverses?
14
WRAP-UP
Answers
A1
85 mod 9 = 4
A2
−23 + 24 = 1
A3
5⁻¹ ≡ 5, so x ≡ 15 ≡ 7 (mod 8)
A4
Only 1 and 5, since 5 × 5 = 25 ≡ 1.
The others share a factor with 6.
15