| Alternative 1 | |
|---|---|
| Accuracy | 95.6% |
| Cost | 1024 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c) :precision binary64 (* (* c -4.0) (/ 0.5 (+ b (sqrt (fma c (* -4.0 a) (* b 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 (c * -4.0) * (0.5 / (b + sqrt(fma(c, (-4.0 * a), (b * 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(Float64(c * -4.0) * Float64(0.5 / Float64(b + sqrt(fma(c, Float64(-4.0 * a), Float64(b * 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[(c * -4.0), $MachinePrecision] * N[(0.5 / N[(b + N[Sqrt[N[(c * N[(-4.0 * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\left(c \cdot -4\right) \cdot \frac{0.5}{b + \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}
Initial program 17.5%
Simplified17.5%
[Start]17.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]17.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
Applied egg-rr17.9%
[Start]17.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}
\] |
|---|---|
+-commutative [=>]17.5 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}}{a \cdot 2}
\] |
flip-+ [=>]17.5 | \[ \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 [<=]18.0 | \[ \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 [=>]18.0 | \[ \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- [=>]18.0 | \[ \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 [<=]18.0 | \[ \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 [=>]17.9 | \[ \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* [=>]17.9 | \[ \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.4 | \[ \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.4 | \[ \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.4 | \[ \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.4 | \[ \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.4 | \[ \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}
\] |
Simplified17.9%
[Start]17.9 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2}
\] |
|---|---|
*-commutative [=>]17.9 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \color{blue}{\left(c \cdot a\right)}\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2}
\] |
*-commutative [=>]17.9 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \color{blue}{\left(c \cdot a\right) \cdot 4}\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2}
\] |
fma-def [<=]17.9 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\color{blue}{b \cdot b + c \cdot \left(a \cdot -4\right)}}}}{a \cdot 2}
\] |
+-commutative [=>]17.9 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\color{blue}{c \cdot \left(a \cdot -4\right) + b \cdot b}}}}{a \cdot 2}
\] |
fma-def [=>]17.9 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\color{blue}{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}}{a \cdot 2}
\] |
Applied egg-rr8.1%
[Start]17.9 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{a \cdot 2}
\] |
|---|---|
expm1-log1p-u [=>]11.9 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{a \cdot 2}\right)\right)}
\] |
expm1-udef [=>]8.1 | \[ \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{a \cdot 2}\right)} - 1}
\] |
associate-/l/ [=>]8.1 | \[ e^{\mathsf{log1p}\left(\color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{\left(a \cdot 2\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right)}}\right)} - 1
\] |
associate-*l* [=>]8.1 | \[ e^{\mathsf{log1p}\left(\frac{b \cdot b - \mathsf{fma}\left(b, b, \color{blue}{c \cdot \left(a \cdot 4\right)}\right)}{\left(a \cdot 2\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right)}\right)} - 1
\] |
*-commutative [=>]8.1 | \[ e^{\mathsf{log1p}\left(\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{\color{blue}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}}\right)} - 1
\] |
Simplified99.4%
[Start]8.1 | \[ e^{\mathsf{log1p}\left(\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}\right)} - 1
\] |
|---|---|
expm1-def [=>]11.9 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}\right)\right)}
\] |
expm1-log1p [=>]17.9 | \[ \color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}}
\] |
associate-/r* [=>]17.9 | \[ \color{blue}{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{a \cdot 2}}
\] |
associate-/r* [=>]17.9 | \[ \color{blue}{\frac{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{a}}{2}}
\] |
*-lft-identity [<=]17.9 | \[ \frac{\frac{\frac{\color{blue}{1 \cdot \left(b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)\right)}}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{a}}{2}
\] |
associate-*l/ [<=]17.9 | \[ \frac{\frac{\color{blue}{\frac{1}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}} \cdot \left(b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)\right)}}{a}}{2}
\] |
*-commutative [<=]17.9 | \[ \frac{\frac{\color{blue}{\left(b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)\right) \cdot \frac{1}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}}{a}}{2}
\] |
associate-*l/ [<=]17.9 | \[ \frac{\color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{a} \cdot \frac{1}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}}{2}
\] |
associate-*r/ [<=]17.9 | \[ \color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{a} \cdot \frac{\frac{1}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{2}}
\] |
Taylor expanded in c around 0 99.5%
Simplified99.5%
[Start]99.5 | \[ \left(-4 \cdot c\right) \cdot \frac{0.5}{b + \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}
\] |
|---|---|
*-commutative [=>]99.5 | \[ \color{blue}{\left(c \cdot -4\right)} \cdot \frac{0.5}{b + \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}
\] |
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 95.6% |
| Cost | 1024 |
| Alternative 2 | |
|---|---|
| Accuracy | 90.7% |
| Cost | 256 |
herbie shell --seed 2023136
(FPCore (a b c)
:name "Quadratic roots, wide range"
:precision binary64
:pre (and (and (and (< 4.930380657631324e-32 a) (< a 2.028240960365167e+31)) (and (< 4.930380657631324e-32 b) (< b 2.028240960365167e+31))) (and (< 4.930380657631324e-32 c) (< c 2.028240960365167e+31)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))