| 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 (/ (* (/ -0.5 a) (* a (* c 4.0))) (+ b (sqrt (fma c (* a -4.0) (* 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 ((-0.5 / a) * (a * (c * 4.0))) / (b + sqrt(fma(c, (a * -4.0), (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(Float64(-0.5 / a) * Float64(a * Float64(c * 4.0))) / Float64(b + sqrt(fma(c, Float64(a * -4.0), 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[(N[(-0.5 / a), $MachinePrecision] * N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\frac{\frac{-0.5}{a} \cdot \left(a \cdot \left(c \cdot 4\right)\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}
Initial program 18.9%
Simplified18.9%
[Start]18.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]18.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
Applied egg-rr18.8%
[Start]18.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}
\] |
|---|---|
sub-neg [=>]18.9 | \[ \frac{\left(-b\right) + \sqrt{\color{blue}{b \cdot b + \left(-\left(4 \cdot a\right) \cdot c\right)}}}{a \cdot 2}
\] |
flip-+ [=>]18.9 | \[ \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)}}}}{a \cdot 2}
\] |
pow2 [=>]18.9 | \[ \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)}}}{a \cdot 2}
\] |
pow2 [=>]18.9 | \[ \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)}}}{a \cdot 2}
\] |
pow-sqr [=>]18.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{\color{blue}{{b}^{\left(2 \cdot 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)}}}{a \cdot 2}
\] |
metadata-eval [=>]18.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)}}}{a \cdot 2}
\] |
distribute-lft-neg-in [=>]18.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{4} - \color{blue}{\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)}}}{a \cdot 2}
\] |
distribute-lft-neg-in [=>]18.8 | \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{4} - \left(\left(-4 \cdot a\right) \cdot c\right) \cdot \color{blue}{\left(\left(-4 \cdot a\right) \cdot c\right)}}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{a \cdot 2}
\] |
*-commutative [=>]18.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)}}}{a \cdot 2}
\] |
*-commutative [=>]18.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)}}}{a \cdot 2}
\] |
distribute-rgt-neg-in [=>]18.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)}}}{a \cdot 2}
\] |
metadata-eval [=>]18.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)}}}{a \cdot 2}
\] |
*-commutative [=>]18.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)}}}{a \cdot 2}
\] |
*-commutative [=>]18.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)}}}{a \cdot 2}
\] |
distribute-rgt-neg-in [=>]18.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)}}}{a \cdot 2}
\] |
metadata-eval [=>]18.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)}}}{a \cdot 2}
\] |
Applied egg-rr19.3%
[Start]18.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)}}}{a \cdot 2}
\] |
|---|---|
+-commutative [=>]18.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)}}{a \cdot 2}
\] |
flip-+ [=>]18.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)}}}{a \cdot 2}
\] |
Simplified19.4%
[Start]19.3 | \[ \frac{\frac{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right) - b \cdot b}{b + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}}{a \cdot 2}
\] |
|---|---|
fma-def [<=]19.4 | \[ \frac{\frac{\color{blue}{\left(b \cdot b + -4 \cdot \left(c \cdot a\right)\right)} - b \cdot b}{b + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}}{a \cdot 2}
\] |
+-commutative [<=]19.4 | \[ \frac{\frac{\color{blue}{\left(-4 \cdot \left(c \cdot a\right) + b \cdot b\right)} - b \cdot b}{b + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}}{a \cdot 2}
\] |
*-commutative [=>]19.4 | \[ \frac{\frac{\left(\color{blue}{\left(c \cdot a\right) \cdot -4} + b \cdot b\right) - b \cdot b}{b + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}}{a \cdot 2}
\] |
fma-def [=>]19.4 | \[ \frac{\frac{\color{blue}{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)} - b \cdot b}{b + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}}{a \cdot 2}
\] |
fma-def [<=]19.4 | \[ \frac{\frac{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b}{b + \sqrt{\color{blue}{b \cdot b + -4 \cdot \left(c \cdot a\right)}}}}{a \cdot 2}
\] |
+-commutative [<=]19.4 | \[ \frac{\frac{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b}{b + \sqrt{\color{blue}{-4 \cdot \left(c \cdot a\right) + b \cdot b}}}}{a \cdot 2}
\] |
*-commutative [=>]19.4 | \[ \frac{\frac{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b}{b + \sqrt{\color{blue}{\left(c \cdot a\right) \cdot -4} + b \cdot b}}}{a \cdot 2}
\] |
fma-def [=>]19.4 | \[ \frac{\frac{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b}{b + \sqrt{\color{blue}{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}}}}{a \cdot 2}
\] |
Applied egg-rr19.4%
[Start]19.4 | \[ \frac{\frac{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b}{b + \sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}}}{a \cdot 2}
\] |
|---|---|
frac-2neg [=>]19.4 | \[ \color{blue}{\frac{-\frac{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b}{b + \sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}}}{-a \cdot 2}}
\] |
div-inv [=>]19.4 | \[ \color{blue}{\left(-\frac{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b}{b + \sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}}\right) \cdot \frac{1}{-a \cdot 2}}
\] |
distribute-neg-frac [=>]19.4 | \[ \color{blue}{\frac{-\left(\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b\right)}{b + \sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}}} \cdot \frac{1}{-a \cdot 2}
\] |
distribute-rgt-neg-in [=>]19.4 | \[ \frac{-\left(\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b\right)}{b + \sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}} \cdot \frac{1}{\color{blue}{a \cdot \left(-2\right)}}
\] |
metadata-eval [=>]19.4 | \[ \frac{-\left(\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b\right)}{b + \sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}} \cdot \frac{1}{a \cdot \color{blue}{-2}}
\] |
Simplified99.5%
[Start]19.4 | \[ \frac{-\left(\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b\right)}{b + \sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}} \cdot \frac{1}{a \cdot -2}
\] |
|---|---|
*-commutative [<=]19.4 | \[ \color{blue}{\frac{1}{a \cdot -2} \cdot \frac{-\left(\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b\right)}{b + \sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}}}
\] |
associate-*r/ [=>]19.4 | \[ \color{blue}{\frac{\frac{1}{a \cdot -2} \cdot \left(-\left(\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b\right)\right)}{b + \sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}}}
\] |
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 14016 |
| Alternative 2 | |
|---|---|
| Accuracy | 95.0% |
| Cost | 7232 |
| Alternative 3 | |
|---|---|
| Accuracy | 89.7% |
| Cost | 256 |
| Alternative 4 | |
|---|---|
| Accuracy | 1.7% |
| Cost | 192 |
herbie shell --seed 2023135
(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)))