Path: blob/main/foundations/02-rings-fields-polynomials/sage/02b-integers-mod-n-as-ring.ipynb
483 views
Integers Mod n as a Ring
Module 02 | 02-rings-fields-polynomials
Z/nZ with both operations, zero divisors, units, and the unit group
Objectives
By the end of this notebook you will be able to:
Construct Z/nZ as a commutative ring with two operations and verify the ring axioms concretely.
Build complete addition and multiplication tables for Z/12Z and read off structural properties.
Define zero divisors, find them all in Z/nZ, and prove the gcd characterization.
Define units, find them all in Z/nZ, and connect to the unit group (Z/nZ)* from Module 01.
State and verify the dichotomy theorem: every nonzero element of Z/nZ is either a unit or a zero divisor.
Explain why zero divisors are catastrophic for cryptography and why we need fields.
Prerequisites
Completion of What Is a Ring?, you know ring axioms (closure under +, *, associativity, distributivity, additive identity/inverses, multiplicative identity).
From Module 01: You studied Z/nZ as an additive group and (Z/nZ)* as a multiplicative group. You know
gcdand modular inverses.
Bridge from 02a: In the previous notebook, we saw that a ring is a set with two operations satisfying certain axioms. We verified those axioms for the integers Z. Now we apply the same lens to a structure you already know well: the integers mod n. The surprise is that putting both operations together on a finite set creates phenomena that neither operation exhibits alone.
Motivating Question
Think back to Module 01. You studied (Z/12Z)* = {1, 5, 7, 11}, the elements that have multiplicative inverses mod 12.
But what happens to the OTHER elements: 2, 3, 4, 6, 8, 9, 10?
They cannot have multiplicative inverses. Are they just... inert? Boring? Harmless?
It turns out they have a far more dangerous property. They can annihilate nonzero elements, multiply two perfectly good nonzero elements and get zero. This is called being a zero divisor, and it is the key new phenomenon that arises when we view Z/nZ as a ring rather than just a group.
Let us find them.
1. Z/nZ as a Ring: Two Operations at Once
Bridge from Module 01: In Module 01, you worked with Z/nZ under addition (an abelian group) and separately with (Z/nZ)* under multiplication (another abelian group). A ring packages both operations into a single algebraic structure, linked by the distributive law.
Let us build Z/12Z as a ring in SageMath and verify the key structure.
Notice: SageMath tells us Z/12Z is not a field. By the end of this notebook, you will understand exactly why, it has zero divisors.
Let us verify the ring axioms concretely. We will check the distributive law, since that is the axiom that connects the two operations.
2. The Complete Operation Tables
To really see the ring, let us build the full addition and multiplication tables for Z/12Z. In Module 01, you may have built the addition table. Now we add the multiplication table and compare them side by side.
2.1 Addition Table
The addition table looks perfectly well-behaved, every element has an additive inverse, every row is a permutation of Z/12Z (this is the Latin square property of group tables).
2.2 Multiplication Table
Now the multiplication table. Predict before you run: Will every row be a permutation of Z/12Z? (Hint: think about what happens in the row for element 2.)
Observe the multiplication table carefully:
The row for 0 is all zeros. (Of course: 0 times anything is 0.)
The row for 1 is just
0, 1, 2, ..., 11. (The multiplicative identity.)The row for 5 is a permutation of all 12 elements. (5 is a unit, it has an inverse!)
The row for 2 is
0, 2, 4, 6, 8, 10, 0, 2, 4, 6, 8, 10. It repeats! And it contains 0 in a position other than the first column.The row for 3 contains a 0 at column 4: that is,
3 * 4 = 0in Z/12Z.
That last observation is the key phenomenon: two nonzero elements whose product is zero.
3. Zero Divisors: When Nonzero Times Nonzero Equals Zero
Definition. Let R be a commutative ring. A zero divisor is a nonzero element such that there exists a nonzero element with .
Misconception Alert: "A zero divisor is an element equal to zero." No! A zero divisor is a nonzero element whose product with some other nonzero element gives zero. The name is confusing, it does not mean "divisor that is zero" but rather "divisor of zero" (an element that divides zero in a nontrivial way).
3.1 Finding Zero Divisors in Z/12Z
Let us find every zero divisor in Z/12Z by brute force.
3.2 The gcd Characterization
Look at those zero divisors: {2, 3, 4, 6, 8, 9, 10}. What do they have in common?
Checkpoint. Predict: Compute gcd(a, 12) for each zero divisor a. What pattern do you see?
Theorem. In Z/nZ, a nonzero element is a zero divisor if and only if .
Why? If , then let . We have in Z/nZ (since ), and . So is a zero divisor.
Conversely, if , then has a multiplicative inverse (it is a unit), and units can never be zero divisors (proof: if and is a unit, multiply both sides by to get ).
Let us verify this computationally.
Every single element matches. The characterization is:
4. Units: The Elements That Can Divide
Bridge from Module 01: You already know this! In Module 01, you studied the multiplicative group (Z/nZ)*, the set of elements with multiplicative inverses. That was the unit group of the ring Z/nZ. Now we see where it fits in the bigger picture.
Definition. An element is a unit if there exists with . The element is called the multiplicative inverse of , written .
Theorem. In Z/nZ, element is a unit if and only if .
5. The Dichotomy Theorem: Unit or Zero Divisor, Never Both
We have two characterizations:
is a unit
is a zero divisor
Since is always either equal to 1 or greater than 1, we get a beautiful dichotomy.
Theorem (Dichotomy). In Z/nZ with , every nonzero element is either a unit or a zero divisor. No element is both. No nonzero element is neither.
Proof sketch:
If : is a unit (has an inverse). cannot be a zero divisor (if , multiply by to get ).
If : is a zero divisor (take ). cannot be a unit (the equation has no solution).
Let us visualize this partition.
Key takeaway: The nonzero elements of Z/12Z split cleanly into two camps:
| Units (gcd = 1) | Zero divisors (gcd > 1) |
|---|---|
| {1, 5, 7, 11} | {2, 3, 4, 6, 8, 9, 10} |
| Have inverses | Annihilate nonzero elements |
| Form a group (Z/12Z)* | Do NOT form a group (not closed under *) |
When Does Z/nZ Have NO Zero Divisors?
Checkpoint. Predict: For which values of n does Z/nZ have no zero divisors at all? (Think about what makes gcd(a, n) = 1 for ALL nonzero a.)
The pattern: Z/nZ has no zero divisors precisely when is prime. When is prime, every nonzero element is a unit, so Z/pZ is a field. We will study fields in depth in notebook 02d.
Crypto Foreshadowing: This is why RSA works with a composite modulus (zero divisors exist and finding them means factoring ), while elliptic curve cryptography works over a prime field (no zero divisors, clean algebraic structure). Zero divisors are not just an algebraic curiosity, they are a security boundary between different types of cryptosystems.
6. Crypto Implications: Why Zero Divisors Are Dangerous
Imagine you try to build a "cryptosystem" by multiplying messages in Z/nZ with a composite n. If your key happens to be a zero divisor, you lose information irreversibly:
The lesson: Multiplication by a zero divisor is a lossy operation. It maps multiple distinct inputs to the same output, so decryption is impossible. This is fundamentally different from multiplication by a unit, which is a bijection (every output comes from a unique input, because you can multiply by the inverse).
This is why cryptographic operations (encryption, signature, etc.) must use units or, better yet, work in a field where every nonzero element is automatically a unit. We will see this principle again and again.
7. Comparing Different Moduli
Let us compare the unit/zero-divisor structure across several moduli to build intuition for which rings are "nice" (few or no zero divisors) vs. "dangerous" (many zero divisors).
Observations:
When is prime: unit ratio = (i.e., 100% units, 0 zero divisors). This is a field.
When is a prime power (): there are still zero divisors (multiples of ), but fewer than for general composites.
When is highly composite (): zero divisors dominate. The ring is "far from a field."
Exercises
Exercise 1: Analyze Z/15Z (Fully Worked)
Task: Find all zero divisors and all units in Z/15Z. Verify the dichotomy.
Solution:
Exercise 2: Analyze Z/20Z (Guided)
Task: Repeat the analysis for Z/20Z. Fill in the TODOs.
Hint: 20 = 4 * 5, so zero divisors are elements sharing a factor of 2 or 5 with 20.
Exercise 3: Explore Z/pZ for a Prime p (Independent)
Task: Choose a prime of your choice (try or ). Verify computationally that Z/pZ has no zero divisors and that every nonzero element is a unit. Build the multiplication table and confirm that every row (except row 0) is a permutation of all elements.
Summary
| Concept | Key idea |
|---|---|
| as a ring | Addition and multiplication mod , linked by the distributive law |
| Zero divisors | Nonzero elements with for some nonzero . In , is a zero divisor iff |
| Units | Elements with multiplicative inverses. In , is a unit iff . These form the group from Module 01 |
| Dichotomy theorem | Every nonzero element of is either a unit or a zero divisor, never both, never neither |
| Prime modulus = no zero divisors | has no zero divisors iff is prime, making a field (notebook 02d) |
| Crypto implication | Zero divisors destroy information (multiplication is not injective). Cryptosystems need units or fields |
What we learned here will be essential for:
Notebook 02d: defining fields precisely (a ring where every nonzero element is a unit)
Module 03: constructing extension fields GF(2^8) for AES
Module 04: understanding why RSA works in (Z/nZ)* with composite n
Next: Polynomial Rings