| Alternative 1 | |
|---|---|
| Accuracy | 91.0% |
| Cost | 14788 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c) :precision binary64 (/ (* 2.0 c) (- (- 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 (2.0 * c) / (-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(2.0 * c) / Float64(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[(2.0 * c), $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{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}
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}
\] |
|---|---|
flip-+ [=>]31.6 | \[ \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \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) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{a \cdot 2}
\] |
sub-neg [=>]31.6 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\left(-b\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}{a \cdot 2}
\] |
add-sqr-sqrt [=>]31.6 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-\color{blue}{\sqrt{b} \cdot \sqrt{b}}\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{a \cdot 2}
\] |
sqrt-prod [<=]31.6 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-\color{blue}{\sqrt{b \cdot b}}\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{a \cdot 2}
\] |
sqr-neg [<=]31.6 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-\sqrt{\color{blue}{\left(-b\right) \cdot \left(-b\right)}}\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{a \cdot 2}
\] |
sqrt-unprod [<=]0.0 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-\color{blue}{\sqrt{-b} \cdot \sqrt{-b}}\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{a \cdot 2}
\] |
add-sqr-sqrt [<=]0.8 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-\color{blue}{\left(-b\right)}\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{a \cdot 2}
\] |
distribute-neg-in [<=]0.8 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{-\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}{a \cdot 2}
\] |
add-sqr-sqrt [=>]0.0 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{-\color{blue}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}}{a \cdot 2}
\] |
distribute-rgt-neg-in [=>]0.0 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \left(-\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right)}}}{a \cdot 2}
\] |
Simplified32.5%
[Start]32.4 | \[ \frac{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
|---|---|
associate-/l/ [=>]32.4 | \[ \frac{\color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}}{a \cdot 2}
\] |
fma-def [<=]32.5 | \[ \frac{\frac{b \cdot b - \color{blue}{\left(b \cdot b + c \cdot \left(a \cdot -4\right)\right)}}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
+-commutative [=>]32.5 | \[ \frac{\frac{b \cdot b - \color{blue}{\left(c \cdot \left(a \cdot -4\right) + b \cdot b\right)}}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
fma-def [=>]32.5 | \[ \frac{\frac{b \cdot b - \color{blue}{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
distribute-lft-neg-in [<=]32.5 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}{\color{blue}{-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}} \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}}{a \cdot 2}
\] |
rem-square-sqrt [=>]32.5 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}{-\color{blue}{\left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}\right)}}}{a \cdot 2}
\] |
fma-def [<=]32.5 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}{-\left(b + \sqrt{\color{blue}{b \cdot b + c \cdot \left(a \cdot -4\right)}}\right)}}{a \cdot 2}
\] |
+-commutative [=>]32.5 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}{-\left(b + \sqrt{\color{blue}{c \cdot \left(a \cdot -4\right) + b \cdot b}}\right)}}{a \cdot 2}
\] |
fma-def [=>]32.5 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}{-\left(b + \sqrt{\color{blue}{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right)}}{a \cdot 2}
\] |
Taylor expanded in b around 0 99.4%
Applied egg-rr99.2%
[Start]99.4 | \[ \frac{\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right)}}{a \cdot 2}
\] |
|---|---|
frac-2neg [=>]99.4 | \[ \color{blue}{\frac{-\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right)}}{-a \cdot 2}}
\] |
div-inv [=>]99.2 | \[ \color{blue}{\left(-\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right)}\right) \cdot \frac{1}{-a \cdot 2}}
\] |
Simplified99.4%
[Start]99.2 | \[ \left(4 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right) \cdot \frac{1}{a \cdot -2}
\] |
|---|---|
*-commutative [=>]99.2 | \[ \left(4 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right) \cdot \frac{1}{\color{blue}{-2 \cdot a}}
\] |
associate-/r* [=>]99.2 | \[ \left(4 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right) \cdot \color{blue}{\frac{\frac{1}{-2}}{a}}
\] |
metadata-eval [=>]99.2 | \[ \left(4 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right) \cdot \frac{\color{blue}{-0.5}}{a}
\] |
metadata-eval [<=]99.2 | \[ \left(4 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right) \cdot \frac{\color{blue}{\frac{0.5}{-1}}}{a}
\] |
associate-/r* [<=]99.2 | \[ \left(4 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right) \cdot \color{blue}{\frac{0.5}{-1 \cdot a}}
\] |
associate-/l/ [<=]99.2 | \[ \left(4 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right) \cdot \color{blue}{\frac{\frac{0.5}{a}}{-1}}
\] |
*-commutative [<=]99.2 | \[ \color{blue}{\frac{\frac{0.5}{a}}{-1} \cdot \left(4 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right)}
\] |
associate-*l/ [=>]99.2 | \[ \color{blue}{\frac{\frac{0.5}{a} \cdot \left(4 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right)}{-1}}
\] |
metadata-eval [<=]99.2 | \[ \frac{\frac{0.5}{a} \cdot \left(4 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right)}{\color{blue}{-1 \cdot 1}}
\] |
associate-/l/ [<=]99.2 | \[ \color{blue}{\frac{\frac{\frac{0.5}{a} \cdot \left(4 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right)}{1}}{-1}}
\] |
Taylor expanded in a around 0 99.7%
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 91.0% |
| Cost | 14788 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 7680 |
| Alternative 3 | |
|---|---|
| Accuracy | 90.8% |
| Cost | 1216 |
| Alternative 4 | |
|---|---|
| Accuracy | 90.8% |
| Cost | 1024 |
| Alternative 5 | |
|---|---|
| Accuracy | 81.2% |
| Cost | 256 |
herbie shell --seed 2023135
(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)))