| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 7744 |
\[\frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + \sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)}}}{a \cdot 2}
\]
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c) :precision binary64 (/ (/ (* -4.0 (* c a)) (+ b (sqrt (fma c (* -4.0 a) (* 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 ((-4.0 * (c * a)) / (b + sqrt(fma(c, (-4.0 * a), (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(-4.0 * Float64(c * a)) / Float64(b + sqrt(fma(c, Float64(-4.0 * a), 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[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(c * N[(-4.0 * a), $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{-4 \cdot \left(c \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}}{a \cdot 2}
Initial program 17.8%
Applied egg-rr17.8%
[Start]17.8 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
sub-neg [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\color{blue}{b \cdot b + \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}
\] |
flip-+ [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\color{blue}{\frac{\left(b \cdot b\right) \cdot \left(b \cdot b\right) - \left(-\left(4 \cdot a\right) \cdot c\right) \cdot \left(-\left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}}{2 \cdot a}
\] |
pow2 [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{\color{blue}{{b}^{2}} \cdot \left(b \cdot b\right) - \left(-\left(4 \cdot a\right) \cdot c\right) \cdot \left(-\left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}
\] |
pow2 [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{2} \cdot \color{blue}{{b}^{2}} - \left(-\left(4 \cdot a\right) \cdot c\right) \cdot \left(-\left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}
\] |
pow-prod-up [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{\color{blue}{{b}^{\left(2 + 2\right)}} - \left(-\left(4 \cdot a\right) \cdot c\right) \cdot \left(-\left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}
\] |
metadata-eval [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{\color{blue}{4}} - \left(-\left(4 \cdot a\right) \cdot c\right) \cdot \left(-\left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}
\] |
*-commutative [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{4} - \left(-\color{blue}{c \cdot \left(4 \cdot a\right)}\right) \cdot \left(-\left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}
\] |
distribute-rgt-neg-in [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{4} - \color{blue}{\left(c \cdot \left(-4 \cdot a\right)\right)} \cdot \left(-\left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}
\] |
*-commutative [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{4} - \left(c \cdot \left(-\color{blue}{a \cdot 4}\right)\right) \cdot \left(-\left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}
\] |
distribute-rgt-neg-in [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{4} - \left(c \cdot \color{blue}{\left(a \cdot \left(-4\right)\right)}\right) \cdot \left(-\left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}
\] |
metadata-eval [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot \color{blue}{-4}\right)\right) \cdot \left(-\left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}
\] |
*-commutative [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(-\color{blue}{c \cdot \left(4 \cdot a\right)}\right)}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}
\] |
distribute-rgt-neg-in [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot -4\right)\right) \cdot \color{blue}{\left(c \cdot \left(-4 \cdot a\right)\right)}}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}
\] |
*-commutative [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(-\color{blue}{a \cdot 4}\right)\right)}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}
\] |
distribute-rgt-neg-in [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \color{blue}{\left(a \cdot \left(-4\right)\right)}\right)}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}
\] |
metadata-eval [=>]17.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot \color{blue}{-4}\right)\right)}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}
\] |
Applied egg-rr18.2%
[Start]17.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot -4\right)\right)}{b \cdot b - c \cdot \left(a \cdot -4\right)}}}{2 \cdot a}
\] |
|---|---|
+-commutative [=>]17.8 | \[ \frac{\color{blue}{\sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot -4\right)\right)}{b \cdot b - c \cdot \left(a \cdot -4\right)}} + \left(-b\right)}}{2 \cdot a}
\] |
flip-+ [=>]17.7 | \[ \frac{\color{blue}{\frac{\sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot -4\right)\right)}{b \cdot b - c \cdot \left(a \cdot -4\right)}} \cdot \sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot -4\right)\right)}{b \cdot b - c \cdot \left(a \cdot -4\right)}} - \left(-b\right) \cdot \left(-b\right)}{\sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot -4\right)\right)}{b \cdot b - c \cdot \left(a \cdot -4\right)}} - \left(-b\right)}}}{2 \cdot a}
\] |
Simplified18.3%
[Start]18.2 | \[ \frac{\frac{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) - b \cdot b}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]18.2 | \[ \frac{\frac{\color{blue}{\frac{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) - b \cdot b}{1}}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{2 \cdot a}
\] |
/-rgt-identity [=>]18.2 | \[ \frac{\frac{\color{blue}{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) - b \cdot b}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{2 \cdot a}
\] |
fma-def [<=]18.3 | \[ \frac{\frac{\color{blue}{\left(b \cdot b + c \cdot \left(a \cdot -4\right)\right)} - b \cdot b}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{2 \cdot a}
\] |
+-commutative [<=]18.3 | \[ \frac{\frac{\color{blue}{\left(c \cdot \left(a \cdot -4\right) + b \cdot b\right)} - b \cdot b}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{2 \cdot a}
\] |
fma-def [=>]18.3 | \[ \frac{\frac{\color{blue}{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} - b \cdot b}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{2 \cdot a}
\] |
fma-def [<=]18.3 | \[ \frac{\frac{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right) - b \cdot b}{b + \sqrt{\color{blue}{b \cdot b + c \cdot \left(a \cdot -4\right)}}}}{2 \cdot a}
\] |
+-commutative [<=]18.3 | \[ \frac{\frac{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right) - b \cdot b}{b + \sqrt{\color{blue}{c \cdot \left(a \cdot -4\right) + b \cdot b}}}}{2 \cdot a}
\] |
fma-def [=>]18.3 | \[ \frac{\frac{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right) - b \cdot b}{b + \sqrt{\color{blue}{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}}{2 \cdot a}
\] |
Taylor expanded in c around 0 99.4%
Final simplification99.4%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 7744 |
| Alternative 2 | |
|---|---|
| Accuracy | 95.2% |
| Cost | 7232 |
| Alternative 3 | |
|---|---|
| Accuracy | 95.1% |
| Cost | 576 |
| Alternative 4 | |
|---|---|
| Accuracy | 90.4% |
| Cost | 256 |
| Alternative 5 | |
|---|---|
| Accuracy | 1.7% |
| Cost | 192 |
herbie shell --seed 2023144
(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)))