
(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 12 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 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * 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(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= Inf) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * 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[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / 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[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / 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}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot 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 74.2%
*-un-lft-identity74.2%
associate-*r/74.2%
fma-define74.2%
add-sqr-sqrt74.2%
times-frac74.1%
fma-define74.1%
hypot-define74.1%
fma-define74.2%
fma-define74.1%
hypot-define96.0%
Applied egg-rr96.0%
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 50.0%
associate-/l*58.2%
Simplified58.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (* a c) (* b d))))
(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 = (a * c) + (b * d);
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 = (a * c) + (b * d);
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 = (a * c) + (b * d) 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(a * c) + Float64(b * d)) 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 = (a * c) + (b * d); 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[(a * c), $MachinePrecision] + N[(b * d), $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 := a \cdot c + b \cdot d\\
\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 74.2%
*-un-lft-identity74.2%
associate-*r/74.2%
fma-define74.2%
add-sqr-sqrt74.2%
times-frac74.1%
fma-define74.1%
hypot-define74.1%
fma-define74.2%
fma-define74.1%
hypot-define96.0%
Applied egg-rr96.0%
fma-define96.0%
+-commutative96.0%
Applied egg-rr96.0%
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 50.0%
associate-/l*58.2%
Simplified58.2%
Final simplification90.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ b (* a (/ c d)))))
(if (<= d -5.3e+95)
(* t_0 (/ -1.0 (hypot c d)))
(if (<= d -1.2e-91)
(/ (fma a c (* b d)) (fma c c (* d d)))
(if (<= d 4.6e-150)
(/ (+ a (/ (* b d) c)) c)
(if (<= d 1.1e+132)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(/ t_0 d)))))))
double code(double a, double b, double c, double d) {
double t_0 = b + (a * (c / d));
double tmp;
if (d <= -5.3e+95) {
tmp = t_0 * (-1.0 / hypot(c, d));
} else if (d <= -1.2e-91) {
tmp = fma(a, c, (b * d)) / fma(c, c, (d * d));
} else if (d <= 4.6e-150) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 1.1e+132) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = t_0 / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(b + Float64(a * Float64(c / d))) tmp = 0.0 if (d <= -5.3e+95) tmp = Float64(t_0 * Float64(-1.0 / hypot(c, d))); elseif (d <= -1.2e-91) tmp = Float64(fma(a, c, Float64(b * d)) / fma(c, c, Float64(d * d))); elseif (d <= 4.6e-150) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif (d <= 1.1e+132) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(t_0 / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.3e+95], N[(t$95$0 * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.2e-91], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.6e-150], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.1e+132], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b + a \cdot \frac{c}{d}\\
\mathbf{if}\;d \leq -5.3 \cdot 10^{+95}:\\
\;\;\;\;t\_0 \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq -1.2 \cdot 10^{-91}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;d \leq 4.6 \cdot 10^{-150}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.1 \cdot 10^{+132}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{d}\\
\end{array}
\end{array}
if d < -5.3000000000000002e95Initial program 41.1%
*-un-lft-identity41.1%
associate-*r/41.1%
fma-define41.1%
add-sqr-sqrt41.1%
times-frac41.2%
fma-define41.2%
hypot-define41.2%
fma-define41.2%
fma-define41.2%
hypot-define70.9%
Applied egg-rr70.9%
Taylor expanded in d around -inf 81.8%
distribute-lft-out81.8%
associate-/l*82.3%
Simplified82.3%
if -5.3000000000000002e95 < d < -1.20000000000000005e-91Initial program 87.8%
fma-define87.9%
fma-define87.9%
Simplified87.9%
if -1.20000000000000005e-91 < d < 4.60000000000000006e-150Initial program 65.7%
Taylor expanded in c around inf 93.8%
if 4.60000000000000006e-150 < d < 1.09999999999999994e132Initial program 80.8%
if 1.09999999999999994e132 < d Initial program 26.9%
Taylor expanded in d around inf 78.8%
associate-/l*84.4%
Simplified84.4%
Final simplification87.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (* a c) (* b d))) (t_1 (+ b (* a (/ c d)))))
(if (<= d -8.6e+95)
(* t_1 (/ -1.0 (hypot c d)))
(if (<= d -3e-90)
(/ t_0 (fma c c (* d d)))
(if (<= d 9.2e-148)
(/ (+ a (/ (* b d) c)) c)
(if (<= d 1.1e+132) (/ t_0 (+ (* c c) (* d d))) (/ t_1 d)))))))
double code(double a, double b, double c, double d) {
double t_0 = (a * c) + (b * d);
double t_1 = b + (a * (c / d));
double tmp;
if (d <= -8.6e+95) {
tmp = t_1 * (-1.0 / hypot(c, d));
} else if (d <= -3e-90) {
tmp = t_0 / fma(c, c, (d * d));
} else if (d <= 9.2e-148) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 1.1e+132) {
tmp = t_0 / ((c * c) + (d * d));
} else {
tmp = t_1 / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(a * c) + Float64(b * d)) t_1 = Float64(b + Float64(a * Float64(c / d))) tmp = 0.0 if (d <= -8.6e+95) tmp = Float64(t_1 * Float64(-1.0 / hypot(c, d))); elseif (d <= -3e-90) tmp = Float64(t_0 / fma(c, c, Float64(d * d))); elseif (d <= 9.2e-148) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif (d <= 1.1e+132) tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(t_1 / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -8.6e+95], N[(t$95$1 * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -3e-90], N[(t$95$0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 9.2e-148], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.1e+132], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 / d), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot c + b \cdot d\\
t_1 := b + a \cdot \frac{c}{d}\\
\mathbf{if}\;d \leq -8.6 \cdot 10^{+95}:\\
\;\;\;\;t\_1 \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq -3 \cdot 10^{-90}:\\
\;\;\;\;\frac{t\_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;d \leq 9.2 \cdot 10^{-148}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.1 \cdot 10^{+132}:\\
\;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{d}\\
\end{array}
\end{array}
if d < -8.6e95Initial program 41.1%
*-un-lft-identity41.1%
associate-*r/41.1%
fma-define41.1%
add-sqr-sqrt41.1%
times-frac41.2%
fma-define41.2%
hypot-define41.2%
fma-define41.2%
fma-define41.2%
hypot-define70.9%
Applied egg-rr70.9%
Taylor expanded in d around -inf 81.8%
distribute-lft-out81.8%
associate-/l*82.3%
Simplified82.3%
if -8.6e95 < d < -3.0000000000000002e-90Initial program 87.8%
fma-define87.9%
fma-define87.9%
Simplified87.9%
fma-define97.2%
+-commutative97.2%
Applied egg-rr87.9%
if -3.0000000000000002e-90 < d < 9.1999999999999999e-148Initial program 65.7%
Taylor expanded in c around inf 93.8%
if 9.1999999999999999e-148 < d < 1.09999999999999994e132Initial program 80.8%
if 1.09999999999999994e132 < d Initial program 26.9%
Taylor expanded in d around inf 78.8%
associate-/l*84.4%
Simplified84.4%
Final simplification87.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (* a c) (* b d))) (t_1 (/ (+ b (* a (/ c d))) d)))
(if (<= d -4.7e+77)
t_1
(if (<= d -2.4e-91)
(/ t_0 (fma c c (* d d)))
(if (<= d 2.4e-150)
(/ (+ a (/ (* b d) c)) c)
(if (<= d 2.2e+132) (/ t_0 (+ (* c c) (* d d))) t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = (a * c) + (b * d);
double t_1 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -4.7e+77) {
tmp = t_1;
} else if (d <= -2.4e-91) {
tmp = t_0 / fma(c, c, (d * d));
} else if (d <= 2.4e-150) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 2.2e+132) {
tmp = t_0 / ((c * c) + (d * d));
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(a * c) + Float64(b * d)) t_1 = Float64(Float64(b + Float64(a * Float64(c / d))) / d) tmp = 0.0 if (d <= -4.7e+77) tmp = t_1; elseif (d <= -2.4e-91) tmp = Float64(t_0 / fma(c, c, Float64(d * d))); elseif (d <= 2.4e-150) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif (d <= 2.2e+132) tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -4.7e+77], t$95$1, If[LessEqual[d, -2.4e-91], N[(t$95$0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.4e-150], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.2e+132], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot c + b \cdot d\\
t_1 := \frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{if}\;d \leq -4.7 \cdot 10^{+77}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -2.4 \cdot 10^{-91}:\\
\;\;\;\;\frac{t\_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;d \leq 2.4 \cdot 10^{-150}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.2 \cdot 10^{+132}:\\
\;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -4.7000000000000001e77 or 2.19999999999999989e132 < d Initial program 38.3%
Taylor expanded in d around inf 81.6%
associate-/l*84.3%
Simplified84.3%
if -4.7000000000000001e77 < d < -2.40000000000000011e-91Initial program 86.2%
fma-define86.3%
fma-define86.3%
Simplified86.3%
fma-define96.9%
+-commutative96.9%
Applied egg-rr86.3%
if -2.40000000000000011e-91 < d < 2.4e-150Initial program 65.7%
Taylor expanded in c around inf 93.8%
if 2.4e-150 < d < 2.19999999999999989e132Initial program 80.8%
Final simplification87.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (/ (+ b (* a (/ c d))) d)))
(if (<= d -4.4e+77)
t_1
(if (<= d -8.8e-88)
t_0
(if (<= d 8.2e-148)
(/ (+ a (/ (* b d) c)) c)
(if (<= d 1.1e+132) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -4.4e+77) {
tmp = t_1;
} else if (d <= -8.8e-88) {
tmp = t_0;
} else if (d <= 8.2e-148) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 1.1e+132) {
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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
t_1 = (b + (a * (c / d))) / d
if (d <= (-4.4d+77)) then
tmp = t_1
else if (d <= (-8.8d-88)) then
tmp = t_0
else if (d <= 8.2d-148) then
tmp = (a + ((b * d) / c)) / c
else if (d <= 1.1d+132) 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 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -4.4e+77) {
tmp = t_1;
} else if (d <= -8.8e-88) {
tmp = t_0;
} else if (d <= 8.2e-148) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 1.1e+132) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = (b + (a * (c / d))) / d tmp = 0 if d <= -4.4e+77: tmp = t_1 elif d <= -8.8e-88: tmp = t_0 elif d <= 8.2e-148: tmp = (a + ((b * d) / c)) / c elif d <= 1.1e+132: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(b + Float64(a * Float64(c / d))) / d) tmp = 0.0 if (d <= -4.4e+77) tmp = t_1; elseif (d <= -8.8e-88) tmp = t_0; elseif (d <= 8.2e-148) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif (d <= 1.1e+132) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); t_1 = (b + (a * (c / d))) / d; tmp = 0.0; if (d <= -4.4e+77) tmp = t_1; elseif (d <= -8.8e-88) tmp = t_0; elseif (d <= 8.2e-148) tmp = (a + ((b * d) / c)) / c; elseif (d <= 1.1e+132) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $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, -4.4e+77], t$95$1, If[LessEqual[d, -8.8e-88], t$95$0, If[LessEqual[d, 8.2e-148], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.1e+132], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{if}\;d \leq -4.4 \cdot 10^{+77}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -8.8 \cdot 10^{-88}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 8.2 \cdot 10^{-148}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.1 \cdot 10^{+132}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -4.4000000000000001e77 or 1.09999999999999994e132 < d Initial program 38.3%
Taylor expanded in d around inf 81.6%
associate-/l*84.3%
Simplified84.3%
if -4.4000000000000001e77 < d < -8.8000000000000002e-88 or 8.2000000000000005e-148 < d < 1.09999999999999994e132Initial program 83.0%
if -8.8000000000000002e-88 < d < 8.2000000000000005e-148Initial program 65.7%
Taylor expanded in c around inf 93.8%
(FPCore (a b c d)
:precision binary64
(if (<= d -4e-50)
(/ b d)
(if (<= d 3.5e+19)
(/ (+ a (/ (* b d) c)) c)
(if (or (<= d 2.4e+116) (not (<= d 2.9e+180)))
(/ b d)
(/ (+ a (/ b (/ c d))) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4e-50) {
tmp = b / d;
} else if (d <= 3.5e+19) {
tmp = (a + ((b * d) / c)) / c;
} else if ((d <= 2.4e+116) || !(d <= 2.9e+180)) {
tmp = b / d;
} else {
tmp = (a + (b / (c / d))) / 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 <= (-4d-50)) then
tmp = b / d
else if (d <= 3.5d+19) then
tmp = (a + ((b * d) / c)) / c
else if ((d <= 2.4d+116) .or. (.not. (d <= 2.9d+180))) then
tmp = b / d
else
tmp = (a + (b / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4e-50) {
tmp = b / d;
} else if (d <= 3.5e+19) {
tmp = (a + ((b * d) / c)) / c;
} else if ((d <= 2.4e+116) || !(d <= 2.9e+180)) {
tmp = b / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -4e-50: tmp = b / d elif d <= 3.5e+19: tmp = (a + ((b * d) / c)) / c elif (d <= 2.4e+116) or not (d <= 2.9e+180): tmp = b / d else: tmp = (a + (b / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -4e-50) tmp = Float64(b / d); elseif (d <= 3.5e+19) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif ((d <= 2.4e+116) || !(d <= 2.9e+180)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -4e-50) tmp = b / d; elseif (d <= 3.5e+19) tmp = (a + ((b * d) / c)) / c; elseif ((d <= 2.4e+116) || ~((d <= 2.9e+180))) tmp = b / d; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -4e-50], N[(b / d), $MachinePrecision], If[LessEqual[d, 3.5e+19], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[d, 2.4e+116], N[Not[LessEqual[d, 2.9e+180]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4 \cdot 10^{-50}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 3.5 \cdot 10^{+19}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.4 \cdot 10^{+116} \lor \neg \left(d \leq 2.9 \cdot 10^{+180}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -4.00000000000000003e-50 or 3.5e19 < d < 2.4e116 or 2.90000000000000007e180 < d Initial program 58.4%
Taylor expanded in c around 0 66.8%
if -4.00000000000000003e-50 < d < 3.5e19Initial program 70.0%
Taylor expanded in c around inf 84.5%
if 2.4e116 < d < 2.90000000000000007e180Initial program 28.1%
Taylor expanded in c around inf 43.6%
clear-num43.4%
inv-pow43.4%
*-commutative43.4%
associate-/r*67.9%
Applied egg-rr67.9%
unpow-167.9%
Simplified67.9%
Taylor expanded in c around 0 43.6%
associate-*l/67.9%
associate-/r/67.9%
Simplified67.9%
Final simplification76.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4e-50) (not (<= d 280000000000.0))) (/ (+ b (* a (/ c d))) d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4e-50) || !(d <= 280000000000.0)) {
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 <= (-4d-50)) .or. (.not. (d <= 280000000000.0d0))) 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 <= -4e-50) || !(d <= 280000000000.0)) {
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 <= -4e-50) or not (d <= 280000000000.0): 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 <= -4e-50) || !(d <= 280000000000.0)) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4e-50) || ~((d <= 280000000000.0))) 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, -4e-50], N[Not[LessEqual[d, 280000000000.0]], $MachinePrecision]], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4 \cdot 10^{-50} \lor \neg \left(d \leq 280000000000\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -4.00000000000000003e-50 or 2.8e11 < d Initial program 57.1%
Taylor expanded in d around inf 76.5%
associate-/l*77.7%
Simplified77.7%
if -4.00000000000000003e-50 < d < 2.8e11Initial program 69.6%
Taylor expanded in c around inf 85.0%
Final simplification81.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4e-50) (not (<= d 2.9e+180))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4e-50) || !(d <= 2.9e+180)) {
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 <= (-4d-50)) .or. (.not. (d <= 2.9d+180))) 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 <= -4e-50) || !(d <= 2.9e+180)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4e-50) or not (d <= 2.9e+180): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4e-50) || !(d <= 2.9e+180)) 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 <= -4e-50) || ~((d <= 2.9e+180))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4e-50], N[Not[LessEqual[d, 2.9e+180]], $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 \cdot 10^{-50} \lor \neg \left(d \leq 2.9 \cdot 10^{+180}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -4.00000000000000003e-50 or 2.90000000000000007e180 < d Initial program 54.6%
Taylor expanded in c around 0 69.1%
if -4.00000000000000003e-50 < d < 2.90000000000000007e180Initial program 69.1%
Taylor expanded in c around inf 76.0%
associate-/l*76.9%
Simplified76.9%
Final simplification73.9%
(FPCore (a b c d)
:precision binary64
(if (<= d -4e-50)
(/ (+ b (/ (* a c) d)) d)
(if (<= d 2150000000000.0)
(/ (+ a (/ (* b d) c)) c)
(/ (+ b (* a (/ c d))) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4e-50) {
tmp = (b + ((a * c) / d)) / d;
} else if (d <= 2150000000000.0) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = (b + (a * (c / d))) / 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 <= (-4d-50)) then
tmp = (b + ((a * c) / d)) / d
else if (d <= 2150000000000.0d0) then
tmp = (a + ((b * d) / c)) / c
else
tmp = (b + (a * (c / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4e-50) {
tmp = (b + ((a * c) / d)) / d;
} else if (d <= 2150000000000.0) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -4e-50: tmp = (b + ((a * c) / d)) / d elif d <= 2150000000000.0: tmp = (a + ((b * d) / c)) / c else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -4e-50) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (d <= 2150000000000.0) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -4e-50) tmp = (b + ((a * c) / d)) / d; elseif (d <= 2150000000000.0) tmp = (a + ((b * d) / c)) / c; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -4e-50], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 2150000000000.0], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4 \cdot 10^{-50}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;d \leq 2150000000000:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if d < -4.00000000000000003e-50Initial program 64.6%
Taylor expanded in d around inf 79.3%
if -4.00000000000000003e-50 < d < 2.15e12Initial program 69.6%
Taylor expanded in c around inf 85.0%
if 2.15e12 < d Initial program 47.8%
Taylor expanded in d around inf 72.9%
associate-/l*76.6%
Simplified76.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5.4e-104) (not (<= d 3.6e+20))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5.4e-104) || !(d <= 3.6e+20)) {
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 <= (-5.4d-104)) .or. (.not. (d <= 3.6d+20))) 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 <= -5.4e-104) || !(d <= 3.6e+20)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5.4e-104) or not (d <= 3.6e+20): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5.4e-104) || !(d <= 3.6e+20)) 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 <= -5.4e-104) || ~((d <= 3.6e+20))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5.4e-104], N[Not[LessEqual[d, 3.6e+20]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.4 \cdot 10^{-104} \lor \neg \left(d \leq 3.6 \cdot 10^{+20}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -5.3999999999999997e-104 or 3.6e20 < d Initial program 58.5%
Taylor expanded in c around 0 61.7%
if -5.3999999999999997e-104 < d < 3.6e20Initial program 68.9%
Taylor expanded in c around inf 68.8%
Final simplification65.0%
(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 63.4%
Taylor expanded in c around inf 41.4%
(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 2024100
(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))))