| Alternative 1 | |
|---|---|
| Error | 12.36% |
| Cost | 13964 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
:precision binary64
(if (<= b -7.2e+152)
(/ (- b) a)
(if (<= b -3.7e-306)
(/ (- (sqrt (+ (* b b) (* c (* a -4.0)))) b) (* a 2.0))
(if (<= b 2.9)
(/ (* c -2.0) (+ b (hypot b (sqrt (* a (* c -4.0))))))
(/ (* c -2.0) (fma b 2.0 (* 0.5 (/ (* a -4.0) (/ b c)))))))))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) {
double tmp;
if (b <= -7.2e+152) {
tmp = -b / a;
} else if (b <= -3.7e-306) {
tmp = (sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
} else if (b <= 2.9) {
tmp = (c * -2.0) / (b + hypot(b, sqrt((a * (c * -4.0)))));
} else {
tmp = (c * -2.0) / fma(b, 2.0, (0.5 * ((a * -4.0) / (b / c))));
}
return tmp;
}
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) tmp = 0.0 if (b <= -7.2e+152) tmp = Float64(Float64(-b) / a); elseif (b <= -3.7e-306) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); elseif (b <= 2.9) tmp = Float64(Float64(c * -2.0) / Float64(b + hypot(b, sqrt(Float64(a * Float64(c * -4.0)))))); else tmp = Float64(Float64(c * -2.0) / fma(b, 2.0, Float64(0.5 * Float64(Float64(a * -4.0) / Float64(b / c))))); end return tmp 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_] := If[LessEqual[b, -7.2e+152], N[((-b) / a), $MachinePrecision], If[LessEqual[b, -3.7e-306], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.9], N[(N[(c * -2.0), $MachinePrecision] / N[(b + N[Sqrt[b ^ 2 + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c * -2.0), $MachinePrecision] / N[(b * 2.0 + N[(0.5 * N[(N[(a * -4.0), $MachinePrecision] / N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -7.2 \cdot 10^{+152}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq -3.7 \cdot 10^{-306}:\\
\;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 2.9:\\
\;\;\;\;\frac{c \cdot -2}{b + \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -2}{\mathsf{fma}\left(b, 2, 0.5 \cdot \frac{a \cdot -4}{\frac{b}{c}}\right)}\\
\end{array}
if b < -7.1999999999999998e152Initial program 98.8
Simplified98.8
[Start]98.8 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]98.8 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]98.8 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
*-commutative [=>]98.8 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{\color{blue}{a \cdot 2}}{--1}}
\] |
associate-/l* [=>]98.8 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{a}{\frac{--1}{2}}}}
\] |
associate-/l* [<=]98.8 | \[ \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/ [<=]98.8 | \[ \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 [<=]98.8 | \[ \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 [<=]98.8 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{--1}} \cdot \frac{\frac{--1}{2}}{a}
\] |
Taylor expanded in b around -inf 3.36
Simplified3.36
[Start]3.36 | \[ -1 \cdot \frac{b}{a}
\] |
|---|---|
associate-*r/ [=>]3.36 | \[ \color{blue}{\frac{-1 \cdot b}{a}}
\] |
mul-1-neg [=>]3.36 | \[ \frac{\color{blue}{-b}}{a}
\] |
if -7.1999999999999998e152 < b < -3.7e-306Initial program 13.02
if -3.7e-306 < b < 2.89999999999999991Initial program 40.83
Simplified40.87
[Start]40.83 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]40.83 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]40.83 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
*-commutative [=>]40.83 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{\color{blue}{a \cdot 2}}{--1}}
\] |
associate-/l* [=>]40.83 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{a}{\frac{--1}{2}}}}
\] |
associate-/l* [<=]40.83 | \[ \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/ [<=]40.91 | \[ \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 [<=]40.91 | \[ \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 [<=]40.91 | \[ \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-rr41.9
Taylor expanded in a around 0 21.7
Simplified21.7
[Start]21.7 | \[ \frac{-2 \cdot c}{b + \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}
\] |
|---|---|
*-commutative [=>]21.7 | \[ \frac{\color{blue}{c \cdot -2}}{b + \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}
\] |
if 2.89999999999999991 < b Initial program 86.66
Simplified86.65
[Start]86.66 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]86.66 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]86.66 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
*-commutative [=>]86.66 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{\color{blue}{a \cdot 2}}{--1}}
\] |
associate-/l* [=>]86.66 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{a}{\frac{--1}{2}}}}
\] |
associate-/l* [<=]86.66 | \[ \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/ [<=]86.66 | \[ \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 [<=]86.66 | \[ \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 [<=]86.66 | \[ \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-rr89.56
Taylor expanded in a around 0 46.06
Simplified46.06
[Start]46.06 | \[ \frac{-2 \cdot c}{b + \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}
\] |
|---|---|
*-commutative [=>]46.06 | \[ \frac{\color{blue}{c \cdot -2}}{b + \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}
\] |
Taylor expanded in b around inf 100
Simplified9.02
[Start]100 | \[ \frac{c \cdot -2}{0.5 \cdot \frac{c \cdot \left(a \cdot {\left(\sqrt{-4}\right)}^{2}\right)}{b} + 2 \cdot b}
\] |
|---|---|
+-commutative [=>]100 | \[ \frac{c \cdot -2}{\color{blue}{2 \cdot b + 0.5 \cdot \frac{c \cdot \left(a \cdot {\left(\sqrt{-4}\right)}^{2}\right)}{b}}}
\] |
*-commutative [=>]100 | \[ \frac{c \cdot -2}{\color{blue}{b \cdot 2} + 0.5 \cdot \frac{c \cdot \left(a \cdot {\left(\sqrt{-4}\right)}^{2}\right)}{b}}
\] |
fma-def [=>]100 | \[ \frac{c \cdot -2}{\color{blue}{\mathsf{fma}\left(b, 2, 0.5 \cdot \frac{c \cdot \left(a \cdot {\left(\sqrt{-4}\right)}^{2}\right)}{b}\right)}}
\] |
*-commutative [=>]100 | \[ \frac{c \cdot -2}{\mathsf{fma}\left(b, 2, 0.5 \cdot \frac{\color{blue}{\left(a \cdot {\left(\sqrt{-4}\right)}^{2}\right) \cdot c}}{b}\right)}
\] |
associate-/l* [=>]100 | \[ \frac{c \cdot -2}{\mathsf{fma}\left(b, 2, 0.5 \cdot \color{blue}{\frac{a \cdot {\left(\sqrt{-4}\right)}^{2}}{\frac{b}{c}}}\right)}
\] |
unpow2 [=>]100 | \[ \frac{c \cdot -2}{\mathsf{fma}\left(b, 2, 0.5 \cdot \frac{a \cdot \color{blue}{\left(\sqrt{-4} \cdot \sqrt{-4}\right)}}{\frac{b}{c}}\right)}
\] |
rem-square-sqrt [=>]9.02 | \[ \frac{c \cdot -2}{\mathsf{fma}\left(b, 2, 0.5 \cdot \frac{a \cdot \color{blue}{-4}}{\frac{b}{c}}\right)}
\] |
Final simplification12.34
| Alternative 1 | |
|---|---|
| Error | 12.36% |
| Cost | 13964 |
| Alternative 2 | |
|---|---|
| Error | 15.61% |
| Cost | 7624 |
| Alternative 3 | |
|---|---|
| Error | 15.5% |
| Cost | 7624 |
| Alternative 4 | |
|---|---|
| Error | 15.16% |
| Cost | 7624 |
| Alternative 5 | |
|---|---|
| Error | 21.6% |
| Cost | 7368 |
| Alternative 6 | |
|---|---|
| Error | 21.61% |
| Cost | 7368 |
| Alternative 7 | |
|---|---|
| Error | 34.39% |
| Cost | 580 |
| Alternative 8 | |
|---|---|
| Error | 61% |
| Cost | 388 |
| Alternative 9 | |
|---|---|
| Error | 34.39% |
| Cost | 388 |
| Alternative 10 | |
|---|---|
| Error | 88.29% |
| Cost | 192 |
herbie shell --seed 2023089
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))