
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (- (- b) t_0) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) t_0)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (-b - t_0) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + t_0);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b >= 0.0d0) then
tmp = (-b - t_0) / (2.0d0 * a)
else
tmp = (2.0d0 * c) / (-b + t_0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (-b - t_0) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + t_0);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b >= 0.0: tmp = (-b - t_0) / (2.0 * a) else: tmp = (2.0 * c) / (-b + t_0) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)); else tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) + t_0)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((4.0 * a) * c))); tmp = 0.0; if (b >= 0.0) tmp = (-b - t_0) / (2.0 * a); else tmp = (2.0 * c) / (-b + t_0); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + t_0}\\
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (- (- b) t_0) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) t_0)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (-b - t_0) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + t_0);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b >= 0.0d0) then
tmp = (-b - t_0) / (2.0d0 * a)
else
tmp = (2.0d0 * c) / (-b + t_0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (-b - t_0) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + t_0);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b >= 0.0: tmp = (-b - t_0) / (2.0 * a) else: tmp = (2.0 * c) / (-b + t_0) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)); else tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) + t_0)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((4.0 * a) * c))); tmp = 0.0; if (b >= 0.0) tmp = (-b - t_0) / (2.0 * a); else tmp = (2.0 * c) / (-b + t_0); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + t_0}\\
\end{array}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* -0.5 (/ (+ b b) a)))
(t_1 (* c (* a 4.0)))
(t_2 (sqrt (- (* b b) t_1)))
(t_3 (* a (* c -4.0)))
(t_4 (sqrt (fma b b t_3))))
(if (<= b -1.3e+87)
(if (>= b 0.0) t_0 (/ (* c 2.0) (fma -2.0 b (* 2.0 (* c (/ a b))))))
(if (<= b 2.9e-298)
(if (>= b 0.0)
(/ (* t_1 (/ 1.0 (+ b t_2))) (* a 2.0))
(/ (* c 2.0) (- t_2 b)))
(if (<= b 2.6e-163)
(if (>= b 0.0)
(* -0.5 (/ 1.0 (/ a (+ b (hypot b (sqrt t_3))))))
(/ (* c 2.0) (fma -2.0 b (* 2.0 (/ a (/ b c))))))
(if (<= b 980.0)
(if (>= b 0.0) (* -0.5 (/ (+ b t_4) a)) (/ (* c 2.0) (- t_4 b)))
(if (>= b 0.0) t_0 (/ (- c) b))))))))
double code(double a, double b, double c) {
double t_0 = -0.5 * ((b + b) / a);
double t_1 = c * (a * 4.0);
double t_2 = sqrt(((b * b) - t_1));
double t_3 = a * (c * -4.0);
double t_4 = sqrt(fma(b, b, t_3));
double tmp_1;
if (b <= -1.3e+87) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (c * 2.0) / fma(-2.0, b, (2.0 * (c * (a / b))));
}
tmp_1 = tmp_2;
} else if (b <= 2.9e-298) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (t_1 * (1.0 / (b + t_2))) / (a * 2.0);
} else {
tmp_3 = (c * 2.0) / (t_2 - b);
}
tmp_1 = tmp_3;
} else if (b <= 2.6e-163) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = -0.5 * (1.0 / (a / (b + hypot(b, sqrt(t_3)))));
} else {
tmp_4 = (c * 2.0) / fma(-2.0, b, (2.0 * (a / (b / c))));
}
tmp_1 = tmp_4;
} else if (b <= 980.0) {
double tmp_5;
if (b >= 0.0) {
tmp_5 = -0.5 * ((b + t_4) / a);
} else {
tmp_5 = (c * 2.0) / (t_4 - b);
}
tmp_1 = tmp_5;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = -c / b;
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(-0.5 * Float64(Float64(b + b) / a)) t_1 = Float64(c * Float64(a * 4.0)) t_2 = sqrt(Float64(Float64(b * b) - t_1)) t_3 = Float64(a * Float64(c * -4.0)) t_4 = sqrt(fma(b, b, t_3)) tmp_1 = 0.0 if (b <= -1.3e+87) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(c * 2.0) / fma(-2.0, b, Float64(2.0 * Float64(c * Float64(a / b))))); end tmp_1 = tmp_2; elseif (b <= 2.9e-298) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(t_1 * Float64(1.0 / Float64(b + t_2))) / Float64(a * 2.0)); else tmp_3 = Float64(Float64(c * 2.0) / Float64(t_2 - b)); end tmp_1 = tmp_3; elseif (b <= 2.6e-163) tmp_4 = 0.0 if (b >= 0.0) tmp_4 = Float64(-0.5 * Float64(1.0 / Float64(a / Float64(b + hypot(b, sqrt(t_3)))))); else tmp_4 = Float64(Float64(c * 2.0) / fma(-2.0, b, Float64(2.0 * Float64(a / Float64(b / c))))); end tmp_1 = tmp_4; elseif (b <= 980.0) tmp_5 = 0.0 if (b >= 0.0) tmp_5 = Float64(-0.5 * Float64(Float64(b + t_4) / a)); else tmp_5 = Float64(Float64(c * 2.0) / Float64(t_4 - b)); end tmp_1 = tmp_5; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(-c) / b); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(-0.5 * N[(N[(b + b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$1), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[Sqrt[N[(b * b + t$95$3), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -1.3e+87], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b + N[(2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2.9e-298], If[GreaterEqual[b, 0.0], N[(N[(t$95$1 * N[(1.0 / N[(b + t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$2 - b), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2.6e-163], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(1.0 / N[(a / N[(b + N[Sqrt[b ^ 2 + N[Sqrt[t$95$3], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b + N[(2.0 * N[(a / N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 980.0], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[(b + t$95$4), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$4 - b), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[((-c) / b), $MachinePrecision]]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -0.5 \cdot \frac{b + b}{a}\\
t_1 := c \cdot \left(a \cdot 4\right)\\
t_2 := \sqrt{b \cdot b - t_1}\\
t_3 := a \cdot \left(c \cdot -4\right)\\
t_4 := \sqrt{\mathsf{fma}\left(b, b, t_3\right)}\\
\mathbf{if}\;b \leq -1.3 \cdot 10^{+87}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(-2, b, 2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.9 \cdot 10^{-298}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{t_1 \cdot \frac{1}{b + t_2}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t_2 - b}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{-163}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{1}{\frac{a}{b + \mathsf{hypot}\left(b, \sqrt{t_3}\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(-2, b, 2 \cdot \frac{a}{\frac{b}{c}}\right)}\\
\end{array}\\
\mathbf{elif}\;b \leq 980:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{b + t_4}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t_4 - b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.29999999999999999e87Initial program 57.3%
Simplified57.3%
Taylor expanded in b around -inf 89.3%
fma-def89.3%
associate-/l*94.9%
Simplified94.9%
Taylor expanded in b around inf 94.9%
associate-*r/94.9%
count-294.9%
Simplified94.9%
associate-/r/94.9%
Applied egg-rr94.9%
if -1.29999999999999999e87 < b < 2.90000000000000015e-298Initial program 95.0%
flip--95.0%
div-inv95.0%
sqr-neg95.0%
add-sqr-sqrt95.0%
*-commutative95.0%
*-commutative95.0%
add-sqr-sqrt92.5%
sqrt-unprod95.0%
sqr-neg95.0%
sqrt-prod95.0%
add-sqr-sqrt95.0%
*-commutative95.0%
*-commutative95.0%
Applied egg-rr95.0%
Taylor expanded in b around 0 95.0%
associate-*r*95.0%
*-commutative95.0%
*-commutative95.0%
Simplified95.0%
if 2.90000000000000015e-298 < b < 2.60000000000000002e-163Initial program 76.0%
Simplified76.0%
Taylor expanded in b around -inf 76.0%
fma-def76.0%
associate-/l*76.0%
Simplified76.0%
clear-num76.0%
inv-pow76.0%
fma-udef76.0%
add-sqr-sqrt76.0%
hypot-def89.8%
Applied egg-rr89.8%
unpow-189.8%
*-commutative89.8%
Simplified89.8%
if 2.60000000000000002e-163 < b < 980Initial program 95.2%
Simplified95.2%
if 980 < b Initial program 70.0%
Simplified70.0%
Taylor expanded in b around -inf 70.0%
fma-def70.0%
associate-/l*70.0%
Simplified70.0%
Taylor expanded in b around inf 95.9%
associate-*r/95.9%
count-295.9%
Simplified95.9%
Taylor expanded in c around 0 95.9%
Final simplification94.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* a (* c -4.0))) (t_1 (* -0.5 (/ (+ b b) a))))
(if (<= b -1.3e+87)
(if (>= b 0.0) t_1 (/ (* c 2.0) (fma -2.0 b (* 2.0 (* c (/ a b))))))
(if (<= b 9.6e-6)
(if (>= b 0.0)
(* -0.5 (/ (exp (log (+ b (hypot b (sqrt t_0))))) a))
(/ (* c 2.0) (- (sqrt (fma b b t_0)) b)))
(if (>= b 0.0) t_1 (/ (- c) b))))))
double code(double a, double b, double c) {
double t_0 = a * (c * -4.0);
double t_1 = -0.5 * ((b + b) / a);
double tmp_1;
if (b <= -1.3e+87) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = (c * 2.0) / fma(-2.0, b, (2.0 * (c * (a / b))));
}
tmp_1 = tmp_2;
} else if (b <= 9.6e-6) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = -0.5 * (exp(log((b + hypot(b, sqrt(t_0))))) / a);
} else {
tmp_3 = (c * 2.0) / (sqrt(fma(b, b, t_0)) - b);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_1;
} else {
tmp_1 = -c / b;
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(a * Float64(c * -4.0)) t_1 = Float64(-0.5 * Float64(Float64(b + b) / a)) tmp_1 = 0.0 if (b <= -1.3e+87) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = Float64(Float64(c * 2.0) / fma(-2.0, b, Float64(2.0 * Float64(c * Float64(a / b))))); end tmp_1 = tmp_2; elseif (b <= 9.6e-6) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(-0.5 * Float64(exp(log(Float64(b + hypot(b, sqrt(t_0))))) / a)); else tmp_3 = Float64(Float64(c * 2.0) / Float64(sqrt(fma(b, b, t_0)) - b)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_1; else tmp_1 = Float64(Float64(-c) / b); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-0.5 * N[(N[(b + b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.3e+87], If[GreaterEqual[b, 0.0], t$95$1, N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b + N[(2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 9.6e-6], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[Exp[N[Log[N[(b + N[Sqrt[b ^ 2 + N[Sqrt[t$95$0], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(N[Sqrt[N[(b * b + t$95$0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$1, N[((-c) / b), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \left(c \cdot -4\right)\\
t_1 := -0.5 \cdot \frac{b + b}{a}\\
\mathbf{if}\;b \leq -1.3 \cdot 10^{+87}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(-2, b, 2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}\\
\end{array}\\
\mathbf{elif}\;b \leq 9.6 \cdot 10^{-6}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{e^{\log \left(b + \mathsf{hypot}\left(b, \sqrt{t_0}\right)\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\sqrt{\mathsf{fma}\left(b, b, t_0\right)} - b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.29999999999999999e87Initial program 57.3%
Simplified57.3%
Taylor expanded in b around -inf 89.3%
fma-def89.3%
associate-/l*94.9%
Simplified94.9%
Taylor expanded in b around inf 94.9%
associate-*r/94.9%
count-294.9%
Simplified94.9%
associate-/r/94.9%
Applied egg-rr94.9%
if -1.29999999999999999e87 < b < 9.5999999999999996e-6Initial program 90.8%
Simplified90.9%
add-sqr-sqrt90.8%
sqrt-prod90.2%
sqr-neg90.2%
sqrt-unprod56.8%
add-sqr-sqrt84.3%
add-exp-log82.5%
add-sqr-sqrt56.8%
sqrt-unprod88.1%
sqr-neg88.1%
sqrt-prod88.7%
add-sqr-sqrt88.7%
fma-udef88.7%
add-sqr-sqrt88.7%
hypot-def91.4%
Applied egg-rr91.4%
if 9.5999999999999996e-6 < b Initial program 70.0%
Simplified70.0%
Taylor expanded in b around -inf 70.0%
fma-def70.0%
associate-/l*70.0%
Simplified70.0%
Taylor expanded in b around inf 95.9%
associate-*r/95.9%
count-295.9%
Simplified95.9%
Taylor expanded in c around 0 95.9%
Final simplification93.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* -0.5 (/ (+ b b) a))) (t_1 (sqrt (fma b b (* a (* c -4.0))))))
(if (<= b -1e+87)
(if (>= b 0.0) t_0 (/ (* c 2.0) (fma -2.0 b (* 2.0 (* c (/ a b))))))
(if (<= b 980.0)
(if (>= b 0.0) (* -0.5 (/ (+ b t_1) a)) (/ (* c 2.0) (- t_1 b)))
(if (>= b 0.0) t_0 (/ (- c) b))))))
double code(double a, double b, double c) {
double t_0 = -0.5 * ((b + b) / a);
double t_1 = sqrt(fma(b, b, (a * (c * -4.0))));
double tmp_1;
if (b <= -1e+87) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (c * 2.0) / fma(-2.0, b, (2.0 * (c * (a / b))));
}
tmp_1 = tmp_2;
} else if (b <= 980.0) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = -0.5 * ((b + t_1) / a);
} else {
tmp_3 = (c * 2.0) / (t_1 - b);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = -c / b;
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(-0.5 * Float64(Float64(b + b) / a)) t_1 = sqrt(fma(b, b, Float64(a * Float64(c * -4.0)))) tmp_1 = 0.0 if (b <= -1e+87) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(c * 2.0) / fma(-2.0, b, Float64(2.0 * Float64(c * Float64(a / b))))); end tmp_1 = tmp_2; elseif (b <= 980.0) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(-0.5 * Float64(Float64(b + t_1) / a)); else tmp_3 = Float64(Float64(c * 2.0) / Float64(t_1 - b)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(-c) / b); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(-0.5 * N[(N[(b + b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(b * b + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -1e+87], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b + N[(2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 980.0], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[(b + t$95$1), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$1 - b), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[((-c) / b), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -0.5 \cdot \frac{b + b}{a}\\
t_1 := \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)}\\
\mathbf{if}\;b \leq -1 \cdot 10^{+87}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(-2, b, 2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}\\
\end{array}\\
\mathbf{elif}\;b \leq 980:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{b + t_1}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t_1 - b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.9999999999999996e86Initial program 57.3%
Simplified57.3%
Taylor expanded in b around -inf 89.3%
fma-def89.3%
associate-/l*94.9%
Simplified94.9%
Taylor expanded in b around inf 94.9%
associate-*r/94.9%
count-294.9%
Simplified94.9%
associate-/r/94.9%
Applied egg-rr94.9%
if -9.9999999999999996e86 < b < 980Initial program 90.8%
Simplified90.9%
if 980 < b Initial program 70.0%
Simplified70.0%
Taylor expanded in b around -inf 70.0%
fma-def70.0%
associate-/l*70.0%
Simplified70.0%
Taylor expanded in b around inf 95.9%
associate-*r/95.9%
count-295.9%
Simplified95.9%
Taylor expanded in c around 0 95.9%
Final simplification93.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* -0.5 (/ (+ b b) a))) (t_1 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (<= b -1.3e+87)
(if (>= b 0.0) t_0 (/ (* c 2.0) (fma -2.0 b (* 2.0 (* c (/ a b))))))
(if (<= b 980.0)
(if (>= b 0.0) (/ (- (- b) t_1) (* a 2.0)) (/ (* c 2.0) (- t_1 b)))
(if (>= b 0.0) t_0 (/ (- c) b))))))
double code(double a, double b, double c) {
double t_0 = -0.5 * ((b + b) / a);
double t_1 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -1.3e+87) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (c * 2.0) / fma(-2.0, b, (2.0 * (c * (a / b))));
}
tmp_1 = tmp_2;
} else if (b <= 980.0) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-b - t_1) / (a * 2.0);
} else {
tmp_3 = (c * 2.0) / (t_1 - b);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = -c / b;
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(-0.5 * Float64(Float64(b + b) / a)) t_1 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) tmp_1 = 0.0 if (b <= -1.3e+87) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(c * 2.0) / fma(-2.0, b, Float64(2.0 * Float64(c * Float64(a / b))))); end tmp_1 = tmp_2; elseif (b <= 980.0) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(Float64(-b) - t_1) / Float64(a * 2.0)); else tmp_3 = Float64(Float64(c * 2.0) / Float64(t_1 - b)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(-c) / b); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(-0.5 * N[(N[(b + b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -1.3e+87], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b + N[(2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 980.0], If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$1), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$1 - b), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[((-c) / b), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -0.5 \cdot \frac{b + b}{a}\\
t_1 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -1.3 \cdot 10^{+87}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(-2, b, 2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}\\
\end{array}\\
\mathbf{elif}\;b \leq 980:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_1}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t_1 - b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.29999999999999999e87Initial program 57.3%
Simplified57.3%
Taylor expanded in b around -inf 89.3%
fma-def89.3%
associate-/l*94.9%
Simplified94.9%
Taylor expanded in b around inf 94.9%
associate-*r/94.9%
count-294.9%
Simplified94.9%
associate-/r/94.9%
Applied egg-rr94.9%
if -1.29999999999999999e87 < b < 980Initial program 90.8%
if 980 < b Initial program 70.0%
Simplified70.0%
Taylor expanded in b around -inf 70.0%
fma-def70.0%
associate-/l*70.0%
Simplified70.0%
Taylor expanded in b around inf 95.9%
associate-*r/95.9%
count-295.9%
Simplified95.9%
Taylor expanded in c around 0 95.9%
Final simplification93.1%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* -0.5 (fma -2.0 (/ c b) (/ (+ b b) a))) (/ (* c 2.0) (fma -2.0 b (* 2.0 (* c (/ a b)))))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -0.5 * fma(-2.0, (c / b), ((b + b) / a));
} else {
tmp = (c * 2.0) / fma(-2.0, b, (2.0 * (c * (a / b))));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(-0.5 * fma(-2.0, Float64(c / b), Float64(Float64(b + b) / a))); else tmp = Float64(Float64(c * 2.0) / fma(-2.0, b, Float64(2.0 * Float64(c * Float64(a / b))))); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(-0.5 * N[(-2.0 * N[(c / b), $MachinePrecision] + N[(N[(b + b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b + N[(2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \mathsf{fma}\left(-2, \frac{c}{b}, \frac{b + b}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(-2, b, 2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}\\
\end{array}
\end{array}
Initial program 78.1%
Simplified78.1%
Taylor expanded in b around -inf 70.5%
fma-def70.5%
associate-/l*71.6%
Simplified71.6%
Taylor expanded in b around inf 67.0%
fma-def67.0%
associate-*r/67.0%
count-267.0%
Simplified67.0%
associate-/r/67.0%
Applied egg-rr67.1%
Final simplification67.1%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* -0.5 (/ (+ b b) a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -0.5 * ((b + b) / a);
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b >= 0.0d0) then
tmp = (-0.5d0) * ((b + b) / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -0.5 * ((b + b) / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -0.5 * ((b + b) / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(-0.5 * Float64(Float64(b + b) / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -0.5 * ((b + b) / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[(b + b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{b + b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
Initial program 78.1%
Simplified78.1%
Taylor expanded in b around -inf 70.5%
fma-def70.5%
associate-/l*71.6%
Simplified71.6%
Taylor expanded in b around inf 66.9%
associate-*r/66.9%
count-266.9%
Simplified66.9%
Taylor expanded in c around 0 67.0%
Final simplification67.0%
herbie shell --seed 2023293
(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)))))))