| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 14016 |
\[\frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-4 \cdot a\right)\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 (/ (/ (* -4.0 (* c a)) (+ b (sqrt (fma c (* -4.0 a) (* b b))))) (* a 2.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 ((-4.0 * (c * a)) / (b + sqrt(fma(c, (-4.0 * a), (b * b))))) / (a * 2.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(-4.0 * Float64(c * a)) / Float64(b + sqrt(fma(c, Float64(-4.0 * a), Float64(b * b))))) / Float64(a * 2.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[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(c * N[(-4.0 * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}}{a \cdot 2}
Initial program 43.8
Simplified43.8
[Start]43.8 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]43.8 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
Applied egg-rr43.3
Taylor expanded in b around 0 0.4
Applied egg-rr0.5
Simplified0.4
[Start]0.5 | \[ \frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + {\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{0.25} \cdot {\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{0.25}}}{a \cdot 2}
\] |
|---|---|
pow-sqr [=>]0.4 | \[ \frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + \color{blue}{{\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{\left(2 \cdot 0.25\right)}}}}{a \cdot 2}
\] |
metadata-eval [=>]0.4 | \[ \frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + {\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{\color{blue}{0.5}}}}{a \cdot 2}
\] |
unpow1/2 [=>]0.4 | \[ \frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + \color{blue}{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
fma-def [<=]0.4 | \[ \frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + \sqrt{\color{blue}{b \cdot b + c \cdot \left(a \cdot -4\right)}}}}{a \cdot 2}
\] |
+-commutative [=>]0.4 | \[ \frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + \sqrt{\color{blue}{c \cdot \left(a \cdot -4\right) + b \cdot b}}}}{a \cdot 2}
\] |
fma-def [=>]0.4 | \[ \frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + \sqrt{\color{blue}{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}}{a \cdot 2}
\] |
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 14016 |
| Alternative 2 | |
|---|---|
| Error | 4.0 |
| Cost | 8448 |
| Alternative 3 | |
|---|---|
| Error | 6.0 |
| Cost | 1344 |
| Alternative 4 | |
|---|---|
| Error | 6.0 |
| Cost | 1344 |
| Alternative 5 | |
|---|---|
| Error | 12.1 |
| Cost | 256 |
herbie shell --seed 2023076
(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)))