
(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 9 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 (fma -1.0 (/ b a) (/ c b)))
(t_1 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (<= b -6e+149)
(if (>= b 0.0) (/ 2.0 (fma 2.0 (/ a b) (* -2.0 (/ b c)))) t_0)
(if (<= b 1.8e+117)
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_1)) (/ (- t_1 b) (* 2.0 a)))
(if (>= b 0.0)
(* c (/ 2.0 (- (- b) (fma -2.0 (/ a (/ b c)) b))))
t_0)))))
double code(double a, double b, double c) {
double t_0 = fma(-1.0, (b / a), (c / b));
double t_1 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -6e+149) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = 2.0 / fma(2.0, (a / b), (-2.0 * (b / c)));
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b <= 1.8e+117) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (2.0 * c) / (-b - t_1);
} else {
tmp_3 = (t_1 - b) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = c * (2.0 / (-b - fma(-2.0, (a / (b / c)), b)));
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) t_0 = fma(-1.0, Float64(b / a), Float64(c / b)) t_1 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) tmp_1 = 0.0 if (b <= -6e+149) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(2.0 / fma(2.0, Float64(a / b), Float64(-2.0 * Float64(b / c)))); else tmp_2 = t_0; end tmp_1 = tmp_2; elseif (b <= 1.8e+117) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_1)); else tmp_3 = Float64(Float64(t_1 - b) / Float64(2.0 * a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(c * Float64(2.0 / Float64(Float64(-b) - fma(-2.0, Float64(a / Float64(b / c)), b)))); else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $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, -6e+149], If[GreaterEqual[b, 0.0], N[(2.0 / N[(2.0 * N[(a / b), $MachinePrecision] + N[(-2.0 * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0], If[LessEqual[b, 1.8e+117], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(c * N[(2.0 / N[((-b) - N[(-2.0 * N[(a / N[(b / c), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
t_1 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -6 \cdot 10^{+149}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(2, \frac{a}{b}, -2 \cdot \frac{b}{c}\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}\\
\mathbf{elif}\;b \leq 1.8 \cdot 10^{+117}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1 - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{2}{\left(-b\right) - \mathsf{fma}\left(-2, \frac{a}{\frac{b}{c}}, b\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if b < -6.00000000000000007e149Initial program 44.6%
Simplified44.6%
Taylor expanded in b around inf 44.6%
+-commutative44.6%
fma-def44.6%
Simplified44.6%
Taylor expanded in b around -inf 100.0%
fma-def100.0%
Simplified100.0%
if -6.00000000000000007e149 < b < 1.80000000000000006e117Initial program 85.1%
if 1.80000000000000006e117 < b Initial program 51.3%
expm1-log1p-u51.2%
expm1-udef43.6%
associate-/l*43.6%
*-commutative43.6%
*-commutative43.6%
Applied egg-rr43.6%
expm1-def50.8%
expm1-log1p50.9%
associate-/r/51.3%
Simplified51.3%
Taylor expanded in b around inf 88.9%
+-commutative88.9%
fma-def88.9%
associate-/l*98.2%
Simplified98.2%
Taylor expanded in b around -inf 98.2%
fma-def98.2%
Simplified98.2%
Final simplification90.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma -1.0 (/ b a) (/ c b)))
(t_1 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (<= b -2e+152)
(if (>= b 0.0) (/ 2.0 (fma 2.0 (/ a b) (* -2.0 (/ b c)))) t_0)
(if (<= b 4e+47)
(if (>= b 0.0) (* c (/ 2.0 (- (- b) t_1))) (/ (- t_1 b) (* 2.0 a)))
(if (>= b 0.0)
(* c (/ 2.0 (- (- b) (fma -2.0 (/ a (/ b c)) b))))
t_0)))))
double code(double a, double b, double c) {
double t_0 = fma(-1.0, (b / a), (c / b));
double t_1 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -2e+152) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = 2.0 / fma(2.0, (a / b), (-2.0 * (b / c)));
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b <= 4e+47) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = c * (2.0 / (-b - t_1));
} else {
tmp_3 = (t_1 - b) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = c * (2.0 / (-b - fma(-2.0, (a / (b / c)), b)));
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) t_0 = fma(-1.0, Float64(b / a), Float64(c / b)) t_1 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) tmp_1 = 0.0 if (b <= -2e+152) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(2.0 / fma(2.0, Float64(a / b), Float64(-2.0 * Float64(b / c)))); else tmp_2 = t_0; end tmp_1 = tmp_2; elseif (b <= 4e+47) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(c * Float64(2.0 / Float64(Float64(-b) - t_1))); else tmp_3 = Float64(Float64(t_1 - b) / Float64(2.0 * a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(c * Float64(2.0 / Float64(Float64(-b) - fma(-2.0, Float64(a / Float64(b / c)), b)))); else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $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, -2e+152], If[GreaterEqual[b, 0.0], N[(2.0 / N[(2.0 * N[(a / b), $MachinePrecision] + N[(-2.0 * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0], If[LessEqual[b, 4e+47], If[GreaterEqual[b, 0.0], N[(c * N[(2.0 / N[((-b) - t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(c * N[(2.0 / N[((-b) - N[(-2.0 * N[(a / N[(b / c), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
t_1 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -2 \cdot 10^{+152}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(2, \frac{a}{b}, -2 \cdot \frac{b}{c}\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{+47}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{2}{\left(-b\right) - t_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1 - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{2}{\left(-b\right) - \mathsf{fma}\left(-2, \frac{a}{\frac{b}{c}}, b\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if b < -2.0000000000000001e152Initial program 44.6%
Simplified44.6%
Taylor expanded in b around inf 44.6%
+-commutative44.6%
fma-def44.6%
Simplified44.6%
Taylor expanded in b around -inf 100.0%
fma-def100.0%
Simplified100.0%
if -2.0000000000000001e152 < b < 4.0000000000000002e47Initial program 83.5%
expm1-log1p-u75.9%
expm1-udef60.4%
associate-/l*60.4%
*-commutative60.4%
*-commutative60.4%
Applied egg-rr60.4%
expm1-def75.9%
expm1-log1p83.4%
associate-/r/83.4%
Simplified83.4%
if 4.0000000000000002e47 < b Initial program 62.1%
expm1-log1p-u60.3%
expm1-udef43.9%
associate-/l*43.9%
*-commutative43.9%
*-commutative43.9%
Applied egg-rr43.9%
expm1-def59.2%
expm1-log1p61.1%
associate-/r/62.0%
Simplified62.0%
Taylor expanded in b around inf 91.3%
+-commutative91.3%
fma-def91.3%
associate-/l*98.5%
Simplified98.5%
Taylor expanded in b around -inf 98.5%
fma-def98.5%
Simplified98.5%
Final simplification90.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.25e-44)
(if (>= b 0.0)
(/ 2.0 (fma 2.0 (/ a b) (* -2.0 (/ b c))))
(fma -1.0 (/ b a) (/ c b)))
(if (>= b 0.0)
(* c (/ 2.0 (- (- b) (fma -2.0 (/ a (/ b c)) b))))
(/ (+ b (sqrt (+ (* b b) (* -4.0 (* a c))))) (* 2.0 a)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -1.25e-44) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = 2.0 / fma(2.0, (a / b), (-2.0 * (b / c)));
} else {
tmp_2 = fma(-1.0, (b / a), (c / b));
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = c * (2.0 / (-b - fma(-2.0, (a / (b / c)), b)));
} else {
tmp_1 = (b + sqrt(((b * b) + (-4.0 * (a * c))))) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -1.25e-44) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(2.0 / fma(2.0, Float64(a / b), Float64(-2.0 * Float64(b / c)))); else tmp_2 = fma(-1.0, Float64(b / a), Float64(c / b)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(c * Float64(2.0 / Float64(Float64(-b) - fma(-2.0, Float64(a / Float64(b / c)), b)))); else tmp_1 = Float64(Float64(b + sqrt(Float64(Float64(b * b) + Float64(-4.0 * Float64(a * c))))) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, -1.25e-44], If[GreaterEqual[b, 0.0], N[(2.0 / N[(2.0 * N[(a / b), $MachinePrecision] + N[(-2.0 * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(c * N[(2.0 / N[((-b) - N[(-2.0 * N[(a / N[(b / c), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.25 \cdot 10^{-44}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(2, \frac{a}{b}, -2 \cdot \frac{b}{c}\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{2}{\left(-b\right) - \mathsf{fma}\left(-2, \frac{a}{\frac{b}{c}}, b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\end{array}
\end{array}
if b < -1.2500000000000001e-44Initial program 71.3%
Simplified71.3%
Taylor expanded in b around inf 71.3%
+-commutative71.3%
fma-def71.3%
Simplified71.3%
Taylor expanded in b around -inf 88.3%
fma-def88.3%
Simplified88.3%
if -1.2500000000000001e-44 < b Initial program 71.8%
expm1-log1p-u64.5%
expm1-udef44.5%
associate-/l*44.5%
*-commutative44.5%
*-commutative44.5%
Applied egg-rr44.5%
expm1-def64.0%
expm1-log1p71.2%
associate-/r/71.6%
Simplified71.6%
Taylor expanded in b around inf 62.9%
+-commutative62.9%
fma-def62.9%
associate-/l*65.8%
Simplified65.8%
expm1-log1p-u60.8%
expm1-udef51.8%
add-sqr-sqrt51.8%
sqrt-unprod51.7%
sqr-neg51.7%
sqrt-prod47.9%
add-sqr-sqrt50.7%
associate-*l*50.7%
Applied egg-rr50.7%
expm1-def58.2%
expm1-log1p63.1%
unpow263.1%
cancel-sign-sub-inv63.1%
unpow263.1%
metadata-eval63.1%
*-commutative63.1%
*-commutative63.1%
Simplified63.1%
Final simplification71.5%
(FPCore (a b c)
:precision binary64
(if (<= b -5.6e+149)
(if (>= b 0.0)
(/ 2.0 (fma 2.0 (/ a b) (* -2.0 (/ b c))))
(fma -1.0 (/ b a) (/ c b)))
(if (>= b 0.0)
(* c (/ 2.0 (- (+ b 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 <= -5.6e+149) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = 2.0 / fma(2.0, (a / b), (-2.0 * (b / c)));
} else {
tmp_2 = fma(-1.0, (b / a), (c / b));
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = c * (2.0 / -(b + 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 <= -5.6e+149) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(2.0 / fma(2.0, Float64(a / b), Float64(-2.0 * Float64(b / c)))); else tmp_2 = fma(-1.0, Float64(b / a), Float64(c / b)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(c * Float64(2.0 / Float64(-Float64(b + 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, -5.6e+149], If[GreaterEqual[b, 0.0], N[(2.0 / N[(2.0 * N[(a / b), $MachinePrecision] + N[(-2.0 * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(c * N[(2.0 / (-N[(b + 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.6 \cdot 10^{+149}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(2, \frac{a}{b}, -2 \cdot \frac{b}{c}\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{2}{-\left(b + 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.5999999999999998e149Initial program 44.6%
Simplified44.6%
Taylor expanded in b around inf 44.6%
+-commutative44.6%
fma-def44.6%
Simplified44.6%
Taylor expanded in b around -inf 100.0%
fma-def100.0%
Simplified100.0%
if -5.5999999999999998e149 < b Initial program 76.7%
expm1-log1p-u71.0%
expm1-udef55.2%
associate-/l*55.2%
*-commutative55.2%
*-commutative55.2%
Applied egg-rr55.2%
expm1-def70.6%
expm1-log1p76.3%
associate-/r/76.7%
Simplified76.7%
Taylor expanded in b around inf 71.7%
Final simplification76.2%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* c (/ 2.0 (- (- b) (fma -2.0 (/ a (/ b c)) b)))) (fma -1.0 (/ b a) (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * (2.0 / (-b - fma(-2.0, (a / (b / c)), b)));
} else {
tmp = fma(-1.0, (b / a), (c / b));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(c * Float64(2.0 / Float64(Float64(-b) - fma(-2.0, Float64(a / Float64(b / c)), b)))); else tmp = fma(-1.0, Float64(b / a), Float64(c / b)); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c * N[(2.0 / N[((-b) - N[(-2.0 * N[(a / N[(b / c), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{2}{\left(-b\right) - \mathsf{fma}\left(-2, \frac{a}{\frac{b}{c}}, b\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\end{array}
\end{array}
Initial program 71.6%
expm1-log1p-u66.8%
expm1-udef53.5%
associate-/l*53.5%
*-commutative53.5%
*-commutative53.5%
Applied egg-rr53.5%
expm1-def66.4%
expm1-log1p71.2%
associate-/r/71.5%
Simplified71.5%
Taylor expanded in b around inf 65.7%
+-commutative65.7%
fma-def65.7%
associate-/l*67.7%
Simplified67.7%
Taylor expanded in b around -inf 63.9%
fma-def63.9%
Simplified63.9%
Final simplification63.9%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ 2.0 (fma 2.0 (/ a b) (* -2.0 (/ b c)))) (fma -1.0 (/ b a) (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = 2.0 / fma(2.0, (a / b), (-2.0 * (b / c)));
} else {
tmp = fma(-1.0, (b / a), (c / b));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(2.0 / fma(2.0, Float64(a / b), Float64(-2.0 * Float64(b / c)))); else tmp = fma(-1.0, Float64(b / a), Float64(c / b)); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(2.0 / N[(2.0 * N[(a / b), $MachinePrecision] + N[(-2.0 * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(2, \frac{a}{b}, -2 \cdot \frac{b}{c}\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\end{array}
\end{array}
Initial program 71.6%
Simplified71.2%
Taylor expanded in b around inf 67.4%
+-commutative67.4%
fma-def67.4%
Simplified67.4%
Taylor expanded in b around -inf 63.7%
fma-def63.7%
Simplified63.7%
Final simplification63.7%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ 2.0 (+ (* -2.0 (/ b c)) (* 2.0 (/ a b)))) (/ (* b -2.0) (* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = 2.0 / ((-2.0 * (b / c)) + (2.0 * (a / b)));
} else {
tmp = (b * -2.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) :: tmp
if (b >= 0.0d0) then
tmp = 2.0d0 / (((-2.0d0) * (b / c)) + (2.0d0 * (a / b)))
else
tmp = (b * (-2.0d0)) / (2.0d0 * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = 2.0 / ((-2.0 * (b / c)) + (2.0 * (a / b)));
} else {
tmp = (b * -2.0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = 2.0 / ((-2.0 * (b / c)) + (2.0 * (a / b))) else: tmp = (b * -2.0) / (2.0 * a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(2.0 / Float64(Float64(-2.0 * Float64(b / c)) + Float64(2.0 * Float64(a / b)))); else tmp = Float64(Float64(b * -2.0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = 2.0 / ((-2.0 * (b / c)) + (2.0 * (a / b))); else tmp = (b * -2.0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(2.0 / N[(N[(-2.0 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2}{-2 \cdot \frac{b}{c} + 2 \cdot \frac{a}{b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 71.6%
Simplified71.2%
Taylor expanded in b around inf 67.4%
+-commutative67.4%
fma-def67.4%
Simplified67.4%
Taylor expanded in b around -inf 63.3%
*-commutative63.3%
Simplified63.3%
fma-udef63.3%
Applied egg-rr63.3%
Final simplification63.3%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ 2.0 (* -2.0 (/ b c))) (/ (* b -2.0) (* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = 2.0 / (-2.0 * (b / c));
} else {
tmp = (b * -2.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) :: tmp
if (b >= 0.0d0) then
tmp = 2.0d0 / ((-2.0d0) * (b / c))
else
tmp = (b * (-2.0d0)) / (2.0d0 * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = 2.0 / (-2.0 * (b / c));
} else {
tmp = (b * -2.0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = 2.0 / (-2.0 * (b / c)) else: tmp = (b * -2.0) / (2.0 * a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(2.0 / Float64(-2.0 * Float64(b / c))); else tmp = Float64(Float64(b * -2.0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = 2.0 / (-2.0 * (b / c)); else tmp = (b * -2.0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(2.0 / N[(-2.0 * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2}{-2 \cdot \frac{b}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 71.6%
Simplified71.2%
Taylor expanded in b around inf 67.4%
+-commutative67.4%
fma-def67.4%
Simplified67.4%
Taylor expanded in b around -inf 63.3%
*-commutative63.3%
Simplified63.3%
Taylor expanded in a around 0 62.9%
Final simplification62.9%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- c) b) (/ (* b -2.0) (* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = (b * -2.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) :: tmp
if (b >= 0.0d0) then
tmp = -c / b
else
tmp = (b * (-2.0d0)) / (2.0d0 * a)
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 = (b * -2.0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -c / b else: tmp = (b * -2.0) / (2.0 * a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(b * -2.0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -c / b; else tmp = (b * -2.0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 71.6%
Simplified71.2%
Taylor expanded in b around inf 67.4%
+-commutative67.4%
fma-def67.4%
Simplified67.4%
Taylor expanded in b around -inf 63.3%
*-commutative63.3%
Simplified63.3%
Taylor expanded in a around 0 62.9%
Taylor expanded in b around 0 63.3%
associate-*r/63.3%
mul-1-neg63.3%
Simplified63.3%
Final simplification63.3%
herbie shell --seed 2023271
(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))))