# How to find roots of general polynomials as functions in Mathematica?

Edit:

I learned from the comment below that there is already a method by summing series here

How can I get the solutions of $x^n-x-t=0$ in hypergeometric form?

and another answer that might be tailored to polynomials of the form:

$$x^n-x=s$$

The method in my answer below finds a differential equation and solves it instead of looking for the series but the series solution might be better in some cases as DSolve can be slow.

I should include given infinite time and memory.

I want to obtain exact solutions for polynomials with symbolic coefficients in Mathematica. I would like the solution to be a function. How can I do that ?

As an example I want to solve the sextic equation :

$$x^6 - x - z$$

and the quintic:

$$z - x + x^5$$

• Similar question here: mathematica.stackexchange.com/questions/98467/… Dec 20, 2022 at 3:14
• @GregHurst I did not see that one. I guess this is a duplicate then although the method is different. As Bob already has an answer I can not delete my answer and question and place it there so I will post that link in the question. Dec 20, 2022 at 3:17
• @GregHurst that method is very impressive. It solves the cubic in example 2 of my answer beautifully in terms of trig functions. Dec 20, 2022 at 3:53

Outline:

• Code

• Discussion on polynomial roots that do not involve radicals

• What is the point of getting an explicit function ?

• Explanation of code

• Examples

• Discussion about factoring and simplifying as a preprocessing step

• Other methods for solving

### Code :

(explanation of code below)

A solution in terms of hypergeometric functions for any z for the quintic :

Note: takes a while like around 3 minutes and leads to PossibleZeroQ errors which might be due to the fact that the coefficients of the differential equation can be large. Although the solution seemed ok one might want to divide the equation by a large numerical factor

sol = y[z] /.
DSolve[DifferentialRootReduce[Root[x |-> z - x + x^5 , 1], z][[0,
1]][y, z], y, z];

For this example, a simpler solution is found more easily with Greg Hurst's method that is linked in the question above. The expression is given in the "What is the point..." section.

check as an example :

Root[x |-> 1 - x + x^5 , 1] - (sol /. z -> 1) // N

(* {-1.77069*10^-10-4.81014*10^-11 I} *)

and a recurrence formula for the series coefficients of the sextic about z=1

Edit

I initially used :

Reap[SeriesCoefficient[
DifferentialRootReduce[Root[x |-> x^6 - x - z , 1], z], {z, 1,
n}] /. DifferenceRoot[e_] :> Sow[e[y, n]]][[2, 1, 1]]

then I realized that SeriesCoefficient[Root[x |-> z - x + x^6 , 1], {z, 0, n}] works directly. However, sometimes the expansion has to be about z=1 or else Mathematica fails which is seen from the initial conditions with the DifferentialRootReduce method but seems invisible when using root directly.

A full solution took too long (maybe I waited around an hour). Perhaps part of the difficulty is that the general solution is a two-variable generalization of the generalized hypergeometric series called a Kampé de Fériet function which might not be a function in Mathematica. I remember getting a full solution for a polynomial of degree 7 or 8 but I tried a degree 7 that crashed Mathematica.

### Discussion on polynomial roots that do not involve radicals

The Albert Rufini theorem 1 2 states (quoted from wikipedia):

the Abel–Ruffini theorem (also known as Abel's impossibility theorem) states that there is no solution in radicals to general polynomial equations of degree five or higher with arbitrary coefficients.

It seems somewhat common to misunderstand the theorem as stating one of the following:

• There are no exact solutions for polynomials of degree 5 or larger

• There are no exact solutions for polynomials of degree 5 or larger other than some special cases (Galois group is solvable)

But in fact it only says that there are no solutions in terms of (quote from [2]) :

a finite number of additions, subtractions, multiplications, divisions, and root extractions.

However, there are many more functions than those above. A typical example is given by the Bring radicals for solutions of the quintic given as hypergeometric function in wolfram alpha here (click exact forms).

There are many methods to find exact roots as shown in this section of the Bring radical page. There is also an article on arxiv (that I have not yet really read) that gives a continued fraction solution.

We will consider here the method of differential resolvents as it is a one liner in Mathematica.

### What is the point of getting an explicit function ?

Surprisingly (at least for me), not much ! Functions defined with Root mostly behave like any other function!

Nevertheless omitting functionality, explicit solutions can be good for having a clear idea what the function is in terms of other known functions rather than being a "new" function. Also, explicit solutions look better for presentations and convey the idea of a more deep understanding of the problem.

Here is the Hypergeometric solution found more easily with Greg Hurst's method of summing the series:

$$\frac{1}{32} t \left(5 t \left(\, _4F_3\left(\frac{9}{20},\frac{13}{20},\frac{17}{20},\frac{21}{20};\frac{3}{4},\frac{5}{4},\frac{3}{2};\frac{3125 t^4}{256}\right)-t \, _4F_3\left(\frac{7}{10},\frac{9}{10},\frac{11}{10},\frac{13}{10};\frac{5}{4},\frac{3}{2},\frac{7}{4};\frac{3125 t^4}{256}\right)\right)-8 \, _4F_3\left(\frac{1}{5},\frac{2}{5},\frac{3}{5},\frac{4}{5};\frac{1}{2},\frac{3}{4},\frac{5}{4};\frac{3125 t^4}{256}\right)\right)-\, _4F_3\left(-\frac{1}{20},\frac{3}{20},\frac{7}{20},\frac{11}{20};\frac{1}{4},\frac{1}{2},\frac{3}{4};\frac{3125 t^4}{256}\right)$$

That function will be denoted as f in the following.

Functions that work both for the explicit and Root function

FunctionSingularities[Root[x |-> x^5 - x + t, 1], t]

(* t^4 == 256/3125 *)

Plot[ {Root[x |-> x^5 - x + t, 1], f[t] - 1}, {t, 0, 10}]

(I shifted the exact solution so that they do not superimpose)

Note : the plot is fast both for the exact and Root solution

Asymptotic expansion at large t (also at small t as mentioned before for the sextic):

Series[Root[x |-> x^5 - x + t, 1], {t, Infinity, 2}]

$$-\sqrt[5]{t}-\frac{1}{5} \left(\frac{1}{t}\right)^{3/5}+\frac{1}{25} \left(\frac{1}{t}\right)^{7/5}+O\left(\left(\frac{1}{t}\right)^{11/5}\right)$$

D[Root[x |-> x^5 - x + t, 1], t]

Functions that work for the root solution but not the exact solution

(maybe if the solution is not in terms of hypergeometric functions then both will work)

FunctionSign[{s, t > 0}, t]

FunctionRange[{f[t], t > 0}, t, g]

FunctionConvexity[{Root[x |-> x^5 - x + t, 1], t > 0}, t]

Functions that work for the exact solution but not Root based solution:

Integrate[f[t], t]

Maybe FullSimplify in combination with other functions in an expression ?

MathematicalFunctionData works with explicit functions so one looses some general formulas when only working with Root objects.

Functions that worked for neither

FunctionMonotonicity[{Root[x |-> x^5 - x + t, 1], t > 0}, t]

### Explanation of code

The code relies on something magical that I recently found out which is that functions like Root[x |-> x^6 - x - z , 1] can be differentiated in Mathematica like any other function:

D[Root[x |-> x^6 - x - z , 1], z]

(* 1/(-1+6 Root[-z-#1+#1^6&,1]^5) *)

I suppose that D is using ImplicitD to do that but I do not know. The idea is then to make a linear differential equation that that function satisfies using DifferentialRootReduce and solve the differential equation either with DSolve or with SeriesCoefficient to get a series solution. That is the method of differential resolvent explained in the previous link given again here.

However note again that when using the SeriesCoefficient solution that one needs to check what the initial conditions are for the differential root and choose the expansion point for series to be the same as for the differential root. Mathematica might fail if you do not do that (at least when the initial conditions are given in terms of Root objects).

### Examples

Example 1: Hammer on mashed potatoes

We may start with something more classic like finding the roots of a quadratic polynomial with maybe an overly complicated method for this case:

Find the solution to

$$2 - x + x^2=0$$

DSolveValue[
DifferentialRootReduce[Root[z - # + #^2 &, 1], z][[0, 1]][y, z],
y[2], z]

$$\frac{1}{2} \left(1-i \sqrt{7}\right)$$

but Root[z - # + #^2 &, 1] is automatically evaluated to its form in terms of radicals so the method is not useful here.

Example 2: Beautifying solutions of the cubic

$$2 - x + x^3$$

DSolveValue[
DifferentialRootReduce[Root[z - # + #^3 &, 1], z][[0, 1]][y, z],
y[2], z] // ToRadicals // Simplify

$$\frac{\left(\left(4 \sqrt{23}-46 i\right) \sqrt[3]{27-3 \sqrt{69}}+\sqrt[3]{2} \left(207 i+46 \sqrt{3}-18 \sqrt{23}-23 i \sqrt{69}\right)\right) \sinh \left(\frac{2}{3} \left(\tanh ^{-1}\left(\frac{3 \sqrt{3}}{\sqrt{23}+2 i}\right)-\tanh ^{-1}\left(\frac{3 \sqrt{3}}{\sqrt{26}+i}\right)\right)\right)+\left(\left(-4 \sqrt{23}+46 i\right) \sqrt[3]{27-3 \sqrt{69}}+\sqrt[3]{2} \left(207 i+46 \sqrt{3}-18 \sqrt{23}-23 i \sqrt{69}\right)\right) \cosh \left(\frac{2}{3} \left(\tanh ^{-1}\left(\frac{3 \sqrt{3}}{\sqrt{23}+2 i}\right)-\tanh ^{-1}\left(\frac{3 \sqrt{3}}{\sqrt{26}+i}\right)\right)\right)}{\left(2 \sqrt{23}-23 i\right) \left(54-6 \sqrt{69}\right)^{2/3}}$$

Note that this solution automatically calls Trig functions which may be desirable in certain situations

Edit :

@GregHurst linked an alternative method (same link as in the original question) that sums a series and it works magnificently as shown here (the solution is nice even before applying full simplify):

root = Root[z - # + #^3 &, 1];
coeff = Refine[FunctionExpand[SeriesCoefficient[root, {z, 0, k}]],
k >= 0];
Sum[coeff t^k, {k, 0, ∞}] // FullSimplify

$$-\frac{\sin \left(\frac{1}{3} \sin ^{-1}\left(\frac{3 \sqrt{3} t}{2}\right)\right)}{\sqrt{3}}-\cos \left(\frac{1}{3} \sin ^{-1}\left(\frac{3 \sqrt{3} t}{2}\right)\right)$$

The solutions above can be compared with ToRadicals:

Root[t - # + #^3 &, 1] // ToRadicals // FullSimplify

$$\frac{\sqrt[3]{2} \left(\sqrt{81 t^2-12}-9 t\right)^{2/3}+2 \sqrt[3]{3}}{6^{2/3} \sqrt[3]{\sqrt{81 t^2-12}-9 t}}$$

Example 3: DSolve does not always solve the linear differential equation :(

This polynomial:

$$1 + 6 x - 12 x^2 - 32 x^3 + 16 x^4 + 32 x^5$$

was extracted from the polynomial of this question after using Factor

DSolve[DifferentialRootReduce[
Root[z + 6 # - 12 #^2 - 32 #^3 + 16 #^4 + 32 #^5 &, 1], z][[0,
1]][y, z], y, z];

is unable to find a solution after taking a long time. A series solution using FunctionExpand on the recurrence formula also fails to sum.

However, in principle one can convert the degree 5 polynomial above to the one in the question using the Tschirnhausen transformation in this section here. Tschirnhausen transformations can also simplify the $$X^{n-1}$$, $$X^{n-2}$$ and $$X^{n-3}$$ coefficients for general polynomials.

### Discussion about factoring and simplifying as a preprocessing step

The last example summarizes an important point which is that one should consider factoring (and extracting only the difficult factors) and simplifying the polynomial if the methods above do not work. For factorization one can factor out any factor in the polynomial that has a solvable Galois group. Unfortunately, Mathematica does not implement this extensively.

Magma seems to be able to find radical roots but I have not really tried. There is also a GAP package as this question shows https://math.stackexchange.com/q/4365625/1049002 but I have not tried.

I do not know if Maple can find roots by radicals.

This other answer is able to find some radical roots that Mathematica does not show but it can be slow and might not always work.

### Other methods for solving

First, Maple might be better at solving the differential equations but I do not have it at the moment.

One might also try mapping either the series expansion or the differential equation to that of an ansatz involving hypergeometric functions as in the answers of this question : How to convert this term to a Hypergeometric function?

One might also try the other methods article mentioned before in the discussion.

Consider also the methods linked in the original question given again here. The series expansion is fast and gives nice results but it does not always work (and neither does the differential equation method which has the disadvantage of being slow to decide whether it will work and does not provide compact results).

If all else fails there is also the possibility of rational/polynomial piecewise/global interpolations/fits as approximations.

Clear["Global`*"]

poly6 = x^6 - x - z;

The exact solutions as Root expressions

sol6 = Solve[poly6 == 0, x]

(* {{x -> Root[-z - #1 + #1^6 &, 1]},
{x -> Root[-z - #1 + #1^6 &, 2]},
{x -> Root[-z - #1 + #1^6 &, 3]},
{x -> Root[-z - #1 + #1^6 &, 4]},
{x -> Root[-z - #1 + #1^6 &, 5]},
{x -> Root[-z - #1 + #1^6 &, 6]}} *)

Verifying,

And @@ (poly6 == 0 /. sol6) // Simplify

(* True *)

For the special case when z == 0

sol6 /. z -> 0

(* {{x -> 0}, {x -> 1}, {x -> -(-1)^(1/5)}, {x -> (-1)^(4/5)},
{x -> -(-1)^(3/5)}, {x -> (-1)^(2/5)}} *)

Similarly,

poly5 = x^5 - x + z;

sol5 = Solve[poly5 == 0, x]

(* {{x -> Root[z - #1 + #1^5 &, 1]}, {x -> Root[z - #1 + #1^5 &, 2]},
{x -> Root[z - #1 + #1^5 &, 3]}, {x -> Root[z - #1 + #1^5 &, 4]},
{x -> Root[z - #1 + #1^5 &, 5]}} *)

And @@ (poly5 == 0 /. sol5) // Simplify

(* True *)

For the special case when z == 0

sol5 /. z -> 0

(* {{x -> -1}, {x -> 0}, {x -> 1}, {x -> -I}, {x -> I}} *)
• This answer made me wonder what really is gained by looking for explicit solutions rather than just sticking with Root objects. After testing different Mathematica functions on Root objects I am surprised how much Root objects behave like any other function (for example with FunctionRange, FunctionSingularities and large t expansions). I have included a "What is the point of getting an explicit function ?" section to compare what is gained and lost with explicit hypergeometric-like functions and Root based functions. Dec 20, 2022 at 11:01
• Unless one is a mathematician or encounters the functions routinely in one's work, the special functions (higher transcendental functions) are no more familiar nor convey any additional meaning than the word Root. Root functions are reasonably compact, and when given parameter values produce values and can be plotted. Dec 20, 2022 at 17:21
• Agreed other than for integration and simplifications in expressions using FullSimplify where an explicit solution might help. I learned quite a bit about how much one can do with just Root functions in the process and admire them more. Dec 20, 2022 at 18:40