Polynomial Definitions
A polynomial is a sum of terms, where each term is a number times a variable raised to a whole-number power. Polynomials are the most-used expressions in algebra. This lesson names their parts (term, coefficient, degree, leading coefficient), shows how to write them in standard form and evaluate them, and shows how programs store a polynomial as a plain list of numbers.
Terms, coefficients and degree
Look at . It has four terms: , , and .
| Word | Meaning | In |
|---|---|---|
| term | one piece of the sum, a number times a power of | , , , |
| coefficient | the number in front of a power of | 4, −2, 7, −5 |
| constant term | the term with no (it is ) | −5 |
| degree of a term | the exponent on | 3, 2, 1, 0 |
| degree of the polynomial | the highest degree of any term with a nonzero coefficient | 3 |
| leading term / coefficient | the term with the highest degree, and its coefficient | , 4 |
The exponents must be whole numbers 0, 1, 2, …. So is a polynomial, but , and are not.
For a term with several variables, the degree is the sum of the exponents: has degree . See Algebra Terminology for the general vocabulary of terms and factors.
Names by number of terms and by degree
| Terms | Name | Example | Degree | Name | Example | |
|---|---|---|---|---|---|---|
| 1 | monomial | 0 | constant | |||
| 2 | binomial | 1 | linear | |||
| 3 | trinomial | 2 | quadratic | |||
| 4+ | polynomial | 3 | cubic |
Standard form lists the terms from the highest power down: becomes . A missing power simply has coefficient 0: is .
Note: The zero polynomial has no nonzero term, so it has no degree (some books say ). Code that computes a degree must handle that case.
Evaluating a polynomial
To evaluate at a number, substitute the number for every and follow the order of operations:
Polynomials as lists of coefficients
A program does not need the letters at all. The list of coefficients carries the whole polynomial. A common convention puts the constant first, so the coefficient of sits at index k:
p = [-5, 7, -2, 4] # -5 + 7x - 2x² + 4x³, index k holds the coefficient of x^k
def degree(coeffs):
for k in range(len(coeffs) - 1, -1, -1):
if coeffs[k] != 0:
return k
return None # the zero polynomial has no degree
def evaluate(coeffs, x):
return sum(c * x**k for k, c in enumerate(coeffs))
print("degree:", degree(p))
print("leading coefficient:", p[degree(p)])
print("p(2) =", evaluate(p, 2))
print("p(-1) =", evaluate(p, -1))
print("degree of [3, 0, 0, 0]:", degree([3, 0, 0, 0]))
print("degree of [0, 0]:", degree([0, 0]))degree: 3
leading coefficient: 4
p(2) = 33
p(-1) = -18
degree of [3, 0, 0, 0]: 0
degree of [0, 0]: None
NumPy and SymPy use the opposite order, highest power first, which matches how we write by hand. SymPy's Poly reads off the parts for you:
import numpy as np
import sympy as sp
x = sp.symbols("x")
P = sp.Poly(4*x**3 - 2*x**2 + 7*x - 5, x)
print("degree:", P.degree())
print("leading coefficient:", P.LC())
print("coefficients, highest first:", P.all_coeffs())
print("p(2) with SymPy:", P.eval(2))
print("p(2) with NumPy:", int(np.polyval([4, -2, 7, -5], 2)))degree: 3
leading coefficient: 4
coefficients, highest first: [4, -2, 7, -5]
p(2) with SymPy: 33
p(2) with NumPy: 33
Tip: Always check which order a library expects.
np.polyvalandnp.rootswant highest power first;numpy.polynomial.Polynomialwants lowest first, like the list above. Mixing them up silently gives a different polynomial.
In software
- Polynomial hashing. The rolling hash behind the Rabin–Karp string search treats the characters of a string as coefficients and evaluates that polynomial at a base , modulo a large prime : . Sliding the window by one character updates the hash in constant time. Hash tables use the same idea for string keys (Hash Tables).
- Curves and animation. Easing curves and Bézier segments are cubic polynomials in time (easing curves).
- Fast evaluation. Evaluating term by term recomputes powers. Evaluating Polynomials Fast shows Horner's rule, which needs only one multiplication per coefficient.
def poly_hash(s, base=31, mod=1_000_000_007):
h = 0
for ch in s: # Horner's rule: h = h*B + next coefficient
h = (h * base + ord(ch)) % mod
return h
for word in ["abc", "acb", "polynomial"]:
print(word, poly_hash(word))abc 96354
acb 96384
polynomial 571076242
Here "abc" is : the character codes are the coefficients. Swapping two letters changes the hash because the coefficients move to different powers.
Exercises
Exercise 1: Name the parts
For , give the standard form, the degree, the leading coefficient and the constant term.
Answer
; degree 5; leading coefficient −1; constant term 6.
Solution
Exercise 2: Polynomial or not?
Which of these are polynomials? (a) (b) (c) (d)
Answer
(a) and (c) are polynomials; (b) and (d) are not.
Solution
Coefficients may be any numbers ( and are fine), but the exponents on must be whole numbers. (b) contains , a negative exponent. (d) contains the exponent .
Exercise 3: Degree with two variables
Find the degree of .
Answer
6
Solution
Exercise 4: Evaluate from a list
The list [1, 0, -3, 0, 2] stores a polynomial with the constant first. Write the polynomial and evaluate it at , by hand and in code.
Answer
, and its value at −2 is 21.
Solution
index: 0 1 2 3 4
coeff: 1 0 −3 0 2 → 1 − 3x² + 2x⁴coeffs = [1, 0, -3, 0, 2]
x = -2
print(sum(c * x**k for k, c in enumerate(coeffs)))21
Exercise 5: Trim trailing zeros
After subtracting polynomials a program may hold [4, 0, 5, 0, 0], whose real degree is 2. Write trim(coeffs) that removes zero coefficients from the high end (keep [0] for the zero polynomial).
Answer
trim([4, 0, 5, 0, 0]) returns [4, 0, 5] and trim([0, 0]) returns [0].
Solution
Pop from the end while the last coefficient is 0 and more than one remains.
def trim(coeffs):
c = list(coeffs)
while len(c) > 1 and c[-1] == 0:
c.pop()
return c
print(trim([4, 0, 5, 0, 0]))
print(trim([0, 0]))
print(trim([1, 2]))[4, 0, 5]
[0]
[1, 2]
Test yourself
What is the degree of ?
- 2
- 3
- 4
- −8
Which expression is NOT a polynomial?
- 5
With the constant-first convention, which polynomial does [0, 3, 0, 1] represent?