| Alternative 1 | |
|---|---|
| Error | 14.8 |
| Cost | 7624 |
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (+ (* b b) (* c (* a -4.0)))))
(t_1 (/ (* c 2.0) (- t_0 b)))
(t_2 (if (>= b 0.0) (/ (- (- b) t_0) (* a 2.0)) t_1))
(t_3 (/ (- (- b) b) (* a 2.0))))
(if (<= t_2 (- INFINITY))
(if (>= b 0.0) t_3 (/ b a))
(if (<= t_2 -1e-293)
t_2
(if (<= t_2 0.0)
(if (>= b 0.0) t_3 (/ (* c 2.0) (* b -2.0)))
(if (<= t_2 2e+223)
t_2
(if (>= b 0.0)
(+ (* (/ b a) -0.5) (* (+ b (* -2.0 (/ c (/ b a)))) (/ -0.5 a)))
t_1)))))))double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (-b - sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + sqrt(((b * b) - ((4.0 * a) * c))));
}
return tmp;
}
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) + (c * (a * -4.0))));
double t_1 = (c * 2.0) / (t_0 - b);
double tmp;
if (b >= 0.0) {
tmp = (-b - t_0) / (a * 2.0);
} else {
tmp = t_1;
}
double t_2 = tmp;
double t_3 = (-b - b) / (a * 2.0);
double tmp_2;
if (t_2 <= -((double) INFINITY)) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = t_3;
} else {
tmp_3 = b / a;
}
tmp_2 = tmp_3;
} else if (t_2 <= -1e-293) {
tmp_2 = t_2;
} else if (t_2 <= 0.0) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = t_3;
} else {
tmp_4 = (c * 2.0) / (b * -2.0);
}
tmp_2 = tmp_4;
} else if (t_2 <= 2e+223) {
tmp_2 = t_2;
} else if (b >= 0.0) {
tmp_2 = ((b / a) * -0.5) + ((b + (-2.0 * (c / (b / a)))) * (-0.5 / a));
} else {
tmp_2 = t_1;
}
return tmp_2;
}
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (-b - Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + Math.sqrt(((b * b) - ((4.0 * a) * c))));
}
return tmp;
}
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) + (c * (a * -4.0))));
double t_1 = (c * 2.0) / (t_0 - b);
double tmp;
if (b >= 0.0) {
tmp = (-b - t_0) / (a * 2.0);
} else {
tmp = t_1;
}
double t_2 = tmp;
double t_3 = (-b - b) / (a * 2.0);
double tmp_2;
if (t_2 <= -Double.POSITIVE_INFINITY) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = t_3;
} else {
tmp_3 = b / a;
}
tmp_2 = tmp_3;
} else if (t_2 <= -1e-293) {
tmp_2 = t_2;
} else if (t_2 <= 0.0) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = t_3;
} else {
tmp_4 = (c * 2.0) / (b * -2.0);
}
tmp_2 = tmp_4;
} else if (t_2 <= 2e+223) {
tmp_2 = t_2;
} else if (b >= 0.0) {
tmp_2 = ((b / a) * -0.5) + ((b + (-2.0 * (c / (b / a)))) * (-0.5 / a));
} else {
tmp_2 = t_1;
}
return tmp_2;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (-b - math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a) else: tmp = (2.0 * c) / (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) return tmp
def code(a, b, c): t_0 = math.sqrt(((b * b) + (c * (a * -4.0)))) t_1 = (c * 2.0) / (t_0 - b) tmp = 0 if b >= 0.0: tmp = (-b - t_0) / (a * 2.0) else: tmp = t_1 t_2 = tmp t_3 = (-b - b) / (a * 2.0) tmp_2 = 0 if t_2 <= -math.inf: tmp_3 = 0 if b >= 0.0: tmp_3 = t_3 else: tmp_3 = b / a tmp_2 = tmp_3 elif t_2 <= -1e-293: tmp_2 = t_2 elif t_2 <= 0.0: tmp_4 = 0 if b >= 0.0: tmp_4 = t_3 else: tmp_4 = (c * 2.0) / (b * -2.0) tmp_2 = tmp_4 elif t_2 <= 2e+223: tmp_2 = t_2 elif b >= 0.0: tmp_2 = ((b / a) * -0.5) + ((b + (-2.0 * (c / (b / a)))) * (-0.5 / a)) else: tmp_2 = t_1 return tmp_2
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)); else tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))))); end return tmp end
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -4.0)))) t_1 = Float64(Float64(c * 2.0) / Float64(t_0 - b)) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(Float64(-b) - t_0) / Float64(a * 2.0)); else tmp = t_1; end t_2 = tmp t_3 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)) tmp_2 = 0.0 if (t_2 <= Float64(-Inf)) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = t_3; else tmp_3 = Float64(b / a); end tmp_2 = tmp_3; elseif (t_2 <= -1e-293) tmp_2 = t_2; elseif (t_2 <= 0.0) tmp_4 = 0.0 if (b >= 0.0) tmp_4 = t_3; else tmp_4 = Float64(Float64(c * 2.0) / Float64(b * -2.0)); end tmp_2 = tmp_4; elseif (t_2 <= 2e+223) tmp_2 = t_2; elseif (b >= 0.0) tmp_2 = Float64(Float64(Float64(b / a) * -0.5) + Float64(Float64(b + Float64(-2.0 * Float64(c / Float64(b / a)))) * Float64(-0.5 / a))); else tmp_2 = t_1; end return tmp_2 end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = (-b - sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); else tmp = (2.0 * c) / (-b + sqrt(((b * b) - ((4.0 * a) * c)))); end tmp_2 = tmp; end
function tmp_6 = code(a, b, c) t_0 = sqrt(((b * b) + (c * (a * -4.0)))); t_1 = (c * 2.0) / (t_0 - b); tmp = 0.0; if (b >= 0.0) tmp = (-b - t_0) / (a * 2.0); else tmp = t_1; end t_2 = tmp; t_3 = (-b - b) / (a * 2.0); tmp_3 = 0.0; if (t_2 <= -Inf) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = t_3; else tmp_4 = b / a; end tmp_3 = tmp_4; elseif (t_2 <= -1e-293) tmp_3 = t_2; elseif (t_2 <= 0.0) tmp_5 = 0.0; if (b >= 0.0) tmp_5 = t_3; else tmp_5 = (c * 2.0) / (b * -2.0); end tmp_3 = tmp_5; elseif (t_2 <= 2e+223) tmp_3 = t_2; elseif (b >= 0.0) tmp_3 = ((b / a) * -0.5) + ((b + (-2.0 * (c / (b / a)))) * (-0.5 / a)); else tmp_3 = t_1; end tmp_6 = tmp_3; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], 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], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$0 - b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], t$95$1]}, Block[{t$95$3 = N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], If[GreaterEqual[b, 0.0], t$95$3, N[(b / a), $MachinePrecision]], If[LessEqual[t$95$2, -1e-293], t$95$2, If[LessEqual[t$95$2, 0.0], If[GreaterEqual[b, 0.0], t$95$3, N[(N[(c * 2.0), $MachinePrecision] / N[(b * -2.0), $MachinePrecision]), $MachinePrecision]], If[LessEqual[t$95$2, 2e+223], t$95$2, If[GreaterEqual[b, 0.0], N[(N[(N[(b / a), $MachinePrecision] * -0.5), $MachinePrecision] + N[(N[(b + N[(-2.0 * N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]]]
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\begin{array}{l}
t_0 := \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}\\
t_1 := \frac{c \cdot 2}{t_0 - b}\\
t_2 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}\\
t_3 := \frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{a}\\
\end{array}\\
\mathbf{elif}\;t_2 \leq -1 \cdot 10^{-293}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{b \cdot -2}\\
\end{array}\\
\mathbf{elif}\;t_2 \leq 2 \cdot 10^{+223}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{b}{a} \cdot -0.5 + \left(b + -2 \cdot \frac{c}{\frac{b}{a}}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Results
if (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < -inf.0Initial program 64.0
Taylor expanded in b around inf 16.3
Taylor expanded in b around -inf 16.3
Simplified16.3
[Start]16.3 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \frac{c \cdot a}{b} + -2 \cdot b}\\
\end{array}
\] |
|---|---|
fma-def [=>]16.3 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\color{blue}{\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{c \cdot a}{b}, -2 \cdot b\right)}}\\
\end{array}
\] |
associate-/l* [=>]16.3 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\color{blue}{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, -2 \cdot b\right)}}\\
\end{array}
\] |
associate-/r/ [=>]16.3 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\color{blue}{\mathsf{fma}\left(2, \frac{c}{b} \cdot a, -2 \cdot b\right)}}\\
\end{array}
\] |
*-commutative [=>]16.3 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{c}{b} \cdot a, b \cdot -2\right)}\\
\end{array}
\] |
Taylor expanded in c around inf 16.3
if -inf.0 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < -1.0000000000000001e-293 or 0.0 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < 2.00000000000000009e223Initial program 2.8
Applied egg-rr15.6
Simplified20.8
[Start]15.6 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot -4\right)\right)}{b \cdot b - c \cdot \left(a \cdot -4\right)}}}\\
\end{array}
\] |
|---|---|
swap-sqr [=>]20.8 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{\frac{{b}^{4} - \left(c \cdot c\right) \cdot \left(\left(a \cdot -4\right) \cdot \left(a \cdot -4\right)\right)}{b \cdot b - c \cdot \left(a \cdot -4\right)}}}\\
\end{array}
\] |
Applied egg-rr2.8
if -1.0000000000000001e-293 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < 0.0Initial program 36.3
Taylor expanded in b around inf 36.3
Taylor expanded in b around -inf 10.6
Simplified10.6
[Start]10.6 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{-2 \cdot b}\\
\end{array}
\] |
|---|---|
*-commutative [=>]10.6 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\color{blue}{\frac{2 \cdot c}{b \cdot -2}}\\
\end{array}
\] |
if 2.00000000000000009e223 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) Initial program 49.8
Applied egg-rr49.8
Simplified49.9
[Start]49.8 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + \left(\left(\left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right) + \left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right)\right) + \left(\left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right) + \left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right)\right)\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
|---|---|
fma-def [<=]49.8 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\color{blue}{\left(b \cdot b + c \cdot \left(a \cdot -4\right)\right)} + \left(\left(\left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right) + \left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right)\right) + \left(\left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right) + \left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right)\right)\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
+-commutative [=>]49.8 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\color{blue}{\left(c \cdot \left(a \cdot -4\right) + b \cdot b\right)} + \left(\left(\left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right) + \left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right)\right) + \left(\left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right) + \left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right)\right)\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
fma-def [=>]49.8 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\color{blue}{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} + \left(\left(\left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right) + \left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right)\right) + \left(\left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right) + \left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right)\right)\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
count-2 [=>]49.8 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right) + \color{blue}{2 \cdot \left(\left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right) + \left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right)\right)}}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
count-2 [=>]49.8 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right) + 2 \cdot \color{blue}{\left(2 \cdot \left(4 \cdot \left(a \cdot c\right) + c \cdot \left(a \cdot -4\right)\right)\right)}}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
+-commutative [=>]49.8 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right) + 2 \cdot \left(2 \cdot \color{blue}{\left(c \cdot \left(a \cdot -4\right) + 4 \cdot \left(a \cdot c\right)\right)}\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
*-commutative [=>]49.8 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right) + 2 \cdot \left(2 \cdot \left(\color{blue}{\left(a \cdot -4\right) \cdot c} + 4 \cdot \left(a \cdot c\right)\right)\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
fma-udef [<=]49.9 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right) + 2 \cdot \left(2 \cdot \color{blue}{\mathsf{fma}\left(a \cdot -4, c, 4 \cdot \left(a \cdot c\right)\right)}\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
associate-*r* [=>]49.9 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right) + 2 \cdot \left(2 \cdot \mathsf{fma}\left(a \cdot -4, c, \color{blue}{\left(4 \cdot a\right) \cdot c}\right)\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
Taylor expanded in c around 0 25.1
Simplified17.4
[Start]25.1 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \left(0.5 \cdot \frac{\left(-4 \cdot a + 4 \cdot \left(4 \cdot a + -4 \cdot a\right)\right) \cdot c}{b} + b\right)}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
|---|---|
fma-def [=>]25.1 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \color{blue}{\mathsf{fma}\left(0.5, \frac{\left(-4 \cdot a + 4 \cdot \left(4 \cdot a + -4 \cdot a\right)\right) \cdot c}{b}, b\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
Applied egg-rr17.4
Simplified17.3
[Start]17.4 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{0}{a \cdot 2} - \left(0.5 \cdot \frac{b}{a} + \mathsf{fma}\left(0.5, \left(-4 \cdot a\right) \cdot \frac{c}{b}, b\right) \cdot \frac{0.5}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
|---|---|
associate--r+ [=>]17.4 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\color{blue}{\left(\frac{0}{a \cdot 2} - 0.5 \cdot \frac{b}{a}\right) - \mathsf{fma}\left(0.5, \left(-4 \cdot a\right) \cdot \frac{c}{b}, b\right) \cdot \frac{0.5}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
div0 [=>]17.4 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\left(\color{blue}{0} - 0.5 \cdot \frac{b}{a}\right) - \mathsf{fma}\left(0.5, \left(-4 \cdot a\right) \cdot \frac{c}{b}, b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
remove-double-neg [<=]17.4 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\left(0 - 0.5 \cdot \frac{b}{a}\right) - \color{blue}{\left(-\left(-\mathsf{fma}\left(0.5, \left(-4 \cdot a\right) \cdot \frac{c}{b}, b\right) \cdot \frac{0.5}{a}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
sub0-neg [=>]17.4 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\color{blue}{\left(-0.5 \cdot \frac{b}{a}\right)} - \left(-\left(-\mathsf{fma}\left(0.5, \left(-4 \cdot a\right) \cdot \frac{c}{b}, b\right) \cdot \frac{0.5}{a}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
*-commutative [=>]17.4 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\left(-\color{blue}{\frac{b}{a} \cdot 0.5}\right) - \left(-\left(-\mathsf{fma}\left(0.5, \left(-4 \cdot a\right) \cdot \frac{c}{b}, b\right) \cdot \frac{0.5}{a}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
distribute-rgt-neg-in [=>]17.4 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\color{blue}{\frac{b}{a} \cdot \left(-0.5\right)} - \left(-\left(-\mathsf{fma}\left(0.5, \left(-4 \cdot a\right) \cdot \frac{c}{b}, b\right) \cdot \frac{0.5}{a}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
metadata-eval [=>]17.4 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a} \cdot \color{blue}{-0.5} - \left(-\left(-\mathsf{fma}\left(0.5, \left(-4 \cdot a\right) \cdot \frac{c}{b}, b\right) \cdot \frac{0.5}{a}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
remove-double-neg [=>]17.4 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a} \cdot -0.5 - \color{blue}{\mathsf{fma}\left(0.5, \left(-4 \cdot a\right) \cdot \frac{c}{b}, b\right) \cdot \frac{0.5}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
fma-udef [=>]17.4 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a} \cdot -0.5 - \color{blue}{\left(0.5 \cdot \left(\left(-4 \cdot a\right) \cdot \frac{c}{b}\right) + b\right)} \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
+-commutative [=>]17.4 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a} \cdot -0.5 - \color{blue}{\left(b + 0.5 \cdot \left(\left(-4 \cdot a\right) \cdot \frac{c}{b}\right)\right)} \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
associate-*l* [=>]17.3 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a} \cdot -0.5 - \left(b + 0.5 \cdot \color{blue}{\left(-4 \cdot \left(a \cdot \frac{c}{b}\right)\right)}\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
associate-*r* [=>]17.3 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a} \cdot -0.5 - \left(b + \color{blue}{\left(0.5 \cdot -4\right) \cdot \left(a \cdot \frac{c}{b}\right)}\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
associate-*r/ [=>]25.0 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a} \cdot -0.5 - \left(b + \left(0.5 \cdot -4\right) \cdot \color{blue}{\frac{a \cdot c}{b}}\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
*-commutative [<=]25.0 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a} \cdot -0.5 - \left(b + \left(0.5 \cdot -4\right) \cdot \frac{\color{blue}{c \cdot a}}{b}\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
metadata-eval [=>]25.0 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a} \cdot -0.5 - \left(b + \color{blue}{-2} \cdot \frac{c \cdot a}{b}\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
associate-/l* [=>]17.3 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a} \cdot -0.5 - \left(b + -2 \cdot \color{blue}{\frac{c}{\frac{b}{a}}}\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
Final simplification7.1
| Alternative 1 | |
|---|---|
| Error | 14.8 |
| Cost | 7624 |
| Alternative 2 | |
|---|---|
| Error | 14.6 |
| Cost | 7624 |
| Alternative 3 | |
|---|---|
| Error | 17.6 |
| Cost | 7368 |
| Alternative 4 | |
|---|---|
| Error | 22.3 |
| Cost | 1092 |
| Alternative 5 | |
|---|---|
| Error | 44.4 |
| Cost | 644 |
| Alternative 6 | |
|---|---|
| Error | 22.5 |
| Cost | 644 |
herbie shell --seed 2023057
(FPCore (a b c)
:name "jeff quadratic root 1"
:precision binary64
(if (>= b 0.0) (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))