Path: blob/main/foundations/02-rings-fields-polynomials/sage/02e-polynomial-division-irreducibility.ipynb
483 views
Polynomial Division & Irreducibility
Module 02 | 02-rings-fields-polynomials
divmod for polys, is_irreducible(), the primes of polynomial rings
Objectives
By the end of this notebook you will be able to:
Perform polynomial long division over and verify the division algorithm.
Test irreducibility of polynomials over finite fields using SageMath.
Explain why irreducibility depends on the base field.
Articulate the parallel: irreducible polynomials are to polynomial rings what primes are to integers.
Understand why irreducible polynomials are the key ingredient for constructing extension fields .
Prerequisites
Completion of Polynomial Rings (polynomial arithmetic in ).
Completion of What Is a Field? (fields, ).
Comfort with modular arithmetic from Module 01.
Motivating Question
You already know that has no real roots (since for all ). Over , we cannot factor it, so we call it irreducible.
But what happens if we change the field?
Over , we get . Reducible!
Over , is irreducible? Let's check: , and in . So is a root, meaning divides it. In fact, over .
Over ? We check: , , . No roots! For a degree-2 polynomial, no roots means irreducible. So is irreducible over .
The same polynomial can be irreducible over one field and reducible over another. This is not a minor technicality, it is the central idea that makes finite field extensions (and therefore AES, elliptic curves, and post-quantum crypto) work.
To understand irreducibility properly, we first need the tool that underpins it: polynomial division.
1. Polynomial Long Division
Bridge from 02c: In the polynomial rings notebook, we learned how to add and multiply polynomials in . Now we add the final arithmetic operation: division with remainder.
The Division Algorithm for Polynomials
Recall the division algorithm for integers: given with , there exist unique such that
The polynomial version is almost identical. Given polynomials with , there exist unique polynomials (quotient) and (remainder) such that:
The role of "less than" in the integer case () is played by "lower degree" in the polynomial case ().
Step-by-step example: dividing over
Let's divide by step by step.
Step 1: Leading term of is , leading term of is . Divide: . Multiply by : . Subtract from :
Step 2: Leading term of remainder is . Divide: . Multiply by : . Subtract:
Step 3: Leading term is . Divide: . Multiply by : . Subtract:
So and . The remainder is zero, meaning divides exactly.
Let's verify with SageMath:
SageMath provides three ways to do polynomial division:
| Operation | SageMath syntax | Returns |
|---|---|---|
| Full division | f.quo_rem(g) | Tuple (q, r) |
| Quotient only | f // g | q |
| Remainder only | f % g | r |
These mirror Python's integer divmod, //, and %.
Division over finite fields
Everything works identically over . The only difference is that all coefficients are reduced mod . This is exactly where cryptography lives.
Checkpoint: Before running the next cell, compute by hand: in , divide by . What are and ?
Hint: The leading coefficient of is , so no inversions needed. Remember all arithmetic is mod 3.
2. Irreducible Polynomials: The "Primes" of Polynomial Rings
Bridge from 02d: We saw that is a field precisely when is prime. Primes are the "atoms" of the integers, they cannot be broken into smaller factors. Polynomials have an exact analogue.
Definition
A polynomial of degree is irreducible over if it cannot be written as where both and have degree .
In other words: the only way to factor is trivially, as for some constant .
The parallel
| Integers | Polynomials |
|---|---|
| Primes | Irreducible polynomials |
| Every integer factors uniquely into primes | Every polynomial factors uniquely into irreducibles |
| is a field iff is prime | is a field iff is irreducible |
| Primes are the building blocks of | Irreducibles are the building blocks of |
The last row in this table is exactly what we will use in notebook 02f to build extension fields like .
Testing irreducibility with SageMath
SageMath provides two key methods:
f.is_irreducible(), returnsTrue/Falsef.factor(), returns the complete factorization
Notice that over . This is because in , so .
Meanwhile, is irreducible over : we check and , so no roots, and for degree 2, no roots implies irreducible.
3. Irreducibility Depends on the Field!
This is the single most important thing to understand about irreducibility: it is not a property of the polynomial alone, but of the polynomial together with the field.
Let's see across several fields:
Checkpoint: Look at the pattern above. Over which primes is irreducible?
Hint: has a root in iff is a quadratic residue mod , which happens iff (or ). So is irreducible over precisely when .
Verify: , , , all irreducible. , , all reducible. And is special ().
Misconception Alert
"If a polynomial has no roots, then it must be irreducible."
This is only true for polynomials of degree 2 or 3! For degree , a polynomial can have no roots and still factor into two polynomials of degree .
Example: over , the polynomial has no roots (, ), but it is not irreducible:
Takeaway: For degree 2 or 3, checking for roots is sufficient to test irreducibility (because if it factors, at least one factor must have degree 1, i.e., it has a root). For degree , you must use proper factorization or is_irreducible().
4. Unique Factorization: Every Polynomial Factors into Irreducibles
Just as the Fundamental Theorem of Arithmetic says every integer factors uniquely into primes, we have:
Unique Factorization in : Every polynomial of degree in can be written uniquely (up to ordering and constant multiples) as a product of irreducible polynomials.
SageMath's .factor() gives us this decomposition directly.
Notice over . Every element of is a root! This is Fermat's Little Theorem in disguise: for all , so has all elements as roots.
5. Counting Irreducibles: How Many Are There?
If we want to build a field , we need an irreducible polynomial of degree over . But do they always exist? How many are there?
The number of monic irreducible polynomials of degree over is given by the necklace formula:
where is the Mobius function. For large , this is approximately .
The key fact: for all and . So irreducible polynomials of every degree always exist, and we can always build .
For degree 8 over , there are 30 monic irreducible polynomials. AES uses one specific choice: . Let's verify:
Crypto Foreshadowing: In Module 03, we will build explicitly using this polynomial and see how AES performs its MixColumns and SubBytes operations as polynomial arithmetic modulo . The choice of irreducible polynomial does not affect the field structure (all choices give isomorphic fields), but it does affect implementation efficiency.
Exercises
Exercise 1: Division Algorithm Verification (Fully Worked)
Task: Divide by over . Verify the division algorithm.
Exercise 2: Finding Irreducibles (Guided)
Task: Find all monic irreducible polynomials of degree 3 over . There should be 8 of them (since ).
Fill in the TODOs below.
Exercise 3: Field-Dependent Irreducibility (Independent)
Task: Consider the polynomial .
Factor over , , , , , and .
Is irreducible over any of these fields?
Investigate: is irreducible over for any prime ? What do you observe?
Hint: This is a famous example. The answer may surprise you, is irreducible over but reducible over every finite field .
Summary
| Concept | Key idea |
|---|---|
| Division algorithm | For any with , unique exist with and . SageMath: f.quo_rem(g), f // g, f % g |
| Irreducible polynomials | The polynomial analogue of prime numbers. They cannot be factored into lower-degree polynomials, and they build all polynomials via unique factorization |
| Irreducibility depends on the field | The same polynomial can be irreducible over one field and reducible over another. Always specify the field! |
| No-roots test (degree 2 and 3 only) | For degree , a polynomial can have no roots yet still be reducible, factoring into two quadratics for example |
| Counting irreducibles | There are approximately monic irreducible polynomials of degree over , and at least one always exists. This guarantees we can always construct |
| Crypto connection | AES uses the irreducible over to build , the field where all byte-level AES operations live |
Next: Quotient Rings and Field Extensions, where we use irreducible polynomials to actually construct new fields.