Mathematics RU

Solver

Higher-degree equation solver: Horner's scheme and factorising polynomials

Cubic, biquadratic and other equations of degree above two, factorising polynomials and polynomial long division, step by step, with every move explained and a graph.

Loading the solver…

What you can type

The solver understands three kinds of problem.

  • An equation, with an equals sign: x^3 - 6x^2 + 11x - 6 = 0, x^4 = 16, (x - 1)^2(x + 2) = 0. It finds all the real roots and their multiplicities.
  • Factorising: a polynomial without an equals sign, optionally with the word “factor”: factor x^4 - 16. It factorises over the rational numbers and finds the roots along the way.
  • Polynomial division: a fraction of two polynomials or the words “divide … by …”: (x^3 - 2x^2 - 4)/(x - 3), divide x^5 + 1 by x + 1. It does long division and finds the quotient and the remainder.

Coefficients can be integers, fractions or decimals; the degree can go up to twelve. The solver won’t take equations with a parameter or with the unknown under a root, and it says so plainly.

How to solve it: from simple to hard

For equations of degree three and higher there is no single formula that’s convenient to use, the way the discriminant is for quadratics. There is, however, a set of techniques, and it’s worth trying them in a particular order, from the cheapest to the most laborious. The solver follows the same path.

  1. Standard form. Move everything to the left, expand the brackets, collect like terms. The exception is an equation that is already factorised, like $(x - 1)^2(x + 2) = 0$: expanding the brackets would do harm; instead set each factor equal to zero.
  2. Take out $x^k$. If there’s no constant term, every term contains $x$. From $x^5 - x = 0$ we get $x(x^4 - 1) = 0$: the root $x = 0$ is already there, and we carry on with the bracket.
  3. Recognise a special form. The equation $x^n = c$ is solved by taking a root. A biquadratic $ax^4 + bx^2 + c = 0$ becomes quadratic after substituting $t = x^2$ (the substitution $t = x^m$ works the same way for $ax^{2m} + bx^m + c$). The four terms of a cubic can sometimes be grouped in pairs so that a common bracket appears.
  4. Look for rational roots. There are finitely many candidates: the divisors of the constant term divided by the divisors of the leading coefficient. Try them one by one; a root $r$ you find lets you divide the polynomial by $x - r$ with Horner’s scheme and lower the degree by one.
  5. A quadratic is left: solve it with the discriminant.
  6. Nothing worked: find the roots approximately, to four decimal places, and mark them honestly with the sign $\approx$.

Why it works

Everything rests on one fact about dividing polynomials. Divide a polynomial $P(x)$ by $x - a$ with remainder, just as you divide numbers by long division. The divisor has degree one, so the remainder is just a number. Which one? Put $x = a$ into the equality $P(x) = (x - a)Q(x) + R$: the first term vanishes, and what remains is $R = P(a)$.

Any number. If $P(a) = 0$, then $a$ is a root, and the polynomial is divisible by $x - a$ with no remainder (the factor theorem). The quotient, a polynomial of degree one less. The other roots of $P$ are the roots of $Q$. The remainder on division by $x - a$ equals the value of the polynomial at $a$. Example: $P(x) = x^3 - 2x^2 - 4$ and $a = 3$. The value is $P(3) = 27 - 18 - 4 = 5$, and indeed $x^3 - 2x^2 - 4 = (x - 3)(x^2 + x + 3) + 5$: expand the brackets and check.

It follows that finding a root means lowering the degree. And where do the candidates come from? Suppose a polynomial with integer coefficients $a_n x^n + \dots + a_1 x + a_0$ has a rational root $\frac{p}{q}$ in lowest terms. Substitute it and multiply by $q^n$:

$$a_n p^n + a_{n-1} p^{n-1} q + \dots + a_1 p q^{n-1} + a_0 q^n = 0.$$

Every term except the last is divisible by $p$, so $a_0 q^n$ is divisible by $p$ too; and since $p$ and $q$ are coprime, $p$ divides $a_0$. In the same way $q$ divides $a_n$. For $2x^3 - x^2 - 8x + 4$ the candidates are $\pm 1, \pm 2, \pm 4, \pm \frac12$, and there can be no other rational roots. If the leading coefficient is $1$, rational roots can only be integer divisors of the constant term.

Horner’s scheme (also called synthetic division) is a quick way both to test a candidate and to divide by $x - a$ at the same time. Write out the coefficients and bring down the first; after that, each number in the bottom row equals the previous one times $a$, plus the coefficient above it. For $x^3 - 6x^2 + 11x - 6$ and $a = 1$:

$$\begin{array}{c|cccc} & 1 & -6 & 11 & -6 \\ \hline 1 & 1 & -5 & 6 & 0 \end{array}$$

The last number is the remainder, that is, $P(1) = 0$: one is a root. The other numbers in the bottom row are the coefficients of the quotient: $x^3 - 6x^2 + 11x - 6 = (x - 1)(x^2 - 5x + 6)$. If a root is repeated, test it again on the quotient: this is how $x^4 - 2x^3 - 3x^2 + 4x + 4$ turns out to be divisible by $x + 1$ twice.

Worked examples

Example 1. Rational roots: $x^3 - 6x^2 + 11x - 6 = 0$

The leading coefficient is $1$ and the constant term is $-6$, so the candidates are $\pm1, \pm2, \pm3, \pm6$. The very first one works: $P(1) = 1 - 6 + 11 - 6 = 0$. Horner’s scheme (written out above) gives the quotient $x^2 - 5x + 6$, whose roots by the formula are $2$ and $3$. Answer: $x_1 = 1$, $x_2 = 2$, $x_3 = 3$, and with it the factorisation $(x - 1)(x - 2)(x - 3)$.

Example 2. A biquadratic: $x^4 - 5x^2 + 4 = 0$

The unknown appears only as $x^2$ and $x^4 = (x^2)^2$. Substituting $t = x^2$ gives $t^2 - 5t + 4 = 0$, so $t = 1$ or $t = 4$. Substituting back: $x^2 = 1$ gives $x = \pm 1$, and $x^2 = 4$ gives $x = \pm 2$. Four roots: $-2$, $-1$, $1$, $2$. Had one of the values of $t$ been negative, it would have given no roots: $x^2$ is never below zero.

Example 3. Grouping: $2x^3 - x^2 - 8x + 4 = 0$

The first two terms are $x^2(2x - 1)$, the last two are $-4(2x - 1)$. The common bracket comes out: $(2x - 1)(x^2 - 4) = 0$. So $x = \frac12$ or $x^2 = 4$, that is, $x = \pm 2$. Trying the candidates $\pm1, \pm2, \pm4, \pm\frac12$ would lead to the same place, only more slowly.

Example 4. When there’s no exact answer: $x^3 - 2x - 5 = 0$

The candidates are $\pm1$ and $\pm5$: $P(1) = -6$, $P(-1) = -4$, $P(5) = 110$, $P(-5) = -120$, and none is a root. There are no rational roots, and the polynomial can’t be factorised over the rationals. For cubics there is Cardano’s formula (1545), but its answer is unwieldy, so the root is found numerically. Between $2$ and $3$ the value changes sign ($P(2) = -1$, $P(3) = 16$), and halving the interval repeatedly gives $x \approx 2.0946$. Newton once used this very equation to demonstrate his method of approximate solution. The other two roots are complex.

Example 5. Long division: $(x^3 - 2x^2 - 4) \div (x - 3)$

Keep the missing power in mind as $0x$. Divide the leading terms: $x^3 \div x = x^2$; subtract $x^2(x - 3) = x^3 - 3x^2$, leaving $x^2 - 4$. Next, $x^2 \div x = x$; subtract $x^2 - 3x$, leaving $3x - 4$. Finally, $3x \div x = 3$; subtract $3x - 9$, leaving $5$. The quotient is $x^2 + x + 3$ and the remainder is $5$, exactly $P(3)$, as the remainder theorem promises.

Common mistakes

  • Leaving out zero coefficients in Horner’s scheme. $x^3 - 2x^2 - 4$ has coefficients $1, -2, 0, -4$, not $1, -2, -4$: without the zero you get a different polynomial.
  • Looking for roots only among the positive divisors. Candidates always come in $\pm$ pairs, and when the leading coefficient isn’t one, also as fractions $\frac{p}{q}$.
  • Not testing a root you’ve found a second time. A root can be repeated: for $(x - 1)^2(x + 2)$, one is a root of the quotient too. Multiplicity matters for graphs and inequalities: at a root of even multiplicity the graph touches the axis without crossing it.
  • Keeping a negative $t$ in a biquadratic. $x^2 = -3$ has no roots; such values of $t$ are thrown away when substituting back.
  • Solving $x^3 = 8$ as $x = \pm 2$. An odd power doesn’t erase the sign: $(-2)^3 = -8$. There is one real root, $x = 2$.
  • Dividing both sides by $x$. “Cancelling” in $x^5 = x$ gives $x^4 = 1$, and the root $x = 0$ vanishes. Take $x$ out as a factor instead.
  • Expanding the brackets in an equation that is already factorised. $(x - 1)^2(x + 2) = 0$ is solved in one line: $x = 1$ or $x = -2$. After expanding you’d have to find these roots all over again.

See also

The duel between Tartaglia and Fiore, Cardano’s formula and its irreducible case, interpolation and Shamir’s secret sharing are in the chapter on polynomials. Why there is no general formula for degree five is explained by Galois theory. The quadratic left over after lowering the degree is solved in detail by the quadratic equation solver, and inequalities with polynomials by the interval method, where the multiplicities of the roots decide whether the sign changes.

Where this is explained

Other solvers