4

There are exact (closed-form) solutions to polynomial equations of degree up to and including 4. I.e. there's a quadratic formula, a cubic formula and even a quartic formula.

Do any of the standard python packages (or even some non-standard ones) implement these? I can see that Numpy offers the ability to find polynomial roots (numpy.polynomial.polynomial.polyroots) but this routine appears to find the roots numerically via an eigenvalue method.

I'm not concerned about accuracy here (i.e. my issue with the Numpy routine is not that it will return floating point results when, perhaps, the answer is actually rational or integer in its real or imaginary parts).

I am concerned with speed. Is it reasonable to expect that a well-implemented cubic or quartic formula would return faster than the eigenvalue methods implemented by Numpy? I would have thought "yes". But I'm not 100% sure.

ali_m
  • 71,714
  • 23
  • 223
  • 298
8one6
  • 13,078
  • 12
  • 62
  • 84
  • You could implement them yourself: http://mathworld.wolfram.com/CubicFormula.html – MaxNoe Dec 08 '15 at 19:56
  • Yeah, I figured someone would say that. I can't imagine I'm the first person to want this. So wanted to give it a quick post to see if it was already there. DRY etc. – 8one6 Dec 08 '15 at 19:57
  • I think the reason why you haven't come across closed-form solutions is that they are rather tricky to implement in a numerically stable way - [*"The closed-form solutions for degrees three (cubic polynomial) and four (quartic polynomial) are complicated and require much more care; consequently, numerical methods such as Bairstow's method may be easier to use."*](https://en.wikipedia.org/wiki/Root-finding_algorithm#Finding_roots_of_polynomials) Of course, that doesn't mean it can't be done... – ali_m Dec 08 '15 at 20:12
  • 1
    Try sympy, symbolic expressions for python, I think I remember reading the code for these formulas there. – Lutz Lehmann Dec 09 '15 at 15:34

0 Answers0