Path: blob/main/foundations/01-modular-arithmetic-groups/python/01b-modular-arithmetic.ipynb
483 views
Modular Arithmetic
Module 01b | Modular Arithmetic and Groups
What if remainders aren't just leftovers, but a complete number system?
Question: On a 12-hour clock, 7 + 8 = 3. You can always "undo" addition (subtract). But can you always "undo" multiplication? Is there a number such that on the clock?
The answer reveals a deep split in modular arithmetic: some elements play nicely, others don't.
Objectives
By the end of this notebook you will be able to:
Perform addition and multiplication in using SageMath
Read and interpret operation tables to spot algebraic structure
Identify zero divisors and explain why they break multiplication
List the units of and connect them to
From Remainders to a Number System
In 01a we saw that Mod(a, n) creates elements that live in a "remainder world" where arithmetic wraps around. Now let's take this seriously: what if we treat these remainders as a complete number system, with its own addition, multiplication, and algebraic rules?
This system is called (read "Z mod n Z"). It has exactly elements: .
as a Number System
Zmod(n) from cryptolab creates the ring . Let's explore it.
Checkpoint: Before running the next cell, predict: what is in ? What about ?
Operation Tables Reveal Structure
An operation table shows every possible computation at a glance. Let's compare addition and multiplication in .
Look at the addition table: every row contains each element exactly once (it's a Latin square). This means for any and , the equation has exactly one solution, you can always "undo" addition.
Now look at the multiplication table: the row for 0 is all zeros (no surprise). But every other row is also a Latin square! In , you can "undo" multiplication too, every non-zero element has a multiplicative inverse.
Will this always happen? Let's try a composite modulus.
Zero Divisors: When Multiplication Breaks
Let's look at .
Checkpoint: In , we found . Why is this a problem? Think about it: if you could "divide by 3," then from you'd get . But ! Zero divisors make division impossible.
Pattern: Element is a zero divisor in if and only if . When is prime, for all , so there are NO zero divisors. This is why prime moduli are special.
Units: The Elements That Behave
The units of are elements with multiplicative inverses: is a unit if there exists with .
When is prime, every non-zero element is a unit: has elements. For composite , only the elements coprime to are units, and there are of them.
The units form their own self-contained system, you can multiply and divide freely within them. This system will turn out to be a group, which we'll study in the next notebook.
Common mistake: " is just the integers with a mod operation stuck on." No! It's a complete number system with its own rules. In , the number 3 has no multiplicative inverse, not because we haven't looked hard enough, but because proves it cannot exist. You can't "cancel" 3 when it annihilates 4.
Exercises
Exercise 1 (Worked)
Build the multiplication table for . Identify all zero divisors. For each, find a non-zero with , and verify .
Exercise 2 (Guided)
List the units of . For each unit , find using Mod(u, 15)^(-1). Verify that the number of units equals .
Compute by hand:
Exercise 3 (Independent)
For each from 2 to 20, compute the number of zero divisors in . (A zero divisor is a non-zero element with for some non-zero .)
For which are there no zero divisors? State a conjecture about what these have in common.
Summary
| Concept | Key idea |
|---|---|
| A complete number system with elements where arithmetic wraps at | |
| Zero divisors | Non-zero elements with , they exist exactly when |
| Units | Elements with multiplicative inverses, exactly those with |
| Counts the units. When is prime, (every non-zero element is a unit) | |
| Prime vs. composite | Prime moduli have no zero divisors and the maximum number of units |
Zero divisors and units are two sides of the same coin: an element is one or the other, determined entirely by its gcd with . This split shapes all of modular algebra.
Crypto teaser: RSA works in where . The number of units is the secret that makes decryption possible, and it can only be computed if you know the factorization of .
Next: Groups: A First Look, we extract the common pattern behind additive and multiplicative arithmetic.