TExcelTAD
Home › Algebra › Dividing Polynomials

Dividing Polynomials

Dividing polynomials works like long division of whole numbers: divide, multiply, subtract, bring down, repeat, until what is left is "smaller" than the divisor. The result is a quotient and a remainder. This lesson does the division by hand, then implements both polynomial long division and the shortcut called synthetic division in Python, and ends with the remainder theorem and the CRC checksums that protect network packets.

Dividing by a monomial

Divide each term separately and subtract exponents:

(12x4−8x3+2x)÷2x=6x3−4x2+1(12x^4 - 8x^3 + 2x) \div 2x = 6x^3 - 4x^2 + 1

Long division

Divide 2x3−3x2+4x−52x^3 - 3x^2 + 4x - 5 by x−2x - 2. Each round looks only at the leading terms:

text
                2x² +  x  +  6
         ┌───────────────────────
  x − 2  │ 2x³ − 3x² + 4x − 5
           2x³ − 4x²                 2x³ ÷ x = 2x²;  2x²·(x − 2)
           ─────────
                  x² + 4x            subtract, bring down 4x
                  x² − 2x            x² ÷ x = x;  x·(x − 2)
                  ───────
                       6x − 5        subtract, bring down −5
                       6x − 12       6x ÷ x = 6;  6·(x − 2)
                       ───────
                             7       remainder

So 2x3−3x2+4x−5=(x−2)(2x2+x+6)+72x^3 - 3x^2 + 4x - 5 = (x - 2)(2x^2 + x + 6) + 7. In general, for a dividend PP and divisor DD:

P(x)=D(x)⋅Q(x)+R(x),degree of R<degree of DP(x) = D(x) \cdot Q(x) + R(x), \qquad \text{degree of } R < \text{degree of } D

Tip: Write every missing power with a 0 coefficient before you start (x3−1x^3 - 1 becomes x3+0x2+0x−1x^3 + 0x^2 + 0x - 1). Otherwise the columns slip and the subtraction goes wrong.

Long division in Python

The algorithm only touches coefficients. The version below stores them highest power first, like the hand layout, and uses Fraction so that a leading coefficient other than 1 gives exact answers:

python · try it yourself
from fractions import Fraction

def poly_divmod(p, d):
    """p, d: coefficients, highest power first. Returns (quotient, remainder)."""
    p = [Fraction(c) for c in p]
    q = []
    while len(p) >= len(d):
        factor = p[0] / d[0]                 # divide the leading terms
        q.append(factor)
        for i in range(len(d)):              # subtract factor · d, lined up on the left
            p[i] -= factor * d[i]
        p.pop(0)                             # the leading term is now 0
    return q, p or [Fraction(0)]

def show(c):
    return [str(x) for x in c]

q, r = poly_divmod([2, -3, 4, -5], [1, -2])
print("quotient:", show(q), " remainder:", show(r))
q, r = poly_divmod([6, 5, -4, 7], [2, 1, -1])
print("quotient:", show(q), " remainder:", show(r))
quotient: ['2', '1', '6']  remainder: ['7']
quotient: ['3', '1']  remainder: ['-2', '8']

The second line says (6x3+5x2−4x+7)÷(2x2+x−1)(6x^3 + 5x^2 - 4x + 7) \div (2x^2 + x - 1) has quotient 3x+13x + 1 and remainder −2x+8-2x + 8. Check: (2x2+x−1)(3x+1)=6x3+5x2−2x−1(2x^2 + x - 1)(3x + 1) = 6x^3 + 5x^2 - 2x - 1, and adding −2x+8-2x + 8 gives back the dividend.

Synthetic division

When the divisor is x−rx - r, the long division can be squeezed into one row of numbers. Write rr on the left and the coefficients on top. Bring down the first coefficient, then repeatedly multiply by rr and add to the next column:

text
  2 │  2   −3    4   −5
    │       4    2   12
    └───────────────────
       2    1    6 │  7

The bottom row gives the quotient 2x2+x+62x^2 + x + 6 and, after the bar, the remainder 7: the same as the long division, with far less writing. For a divisor x+3x + 3, use r=−3r = -3.

python · try it yourself
def synthetic(coeffs, r):
    """Divide by (x - r). coeffs highest power first."""
    row = [coeffs[0]]
    for c in coeffs[1:]:
        row.append(c + r * row[-1])          # multiply by r, add
    return row[:-1], row[-1]                 # quotient, remainder

print(synthetic([2, -3, 4, -5], 2))
print(synthetic([1, 0, 0, -8], 2))           # x³ − 8 by x − 2
print(synthetic([2, 3, -11, -6], 2))         # remainder 0: x − 2 is a factor
([2, 1, 6], 7)
([1, 2, 4], 0)
([2, 7, 3], 0)

The loop "multiply by rr, add the next coefficient" is exactly Horner's rule for evaluating a polynomial at rr. That is no coincidence.

The remainder and factor theorems

Dividing P(x)P(x) by x−rx - r leaves a constant remainder RR, and P(x)=(x−r)Q(x)+RP(x) = (x - r)Q(x) + R. Put x=rx = r in: the first part vanishes, so

Remainder theorem:P(r)=remainder of P(x)÷(x−r)Factor theorem:x−r is a factor of P(x)  ⟺  P(r)=0\begin{aligned} \text{Remainder theorem:}\quad &P(r) = \text{remainder of } P(x) \div (x - r) \\ \text{Factor theorem:}\quad &x - r \text{ is a factor of } P(x) \iff P(r) = 0 \end{aligned}

Check: 2⋅23−3⋅22+4⋅2−5=16−12+8−5=72 \cdot 2^3 - 3 \cdot 2^2 + 4 \cdot 2 - 5 = 16 - 12 + 8 - 5 = 7 ✓. And since 2x3+3x2−11x−62x^3 + 3x^2 - 11x - 6 gives remainder 0 at r=2r = 2, it factors as (x−2)(2x2+7x+3)=(x−2)(2x+1)(x+3)(x - 2)(2x^2 + 7x + 3) = (x - 2)(2x + 1)(x + 3). Finding one root and dividing it out is the standard way to break a cubic down to a quadratic, which you can then factor or solve with the formula.

SymPy has both operations built in:

python · try it yourself
import sympy as sp

x = sp.symbols("x")
q, r = sp.div(6*x**3 + 5*x**2 - 4*x + 7, 2*x**2 + x - 1, x)
print("q =", q, "  r =", r)
print(sp.factor(2*x**3 + 3*x**2 - 11*x - 6))
q = 3*x + 1   r = 8 - 2*x
(x - 2)*(x + 3)*(2*x + 1)

In software: CRC checksums

Ethernet frames, ZIP files and PNG images carry a CRC (cyclic redundancy check). The sender treats the message bits as coefficients of a polynomial, divides it by a fixed generator polynomial, and appends the remainder. Arithmetic is modulo 2, where subtraction is XOR, so the long division becomes "XOR the generator in wherever the leading bit is 1". The receiver repeats the division: a nonzero remainder means the data was corrupted.

python · try it yourself
def crc_remainder(bits, gen):
    """Polynomial long division over GF(2). bits, gen: strings of 0/1."""
    work = list(map(int, bits + "0" * (len(gen) - 1)))   # make room for the remainder
    g = list(map(int, gen))
    for i in range(len(bits)):
        if work[i]:                                       # leading coefficient is 1
            for j in range(len(g)):
                work[i + j] ^= g[j]                       # subtract = XOR
    return "".join(map(str, work[-(len(gen) - 1):]))

msg, gen = "1101011", "1011"          # generator x³ + x + 1
crc = crc_remainder(msg, gen)
print("CRC:", crc)
print("check sent frame:", crc_remainder(msg + crc, gen)[-3:] == "000")
CRC: 110
check sent frame: True

Real CRCs (CRC-32 uses a degree-32 generator) work the same way, just with table lookups to process a byte at a time (hashing explains why a CRC detects accidents but is no defence against attackers).

Exercises

Exercise 1: By a monomial

Simplify (15a5−10a3+5a2)÷5a2(15a^5 - 10a^3 + 5a^2) \div 5a^2.

Answer

3a3−2a+13a^3 - 2a + 1

Solution
15a5÷5a2=3a3−10a3÷5a2=−2a5a2÷5a2=1\begin{aligned} 15a^5 \div 5a^2 &= 3a^3 \\ -10a^3 \div 5a^2 &= -2a \\ 5a^2 \div 5a^2 &= 1 \end{aligned}

Exercise 2: Synthetic division

Divide x3+4x2−7x−10x^3 + 4x^2 - 7x - 10 by x+1x + 1.

Answer

Quotient x2+3x−10x^2 + 3x - 10, remainder 0.

Solution

Use r=−1r = -1:

text
 −1 │ 1    4   −7  −10
    │     −1   −3   10
    └─────────────────
      1    3  −10 │  0

Since the remainder is 0, x+1x + 1 is a factor, and x2+3x−10=(x+5)(x−2)x^2 + 3x - 10 = (x + 5)(x - 2).

Exercise 3: Remainder without dividing

Find the remainder when x4−3x3+2x−9x^4 - 3x^3 + 2x - 9 is divided by x−3x - 3.

Answer

−3

Solution

By the remainder theorem it is P(3)=81−81+6−9=−3P(3) = 81 - 81 + 6 - 9 = -3.

python · try it yourself
def synthetic(coeffs, r):
    row = [coeffs[0]]
    for c in coeffs[1:]:
        row.append(c + r * row[-1])
    return row[:-1], row[-1]

print(synthetic([1, -3, 0, 2, -9], 3))
([1, 0, 0, 2], -3)

Exercise 4: Long division with a quadratic divisor

Divide x4+2x3−x+5x^4 + 2x^3 - x + 5 by x2+1x^2 + 1.

Answer

Quotient x2+2x−1x^2 + 2x - 1, remainder −3x+6-3x + 6.

Solution
x4÷x2=x2:x4+2x3+0x2−x+5−(x4+x2)=2x3−x2−x+52x3÷x2=2x:2x3−x2−x+5−(2x3+2x)=−x2−3x+5−x2÷x2=−1:−x2−3x+5−(−x2−1)=−3x+6\begin{aligned} x^4 \div x^2 = x^2{:}\quad &x^4 + 2x^3 + 0x^2 - x + 5 - (x^4 + x^2) = 2x^3 - x^2 - x + 5 \\ 2x^3 \div x^2 = 2x{:}\quad &2x^3 - x^2 - x + 5 - (2x^3 + 2x) = -x^2 - 3x + 5 \\ -x^2 \div x^2 = -1{:}\quad &{-x^2} - 3x + 5 - (-x^2 - 1) = -3x + 6 \end{aligned}
python · try it yourself
import sympy as sp

x = sp.symbols("x")
print(sp.div(x**4 + 2*x**3 - x + 5, x**2 + 1, x))
(x**2 + 2*x - 1, 6 - 3*x)

Exercise 5: Find k

For which kk is x−2x - 2 a factor of x3+kx2−4x+4x^3 + kx^2 - 4x + 4?

Answer

k=−1k = -1

Solution

By the factor theorem P(2)=0P(2) = 0: 8+4k−8+4=08 + 4k - 8 + 4 = 0, so 4k=−44k = -4 and k=−1k = -1. Check: x3−x2−4x+4=(x−2)(x2+x−2)=(x−2)(x+2)(x−1)x^3 - x^2 - 4x + 4 = (x - 2)(x^2 + x - 2) = (x - 2)(x + 2)(x - 1).

Test yourself

What is the remainder of (x3−2x+1)÷(x−1)(x^3 - 2x + 1) \div (x - 1)?

  1. 0
  2. 1
  3. −1
  4. 2

When dividing by x+4x + 4 with synthetic division, which number goes in the box?

  1. 4
  2. 1
  3. −4
  4. 1/4

A degree-5 polynomial is divided by a degree-2 polynomial. What are the possible degrees of the remainder?

  1. Exactly 2
  2. 1 or 0 (or the remainder is 0)
  3. 3
  4. Any degree up to 5