| Alternative 1 | |
|---|---|
| Error | 9.94% |
| Cost | 38052 |
(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 (/ (- c) b))
(t_1 (* -4.0 (* a c)))
(t_2 (* c (* a -4.0)))
(t_3 (sqrt (+ (* b b) t_1)))
(t_4 (/ (- (- b) t_3) (* a 2.0)))
(t_5 (sqrt (+ (* b b) t_2)))
(t_6
(if (>= b 0.0) (/ (- (- b) t_5) (* a 2.0)) (/ (* c 2.0) (- t_5 b))))
(t_7 (/ (- (- b) b) (* a 2.0))))
(if (<= t_6 (- INFINITY))
(if (>= b 0.0) t_7 (/ (- b) a))
(if (<= t_6 -1e-275)
(if (>= b 0.0) t_4 (/ (* c 2.0) (- t_3 b)))
(if (<= t_6 0.0)
(if (>= b 0.0) (/ (- (- b) (sqrt t_2)) (* a 2.0)) t_0)
(if (<= t_6 1e+290)
(if (>= b 0.0)
t_4
(/
(* c 2.0)
(-
(sqrt (+ (* 4.0 (* a c)) (+ (+ (* b b) (* a (* c -4.0))) t_1)))
b)))
(if (>= b 0.0) t_7 t_0)))))))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 = -c / b;
double t_1 = -4.0 * (a * c);
double t_2 = c * (a * -4.0);
double t_3 = sqrt(((b * b) + t_1));
double t_4 = (-b - t_3) / (a * 2.0);
double t_5 = sqrt(((b * b) + t_2));
double tmp;
if (b >= 0.0) {
tmp = (-b - t_5) / (a * 2.0);
} else {
tmp = (c * 2.0) / (t_5 - b);
}
double t_6 = tmp;
double t_7 = (-b - b) / (a * 2.0);
double tmp_2;
if (t_6 <= -((double) INFINITY)) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = t_7;
} else {
tmp_3 = -b / a;
}
tmp_2 = tmp_3;
} else if (t_6 <= -1e-275) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = t_4;
} else {
tmp_4 = (c * 2.0) / (t_3 - b);
}
tmp_2 = tmp_4;
} else if (t_6 <= 0.0) {
double tmp_5;
if (b >= 0.0) {
tmp_5 = (-b - sqrt(t_2)) / (a * 2.0);
} else {
tmp_5 = t_0;
}
tmp_2 = tmp_5;
} else if (t_6 <= 1e+290) {
double tmp_6;
if (b >= 0.0) {
tmp_6 = t_4;
} else {
tmp_6 = (c * 2.0) / (sqrt(((4.0 * (a * c)) + (((b * b) + (a * (c * -4.0))) + t_1))) - b);
}
tmp_2 = tmp_6;
} else if (b >= 0.0) {
tmp_2 = t_7;
} else {
tmp_2 = t_0;
}
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 = -c / b;
double t_1 = -4.0 * (a * c);
double t_2 = c * (a * -4.0);
double t_3 = Math.sqrt(((b * b) + t_1));
double t_4 = (-b - t_3) / (a * 2.0);
double t_5 = Math.sqrt(((b * b) + t_2));
double tmp;
if (b >= 0.0) {
tmp = (-b - t_5) / (a * 2.0);
} else {
tmp = (c * 2.0) / (t_5 - b);
}
double t_6 = tmp;
double t_7 = (-b - b) / (a * 2.0);
double tmp_2;
if (t_6 <= -Double.POSITIVE_INFINITY) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = t_7;
} else {
tmp_3 = -b / a;
}
tmp_2 = tmp_3;
} else if (t_6 <= -1e-275) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = t_4;
} else {
tmp_4 = (c * 2.0) / (t_3 - b);
}
tmp_2 = tmp_4;
} else if (t_6 <= 0.0) {
double tmp_5;
if (b >= 0.0) {
tmp_5 = (-b - Math.sqrt(t_2)) / (a * 2.0);
} else {
tmp_5 = t_0;
}
tmp_2 = tmp_5;
} else if (t_6 <= 1e+290) {
double tmp_6;
if (b >= 0.0) {
tmp_6 = t_4;
} else {
tmp_6 = (c * 2.0) / (Math.sqrt(((4.0 * (a * c)) + (((b * b) + (a * (c * -4.0))) + t_1))) - b);
}
tmp_2 = tmp_6;
} else if (b >= 0.0) {
tmp_2 = t_7;
} else {
tmp_2 = t_0;
}
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 = -c / b t_1 = -4.0 * (a * c) t_2 = c * (a * -4.0) t_3 = math.sqrt(((b * b) + t_1)) t_4 = (-b - t_3) / (a * 2.0) t_5 = math.sqrt(((b * b) + t_2)) tmp = 0 if b >= 0.0: tmp = (-b - t_5) / (a * 2.0) else: tmp = (c * 2.0) / (t_5 - b) t_6 = tmp t_7 = (-b - b) / (a * 2.0) tmp_2 = 0 if t_6 <= -math.inf: tmp_3 = 0 if b >= 0.0: tmp_3 = t_7 else: tmp_3 = -b / a tmp_2 = tmp_3 elif t_6 <= -1e-275: tmp_4 = 0 if b >= 0.0: tmp_4 = t_4 else: tmp_4 = (c * 2.0) / (t_3 - b) tmp_2 = tmp_4 elif t_6 <= 0.0: tmp_5 = 0 if b >= 0.0: tmp_5 = (-b - math.sqrt(t_2)) / (a * 2.0) else: tmp_5 = t_0 tmp_2 = tmp_5 elif t_6 <= 1e+290: tmp_6 = 0 if b >= 0.0: tmp_6 = t_4 else: tmp_6 = (c * 2.0) / (math.sqrt(((4.0 * (a * c)) + (((b * b) + (a * (c * -4.0))) + t_1))) - b) tmp_2 = tmp_6 elif b >= 0.0: tmp_2 = t_7 else: tmp_2 = t_0 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 = Float64(Float64(-c) / b) t_1 = Float64(-4.0 * Float64(a * c)) t_2 = Float64(c * Float64(a * -4.0)) t_3 = sqrt(Float64(Float64(b * b) + t_1)) t_4 = Float64(Float64(Float64(-b) - t_3) / Float64(a * 2.0)) t_5 = sqrt(Float64(Float64(b * b) + t_2)) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(Float64(-b) - t_5) / Float64(a * 2.0)); else tmp = Float64(Float64(c * 2.0) / Float64(t_5 - b)); end t_6 = tmp t_7 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)) tmp_2 = 0.0 if (t_6 <= Float64(-Inf)) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = t_7; else tmp_3 = Float64(Float64(-b) / a); end tmp_2 = tmp_3; elseif (t_6 <= -1e-275) tmp_4 = 0.0 if (b >= 0.0) tmp_4 = t_4; else tmp_4 = Float64(Float64(c * 2.0) / Float64(t_3 - b)); end tmp_2 = tmp_4; elseif (t_6 <= 0.0) tmp_5 = 0.0 if (b >= 0.0) tmp_5 = Float64(Float64(Float64(-b) - sqrt(t_2)) / Float64(a * 2.0)); else tmp_5 = t_0; end tmp_2 = tmp_5; elseif (t_6 <= 1e+290) tmp_6 = 0.0 if (b >= 0.0) tmp_6 = t_4; else tmp_6 = Float64(Float64(c * 2.0) / Float64(sqrt(Float64(Float64(4.0 * Float64(a * c)) + Float64(Float64(Float64(b * b) + Float64(a * Float64(c * -4.0))) + t_1))) - b)); end tmp_2 = tmp_6; elseif (b >= 0.0) tmp_2 = t_7; else tmp_2 = t_0; 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_8 = code(a, b, c) t_0 = -c / b; t_1 = -4.0 * (a * c); t_2 = c * (a * -4.0); t_3 = sqrt(((b * b) + t_1)); t_4 = (-b - t_3) / (a * 2.0); t_5 = sqrt(((b * b) + t_2)); tmp = 0.0; if (b >= 0.0) tmp = (-b - t_5) / (a * 2.0); else tmp = (c * 2.0) / (t_5 - b); end t_6 = tmp; t_7 = (-b - b) / (a * 2.0); tmp_3 = 0.0; if (t_6 <= -Inf) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = t_7; else tmp_4 = -b / a; end tmp_3 = tmp_4; elseif (t_6 <= -1e-275) tmp_5 = 0.0; if (b >= 0.0) tmp_5 = t_4; else tmp_5 = (c * 2.0) / (t_3 - b); end tmp_3 = tmp_5; elseif (t_6 <= 0.0) tmp_6 = 0.0; if (b >= 0.0) tmp_6 = (-b - sqrt(t_2)) / (a * 2.0); else tmp_6 = t_0; end tmp_3 = tmp_6; elseif (t_6 <= 1e+290) tmp_7 = 0.0; if (b >= 0.0) tmp_7 = t_4; else tmp_7 = (c * 2.0) / (sqrt(((4.0 * (a * c)) + (((b * b) + (a * (c * -4.0))) + t_1))) - b); end tmp_3 = tmp_7; elseif (b >= 0.0) tmp_3 = t_7; else tmp_3 = t_0; end tmp_8 = 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[((-c) / b), $MachinePrecision]}, Block[{t$95$1 = N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[(N[(b * b), $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[(N[((-b) - t$95$3), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[Sqrt[N[(N[(b * b), $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$6 = If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$5), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$5 - b), $MachinePrecision]), $MachinePrecision]]}, Block[{t$95$7 = N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$6, (-Infinity)], If[GreaterEqual[b, 0.0], t$95$7, N[((-b) / a), $MachinePrecision]], If[LessEqual[t$95$6, -1e-275], If[GreaterEqual[b, 0.0], t$95$4, N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$3 - b), $MachinePrecision]), $MachinePrecision]], If[LessEqual[t$95$6, 0.0], If[GreaterEqual[b, 0.0], N[(N[((-b) - N[Sqrt[t$95$2], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], t$95$0], If[LessEqual[t$95$6, 1e+290], If[GreaterEqual[b, 0.0], t$95$4, N[(N[(c * 2.0), $MachinePrecision] / N[(N[Sqrt[N[(N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$7, t$95$0]]]]]]]]]]]]]
\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 := \frac{-c}{b}\\
t_1 := -4 \cdot \left(a \cdot c\right)\\
t_2 := c \cdot \left(a \cdot -4\right)\\
t_3 := \sqrt{b \cdot b + t_1}\\
t_4 := \frac{\left(-b\right) - t_3}{a \cdot 2}\\
t_5 := \sqrt{b \cdot b + t_2}\\
t_6 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_5}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t_5 - b}\\
\end{array}\\
t_7 := \frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{if}\;t_6 \leq -\infty:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_7\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}\\
\mathbf{elif}\;t_6 \leq -1 \cdot 10^{-275}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_4\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t_3 - b}\\
\end{array}\\
\mathbf{elif}\;t_6 \leq 0:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{t_2}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}\\
\mathbf{elif}\;t_6 \leq 10^{+290}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_4\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\sqrt{4 \cdot \left(a \cdot c\right) + \left(\left(b \cdot b + a \cdot \left(c \cdot -4\right)\right) + t_1\right)} - b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t_7\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\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 100
Simplified100
[Start]100 | \[ \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}
\] |
|---|---|
associate-*l* [=>]100 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \color{blue}{4 \cdot \left(a \cdot c\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 [=>]100 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{a \cdot 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
*-commutative [=>]100 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
associate-*l* [=>]100 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\
\end{array}
\] |
Taylor expanded in b around inf 25.92
Taylor expanded in c around 0 25.92
Simplified25.92
[Start]25.92 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{b}{a}\\
\end{array}
\] |
|---|---|
mul-1-neg [=>]25.92 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\] |
distribute-neg-frac [=>]25.92 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\] |
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)))))) < -9.99999999999999934e-276Initial program 3.63
Simplified3.63
[Start]3.63 | \[ \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}
\] |
|---|---|
associate-*l* [=>]3.63 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \color{blue}{4 \cdot \left(a \cdot c\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 [=>]3.63 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{a \cdot 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
*-commutative [=>]3.63 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
associate-*l* [=>]3.63 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\
\end{array}
\] |
if -9.99999999999999934e-276 < (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 57.91
Simplified57.86
[Start]57.91 | \[ \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}
\] |
|---|---|
associate-*l* [=>]57.91 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \color{blue}{4 \cdot \left(a \cdot c\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 [=>]57.91 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{a \cdot 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
*-commutative [=>]57.91 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
associate-*l* [=>]57.86 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\
\end{array}
\] |
Taylor expanded in b around -inf 18.85
Simplified15.53
[Start]18.85 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \left(2 \cdot \frac{c \cdot a}{b} + -1 \cdot b\right)}\\
\end{array}
\] |
|---|---|
fma-def [=>]18.85 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\color{blue}{\left(-b\right) + \mathsf{fma}\left(2, \frac{c \cdot a}{b}, -1 \cdot b\right)}}\\
\end{array}
\] |
associate-/l* [=>]15.53 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \color{blue}{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, -1 \cdot b\right)}}\\
\end{array}
\] |
mul-1-neg [=>]15.53 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, -b\right)}\\
\end{array}
\] |
Taylor expanded in b around 0 15.53
Simplified15.53
[Start]15.53 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{-4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, -b\right)}\\
\end{array}
\] |
|---|---|
*-commutative [<=]15.53 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{-4 \cdot \color{blue}{\left(a \cdot c\right)}}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, -b\right)}\\
\end{array}
\] |
*-commutative [<=]15.53 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\color{blue}{\left(a \cdot c\right) \cdot -4}}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, -b\right)}\\
\end{array}
\] |
*-commutative [=>]15.53 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\color{blue}{\left(c \cdot a\right)} \cdot -4}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, -b\right)}\\
\end{array}
\] |
associate-*l* [=>]15.53 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\color{blue}{c \cdot \left(a \cdot -4\right)}}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, -b\right)}\\
\end{array}
\] |
Taylor expanded in c around 0 15.64
Simplified15.64
[Start]15.64 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\end{array}
\] |
|---|---|
associate-*r/ [=>]15.64 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1 \cdot c}{b}\\
\end{array}
\] |
neg-mul-1 [<=]15.64 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\] |
if -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)))))) < 1.00000000000000006e290Initial program 4.18
Simplified4.19
[Start]4.18 | \[ \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}
\] |
|---|---|
associate-*l* [=>]4.19 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \color{blue}{4 \cdot \left(a \cdot c\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 [=>]4.19 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{a \cdot 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
*-commutative [=>]4.19 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
associate-*l* [=>]4.19 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\
\end{array}
\] |
Applied egg-rr4.2
Applied egg-rr4.19
if 1.00000000000000006e290 < (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 96.58
Simplified96.27
[Start]96.58 | \[ \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}
\] |
|---|---|
associate-*l* [=>]96.42 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \color{blue}{4 \cdot \left(a \cdot c\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 [=>]96.42 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{a \cdot 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
*-commutative [=>]96.42 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\] |
associate-*l* [=>]96.27 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\
\end{array}
\] |
Taylor expanded in b around inf 32.17
Taylor expanded in b around -inf 24.74
Simplified24.74
[Start]24.74 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\end{array}
\] |
|---|---|
mul-1-neg [=>]24.74 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}
\] |
distribute-neg-frac [=>]24.74 | \[ \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\] |
Final simplification9.94
| Alternative 1 | |
|---|---|
| Error | 9.94% |
| Cost | 38052 |
| Alternative 2 | |
|---|---|
| Error | 10.05% |
| Cost | 7952 |
| Alternative 3 | |
|---|---|
| Error | 15.64% |
| Cost | 7888 |
| Alternative 4 | |
|---|---|
| Error | 15.63% |
| Cost | 7888 |
| Alternative 5 | |
|---|---|
| Error | 10.13% |
| Cost | 7888 |
| Alternative 6 | |
|---|---|
| Error | 21.14% |
| Cost | 7760 |
| Alternative 7 | |
|---|---|
| Error | 21.16% |
| Cost | 7696 |
| Alternative 8 | |
|---|---|
| Error | 21.18% |
| Cost | 7632 |
| Alternative 9 | |
|---|---|
| Error | 28.09% |
| Cost | 7368 |
| Alternative 10 | |
|---|---|
| Error | 27.66% |
| Cost | 7368 |
| Alternative 11 | |
|---|---|
| Error | 71.14% |
| Cost | 644 |
| Alternative 12 | |
|---|---|
| Error | 34.85% |
| Cost | 644 |
herbie shell --seed 2023089
(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)))))))