| Alternative 1 | |
|---|---|
| Accuracy | 93.9% |
| Cost | 20736 |

(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 a) (* (pow (* a c) 4.0) (* 20.0 (pow b -7.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 / a), (pow((a * c), 4.0) * (20.0 * pow(b, -7.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 fma(Float64(-0.25 / a), Float64((Float64(a * c) ^ 4.0) * Float64(20.0 * (b ^ -7.0))), Float64(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 / a), $MachinePrecision] * N[(N[Power[N[(a * c), $MachinePrecision], 4.0], $MachinePrecision] * N[(20.0 * N[Power[b, -7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(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] - N[(N[(c / N[(N[Power[b, 3.0], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] * a + N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\mathsf{fma}\left(\frac{-0.25}{a}, {\left(a \cdot c\right)}^{4} \cdot \left(20 \cdot {b}^{-7}\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) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 33.1%
Simplified33.1%
[Start]33.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]33.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
+-commutative [=>]33.1 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}}{a \cdot 2}
\] |
unsub-neg [=>]33.1 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{a \cdot 2}
\] |
fma-neg [=>]33.1 | \[ \frac{\sqrt{\color{blue}{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}} - b}{a \cdot 2}
\] |
associate-*l* [=>]33.1 | \[ \frac{\sqrt{\mathsf{fma}\left(b, b, -\color{blue}{4 \cdot \left(a \cdot c\right)}\right)} - b}{a \cdot 2}
\] |
*-commutative [=>]33.1 | \[ \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 [=>]33.1 | \[ \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 [=>]33.1 | \[ \frac{\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot \color{blue}{-4}\right)} - b}{a \cdot 2}
\] |
Taylor expanded in b around inf 96.1%
Simplified96.1%
[Start]96.1 | \[ -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + \left(-0.25 \cdot \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right)
\] |
|---|---|
+-commutative [=>]96.1 | \[ \color{blue}{\left(-0.25 \cdot \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right) + -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}}
\] |
associate-+l+ [=>]96.1 | \[ \color{blue}{-0.25 \cdot \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(\left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right) + -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)}
\] |
associate-*r/ [=>]96.1 | \[ \color{blue}{\frac{-0.25 \cdot \left({\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)\right)}{a \cdot {b}^{7}}} + \left(\left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right) + -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)
\] |
times-frac [=>]96.1 | \[ \color{blue}{\frac{-0.25}{a} \cdot \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{{b}^{7}}} + \left(\left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right) + -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)
\] |
+-commutative [<=]96.1 | \[ \frac{-0.25}{a} \cdot \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{{b}^{7}} + \color{blue}{\left(-1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + \left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right)}
\] |
fma-def [=>]96.1 | \[ \color{blue}{\mathsf{fma}\left(\frac{-0.25}{a}, \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{{b}^{7}}, -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + \left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right)}
\] |
Applied egg-rr95.8%
[Start]96.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{\left({c}^{4} \cdot {a}^{4}\right) \cdot 20}{{b}^{7}}, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
|---|---|
expm1-log1p-u [=>]96.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\left({c}^{4} \cdot {a}^{4}\right) \cdot 20}{{b}^{7}}\right)\right)}, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
expm1-udef [=>]95.8 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \color{blue}{e^{\mathsf{log1p}\left(\frac{\left({c}^{4} \cdot {a}^{4}\right) \cdot 20}{{b}^{7}}\right)} - 1}, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
div-inv [=>]95.8 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, e^{\mathsf{log1p}\left(\color{blue}{\left(\left({c}^{4} \cdot {a}^{4}\right) \cdot 20\right) \cdot \frac{1}{{b}^{7}}}\right)} - 1, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
associate-*l* [=>]95.8 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, e^{\mathsf{log1p}\left(\color{blue}{\left({c}^{4} \cdot {a}^{4}\right) \cdot \left(20 \cdot \frac{1}{{b}^{7}}\right)}\right)} - 1, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
pow-prod-down [=>]95.8 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, e^{\mathsf{log1p}\left(\color{blue}{{\left(c \cdot a\right)}^{4}} \cdot \left(20 \cdot \frac{1}{{b}^{7}}\right)\right)} - 1, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
pow-flip [=>]95.8 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, e^{\mathsf{log1p}\left({\left(c \cdot a\right)}^{4} \cdot \left(20 \cdot \color{blue}{{b}^{\left(-7\right)}}\right)\right)} - 1, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
metadata-eval [=>]95.8 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, e^{\mathsf{log1p}\left({\left(c \cdot a\right)}^{4} \cdot \left(20 \cdot {b}^{\color{blue}{-7}}\right)\right)} - 1, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
Simplified96.1%
[Start]95.8 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, e^{\mathsf{log1p}\left({\left(c \cdot a\right)}^{4} \cdot \left(20 \cdot {b}^{-7}\right)\right)} - 1, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
|---|---|
expm1-def [=>]96.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(c \cdot a\right)}^{4} \cdot \left(20 \cdot {b}^{-7}\right)\right)\right)}, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
expm1-log1p [=>]96.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \color{blue}{{\left(c \cdot a\right)}^{4} \cdot \left(20 \cdot {b}^{-7}\right)}, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
Applied egg-rr96.1%
[Start]96.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, {\left(c \cdot a\right)}^{4} \cdot \left(20 \cdot {b}^{-7}\right), -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
|---|---|
div-inv [=>]96.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, {\left(c \cdot a\right)}^{4} \cdot \left(20 \cdot {b}^{-7}\right), -2 \cdot \left(\color{blue}{\left({c}^{3} \cdot \frac{1}{{b}^{5}}\right)} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
unpow3 [=>]96.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, {\left(c \cdot a\right)}^{4} \cdot \left(20 \cdot {b}^{-7}\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) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
associate-*l* [=>]96.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, {\left(c \cdot a\right)}^{4} \cdot \left(20 \cdot {b}^{-7}\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) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
pow-flip [=>]96.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, {\left(c \cdot a\right)}^{4} \cdot \left(20 \cdot {b}^{-7}\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) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
metadata-eval [=>]96.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, {\left(c \cdot a\right)}^{4} \cdot \left(20 \cdot {b}^{-7}\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) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
Final simplification96.1%
| Alternative 1 | |
|---|---|
| Accuracy | 93.9% |
| Cost | 20736 |
| Alternative 2 | |
|---|---|
| Accuracy | 90.6% |
| Cost | 7232 |
| Alternative 3 | |
|---|---|
| Accuracy | 90.2% |
| Cost | 1600 |
| Alternative 4 | |
|---|---|
| Accuracy | 81.1% |
| Cost | 256 |
| Alternative 5 | |
|---|---|
| Accuracy | 3.2% |
| Cost | 64 |
herbie shell --seed 2023160
(FPCore (a b c)
:name "Quadratic roots, medium range"
:precision binary64
:pre (and (and (and (< 1.1102230246251565e-16 a) (< a 9007199254740992.0)) (and (< 1.1102230246251565e-16 b) (< b 9007199254740992.0))) (and (< 1.1102230246251565e-16 c) (< c 9007199254740992.0)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))