Path: blob/main/foundations/02-rings-fields-polynomials/sage/02c-polynomial-rings.ipynb
483 views
Polynomial Rings
Module 02 | 02-rings-fields-polynomials
Polynomials as formal objects, PolynomialRing(), arithmetic, the polynomial-vs-function trap
Objectives
By the end of this notebook you will be able to:
Explain why a polynomial is a formal algebraic object (a sequence of coefficients), not a function.
Create polynomial rings over different coefficient rings in SageMath using
PolynomialRing().Perform polynomial arithmetic (addition, multiplication) and predict degrees of results.
Identify the crucial difference between "polynomial" and "polynomial function" over finite fields.
See the structural parallel: Z is to Z/nZ as F is to F[x]/(p(x)).
Prerequisites
Completion of Integers Mod n as a Ring.
You know what a ring is (two operations, axioms) and have seen Z/nZ as a concrete example.
Basic comfort with SageMath syntax.
Bridge: From Number Rings to Polynomial Rings
In notebook 02b, we built the ring Z/nZ by taking the integers and "wrapping around" modulo . The elements were numbers, the operations were addition and multiplication mod , and we verified all the ring axioms.
Now here is the key insight: numbers are not the only things that form rings.
Polynomials do too. You can add them, multiply them, there is a zero polynomial, a one polynomial, and all the ring axioms hold. This is not a metaphor --- polynomial rings are one of the most important structures in all of algebra and cryptography.
But to see polynomials as ring elements, we need to change how we think about them. In calculus, you probably thought of as a function that takes an input and produces an output. That intuition will mislead you here. We need to think of polynomials as formal expressions --- objects defined entirely by their list of coefficients.
Motivating Question
Over the real numbers, if two polynomials give the same output for every input, they must be the same polynomial. You probably take this for granted.
Question: Over , can two different polynomials give the same output for every possible input?
Think about it for a moment. There are only two possible inputs: 0 and 1. A polynomial like can be evaluated at both. What do you get?
Let us find out.
What Just Happened?
The polynomial over evaluates to on every input:
(remember, in , )
So defines the zero function on . But it is not the zero polynomial --- the zero polynomial has all coefficients equal to 0, while has nonzero coefficients.
Misconception Alert: Over finite fields, "same function on all inputs" does NOT mean "same polynomial." A polynomial is defined by its coefficients, not by the function it computes. This distinction is invisible over or (infinite fields), which is why your calculus intuition hides it.
Polynomials as Formal Objects
A polynomial over a ring is a finite formal sum:
The key word is formal. The symbol is not a variable that takes values --- it is an indeterminate, a placeholder that organizes the coefficients. Two polynomials are equal if and only if all their coefficients match, regardless of what happens when you "plug in" values.
| Concept | Polynomial (formal) | Polynomial function |
|---|---|---|
| What is it? | A sequence of coefficients | A map |
| When are two equal? | All coefficients match | Same output on all inputs |
| Over : | These agree | These agree |
| Over : | and define the same function! |
Checkpoint 1: Predict Before You Run
Over , consider the polynomial (equivalently since ).
Predict: what is ? ? ?
Is this the zero polynomial? Is it the zero function on ?
Creating Polynomial Rings in SageMath
SageMath makes it easy to construct polynomial rings. The key function is PolynomialRing(R, 'x') where:
Ris the coefficient ring (where the live)'x'is the name of the indeterminate
Common coefficient rings:
ZZ--- the integers , givingQQ--- the rationals , givingGF(p)--- the finite field with elements, giving
Polynomial Arithmetic
The ring operations on polynomials are defined coefficient by coefficient for addition, and by the usual convolution (distribute-and-collect) rule for multiplication.
Addition:
Multiplication: Multiply every term by every term, then collect like powers of .
The zero element is the polynomial ; the identity is the polynomial (constant polynomial). Let us see this in action.
Degree Rules
The degree of a polynomial (with ) is . Degree tells you the "size" of a polynomial. It obeys clean rules:
(over a domain --- no zero divisors in coefficients)
--- and it can be strictly less if leading terms cancel!
By convention, in SageMath (some texts use ).
Checkpoint 2: Degree Predictions
Before running the next cell, predict:
If has degree 4 and has degree 3, what is ?
If and , what is ?
What is in SageMath?
Same Polynomial, Different Coefficient Rings
Here is something that catches people off guard: the "same" polynomial behaves very differently depending on which ring the coefficients live in.
Consider .
Over : irreducible (no rational roots).
Over : still irreducible.
Over : because !
Over : because and .
The coefficient ring fundamentally changes the algebra.
Checkpoint 3: Coefficient Arithmetic
In , we have . So:
What is in ?
What is in ? (Expand it by hand first!)
Remember: over .
The Structural Parallel: Integers and Polynomials
Here is the deepest idea in this notebook, and one that will pay off enormously in Module 03 (AES) and beyond.
| Integers | Polynomials |
|---|---|
| = the ring of integers | = the ring of polynomials over a field |
| Divide: , | Divide: , |
| Quotient ring: | Quotient ring: |
| Elements: remainders | Elements: remainders of degree |
| When is a field? When is prime | When is a field? When is irreducible |
We will make this precise in notebooks 02e and 02f. For now, just notice the pattern.
Crypto Foreshadowing: AES (the Advanced Encryption Standard) does all of its internal arithmetic in the ring . That is a polynomial quotient ring --- exactly the construction in the right column of the table above. The polynomial is irreducible over , which makes this quotient ring a field with elements. Every byte in AES is an element of this field. We will build this from scratch in Module 03.
Exercises
Three exercises with graduated scaffolding: fully worked, guided, then independent.
Exercise 1: Polynomial vs. Function (Fully Worked)
Task: Find all polynomials of degree over that define the zero function (evaluate to 0 on every element of ).
Strategy: There are polynomials of degree over (each of the 3 coefficients is 0 or 1). We will test each one.
Exercise 2: Degree Arithmetic (Guided)
Task: Given and in :
Compute and verify .
Compute and verify .
Find a polynomial in such that .
Fill in the TODO lines below.
Exercise 3: Exploration (Independent)
Task: Over , find all polynomials of degree exactly 1 (i.e., with ) that are zero functions on .
Then answer: over , what is the lowest-degree nonzero polynomial that defines the zero function? Can you conjecture a general formula? (Hint: think about Fermat's little theorem --- for all .)
Summary
| Concept | Key idea |
|---|---|
| Polynomials are formal objects | Defined by their coefficients, not the functions they compute. Over finite fields, distinct polynomials can define the same function |
| Polynomial rings | Genuine rings satisfying all axioms, with coefficient-wise addition and convolution multiplication |
| Degree rules | and |
| Coefficient ring matters | The same expression (like ) can be irreducible over one ring and factorable over another |
| The big parallel | mirrors , and this construction builds the finite fields used in AES, elliptic curves, and beyond |
Next: What Is a Field?, where we see what makes certain rings special enough to have division.