
(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 11 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))) 5e+299) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (+ (/ a c) (/ b (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 5e+299) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (a / c) + (b / (c * (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))) <= 5e+299) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(a / c) + Float64(b / Float64(c * 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], 5e+299], 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[(a / c), $MachinePrecision] + N[(b / N[(c * 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 5 \cdot 10^{+299}:\\
\;\;\;\;\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{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 5.0000000000000003e299Initial program 78.2%
*-un-lft-identity78.2%
associate-*r/78.2%
fma-def78.2%
add-sqr-sqrt78.2%
times-frac78.2%
fma-def78.2%
hypot-def78.2%
fma-def78.2%
fma-def78.2%
hypot-def93.4%
Applied egg-rr93.4%
if 5.0000000000000003e299 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 13.8%
Taylor expanded in c around inf 41.9%
associate-/l*49.2%
Simplified49.2%
div-inv49.2%
unpow249.2%
associate-*l*56.3%
add-sqr-sqrt28.8%
sqrt-prod44.9%
sqr-neg44.9%
sqrt-unprod23.1%
add-sqr-sqrt44.6%
div-inv44.6%
add-sqr-sqrt23.1%
sqrt-unprod44.9%
sqr-neg44.9%
sqrt-prod28.8%
add-sqr-sqrt56.3%
Applied egg-rr56.3%
Final simplification85.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (* a c) (* b d))) (t_1 (+ b (* a (/ c d)))))
(if (<= d -2.7e+36)
(/ t_1 (- (hypot c d)))
(if (<= d -1.8e-169)
(/ t_0 (pow (hypot c d) 2.0))
(if (<= d 1e-293)
(+ (/ a c) (/ b (* c (/ c d))))
(if (<= d 4.4e+66)
(/ t_0 (+ (* c c) (* d d)))
(/ t_1 (hypot c 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 <= -2.7e+36) {
tmp = t_1 / -hypot(c, d);
} else if (d <= -1.8e-169) {
tmp = t_0 / pow(hypot(c, d), 2.0);
} else if (d <= 1e-293) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (d <= 4.4e+66) {
tmp = t_0 / ((c * c) + (d * d));
} else {
tmp = t_1 / hypot(c, d);
}
return tmp;
}
public static 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 <= -2.7e+36) {
tmp = t_1 / -Math.hypot(c, d);
} else if (d <= -1.8e-169) {
tmp = t_0 / Math.pow(Math.hypot(c, d), 2.0);
} else if (d <= 1e-293) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (d <= 4.4e+66) {
tmp = t_0 / ((c * c) + (d * d));
} else {
tmp = t_1 / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): t_0 = (a * c) + (b * d) t_1 = b + (a * (c / d)) tmp = 0 if d <= -2.7e+36: tmp = t_1 / -math.hypot(c, d) elif d <= -1.8e-169: tmp = t_0 / math.pow(math.hypot(c, d), 2.0) elif d <= 1e-293: tmp = (a / c) + (b / (c * (c / d))) elif d <= 4.4e+66: tmp = t_0 / ((c * c) + (d * d)) else: tmp = t_1 / math.hypot(c, 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 <= -2.7e+36) tmp = Float64(t_1 / Float64(-hypot(c, d))); elseif (d <= -1.8e-169) tmp = Float64(t_0 / (hypot(c, d) ^ 2.0)); elseif (d <= 1e-293) tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))); elseif (d <= 4.4e+66) tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(t_1 / hypot(c, d)); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a * c) + (b * d); t_1 = b + (a * (c / d)); tmp = 0.0; if (d <= -2.7e+36) tmp = t_1 / -hypot(c, d); elseif (d <= -1.8e-169) tmp = t_0 / (hypot(c, d) ^ 2.0); elseif (d <= 1e-293) tmp = (a / c) + (b / (c * (c / d))); elseif (d <= 4.4e+66) tmp = t_0 / ((c * c) + (d * d)); else tmp = t_1 / hypot(c, 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]}, Block[{t$95$1 = N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.7e+36], N[(t$95$1 / (-N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision])), $MachinePrecision], If[LessEqual[d, -1.8e-169], N[(t$95$0 / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1e-293], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.4e+66], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $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 -2.7 \cdot 10^{+36}:\\
\;\;\;\;\frac{t\_1}{-\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq -1.8 \cdot 10^{-169}:\\
\;\;\;\;\frac{t\_0}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\
\mathbf{elif}\;d \leq 10^{-293}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{elif}\;d \leq 4.4 \cdot 10^{+66}:\\
\;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -2.7000000000000001e36Initial program 48.1%
*-un-lft-identity48.1%
associate-*r/48.1%
fma-def48.1%
add-sqr-sqrt48.1%
times-frac48.1%
fma-def48.1%
hypot-def48.1%
fma-def48.1%
fma-def48.1%
hypot-def69.1%
Applied egg-rr69.1%
Taylor expanded in d around -inf 81.6%
associate-*l/81.8%
*-un-lft-identity81.8%
frac-2neg81.8%
Applied egg-rr82.1%
if -2.7000000000000001e36 < d < -1.80000000000000001e-169Initial program 81.4%
expm1-log1p-u79.3%
expm1-udef45.7%
fma-def45.7%
add-sqr-sqrt45.7%
pow245.7%
fma-def45.7%
hypot-def45.7%
Applied egg-rr45.7%
expm1-def79.3%
expm1-log1p81.5%
Simplified81.5%
if -1.80000000000000001e-169 < d < 1.0000000000000001e-293Initial program 67.3%
Taylor expanded in c around inf 82.0%
associate-/l*82.2%
Simplified82.2%
div-inv82.2%
unpow282.2%
associate-*l*85.5%
add-sqr-sqrt6.1%
sqrt-prod68.5%
sqr-neg68.5%
sqrt-unprod61.9%
add-sqr-sqrt68.0%
div-inv68.0%
add-sqr-sqrt61.9%
sqrt-unprod68.5%
sqr-neg68.5%
sqrt-prod6.1%
add-sqr-sqrt85.5%
Applied egg-rr85.5%
if 1.0000000000000001e-293 < d < 4.3999999999999997e66Initial program 80.3%
if 4.3999999999999997e66 < d Initial program 35.1%
*-un-lft-identity35.1%
associate-*r/35.1%
fma-def35.1%
add-sqr-sqrt35.2%
times-frac35.3%
fma-def35.3%
hypot-def35.3%
fma-def35.3%
fma-def35.3%
hypot-def63.6%
Applied egg-rr63.6%
Taylor expanded in d around -inf 15.1%
expm1-log1p-u15.0%
expm1-udef15.9%
Applied egg-rr23.6%
expm1-def65.6%
expm1-log1p81.2%
Simplified81.2%
Final simplification81.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (+ (/ b d) (* c (/ a (pow d 2.0))))))
(if (<= d -3.6e+46)
t_1
(if (<= d -5.5e-170)
t_0
(if (<= d 1e-293)
(+ (/ a c) (/ b (* c (/ c d))))
(if (<= d 1.25e+62) 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 / d) + (c * (a / pow(d, 2.0)));
double tmp;
if (d <= -3.6e+46) {
tmp = t_1;
} else if (d <= -5.5e-170) {
tmp = t_0;
} else if (d <= 1e-293) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (d <= 1.25e+62) {
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 / d) + (c * (a / (d ** 2.0d0)))
if (d <= (-3.6d+46)) then
tmp = t_1
else if (d <= (-5.5d-170)) then
tmp = t_0
else if (d <= 1d-293) then
tmp = (a / c) + (b / (c * (c / d)))
else if (d <= 1.25d+62) 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 / d) + (c * (a / Math.pow(d, 2.0)));
double tmp;
if (d <= -3.6e+46) {
tmp = t_1;
} else if (d <= -5.5e-170) {
tmp = t_0;
} else if (d <= 1e-293) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (d <= 1.25e+62) {
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 / d) + (c * (a / math.pow(d, 2.0))) tmp = 0 if d <= -3.6e+46: tmp = t_1 elif d <= -5.5e-170: tmp = t_0 elif d <= 1e-293: tmp = (a / c) + (b / (c * (c / d))) elif d <= 1.25e+62: 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 / d) + Float64(c * Float64(a / (d ^ 2.0)))) tmp = 0.0 if (d <= -3.6e+46) tmp = t_1; elseif (d <= -5.5e-170) tmp = t_0; elseif (d <= 1e-293) tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))); elseif (d <= 1.25e+62) 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 / d) + (c * (a / (d ^ 2.0))); tmp = 0.0; if (d <= -3.6e+46) tmp = t_1; elseif (d <= -5.5e-170) tmp = t_0; elseif (d <= 1e-293) tmp = (a / c) + (b / (c * (c / d))); elseif (d <= 1.25e+62) 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 / d), $MachinePrecision] + N[(c * N[(a / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3.6e+46], t$95$1, If[LessEqual[d, -5.5e-170], t$95$0, If[LessEqual[d, 1e-293], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.25e+62], 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}{d} + c \cdot \frac{a}{{d}^{2}}\\
\mathbf{if}\;d \leq -3.6 \cdot 10^{+46}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -5.5 \cdot 10^{-170}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 10^{-293}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{elif}\;d \leq 1.25 \cdot 10^{+62}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -3.5999999999999999e46 or 1.25000000000000007e62 < d Initial program 41.9%
Taylor expanded in c around 0 74.4%
associate-/l*75.7%
associate-/r/76.5%
Simplified76.5%
if -3.5999999999999999e46 < d < -5.50000000000000018e-170 or 1.0000000000000001e-293 < d < 1.25000000000000007e62Initial program 81.1%
if -5.50000000000000018e-170 < d < 1.0000000000000001e-293Initial program 67.3%
Taylor expanded in c around inf 82.0%
associate-/l*82.2%
Simplified82.2%
div-inv82.2%
unpow282.2%
associate-*l*85.5%
add-sqr-sqrt6.1%
sqrt-prod68.5%
sqr-neg68.5%
sqrt-unprod61.9%
add-sqr-sqrt68.0%
div-inv68.0%
add-sqr-sqrt61.9%
sqrt-unprod68.5%
sqr-neg68.5%
sqrt-prod6.1%
add-sqr-sqrt85.5%
Applied egg-rr85.5%
Final simplification79.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -4.3e+46)
(+ (/ b d) (* c (/ a (pow d 2.0))))
(if (<= d -5.4e-170)
t_0
(if (<= d 1e-293)
(+ (/ a c) (/ b (* c (/ c d))))
(if (<= d 1.25e+66) t_0 (/ (+ b (* a (/ c d))) (hypot 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 <= -4.3e+46) {
tmp = (b / d) + (c * (a / pow(d, 2.0)));
} else if (d <= -5.4e-170) {
tmp = t_0;
} else if (d <= 1e-293) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (d <= 1.25e+66) {
tmp = t_0;
} else {
tmp = (b + (a * (c / d))) / hypot(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 <= -4.3e+46) {
tmp = (b / d) + (c * (a / Math.pow(d, 2.0)));
} else if (d <= -5.4e-170) {
tmp = t_0;
} else if (d <= 1e-293) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (d <= 1.25e+66) {
tmp = t_0;
} else {
tmp = (b + (a * (c / d))) / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -4.3e+46: tmp = (b / d) + (c * (a / math.pow(d, 2.0))) elif d <= -5.4e-170: tmp = t_0 elif d <= 1e-293: tmp = (a / c) + (b / (c * (c / d))) elif d <= 1.25e+66: tmp = t_0 else: tmp = (b + (a * (c / d))) / math.hypot(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 <= -4.3e+46) tmp = Float64(Float64(b / d) + Float64(c * Float64(a / (d ^ 2.0)))); elseif (d <= -5.4e-170) tmp = t_0; elseif (d <= 1e-293) tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))); elseif (d <= 1.25e+66) tmp = t_0; else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / hypot(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 <= -4.3e+46) tmp = (b / d) + (c * (a / (d ^ 2.0))); elseif (d <= -5.4e-170) tmp = t_0; elseif (d <= 1e-293) tmp = (a / c) + (b / (c * (c / d))); elseif (d <= 1.25e+66) tmp = t_0; else tmp = (b + (a * (c / d))) / hypot(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, -4.3e+46], N[(N[(b / d), $MachinePrecision] + N[(c * N[(a / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5.4e-170], t$95$0, If[LessEqual[d, 1e-293], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.25e+66], t$95$0, N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $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 -4.3 \cdot 10^{+46}:\\
\;\;\;\;\frac{b}{d} + c \cdot \frac{a}{{d}^{2}}\\
\mathbf{elif}\;d \leq -5.4 \cdot 10^{-170}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 10^{-293}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{elif}\;d \leq 1.25 \cdot 10^{+66}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -4.30000000000000005e46Initial program 46.4%
Taylor expanded in c around 0 75.0%
associate-/l*75.3%
associate-/r/76.8%
Simplified76.8%
if -4.30000000000000005e46 < d < -5.3999999999999997e-170 or 1.0000000000000001e-293 < d < 1.24999999999999998e66Initial program 81.1%
if -5.3999999999999997e-170 < d < 1.0000000000000001e-293Initial program 67.3%
Taylor expanded in c around inf 82.0%
associate-/l*82.2%
Simplified82.2%
div-inv82.2%
unpow282.2%
associate-*l*85.5%
add-sqr-sqrt6.1%
sqrt-prod68.5%
sqr-neg68.5%
sqrt-unprod61.9%
add-sqr-sqrt68.0%
div-inv68.0%
add-sqr-sqrt61.9%
sqrt-unprod68.5%
sqr-neg68.5%
sqrt-prod6.1%
add-sqr-sqrt85.5%
Applied egg-rr85.5%
if 1.24999999999999998e66 < d Initial program 35.1%
*-un-lft-identity35.1%
associate-*r/35.1%
fma-def35.1%
add-sqr-sqrt35.2%
times-frac35.3%
fma-def35.3%
hypot-def35.3%
fma-def35.3%
fma-def35.3%
hypot-def63.6%
Applied egg-rr63.6%
Taylor expanded in d around -inf 15.1%
expm1-log1p-u15.0%
expm1-udef15.9%
Applied egg-rr23.6%
expm1-def65.6%
expm1-log1p81.2%
Simplified81.2%
Final simplification80.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (+ b (* a (/ c d)))))
(if (<= d -2.7e+36)
(/ t_1 (- (hypot c d)))
(if (<= d -1.3e-170)
t_0
(if (<= d 1e-293)
(+ (/ a c) (/ b (* c (/ c d))))
(if (<= d 2.4e+60) t_0 (/ t_1 (hypot c d))))))))
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));
double tmp;
if (d <= -2.7e+36) {
tmp = t_1 / -hypot(c, d);
} else if (d <= -1.3e-170) {
tmp = t_0;
} else if (d <= 1e-293) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (d <= 2.4e+60) {
tmp = t_0;
} else {
tmp = t_1 / hypot(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 t_1 = b + (a * (c / d));
double tmp;
if (d <= -2.7e+36) {
tmp = t_1 / -Math.hypot(c, d);
} else if (d <= -1.3e-170) {
tmp = t_0;
} else if (d <= 1e-293) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (d <= 2.4e+60) {
tmp = t_0;
} else {
tmp = t_1 / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = b + (a * (c / d)) tmp = 0 if d <= -2.7e+36: tmp = t_1 / -math.hypot(c, d) elif d <= -1.3e-170: tmp = t_0 elif d <= 1e-293: tmp = (a / c) + (b / (c * (c / d))) elif d <= 2.4e+60: tmp = t_0 else: tmp = t_1 / math.hypot(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))) t_1 = Float64(b + Float64(a * Float64(c / d))) tmp = 0.0 if (d <= -2.7e+36) tmp = Float64(t_1 / Float64(-hypot(c, d))); elseif (d <= -1.3e-170) tmp = t_0; elseif (d <= 1e-293) tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))); elseif (d <= 2.4e+60) tmp = t_0; else tmp = Float64(t_1 / hypot(c, d)); 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)); tmp = 0.0; if (d <= -2.7e+36) tmp = t_1 / -hypot(c, d); elseif (d <= -1.3e-170) tmp = t_0; elseif (d <= 1e-293) tmp = (a / c) + (b / (c * (c / d))); elseif (d <= 2.4e+60) tmp = t_0; else tmp = t_1 / hypot(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]}, Block[{t$95$1 = N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.7e+36], N[(t$95$1 / (-N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision])), $MachinePrecision], If[LessEqual[d, -1.3e-170], t$95$0, If[LessEqual[d, 1e-293], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.4e+60], t$95$0, N[(t$95$1 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := b + a \cdot \frac{c}{d}\\
\mathbf{if}\;d \leq -2.7 \cdot 10^{+36}:\\
\;\;\;\;\frac{t\_1}{-\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq -1.3 \cdot 10^{-170}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 10^{-293}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{elif}\;d \leq 2.4 \cdot 10^{+60}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -2.7000000000000001e36Initial program 48.1%
*-un-lft-identity48.1%
associate-*r/48.1%
fma-def48.1%
add-sqr-sqrt48.1%
times-frac48.1%
fma-def48.1%
hypot-def48.1%
fma-def48.1%
fma-def48.1%
hypot-def69.1%
Applied egg-rr69.1%
Taylor expanded in d around -inf 81.6%
associate-*l/81.8%
*-un-lft-identity81.8%
frac-2neg81.8%
Applied egg-rr82.1%
if -2.7000000000000001e36 < d < -1.3000000000000001e-170 or 1.0000000000000001e-293 < d < 2.4e60Initial program 80.8%
if -1.3000000000000001e-170 < d < 1.0000000000000001e-293Initial program 67.3%
Taylor expanded in c around inf 82.0%
associate-/l*82.2%
Simplified82.2%
div-inv82.2%
unpow282.2%
associate-*l*85.5%
add-sqr-sqrt6.1%
sqrt-prod68.5%
sqr-neg68.5%
sqrt-unprod61.9%
add-sqr-sqrt68.0%
div-inv68.0%
add-sqr-sqrt61.9%
sqrt-unprod68.5%
sqr-neg68.5%
sqrt-prod6.1%
add-sqr-sqrt85.5%
Applied egg-rr85.5%
if 2.4e60 < d Initial program 35.1%
*-un-lft-identity35.1%
associate-*r/35.1%
fma-def35.1%
add-sqr-sqrt35.2%
times-frac35.3%
fma-def35.3%
hypot-def35.3%
fma-def35.3%
fma-def35.3%
hypot-def63.6%
Applied egg-rr63.6%
Taylor expanded in d around -inf 15.1%
expm1-log1p-u15.0%
expm1-udef15.9%
Applied egg-rr23.6%
expm1-def65.6%
expm1-log1p81.2%
Simplified81.2%
Final simplification81.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -1e+129)
(* b (/ -1.0 (hypot c d)))
(if (<= d -1.3e-170)
t_0
(if (<= d 1e-293)
(+ (/ a c) (/ b (* c (/ c d))))
(if (<= d 2.2e+81) t_0 (* b (/ 1.0 (hypot 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 <= -1e+129) {
tmp = b * (-1.0 / hypot(c, d));
} else if (d <= -1.3e-170) {
tmp = t_0;
} else if (d <= 1e-293) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (d <= 2.2e+81) {
tmp = t_0;
} else {
tmp = b * (1.0 / hypot(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 <= -1e+129) {
tmp = b * (-1.0 / Math.hypot(c, d));
} else if (d <= -1.3e-170) {
tmp = t_0;
} else if (d <= 1e-293) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (d <= 2.2e+81) {
tmp = t_0;
} else {
tmp = b * (1.0 / Math.hypot(c, d));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -1e+129: tmp = b * (-1.0 / math.hypot(c, d)) elif d <= -1.3e-170: tmp = t_0 elif d <= 1e-293: tmp = (a / c) + (b / (c * (c / d))) elif d <= 2.2e+81: tmp = t_0 else: tmp = b * (1.0 / math.hypot(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 <= -1e+129) tmp = Float64(b * Float64(-1.0 / hypot(c, d))); elseif (d <= -1.3e-170) tmp = t_0; elseif (d <= 1e-293) tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))); elseif (d <= 2.2e+81) tmp = t_0; else tmp = Float64(b * Float64(1.0 / hypot(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 <= -1e+129) tmp = b * (-1.0 / hypot(c, d)); elseif (d <= -1.3e-170) tmp = t_0; elseif (d <= 1e-293) tmp = (a / c) + (b / (c * (c / d))); elseif (d <= 2.2e+81) tmp = t_0; else tmp = b * (1.0 / hypot(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, -1e+129], N[(b * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.3e-170], t$95$0, If[LessEqual[d, 1e-293], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.2e+81], t$95$0, N[(b * N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $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 \cdot 10^{+129}:\\
\;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq -1.3 \cdot 10^{-170}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 10^{-293}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{elif}\;d \leq 2.2 \cdot 10^{+81}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;b \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -1e129Initial program 31.0%
*-un-lft-identity31.0%
associate-*r/31.0%
fma-def31.0%
add-sqr-sqrt31.0%
times-frac31.0%
fma-def31.0%
hypot-def31.0%
fma-def31.0%
fma-def31.0%
hypot-def62.5%
Applied egg-rr62.5%
Taylor expanded in d around -inf 75.7%
mul-1-neg75.7%
Simplified75.7%
if -1e129 < d < -1.3000000000000001e-170 or 1.0000000000000001e-293 < d < 2.19999999999999987e81Initial program 79.6%
if -1.3000000000000001e-170 < d < 1.0000000000000001e-293Initial program 67.3%
Taylor expanded in c around inf 82.0%
associate-/l*82.2%
Simplified82.2%
div-inv82.2%
unpow282.2%
associate-*l*85.5%
add-sqr-sqrt6.1%
sqrt-prod68.5%
sqr-neg68.5%
sqrt-unprod61.9%
add-sqr-sqrt68.0%
div-inv68.0%
add-sqr-sqrt61.9%
sqrt-unprod68.5%
sqr-neg68.5%
sqrt-prod6.1%
add-sqr-sqrt85.5%
Applied egg-rr85.5%
if 2.19999999999999987e81 < d Initial program 34.2%
*-un-lft-identity34.2%
associate-*r/34.2%
fma-def34.2%
add-sqr-sqrt34.3%
times-frac34.3%
fma-def34.3%
hypot-def34.3%
fma-def34.3%
fma-def34.3%
hypot-def64.2%
Applied egg-rr64.2%
Taylor expanded in c around 0 72.7%
Final simplification78.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (+ (/ a c) (/ b (* c (/ c d))))))
(if (<= c -2.7e+76)
t_1
(if (<= c -2.1e-107)
t_0
(if (<= c 1.2e-146) (/ b d) (if (<= c 9e+36) 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 = (a / c) + (b / (c * (c / d)));
double tmp;
if (c <= -2.7e+76) {
tmp = t_1;
} else if (c <= -2.1e-107) {
tmp = t_0;
} else if (c <= 1.2e-146) {
tmp = b / d;
} else if (c <= 9e+36) {
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 = (a / c) + (b / (c * (c / d)))
if (c <= (-2.7d+76)) then
tmp = t_1
else if (c <= (-2.1d-107)) then
tmp = t_0
else if (c <= 1.2d-146) then
tmp = b / d
else if (c <= 9d+36) 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 = (a / c) + (b / (c * (c / d)));
double tmp;
if (c <= -2.7e+76) {
tmp = t_1;
} else if (c <= -2.1e-107) {
tmp = t_0;
} else if (c <= 1.2e-146) {
tmp = b / d;
} else if (c <= 9e+36) {
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 = (a / c) + (b / (c * (c / d))) tmp = 0 if c <= -2.7e+76: tmp = t_1 elif c <= -2.1e-107: tmp = t_0 elif c <= 1.2e-146: tmp = b / d elif c <= 9e+36: 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(a / c) + Float64(b / Float64(c * Float64(c / d)))) tmp = 0.0 if (c <= -2.7e+76) tmp = t_1; elseif (c <= -2.1e-107) tmp = t_0; elseif (c <= 1.2e-146) tmp = Float64(b / d); elseif (c <= 9e+36) 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 = (a / c) + (b / (c * (c / d))); tmp = 0.0; if (c <= -2.7e+76) tmp = t_1; elseif (c <= -2.1e-107) tmp = t_0; elseif (c <= 1.2e-146) tmp = b / d; elseif (c <= 9e+36) 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[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.7e+76], t$95$1, If[LessEqual[c, -2.1e-107], t$95$0, If[LessEqual[c, 1.2e-146], N[(b / d), $MachinePrecision], If[LessEqual[c, 9e+36], 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{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{if}\;c \leq -2.7 \cdot 10^{+76}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -2.1 \cdot 10^{-107}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.2 \cdot 10^{-146}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 9 \cdot 10^{+36}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -2.6999999999999999e76 or 8.99999999999999994e36 < c Initial program 48.3%
Taylor expanded in c around inf 75.9%
associate-/l*79.4%
Simplified79.4%
div-inv79.4%
unpow279.4%
associate-*l*81.5%
add-sqr-sqrt34.3%
sqrt-prod67.6%
sqr-neg67.6%
sqrt-unprod41.6%
add-sqr-sqrt69.3%
div-inv69.3%
add-sqr-sqrt41.6%
sqrt-unprod67.6%
sqr-neg67.6%
sqrt-prod34.3%
add-sqr-sqrt81.5%
Applied egg-rr81.5%
if -2.6999999999999999e76 < c < -2.0999999999999999e-107 or 1.2000000000000001e-146 < c < 8.99999999999999994e36Initial program 76.7%
if -2.0999999999999999e-107 < c < 1.2000000000000001e-146Initial program 66.7%
Taylor expanded in c around 0 77.4%
Final simplification78.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ a c) (/ b (* c (/ c d))))))
(if (<= c -80000000.0)
t_0
(if (<= c -6e-33)
(/ b d)
(if (<= c -1.86e-93)
(/ (* a c) (+ (* c c) (* d d)))
(if (<= c 2.1e-73) (/ b d) t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = (a / c) + (b / (c * (c / d)));
double tmp;
if (c <= -80000000.0) {
tmp = t_0;
} else if (c <= -6e-33) {
tmp = b / d;
} else if (c <= -1.86e-93) {
tmp = (a * c) / ((c * c) + (d * d));
} else if (c <= 2.1e-73) {
tmp = b / d;
} else {
tmp = t_0;
}
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 / (c * (c / d)))
if (c <= (-80000000.0d0)) then
tmp = t_0
else if (c <= (-6d-33)) then
tmp = b / d
else if (c <= (-1.86d-93)) then
tmp = (a * c) / ((c * c) + (d * d))
else if (c <= 2.1d-73) then
tmp = b / d
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (a / c) + (b / (c * (c / d)));
double tmp;
if (c <= -80000000.0) {
tmp = t_0;
} else if (c <= -6e-33) {
tmp = b / d;
} else if (c <= -1.86e-93) {
tmp = (a * c) / ((c * c) + (d * d));
} else if (c <= 2.1e-73) {
tmp = b / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a / c) + (b / (c * (c / d))) tmp = 0 if c <= -80000000.0: tmp = t_0 elif c <= -6e-33: tmp = b / d elif c <= -1.86e-93: tmp = (a * c) / ((c * c) + (d * d)) elif c <= 2.1e-73: tmp = b / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))) tmp = 0.0 if (c <= -80000000.0) tmp = t_0; elseif (c <= -6e-33) tmp = Float64(b / d); elseif (c <= -1.86e-93) tmp = Float64(Float64(a * c) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 2.1e-73) tmp = Float64(b / d); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a / c) + (b / (c * (c / d))); tmp = 0.0; if (c <= -80000000.0) tmp = t_0; elseif (c <= -6e-33) tmp = b / d; elseif (c <= -1.86e-93) tmp = (a * c) / ((c * c) + (d * d)); elseif (c <= 2.1e-73) tmp = b / d; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -80000000.0], t$95$0, If[LessEqual[c, -6e-33], N[(b / d), $MachinePrecision], If[LessEqual[c, -1.86e-93], N[(N[(a * c), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.1e-73], N[(b / d), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{if}\;c \leq -80000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -6 \cdot 10^{-33}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq -1.86 \cdot 10^{-93}:\\
\;\;\;\;\frac{a \cdot c}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 2.1 \cdot 10^{-73}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -8e7 or 2.0999999999999999e-73 < c Initial program 57.6%
Taylor expanded in c around inf 70.5%
associate-/l*70.6%
Simplified70.6%
div-inv70.6%
unpow270.6%
associate-*l*72.1%
add-sqr-sqrt31.2%
sqrt-prod58.8%
sqr-neg58.8%
sqrt-unprod33.3%
add-sqr-sqrt59.3%
div-inv59.3%
add-sqr-sqrt33.3%
sqrt-unprod58.8%
sqr-neg58.8%
sqrt-prod31.2%
add-sqr-sqrt72.1%
Applied egg-rr72.1%
if -8e7 < c < -6.0000000000000003e-33 or -1.8600000000000001e-93 < c < 2.0999999999999999e-73Initial program 67.8%
Taylor expanded in c around 0 74.1%
if -6.0000000000000003e-33 < c < -1.8600000000000001e-93Initial program 87.6%
Taylor expanded in a around inf 67.2%
*-commutative67.2%
Simplified67.2%
Final simplification72.6%
(FPCore (a b c d) :precision binary64 (if (or (<= c -410000.0) (not (<= c 7.2e-72))) (+ (/ a c) (/ b (* c (/ c d)))) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -410000.0) || !(c <= 7.2e-72)) {
tmp = (a / c) + (b / (c * (c / d)));
} 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 <= (-410000.0d0)) .or. (.not. (c <= 7.2d-72))) then
tmp = (a / c) + (b / (c * (c / d)))
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 <= -410000.0) || !(c <= 7.2e-72)) {
tmp = (a / c) + (b / (c * (c / d)));
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -410000.0) or not (c <= 7.2e-72): tmp = (a / c) + (b / (c * (c / d))) else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -410000.0) || !(c <= 7.2e-72)) tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -410000.0) || ~((c <= 7.2e-72))) tmp = (a / c) + (b / (c * (c / d))); else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -410000.0], N[Not[LessEqual[c, 7.2e-72]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -410000 \lor \neg \left(c \leq 7.2 \cdot 10^{-72}\right):\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -4.1e5 or 7.2e-72 < c Initial program 57.6%
Taylor expanded in c around inf 70.5%
associate-/l*70.6%
Simplified70.6%
div-inv70.6%
unpow270.6%
associate-*l*72.1%
add-sqr-sqrt31.2%
sqrt-prod58.8%
sqr-neg58.8%
sqrt-unprod33.3%
add-sqr-sqrt59.3%
div-inv59.3%
add-sqr-sqrt33.3%
sqrt-unprod58.8%
sqr-neg58.8%
sqrt-prod31.2%
add-sqr-sqrt72.1%
Applied egg-rr72.1%
if -4.1e5 < c < 7.2e-72Initial program 70.3%
Taylor expanded in c around 0 68.9%
Final simplification70.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -8e+48) (not (<= c 2.1e-66))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -8e+48) || !(c <= 2.1e-66)) {
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 <= (-8d+48)) .or. (.not. (c <= 2.1d-66))) 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 <= -8e+48) || !(c <= 2.1e-66)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -8e+48) or not (c <= 2.1e-66): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -8e+48) || !(c <= 2.1e-66)) 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 <= -8e+48) || ~((c <= 2.1e-66))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -8e+48], N[Not[LessEqual[c, 2.1e-66]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8 \cdot 10^{+48} \lor \neg \left(c \leq 2.1 \cdot 10^{-66}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -8.00000000000000035e48 or 2.1e-66 < c Initial program 58.1%
Taylor expanded in c around inf 62.2%
if -8.00000000000000035e48 < c < 2.1e-66Initial program 68.9%
Taylor expanded in c around 0 66.9%
Final simplification64.7%
(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.8%
Taylor expanded in c around inf 40.5%
Final simplification40.5%
(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 2024040
(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))))