Message Boards Message Boards

Solving polynomials

Posted 7 years ago

NOTE: a notebook with all content is attached at the end of the post.


enter image description here

Solving polynomials

A bunch of constant coefficients, a, b, c, ..., (numbers) determine a succession of polynomials

TableForm[{a x + b, a x^2 + b x + c, a x^3 + b x^2 + c x + d, ". . ."}] // TraditionalForm

enter image description here

and the problem of solving polynomials is the business of finding the values of x that make these quantities vanish (equal 0). The names of these polynomials are successively "linear", "quadratic", "cubic", "quartic", "quintic", "sextic". "septic", "octic", ... , depending on the highest power of x (the "degree"). "Quartic", "quintic", et sequitur come from the Latin words for "four", "five", "six", ..., but "linear", "quadratic", and "cubic" are old idioms, like the word "squared" if you think about it. We say the equation $y = a x + b$ is "linear" because plotting it makes a straight line. E.g., with a = 2 and b = 3,

Plot[2 x + 3, {x, -2, 1}]

enter image description here

so the (lone) solution of 2 x + 3 = 0 is x = -3/2, and in general, x = -b/a.

The equation $y = a x^2+b x+c$ is presumably named "quadratic" because of its x "squared" term. It is sufficiently important that you will eventually remember its two solutions,

Solve[a x^2 + b x + c == 0, x]

enter image description here

long after forgetting why anyone would want to solve it. Radical expressions like these are called surds. Perhaps the commonest application is geometry. Circles, parabolas, and hyperbolas are usually specified by quadratic polynomials, and we get a quadratic equation whenever we ask where one of them intersects a given line. This even happens when the hyperbola is in rectangular form, e.g.,

Plot[{(1 - x)/(x + 2), 2 x + 3}, {x, -4, 1}, PlotRange -> {{-4, 1}, {-6, 6}}, AspectRatio -> 4/5]

enter image description here

The equation for where the hyperbola branches intersect the line is

(1 - x)/(x + 2) == 2 x + 3;

This doesn't look like a x^2+b x+c==0 until we multiply both sides by x+2,

Distribute[(x + 2)*%, Equal]

1 - x == (2 + x) (3 + 2 x)

subtract both sides from (2+x) (3+2 x)

(2 + x) (3 + 2 x) - # & /@ %

-1 + x + (2 + x) (3 + 2 x) == 0

and expand:

Expand@%

5 + 8 x + 2 x^2 == 0

Because Mathematica is unconventional in manipulating equations, the "subtract both sides" step was a bit obscure. It uses & to make a function that subtracts things (#) from (2+x) (3+2 x), then "maps" (/@) it down both sides of the equation.

At any rate, solving the quadratic equation:

Solve[%]

{{x -> 1/2 (-4 - Sqrt[6])}, {x -> 1/2 (-4 + Sqrt[6])}}

Or approximately

N@%

{{x -> -3.22474}, {x -> -0.775255}}

Of course, Mathematica is perfectly happy to

Solve[(1 - x)/(x + 2) == 2 x + 3]

{{x -> 1/2 (-4 - Sqrt[6])}, {x -> 1/2 (-4 + Sqrt[6])}}

directly. And we can use these values as the plot range

Flatten[% /. Rule -> List]

{x, 1/2 (-4 - Sqrt[6]), x, 1/2 (-4 + Sqrt[6])}

to visually check for plausibility:

Plot[{(1 - x)/(x + 2), 2 x + 3}, %[[{1, 2, 4}]]]

enter image description here

The plot starts and ends at the intersections. (The {1,2,4} was to get rid of the extra x.)

Had the hyperbola been upside down, we'd appear to have no solutions:

Plot[{(x - 1)/(x + 2), 2 x + 3}, {x, -4, 1}, PlotRange -> {{-4, 1}, {-6, 6}}, AspectRatio -> 4/5]

enter image description here

But instead of {}, Mathematica answers

Solve[(x - 1)/(x + 2) == 2 x + 3]

{{x -> 1/2 (-3 - I Sqrt[5])}, {x -> 1/2 (-3 + I Sqrt[5])}}

I.e., the solutions contain imaginary numbers.

The quadratic equation was solved by the ingenious trick of Completing the Square, that is, adding $b^2/4a -c$ to both sides:

# + b^2/(4 a) - c & /@ (a x^2 + b x + c == 0)

b^2/(4 a) + b x + a x^2 == b^2/(4 a) - c

Then the left side factors into a square over 4 a:

Factor /@ %

(b + 2 a x)^2/(4 a) == -((-b^2 + 4 a c)/(4 a))

Then after multiplying by 4 a

4 a # & /@ %

(b + 2 a x)^2 == b^2 - 4 a c

we can take the square root of both sides.

Sqrt /@ % // PowerExpand

b + 2 a x == Sqrt[b^2 - 4 a c]

and now it's a linear equation. The PowerExpand forced Mathematica, against its better judgment, to choose b + 2 a x, rather than the equally valid - b - 2 a x, for the square root of the square.

Just as "everybody" remembers the solution to the quadratic equation, "nobody" remembers the solution to the cubic. Here's why:

Solve[ a x^3 + b x^2 + c x + d == 0, x] // TraditionalForm

enter image description here

Now consider the simple case

Plot[x^3 - x + 1/3, {x, -3/2, 3/2}]

enter image description here

It clearly has three real roots, near -1.1, .35, and .75 . What are they, exactly?

Solve[x^3 - x + 1/3 == 0]

enter image description here

Hey wait a minute, I thought we said the roots are real. Maybe Mathematica just forgot to simplify:

Simplify@%%

enter image description here

How can this complex mess be real? Let's take the imaginary part:

ComplexExpand@Im[x /. %]

{0, 0, 0}

Well then, for Heaven's sake, tell us the real part!

ComplexExpand@Re[x /. %%]

enter image description here

Trig functions!? I demand the return of my square roots and cube roots!

Developer`TrigToRadicals@%%

enter image description here

Gaa! Those trig functions were real, but why is this crawling with imaginary units? What happened to -1.1, .35, and .75 ?? Numbers, please.

N@%

{0.742227 + 0. I, 0.394931 + 0. I, -1.13716 + 0. I}

They're there, but what are those stupid 0. i ? Strangely enough, they're unavoidable. A branch of Mathematics known a Galois Theory has proven impossible the expression of the answer without cube roots of imaginary numbers, even though they add up to reals.

And here's an Animate by Henry Baker (see actual animation at the top of the post) showing the relation among the roots when all three are real:

enter image description here

This is a fair picture of the general case - cubics with three real roots have a point of inflection, about which they are symmetric. I.e., if you translate the point of inflection to the origin, you get an odd function $f(-x) = -f(x)$.

Quartic equations can come up when you intersect curves with each other. You need to be slightly insane to want to see the general quartic solution, but here it is if you want to press shift return.

Solve[ a x^4 + b x^3 + c x^2 + d x + e == 0, x]

So it would be downright suicidal to try the general quintic.

Solve[ a x^5 + b x^4 + c x^3 + d x^2 + e x + f == 0, x]

enter image description here

Hah, Mathematica took mercy on us, and copped out. But why didn't it at least offer its interactive Large Expression explorer? Because it can't. There is no expression in radicals for the general quintic! Clearly we can solve some quintics by factoring them.

Expand@# == # &[(x^2 + 1) (x^3 - x - 1)]

-1 - x - x^2 + x^5 == (1 + x^2) (-1 - x + x^3)

But after centuries of frustration, solving the quintic has joined angle trisection and cube doubling in the dungeon of the impossible.

Many people falsely believe that the only solvable quintics are either factorable, or obvious, such as $(x+a)^5+b=0$. But a small percentage, technically 0%, can be ingeniously solved, such as

x^5 - 5 x^2 - 3 == 0

whose roots are seriously messy. The only real one is

enter image description here

At least it has the decency to look real. Plain Mathematica can't do this--not even verify it! Except approximately:

%^5 - 5`69 %^2

3.0000000000000000000000000000000000000000000000000000000000000000000

I once (correctly?) convinced myself that every solvable sextic reduces to either a cubic with quadratic surd coefficients or a quadratic with cubic surd coefficients. Who would ever want to solve a sextic? Geometry again. Problem: Dissect a square into a finite number of acute, isosceles triangles. It can be done with ten: enter image description here

The equations determining Subscript[x, 1],Subscript[y, 1],Subscript[x, 2], and Subscript[r, 3] are duodecic! They factor down to sextics with surd coefficients, but insoluble according to expert Noam Elkies. But when the degree is 6, 8, 9, ... or any composite (nonprime) number, there is sometimes a way to get lucky.

Factor[5 + 4 x^2 - 4 x^3 + x^4 - 2 x^5 + x^6]

5 + 4 x^2 - 4 x^3 + x^4 - 2 x^5 + x^6

doesn't factor. Yet

Solve[% == 0]

enter image description here

found all six solutions! How? This sextic can be written as

x^2 - 4 x + 5 /. x -> x^3 - x^2

5 - 4 (-x^2 + x^3) + (-x^2 + x^3)^2

Factor@%

5 + 4 x^2 - 4 x^3 + x^4 - 2 x^5 + x^6

That is, the substitution of a cubic into a quadratic. If we could notice this, we'd merely replace $x^3-x^2-2$ by y, solve the resulting quadratic for y and then solve the cubic for x in terms of y. But how could we notice this? With the magic function

Decompose[5 + 4 x^2 - 4 x^3 + x^4 - 2 x^5 + x^6, x]

{5 - 4 x + x^2, -x^2 + x^3}

which the Solve function fortunately knows about. Who knows? Your octic might be merely the composition of three quadratics.

But note: Here is a solution to a sextic that neither factors

enter image description here

5 + 18 x + 36 x^2 + 36 x^6

nor decomposes.

enter image description here

{570630428688384000000 + 4891824455002619904 x + 161093791317491712

x^2 + 12153384861696 x^3 + 984379392 x^4 - 17280 x^5 + x^6}

Simplify[% /. x -> %%]

{0}

So the quantity in parentheses satisfies a minimum polynomial of minimum degree 36!

Amazingly, here's an old trick that even Mathematica Version 11 doesn't know: You can always solve a sextic, (even an octic!), if the coefficients form a palindrome. E.g.,

Solve[1 + x + x x - x^3 + x^4 + x^5 + x^6 == 0]

enter image description here

(Fail.) But we can do the fully general case! For arbitrary a,b,c,d, suppose x satisfies the reciprocal polynomial (as palindromes are called)

a x^6 + b x^5 + c x^4 + d x^3 + c x x + b x + a

a + b x + c x^2 + d x^3 + c x^4 + b x^5 + a x^6

Now suppose y = x + 1/x (or x y = x^2+1), and find the remainder (with respect to x) of dividing the sextic by this quadratic:

Factor[PolynomialRemainder[%, x + 1/x - y, x]]

(-x - y + x y^2) (-2 b + d - 3 a y + c y + b y^2 + a y^3)

Finding this remainder means subtracting the multiple of the quadratic that reduces the sextic to be linear in x. But we have supposed that both the quadratic and sextic are 0, so we have subtracted 0 from 0, getting a dubious relation between x and y, times a cubic in y that we can solve! We finish by solving y = x + 1/x for x.

Palindrome polynomials are called "reciprocal" because they have the same roots if you replace x by 1/x, which reverses the order of the coefficients (and divides by x^6).

The y = x + 1/x trick works because we can pair terms with their reciprocals, and use relations like

1/x^3 + x^3 == -3 (1/x + x) + (1/x + x)^3

1/x^2 + x^2 == -2 + (1/x + x)^2

Julian and I have a septic solver, but he doesn't trust it to find all solutions. Beyond seven, the chances of finding a competent solver, human or otherwise, tail off rapidly, along with the chances that he|she|it will find it solvable even theoretically. But if your problem wasn't simply made up at random, it's always worth a try.

Attachments:
POSTED BY: Bill Gosper
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract