File: quartic_roots.qbk

package info (click to toggle)
scipy 1.16.0-1exp7
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 234,820 kB
  • sloc: cpp: 503,145; python: 344,611; ansic: 195,638; javascript: 89,566; fortran: 56,210; cs: 3,081; f90: 1,150; sh: 848; makefile: 785; pascal: 284; csh: 135; lisp: 134; xml: 56; perl: 51
file content (40 lines) | stat: -rw-r--r-- 1,544 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
[/
Copyright (c) 2021 Nick Thompson
Use, modification and distribution are subject to the
Boost Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
]

[section:quartic_roots Roots of Quartic Polynomials]

[heading Synopsis]

```
#include <boost/math/tools/quartic_roots.hpp>

namespace boost::math::tools {

// Solves ax⁴ + bx³ + cx² + dx + e = 0.
std::array<Real,3> quartic_roots(Real a, Real b, Real c, Real d, Real e);

}
```

[heading Background]

The `quartic_roots` function extracts all real roots of a quartic polynomial ax⁴+ bx³ + cx² + dx + e.
The result is a `std::array<Real, 4>`, which has length four, irrespective of the number of real roots the polynomial possesses.
(This is to prevent the performance overhead of allocating a vector, which often exceeds the time to extract the roots.)
The roots are returned in nondecreasing order. If a root is complex, then it is placed at the back of the array and set to a nan.

The algorithm uses the classical method of Ferrari, and follows [@https://github.com/erich666/GraphicsGems/blob/master/gems/Roots3And4.c Graphics Gems V],
with an additional Halley iterate for root polishing.
A typical use of a quartic real-root solver is to raytrace a torus.

[heading Performance and Accuracy]

On a consumer laptop, we observe extraction of the roots taking ~90ns.
The file `reporting/performance/quartic_roots_performance.cpp` allows determination of the speed on your system.

[endsect]
[/section:quartic_roots]