(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 2.0) (- (- b) b)))
(t_1 (sqrt (fma a (* c -4.0) (* b b))))
(t_2 (+ b t_1))
(t_3 (if (>= b 0.0) (* -0.5 (* 2.0 (/ b a))) t_0))
(t_4 (sqrt (- (* b b) (* (* 4.0 a) c))))
(t_5
(if (>= b 0.0) (/ (- (- b) t_4) (* a 2.0)) (/ (* c 2.0) (- t_4 b))))
(t_6 (if (>= b 0.0) (* -0.5 (/ t_2 a)) (/ (* c 2.0) (- t_1 b)))))
(if (<= t_5 (- INFINITY))
t_3
(if (<= t_5 -1.9483279597902858e-234)
t_6
(if (<= t_5 0.0)
(if (>= b 0.0)
(* -0.5 (* (/ 1.0 (pow (cbrt a) 2.0)) (/ t_2 (cbrt a))))
t_0)
(if (<= t_5 2.2466067908429286e+266) t_6 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 = (c * 2.0) / (-b - b);
double t_1 = sqrt(fma(a, (c * -4.0), (b * b)));
double t_2 = b + t_1;
double tmp;
if (b >= 0.0) {
tmp = -0.5 * (2.0 * (b / a));
} else {
tmp = t_0;
}
double t_3 = tmp;
double t_4 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp_1;
if (b >= 0.0) {
tmp_1 = (-b - t_4) / (a * 2.0);
} else {
tmp_1 = (c * 2.0) / (t_4 - b);
}
double t_5 = tmp_1;
double tmp_2;
if (b >= 0.0) {
tmp_2 = -0.5 * (t_2 / a);
} else {
tmp_2 = (c * 2.0) / (t_1 - b);
}
double t_6 = tmp_2;
double tmp_3;
if (t_5 <= -((double) INFINITY)) {
tmp_3 = t_3;
} else if (t_5 <= -1.9483279597902858e-234) {
tmp_3 = t_6;
} else if (t_5 <= 0.0) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = -0.5 * ((1.0 / pow(cbrt(a), 2.0)) * (t_2 / cbrt(a)));
} else {
tmp_4 = t_0;
}
tmp_3 = tmp_4;
} else if (t_5 <= 2.2466067908429286e+266) {
tmp_3 = t_6;
} 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 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - b)) t_1 = sqrt(fma(a, Float64(c * -4.0), Float64(b * b))) t_2 = Float64(b + t_1) tmp = 0.0 if (b >= 0.0) tmp = Float64(-0.5 * Float64(2.0 * Float64(b / a))); else tmp = t_0; end t_3 = tmp t_4 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp_1 = 0.0 if (b >= 0.0) tmp_1 = Float64(Float64(Float64(-b) - t_4) / Float64(a * 2.0)); else tmp_1 = Float64(Float64(c * 2.0) / Float64(t_4 - b)); end t_5 = tmp_1 tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(-0.5 * Float64(t_2 / a)); else tmp_2 = Float64(Float64(c * 2.0) / Float64(t_1 - b)); end t_6 = tmp_2 tmp_3 = 0.0 if (t_5 <= Float64(-Inf)) tmp_3 = t_3; elseif (t_5 <= -1.9483279597902858e-234) tmp_3 = t_6; elseif (t_5 <= 0.0) tmp_4 = 0.0 if (b >= 0.0) tmp_4 = Float64(-0.5 * Float64(Float64(1.0 / (cbrt(a) ^ 2.0)) * Float64(t_2 / cbrt(a)))); else tmp_4 = t_0; end tmp_3 = tmp_4; elseif (t_5 <= 2.2466067908429286e+266) tmp_3 = t_6; else tmp_3 = t_3; end return 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[(N[(c * 2.0), $MachinePrecision] / N[((-b) - b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(b + t$95$1), $MachinePrecision]}, Block[{t$95$3 = If[GreaterEqual[b, 0.0], N[(-0.5 * N[(2.0 * N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]}, Block[{t$95$4 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$5 = If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$4), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$4 - b), $MachinePrecision]), $MachinePrecision]]}, Block[{t$95$6 = If[GreaterEqual[b, 0.0], N[(-0.5 * N[(t$95$2 / a), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$1 - b), $MachinePrecision]), $MachinePrecision]]}, If[LessEqual[t$95$5, (-Infinity)], t$95$3, If[LessEqual[t$95$5, -1.9483279597902858e-234], t$95$6, If[LessEqual[t$95$5, 0.0], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[(1.0 / N[Power[N[Power[a, 1/3], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(t$95$2 / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0], If[LessEqual[t$95$5, 2.2466067908429286e+266], t$95$6, 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 := \frac{c \cdot 2}{\left(-b\right) - b}\\
t_1 := \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\\
t_2 := b + t_1\\
t_3 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{b}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}\\
t_4 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
t_5 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_4}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t_4 - b}\\
\end{array}\\
t_6 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{t_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t_1 - b}\\
\end{array}\\
\mathbf{if}\;t_5 \leq -\infty:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t_5 \leq -1.9483279597902858 \cdot 10^{-234}:\\
\;\;\;\;t_6\\
\mathbf{elif}\;t_5 \leq 0:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \left(\frac{1}{{\left(\sqrt[3]{a}\right)}^{2}} \cdot \frac{t_2}{\sqrt[3]{a}}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}\\
\mathbf{elif}\;t_5 \leq 2.2466067908429286 \cdot 10^{+266}:\\
\;\;\;\;t_6\\
\mathbf{else}:\\
\;\;\;\;t_3\\
\end{array}



Bits error versus a



Bits error versus b



Bits error versus c
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.0 or 2.24660679084292859e266 < (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 60.5
Simplified60.3
Taylor expanded in b around -inf 58.8
Taylor expanded in b around inf 16.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)))))) < -1.94832795979028585e-234 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.24660679084292859e266Initial program 2.9
Simplified2.9
if -1.94832795979028585e-234 < (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 35.3
Simplified35.3
Taylor expanded in b around -inf 10.2
Applied egg-rr10.2
Final simplification6.9
herbie shell --seed 2022131
(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)))))))