| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 14144 |
\[\frac{1}{\frac{a \cdot 2}{\frac{-4 \cdot \left(a \cdot c\right)}{b + \sqrt{\mathsf{fma}\left(a, -4 \cdot c, b \cdot b\right)}}}}
\]
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c) :precision binary64 (/ (/ (fma a (* -4.0 c) 0.0) (* a 2.0)) (+ b (sqrt (fma a (* -4.0 c) (* 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 (fma(a, (-4.0 * c), 0.0) / (a * 2.0)) / (b + sqrt(fma(a, (-4.0 * c), (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(fma(a, Float64(-4.0 * c), 0.0) / Float64(a * 2.0)) / Float64(b + sqrt(fma(a, Float64(-4.0 * c), 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[(N[(a * N[(-4.0 * c), $MachinePrecision] + 0.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(a * N[(-4.0 * c), $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{\frac{\mathsf{fma}\left(a, -4 \cdot c, 0\right)}{a \cdot 2}}{b + \sqrt{\mathsf{fma}\left(a, -4 \cdot c, b \cdot b\right)}}
Initial program 44.0
Simplified44.0
[Start]44.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]44.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]44.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
*-commutative [=>]44.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{\color{blue}{a \cdot 2}}{--1}}
\] |
associate-/l* [=>]44.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{a}{\frac{--1}{2}}}}
\] |
associate-/l* [<=]44.0 | \[ \color{blue}{\frac{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{--1}{2}}{a}}
\] |
associate-*r/ [<=]44.0 | \[ \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{\frac{--1}{2}}{a}}
\] |
/-rgt-identity [<=]44.0 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{1}} \cdot \frac{\frac{--1}{2}}{a}
\] |
metadata-eval [<=]44.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{--1}} \cdot \frac{\frac{--1}{2}}{a}
\] |
Applied egg-rr44.6
Simplified44.6
[Start]44.6 | \[ \frac{{\left(\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)\right)}^{0.25} + \sqrt{b}}{\frac{\frac{a}{0.5}}{{\left(\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)\right)}^{0.25} - \sqrt{b}}}
\] |
|---|---|
associate-/r/ [=>]44.6 | \[ \color{blue}{\frac{{\left(\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)\right)}^{0.25} + \sqrt{b}}{\frac{a}{0.5}} \cdot \left({\left(\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)\right)}^{0.25} - \sqrt{b}\right)}
\] |
+-commutative [=>]44.6 | \[ \frac{\color{blue}{\sqrt{b} + {\left(\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)\right)}^{0.25}}}{\frac{a}{0.5}} \cdot \left({\left(\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)\right)}^{0.25} - \sqrt{b}\right)
\] |
fma-def [<=]44.6 | \[ \frac{\sqrt{b} + {\color{blue}{\left(b \cdot b + a \cdot \left(c \cdot -4\right)\right)}}^{0.25}}{\frac{a}{0.5}} \cdot \left({\left(\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)\right)}^{0.25} - \sqrt{b}\right)
\] |
+-commutative [<=]44.6 | \[ \frac{\sqrt{b} + {\color{blue}{\left(a \cdot \left(c \cdot -4\right) + b \cdot b\right)}}^{0.25}}{\frac{a}{0.5}} \cdot \left({\left(\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)\right)}^{0.25} - \sqrt{b}\right)
\] |
fma-def [=>]44.6 | \[ \frac{\sqrt{b} + {\color{blue}{\left(\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)\right)}}^{0.25}}{\frac{a}{0.5}} \cdot \left({\left(\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)\right)}^{0.25} - \sqrt{b}\right)
\] |
fma-def [<=]44.6 | \[ \frac{\sqrt{b} + {\left(\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)\right)}^{0.25}}{\frac{a}{0.5}} \cdot \left({\color{blue}{\left(b \cdot b + a \cdot \left(c \cdot -4\right)\right)}}^{0.25} - \sqrt{b}\right)
\] |
+-commutative [<=]44.6 | \[ \frac{\sqrt{b} + {\left(\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)\right)}^{0.25}}{\frac{a}{0.5}} \cdot \left({\color{blue}{\left(a \cdot \left(c \cdot -4\right) + b \cdot b\right)}}^{0.25} - \sqrt{b}\right)
\] |
fma-def [=>]44.6 | \[ \frac{\sqrt{b} + {\left(\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)\right)}^{0.25}}{\frac{a}{0.5}} \cdot \left({\color{blue}{\left(\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)\right)}}^{0.25} - \sqrt{b}\right)
\] |
Applied egg-rr44.0
Applied egg-rr43.5
Applied egg-rr52.0
Simplified0.2
[Start]52.0 | \[ e^{\mathsf{log1p}\left(\frac{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right) - b \cdot b}{\left(a \cdot 2\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\right)}\right)} - 1
\] |
|---|---|
expm1-def [=>]49.7 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right) - b \cdot b}{\left(a \cdot 2\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\right)}\right)\right)}
\] |
expm1-log1p [=>]43.5 | \[ \color{blue}{\frac{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right) - b \cdot b}{\left(a \cdot 2\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\right)}}
\] |
associate-/r* [=>]43.5 | \[ \color{blue}{\frac{\frac{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right) - b \cdot b}{a \cdot 2}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}}
\] |
fma-udef [=>]43.5 | \[ \frac{\frac{\color{blue}{\left(a \cdot \left(c \cdot -4\right) + b \cdot b\right)} - b \cdot b}{a \cdot 2}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}
\] |
associate-+r- [<=]0.2 | \[ \frac{\frac{\color{blue}{a \cdot \left(c \cdot -4\right) + \left(b \cdot b - b \cdot b\right)}}{a \cdot 2}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}
\] |
fma-def [=>]0.2 | \[ \frac{\frac{\color{blue}{\mathsf{fma}\left(a, c \cdot -4, b \cdot b - b \cdot b\right)}}{a \cdot 2}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}
\] |
*-commutative [=>]0.2 | \[ \frac{\frac{\mathsf{fma}\left(a, \color{blue}{-4 \cdot c}, b \cdot b - b \cdot b\right)}{a \cdot 2}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}
\] |
+-inverses [=>]0.2 | \[ \frac{\frac{\mathsf{fma}\left(a, -4 \cdot c, \color{blue}{0}\right)}{a \cdot 2}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}
\] |
*-commutative [=>]0.2 | \[ \frac{\frac{\mathsf{fma}\left(a, -4 \cdot c, 0\right)}{a \cdot 2}}{b + \sqrt{\mathsf{fma}\left(a, \color{blue}{-4 \cdot c}, b \cdot b\right)}}
\] |
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 14144 |
| Alternative 2 | |
|---|---|
| Error | 0.4 |
| Cost | 14016 |
| Alternative 3 | |
|---|---|
| Error | 3.8 |
| Cost | 7552 |
| Alternative 4 | |
|---|---|
| Error | 5.7 |
| Cost | 576 |
| Alternative 5 | |
|---|---|
| Error | 11.9 |
| Cost | 256 |
| Alternative 6 | |
|---|---|
| Error | 63.0 |
| Cost | 192 |
herbie shell --seed 2023237
(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)))