| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 14016 |
\[\frac{\frac{c \cdot \left(-4 \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\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 (* 0.5 (/ (/ (+ (* c (* -4.0 a)) (* 0.0 (* b b))) a) (+ 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 0.5 * ((((c * (-4.0 * a)) + (0.0 * (b * b))) / a) / (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(0.5 * Float64(Float64(Float64(Float64(c * Float64(-4.0 * a)) + Float64(0.0 * Float64(b * b))) / a) / 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[(0.5 * N[(N[(N[(N[(c * N[(-4.0 * a), $MachinePrecision]), $MachinePrecision] + N[(0.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision] / N[(b + N[Sqrt[N[(c * N[(-4.0 * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
0.5 \cdot \frac{\frac{c \cdot \left(-4 \cdot a\right) + 0 \cdot \left(b \cdot b\right)}{a}}{b + \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}
Initial program 52.3
Simplified52.3
[Start]52.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]52.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
Applied egg-rr52.1
Simplified52.1
[Start]52.1 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2}
\] |
|---|---|
*-commutative [=>]52.1 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \color{blue}{\left(c \cdot a\right)}\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2}
\] |
*-commutative [=>]52.1 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \color{blue}{\left(c \cdot a\right) \cdot 4}\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2}
\] |
fma-def [<=]52.1 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\color{blue}{b \cdot b + c \cdot \left(a \cdot -4\right)}}}}{a \cdot 2}
\] |
+-commutative [=>]52.1 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\color{blue}{c \cdot \left(a \cdot -4\right) + b \cdot b}}}}{a \cdot 2}
\] |
fma-def [=>]52.1 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\color{blue}{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}}{a \cdot 2}
\] |
Applied egg-rr58.8
Simplified0.2
[Start]58.8 | \[ e^{\mathsf{log1p}\left(\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}\right)} - 1
\] |
|---|---|
expm1-def [=>]56.2 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}\right)\right)}
\] |
expm1-log1p [=>]52.1 | \[ \color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}}
\] |
*-lft-identity [<=]52.1 | \[ \frac{\color{blue}{1 \cdot \left(b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)\right)}}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}
\] |
associate-*l/ [<=]52.1 | \[ \color{blue}{\frac{1}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)} \cdot \left(b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)\right)}
\] |
associate-/r* [=>]52.1 | \[ \color{blue}{\frac{\frac{1}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{a \cdot 2}} \cdot \left(b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)\right)
\] |
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 14016 |
| Alternative 2 | |
|---|---|
| Error | 3.0 |
| Cost | 7232 |
| Alternative 3 | |
|---|---|
| Error | 3.1 |
| Cost | 832 |
| Alternative 4 | |
|---|---|
| Error | 3.1 |
| Cost | 576 |
| Alternative 5 | |
|---|---|
| Error | 6.3 |
| Cost | 256 |
| Alternative 6 | |
|---|---|
| Error | 62.9 |
| Cost | 192 |
herbie shell --seed 2023039
(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)))