
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (+ (- b) t_0) (* 2.0 a)))))
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 = (2.0 * c) / (-b - t_0);
} else {
tmp = (-b + t_0) / (2.0 * a);
}
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 = (2.0d0 * c) / (-b - t_0)
else
tmp = (-b + t_0) / (2.0d0 * a)
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 = (2.0 * c) / (-b - t_0);
} else {
tmp = (-b + t_0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b >= 0.0: tmp = (2.0 * c) / (-b - t_0) else: tmp = (-b + t_0) / (2.0 * a) 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(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); 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 = (2.0 * c) / (-b - t_0); else tmp = (-b + t_0) / (2.0 * a); 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[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $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{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + t\_0}{2 \cdot a}\\
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (+ (- b) t_0) (* 2.0 a)))))
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 = (2.0 * c) / (-b - t_0);
} else {
tmp = (-b + t_0) / (2.0 * a);
}
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 = (2.0d0 * c) / (-b - t_0)
else
tmp = (-b + t_0) / (2.0d0 * a)
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 = (2.0 * c) / (-b - t_0);
} else {
tmp = (-b + t_0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b >= 0.0: tmp = (2.0 * c) / (-b - t_0) else: tmp = (-b + t_0) / (2.0 * a) 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(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); 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 = (2.0 * c) / (-b - t_0); else tmp = (-b + t_0) / (2.0 * a); 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[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $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{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + t\_0}{2 \cdot a}\\
\end{array}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (or (<= b -2e+153) (not (<= b 2.1e+126)))
(if (>= b 0.0)
(/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b))))
(/ (- (- b) b) (* 2.0 a)))
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (- t_0 b) (* 2.0 a))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if ((b <= -2e+153) || !(b <= 2.1e+126)) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
} else {
tmp_2 = (-b - b) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / (-b - t_0);
} else {
tmp_1 = (t_0 - b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) tmp_1 = 0.0 if ((b <= -2e+153) || !(b <= 2.1e+126)) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))); else tmp_2 = Float64(Float64(Float64(-b) - b) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp_1 = Float64(Float64(t_0 - b) / Float64(2.0 * a)); end return tmp_1 end
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]}, If[Or[LessEqual[b, -2e+153], N[Not[LessEqual[b, 2.1e+126]], $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -2 \cdot 10^{+153} \lor \neg \left(b \leq 2.1 \cdot 10^{+126}\right):\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -2e153 or 2.0999999999999999e126 < b Initial program 48.9%
Taylor expanded in a around 0 66.2%
distribute-lft-out--66.2%
associate-/l*70.4%
fma-neg70.4%
Simplified70.4%
add-cbrt-cube70.4%
pow370.4%
pow1/270.4%
metadata-eval70.4%
pow-pow70.4%
pow270.4%
associate-*l*70.4%
metadata-eval70.4%
metadata-eval70.4%
Applied egg-rr70.4%
Taylor expanded in b around -inf 98.0%
if -2e153 < b < 2.0999999999999999e126Initial program 83.4%
Final simplification88.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b))))))
(if (<= b -2e+155)
(if (>= b 0.0) t_0 (/ (- (- b) b) (* 2.0 a)))
(if (<= b 1.25e-27)
(if (>= b 0.0)
(/ -1.0 (/ b c))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a)))
(if (>= b 0.0) t_0 (/ (- (+ b (* -2.0 (/ (* c a) b))) b) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
double tmp_1;
if (b <= -2e+155) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (-b - b) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 1.25e-27) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = -1.0 / (b / c);
} else {
tmp_3 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = ((b + (-2.0 * ((c * a) / b))) - b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))) tmp_1 = 0.0 if (b <= -2e+155) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(Float64(-b) - b) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b <= 1.25e-27) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(-1.0 / Float64(b / c)); else tmp_3 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(2.0 * a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(Float64(b + Float64(-2.0 * Float64(Float64(c * a) / b))) - b) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2e+155], If[GreaterEqual[b, 0.0], t$95$0, N[(N[((-b) - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 1.25e-27], If[GreaterEqual[b, 0.0], N[(-1.0 / N[(b / c), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(N[(b + N[(-2.0 * N[(N[(c * a), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{if}\;b \leq -2 \cdot 10^{+155}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{-27}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-1}{\frac{b}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(b + -2 \cdot \frac{c \cdot a}{b}\right) - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -2.00000000000000001e155Initial program 36.6%
Taylor expanded in a around 0 36.6%
distribute-lft-out--36.6%
associate-/l*36.6%
fma-neg36.6%
Simplified36.6%
add-cbrt-cube36.6%
pow336.6%
pow1/236.6%
metadata-eval36.6%
pow-pow36.6%
pow236.6%
associate-*l*36.6%
metadata-eval36.6%
metadata-eval36.6%
Applied egg-rr36.6%
Taylor expanded in b around -inf 97.8%
if -2.00000000000000001e155 < b < 1.25e-27Initial program 83.8%
Taylor expanded in a around 0 63.9%
distribute-lft-out--63.9%
associate-/l*63.7%
fma-neg63.7%
Simplified63.7%
clear-num63.7%
inv-pow63.7%
Applied egg-rr63.7%
unpow-163.7%
times-frac63.7%
metadata-eval63.7%
fma-neg63.7%
Simplified63.7%
Taylor expanded in a around 0 63.9%
associate-*r/63.9%
neg-mul-163.9%
Simplified63.9%
if 1.25e-27 < b Initial program 69.7%
Taylor expanded in a around 0 78.6%
distribute-lft-out--78.6%
associate-/l*82.8%
fma-neg82.8%
Simplified82.8%
Taylor expanded in a around 0 82.8%
Final simplification76.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b))))))
(if (<= b -2.8e+151)
(if (>= b 0.0) t_0 (/ (- (- b) b) (* 2.0 a)))
(if (<= b 1.35e-169)
(if (>= b 0.0)
(* b (/ (+ 1.0 (/ (pow b 2.0) (* c a))) a))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a)))
(if (>= b 0.0) t_0 (/ (- (+ b (* -2.0 (/ (* c a) b))) b) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
double tmp_1;
if (b <= -2.8e+151) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (-b - b) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 1.35e-169) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = b * ((1.0 + (pow(b, 2.0) / (c * a))) / a);
} else {
tmp_3 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = ((b + (-2.0 * ((c * a) / b))) - b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))) tmp_1 = 0.0 if (b <= -2.8e+151) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(Float64(-b) - b) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b <= 1.35e-169) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(b * Float64(Float64(1.0 + Float64((b ^ 2.0) / Float64(c * a))) / a)); else tmp_3 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(2.0 * a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(Float64(b + Float64(-2.0 * Float64(Float64(c * a) / b))) - b) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2.8e+151], If[GreaterEqual[b, 0.0], t$95$0, N[(N[((-b) - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 1.35e-169], If[GreaterEqual[b, 0.0], N[(b * N[(N[(1.0 + N[(N[Power[b, 2.0], $MachinePrecision] / N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(N[(b + N[(-2.0 * N[(N[(c * a), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{if}\;b \leq -2.8 \cdot 10^{+151}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{-169}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;b \cdot \frac{1 + \frac{{b}^{2}}{c \cdot a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(b + -2 \cdot \frac{c \cdot a}{b}\right) - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -2.79999999999999987e151Initial program 36.6%
Taylor expanded in a around 0 36.6%
distribute-lft-out--36.6%
associate-/l*36.6%
fma-neg36.6%
Simplified36.6%
add-cbrt-cube36.6%
pow336.6%
pow1/236.6%
metadata-eval36.6%
pow-pow36.6%
pow236.6%
associate-*l*36.6%
metadata-eval36.6%
metadata-eval36.6%
Applied egg-rr36.6%
Taylor expanded in b around -inf 97.8%
if -2.79999999999999987e151 < b < 1.3500000000000001e-169Initial program 86.6%
Taylor expanded in a around 0 72.4%
distribute-lft-out--72.4%
associate-/l*72.3%
fma-neg72.3%
Simplified72.3%
Taylor expanded in b around 0 72.3%
Taylor expanded in a around inf 72.4%
if 1.3500000000000001e-169 < b Initial program 69.5%
Taylor expanded in a around 0 68.6%
distribute-lft-out--68.6%
associate-/l*72.1%
fma-neg72.1%
Simplified72.1%
Taylor expanded in a around 0 72.1%
Final simplification76.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b))))))
(if (<= b -4e+151)
(if (>= b 0.0) t_0 (/ (- (- b) b) (* 2.0 a)))
(if (>= b 0.0)
t_0
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a))))))
double code(double a, double b, double c) {
double t_0 = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
double tmp_1;
if (b <= -4e+151) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (-b - b) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))) tmp_1 = 0.0 if (b <= -4e+151) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(Float64(-b) - b) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -4e+151], If[GreaterEqual[b, 0.0], t$95$0, N[(N[((-b) - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{if}\;b \leq -4 \cdot 10^{+151}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -4.00000000000000007e151Initial program 36.6%
Taylor expanded in a around 0 36.6%
distribute-lft-out--36.6%
associate-/l*36.6%
fma-neg36.6%
Simplified36.6%
add-cbrt-cube36.6%
pow336.6%
pow1/236.6%
metadata-eval36.6%
pow-pow36.6%
pow236.6%
associate-*l*36.6%
metadata-eval36.6%
metadata-eval36.6%
Applied egg-rr36.6%
Taylor expanded in b around -inf 97.8%
if -4.00000000000000007e151 < b Initial program 77.6%
Taylor expanded in a around 0 70.4%
distribute-lft-out--70.4%
associate-/l*72.2%
fma-neg72.2%
Simplified72.2%
Final simplification76.4%
(FPCore (a b c)
:precision binary64
(if (<= b -5e+151)
(if (>= b 0.0)
(/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b))))
(/ (- (- b) b) (* 2.0 a)))
(if (>= b 0.0)
(/ 1.0 (fma -1.0 (/ b c) (/ a b)))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -5e+151) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
} else {
tmp_2 = (-b - b) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = 1.0 / fma(-1.0, (b / c), (a / b));
} else {
tmp_1 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -5e+151) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))); else tmp_2 = Float64(Float64(Float64(-b) - b) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(1.0 / fma(-1.0, Float64(b / c), Float64(a / b))); else tmp_1 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, -5e+151], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(1.0 / N[(-1.0 * N[(b / c), $MachinePrecision] + N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{+151}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(-1, \frac{b}{c}, \frac{a}{b}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -5.0000000000000002e151Initial program 36.6%
Taylor expanded in a around 0 36.6%
distribute-lft-out--36.6%
associate-/l*36.6%
fma-neg36.6%
Simplified36.6%
add-cbrt-cube36.6%
pow336.6%
pow1/236.6%
metadata-eval36.6%
pow-pow36.6%
pow236.6%
associate-*l*36.6%
metadata-eval36.6%
metadata-eval36.6%
Applied egg-rr36.6%
Taylor expanded in b around -inf 97.8%
if -5.0000000000000002e151 < b Initial program 77.6%
Taylor expanded in a around 0 70.4%
distribute-lft-out--70.4%
associate-/l*72.2%
fma-neg72.2%
Simplified72.2%
clear-num70.3%
inv-pow70.3%
Applied egg-rr70.3%
unpow-170.3%
times-frac70.3%
metadata-eval70.3%
fma-neg70.3%
Simplified70.3%
Taylor expanded in a around 0 70.5%
fma-define70.5%
Simplified70.5%
Final simplification75.0%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b)))) (/ (- (- b) b) (* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
} else {
tmp = (-b - b) / (2.0 * a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))); else tmp = Float64(Float64(Float64(-b) - b) / Float64(2.0 * a)); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 70.8%
Taylor expanded in a around 0 64.9%
distribute-lft-out--64.9%
associate-/l*66.3%
fma-neg66.3%
Simplified66.3%
add-cbrt-cube60.3%
pow360.3%
pow1/260.3%
metadata-eval60.3%
pow-pow60.3%
pow260.3%
associate-*l*60.3%
metadata-eval60.3%
metadata-eval60.3%
Applied egg-rr60.3%
Taylor expanded in b around -inf 66.0%
Final simplification66.0%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* c (/ -2.0 (+ b (+ b (* -2.0 (* a (/ c b))))))) (/ (- b b) (* a -2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * (-2.0 / (b + (b + (-2.0 * (a * (c / b))))));
} else {
tmp = (b - b) / (a * -2.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) :: tmp
if (b >= 0.0d0) then
tmp = c * ((-2.0d0) / (b + (b + ((-2.0d0) * (a * (c / b))))))
else
tmp = (b - b) / (a * (-2.0d0))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * (-2.0 / (b + (b + (-2.0 * (a * (c / b))))));
} else {
tmp = (b - b) / (a * -2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = c * (-2.0 / (b + (b + (-2.0 * (a * (c / b)))))) else: tmp = (b - b) / (a * -2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(c * Float64(-2.0 / Float64(b + Float64(b + Float64(-2.0 * Float64(a * Float64(c / b))))))); else tmp = Float64(Float64(b - b) / Float64(a * -2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = c * (-2.0 / (b + (b + (-2.0 * (a * (c / b)))))); else tmp = (b - b) / (a * -2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(b + N[(b + N[(-2.0 * N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - b), $MachinePrecision] / N[(a * -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{b + \left(b + -2 \cdot \left(a \cdot \frac{c}{b}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - b}{a \cdot -2}\\
\end{array}
\end{array}
Initial program 70.8%
Simplified70.8%
Taylor expanded in c around 0 37.8%
Taylor expanded in c around 0 31.8%
associate-/l*33.3%
Simplified33.3%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- c) b) 0.0))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = 0.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) :: tmp
if (b >= 0.0d0) then
tmp = -c / b
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -c / b else: tmp = 0.0 return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-c) / b); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -c / b; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
Initial program 70.8%
Simplified70.8%
Taylor expanded in c around 0 37.8%
Taylor expanded in b around inf 33.1%
Taylor expanded in b around 0 33.2%
mul-1-neg33.2%
*-rgt-identity33.2%
metadata-eval33.2%
distribute-rgt-neg-in33.2%
distribute-frac-neg233.2%
*-commutative33.2%
neg-mul-133.2%
remove-double-neg33.2%
Simplified33.2%
Final simplification33.2%
herbie shell --seed 2024146
(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))))