
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (* a c) (* b d))) (t_1 (/ b (/ c d))))
(if (<= c -3.6e+133)
(/ (- (- a) t_1) (hypot c d))
(if (<= c -1.1e-112)
(/ t_0 (+ (* c c) (* d d)))
(if (<= c 2.95e-139)
(/ (+ b (* a (/ c d))) d)
(if (<= c 3.1e+93)
(/ t_0 (fma c c (* d d)))
(/ (+ a 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 / (c / d);
double tmp;
if (c <= -3.6e+133) {
tmp = (-a - t_1) / hypot(c, d);
} else if (c <= -1.1e-112) {
tmp = t_0 / ((c * c) + (d * d));
} else if (c <= 2.95e-139) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 3.1e+93) {
tmp = t_0 / fma(c, c, (d * d));
} else {
tmp = (a + t_1) / 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(c / d)) tmp = 0.0 if (c <= -3.6e+133) tmp = Float64(Float64(Float64(-a) - t_1) / hypot(c, d)); elseif (c <= -1.1e-112) tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 2.95e-139) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 3.1e+93) tmp = Float64(t_0 / fma(c, c, Float64(d * d))); else tmp = Float64(Float64(a + t_1) / hypot(c, 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[(c / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.6e+133], N[(N[((-a) - t$95$1), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.1e-112], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.95e-139], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 3.1e+93], N[(t$95$0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + t$95$1), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot c + b \cdot d\\
t_1 := \frac{b}{\frac{c}{d}}\\
\mathbf{if}\;c \leq -3.6 \cdot 10^{+133}:\\
\;\;\;\;\frac{\left(-a\right) - t_1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -1.1 \cdot 10^{-112}:\\
\;\;\;\;\frac{t_0}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 2.95 \cdot 10^{-139}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 3.1 \cdot 10^{+93}:\\
\;\;\;\;\frac{t_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + t_1}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if c < -3.59999999999999978e133Initial program 33.9%
add-sqr-sqrt33.9%
*-un-lft-identity33.9%
times-frac33.9%
hypot-def33.9%
fma-def33.9%
hypot-def53.6%
Applied egg-rr53.6%
associate-*l/53.6%
*-un-lft-identity53.6%
Applied egg-rr53.6%
Taylor expanded in c around -inf 81.7%
distribute-lft-out81.7%
associate-/l*84.4%
Simplified84.4%
if -3.59999999999999978e133 < c < -1.10000000000000011e-112Initial program 91.2%
if -1.10000000000000011e-112 < c < 2.9499999999999999e-139Initial program 63.9%
add-sqr-sqrt63.9%
*-un-lft-identity63.9%
times-frac63.8%
hypot-def63.8%
fma-def63.8%
hypot-def81.9%
Applied egg-rr81.9%
Taylor expanded in c around 0 57.9%
Taylor expanded in c around 0 91.0%
expm1-log1p-u75.6%
expm1-udef38.2%
associate-*l/38.2%
*-un-lft-identity38.2%
associate-/l*38.2%
div-inv38.2%
clear-num38.2%
Applied egg-rr38.2%
expm1-def77.3%
expm1-log1p92.8%
Simplified92.8%
if 2.9499999999999999e-139 < c < 3.10000000000000019e93Initial program 78.3%
fma-def78.3%
fma-def78.4%
Simplified78.4%
fma-def78.4%
+-commutative78.4%
Applied egg-rr78.4%
if 3.10000000000000019e93 < c Initial program 32.0%
add-sqr-sqrt32.0%
*-un-lft-identity32.0%
times-frac31.9%
hypot-def31.9%
fma-def31.9%
hypot-def60.6%
Applied egg-rr60.6%
associate-*l/60.6%
*-un-lft-identity60.6%
Applied egg-rr60.6%
Taylor expanded in c around inf 76.3%
associate-/l*83.8%
Simplified83.8%
Final simplification86.3%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY) (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d)) (* (/ c (hypot c d)) (/ a (hypot c 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 = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = (c / hypot(c, d)) * (a / hypot(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))) <= Inf) tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(c / hypot(c, d)) * Float64(a / hypot(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], Infinity], N[(N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $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 \infty:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 74.9%
add-sqr-sqrt74.9%
*-un-lft-identity74.9%
times-frac74.9%
hypot-def74.9%
fma-def74.9%
hypot-def92.7%
Applied egg-rr92.7%
associate-*l/92.9%
*-un-lft-identity92.9%
Applied egg-rr92.9%
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 a around inf 1.6%
*-commutative1.6%
Simplified1.6%
pow21.6%
add-sqr-sqrt1.6%
pow21.6%
hypot-udef1.6%
pow21.6%
hypot-udef1.6%
times-frac55.0%
Applied egg-rr55.0%
Final simplification85.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -1.35e+141)
(/ (- a) (hypot c d))
(if (<= c -1.05e-112)
t_0
(if (<= c 1.15e-138)
(/ (+ b (* a (/ c d))) d)
(if (<= c 1.8e+92) t_0 (+ (/ a c) (* d (/ b (pow c 2.0))))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -1.35e+141) {
tmp = -a / hypot(c, d);
} else if (c <= -1.05e-112) {
tmp = t_0;
} else if (c <= 1.15e-138) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.8e+92) {
tmp = t_0;
} else {
tmp = (a / c) + (d * (b / pow(c, 2.0)));
}
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 (c <= -1.35e+141) {
tmp = -a / Math.hypot(c, d);
} else if (c <= -1.05e-112) {
tmp = t_0;
} else if (c <= 1.15e-138) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.8e+92) {
tmp = t_0;
} else {
tmp = (a / c) + (d * (b / Math.pow(c, 2.0)));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -1.35e+141: tmp = -a / math.hypot(c, d) elif c <= -1.05e-112: tmp = t_0 elif c <= 1.15e-138: tmp = (b + (a * (c / d))) / d elif c <= 1.8e+92: tmp = t_0 else: tmp = (a / c) + (d * (b / math.pow(c, 2.0))) 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 (c <= -1.35e+141) tmp = Float64(Float64(-a) / hypot(c, d)); elseif (c <= -1.05e-112) tmp = t_0; elseif (c <= 1.15e-138) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 1.8e+92) tmp = t_0; else tmp = Float64(Float64(a / c) + Float64(d * Float64(b / (c ^ 2.0)))); 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 (c <= -1.35e+141) tmp = -a / hypot(c, d); elseif (c <= -1.05e-112) tmp = t_0; elseif (c <= 1.15e-138) tmp = (b + (a * (c / d))) / d; elseif (c <= 1.8e+92) tmp = t_0; else tmp = (a / c) + (d * (b / (c ^ 2.0))); 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[c, -1.35e+141], N[((-a) / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.05e-112], t$95$0, If[LessEqual[c, 1.15e-138], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.8e+92], t$95$0, N[(N[(a / c), $MachinePrecision] + N[(d * N[(b / N[Power[c, 2.0], $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}\;c \leq -1.35 \cdot 10^{+141}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -1.05 \cdot 10^{-112}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.15 \cdot 10^{-138}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.8 \cdot 10^{+92}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\
\end{array}
\end{array}
if c < -1.35e141Initial program 33.9%
add-sqr-sqrt33.9%
*-un-lft-identity33.9%
times-frac33.9%
hypot-def33.9%
fma-def33.9%
hypot-def53.6%
Applied egg-rr53.6%
associate-*l/53.6%
*-un-lft-identity53.6%
Applied egg-rr53.6%
Taylor expanded in c around -inf 78.6%
neg-mul-178.6%
Simplified78.6%
if -1.35e141 < c < -1.05e-112 or 1.14999999999999995e-138 < c < 1.8e92Initial program 84.2%
if -1.05e-112 < c < 1.14999999999999995e-138Initial program 63.9%
add-sqr-sqrt63.9%
*-un-lft-identity63.9%
times-frac63.8%
hypot-def63.8%
fma-def63.8%
hypot-def81.9%
Applied egg-rr81.9%
Taylor expanded in c around 0 57.9%
Taylor expanded in c around 0 91.0%
expm1-log1p-u75.6%
expm1-udef38.2%
associate-*l/38.2%
*-un-lft-identity38.2%
associate-/l*38.2%
div-inv38.2%
clear-num38.2%
Applied egg-rr38.2%
expm1-def77.3%
expm1-log1p92.8%
Simplified92.8%
if 1.8e92 < c Initial program 32.0%
Taylor expanded in c around inf 71.2%
associate-/l*71.8%
associate-/r/73.7%
Simplified73.7%
Final simplification83.4%
(FPCore (a b c d)
:precision binary64
(if (<= d -6.4e+125)
(* (/ 1.0 d) (+ b (* c (/ a d))))
(if (<= d -8.6e+75)
(+ (/ a c) (* d (/ b (pow c 2.0))))
(if (<= d -1.1e-131)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 6.5e+65)
(+ (/ a c) (/ b (/ (pow c 2.0) d)))
(/ (+ b (* a (/ c d))) d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -6.4e+125) {
tmp = (1.0 / d) * (b + (c * (a / d)));
} else if (d <= -8.6e+75) {
tmp = (a / c) + (d * (b / pow(c, 2.0)));
} else if (d <= -1.1e-131) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 6.5e+65) {
tmp = (a / c) + (b / (pow(c, 2.0) / d));
} 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 <= (-6.4d+125)) then
tmp = (1.0d0 / d) * (b + (c * (a / d)))
else if (d <= (-8.6d+75)) then
tmp = (a / c) + (d * (b / (c ** 2.0d0)))
else if (d <= (-1.1d-131)) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else if (d <= 6.5d+65) then
tmp = (a / c) + (b / ((c ** 2.0d0) / d))
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 <= -6.4e+125) {
tmp = (1.0 / d) * (b + (c * (a / d)));
} else if (d <= -8.6e+75) {
tmp = (a / c) + (d * (b / Math.pow(c, 2.0)));
} else if (d <= -1.1e-131) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 6.5e+65) {
tmp = (a / c) + (b / (Math.pow(c, 2.0) / d));
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -6.4e+125: tmp = (1.0 / d) * (b + (c * (a / d))) elif d <= -8.6e+75: tmp = (a / c) + (d * (b / math.pow(c, 2.0))) elif d <= -1.1e-131: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif d <= 6.5e+65: tmp = (a / c) + (b / (math.pow(c, 2.0) / d)) else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -6.4e+125) tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(c * Float64(a / d)))); elseif (d <= -8.6e+75) tmp = Float64(Float64(a / c) + Float64(d * Float64(b / (c ^ 2.0)))); elseif (d <= -1.1e-131) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 6.5e+65) tmp = Float64(Float64(a / c) + Float64(b / Float64((c ^ 2.0) / d))); 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 <= -6.4e+125) tmp = (1.0 / d) * (b + (c * (a / d))); elseif (d <= -8.6e+75) tmp = (a / c) + (d * (b / (c ^ 2.0))); elseif (d <= -1.1e-131) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (d <= 6.5e+65) tmp = (a / c) + (b / ((c ^ 2.0) / d)); else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -6.4e+125], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -8.6e+75], N[(N[(a / c), $MachinePrecision] + N[(d * N[(b / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.1e-131], 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, 6.5e+65], N[(N[(a / c), $MachinePrecision] + N[(b / N[(N[Power[c, 2.0], $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.4 \cdot 10^{+125}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + c \cdot \frac{a}{d}\right)\\
\mathbf{elif}\;d \leq -8.6 \cdot 10^{+75}:\\
\;\;\;\;\frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\
\mathbf{elif}\;d \leq -1.1 \cdot 10^{-131}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 6.5 \cdot 10^{+65}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{\frac{{c}^{2}}{d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if d < -6.39999999999999967e125Initial program 45.1%
add-sqr-sqrt45.1%
*-un-lft-identity45.1%
times-frac45.1%
hypot-def45.1%
fma-def45.1%
hypot-def73.0%
Applied egg-rr73.0%
Taylor expanded in c around 0 37.2%
Taylor expanded in c around 0 87.9%
associate-/l*86.0%
associate-/r/88.2%
Applied egg-rr88.2%
if -6.39999999999999967e125 < d < -8.6000000000000002e75Initial program 34.6%
Taylor expanded in c around inf 68.3%
associate-/l*79.4%
associate-/r/79.4%
Simplified79.4%
if -8.6000000000000002e75 < d < -1.1e-131Initial program 92.5%
if -1.1e-131 < d < 6.5000000000000003e65Initial program 68.1%
Taylor expanded in c around inf 83.7%
associate-/l*84.8%
Simplified84.8%
if 6.5000000000000003e65 < d Initial program 41.8%
add-sqr-sqrt41.8%
*-un-lft-identity41.8%
times-frac41.8%
hypot-def41.8%
fma-def41.8%
hypot-def57.5%
Applied egg-rr57.5%
Taylor expanded in c around 0 68.7%
Taylor expanded in c around 0 65.9%
expm1-log1p-u49.2%
expm1-udef28.8%
associate-*l/28.8%
*-un-lft-identity28.8%
associate-/l*32.0%
div-inv32.0%
clear-num32.0%
Applied egg-rr32.0%
expm1-def58.5%
expm1-log1p75.2%
Simplified75.2%
Final simplification83.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -3e+138)
(/ (- a) (hypot c d))
(if (<= c -2.7e-112)
t_0
(if (<= c 1.42e-139)
(/ (+ b (* a (/ c d))) d)
(if (<= c 1.4e+91) t_0 (/ (+ a (/ b (/ 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 (c <= -3e+138) {
tmp = -a / hypot(c, d);
} else if (c <= -2.7e-112) {
tmp = t_0;
} else if (c <= 1.42e-139) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.4e+91) {
tmp = t_0;
} else {
tmp = (a + (b / (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 (c <= -3e+138) {
tmp = -a / Math.hypot(c, d);
} else if (c <= -2.7e-112) {
tmp = t_0;
} else if (c <= 1.42e-139) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.4e+91) {
tmp = t_0;
} else {
tmp = (a + (b / (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 c <= -3e+138: tmp = -a / math.hypot(c, d) elif c <= -2.7e-112: tmp = t_0 elif c <= 1.42e-139: tmp = (b + (a * (c / d))) / d elif c <= 1.4e+91: tmp = t_0 else: tmp = (a + (b / (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 (c <= -3e+138) tmp = Float64(Float64(-a) / hypot(c, d)); elseif (c <= -2.7e-112) tmp = t_0; elseif (c <= 1.42e-139) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 1.4e+91) tmp = t_0; else tmp = Float64(Float64(a + Float64(b / 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 (c <= -3e+138) tmp = -a / hypot(c, d); elseif (c <= -2.7e-112) tmp = t_0; elseif (c <= 1.42e-139) tmp = (b + (a * (c / d))) / d; elseif (c <= 1.4e+91) tmp = t_0; else tmp = (a + (b / (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[c, -3e+138], N[((-a) / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -2.7e-112], t$95$0, If[LessEqual[c, 1.42e-139], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.4e+91], t$95$0, N[(N[(a + N[(b / 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}\;c \leq -3 \cdot 10^{+138}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -2.7 \cdot 10^{-112}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.42 \cdot 10^{-139}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.4 \cdot 10^{+91}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if c < -3.0000000000000001e138Initial program 33.9%
add-sqr-sqrt33.9%
*-un-lft-identity33.9%
times-frac33.9%
hypot-def33.9%
fma-def33.9%
hypot-def53.6%
Applied egg-rr53.6%
associate-*l/53.6%
*-un-lft-identity53.6%
Applied egg-rr53.6%
Taylor expanded in c around -inf 78.6%
neg-mul-178.6%
Simplified78.6%
if -3.0000000000000001e138 < c < -2.7000000000000001e-112 or 1.41999999999999997e-139 < c < 1.3999999999999999e91Initial program 84.2%
if -2.7000000000000001e-112 < c < 1.41999999999999997e-139Initial program 63.9%
add-sqr-sqrt63.9%
*-un-lft-identity63.9%
times-frac63.8%
hypot-def63.8%
fma-def63.8%
hypot-def81.9%
Applied egg-rr81.9%
Taylor expanded in c around 0 57.9%
Taylor expanded in c around 0 91.0%
expm1-log1p-u75.6%
expm1-udef38.2%
associate-*l/38.2%
*-un-lft-identity38.2%
associate-/l*38.2%
div-inv38.2%
clear-num38.2%
Applied egg-rr38.2%
expm1-def77.3%
expm1-log1p92.8%
Simplified92.8%
if 1.3999999999999999e91 < c Initial program 32.0%
add-sqr-sqrt32.0%
*-un-lft-identity32.0%
times-frac31.9%
hypot-def31.9%
fma-def31.9%
hypot-def60.6%
Applied egg-rr60.6%
associate-*l/60.6%
*-un-lft-identity60.6%
Applied egg-rr60.6%
Taylor expanded in c around inf 76.3%
associate-/l*83.8%
Simplified83.8%
Final simplification85.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -3.7e+137)
(/ (- (* d (/ (- b) c)) a) (hypot c d))
(if (<= c -1.9e-112)
t_0
(if (<= c 6.9e-140)
(/ (+ b (* a (/ c d))) d)
(if (<= c 2.1e+94) t_0 (/ (+ a (/ b (/ 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 (c <= -3.7e+137) {
tmp = ((d * (-b / c)) - a) / hypot(c, d);
} else if (c <= -1.9e-112) {
tmp = t_0;
} else if (c <= 6.9e-140) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 2.1e+94) {
tmp = t_0;
} else {
tmp = (a + (b / (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 (c <= -3.7e+137) {
tmp = ((d * (-b / c)) - a) / Math.hypot(c, d);
} else if (c <= -1.9e-112) {
tmp = t_0;
} else if (c <= 6.9e-140) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 2.1e+94) {
tmp = t_0;
} else {
tmp = (a + (b / (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 c <= -3.7e+137: tmp = ((d * (-b / c)) - a) / math.hypot(c, d) elif c <= -1.9e-112: tmp = t_0 elif c <= 6.9e-140: tmp = (b + (a * (c / d))) / d elif c <= 2.1e+94: tmp = t_0 else: tmp = (a + (b / (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 (c <= -3.7e+137) tmp = Float64(Float64(Float64(d * Float64(Float64(-b) / c)) - a) / hypot(c, d)); elseif (c <= -1.9e-112) tmp = t_0; elseif (c <= 6.9e-140) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 2.1e+94) tmp = t_0; else tmp = Float64(Float64(a + Float64(b / 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 (c <= -3.7e+137) tmp = ((d * (-b / c)) - a) / hypot(c, d); elseif (c <= -1.9e-112) tmp = t_0; elseif (c <= 6.9e-140) tmp = (b + (a * (c / d))) / d; elseif (c <= 2.1e+94) tmp = t_0; else tmp = (a + (b / (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[c, -3.7e+137], N[(N[(N[(d * N[((-b) / c), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.9e-112], t$95$0, If[LessEqual[c, 6.9e-140], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.1e+94], t$95$0, N[(N[(a + N[(b / 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}\;c \leq -3.7 \cdot 10^{+137}:\\
\;\;\;\;\frac{d \cdot \frac{-b}{c} - a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -1.9 \cdot 10^{-112}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 6.9 \cdot 10^{-140}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 2.1 \cdot 10^{+94}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if c < -3.7000000000000002e137Initial program 33.9%
add-sqr-sqrt33.9%
*-un-lft-identity33.9%
times-frac33.9%
hypot-def33.9%
fma-def33.9%
hypot-def53.6%
Applied egg-rr53.6%
associate-*l/53.6%
*-un-lft-identity53.6%
Applied egg-rr53.6%
Taylor expanded in c around -inf 81.7%
neg-mul-181.7%
+-commutative81.7%
unsub-neg81.7%
associate-*r/81.7%
mul-1-neg81.7%
distribute-rgt-neg-out81.7%
Simplified81.7%
Taylor expanded in b around 0 81.7%
mul-1-neg81.7%
*-commutative81.7%
associate-*r/84.4%
distribute-rgt-neg-in84.4%
Simplified84.4%
if -3.7000000000000002e137 < c < -1.89999999999999997e-112 or 6.9000000000000004e-140 < c < 2.09999999999999989e94Initial program 84.2%
if -1.89999999999999997e-112 < c < 6.9000000000000004e-140Initial program 63.9%
add-sqr-sqrt63.9%
*-un-lft-identity63.9%
times-frac63.8%
hypot-def63.8%
fma-def63.8%
hypot-def81.9%
Applied egg-rr81.9%
Taylor expanded in c around 0 57.9%
Taylor expanded in c around 0 91.0%
expm1-log1p-u75.6%
expm1-udef38.2%
associate-*l/38.2%
*-un-lft-identity38.2%
associate-/l*38.2%
div-inv38.2%
clear-num38.2%
Applied egg-rr38.2%
expm1-def77.3%
expm1-log1p92.8%
Simplified92.8%
if 2.09999999999999989e94 < c Initial program 32.0%
add-sqr-sqrt32.0%
*-un-lft-identity32.0%
times-frac31.9%
hypot-def31.9%
fma-def31.9%
hypot-def60.6%
Applied egg-rr60.6%
associate-*l/60.6%
*-un-lft-identity60.6%
Applied egg-rr60.6%
Taylor expanded in c around inf 76.3%
associate-/l*83.8%
Simplified83.8%
Final simplification86.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))) (t_1 (/ b (/ c d))))
(if (<= c -5.7e+135)
(/ (- (- a) t_1) (hypot c d))
(if (<= c -7.5e-113)
t_0
(if (<= c 1.5e-140)
(/ (+ b (* a (/ c d))) d)
(if (<= c 8e+92) t_0 (/ (+ a 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 / (c / d);
double tmp;
if (c <= -5.7e+135) {
tmp = (-a - t_1) / hypot(c, d);
} else if (c <= -7.5e-113) {
tmp = t_0;
} else if (c <= 1.5e-140) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 8e+92) {
tmp = t_0;
} else {
tmp = (a + 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 / (c / d);
double tmp;
if (c <= -5.7e+135) {
tmp = (-a - t_1) / Math.hypot(c, d);
} else if (c <= -7.5e-113) {
tmp = t_0;
} else if (c <= 1.5e-140) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 8e+92) {
tmp = t_0;
} else {
tmp = (a + 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 / (c / d) tmp = 0 if c <= -5.7e+135: tmp = (-a - t_1) / math.hypot(c, d) elif c <= -7.5e-113: tmp = t_0 elif c <= 1.5e-140: tmp = (b + (a * (c / d))) / d elif c <= 8e+92: tmp = t_0 else: tmp = (a + 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(c / d)) tmp = 0.0 if (c <= -5.7e+135) tmp = Float64(Float64(Float64(-a) - t_1) / hypot(c, d)); elseif (c <= -7.5e-113) tmp = t_0; elseif (c <= 1.5e-140) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 8e+92) tmp = t_0; else tmp = Float64(Float64(a + 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 / (c / d); tmp = 0.0; if (c <= -5.7e+135) tmp = (-a - t_1) / hypot(c, d); elseif (c <= -7.5e-113) tmp = t_0; elseif (c <= 1.5e-140) tmp = (b + (a * (c / d))) / d; elseif (c <= 8e+92) tmp = t_0; else tmp = (a + 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[(c / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -5.7e+135], N[(N[((-a) - t$95$1), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -7.5e-113], t$95$0, If[LessEqual[c, 1.5e-140], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8e+92], t$95$0, N[(N[(a + t$95$1), $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}\\
t_1 := \frac{b}{\frac{c}{d}}\\
\mathbf{if}\;c \leq -5.7 \cdot 10^{+135}:\\
\;\;\;\;\frac{\left(-a\right) - t_1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -7.5 \cdot 10^{-113}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.5 \cdot 10^{-140}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 8 \cdot 10^{+92}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + t_1}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if c < -5.7000000000000002e135Initial program 33.9%
add-sqr-sqrt33.9%
*-un-lft-identity33.9%
times-frac33.9%
hypot-def33.9%
fma-def33.9%
hypot-def53.6%
Applied egg-rr53.6%
associate-*l/53.6%
*-un-lft-identity53.6%
Applied egg-rr53.6%
Taylor expanded in c around -inf 81.7%
distribute-lft-out81.7%
associate-/l*84.4%
Simplified84.4%
if -5.7000000000000002e135 < c < -7.5000000000000002e-113 or 1.50000000000000009e-140 < c < 8.0000000000000003e92Initial program 84.2%
if -7.5000000000000002e-113 < c < 1.50000000000000009e-140Initial program 63.9%
add-sqr-sqrt63.9%
*-un-lft-identity63.9%
times-frac63.8%
hypot-def63.8%
fma-def63.8%
hypot-def81.9%
Applied egg-rr81.9%
Taylor expanded in c around 0 57.9%
Taylor expanded in c around 0 91.0%
expm1-log1p-u75.6%
expm1-udef38.2%
associate-*l/38.2%
*-un-lft-identity38.2%
associate-/l*38.2%
div-inv38.2%
clear-num38.2%
Applied egg-rr38.2%
expm1-def77.3%
expm1-log1p92.8%
Simplified92.8%
if 8.0000000000000003e92 < c Initial program 32.0%
add-sqr-sqrt32.0%
*-un-lft-identity32.0%
times-frac31.9%
hypot-def31.9%
fma-def31.9%
hypot-def60.6%
Applied egg-rr60.6%
associate-*l/60.6%
*-un-lft-identity60.6%
Applied egg-rr60.6%
Taylor expanded in c around inf 76.3%
associate-/l*83.8%
Simplified83.8%
Final simplification86.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -4.2e+140)
(/ (- a) (hypot c d))
(if (<= c -9e-113)
t_0
(if (<= c 2.15e-140)
(/ (+ b (* a (/ c d))) d)
(if (<= c 1.25e+141) t_0 (/ a c)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -4.2e+140) {
tmp = -a / hypot(c, d);
} else if (c <= -9e-113) {
tmp = t_0;
} else if (c <= 2.15e-140) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.25e+141) {
tmp = t_0;
} else {
tmp = a / c;
}
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 (c <= -4.2e+140) {
tmp = -a / Math.hypot(c, d);
} else if (c <= -9e-113) {
tmp = t_0;
} else if (c <= 2.15e-140) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.25e+141) {
tmp = t_0;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -4.2e+140: tmp = -a / math.hypot(c, d) elif c <= -9e-113: tmp = t_0 elif c <= 2.15e-140: tmp = (b + (a * (c / d))) / d elif c <= 1.25e+141: tmp = t_0 else: tmp = a / c 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 (c <= -4.2e+140) tmp = Float64(Float64(-a) / hypot(c, d)); elseif (c <= -9e-113) tmp = t_0; elseif (c <= 2.15e-140) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 1.25e+141) tmp = t_0; else tmp = Float64(a / c); 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 (c <= -4.2e+140) tmp = -a / hypot(c, d); elseif (c <= -9e-113) tmp = t_0; elseif (c <= 2.15e-140) tmp = (b + (a * (c / d))) / d; elseif (c <= 1.25e+141) tmp = t_0; else tmp = a / c; 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[c, -4.2e+140], N[((-a) / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -9e-113], t$95$0, If[LessEqual[c, 2.15e-140], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.25e+141], t$95$0, N[(a / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -4.2 \cdot 10^{+140}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -9 \cdot 10^{-113}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 2.15 \cdot 10^{-140}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.25 \cdot 10^{+141}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -4.2000000000000004e140Initial program 33.9%
add-sqr-sqrt33.9%
*-un-lft-identity33.9%
times-frac33.9%
hypot-def33.9%
fma-def33.9%
hypot-def53.6%
Applied egg-rr53.6%
associate-*l/53.6%
*-un-lft-identity53.6%
Applied egg-rr53.6%
Taylor expanded in c around -inf 78.6%
neg-mul-178.6%
Simplified78.6%
if -4.2000000000000004e140 < c < -9.0000000000000002e-113 or 2.14999999999999981e-140 < c < 1.25000000000000006e141Initial program 82.3%
if -9.0000000000000002e-113 < c < 2.14999999999999981e-140Initial program 63.9%
add-sqr-sqrt63.9%
*-un-lft-identity63.9%
times-frac63.8%
hypot-def63.8%
fma-def63.8%
hypot-def81.9%
Applied egg-rr81.9%
Taylor expanded in c around 0 57.9%
Taylor expanded in c around 0 91.0%
expm1-log1p-u75.6%
expm1-udef38.2%
associate-*l/38.2%
*-un-lft-identity38.2%
associate-/l*38.2%
div-inv38.2%
clear-num38.2%
Applied egg-rr38.2%
expm1-def77.3%
expm1-log1p92.8%
Simplified92.8%
if 1.25000000000000006e141 < c Initial program 21.6%
Taylor expanded in c around inf 73.0%
Final simplification82.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -4.8e+140)
(/ a c)
(if (<= c -1.12e-112)
t_0
(if (<= c 2.6e-139)
(/ (+ b (* a (/ c d))) d)
(if (<= c 1.06e+141) t_0 (/ a c)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -4.8e+140) {
tmp = a / c;
} else if (c <= -1.12e-112) {
tmp = t_0;
} else if (c <= 2.6e-139) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.06e+141) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (c <= (-4.8d+140)) then
tmp = a / c
else if (c <= (-1.12d-112)) then
tmp = t_0
else if (c <= 2.6d-139) then
tmp = (b + (a * (c / d))) / d
else if (c <= 1.06d+141) then
tmp = t_0
else
tmp = a / c
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 (c <= -4.8e+140) {
tmp = a / c;
} else if (c <= -1.12e-112) {
tmp = t_0;
} else if (c <= 2.6e-139) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.06e+141) {
tmp = t_0;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -4.8e+140: tmp = a / c elif c <= -1.12e-112: tmp = t_0 elif c <= 2.6e-139: tmp = (b + (a * (c / d))) / d elif c <= 1.06e+141: tmp = t_0 else: tmp = a / c 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 (c <= -4.8e+140) tmp = Float64(a / c); elseif (c <= -1.12e-112) tmp = t_0; elseif (c <= 2.6e-139) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 1.06e+141) tmp = t_0; else tmp = Float64(a / c); 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 (c <= -4.8e+140) tmp = a / c; elseif (c <= -1.12e-112) tmp = t_0; elseif (c <= 2.6e-139) tmp = (b + (a * (c / d))) / d; elseif (c <= 1.06e+141) tmp = t_0; else tmp = a / c; 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[c, -4.8e+140], N[(a / c), $MachinePrecision], If[LessEqual[c, -1.12e-112], t$95$0, If[LessEqual[c, 2.6e-139], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.06e+141], t$95$0, N[(a / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -4.8 \cdot 10^{+140}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -1.12 \cdot 10^{-112}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 2.6 \cdot 10^{-139}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.06 \cdot 10^{+141}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -4.7999999999999999e140 or 1.05999999999999997e141 < c Initial program 27.7%
Taylor expanded in c around inf 75.8%
if -4.7999999999999999e140 < c < -1.12e-112 or 2.5999999999999998e-139 < c < 1.05999999999999997e141Initial program 82.3%
if -1.12e-112 < c < 2.5999999999999998e-139Initial program 63.9%
add-sqr-sqrt63.9%
*-un-lft-identity63.9%
times-frac63.8%
hypot-def63.8%
fma-def63.8%
hypot-def81.9%
Applied egg-rr81.9%
Taylor expanded in c around 0 57.9%
Taylor expanded in c around 0 91.0%
expm1-log1p-u75.6%
expm1-udef38.2%
associate-*l/38.2%
*-un-lft-identity38.2%
associate-/l*38.2%
div-inv38.2%
clear-num38.2%
Applied egg-rr38.2%
expm1-def77.3%
expm1-log1p92.8%
Simplified92.8%
Final simplification82.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.45e+45) (not (<= c 5.5e+109))) (/ a c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.45e+45) || !(c <= 5.5e+109)) {
tmp = a / 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 ((c <= (-2.45d+45)) .or. (.not. (c <= 5.5d+109))) then
tmp = a / 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 ((c <= -2.45e+45) || !(c <= 5.5e+109)) {
tmp = a / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.45e+45) or not (c <= 5.5e+109): tmp = a / c else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.45e+45) || !(c <= 5.5e+109)) tmp = Float64(a / 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 ((c <= -2.45e+45) || ~((c <= 5.5e+109))) tmp = a / c; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.45e+45], N[Not[LessEqual[c, 5.5e+109]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.45 \cdot 10^{+45} \lor \neg \left(c \leq 5.5 \cdot 10^{+109}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if c < -2.4500000000000001e45 or 5.4999999999999998e109 < c Initial program 41.0%
Taylor expanded in c around inf 72.8%
if -2.4500000000000001e45 < c < 5.4999999999999998e109Initial program 73.8%
add-sqr-sqrt73.8%
*-un-lft-identity73.8%
times-frac73.7%
hypot-def73.7%
fma-def73.7%
hypot-def84.0%
Applied egg-rr84.0%
Taylor expanded in c around 0 42.8%
Taylor expanded in c around 0 72.4%
expm1-log1p-u57.8%
expm1-udef30.1%
associate-*l/30.1%
*-un-lft-identity30.1%
associate-/l*30.7%
div-inv30.7%
clear-num30.7%
Applied egg-rr30.7%
expm1-def58.7%
expm1-log1p73.4%
Simplified73.4%
Final simplification73.2%
(FPCore (a b c d)
:precision binary64
(if (or (<= d -6.4e+125)
(not (or (<= d -9.8e+72) (and (not (<= d -6e-23)) (<= d 3.45e+65)))))
(/ b d)
(/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.4e+125) || !((d <= -9.8e+72) || (!(d <= -6e-23) && (d <= 3.45e+65)))) {
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 <= (-6.4d+125)) .or. (.not. (d <= (-9.8d+72)) .or. (.not. (d <= (-6d-23))) .and. (d <= 3.45d+65))) 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 <= -6.4e+125) || !((d <= -9.8e+72) || (!(d <= -6e-23) && (d <= 3.45e+65)))) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -6.4e+125) or not ((d <= -9.8e+72) or (not (d <= -6e-23) and (d <= 3.45e+65))): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -6.4e+125) || !((d <= -9.8e+72) || (!(d <= -6e-23) && (d <= 3.45e+65)))) 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 <= -6.4e+125) || ~(((d <= -9.8e+72) || (~((d <= -6e-23)) && (d <= 3.45e+65))))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6.4e+125], N[Not[Or[LessEqual[d, -9.8e+72], And[N[Not[LessEqual[d, -6e-23]], $MachinePrecision], LessEqual[d, 3.45e+65]]]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.4 \cdot 10^{+125} \lor \neg \left(d \leq -9.8 \cdot 10^{+72} \lor \neg \left(d \leq -6 \cdot 10^{-23}\right) \land d \leq 3.45 \cdot 10^{+65}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -6.39999999999999967e125 or -9.80000000000000012e72 < d < -6.00000000000000006e-23 or 3.45e65 < d Initial program 51.1%
Taylor expanded in c around 0 67.6%
if -6.39999999999999967e125 < d < -9.80000000000000012e72 or -6.00000000000000006e-23 < d < 3.45e65Initial program 69.6%
Taylor expanded in c around inf 67.8%
Final simplification67.7%
(FPCore (a b c d) :precision binary64 (if (<= d -2.6e+139) (/ a d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.6e+139) {
tmp = a / 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 <= (-2.6d+139)) then
tmp = a / 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 <= -2.6e+139) {
tmp = a / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -2.6e+139: tmp = a / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -2.6e+139) tmp = Float64(a / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -2.6e+139) tmp = a / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.6e+139], N[(a / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.6 \cdot 10^{+139}:\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -2.60000000000000022e139Initial program 45.1%
add-sqr-sqrt45.1%
*-un-lft-identity45.1%
times-frac45.1%
hypot-def45.1%
fma-def45.1%
hypot-def73.0%
Applied egg-rr73.0%
Taylor expanded in c around 0 37.2%
Taylor expanded in c around inf 25.9%
if -2.60000000000000022e139 < d Initial program 63.4%
Taylor expanded in c around inf 49.0%
Final simplification45.4%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 60.6%
Taylor expanded in c around inf 43.1%
Final simplification43.1%
(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 2023314
(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))))