TExcelTAD
Home › Algebra › Polynomial Definitions

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 p(x)=4x3−2x2+7x−5p(x) = 4x^3 - 2x^2 + 7x - 5. It has four terms: 4x34x^3, −2x2-2x^2, 7x7x and −5-5.

Word Meaning In 4x3−2x2+7x−54x^3 - 2x^2 + 7x - 5
term one piece of the sum, a number times a power of xx 4x34x^3, −2x2-2x^2, 7x7x, −5-5
coefficient the number in front of a power of xx 4, −2, 7, −5
constant term the term with no xx (it is −5⋅x0-5 \cdot x^0) −5
degree of a term the exponent on xx 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 4x34x^3, 4

The exponents must be whole numbers 0, 1, 2, …. So x2+3xx^2 + 3x is a polynomial, but x=x1/2\sqrt{x} = x^{1/2}, 1x=x−1\frac{1}{x} = x^{-1} and 2x2^x are not.

For a term with several variables, the degree is the sum of the exponents: 5x2y35x^2y^3 has degree 2+3=52 + 3 = 5. 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 −3x4-3x^4 0 constant 77
2 binomial x2−9x^2 - 9 1 linear 2x+12x + 1
3 trinomial x2+5x+6x^2 + 5x + 6 2 quadratic x2−4xx^2 - 4x
4+ polynomial x3+x2+x+1x^3 + x^2 + x + 1 3 cubic x3−8x^3 - 8

Standard form lists the terms from the highest power down: −5+7x+4x3−2x2-5 + 7x + 4x^3 - 2x^2 becomes 4x3−2x2+7x−54x^3 - 2x^2 + 7x - 5. A missing power simply has coefficient 0: x3−8x^3 - 8 is 1x3+0x2+0x−81x^3 + 0x^2 + 0x - 8.

Note: The zero polynomial 00 has no nonzero term, so it has no degree (some books say −∞-\infty). Code that computes a degree must handle that case.

Evaluating a polynomial

To evaluate p(x)p(x) at a number, substitute the number for every xx and follow the order of operations:

p(2)=4⋅23−2⋅22+7⋅2−5=32−8+14−5=33p(2) = 4 \cdot 2^3 - 2 \cdot 2^2 + 7 \cdot 2 - 5 = 32 - 8 + 14 - 5 = 33

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 xkx^k sits at index k:

python · try it yourself
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:

python · try it yourself
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.polyval and np.roots want highest power first; numpy.polynomial.Polynomial wants 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 BB, modulo a large prime MM: hash⁡("abc")=(a⋅B2+b⋅B+c) mod M\operatorname{hash}(\texttt{"abc"}) = (a \cdot B^2 + b \cdot B + c) \bmod M. 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 tt (easing curves).
  • Fast evaluation. Evaluating term by term recomputes powers. Evaluating Polynomials Fast shows Horner's rule, which needs only one multiplication per coefficient.
python · try it yourself
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 97⋅312+98⋅31+99=96 35497 \cdot 31^2 + 98 \cdot 31 + 99 = 96\,354: 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 q(x)=6−x5+3x2q(x) = 6 - x^5 + 3x^2, give the standard form, the degree, the leading coefficient and the constant term.

Answer

−x5+3x2+6-x^5 + 3x^2 + 6; degree 5; leading coefficient −1; constant term 6.

Solution
order by power: −x5+3x2+6highest power with nonzero coefficient: x5  →  degree 5coefficient of x5 is −1 (the minus sign belongs to the coefficient)term with no x: 6\begin{aligned} &\text{order by power: } -x^5 + 3x^2 + 6 \\ &\text{highest power with nonzero coefficient: } x^5 \;\to\; \text{degree 5} \\ &\text{coefficient of } x^5 \text{ is } {-1} \text{ (the minus sign belongs to the coefficient)} \\ &\text{term with no } x\text{: } 6 \end{aligned}

Exercise 2: Polynomial or not?

Which of these are polynomials? (a) 3x2−x+123x^2 - x + \frac{1}{2} (b) x3+2xx^3 + \frac{2}{x} (c) 5⋅x4\sqrt{5} \cdot x^4 (d) x1/2+1x^{1/2} + 1

Answer

(a) and (c) are polynomials; (b) and (d) are not.

Solution

Coefficients may be any numbers (12\frac{1}{2} and 5\sqrt{5} are fine), but the exponents on xx must be whole numbers. (b) contains 2x=2x−1\frac{2}{x} = 2x^{-1}, a negative exponent. (d) contains the exponent 12\frac{1}{2}.

Exercise 3: Degree with two variables

Find the degree of 2x3y−7x2y4+xy2x^3y - 7x^2y^4 + xy.

Answer

6

Solution
2x3y  →  3+1=4−7x2y4  →  2+4=6xy  →  1+1=2highest: 6\begin{aligned} 2x^3y &\;\to\; 3 + 1 = 4 \\ -7x^2y^4 &\;\to\; 2 + 4 = 6 \\ xy &\;\to\; 1 + 1 = 2 \\ &\text{highest: } 6 \end{aligned}

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 x=−2x = -2, by hand and in code.

Answer

2x4−3x2+12x^4 - 3x^2 + 1, and its value at −2 is 21.

Solution
text
index:  0   1   2   3   4
coeff:  1   0  −3   0   2   →  1 − 3x² + 2x⁴
p(−2)=2⋅16−3⋅4+1=32−12+1=21p(-2) = 2 \cdot 16 - 3 \cdot 4 + 1 = 32 - 12 + 1 = 21
python · try it yourself
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.

python · try it yourself
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 3x2−8x4+x−13x^2 - 8x^4 + x - 1?

  1. 2
  2. 3
  3. 4
  4. −8

Which expression is NOT a polynomial?

  1. x2−9x^2 - 9
  2. 5
  3. 4x3+x/24x^3 + x/2
  4. x+1/xx + 1/x

With the constant-first convention, which polynomial does [0, 3, 0, 1] represent?

  1. x3+3xx^3 + 3x
  2. 3x3+x3x^3 + x
  3. 3x2+x43x^2 + x^4
  4. x+3x + 3