
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * 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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * 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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ d (hypot c d))) (t_1 (fma a (/ c d) b)))
(if (<= d -1.3e-67)
(/ (* t_0 t_1) (hypot c d))
(if (<= d 1.95e-42)
(/ (+ a (* b (/ d c))) c)
(* t_0 (/ t_1 (hypot c d)))))))
double code(double a, double b, double c, double d) {
double t_0 = d / hypot(c, d);
double t_1 = fma(a, (c / d), b);
double tmp;
if (d <= -1.3e-67) {
tmp = (t_0 * t_1) / hypot(c, d);
} else if (d <= 1.95e-42) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = t_0 * (t_1 / hypot(c, d));
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(d / hypot(c, d)) t_1 = fma(a, Float64(c / d), b) tmp = 0.0 if (d <= -1.3e-67) tmp = Float64(Float64(t_0 * t_1) / hypot(c, d)); elseif (d <= 1.95e-42) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(t_0 * Float64(t_1 / hypot(c, d))); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision]}, If[LessEqual[d, -1.3e-67], N[(N[(t$95$0 * t$95$1), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.95e-42], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(t$95$0 * N[(t$95$1 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{d}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := \mathsf{fma}\left(a, \frac{c}{d}, b\right)\\
\mathbf{if}\;d \leq -1.3 \cdot 10^{-67}:\\
\;\;\;\;\frac{t\_0 \cdot t\_1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq 1.95 \cdot 10^{-42}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \frac{t\_1}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -1.2999999999999999e-67Initial program 56.1%
Taylor expanded in d around inf 56.1%
associate-/l*56.0%
Simplified56.0%
*-commutative56.0%
add-sqr-sqrt56.0%
hypot-undefine56.0%
hypot-undefine56.0%
times-frac94.0%
+-commutative94.0%
fma-define94.0%
Applied egg-rr94.0%
associate-*l/94.1%
fma-undefine94.1%
associate-/l*88.2%
+-commutative88.2%
*-commutative88.2%
+-commutative88.2%
associate-/l*94.1%
fma-undefine94.1%
Applied egg-rr94.1%
if -1.2999999999999999e-67 < d < 1.9500000000000001e-42Initial program 68.9%
Taylor expanded in c around inf 88.4%
associate-/l*88.5%
Simplified88.5%
if 1.9500000000000001e-42 < d Initial program 52.1%
Taylor expanded in d around inf 52.1%
associate-/l*52.1%
Simplified52.1%
*-commutative52.1%
add-sqr-sqrt52.1%
hypot-undefine52.1%
hypot-undefine52.1%
times-frac96.8%
+-commutative96.8%
fma-define96.8%
Applied egg-rr96.8%
Final simplification92.4%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* c a) (* d b)) (+ (* c c) (* d d))) INFINITY) (/ (/ (fma a c (* d b)) (hypot c d)) (hypot c d)) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((c * a) + (d * b)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
tmp = (fma(a, c, (d * b)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (Float64(Float64(Float64(c * a) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))) <= Inf) tmp = Float64(Float64(fma(a, c, Float64(d * b)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 75.5%
*-un-lft-identity75.5%
associate-*r/75.5%
fma-define75.5%
add-sqr-sqrt75.5%
times-frac75.4%
fma-define75.4%
hypot-define75.4%
fma-define75.4%
fma-define75.5%
hypot-define94.5%
Applied egg-rr94.5%
associate-*l/94.7%
*-un-lft-identity94.7%
Applied egg-rr94.7%
if +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 0.0%
Taylor expanded in d around inf 44.6%
associate-/l*64.0%
Simplified64.0%
Final simplification88.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.65e-66) (not (<= d 1.95e-41))) (* (/ d (hypot c d)) (/ (fma a (/ c d) b) (hypot c d))) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.65e-66) || !(d <= 1.95e-41)) {
tmp = (d / hypot(c, d)) * (fma(a, (c / d), b) / hypot(c, d));
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.65e-66) || !(d <= 1.95e-41)) tmp = Float64(Float64(d / hypot(c, d)) * Float64(fma(a, Float64(c / d), b) / hypot(c, d))); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.65e-66], N[Not[LessEqual[d, 1.95e-41]], $MachinePrecision]], N[(N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.65 \cdot 10^{-66} \lor \neg \left(d \leq 1.95 \cdot 10^{-41}\right):\\
\;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.6499999999999999e-66 or 1.94999999999999995e-41 < d Initial program 54.3%
Taylor expanded in d around inf 54.3%
associate-/l*54.3%
Simplified54.3%
*-commutative54.3%
add-sqr-sqrt54.3%
hypot-undefine54.3%
hypot-undefine54.3%
times-frac95.2%
+-commutative95.2%
fma-define95.2%
Applied egg-rr95.2%
if -1.6499999999999999e-66 < d < 1.94999999999999995e-41Initial program 68.9%
Taylor expanded in c around inf 88.4%
associate-/l*88.5%
Simplified88.5%
Final simplification92.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (* c a) (* d b))))
(if (<= (/ t_0 (+ (* c c) (* d d))) INFINITY)
(* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
(/ (+ b (* a (/ c d))) d))))
double code(double a, double b, double c, double d) {
double t_0 = (c * a) + (d * b);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= ((double) INFINITY)) {
tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = (c * a) + (d * b);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= Double.POSITIVE_INFINITY) {
tmp = (1.0 / Math.hypot(c, d)) * (t_0 / Math.hypot(c, d));
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = (c * a) + (d * b) tmp = 0 if (t_0 / ((c * c) + (d * d))) <= math.inf: tmp = (1.0 / math.hypot(c, d)) * (t_0 / math.hypot(c, d)) else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(c * a) + Float64(d * b)) tmp = 0.0 if (Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) <= Inf) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (c * a) + (d * b); tmp = 0.0; if ((t_0 / ((c * c) + (d * d))) <= Inf) tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d)); else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot a + d \cdot b\\
\mathbf{if}\;\frac{t\_0}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t\_0}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 75.5%
*-un-lft-identity75.5%
associate-*r/75.5%
fma-define75.5%
add-sqr-sqrt75.5%
times-frac75.4%
fma-define75.4%
hypot-define75.4%
fma-define75.4%
fma-define75.5%
hypot-define94.5%
Applied egg-rr94.5%
fma-define94.5%
+-commutative94.5%
Applied egg-rr94.5%
if +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 0.0%
Taylor expanded in d around inf 44.6%
associate-/l*64.0%
Simplified64.0%
Final simplification88.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* c a) (* d b)) (+ (* c c) (* d d))))
(t_1 (+ b (* a (/ c d)))))
(if (<= d -1.3e+106)
(/ t_1 d)
(if (<= d -7.5e-67)
t_0
(if (<= d 1.06e-45)
(/ (+ a (* b (/ d c))) c)
(if (<= d 1.45e+146) t_0 (* (/ 1.0 (hypot c d)) t_1)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d));
double t_1 = b + (a * (c / d));
double tmp;
if (d <= -1.3e+106) {
tmp = t_1 / d;
} else if (d <= -7.5e-67) {
tmp = t_0;
} else if (d <= 1.06e-45) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 1.45e+146) {
tmp = t_0;
} else {
tmp = (1.0 / hypot(c, d)) * t_1;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d));
double t_1 = b + (a * (c / d));
double tmp;
if (d <= -1.3e+106) {
tmp = t_1 / d;
} else if (d <= -7.5e-67) {
tmp = t_0;
} else if (d <= 1.06e-45) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 1.45e+146) {
tmp = t_0;
} else {
tmp = (1.0 / Math.hypot(c, d)) * t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d)) t_1 = b + (a * (c / d)) tmp = 0 if d <= -1.3e+106: tmp = t_1 / d elif d <= -7.5e-67: tmp = t_0 elif d <= 1.06e-45: tmp = (a + (b * (d / c))) / c elif d <= 1.45e+146: tmp = t_0 else: tmp = (1.0 / math.hypot(c, d)) * t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * a) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(b + Float64(a * Float64(c / d))) tmp = 0.0 if (d <= -1.3e+106) tmp = Float64(t_1 / d); elseif (d <= -7.5e-67) tmp = t_0; elseif (d <= 1.06e-45) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (d <= 1.45e+146) tmp = t_0; else tmp = Float64(Float64(1.0 / hypot(c, d)) * t_1); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d)); t_1 = b + (a * (c / d)); tmp = 0.0; if (d <= -1.3e+106) tmp = t_1 / d; elseif (d <= -7.5e-67) tmp = t_0; elseif (d <= 1.06e-45) tmp = (a + (b * (d / c))) / c; elseif (d <= 1.45e+146) tmp = t_0; else tmp = (1.0 / hypot(c, d)) * t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.3e+106], N[(t$95$1 / d), $MachinePrecision], If[LessEqual[d, -7.5e-67], t$95$0, If[LessEqual[d, 1.06e-45], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.45e+146], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\
t_1 := b + a \cdot \frac{c}{d}\\
\mathbf{if}\;d \leq -1.3 \cdot 10^{+106}:\\
\;\;\;\;\frac{t\_1}{d}\\
\mathbf{elif}\;d \leq -7.5 \cdot 10^{-67}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.06 \cdot 10^{-45}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.45 \cdot 10^{+146}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot t\_1\\
\end{array}
\end{array}
if d < -1.3000000000000001e106Initial program 35.2%
Taylor expanded in d around inf 82.7%
associate-/l*91.4%
Simplified91.4%
if -1.3000000000000001e106 < d < -7.5000000000000005e-67 or 1.06000000000000004e-45 < d < 1.4499999999999999e146Initial program 79.1%
if -7.5000000000000005e-67 < d < 1.06000000000000004e-45Initial program 68.6%
Taylor expanded in c around inf 88.3%
associate-/l*88.4%
Simplified88.4%
if 1.4499999999999999e146 < d Initial program 24.3%
*-un-lft-identity24.3%
associate-*r/24.3%
fma-define24.3%
add-sqr-sqrt24.3%
times-frac24.3%
fma-define24.3%
hypot-define24.3%
fma-define24.3%
fma-define24.3%
hypot-define55.8%
Applied egg-rr55.8%
Taylor expanded in c around 0 72.8%
associate-/l*85.9%
*-commutative85.9%
Applied egg-rr85.9%
Final simplification85.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* c a) (* d b)) (+ (* c c) (* d d)))))
(if (<= d -9.5e+103)
(/ (+ b (* a (/ c d))) d)
(if (<= d -7.2e-67)
t_0
(if (<= d 1.05e-45)
(/ (+ a (* b (/ d c))) c)
(if (<= d 4.1e+148)
t_0
(* (/ 1.0 (hypot c d)) (+ b (* c (/ a d))))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d));
double tmp;
if (d <= -9.5e+103) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -7.2e-67) {
tmp = t_0;
} else if (d <= 1.05e-45) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 4.1e+148) {
tmp = t_0;
} else {
tmp = (1.0 / hypot(c, d)) * (b + (c * (a / d)));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d));
double tmp;
if (d <= -9.5e+103) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -7.2e-67) {
tmp = t_0;
} else if (d <= 1.05e-45) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 4.1e+148) {
tmp = t_0;
} else {
tmp = (1.0 / Math.hypot(c, d)) * (b + (c * (a / d)));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d)) tmp = 0 if d <= -9.5e+103: tmp = (b + (a * (c / d))) / d elif d <= -7.2e-67: tmp = t_0 elif d <= 1.05e-45: tmp = (a + (b * (d / c))) / c elif d <= 4.1e+148: tmp = t_0 else: tmp = (1.0 / math.hypot(c, d)) * (b + (c * (a / d))) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * a) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (d <= -9.5e+103) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= -7.2e-67) tmp = t_0; elseif (d <= 1.05e-45) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (d <= 4.1e+148) tmp = t_0; else tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(b + Float64(c * Float64(a / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -9.5e+103) tmp = (b + (a * (c / d))) / d; elseif (d <= -7.2e-67) tmp = t_0; elseif (d <= 1.05e-45) tmp = (a + (b * (d / c))) / c; elseif (d <= 4.1e+148) tmp = t_0; else tmp = (1.0 / hypot(c, d)) * (b + (c * (a / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -9.5e+103], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -7.2e-67], t$95$0, If[LessEqual[d, 1.05e-45], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 4.1e+148], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -9.5 \cdot 10^{+103}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq -7.2 \cdot 10^{-67}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.05 \cdot 10^{-45}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 4.1 \cdot 10^{+148}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + c \cdot \frac{a}{d}\right)\\
\end{array}
\end{array}
if d < -9.49999999999999922e103Initial program 35.2%
Taylor expanded in d around inf 82.7%
associate-/l*91.4%
Simplified91.4%
if -9.49999999999999922e103 < d < -7.19999999999999998e-67 or 1.04999999999999998e-45 < d < 4.0999999999999998e148Initial program 79.1%
if -7.19999999999999998e-67 < d < 1.04999999999999998e-45Initial program 68.6%
Taylor expanded in c around inf 88.3%
associate-/l*88.4%
Simplified88.4%
if 4.0999999999999998e148 < d Initial program 24.3%
*-un-lft-identity24.3%
associate-*r/24.3%
fma-define24.3%
add-sqr-sqrt24.3%
times-frac24.3%
fma-define24.3%
hypot-define24.3%
fma-define24.3%
fma-define24.3%
hypot-define55.8%
Applied egg-rr55.8%
Taylor expanded in c around 0 72.8%
*-commutative72.8%
*-un-lft-identity72.8%
times-frac86.0%
Applied egg-rr86.0%
Final simplification85.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* c a) (* d b)) (+ (* c c) (* d d))))
(t_1 (/ (+ b (* a (/ c d))) d)))
(if (<= d -2.1e+105)
t_1
(if (<= d -9.6e-68)
t_0
(if (<= d 2.05e-44)
(/ (+ a (* b (/ d c))) c)
(if (<= d 9.7e+145) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d));
double t_1 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -2.1e+105) {
tmp = t_1;
} else if (d <= -9.6e-68) {
tmp = t_0;
} else if (d <= 2.05e-44) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 9.7e+145) {
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 * a) + (d * b)) / ((c * c) + (d * d))
t_1 = (b + (a * (c / d))) / d
if (d <= (-2.1d+105)) then
tmp = t_1
else if (d <= (-9.6d-68)) then
tmp = t_0
else if (d <= 2.05d-44) then
tmp = (a + (b * (d / c))) / c
else if (d <= 9.7d+145) 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 * a) + (d * b)) / ((c * c) + (d * d));
double t_1 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -2.1e+105) {
tmp = t_1;
} else if (d <= -9.6e-68) {
tmp = t_0;
} else if (d <= 2.05e-44) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 9.7e+145) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d)) t_1 = (b + (a * (c / d))) / d tmp = 0 if d <= -2.1e+105: tmp = t_1 elif d <= -9.6e-68: tmp = t_0 elif d <= 2.05e-44: tmp = (a + (b * (d / c))) / c elif d <= 9.7e+145: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * a) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(b + Float64(a * Float64(c / d))) / d) tmp = 0.0 if (d <= -2.1e+105) tmp = t_1; elseif (d <= -9.6e-68) tmp = t_0; elseif (d <= 2.05e-44) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (d <= 9.7e+145) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d)); t_1 = (b + (a * (c / d))) / d; tmp = 0.0; if (d <= -2.1e+105) tmp = t_1; elseif (d <= -9.6e-68) tmp = t_0; elseif (d <= 2.05e-44) tmp = (a + (b * (d / c))) / c; elseif (d <= 9.7e+145) 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 * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.1e+105], t$95$1, If[LessEqual[d, -9.6e-68], t$95$0, If[LessEqual[d, 2.05e-44], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 9.7e+145], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\
t_1 := \frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{if}\;d \leq -2.1 \cdot 10^{+105}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -9.6 \cdot 10^{-68}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.05 \cdot 10^{-44}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 9.7 \cdot 10^{+145}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -2.1000000000000001e105 or 9.69999999999999987e145 < d Initial program 30.8%
Taylor expanded in d around inf 78.7%
associate-/l*89.1%
Simplified89.1%
if -2.1000000000000001e105 < d < -9.59999999999999965e-68 or 2.04999999999999996e-44 < d < 9.69999999999999987e145Initial program 79.1%
if -9.59999999999999965e-68 < d < 2.04999999999999996e-44Initial program 68.6%
Taylor expanded in c around inf 88.3%
associate-/l*88.4%
Simplified88.4%
Final simplification85.9%
(FPCore (a b c d)
:precision binary64
(if (<= d -2e+85)
(/ (+ b (* a (/ c d))) d)
(if (<= d -3.85e+21)
(/ (* d b) (+ (* c c) (* d d)))
(if (or (<= d -5e-21) (not (<= d 9.5e-37)))
(/ (+ b (/ a (/ d c))) d)
(/ (+ a (* b (/ d c))) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2e+85) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -3.85e+21) {
tmp = (d * b) / ((c * c) + (d * d));
} else if ((d <= -5e-21) || !(d <= 9.5e-37)) {
tmp = (b + (a / (d / c))) / d;
} else {
tmp = (a + (b * (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+85)) then
tmp = (b + (a * (c / d))) / d
else if (d <= (-3.85d+21)) then
tmp = (d * b) / ((c * c) + (d * d))
else if ((d <= (-5d-21)) .or. (.not. (d <= 9.5d-37))) then
tmp = (b + (a / (d / c))) / d
else
tmp = (a + (b * (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+85) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -3.85e+21) {
tmp = (d * b) / ((c * c) + (d * d));
} else if ((d <= -5e-21) || !(d <= 9.5e-37)) {
tmp = (b + (a / (d / c))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -2e+85: tmp = (b + (a * (c / d))) / d elif d <= -3.85e+21: tmp = (d * b) / ((c * c) + (d * d)) elif (d <= -5e-21) or not (d <= 9.5e-37): tmp = (b + (a / (d / c))) / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -2e+85) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= -3.85e+21) tmp = Float64(Float64(d * b) / Float64(Float64(c * c) + Float64(d * d))); elseif ((d <= -5e-21) || !(d <= 9.5e-37)) tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -2e+85) tmp = (b + (a * (c / d))) / d; elseif (d <= -3.85e+21) tmp = (d * b) / ((c * c) + (d * d)); elseif ((d <= -5e-21) || ~((d <= 9.5e-37))) tmp = (b + (a / (d / c))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -2e+85], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -3.85e+21], N[(N[(d * b), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[d, -5e-21], N[Not[LessEqual[d, 9.5e-37]], $MachinePrecision]], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2 \cdot 10^{+85}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq -3.85 \cdot 10^{+21}:\\
\;\;\;\;\frac{d \cdot b}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq -5 \cdot 10^{-21} \lor \neg \left(d \leq 9.5 \cdot 10^{-37}\right):\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -2e85Initial program 36.6%
Taylor expanded in d around inf 80.2%
associate-/l*88.2%
Simplified88.2%
if -2e85 < d < -3.85e21Initial program 88.7%
Taylor expanded in a around 0 83.1%
if -3.85e21 < d < -4.99999999999999973e-21 or 9.49999999999999927e-37 < d Initial program 56.5%
Taylor expanded in d around inf 64.9%
associate-/l*70.2%
Simplified70.2%
clear-num70.2%
un-div-inv70.2%
Applied egg-rr70.2%
if -4.99999999999999973e-21 < d < 9.49999999999999927e-37Initial program 69.1%
Taylor expanded in c around inf 86.1%
associate-/l*86.1%
Simplified86.1%
Final simplification81.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.8e+30) (not (<= d 4.8e+74))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.8e+30) || !(d <= 4.8e+74)) {
tmp = b / d;
} else {
tmp = (a + (b * (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 <= (-4.8d+30)) .or. (.not. (d <= 4.8d+74))) then
tmp = b / d
else
tmp = (a + (b * (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 <= -4.8e+30) || !(d <= 4.8e+74)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.8e+30) or not (d <= 4.8e+74): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.8e+30) || !(d <= 4.8e+74)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4.8e+30) || ~((d <= 4.8e+74))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.8e+30], N[Not[LessEqual[d, 4.8e+74]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.8 \cdot 10^{+30} \lor \neg \left(d \leq 4.8 \cdot 10^{+74}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -4.7999999999999999e30 or 4.80000000000000017e74 < d Initial program 44.8%
Taylor expanded in c around 0 76.1%
if -4.7999999999999999e30 < d < 4.80000000000000017e74Initial program 71.1%
Taylor expanded in c around inf 76.3%
associate-/l*76.4%
Simplified76.4%
Final simplification76.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5.8e-25) (not (<= d 9.5e-31))) (/ (+ b (* a (/ c d))) d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5.8e-25) || !(d <= 9.5e-31)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b * (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 <= (-5.8d-25)) .or. (.not. (d <= 9.5d-31))) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a + (b * (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 <= -5.8e-25) || !(d <= 9.5e-31)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5.8e-25) or not (d <= 9.5e-31): tmp = (b + (a * (c / d))) / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5.8e-25) || !(d <= 9.5e-31)) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -5.8e-25) || ~((d <= 9.5e-31))) tmp = (b + (a * (c / d))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5.8e-25], N[Not[LessEqual[d, 9.5e-31]], $MachinePrecision]], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.8 \cdot 10^{-25} \lor \neg \left(d \leq 9.5 \cdot 10^{-31}\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -5.8000000000000001e-25 or 9.5000000000000008e-31 < d Initial program 53.5%
Taylor expanded in d around inf 69.4%
associate-/l*75.0%
Simplified75.0%
if -5.8000000000000001e-25 < d < 9.5000000000000008e-31Initial program 69.1%
Taylor expanded in c around inf 86.1%
associate-/l*86.1%
Simplified86.1%
Final simplification79.9%
(FPCore (a b c d) :precision binary64 (if (<= d -1e-20) (/ (+ b (* a (/ c d))) d) (if (<= d 1.15e-30) (/ (+ a (* b (/ d c))) c) (/ (+ b (/ a (/ d c))) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1e-20) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= 1.15e-30) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + (a / (d / 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 (d <= (-1d-20)) then
tmp = (b + (a * (c / d))) / d
else if (d <= 1.15d-30) then
tmp = (a + (b * (d / c))) / c
else
tmp = (b + (a / (d / c))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1e-20) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= 1.15e-30) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + (a / (d / c))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1e-20: tmp = (b + (a * (c / d))) / d elif d <= 1.15e-30: tmp = (a + (b * (d / c))) / c else: tmp = (b + (a / (d / c))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1e-20) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= 1.15e-30) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1e-20) tmp = (b + (a * (c / d))) / d; elseif (d <= 1.15e-30) tmp = (a + (b * (d / c))) / c; else tmp = (b + (a / (d / c))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1e-20], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.15e-30], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1 \cdot 10^{-20}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq 1.15 \cdot 10^{-30}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\end{array}
\end{array}
if d < -9.99999999999999945e-21Initial program 55.3%
Taylor expanded in d around inf 73.5%
associate-/l*78.5%
Simplified78.5%
if -9.99999999999999945e-21 < d < 1.14999999999999992e-30Initial program 69.1%
Taylor expanded in c around inf 86.1%
associate-/l*86.1%
Simplified86.1%
if 1.14999999999999992e-30 < d Initial program 51.4%
Taylor expanded in d around inf 64.4%
associate-/l*70.7%
Simplified70.7%
clear-num70.7%
un-div-inv70.7%
Applied egg-rr70.7%
Final simplification79.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.3e+14) (not (<= d 1.3e-37))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.3e+14) || !(d <= 1.3e-37)) {
tmp = b / d;
} else {
tmp = a / 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 <= (-4.3d+14)) .or. (.not. (d <= 1.3d-37))) then
tmp = b / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.3e+14) || !(d <= 1.3e-37)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.3e+14) or not (d <= 1.3e-37): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.3e+14) || !(d <= 1.3e-37)) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4.3e+14) || ~((d <= 1.3e-37))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.3e+14], N[Not[LessEqual[d, 1.3e-37]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.3 \cdot 10^{+14} \lor \neg \left(d \leq 1.3 \cdot 10^{-37}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -4.3e14 or 1.2999999999999999e-37 < d Initial program 51.4%
Taylor expanded in c around 0 68.3%
if -4.3e14 < d < 1.2999999999999999e-37Initial program 70.0%
Taylor expanded in c around inf 65.3%
Final simplification66.8%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / 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 = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 60.4%
Taylor expanded in c around inf 43.0%
Final simplification43.0%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (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(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * 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 = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (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[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * 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{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024055
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))