0
votes

When I solve for a high degree polynomial in Wolfram Mathamatica it returns a function with variable slots (the "#1"'s) in it, like this:

In[1]:= Solve[p^4 + 4*p^4 (1 - p) + 10*p^4*(1 - p)^2 + 20*p^5*(1 - p)^3 + (
40*p^6*(1 - p)^4)/(1 - 2*p*(1 - p)) == x && 0 < p < 1 && 0 < x < 1, p, Reals]
Out[1]:= {{p -> Root[x - 2 x #1 + 2 x #1^2 - 15 #1^4 + 34 #1^5 - 28 #1^6 + 
   8 #1^7 &, 2]}

How can I get it to give me the answer without the variable slots? It's not as if it needs more information, because if I assign a value to x it will evaluate the expression completely:

In[2]:= x=0.7
Out[2]:= 0.7
In[3]:= Root[x - 2 x #1 + 2 x #1^2 - 15 #1^4 + 34 #1^5 - 28 #1^6 + 8 #1^7 &, 2]
Out[3]:= 0.583356

The Mathematica help shows this syntax under the reference for Root[] but gives no explanation.

I need to use this result in terms of x in a VB program so I need to know how to get rid of the #1's. Any help would be greatly appreciated, thank you!

1

1 Answers

2
votes

This is more of a mathematical issue than a programming issue. The fact is that there are plenty of mathematical functions that have roots that cannot be expressed in closed form. The classic example is the Abel-Ruffini theorem, which states that the roots of the general polynomial of degree five or higher cannot be expressed in closed form. The need to express the roots of such a polynomial is the whole purpose of Mathematica's Root object. Here's a simple example:

roots = x /. Solve[x^5 - x - 1 == 0, x]
(* Out: 
  {Root[-1 - #1 + #1^5 &, 1], Root[-1 - #1 + #1^5 &, 2], 
   Root[-1 - #1 + #1^5 &, 3], Root[-1 - #1 + #1^5 &, 4], 
   Root[-1 - #1 + #1^5 &, 5]}
*)

These are exact representations of the roots of the polynomial. They can be estimated to whatever precision you want:

N[roots, 20]
(* Out:
  {1.1673039782614186843, 
   -0.76488443360058472603 - 0.35247154603172624932 I, 
   -0.76488443360058472603 + 0.35247154603172624932 I, 
    0.18123244446987538390 - 1.08395410131771066843 I, 
    0.18123244446987538390 + 1.08395410131771066843 I}
*)

Now, in your case, you are asking when a rational function of degree 7 in $p$ is equal to $x$. The answer is

Root[x - 2 x #1 + 2 x #1^2 - 15 #1^4 + 34 #1^5 - 28 #1^6 + 8 #1^7 &, 2]

This tells you that you need

x - 2 x p + 2 x p^2 - 15 p^4 + 34 p^5 - 28 p^6 + 8 p^7 = 0

and there is no simpler closed form. Now, if you set x=0.7, or some other decimal approximation, then you'll get a numerical estimate that's good for that particular x value. It's still not a closed form, though. For comparison, try x=7/10. You should get

x=7/10
Root[7 - 14 #1 + 14 #1^2 - 150 #1^4 + 340 #1^5 - 280 #1^6 + 80 #1^7 &, 2]

Now, you could certainly write a function f using the Root object to help you explore what's going on.

f[x_] = Root[x - 2 x #1 + 2 x #1^2 - 15 #1^4 + 34 #1^5 - 28 #1^6 + 8 #1^7 &,2];
f[0.7]
(* Out: 0.583356  *)

You can even plot it.

Plot[f[x], {x, 0, 1}]

enter image description here