| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 14016 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c) :precision binary64 (/ (/ (* c (* a -4.0)) (+ b (sqrt (fma c (* a -4.0) (* b b))))) (* a 2.0)))
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 ((c * (a * -4.0)) / (b + sqrt(fma(c, (a * -4.0), (b * b))))) / (a * 2.0);
}
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(Float64(Float64(c * Float64(a * -4.0)) / Float64(b + sqrt(fma(c, Float64(a * -4.0), Float64(b * b))))) / Float64(a * 2.0)) 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[(N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\frac{\frac{c \cdot \left(a \cdot -4\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{a \cdot 2}
Initial program 31.6%
Simplified31.6%
[Start]31.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]31.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
Applied egg-rr32.4%
[Start]31.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}
\] |
|---|---|
+-commutative [=>]31.6 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}}{a \cdot 2}
\] |
flip-+ [=>]31.6 | \[ \frac{\color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right) \cdot \left(-b\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right)}}}{a \cdot 2}
\] |
add-sqr-sqrt [<=]32.5 | \[ \frac{\frac{\color{blue}{\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)} - \left(-b\right) \cdot \left(-b\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right)}}{a \cdot 2}
\] |
sqr-neg [=>]32.5 | \[ \frac{\frac{\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right) - \color{blue}{b \cdot b}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right)}}{a \cdot 2}
\] |
associate--l- [=>]32.5 | \[ \frac{\frac{\color{blue}{b \cdot b - \left(\left(4 \cdot a\right) \cdot c + b \cdot b\right)}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right)}}{a \cdot 2}
\] |
+-commutative [<=]32.5 | \[ \frac{\frac{b \cdot b - \color{blue}{\left(b \cdot b + \left(4 \cdot a\right) \cdot c\right)}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right)}}{a \cdot 2}
\] |
fma-def [=>]32.4 | \[ \frac{\frac{b \cdot b - \color{blue}{\mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right)}}{a \cdot 2}
\] |
associate-*l* [=>]32.4 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \color{blue}{4 \cdot \left(a \cdot c\right)}\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right)}}{a \cdot 2}
\] |
add-sqr-sqrt [=>]0.0 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \color{blue}{\sqrt{-b} \cdot \sqrt{-b}}}}{a \cdot 2}
\] |
sqrt-unprod [=>]0.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right)}}}}{a \cdot 2}
\] |
sqr-neg [=>]0.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \sqrt{\color{blue}{b \cdot b}}}}{a \cdot 2}
\] |
sqrt-prod [=>]1.6 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \color{blue}{\sqrt{b} \cdot \sqrt{b}}}}{a \cdot 2}
\] |
add-sqr-sqrt [<=]0.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \color{blue}{b}}}{a \cdot 2}
\] |
unsub-neg [<=]0.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}}}{a \cdot 2}
\] |
+-commutative [<=]0.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\color{blue}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{a \cdot 2}
\] |
Taylor expanded in b around 0 99.4%
Simplified99.4%
[Start]99.4 | \[ \frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2}
\] |
|---|---|
*-commutative [=>]99.4 | \[ \frac{\frac{\color{blue}{\left(c \cdot a\right) \cdot -4}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2}
\] |
associate-*r* [<=]99.4 | \[ \frac{\frac{\color{blue}{c \cdot \left(a \cdot -4\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2}
\] |
Applied egg-rr99.2%
[Start]99.4 | \[ \frac{\frac{c \cdot \left(a \cdot -4\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2}
\] |
|---|---|
pow1/2 [=>]99.4 | \[ \frac{\frac{c \cdot \left(a \cdot -4\right)}{b + \color{blue}{{\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{0.5}}}}{a \cdot 2}
\] |
sqr-pow [=>]99.2 | \[ \frac{\frac{c \cdot \left(a \cdot -4\right)}{b + \color{blue}{{\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{\left(\frac{0.5}{2}\right)} \cdot {\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{\left(\frac{0.5}{2}\right)}}}}{a \cdot 2}
\] |
metadata-eval [=>]99.2 | \[ \frac{\frac{c \cdot \left(a \cdot -4\right)}{b + {\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{\color{blue}{0.25}} \cdot {\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{\left(\frac{0.5}{2}\right)}}}{a \cdot 2}
\] |
metadata-eval [=>]99.2 | \[ \frac{\frac{c \cdot \left(a \cdot -4\right)}{b + {\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{0.25} \cdot {\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{\color{blue}{0.25}}}}{a \cdot 2}
\] |
Simplified99.4%
[Start]99.2 | \[ \frac{\frac{c \cdot \left(a \cdot -4\right)}{b + {\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{0.25} \cdot {\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{0.25}}}{a \cdot 2}
\] |
|---|---|
pow-sqr [=>]99.4 | \[ \frac{\frac{c \cdot \left(a \cdot -4\right)}{b + \color{blue}{{\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{\left(2 \cdot 0.25\right)}}}}{a \cdot 2}
\] |
metadata-eval [=>]99.4 | \[ \frac{\frac{c \cdot \left(a \cdot -4\right)}{b + {\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{\color{blue}{0.5}}}}{a \cdot 2}
\] |
unpow1/2 [=>]99.4 | \[ \frac{\frac{c \cdot \left(a \cdot -4\right)}{b + \color{blue}{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
fma-def [<=]99.4 | \[ \frac{\frac{c \cdot \left(a \cdot -4\right)}{b + \sqrt{\color{blue}{b \cdot b + c \cdot \left(a \cdot -4\right)}}}}{a \cdot 2}
\] |
+-commutative [=>]99.4 | \[ \frac{\frac{c \cdot \left(a \cdot -4\right)}{b + \sqrt{\color{blue}{c \cdot \left(a \cdot -4\right) + b \cdot b}}}}{a \cdot 2}
\] |
fma-def [=>]99.4 | \[ \frac{\frac{c \cdot \left(a \cdot -4\right)}{b + \sqrt{\color{blue}{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}}{a \cdot 2}
\] |
Final simplification99.4%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 14016 |
| Alternative 2 | |
|---|---|
| Accuracy | 93.8% |
| Cost | 8448 |
| Alternative 3 | |
|---|---|
| Accuracy | 90.7% |
| Cost | 1344 |
| Alternative 4 | |
|---|---|
| Accuracy | 90.7% |
| Cost | 1024 |
| Alternative 5 | |
|---|---|
| Accuracy | 81.2% |
| Cost | 256 |
| Alternative 6 | |
|---|---|
| Accuracy | 1.6% |
| Cost | 192 |
herbie shell --seed 2023131
(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)))