
(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 10 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 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -1.5e+137)
(* (+ b (/ a (/ d c))) (/ -1.0 (hypot c d)))
(if (<= d -2.65e-107)
t_0
(if (<= d 2.3e-77)
(+ (/ a c) (/ (/ (* b d) c) c))
(if (<= d 4.1e+75)
t_0
(* (/ 1.0 (hypot c d)) (+ b (/ c (/ d a))))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.5e+137) {
tmp = (b + (a / (d / c))) * (-1.0 / hypot(c, d));
} else if (d <= -2.65e-107) {
tmp = t_0;
} else if (d <= 2.3e-77) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 4.1e+75) {
tmp = t_0;
} else {
tmp = (1.0 / hypot(c, d)) * (b + (c / (d / a)));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.5e+137) {
tmp = (b + (a / (d / c))) * (-1.0 / Math.hypot(c, d));
} else if (d <= -2.65e-107) {
tmp = t_0;
} else if (d <= 2.3e-77) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 4.1e+75) {
tmp = t_0;
} else {
tmp = (1.0 / Math.hypot(c, d)) * (b + (c / (d / a)));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -1.5e+137: tmp = (b + (a / (d / c))) * (-1.0 / math.hypot(c, d)) elif d <= -2.65e-107: tmp = t_0 elif d <= 2.3e-77: tmp = (a / c) + (((b * d) / c) / c) elif d <= 4.1e+75: tmp = t_0 else: tmp = (1.0 / math.hypot(c, d)) * (b + (c / (d / a))) 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))) tmp = 0.0 if (d <= -1.5e+137) tmp = Float64(Float64(b + Float64(a / Float64(d / c))) * Float64(-1.0 / hypot(c, d))); elseif (d <= -2.65e-107) tmp = t_0; elseif (d <= 2.3e-77) tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); elseif (d <= 4.1e+75) tmp = t_0; else tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(b + Float64(c / Float64(d / a)))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -1.5e+137) tmp = (b + (a / (d / c))) * (-1.0 / hypot(c, d)); elseif (d <= -2.65e-107) tmp = t_0; elseif (d <= 2.3e-77) tmp = (a / c) + (((b * d) / c) / c); elseif (d <= 4.1e+75) tmp = t_0; else tmp = (1.0 / hypot(c, d)) * (b + (c / (d / a))); 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]}, If[LessEqual[d, -1.5e+137], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.65e-107], t$95$0, If[LessEqual[d, 2.3e-77], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.1e+75], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b + N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -1.5 \cdot 10^{+137}:\\
\;\;\;\;\left(b + \frac{a}{\frac{d}{c}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq -2.65 \cdot 10^{-107}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.3 \cdot 10^{-77}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 4.1 \cdot 10^{+75}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + \frac{c}{\frac{d}{a}}\right)\\
\end{array}
\end{array}
if d < -1.5e137Initial program 36.1%
*-un-lft-identity36.1%
add-sqr-sqrt36.1%
times-frac36.1%
hypot-def36.1%
fma-def36.1%
hypot-def56.6%
Applied egg-rr56.6%
Taylor expanded in d around -inf 75.9%
neg-mul-175.9%
+-commutative75.9%
unsub-neg75.9%
mul-1-neg75.9%
associate-/l*80.6%
distribute-neg-frac80.6%
Simplified80.6%
if -1.5e137 < d < -2.65e-107 or 2.29999999999999999e-77 < d < 4.0999999999999998e75Initial program 84.1%
if -2.65e-107 < d < 2.29999999999999999e-77Initial program 69.0%
Taylor expanded in c around inf 86.0%
associate-/l*83.2%
Simplified83.2%
clear-num83.2%
associate-/r/83.2%
clear-num83.5%
Applied egg-rr83.5%
associate-*l/86.0%
unpow286.0%
associate-/r*92.8%
*-commutative92.8%
Applied egg-rr92.8%
if 4.0999999999999998e75 < d Initial program 22.8%
*-un-lft-identity22.8%
add-sqr-sqrt22.8%
times-frac22.9%
hypot-def22.9%
fma-def22.9%
hypot-def44.3%
Applied egg-rr44.3%
Taylor expanded in c around 0 81.4%
associate-/l*90.2%
Simplified90.2%
clear-num90.2%
associate-/r/90.2%
clear-num90.3%
Applied egg-rr90.3%
associate-*l/81.4%
associate-/l*90.3%
Applied egg-rr90.3%
Final simplification87.8%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 2e+272) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (* (/ 1.0 d) (+ b (* a (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 2e+272) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (1.0 / d) * (b + (a * (c / 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))) <= 2e+272) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / 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], 2e+272], 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[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+272}:\\
\;\;\;\;\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{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 2.0000000000000001e272Initial program 78.9%
*-un-lft-identity78.9%
add-sqr-sqrt78.9%
times-frac78.8%
hypot-def78.8%
fma-def78.8%
hypot-def96.2%
Applied egg-rr96.2%
if 2.0000000000000001e272 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 8.5%
*-un-lft-identity8.5%
add-sqr-sqrt8.5%
times-frac8.5%
hypot-def8.5%
fma-def8.5%
hypot-def10.8%
Applied egg-rr10.8%
Taylor expanded in c around 0 32.1%
associate-/l*38.2%
Simplified38.2%
clear-num38.2%
associate-/r/38.2%
clear-num38.2%
Applied egg-rr38.2%
Taylor expanded in c around 0 60.0%
Final simplification87.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -1.85e+137)
(* (/ 1.0 d) (+ b (/ a (/ d c))))
(if (<= d -1.65e-105)
t_0
(if (<= d 4.5e-78)
(+ (/ a c) (/ (/ (* b d) c) c))
(if (<= d 4e+75) t_0 (* (/ 1.0 (hypot c d)) (+ b (* a (/ c d))))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.85e+137) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (d <= -1.65e-105) {
tmp = t_0;
} else if (d <= 4.5e-78) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 4e+75) {
tmp = t_0;
} else {
tmp = (1.0 / hypot(c, d)) * (b + (a * (c / d)));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.85e+137) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (d <= -1.65e-105) {
tmp = t_0;
} else if (d <= 4.5e-78) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 4e+75) {
tmp = t_0;
} else {
tmp = (1.0 / Math.hypot(c, d)) * (b + (a * (c / d)));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -1.85e+137: tmp = (1.0 / d) * (b + (a / (d / c))) elif d <= -1.65e-105: tmp = t_0 elif d <= 4.5e-78: tmp = (a / c) + (((b * d) / c) / c) elif d <= 4e+75: tmp = t_0 else: tmp = (1.0 / math.hypot(c, d)) * (b + (a * (c / d))) 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))) tmp = 0.0 if (d <= -1.85e+137) tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c)))); elseif (d <= -1.65e-105) tmp = t_0; elseif (d <= 4.5e-78) tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); elseif (d <= 4e+75) tmp = t_0; else tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(b + Float64(a * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -1.85e+137) tmp = (1.0 / d) * (b + (a / (d / c))); elseif (d <= -1.65e-105) tmp = t_0; elseif (d <= 4.5e-78) tmp = (a / c) + (((b * d) / c) / c); elseif (d <= 4e+75) tmp = t_0; else tmp = (1.0 / hypot(c, d)) * (b + (a * (c / d))); 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]}, If[LessEqual[d, -1.85e+137], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.65e-105], t$95$0, If[LessEqual[d, 4.5e-78], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4e+75], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -1.85 \cdot 10^{+137}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\mathbf{elif}\;d \leq -1.65 \cdot 10^{-105}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 4.5 \cdot 10^{-78}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 4 \cdot 10^{+75}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + a \cdot \frac{c}{d}\right)\\
\end{array}
\end{array}
if d < -1.8500000000000001e137Initial program 36.1%
*-un-lft-identity36.1%
add-sqr-sqrt36.1%
times-frac36.1%
hypot-def36.1%
fma-def36.1%
hypot-def56.6%
Applied egg-rr56.6%
Taylor expanded in c around 0 28.3%
associate-/l*28.5%
Simplified28.5%
Taylor expanded in c around 0 77.7%
if -1.8500000000000001e137 < d < -1.6499999999999999e-105 or 4.5e-78 < d < 3.99999999999999971e75Initial program 84.1%
if -1.6499999999999999e-105 < d < 4.5e-78Initial program 69.0%
Taylor expanded in c around inf 86.0%
associate-/l*83.2%
Simplified83.2%
clear-num83.2%
associate-/r/83.2%
clear-num83.5%
Applied egg-rr83.5%
associate-*l/86.0%
unpow286.0%
associate-/r*92.8%
*-commutative92.8%
Applied egg-rr92.8%
if 3.99999999999999971e75 < d Initial program 22.8%
*-un-lft-identity22.8%
add-sqr-sqrt22.8%
times-frac22.9%
hypot-def22.9%
fma-def22.9%
hypot-def44.3%
Applied egg-rr44.3%
Taylor expanded in c around 0 81.4%
associate-/l*90.2%
Simplified90.2%
clear-num90.2%
associate-/r/90.2%
clear-num90.3%
Applied egg-rr90.3%
Final simplification87.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -1.66e+137)
(* (/ 1.0 d) (+ b (/ a (/ d c))))
(if (<= d -5.1e-107)
t_0
(if (<= d 2.5e-77)
(+ (/ a c) (/ (/ (* b d) c) c))
(if (<= d 4.2e+75)
t_0
(* (/ 1.0 (hypot c d)) (+ b (/ c (/ d a))))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.66e+137) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (d <= -5.1e-107) {
tmp = t_0;
} else if (d <= 2.5e-77) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 4.2e+75) {
tmp = t_0;
} else {
tmp = (1.0 / hypot(c, d)) * (b + (c / (d / a)));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.66e+137) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (d <= -5.1e-107) {
tmp = t_0;
} else if (d <= 2.5e-77) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 4.2e+75) {
tmp = t_0;
} else {
tmp = (1.0 / Math.hypot(c, d)) * (b + (c / (d / a)));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -1.66e+137: tmp = (1.0 / d) * (b + (a / (d / c))) elif d <= -5.1e-107: tmp = t_0 elif d <= 2.5e-77: tmp = (a / c) + (((b * d) / c) / c) elif d <= 4.2e+75: tmp = t_0 else: tmp = (1.0 / math.hypot(c, d)) * (b + (c / (d / a))) 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))) tmp = 0.0 if (d <= -1.66e+137) tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c)))); elseif (d <= -5.1e-107) tmp = t_0; elseif (d <= 2.5e-77) tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); elseif (d <= 4.2e+75) tmp = t_0; else tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(b + Float64(c / Float64(d / a)))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -1.66e+137) tmp = (1.0 / d) * (b + (a / (d / c))); elseif (d <= -5.1e-107) tmp = t_0; elseif (d <= 2.5e-77) tmp = (a / c) + (((b * d) / c) / c); elseif (d <= 4.2e+75) tmp = t_0; else tmp = (1.0 / hypot(c, d)) * (b + (c / (d / a))); 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]}, If[LessEqual[d, -1.66e+137], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5.1e-107], t$95$0, If[LessEqual[d, 2.5e-77], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.2e+75], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b + N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -1.66 \cdot 10^{+137}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\mathbf{elif}\;d \leq -5.1 \cdot 10^{-107}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.5 \cdot 10^{-77}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 4.2 \cdot 10^{+75}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + \frac{c}{\frac{d}{a}}\right)\\
\end{array}
\end{array}
if d < -1.65999999999999991e137Initial program 36.1%
*-un-lft-identity36.1%
add-sqr-sqrt36.1%
times-frac36.1%
hypot-def36.1%
fma-def36.1%
hypot-def56.6%
Applied egg-rr56.6%
Taylor expanded in c around 0 28.3%
associate-/l*28.5%
Simplified28.5%
Taylor expanded in c around 0 77.7%
if -1.65999999999999991e137 < d < -5.1000000000000002e-107 or 2.49999999999999982e-77 < d < 4.19999999999999997e75Initial program 84.1%
if -5.1000000000000002e-107 < d < 2.49999999999999982e-77Initial program 69.0%
Taylor expanded in c around inf 86.0%
associate-/l*83.2%
Simplified83.2%
clear-num83.2%
associate-/r/83.2%
clear-num83.5%
Applied egg-rr83.5%
associate-*l/86.0%
unpow286.0%
associate-/r*92.8%
*-commutative92.8%
Applied egg-rr92.8%
if 4.19999999999999997e75 < d Initial program 22.8%
*-un-lft-identity22.8%
add-sqr-sqrt22.8%
times-frac22.9%
hypot-def22.9%
fma-def22.9%
hypot-def44.3%
Applied egg-rr44.3%
Taylor expanded in c around 0 81.4%
associate-/l*90.2%
Simplified90.2%
clear-num90.2%
associate-/r/90.2%
clear-num90.3%
Applied egg-rr90.3%
associate-*l/81.4%
associate-/l*90.3%
Applied egg-rr90.3%
Final simplification87.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -1.5e+137)
(* (/ 1.0 d) (+ b (/ a (/ d c))))
(if (<= d -8.5e-106)
t_0
(if (<= d 3.2e-78)
(+ (/ a c) (/ (/ (* b d) c) c))
(if (<= d 3.7e+75) t_0 (* (/ 1.0 d) (+ b (* a (/ c d))))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.5e+137) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (d <= -8.5e-106) {
tmp = t_0;
} else if (d <= 3.2e-78) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 3.7e+75) {
tmp = t_0;
} else {
tmp = (1.0 / d) * (b + (a * (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) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (d <= (-1.5d+137)) then
tmp = (1.0d0 / d) * (b + (a / (d / c)))
else if (d <= (-8.5d-106)) then
tmp = t_0
else if (d <= 3.2d-78) then
tmp = (a / c) + (((b * d) / c) / c)
else if (d <= 3.7d+75) then
tmp = t_0
else
tmp = (1.0d0 / d) * (b + (a * (c / d)))
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 tmp;
if (d <= -1.5e+137) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (d <= -8.5e-106) {
tmp = t_0;
} else if (d <= 3.2e-78) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 3.7e+75) {
tmp = t_0;
} else {
tmp = (1.0 / d) * (b + (a * (c / d)));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -1.5e+137: tmp = (1.0 / d) * (b + (a / (d / c))) elif d <= -8.5e-106: tmp = t_0 elif d <= 3.2e-78: tmp = (a / c) + (((b * d) / c) / c) elif d <= 3.7e+75: tmp = t_0 else: tmp = (1.0 / d) * (b + (a * (c / d))) 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))) tmp = 0.0 if (d <= -1.5e+137) tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c)))); elseif (d <= -8.5e-106) tmp = t_0; elseif (d <= 3.2e-78) tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); elseif (d <= 3.7e+75) tmp = t_0; else tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -1.5e+137) tmp = (1.0 / d) * (b + (a / (d / c))); elseif (d <= -8.5e-106) tmp = t_0; elseif (d <= 3.2e-78) tmp = (a / c) + (((b * d) / c) / c); elseif (d <= 3.7e+75) tmp = t_0; else tmp = (1.0 / d) * (b + (a * (c / d))); 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]}, If[LessEqual[d, -1.5e+137], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -8.5e-106], t$95$0, If[LessEqual[d, 3.2e-78], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.7e+75], t$95$0, N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -1.5 \cdot 10^{+137}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\mathbf{elif}\;d \leq -8.5 \cdot 10^{-106}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 3.2 \cdot 10^{-78}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 3.7 \cdot 10^{+75}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\
\end{array}
\end{array}
if d < -1.5e137Initial program 36.1%
*-un-lft-identity36.1%
add-sqr-sqrt36.1%
times-frac36.1%
hypot-def36.1%
fma-def36.1%
hypot-def56.6%
Applied egg-rr56.6%
Taylor expanded in c around 0 28.3%
associate-/l*28.5%
Simplified28.5%
Taylor expanded in c around 0 77.7%
if -1.5e137 < d < -8.4999999999999998e-106 or 3.2e-78 < d < 3.70000000000000011e75Initial program 84.1%
if -8.4999999999999998e-106 < d < 3.2e-78Initial program 69.0%
Taylor expanded in c around inf 86.0%
associate-/l*83.2%
Simplified83.2%
clear-num83.2%
associate-/r/83.2%
clear-num83.5%
Applied egg-rr83.5%
associate-*l/86.0%
unpow286.0%
associate-/r*92.8%
*-commutative92.8%
Applied egg-rr92.8%
if 3.70000000000000011e75 < d Initial program 22.8%
*-un-lft-identity22.8%
add-sqr-sqrt22.8%
times-frac22.9%
hypot-def22.9%
fma-def22.9%
hypot-def44.3%
Applied egg-rr44.3%
Taylor expanded in c around 0 81.4%
associate-/l*90.2%
Simplified90.2%
clear-num90.2%
associate-/r/90.2%
clear-num90.3%
Applied egg-rr90.3%
Taylor expanded in c around 0 90.2%
Final simplification87.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.3e-6) (not (<= c 1.25e+32))) (/ a c) (* (/ 1.0 d) (+ b (* a (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.3e-6) || !(c <= 1.25e+32)) {
tmp = a / c;
} else {
tmp = (1.0 / d) * (b + (a * (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 ((c <= (-1.3d-6)) .or. (.not. (c <= 1.25d+32))) then
tmp = a / c
else
tmp = (1.0d0 / d) * (b + (a * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.3e-6) || !(c <= 1.25e+32)) {
tmp = a / c;
} else {
tmp = (1.0 / d) * (b + (a * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.3e-6) or not (c <= 1.25e+32): tmp = a / c else: tmp = (1.0 / d) * (b + (a * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.3e-6) || !(c <= 1.25e+32)) tmp = Float64(a / c); else tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.3e-6) || ~((c <= 1.25e+32))) tmp = a / c; else tmp = (1.0 / d) * (b + (a * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.3e-6], N[Not[LessEqual[c, 1.25e+32]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.3 \cdot 10^{-6} \lor \neg \left(c \leq 1.25 \cdot 10^{+32}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\
\end{array}
\end{array}
if c < -1.30000000000000005e-6 or 1.2499999999999999e32 < c Initial program 51.3%
Taylor expanded in c around inf 67.2%
if -1.30000000000000005e-6 < c < 1.2499999999999999e32Initial program 71.7%
*-un-lft-identity71.7%
add-sqr-sqrt71.7%
times-frac71.7%
hypot-def71.7%
fma-def71.7%
hypot-def82.1%
Applied egg-rr82.1%
Taylor expanded in c around 0 50.0%
associate-/l*50.0%
Simplified50.0%
clear-num50.0%
associate-/r/50.0%
clear-num50.0%
Applied egg-rr50.0%
Taylor expanded in c around 0 81.2%
Final simplification74.4%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.45e-8) (not (<= c 3.6e+23))) (+ (/ a c) (* (/ d c) (/ b c))) (* (/ 1.0 d) (+ b (* a (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.45e-8) || !(c <= 3.6e+23)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = (1.0 / d) * (b + (a * (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 ((c <= (-1.45d-8)) .or. (.not. (c <= 3.6d+23))) then
tmp = (a / c) + ((d / c) * (b / c))
else
tmp = (1.0d0 / d) * (b + (a * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.45e-8) || !(c <= 3.6e+23)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = (1.0 / d) * (b + (a * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.45e-8) or not (c <= 3.6e+23): tmp = (a / c) + ((d / c) * (b / c)) else: tmp = (1.0 / d) * (b + (a * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.45e-8) || !(c <= 3.6e+23)) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); else tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.45e-8) || ~((c <= 3.6e+23))) tmp = (a / c) + ((d / c) * (b / c)); else tmp = (1.0 / d) * (b + (a * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.45e-8], N[Not[LessEqual[c, 3.6e+23]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.45 \cdot 10^{-8} \lor \neg \left(c \leq 3.6 \cdot 10^{+23}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\
\end{array}
\end{array}
if c < -1.4500000000000001e-8 or 3.5999999999999998e23 < c Initial program 51.7%
Taylor expanded in c around inf 77.8%
associate-/l*75.0%
Simplified75.0%
pow275.0%
*-un-lft-identity75.0%
times-frac77.2%
Applied egg-rr77.2%
/-rgt-identity77.2%
*-un-lft-identity77.2%
*-commutative77.2%
times-frac82.4%
clear-num82.8%
Applied egg-rr82.8%
if -1.4500000000000001e-8 < c < 3.5999999999999998e23Initial program 71.5%
*-un-lft-identity71.5%
add-sqr-sqrt71.5%
times-frac71.5%
hypot-def71.5%
fma-def71.5%
hypot-def82.0%
Applied egg-rr82.0%
Taylor expanded in c around 0 50.4%
associate-/l*50.3%
Simplified50.3%
clear-num50.4%
associate-/r/50.3%
clear-num50.3%
Applied egg-rr50.3%
Taylor expanded in c around 0 81.8%
Final simplification82.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -7.5e-32) (not (<= c 1.6e-58))) (+ (/ a c) (/ (/ b (/ c d)) c)) (* (/ 1.0 d) (+ b (/ a (/ d c))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -7.5e-32) || !(c <= 1.6e-58)) {
tmp = (a / c) + ((b / (c / d)) / c);
} else {
tmp = (1.0 / d) * (b + (a / (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 ((c <= (-7.5d-32)) .or. (.not. (c <= 1.6d-58))) then
tmp = (a / c) + ((b / (c / d)) / c)
else
tmp = (1.0d0 / d) * (b + (a / (d / c)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -7.5e-32) || !(c <= 1.6e-58)) {
tmp = (a / c) + ((b / (c / d)) / c);
} else {
tmp = (1.0 / d) * (b + (a / (d / c)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -7.5e-32) or not (c <= 1.6e-58): tmp = (a / c) + ((b / (c / d)) / c) else: tmp = (1.0 / d) * (b + (a / (d / c))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -7.5e-32) || !(c <= 1.6e-58)) tmp = Float64(Float64(a / c) + Float64(Float64(b / Float64(c / d)) / c)); else tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -7.5e-32) || ~((c <= 1.6e-58))) tmp = (a / c) + ((b / (c / d)) / c); else tmp = (1.0 / d) * (b + (a / (d / c))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -7.5e-32], N[Not[LessEqual[c, 1.6e-58]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.5 \cdot 10^{-32} \lor \neg \left(c \leq 1.6 \cdot 10^{-58}\right):\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b}{\frac{c}{d}}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\end{array}
\end{array}
if c < -7.49999999999999953e-32 or 1.6e-58 < c Initial program 53.2%
Taylor expanded in c around inf 74.1%
associate-/l*72.3%
Simplified72.3%
clear-num72.3%
associate-/r/72.3%
clear-num72.5%
Applied egg-rr72.5%
associate-*l/74.1%
unpow274.1%
times-frac77.7%
clear-num77.5%
times-frac74.2%
*-un-lft-identity74.2%
associate-/r*78.9%
Applied egg-rr78.9%
if -7.49999999999999953e-32 < c < 1.6e-58Initial program 72.7%
*-un-lft-identity72.7%
add-sqr-sqrt72.7%
times-frac72.7%
hypot-def72.7%
fma-def72.7%
hypot-def84.2%
Applied egg-rr84.2%
Taylor expanded in c around 0 53.1%
associate-/l*53.1%
Simplified53.1%
Taylor expanded in c around 0 87.2%
Final simplification82.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.95e-5) (not (<= c 1.56e-58))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.95e-5) || !(c <= 1.56e-58)) {
tmp = a / c;
} else {
tmp = b / 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 ((c <= (-1.95d-5)) .or. (.not. (c <= 1.56d-58))) then
tmp = a / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.95e-5) || !(c <= 1.56e-58)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.95e-5) or not (c <= 1.56e-58): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.95e-5) || !(c <= 1.56e-58)) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.95e-5) || ~((c <= 1.56e-58))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.95e-5], N[Not[LessEqual[c, 1.56e-58]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.95 \cdot 10^{-5} \lor \neg \left(c \leq 1.56 \cdot 10^{-58}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -1.95e-5 or 1.56000000000000008e-58 < c Initial program 52.0%
Taylor expanded in c around inf 65.6%
if -1.95e-5 < c < 1.56000000000000008e-58Initial program 72.8%
Taylor expanded in c around 0 66.5%
Final simplification66.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 61.8%
Taylor expanded in c around inf 43.6%
Final simplification43.6%
(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 2024029
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:herbie-target
(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))))