(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- b) a))
(t_1 (sqrt (- (* b b) (* c (* 4.0 a)))))
(t_2 (/ (- t_1 b) (* 2.0 a)))
(t_3 (if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_1)) t_2))
(t_4
(if (>= b 0.0)
(/ (* 2.0 c) (fma -1.0 b (- (sqrt (fma -4.0 (* c a) (* b b))))))
t_2)))
(if (<= t_3 (- INFINITY))
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) (sqrt (* -4.0 (* c a))))) t_0)
(if (<= t_3 -3.404158954114064e-306)
t_4
(if (<= t_3 0.0)
(if (>= b 0.0) (/ (* 2.0 c) (* 2.0 (- (/ (* c a) b) b))) t_2)
(if (<= t_3 2.0351967914969266e+216)
t_4
(if (>= b 0.0)
(- (fma (/ (* c c) (pow b 3.0)) a (/ c b)))
t_0)))))))double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-b - sqrt(((b * b) - ((4.0 * a) * c))));
} else {
tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
return tmp;
}
double code(double a, double b, double c) {
double t_0 = -b / a;
double t_1 = sqrt(((b * b) - (c * (4.0 * a))));
double t_2 = (t_1 - b) / (2.0 * a);
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-b - t_1);
} else {
tmp = t_2;
}
double t_3 = tmp;
double tmp_1;
if (b >= 0.0) {
tmp_1 = (2.0 * c) / fma(-1.0, b, -sqrt(fma(-4.0, (c * a), (b * b))));
} else {
tmp_1 = t_2;
}
double t_4 = tmp_1;
double tmp_3;
if (t_3 <= -((double) INFINITY)) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = (2.0 * c) / (-b - sqrt((-4.0 * (c * a))));
} else {
tmp_4 = t_0;
}
tmp_3 = tmp_4;
} else if (t_3 <= -3.404158954114064e-306) {
tmp_3 = t_4;
} else if (t_3 <= 0.0) {
double tmp_5;
if (b >= 0.0) {
tmp_5 = (2.0 * c) / (2.0 * (((c * a) / b) - b));
} else {
tmp_5 = t_2;
}
tmp_3 = tmp_5;
} else if (t_3 <= 2.0351967914969266e+216) {
tmp_3 = t_4;
} else if (b >= 0.0) {
tmp_3 = -fma(((c * c) / pow(b, 3.0)), a, (c / b));
} else {
tmp_3 = t_0;
}
return tmp_3;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))))); else tmp = Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)); end return tmp end
function code(a, b, c) t_0 = Float64(Float64(-b) / a) t_1 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) t_2 = Float64(Float64(t_1 - b) / Float64(2.0 * a)) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_1)); else tmp = t_2; end t_3 = tmp tmp_1 = 0.0 if (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / fma(-1.0, b, Float64(-sqrt(fma(-4.0, Float64(c * a), Float64(b * b)))))); else tmp_1 = t_2; end t_4 = tmp_1 tmp_3 = 0.0 if (t_3 <= Float64(-Inf)) tmp_4 = 0.0 if (b >= 0.0) tmp_4 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - sqrt(Float64(-4.0 * Float64(c * a))))); else tmp_4 = t_0; end tmp_3 = tmp_4; elseif (t_3 <= -3.404158954114064e-306) tmp_3 = t_4; elseif (t_3 <= 0.0) tmp_5 = 0.0 if (b >= 0.0) tmp_5 = Float64(Float64(2.0 * c) / Float64(2.0 * Float64(Float64(Float64(c * a) / b) - b))); else tmp_5 = t_2; end tmp_3 = tmp_5; elseif (t_3 <= 2.0351967914969266e+216) tmp_3 = t_4; elseif (b >= 0.0) tmp_3 = Float64(-fma(Float64(Float64(c * c) / (b ^ 3.0)), a, Float64(c / b))); else tmp_3 = t_0; end return tmp_3 end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], 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], 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[((-b) / a), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$1 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$1), $MachinePrecision]), $MachinePrecision], t$95$2]}, Block[{t$95$4 = If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(-1.0 * b + (-N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], t$95$2]}, If[LessEqual[t$95$3, (-Infinity)], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0], If[LessEqual[t$95$3, -3.404158954114064e-306], t$95$4, If[LessEqual[t$95$3, 0.0], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(N[(N[(c * a), $MachinePrecision] / b), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2], If[LessEqual[t$95$3, 2.0351967914969266e+216], t$95$4, If[GreaterEqual[b, 0.0], (-N[(N[(N[(c * c), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision] * a + N[(c / b), $MachinePrecision]), $MachinePrecision]), t$95$0]]]]]]]]]]
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\
\end{array}
\begin{array}{l}
t_0 := \frac{-b}{a}\\
t_1 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\
t_2 := \frac{t_1 - b}{2 \cdot a}\\
t_3 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t_1}\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}\\
t_4 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(-1, b, -\sqrt{\mathsf{fma}\left(-4, c \cdot a, b \cdot b\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}\\
\mathbf{if}\;t_3 \leq -\infty:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{-4 \cdot \left(c \cdot a\right)}}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}\\
\mathbf{elif}\;t_3 \leq -3.404158954114064 \cdot 10^{-306}:\\
\;\;\;\;t_4\\
\mathbf{elif}\;t_3 \leq 0:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \left(\frac{c \cdot a}{b} - b\right)}\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}\\
\mathbf{elif}\;t_3 \leq 2.0351967914969266 \cdot 10^{+216}:\\
\;\;\;\;t_4\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-\mathsf{fma}\left(\frac{c \cdot c}{{b}^{3}}, a, \frac{c}{b}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}



Bits error versus a



Bits error versus b



Bits error versus c
if (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < -inf.0Initial program 64.0
Taylor expanded in b around -inf 18.8
Taylor expanded in b around 0 18.7
Taylor expanded in b around 0 18.7
if -inf.0 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < -3.4041589541140641e-306 or 0.0 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < 2.03519679149692657e216Initial program 2.5
Applied egg-rr2.6
Applied egg-rr2.5
if -3.4041589541140641e-306 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < 0.0Initial program 37.4
Applied egg-rr37.4
Taylor expanded in b around inf 12.2
Simplified12.2
if 2.03519679149692657e216 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) Initial program 48.9
Taylor expanded in b around -inf 19.8
Taylor expanded in b around 0 19.6
Taylor expanded in c around 0 21.5
Simplified19.8
Final simplification7.7
herbie shell --seed 2022131
(FPCore (a b c)
:name "jeff quadratic root 2"
:precision binary64
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))