| Alternative 1 | |
|---|---|
| Error | 99.5% |
| Cost | 7744.00 |
\[\frac{\frac{-0.5}{a} \cdot \left(a \cdot \left(c \cdot 4\right)\right)}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}
\]
(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 (* -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 (-2.0 * c) / (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(-2.0 * c) / 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[(-2.0 * c), $MachinePrecision] / N[(b + N[Sqrt[N[(c * N[(-4.0 * a), $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}{b + \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\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-rr17.9
Applied egg-rr18.3
Simplified18.4
[Start]18.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 [<=]18.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 [<=]18.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 [=>]18.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 [=>]18.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 [<=]18.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 [<=]18.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 [=>]18.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 [=>]18.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-rr18.4
Simplified99.5
[Start]18.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 [<=]18.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/ [=>]18.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)}}}
\] |
Taylor expanded in a around 0 99.9
Final simplification99.9
| Alternative 1 | |
|---|---|
| Error | 99.5% |
| Cost | 7744.00 |
| Alternative 2 | |
|---|---|
| Error | 95.5% |
| Cost | 1024.00 |
| Alternative 3 | |
|---|---|
| Error | 90.4% |
| Cost | 256.00 |
herbie shell --seed 2023093
(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)))