| Alternative 1 | |
|---|---|
| Accuracy | 89.6% |
| Cost | 28164 |

(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c) :precision binary64 (- (fma -0.25 (* (/ (pow a 3.0) b) (* (* (* c c) (* (* c c) (pow b -6.0))) 20.0)) (* -2.0 (* (* (* c c) (* c (pow b -5.0))) (* a a)))) (fma (/ c (/ (pow b 3.0) c)) a (/ c b))))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
double code(double a, double b, double c) {
return fma(-0.25, ((pow(a, 3.0) / b) * (((c * c) * ((c * c) * pow(b, -6.0))) * 20.0)), (-2.0 * (((c * c) * (c * pow(b, -5.0))) * (a * a)))) - fma((c / (pow(b, 3.0) / c)), a, (c / b));
}
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function code(a, b, c) return Float64(fma(-0.25, Float64(Float64((a ^ 3.0) / b) * Float64(Float64(Float64(c * c) * Float64(Float64(c * c) * (b ^ -6.0))) * 20.0)), Float64(-2.0 * Float64(Float64(Float64(c * c) * Float64(c * (b ^ -5.0))) * Float64(a * a)))) - fma(Float64(c / Float64((b ^ 3.0) / c)), a, Float64(c / b))) end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := N[(N[(-0.25 * N[(N[(N[Power[a, 3.0], $MachinePrecision] / b), $MachinePrecision] * N[(N[(N[(c * c), $MachinePrecision] * N[(N[(c * c), $MachinePrecision] * N[Power[b, -6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 20.0), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * N[(N[(N[(c * c), $MachinePrecision] * N[(c * N[Power[b, -5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(c / N[(N[Power[b, 3.0], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] * a + N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\left(\left(c \cdot c\right) \cdot \left(\left(c \cdot c\right) \cdot {b}^{-6}\right)\right) \cdot 20\right), -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 54.3%
Simplified54.4%
[Start]54.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]54.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
+-commutative [=>]54.3 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}}{a \cdot 2}
\] |
unsub-neg [=>]54.3 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{a \cdot 2}
\] |
fma-neg [=>]54.4 | \[ \frac{\sqrt{\color{blue}{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}} - b}{a \cdot 2}
\] |
associate-*l* [=>]54.4 | \[ \frac{\sqrt{\mathsf{fma}\left(b, b, -\color{blue}{4 \cdot \left(a \cdot c\right)}\right)} - b}{a \cdot 2}
\] |
*-commutative [=>]54.4 | \[ \frac{\sqrt{\mathsf{fma}\left(b, b, -\color{blue}{\left(a \cdot c\right) \cdot 4}\right)} - b}{a \cdot 2}
\] |
distribute-rgt-neg-in [=>]54.4 | \[ \frac{\sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(a \cdot c\right) \cdot \left(-4\right)}\right)} - b}{a \cdot 2}
\] |
metadata-eval [=>]54.4 | \[ \frac{\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot \color{blue}{-4}\right)} - b}{a \cdot 2}
\] |
Taylor expanded in a around 0 92.6%
Simplified92.6%
[Start]92.6 | \[ -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + \left(-1 \cdot \frac{c}{b} + \left(-0.25 \cdot \frac{{a}^{3} \cdot \left(16 \cdot \frac{{c}^{4}}{{b}^{6}} + {\left(-2 \cdot \frac{{c}^{2}}{{b}^{3}}\right)}^{2}\right)}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right)
\] |
|---|---|
associate-+r+ [=>]92.6 | \[ \color{blue}{\left(-1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + -1 \cdot \frac{c}{b}\right) + \left(-0.25 \cdot \frac{{a}^{3} \cdot \left(16 \cdot \frac{{c}^{4}}{{b}^{6}} + {\left(-2 \cdot \frac{{c}^{2}}{{b}^{3}}\right)}^{2}\right)}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)}
\] |
+-commutative [=>]92.6 | \[ \color{blue}{\left(-0.25 \cdot \frac{{a}^{3} \cdot \left(16 \cdot \frac{{c}^{4}}{{b}^{6}} + {\left(-2 \cdot \frac{{c}^{2}}{{b}^{3}}\right)}^{2}\right)}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right) + \left(-1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + -1 \cdot \frac{c}{b}\right)}
\] |
distribute-lft-out [=>]92.6 | \[ \left(-0.25 \cdot \frac{{a}^{3} \cdot \left(16 \cdot \frac{{c}^{4}}{{b}^{6}} + {\left(-2 \cdot \frac{{c}^{2}}{{b}^{3}}\right)}^{2}\right)}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right) + \color{blue}{-1 \cdot \left(\frac{{c}^{2} \cdot a}{{b}^{3}} + \frac{c}{b}\right)}
\] |
mul-1-neg [=>]92.6 | \[ \left(-0.25 \cdot \frac{{a}^{3} \cdot \left(16 \cdot \frac{{c}^{4}}{{b}^{6}} + {\left(-2 \cdot \frac{{c}^{2}}{{b}^{3}}\right)}^{2}\right)}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right) + \color{blue}{\left(-\left(\frac{{c}^{2} \cdot a}{{b}^{3}} + \frac{c}{b}\right)\right)}
\] |
unsub-neg [=>]92.6 | \[ \color{blue}{\left(-0.25 \cdot \frac{{a}^{3} \cdot \left(16 \cdot \frac{{c}^{4}}{{b}^{6}} + {\left(-2 \cdot \frac{{c}^{2}}{{b}^{3}}\right)}^{2}\right)}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right) - \left(\frac{{c}^{2} \cdot a}{{b}^{3}} + \frac{c}{b}\right)}
\] |
Applied egg-rr92.6%
[Start]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\frac{{c}^{4}}{{b}^{6}} \cdot 20\right), -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
|---|---|
div-inv [=>]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\frac{{c}^{4}}{{b}^{6}} \cdot 20\right), -2 \cdot \left(\color{blue}{\left({c}^{3} \cdot \frac{1}{{b}^{5}}\right)} \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
unpow3 [=>]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\frac{{c}^{4}}{{b}^{6}} \cdot 20\right), -2 \cdot \left(\left(\color{blue}{\left(\left(c \cdot c\right) \cdot c\right)} \cdot \frac{1}{{b}^{5}}\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
associate-*l* [=>]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\frac{{c}^{4}}{{b}^{6}} \cdot 20\right), -2 \cdot \left(\color{blue}{\left(\left(c \cdot c\right) \cdot \left(c \cdot \frac{1}{{b}^{5}}\right)\right)} \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
pow-flip [=>]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\frac{{c}^{4}}{{b}^{6}} \cdot 20\right), -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot \color{blue}{{b}^{\left(-5\right)}}\right)\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
metadata-eval [=>]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\frac{{c}^{4}}{{b}^{6}} \cdot 20\right), -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{\color{blue}{-5}}\right)\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
Applied egg-rr92.6%
[Start]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\frac{{c}^{4}}{{b}^{6}} \cdot 20\right), -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
|---|---|
div-inv [=>]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\color{blue}{\left({c}^{4} \cdot \frac{1}{{b}^{6}}\right)} \cdot 20\right), -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
metadata-eval [<=]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\left({c}^{\color{blue}{\left(2 + 2\right)}} \cdot \frac{1}{{b}^{6}}\right) \cdot 20\right), -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
metadata-eval [<=]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\left({c}^{\left(\color{blue}{\sqrt{4}} + 2\right)} \cdot \frac{1}{{b}^{6}}\right) \cdot 20\right), -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
metadata-eval [<=]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\left({c}^{\left(\sqrt{4} + \color{blue}{\sqrt{4}}\right)} \cdot \frac{1}{{b}^{6}}\right) \cdot 20\right), -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
pow-prod-up [<=]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\left(\color{blue}{\left({c}^{\left(\sqrt{4}\right)} \cdot {c}^{\left(\sqrt{4}\right)}\right)} \cdot \frac{1}{{b}^{6}}\right) \cdot 20\right), -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
pow-prod-down [=>]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\left(\color{blue}{{\left(c \cdot c\right)}^{\left(\sqrt{4}\right)}} \cdot \frac{1}{{b}^{6}}\right) \cdot 20\right), -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
metadata-eval [=>]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\left({\left(c \cdot c\right)}^{\color{blue}{2}} \cdot \frac{1}{{b}^{6}}\right) \cdot 20\right), -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
pow2 [<=]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\left(\color{blue}{\left(\left(c \cdot c\right) \cdot \left(c \cdot c\right)\right)} \cdot \frac{1}{{b}^{6}}\right) \cdot 20\right), -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
associate-*l* [=>]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\color{blue}{\left(\left(c \cdot c\right) \cdot \left(\left(c \cdot c\right) \cdot \frac{1}{{b}^{6}}\right)\right)} \cdot 20\right), -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
pow-flip [=>]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\left(\left(c \cdot c\right) \cdot \left(\left(c \cdot c\right) \cdot \color{blue}{{b}^{\left(-6\right)}}\right)\right) \cdot 20\right), -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
metadata-eval [=>]92.6 | \[ \mathsf{fma}\left(-0.25, \frac{{a}^{3}}{b} \cdot \left(\left(\left(c \cdot c\right) \cdot \left(\left(c \cdot c\right) \cdot {b}^{\color{blue}{-6}}\right)\right) \cdot 20\right), -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) \cdot \left(a \cdot a\right)\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)
\] |
Final simplification92.6%
| Alternative 1 | |
|---|---|
| Accuracy | 89.6% |
| Cost | 28164 |
| Alternative 2 | |
|---|---|
| Accuracy | 85.1% |
| Cost | 13764 |
| Alternative 3 | |
|---|---|
| Accuracy | 85.1% |
| Cost | 7492 |
| Alternative 4 | |
|---|---|
| Accuracy | 82.1% |
| Cost | 576 |
| Alternative 5 | |
|---|---|
| Accuracy | 64.4% |
| Cost | 256 |
| Alternative 6 | |
|---|---|
| Accuracy | 1.6% |
| Cost | 192 |
herbie shell --seed 2023163
(FPCore (a b c)
:name "Quadratic roots, narrow range"
:precision binary64
:pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))