| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 7808 |
\[\frac{\frac{\left(a \cdot c\right) \cdot 4}{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right) + b \cdot b}}}{2 \cdot a}
\]
(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 a) (* a c)) (- (- b) (sqrt (fma b b (* c (* a -4.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 ((2.0 / a) * (a * c)) / (-b - sqrt(fma(b, b, (c * (a * -4.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(2.0 / a) * Float64(a * c)) / Float64(Float64(-b) - sqrt(fma(b, b, Float64(c * Float64(a * -4.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[(2.0 / a), $MachinePrecision] * N[(a * c), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $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{2}{a} \cdot \left(a \cdot c\right)}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}
Initial program 17.9%
Simplified17.9%
[Start]17.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]17.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
Applied egg-rr18.4%
Simplified18.4%
[Start]18.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/ [=>]18.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 [<=]18.4 | \[ \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 [=>]18.4 | \[ \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 [=>]18.4 | \[ \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 [<=]18.4 | \[ \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 [=>]18.4 | \[ \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 [<=]18.4 | \[ \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 [=>]18.4 | \[ \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 [=>]18.4 | \[ \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.3%
Simplified99.5%
[Start]99.3 | \[ \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.3 | \[ \color{blue}{\frac{1}{a \cdot -2} \cdot \left(4 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right)}
\] |
*-commutative [=>]99.3 | \[ \frac{1}{\color{blue}{-2 \cdot a}} \cdot \left(4 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right)
\] |
associate-/r* [=>]99.3 | \[ \color{blue}{\frac{\frac{1}{-2}}{a}} \cdot \left(4 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right)
\] |
metadata-eval [=>]99.3 | \[ \frac{\color{blue}{-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)
\] |
metadata-eval [<=]99.3 | \[ \frac{\color{blue}{\frac{0.5}{-1}}}{a} \cdot \left(4 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}\right)
\] |
associate-/r* [<=]99.3 | \[ \color{blue}{\frac{0.5}{-1 \cdot a}} \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.3 | \[ \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.3 | \[ \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}}
\] |
associate-*r* [=>]99.3 | \[ \frac{\color{blue}{\left(\frac{0.5}{a} \cdot 4\right) \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}}{-1}
\] |
*-commutative [<=]99.3 | \[ \frac{\color{blue}{\left(4 \cdot \frac{0.5}{a}\right)} \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{-1}
\] |
/-rgt-identity [<=]99.3 | \[ \frac{\color{blue}{\frac{4 \cdot \frac{0.5}{a}}{1}} \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{-1}
\] |
associate-*r/ [=>]99.5 | \[ \frac{\color{blue}{\frac{\frac{4 \cdot \frac{0.5}{a}}{1} \cdot \left(c \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}}{-1}
\] |
/-rgt-identity [=>]99.5 | \[ \frac{\frac{\color{blue}{\left(4 \cdot \frac{0.5}{a}\right)} \cdot \left(c \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{-1}
\] |
associate-/l/ [=>]99.5 | \[ \color{blue}{\frac{\left(4 \cdot \frac{0.5}{a}\right) \cdot \left(c \cdot a\right)}{-1 \cdot \left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right)}}
\] |
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 7808 |
| Alternative 2 | |
|---|---|
| Accuracy | 95.4% |
| Cost | 7232 |
| Alternative 3 | |
|---|---|
| Accuracy | 95.2% |
| Cost | 1600 |
| Alternative 4 | |
|---|---|
| Accuracy | 95.1% |
| Cost | 1344 |
| Alternative 5 | |
|---|---|
| Accuracy | 90.4% |
| Cost | 256 |
| Alternative 6 | |
|---|---|
| Accuracy | 1.7% |
| Cost | 192 |
herbie shell --seed 2023122
(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)))