
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ c (hypot c d)))
(t_1 (/ b (hypot c d)))
(t_2 (fma t_0 t_1 (* a (/ d (- (pow (hypot c d) 2.0))))))
(t_3 (fma t_0 t_1 (/ (- a) d))))
(if (<= d -2.2e+145)
t_3
(if (<= d -1e-158)
t_2
(if (<= d 2.25e-132)
(/ (- b (* a (/ d c))) c)
(if (<= d 1.25e+98) t_2 t_3))))))
double code(double a, double b, double c, double d) {
double t_0 = c / hypot(c, d);
double t_1 = b / hypot(c, d);
double t_2 = fma(t_0, t_1, (a * (d / -pow(hypot(c, d), 2.0))));
double t_3 = fma(t_0, t_1, (-a / d));
double tmp;
if (d <= -2.2e+145) {
tmp = t_3;
} else if (d <= -1e-158) {
tmp = t_2;
} else if (d <= 2.25e-132) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 1.25e+98) {
tmp = t_2;
} else {
tmp = t_3;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(c / hypot(c, d)) t_1 = Float64(b / hypot(c, d)) t_2 = fma(t_0, t_1, Float64(a * Float64(d / Float64(-(hypot(c, d) ^ 2.0))))) t_3 = fma(t_0, t_1, Float64(Float64(-a) / d)) tmp = 0.0 if (d <= -2.2e+145) tmp = t_3; elseif (d <= -1e-158) tmp = t_2; elseif (d <= 2.25e-132) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 1.25e+98) tmp = t_2; else tmp = t_3; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * t$95$1 + N[(a * N[(d / (-N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$0 * t$95$1 + N[((-a) / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.2e+145], t$95$3, If[LessEqual[d, -1e-158], t$95$2, If[LessEqual[d, 2.25e-132], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.25e+98], t$95$2, t$95$3]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
t_2 := \mathsf{fma}\left(t\_0, t\_1, a \cdot \frac{d}{-{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\
t_3 := \mathsf{fma}\left(t\_0, t\_1, \frac{-a}{d}\right)\\
\mathbf{if}\;d \leq -2.2 \cdot 10^{+145}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;d \leq -1 \cdot 10^{-158}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;d \leq 2.25 \cdot 10^{-132}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.25 \cdot 10^{+98}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\end{array}
\end{array}
if d < -2.20000000000000009e145 or 1.25e98 < d Initial program 40.2%
div-sub40.2%
*-commutative40.2%
fma-define40.2%
add-sqr-sqrt40.2%
times-frac40.5%
fma-neg40.5%
fma-define40.5%
hypot-define40.5%
fma-define40.5%
hypot-define55.9%
associate-/l*62.9%
fma-define62.9%
add-sqr-sqrt62.9%
pow262.9%
Applied egg-rr62.9%
Taylor expanded in d around inf 96.3%
if -2.20000000000000009e145 < d < -1.00000000000000006e-158 or 2.25e-132 < d < 1.25e98Initial program 78.9%
div-sub78.9%
*-commutative78.9%
fma-define78.9%
add-sqr-sqrt78.9%
times-frac79.1%
fma-neg79.1%
fma-define79.1%
hypot-define79.1%
fma-define79.1%
hypot-define90.4%
associate-/l*95.2%
fma-define95.2%
add-sqr-sqrt95.2%
pow295.2%
Applied egg-rr95.2%
if -1.00000000000000006e-158 < d < 2.25e-132Initial program 72.1%
div-sub66.5%
*-commutative66.5%
fma-define66.5%
add-sqr-sqrt66.5%
times-frac72.0%
fma-neg72.0%
fma-define72.0%
hypot-define72.0%
fma-define72.0%
hypot-define88.5%
associate-/l*87.7%
fma-define87.7%
add-sqr-sqrt87.7%
pow287.7%
Applied egg-rr87.7%
Taylor expanded in c around inf 93.8%
mul-1-neg93.8%
unsub-neg93.8%
associate-/l*95.1%
Simplified95.1%
Final simplification95.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d))))
(t_1 (fma (/ c (hypot c d)) (/ b (hypot c d)) (/ (- a) d))))
(if (<= d -1.8e+87)
t_1
(if (<= d -9.5e-159)
t_0
(if (<= d 5.4e-92)
(/ (- b (* a (/ d c))) c)
(if (<= d 1.3e+93) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double t_1 = fma((c / hypot(c, d)), (b / hypot(c, d)), (-a / d));
double tmp;
if (d <= -1.8e+87) {
tmp = t_1;
} else if (d <= -9.5e-159) {
tmp = t_0;
} else if (d <= 5.4e-92) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 1.3e+93) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(Float64(-a) / d)) tmp = 0.0 if (d <= -1.8e+87) tmp = t_1; elseif (d <= -9.5e-159) tmp = t_0; elseif (d <= 5.4e-92) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 1.3e+93) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[((-a) / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.8e+87], t$95$1, If[LessEqual[d, -9.5e-159], t$95$0, If[LessEqual[d, 5.4e-92], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.3e+93], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
t_1 := \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\
\mathbf{if}\;d \leq -1.8 \cdot 10^{+87}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -9.5 \cdot 10^{-159}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 5.4 \cdot 10^{-92}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.3 \cdot 10^{+93}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.79999999999999997e87 or 1.3e93 < d Initial program 39.6%
div-sub39.6%
*-commutative39.6%
fma-define39.6%
add-sqr-sqrt39.6%
times-frac41.1%
fma-neg41.1%
fma-define41.1%
hypot-define41.1%
fma-define41.1%
hypot-define55.7%
associate-/l*64.6%
fma-define64.6%
add-sqr-sqrt64.6%
pow264.6%
Applied egg-rr64.6%
Taylor expanded in d around inf 95.5%
if -1.79999999999999997e87 < d < -9.4999999999999997e-159 or 5.3999999999999999e-92 < d < 1.3e93Initial program 81.2%
if -9.4999999999999997e-159 < d < 5.3999999999999999e-92Initial program 72.8%
div-sub67.8%
*-commutative67.8%
fma-define67.8%
add-sqr-sqrt67.8%
times-frac72.7%
fma-neg72.7%
fma-define72.7%
hypot-define72.7%
fma-define72.7%
hypot-define88.6%
associate-/l*88.9%
fma-define88.9%
add-sqr-sqrt88.9%
pow288.9%
Applied egg-rr88.9%
Taylor expanded in c around inf 93.3%
mul-1-neg93.3%
unsub-neg93.3%
associate-/l*94.5%
Simplified94.5%
Final simplification90.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d))))
(t_1 (/ (- (/ c (/ d b)) a) d)))
(if (<= d -2.7e+84)
t_1
(if (<= d -2.06e-159)
t_0
(if (<= d 1.4e-97)
(/ (- b (* a (/ d c))) c)
(if (<= d 6.7e+93) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double t_1 = ((c / (d / b)) - a) / d;
double tmp;
if (d <= -2.7e+84) {
tmp = t_1;
} else if (d <= -2.06e-159) {
tmp = t_0;
} else if (d <= 1.4e-97) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 6.7e+93) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
t_1 = ((c / (d / b)) - a) / d
if (d <= (-2.7d+84)) then
tmp = t_1
else if (d <= (-2.06d-159)) then
tmp = t_0
else if (d <= 1.4d-97) then
tmp = (b - (a * (d / c))) / c
else if (d <= 6.7d+93) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double t_1 = ((c / (d / b)) - a) / d;
double tmp;
if (d <= -2.7e+84) {
tmp = t_1;
} else if (d <= -2.06e-159) {
tmp = t_0;
} else if (d <= 1.4e-97) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 6.7e+93) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)) t_1 = ((c / (d / b)) - a) / d tmp = 0 if d <= -2.7e+84: tmp = t_1 elif d <= -2.06e-159: tmp = t_0 elif d <= 1.4e-97: tmp = (b - (a * (d / c))) / c elif d <= 6.7e+93: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(Float64(c / Float64(d / b)) - a) / d) tmp = 0.0 if (d <= -2.7e+84) tmp = t_1; elseif (d <= -2.06e-159) tmp = t_0; elseif (d <= 1.4e-97) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 6.7e+93) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)); t_1 = ((c / (d / b)) - a) / d; tmp = 0.0; if (d <= -2.7e+84) tmp = t_1; elseif (d <= -2.06e-159) tmp = t_0; elseif (d <= 1.4e-97) tmp = (b - (a * (d / c))) / c; elseif (d <= 6.7e+93) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.7e+84], t$95$1, If[LessEqual[d, -2.06e-159], t$95$0, If[LessEqual[d, 1.4e-97], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 6.7e+93], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
t_1 := \frac{\frac{c}{\frac{d}{b}} - a}{d}\\
\mathbf{if}\;d \leq -2.7 \cdot 10^{+84}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -2.06 \cdot 10^{-159}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.4 \cdot 10^{-97}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 6.7 \cdot 10^{+93}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -2.7e84 or 6.69999999999999965e93 < d Initial program 39.6%
Taylor expanded in c around 0 73.5%
+-commutative73.5%
mul-1-neg73.5%
unsub-neg73.5%
unpow273.5%
associate-/r*80.4%
div-sub80.4%
*-commutative80.4%
associate-/l*87.5%
Simplified87.5%
clear-num87.5%
un-div-inv87.6%
Applied egg-rr87.6%
if -2.7e84 < d < -2.05999999999999989e-159 or 1.4000000000000001e-97 < d < 6.69999999999999965e93Initial program 81.2%
if -2.05999999999999989e-159 < d < 1.4000000000000001e-97Initial program 72.8%
div-sub67.8%
*-commutative67.8%
fma-define67.8%
add-sqr-sqrt67.8%
times-frac72.7%
fma-neg72.7%
fma-define72.7%
hypot-define72.7%
fma-define72.7%
hypot-define88.6%
associate-/l*88.9%
fma-define88.9%
add-sqr-sqrt88.9%
pow288.9%
Applied egg-rr88.9%
Taylor expanded in c around inf 93.3%
mul-1-neg93.3%
unsub-neg93.3%
associate-/l*94.5%
Simplified94.5%
Final simplification87.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.6e+84) (not (<= d 1.85e-10))) (/ (- (/ c (/ d b)) a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.6e+84) || !(d <= 1.85e-10)) {
tmp = ((c / (d / b)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-1.6d+84)) .or. (.not. (d <= 1.85d-10))) then
tmp = ((c / (d / b)) - a) / d
else
tmp = (b - (a * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.6e+84) || !(d <= 1.85e-10)) {
tmp = ((c / (d / b)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.6e+84) or not (d <= 1.85e-10): tmp = ((c / (d / b)) - a) / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.6e+84) || !(d <= 1.85e-10)) tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / d); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.6e+84) || ~((d <= 1.85e-10))) tmp = ((c / (d / b)) - a) / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.6e+84], N[Not[LessEqual[d, 1.85e-10]], $MachinePrecision]], N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.6 \cdot 10^{+84} \lor \neg \left(d \leq 1.85 \cdot 10^{-10}\right):\\
\;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.60000000000000005e84 or 1.85000000000000007e-10 < d Initial program 48.8%
Taylor expanded in c around 0 69.0%
+-commutative69.0%
mul-1-neg69.0%
unsub-neg69.0%
unpow269.0%
associate-/r*74.2%
div-sub74.2%
*-commutative74.2%
associate-/l*79.6%
Simplified79.6%
clear-num79.6%
un-div-inv79.6%
Applied egg-rr79.6%
if -1.60000000000000005e84 < d < 1.85000000000000007e-10Initial program 77.1%
div-sub74.1%
*-commutative74.1%
fma-define74.1%
add-sqr-sqrt74.1%
times-frac76.5%
fma-neg76.5%
fma-define76.5%
hypot-define76.5%
fma-define76.5%
hypot-define91.1%
associate-/l*91.3%
fma-define91.3%
add-sqr-sqrt91.3%
pow291.3%
Applied egg-rr91.3%
Taylor expanded in c around inf 84.9%
mul-1-neg84.9%
unsub-neg84.9%
associate-/l*85.6%
Simplified85.6%
Final simplification83.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2e+88) (not (<= d 1.9e-10))) (/ (- (* c (/ b d)) a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2e+88) || !(d <= 1.9e-10)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-2d+88)) .or. (.not. (d <= 1.9d-10))) then
tmp = ((c * (b / d)) - a) / d
else
tmp = (b - (a * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2e+88) || !(d <= 1.9e-10)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2e+88) or not (d <= 1.9e-10): tmp = ((c * (b / d)) - a) / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2e+88) || !(d <= 1.9e-10)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2e+88) || ~((d <= 1.9e-10))) tmp = ((c * (b / d)) - a) / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2e+88], N[Not[LessEqual[d, 1.9e-10]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2 \cdot 10^{+88} \lor \neg \left(d \leq 1.9 \cdot 10^{-10}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.99999999999999992e88 or 1.8999999999999999e-10 < d Initial program 48.8%
Taylor expanded in c around 0 69.0%
+-commutative69.0%
mul-1-neg69.0%
unsub-neg69.0%
unpow269.0%
associate-/r*74.2%
div-sub74.2%
*-commutative74.2%
associate-/l*79.6%
Simplified79.6%
if -1.99999999999999992e88 < d < 1.8999999999999999e-10Initial program 77.1%
div-sub74.1%
*-commutative74.1%
fma-define74.1%
add-sqr-sqrt74.1%
times-frac76.5%
fma-neg76.5%
fma-define76.5%
hypot-define76.5%
fma-define76.5%
hypot-define91.1%
associate-/l*91.3%
fma-define91.3%
add-sqr-sqrt91.3%
pow291.3%
Applied egg-rr91.3%
Taylor expanded in c around inf 84.9%
mul-1-neg84.9%
unsub-neg84.9%
associate-/l*85.6%
Simplified85.6%
Final simplification82.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -6.6e+93) (not (<= d 4e+96))) (/ (- a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.6e+93) || !(d <= 4e+96)) {
tmp = -a / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-6.6d+93)) .or. (.not. (d <= 4d+96))) then
tmp = -a / d
else
tmp = (b - (a * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.6e+93) || !(d <= 4e+96)) {
tmp = -a / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -6.6e+93) or not (d <= 4e+96): tmp = -a / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -6.6e+93) || !(d <= 4e+96)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -6.6e+93) || ~((d <= 4e+96))) tmp = -a / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6.6e+93], N[Not[LessEqual[d, 4e+96]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.6 \cdot 10^{+93} \lor \neg \left(d \leq 4 \cdot 10^{+96}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -6.60000000000000017e93 or 4.0000000000000002e96 < d Initial program 40.0%
Taylor expanded in c around 0 75.1%
associate-*r/75.1%
neg-mul-175.1%
Simplified75.1%
if -6.60000000000000017e93 < d < 4.0000000000000002e96Initial program 76.6%
div-sub74.1%
*-commutative74.1%
fma-define74.1%
add-sqr-sqrt74.1%
times-frac76.7%
fma-neg76.7%
fma-define76.7%
hypot-define76.7%
fma-define76.7%
hypot-define90.5%
associate-/l*91.8%
fma-define91.8%
add-sqr-sqrt91.8%
pow291.8%
Applied egg-rr91.8%
Taylor expanded in c around inf 77.1%
mul-1-neg77.1%
unsub-neg77.1%
associate-/l*78.8%
Simplified78.8%
Final simplification77.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.56e-78) (not (<= d 1.8e-10))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.56e-78) || !(d <= 1.8e-10)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-1.56d-78)) .or. (.not. (d <= 1.8d-10))) then
tmp = -a / d
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.56e-78) || !(d <= 1.8e-10)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.56e-78) or not (d <= 1.8e-10): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.56e-78) || !(d <= 1.8e-10)) tmp = Float64(Float64(-a) / d); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.56e-78) || ~((d <= 1.8e-10))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.56e-78], N[Not[LessEqual[d, 1.8e-10]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.56 \cdot 10^{-78} \lor \neg \left(d \leq 1.8 \cdot 10^{-10}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -1.56000000000000002e-78 or 1.8e-10 < d Initial program 55.2%
Taylor expanded in c around 0 62.1%
associate-*r/62.1%
neg-mul-162.1%
Simplified62.1%
if -1.56000000000000002e-78 < d < 1.8e-10Initial program 76.7%
Taylor expanded in c around inf 73.2%
Final simplification67.0%
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
return b / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = b / c
end function
public static double code(double a, double b, double c, double d) {
return b / c;
}
def code(a, b, c, d): return b / c
function code(a, b, c, d) return Float64(b / c) end
function tmp = code(a, b, c, d) tmp = b / c; end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{c}
\end{array}
Initial program 64.7%
Taylor expanded in c around inf 44.5%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024084
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))