| Alternative 1 | |
|---|---|
| Error | 12.2 |
| Cost | 33356 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* a (* c -4.0))))
(if (<= b -1.2e+151)
(- (/ c b) (/ b a))
(if (<= b -6.8e-158)
(/ (- (sqrt (+ (* b b) (* c (* a -4.0)))) b) (* a 2.0))
(if (<= b 4.65e-290)
(/
0.5
(/
a
(-
(hypot
b
(pow (exp (* 0.25 (- (log (* c 4.0)) (log (/ -1.0 a))))) 2.0))
b)))
(if (<= b 1.26e-43)
(/
(* (/ 0.5 a) (- (fma b b t_0) (* b b)))
(+ b (hypot b (sqrt t_0))))
(- (/ c 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) {
double t_0 = a * (c * -4.0);
double tmp;
if (b <= -1.2e+151) {
tmp = (c / b) - (b / a);
} else if (b <= -6.8e-158) {
tmp = (sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
} else if (b <= 4.65e-290) {
tmp = 0.5 / (a / (hypot(b, pow(exp((0.25 * (log((c * 4.0)) - log((-1.0 / a))))), 2.0)) - b));
} else if (b <= 1.26e-43) {
tmp = ((0.5 / a) * (fma(b, b, t_0) - (b * b))) / (b + hypot(b, sqrt(t_0)));
} else {
tmp = -(c / b);
}
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) t_0 = Float64(a * Float64(c * -4.0)) tmp = 0.0 if (b <= -1.2e+151) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= -6.8e-158) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); elseif (b <= 4.65e-290) tmp = Float64(0.5 / Float64(a / Float64(hypot(b, (exp(Float64(0.25 * Float64(log(Float64(c * 4.0)) - log(Float64(-1.0 / a))))) ^ 2.0)) - b))); elseif (b <= 1.26e-43) tmp = Float64(Float64(Float64(0.5 / a) * Float64(fma(b, b, t_0) - Float64(b * b))) / Float64(b + hypot(b, sqrt(t_0)))); else tmp = Float64(-Float64(c / b)); 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_] := Block[{t$95$0 = N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.2e+151], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -6.8e-158], 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, 4.65e-290], N[(0.5 / N[(a / N[(N[Sqrt[b ^ 2 + N[Power[N[Exp[N[(0.25 * N[(N[Log[N[(c * 4.0), $MachinePrecision]], $MachinePrecision] - N[Log[N[(-1.0 / a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] ^ 2], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.26e-43], N[(N[(N[(0.5 / a), $MachinePrecision] * N[(N[(b * b + t$95$0), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[b ^ 2 + N[Sqrt[t$95$0], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[(c / b), $MachinePrecision])]]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
t_0 := a \cdot \left(c \cdot -4\right)\\
\mathbf{if}\;b \leq -1.2 \cdot 10^{+151}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq -6.8 \cdot 10^{-158}:\\
\;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 4.65 \cdot 10^{-290}:\\
\;\;\;\;\frac{0.5}{\frac{a}{\mathsf{hypot}\left(b, {\left(e^{0.25 \cdot \left(\log \left(c \cdot 4\right) - \log \left(\frac{-1}{a}\right)\right)}\right)}^{2}\right) - b}}\\
\mathbf{elif}\;b \leq 1.26 \cdot 10^{-43}:\\
\;\;\;\;\frac{\frac{0.5}{a} \cdot \left(\mathsf{fma}\left(b, b, t_0\right) - b \cdot b\right)}{b + \mathsf{hypot}\left(b, \sqrt{t_0}\right)}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}
if b < -1.20000000000000005e151Initial program 63.3
Simplified63.3
[Start]63.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]63.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
Taylor expanded in b around -inf 2.2
Simplified2.2
[Start]2.2 | \[ \frac{c}{b} + -1 \cdot \frac{b}{a}
\] |
|---|---|
mul-1-neg [=>]2.2 | \[ \frac{c}{b} + \color{blue}{\left(-\frac{b}{a}\right)}
\] |
unsub-neg [=>]2.2 | \[ \color{blue}{\frac{c}{b} - \frac{b}{a}}
\] |
if -1.20000000000000005e151 < b < -6.7999999999999999e-158Initial program 5.8
if -6.7999999999999999e-158 < b < 4.65000000000000014e-290Initial program 14.6
Simplified14.7
[Start]14.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]14.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]14.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
*-commutative [=>]14.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{\color{blue}{a \cdot 2}}{--1}}
\] |
associate-/l* [=>]14.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{a}{\frac{--1}{2}}}}
\] |
associate-/l* [<=]14.6 | \[ \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/ [<=]14.7 | \[ \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{\frac{--1}{2}}{a}}
\] |
+-commutative [=>]14.7 | \[ \color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)\right)} \cdot \frac{\frac{--1}{2}}{a}
\] |
unsub-neg [=>]14.7 | \[ \color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right)} \cdot \frac{\frac{--1}{2}}{a}
\] |
fma-neg [=>]14.7 | \[ \left(\sqrt{\color{blue}{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
associate-*l* [=>]14.7 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, -\color{blue}{4 \cdot \left(a \cdot c\right)}\right)} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
distribute-lft-neg-in [=>]14.7 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(-4\right) \cdot \left(a \cdot c\right)}\right)} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
*-commutative [=>]14.7 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(a \cdot c\right) \cdot \left(-4\right)}\right)} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
associate-*l* [=>]14.7 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, \color{blue}{a \cdot \left(c \cdot \left(-4\right)\right)}\right)} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
metadata-eval [=>]14.7 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot \color{blue}{-4}\right)\right)} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
metadata-eval [=>]14.7 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b\right) \cdot \frac{\frac{\color{blue}{1}}{2}}{a}
\] |
metadata-eval [=>]14.7 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b\right) \cdot \frac{\color{blue}{0.5}}{a}
\] |
Applied egg-rr11.5
Applied egg-rr11.7
Taylor expanded in a around -inf 35.4
if 4.65000000000000014e-290 < b < 1.26e-43Initial program 22.9
Simplified23.0
[Start]22.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]22.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]22.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
*-commutative [=>]22.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{\color{blue}{a \cdot 2}}{--1}}
\] |
associate-/l* [=>]22.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{a}{\frac{--1}{2}}}}
\] |
associate-/l* [<=]22.9 | \[ \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/ [<=]22.9 | \[ \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{\frac{--1}{2}}{a}}
\] |
+-commutative [=>]22.9 | \[ \color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)\right)} \cdot \frac{\frac{--1}{2}}{a}
\] |
unsub-neg [=>]22.9 | \[ \color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right)} \cdot \frac{\frac{--1}{2}}{a}
\] |
fma-neg [=>]22.9 | \[ \left(\sqrt{\color{blue}{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
associate-*l* [=>]22.9 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, -\color{blue}{4 \cdot \left(a \cdot c\right)}\right)} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
distribute-lft-neg-in [=>]22.9 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(-4\right) \cdot \left(a \cdot c\right)}\right)} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
*-commutative [=>]22.9 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(a \cdot c\right) \cdot \left(-4\right)}\right)} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
associate-*l* [=>]23.0 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, \color{blue}{a \cdot \left(c \cdot \left(-4\right)\right)}\right)} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
metadata-eval [=>]23.0 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot \color{blue}{-4}\right)\right)} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
metadata-eval [=>]23.0 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b\right) \cdot \frac{\frac{\color{blue}{1}}{2}}{a}
\] |
metadata-eval [=>]23.0 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b\right) \cdot \frac{\color{blue}{0.5}}{a}
\] |
Applied egg-rr23.4
if 1.26e-43 < b Initial program 53.6
Simplified53.6
[Start]53.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]53.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]53.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
*-commutative [=>]53.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{\color{blue}{a \cdot 2}}{--1}}
\] |
associate-/l* [=>]53.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{a}{\frac{--1}{2}}}}
\] |
associate-/l* [<=]53.6 | \[ \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/ [<=]53.6 | \[ \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{\frac{--1}{2}}{a}}
\] |
+-commutative [=>]53.6 | \[ \color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)\right)} \cdot \frac{\frac{--1}{2}}{a}
\] |
unsub-neg [=>]53.6 | \[ \color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right)} \cdot \frac{\frac{--1}{2}}{a}
\] |
fma-neg [=>]53.6 | \[ \left(\sqrt{\color{blue}{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
associate-*l* [=>]53.6 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, -\color{blue}{4 \cdot \left(a \cdot c\right)}\right)} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
distribute-lft-neg-in [=>]53.6 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(-4\right) \cdot \left(a \cdot c\right)}\right)} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
*-commutative [=>]53.6 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(a \cdot c\right) \cdot \left(-4\right)}\right)} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
associate-*l* [=>]53.6 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, \color{blue}{a \cdot \left(c \cdot \left(-4\right)\right)}\right)} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
metadata-eval [=>]53.6 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot \color{blue}{-4}\right)\right)} - b\right) \cdot \frac{\frac{--1}{2}}{a}
\] |
metadata-eval [=>]53.6 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b\right) \cdot \frac{\frac{\color{blue}{1}}{2}}{a}
\] |
metadata-eval [=>]53.6 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b\right) \cdot \frac{\color{blue}{0.5}}{a}
\] |
Taylor expanded in b around inf 7.8
Simplified7.8
[Start]7.8 | \[ -1 \cdot \frac{c}{b}
\] |
|---|---|
mul-1-neg [=>]7.8 | \[ \color{blue}{-\frac{c}{b}}
\] |
Final simplification12.2
| Alternative 1 | |
|---|---|
| Error | 12.2 |
| Cost | 33356 |
| Alternative 2 | |
|---|---|
| Error | 10.0 |
| Cost | 7624 |
| Alternative 3 | |
|---|---|
| Error | 9.9 |
| Cost | 7624 |
| Alternative 4 | |
|---|---|
| Error | 13.7 |
| Cost | 7368 |
| Alternative 5 | |
|---|---|
| Error | 23.1 |
| Cost | 388 |
| Alternative 6 | |
|---|---|
| Error | 40.0 |
| Cost | 256 |
| Alternative 7 | |
|---|---|
| Error | 56.2 |
| Cost | 64 |
herbie shell --seed 2023073
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))