| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 7680 |
\[\frac{\frac{2}{a} \cdot \left(c \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b + c \cdot \left(a \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 (* 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 43.5
Simplified43.5
[Start]43.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]43.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
Applied egg-rr43.0
Simplified42.9
[Start]43.0 | \[ \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/ [=>]43.0 | \[ \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 [<=]42.9 | \[ \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 [=>]42.9 | \[ \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 [=>]42.9 | \[ \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 [<=]42.9 | \[ \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 [=>]42.9 | \[ \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 [<=]42.9 | \[ \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 [=>]42.9 | \[ \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 [=>]42.9 | \[ \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 0.4
Applied egg-rr0.5
Simplified0.4
[Start]0.5 | \[ \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 [=>]0.5 | \[ \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* [=>]0.5 | \[ \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 [=>]0.5 | \[ \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 [<=]0.5 | \[ \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* [<=]0.5 | \[ \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/ [<=]0.5 | \[ \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 [<=]0.5 | \[ \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/ [=>]0.5 | \[ \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 [<=]0.5 | \[ \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/ [<=]0.5 | \[ \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 0.2
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 7680 |
| Alternative 2 | |
|---|---|
| Error | 6.1 |
| Cost | 1216 |
| Alternative 3 | |
|---|---|
| Error | 12.3 |
| Cost | 256 |
herbie shell --seed 2023073
(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)))