(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
(if (>= b 0.0) (/ (- (- b) t_0) (* a 2.0)) (/ (* c 2.0) (- t_0 b))))
(t_2 (/ (- (- b) b) (* a 2.0)))
(t_3 (if (>= b 0.0) t_2 (- (/ c b)))))
(if (<= t_1 (- INFINITY))
(if (>= b 0.0) t_2 (/ (* c 2.0) (- (sqrt (* (* a c) -4.0)) b)))
(if (<= t_1 -5e-302)
t_1
(if (<= t_1 0.0) t_3 (if (<= t_1 1e+293) t_1 t_3))))))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 tmp;
if (b >= 0.0) {
tmp = (-b - t_0) / (a * 2.0);
} else {
tmp = (c * 2.0) / (t_0 - b);
}
double t_1 = tmp;
double t_2 = (-b - b) / (a * 2.0);
double tmp_1;
if (b >= 0.0) {
tmp_1 = t_2;
} else {
tmp_1 = -(c / b);
}
double t_3 = tmp_1;
double tmp_3;
if (t_1 <= -((double) INFINITY)) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = t_2;
} else {
tmp_4 = (c * 2.0) / (sqrt(((a * c) * -4.0)) - b);
}
tmp_3 = tmp_4;
} else if (t_1 <= -5e-302) {
tmp_3 = t_1;
} else if (t_1 <= 0.0) {
tmp_3 = t_3;
} else if (t_1 <= 1e+293) {
tmp_3 = t_1;
} else {
tmp_3 = t_3;
}
return tmp_3;
}
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 tmp;
if (b >= 0.0) {
tmp = (-b - t_0) / (a * 2.0);
} else {
tmp = (c * 2.0) / (t_0 - b);
}
double t_1 = tmp;
double t_2 = (-b - b) / (a * 2.0);
double tmp_1;
if (b >= 0.0) {
tmp_1 = t_2;
} else {
tmp_1 = -(c / b);
}
double t_3 = tmp_1;
double tmp_3;
if (t_1 <= -Double.POSITIVE_INFINITY) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = t_2;
} else {
tmp_4 = (c * 2.0) / (Math.sqrt(((a * c) * -4.0)) - b);
}
tmp_3 = tmp_4;
} else if (t_1 <= -5e-302) {
tmp_3 = t_1;
} else if (t_1 <= 0.0) {
tmp_3 = t_3;
} else if (t_1 <= 1e+293) {
tmp_3 = t_1;
} else {
tmp_3 = t_3;
}
return tmp_3;
}
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)))) tmp = 0 if b >= 0.0: tmp = (-b - t_0) / (a * 2.0) else: tmp = (c * 2.0) / (t_0 - b) t_1 = tmp t_2 = (-b - b) / (a * 2.0) tmp_1 = 0 if b >= 0.0: tmp_1 = t_2 else: tmp_1 = -(c / b) t_3 = tmp_1 tmp_3 = 0 if t_1 <= -math.inf: tmp_4 = 0 if b >= 0.0: tmp_4 = t_2 else: tmp_4 = (c * 2.0) / (math.sqrt(((a * c) * -4.0)) - b) tmp_3 = tmp_4 elif t_1 <= -5e-302: tmp_3 = t_1 elif t_1 <= 0.0: tmp_3 = t_3 elif t_1 <= 1e+293: tmp_3 = t_1 else: tmp_3 = t_3 return tmp_3
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)))) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(Float64(-b) - t_0) / Float64(a * 2.0)); else tmp = Float64(Float64(c * 2.0) / Float64(t_0 - b)); end t_1 = tmp t_2 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)) tmp_1 = 0.0 if (b >= 0.0) tmp_1 = t_2; else tmp_1 = Float64(-Float64(c / b)); end t_3 = tmp_1 tmp_3 = 0.0 if (t_1 <= Float64(-Inf)) tmp_4 = 0.0 if (b >= 0.0) tmp_4 = t_2; else tmp_4 = Float64(Float64(c * 2.0) / Float64(sqrt(Float64(Float64(a * c) * -4.0)) - b)); end tmp_3 = tmp_4; elseif (t_1 <= -5e-302) tmp_3 = t_1; elseif (t_1 <= 0.0) tmp_3 = t_3; elseif (t_1 <= 1e+293) tmp_3 = t_1; else tmp_3 = t_3; end return tmp_3 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)))); tmp = 0.0; if (b >= 0.0) tmp = (-b - t_0) / (a * 2.0); else tmp = (c * 2.0) / (t_0 - b); end t_1 = tmp; t_2 = (-b - b) / (a * 2.0); tmp_2 = 0.0; if (b >= 0.0) tmp_2 = t_2; else tmp_2 = -(c / b); end t_3 = tmp_2; tmp_4 = 0.0; if (t_1 <= -Inf) tmp_5 = 0.0; if (b >= 0.0) tmp_5 = t_2; else tmp_5 = (c * 2.0) / (sqrt(((a * c) * -4.0)) - b); end tmp_4 = tmp_5; elseif (t_1 <= -5e-302) tmp_4 = t_1; elseif (t_1 <= 0.0) tmp_4 = t_3; elseif (t_1 <= 1e+293) tmp_4 = t_1; else tmp_4 = t_3; end tmp_6 = tmp_4; 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 = If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$0 - b), $MachinePrecision]), $MachinePrecision]]}, Block[{t$95$2 = N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = If[GreaterEqual[b, 0.0], t$95$2, (-N[(c / b), $MachinePrecision])]}, If[LessEqual[t$95$1, (-Infinity)], If[GreaterEqual[b, 0.0], t$95$2, N[(N[(c * 2.0), $MachinePrecision] / N[(N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]], If[LessEqual[t$95$1, -5e-302], t$95$1, If[LessEqual[t$95$1, 0.0], t$95$3, If[LessEqual[t$95$1, 1e+293], t$95$1, t$95$3]]]]]]]]
\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 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t_0 - b}\\
\end{array}\\
t_2 := \frac{\left(-b\right) - b}{a \cdot 2}\\
t_3 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\sqrt{\left(a \cdot c\right) \cdot -4} - b}\\
\end{array}\\
\mathbf{elif}\;t_1 \leq -5 \cdot 10^{-302}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t_1 \leq 10^{+293}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_3\\
\end{array}



Bits error versus a



Bits error versus b



Bits error versus c
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 18.0
Taylor expanded in b around 0 18.0
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)))))) < -5.00000000000000033e-302 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)))))) < 9.9999999999999992e292Initial program 2.8
if -5.00000000000000033e-302 < (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.0 or 9.9999999999999992e292 < (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 43.3
Taylor expanded in b around inf 31.8
Taylor expanded in b around -inf 11.0
Final simplification6.5
herbie shell --seed 2022159
(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)))))))