
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 1e+287) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (* (/ 1.0 c) (+ a (/ b (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 1e+287) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (1.0 / c) * (a + (b / (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))) <= 1e+287) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / 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], 1e+287], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / 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 10^{+287}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.0000000000000001e287Initial program 79.7%
*-un-lft-identity79.7%
add-sqr-sqrt79.7%
times-frac79.7%
hypot-def79.7%
fma-def79.7%
hypot-def98.1%
Applied egg-rr98.1%
if 1.0000000000000001e287 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 15.2%
*-un-lft-identity15.2%
add-sqr-sqrt15.2%
times-frac15.2%
hypot-def15.2%
fma-def15.2%
hypot-def22.1%
Applied egg-rr22.1%
Taylor expanded in c around inf 33.4%
associate-/l*37.8%
Simplified37.8%
Taylor expanded in c around inf 71.5%
Final simplification92.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -1.25e+66)
(* (+ a (/ b (/ c d))) (/ -1.0 (hypot c d)))
(if (<= c -1.5e-105)
t_0
(if (<= c 1.15e-86)
(* (/ -1.0 d) (- (- b) (/ (* a c) d)))
(if (<= c 7.2e+47)
t_0
(+ (/ a (hypot c d)) (* (/ b (hypot c d)) (/ d 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 <= -1.25e+66) {
tmp = (a + (b / (c / d))) * (-1.0 / hypot(c, d));
} else if (c <= -1.5e-105) {
tmp = t_0;
} else if (c <= 1.15e-86) {
tmp = (-1.0 / d) * (-b - ((a * c) / d));
} else if (c <= 7.2e+47) {
tmp = t_0;
} else {
tmp = (a / hypot(c, d)) + ((b / hypot(c, d)) * (d / 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 <= -1.25e+66) {
tmp = (a + (b / (c / d))) * (-1.0 / Math.hypot(c, d));
} else if (c <= -1.5e-105) {
tmp = t_0;
} else if (c <= 1.15e-86) {
tmp = (-1.0 / d) * (-b - ((a * c) / d));
} else if (c <= 7.2e+47) {
tmp = t_0;
} else {
tmp = (a / Math.hypot(c, d)) + ((b / Math.hypot(c, d)) * (d / c));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -1.25e+66: tmp = (a + (b / (c / d))) * (-1.0 / math.hypot(c, d)) elif c <= -1.5e-105: tmp = t_0 elif c <= 1.15e-86: tmp = (-1.0 / d) * (-b - ((a * c) / d)) elif c <= 7.2e+47: tmp = t_0 else: tmp = (a / math.hypot(c, d)) + ((b / math.hypot(c, d)) * (d / 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 <= -1.25e+66) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) * Float64(-1.0 / hypot(c, d))); elseif (c <= -1.5e-105) tmp = t_0; elseif (c <= 1.15e-86) tmp = Float64(Float64(-1.0 / d) * Float64(Float64(-b) - Float64(Float64(a * c) / d))); elseif (c <= 7.2e+47) tmp = t_0; else tmp = Float64(Float64(a / hypot(c, d)) + Float64(Float64(b / hypot(c, d)) * Float64(d / 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 <= -1.25e+66) tmp = (a + (b / (c / d))) * (-1.0 / hypot(c, d)); elseif (c <= -1.5e-105) tmp = t_0; elseif (c <= 1.15e-86) tmp = (-1.0 / d) * (-b - ((a * c) / d)); elseif (c <= 7.2e+47) tmp = t_0; else tmp = (a / hypot(c, d)) + ((b / hypot(c, d)) * (d / 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, -1.25e+66], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.5e-105], t$95$0, If[LessEqual[c, 1.15e-86], N[(N[(-1.0 / d), $MachinePrecision] * N[((-b) - N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.2e+47], t$95$0, N[(N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(d / c), $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.25 \cdot 10^{+66}:\\
\;\;\;\;\left(a + \frac{b}{\frac{c}{d}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -1.5 \cdot 10^{-105}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.15 \cdot 10^{-86}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\
\mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)} + \frac{b}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{c}\\
\end{array}
\end{array}
if c < -1.24999999999999998e66Initial program 43.4%
*-un-lft-identity43.4%
add-sqr-sqrt43.4%
times-frac43.4%
hypot-def43.4%
fma-def43.4%
hypot-def65.5%
Applied egg-rr65.5%
Taylor expanded in c around -inf 86.3%
mul-1-neg86.3%
unsub-neg86.3%
neg-mul-186.3%
associate-/l*86.4%
Simplified86.4%
if -1.24999999999999998e66 < c < -1.5e-105 or 1.14999999999999998e-86 < c < 7.20000000000000015e47Initial program 87.9%
if -1.5e-105 < c < 1.14999999999999998e-86Initial program 74.4%
*-un-lft-identity74.4%
add-sqr-sqrt74.4%
times-frac74.5%
hypot-def74.5%
fma-def74.5%
hypot-def88.4%
Applied egg-rr88.4%
Taylor expanded in d around -inf 60.4%
Taylor expanded in d around -inf 92.1%
if 7.20000000000000015e47 < c Initial program 48.3%
*-un-lft-identity48.3%
add-sqr-sqrt48.3%
times-frac48.2%
hypot-def48.2%
fma-def48.2%
hypot-def72.7%
Applied egg-rr72.7%
Taylor expanded in c around inf 90.3%
associate-/l*92.9%
Simplified92.9%
distribute-lft-in92.9%
associate-*l/93.2%
*-un-lft-identity93.2%
div-inv93.2%
clear-num93.2%
associate-*r*93.2%
add-sqr-sqrt48.7%
sqrt-unprod64.8%
sqr-neg64.8%
mul-1-neg64.8%
mul-1-neg64.8%
sqrt-unprod34.9%
add-sqr-sqrt73.3%
associate-*l/73.3%
*-un-lft-identity73.3%
add-sqr-sqrt34.9%
sqrt-unprod64.8%
mul-1-neg64.8%
mul-1-neg64.8%
sqr-neg64.8%
sqrt-unprod48.7%
add-sqr-sqrt93.3%
Applied egg-rr93.3%
Final simplification90.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -1.25e+66)
(* (+ a (/ b (/ c d))) (/ -1.0 (hypot c d)))
(if (<= c -1.22e-105)
t_0
(if (<= c 3.6e-80)
(* (/ -1.0 d) (- (- b) (/ (* a c) d)))
(if (<= c 7.2e+47)
t_0
(* (/ 1.0 (hypot c d)) (+ a (/ 1.0 (/ (/ c d) b))))))))))
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.25e+66) {
tmp = (a + (b / (c / d))) * (-1.0 / hypot(c, d));
} else if (c <= -1.22e-105) {
tmp = t_0;
} else if (c <= 3.6e-80) {
tmp = (-1.0 / d) * (-b - ((a * c) / d));
} else if (c <= 7.2e+47) {
tmp = t_0;
} else {
tmp = (1.0 / hypot(c, d)) * (a + (1.0 / ((c / d) / b)));
}
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.25e+66) {
tmp = (a + (b / (c / d))) * (-1.0 / Math.hypot(c, d));
} else if (c <= -1.22e-105) {
tmp = t_0;
} else if (c <= 3.6e-80) {
tmp = (-1.0 / d) * (-b - ((a * c) / d));
} else if (c <= 7.2e+47) {
tmp = t_0;
} else {
tmp = (1.0 / Math.hypot(c, d)) * (a + (1.0 / ((c / d) / b)));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -1.25e+66: tmp = (a + (b / (c / d))) * (-1.0 / math.hypot(c, d)) elif c <= -1.22e-105: tmp = t_0 elif c <= 3.6e-80: tmp = (-1.0 / d) * (-b - ((a * c) / d)) elif c <= 7.2e+47: tmp = t_0 else: tmp = (1.0 / math.hypot(c, d)) * (a + (1.0 / ((c / d) / b))) 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.25e+66) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) * Float64(-1.0 / hypot(c, d))); elseif (c <= -1.22e-105) tmp = t_0; elseif (c <= 3.6e-80) tmp = Float64(Float64(-1.0 / d) * Float64(Float64(-b) - Float64(Float64(a * c) / d))); elseif (c <= 7.2e+47) tmp = t_0; else tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(a + Float64(1.0 / Float64(Float64(c / d) / b)))); 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.25e+66) tmp = (a + (b / (c / d))) * (-1.0 / hypot(c, d)); elseif (c <= -1.22e-105) tmp = t_0; elseif (c <= 3.6e-80) tmp = (-1.0 / d) * (-b - ((a * c) / d)); elseif (c <= 7.2e+47) tmp = t_0; else tmp = (1.0 / hypot(c, d)) * (a + (1.0 / ((c / d) / b))); 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.25e+66], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.22e-105], t$95$0, If[LessEqual[c, 3.6e-80], N[(N[(-1.0 / d), $MachinePrecision] * N[((-b) - N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.2e+47], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a + N[(1.0 / N[(N[(c / d), $MachinePrecision] / b), $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.25 \cdot 10^{+66}:\\
\;\;\;\;\left(a + \frac{b}{\frac{c}{d}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -1.22 \cdot 10^{-105}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 3.6 \cdot 10^{-80}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\
\mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{1}{\frac{\frac{c}{d}}{b}}\right)\\
\end{array}
\end{array}
if c < -1.24999999999999998e66Initial program 43.4%
*-un-lft-identity43.4%
add-sqr-sqrt43.4%
times-frac43.4%
hypot-def43.4%
fma-def43.4%
hypot-def65.5%
Applied egg-rr65.5%
Taylor expanded in c around -inf 86.3%
mul-1-neg86.3%
unsub-neg86.3%
neg-mul-186.3%
associate-/l*86.4%
Simplified86.4%
if -1.24999999999999998e66 < c < -1.22000000000000001e-105 or 3.6e-80 < c < 7.20000000000000015e47Initial program 87.9%
if -1.22000000000000001e-105 < c < 3.6e-80Initial program 74.4%
*-un-lft-identity74.4%
add-sqr-sqrt74.4%
times-frac74.5%
hypot-def74.5%
fma-def74.5%
hypot-def88.4%
Applied egg-rr88.4%
Taylor expanded in d around -inf 60.4%
Taylor expanded in d around -inf 92.1%
if 7.20000000000000015e47 < c Initial program 48.3%
*-un-lft-identity48.3%
add-sqr-sqrt48.3%
times-frac48.2%
hypot-def48.2%
fma-def48.2%
hypot-def72.7%
Applied egg-rr72.7%
Taylor expanded in c around inf 90.3%
associate-/l*92.9%
Simplified92.9%
clear-num92.9%
inv-pow92.9%
Applied egg-rr92.9%
unpow-192.9%
Simplified92.9%
Final simplification90.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (+ a (/ b (/ c d)))))
(if (<= c -1.45e+80)
(* (/ 1.0 c) t_1)
(if (<= c -1.4e-105)
t_0
(if (<= c 1.45e-81)
(* (/ -1.0 d) (- (- b) (/ (* a c) d)))
(if (<= c 7.2e+47) t_0 (* (/ 1.0 (hypot c d)) 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 + (b / (c / d));
double tmp;
if (c <= -1.45e+80) {
tmp = (1.0 / c) * t_1;
} else if (c <= -1.4e-105) {
tmp = t_0;
} else if (c <= 1.45e-81) {
tmp = (-1.0 / d) * (-b - ((a * c) / d));
} else if (c <= 7.2e+47) {
tmp = t_0;
} else {
tmp = (1.0 / hypot(c, d)) * t_1;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = a + (b / (c / d));
double tmp;
if (c <= -1.45e+80) {
tmp = (1.0 / c) * t_1;
} else if (c <= -1.4e-105) {
tmp = t_0;
} else if (c <= 1.45e-81) {
tmp = (-1.0 / d) * (-b - ((a * c) / d));
} else if (c <= 7.2e+47) {
tmp = t_0;
} else {
tmp = (1.0 / Math.hypot(c, d)) * t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = a + (b / (c / d)) tmp = 0 if c <= -1.45e+80: tmp = (1.0 / c) * t_1 elif c <= -1.4e-105: tmp = t_0 elif c <= 1.45e-81: tmp = (-1.0 / d) * (-b - ((a * c) / d)) elif c <= 7.2e+47: tmp = t_0 else: tmp = (1.0 / math.hypot(c, d)) * t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(a + Float64(b / Float64(c / d))) tmp = 0.0 if (c <= -1.45e+80) tmp = Float64(Float64(1.0 / c) * t_1); elseif (c <= -1.4e-105) tmp = t_0; elseif (c <= 1.45e-81) tmp = Float64(Float64(-1.0 / d) * Float64(Float64(-b) - Float64(Float64(a * c) / d))); elseif (c <= 7.2e+47) tmp = t_0; else tmp = Float64(Float64(1.0 / hypot(c, d)) * t_1); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); t_1 = a + (b / (c / d)); tmp = 0.0; if (c <= -1.45e+80) tmp = (1.0 / c) * t_1; elseif (c <= -1.4e-105) tmp = t_0; elseif (c <= 1.45e-81) tmp = (-1.0 / d) * (-b - ((a * c) / d)); elseif (c <= 7.2e+47) tmp = t_0; else tmp = (1.0 / hypot(c, d)) * t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.45e+80], N[(N[(1.0 / c), $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[c, -1.4e-105], t$95$0, If[LessEqual[c, 1.45e-81], N[(N[(-1.0 / d), $MachinePrecision] * N[((-b) - N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.2e+47], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := a + \frac{b}{\frac{c}{d}}\\
\mathbf{if}\;c \leq -1.45 \cdot 10^{+80}:\\
\;\;\;\;\frac{1}{c} \cdot t_1\\
\mathbf{elif}\;c \leq -1.4 \cdot 10^{-105}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.45 \cdot 10^{-81}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\
\mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot t_1\\
\end{array}
\end{array}
if c < -1.44999999999999993e80Initial program 40.4%
*-un-lft-identity40.4%
add-sqr-sqrt40.4%
times-frac40.4%
hypot-def40.4%
fma-def40.4%
hypot-def64.5%
Applied egg-rr64.5%
Taylor expanded in c around inf 27.3%
associate-/l*27.4%
Simplified27.4%
Taylor expanded in c around inf 87.2%
if -1.44999999999999993e80 < c < -1.4e-105 or 1.44999999999999994e-81 < c < 7.20000000000000015e47Initial program 87.2%
if -1.4e-105 < c < 1.44999999999999994e-81Initial program 74.4%
*-un-lft-identity74.4%
add-sqr-sqrt74.4%
times-frac74.5%
hypot-def74.5%
fma-def74.5%
hypot-def88.4%
Applied egg-rr88.4%
Taylor expanded in d around -inf 60.4%
Taylor expanded in d around -inf 92.1%
if 7.20000000000000015e47 < c Initial program 48.3%
*-un-lft-identity48.3%
add-sqr-sqrt48.3%
times-frac48.2%
hypot-def48.2%
fma-def48.2%
hypot-def72.7%
Applied egg-rr72.7%
Taylor expanded in c around inf 90.3%
associate-/l*92.9%
Simplified92.9%
Final simplification90.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (+ a (/ b (/ c d)))))
(if (<= c -3.1e+65)
(* t_1 (/ -1.0 (hypot c d)))
(if (<= c -1.2e-105)
t_0
(if (<= c 3.9e-83)
(* (/ -1.0 d) (- (- b) (/ (* a c) d)))
(if (<= c 7.2e+47) t_0 (* (/ 1.0 (hypot c d)) 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 + (b / (c / d));
double tmp;
if (c <= -3.1e+65) {
tmp = t_1 * (-1.0 / hypot(c, d));
} else if (c <= -1.2e-105) {
tmp = t_0;
} else if (c <= 3.9e-83) {
tmp = (-1.0 / d) * (-b - ((a * c) / d));
} else if (c <= 7.2e+47) {
tmp = t_0;
} else {
tmp = (1.0 / hypot(c, d)) * t_1;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = a + (b / (c / d));
double tmp;
if (c <= -3.1e+65) {
tmp = t_1 * (-1.0 / Math.hypot(c, d));
} else if (c <= -1.2e-105) {
tmp = t_0;
} else if (c <= 3.9e-83) {
tmp = (-1.0 / d) * (-b - ((a * c) / d));
} else if (c <= 7.2e+47) {
tmp = t_0;
} else {
tmp = (1.0 / Math.hypot(c, d)) * t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = a + (b / (c / d)) tmp = 0 if c <= -3.1e+65: tmp = t_1 * (-1.0 / math.hypot(c, d)) elif c <= -1.2e-105: tmp = t_0 elif c <= 3.9e-83: tmp = (-1.0 / d) * (-b - ((a * c) / d)) elif c <= 7.2e+47: tmp = t_0 else: tmp = (1.0 / math.hypot(c, d)) * t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(a + Float64(b / Float64(c / d))) tmp = 0.0 if (c <= -3.1e+65) tmp = Float64(t_1 * Float64(-1.0 / hypot(c, d))); elseif (c <= -1.2e-105) tmp = t_0; elseif (c <= 3.9e-83) tmp = Float64(Float64(-1.0 / d) * Float64(Float64(-b) - Float64(Float64(a * c) / d))); elseif (c <= 7.2e+47) tmp = t_0; else tmp = Float64(Float64(1.0 / hypot(c, d)) * t_1); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); t_1 = a + (b / (c / d)); tmp = 0.0; if (c <= -3.1e+65) tmp = t_1 * (-1.0 / hypot(c, d)); elseif (c <= -1.2e-105) tmp = t_0; elseif (c <= 3.9e-83) tmp = (-1.0 / d) * (-b - ((a * c) / d)); elseif (c <= 7.2e+47) tmp = t_0; else tmp = (1.0 / hypot(c, d)) * t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.1e+65], N[(t$95$1 * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.2e-105], t$95$0, If[LessEqual[c, 3.9e-83], N[(N[(-1.0 / d), $MachinePrecision] * N[((-b) - N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.2e+47], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := a + \frac{b}{\frac{c}{d}}\\
\mathbf{if}\;c \leq -3.1 \cdot 10^{+65}:\\
\;\;\;\;t_1 \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -1.2 \cdot 10^{-105}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 3.9 \cdot 10^{-83}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\
\mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot t_1\\
\end{array}
\end{array}
if c < -3.09999999999999991e65Initial program 43.4%
*-un-lft-identity43.4%
add-sqr-sqrt43.4%
times-frac43.4%
hypot-def43.4%
fma-def43.4%
hypot-def65.5%
Applied egg-rr65.5%
Taylor expanded in c around -inf 86.3%
mul-1-neg86.3%
unsub-neg86.3%
neg-mul-186.3%
associate-/l*86.4%
Simplified86.4%
if -3.09999999999999991e65 < c < -1.20000000000000007e-105 or 3.9e-83 < c < 7.20000000000000015e47Initial program 87.9%
if -1.20000000000000007e-105 < c < 3.9e-83Initial program 74.4%
*-un-lft-identity74.4%
add-sqr-sqrt74.4%
times-frac74.5%
hypot-def74.5%
fma-def74.5%
hypot-def88.4%
Applied egg-rr88.4%
Taylor expanded in d around -inf 60.4%
Taylor expanded in d around -inf 92.1%
if 7.20000000000000015e47 < c Initial program 48.3%
*-un-lft-identity48.3%
add-sqr-sqrt48.3%
times-frac48.2%
hypot-def48.2%
fma-def48.2%
hypot-def72.7%
Applied egg-rr72.7%
Taylor expanded in c around inf 90.3%
associate-/l*92.9%
Simplified92.9%
Final simplification90.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (* (/ 1.0 c) (+ a (/ b (/ c d))))))
(if (<= c -3.4e+79)
t_1
(if (<= c -1.2e-105)
t_0
(if (<= c 3.35e-87)
(* (/ -1.0 d) (- (- b) (/ (* a c) d)))
(if (<= c 7.2e+47) 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 = (1.0 / c) * (a + (b / (c / d)));
double tmp;
if (c <= -3.4e+79) {
tmp = t_1;
} else if (c <= -1.2e-105) {
tmp = t_0;
} else if (c <= 3.35e-87) {
tmp = (-1.0 / d) * (-b - ((a * c) / d));
} else if (c <= 7.2e+47) {
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 = (1.0d0 / c) * (a + (b / (c / d)))
if (c <= (-3.4d+79)) then
tmp = t_1
else if (c <= (-1.2d-105)) then
tmp = t_0
else if (c <= 3.35d-87) then
tmp = ((-1.0d0) / d) * (-b - ((a * c) / d))
else if (c <= 7.2d+47) 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 = (1.0 / c) * (a + (b / (c / d)));
double tmp;
if (c <= -3.4e+79) {
tmp = t_1;
} else if (c <= -1.2e-105) {
tmp = t_0;
} else if (c <= 3.35e-87) {
tmp = (-1.0 / d) * (-b - ((a * c) / d));
} else if (c <= 7.2e+47) {
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 = (1.0 / c) * (a + (b / (c / d))) tmp = 0 if c <= -3.4e+79: tmp = t_1 elif c <= -1.2e-105: tmp = t_0 elif c <= 3.35e-87: tmp = (-1.0 / d) * (-b - ((a * c) / d)) elif c <= 7.2e+47: 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(1.0 / c) * Float64(a + Float64(b / Float64(c / d)))) tmp = 0.0 if (c <= -3.4e+79) tmp = t_1; elseif (c <= -1.2e-105) tmp = t_0; elseif (c <= 3.35e-87) tmp = Float64(Float64(-1.0 / d) * Float64(Float64(-b) - Float64(Float64(a * c) / d))); elseif (c <= 7.2e+47) 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 = (1.0 / c) * (a + (b / (c / d))); tmp = 0.0; if (c <= -3.4e+79) tmp = t_1; elseif (c <= -1.2e-105) tmp = t_0; elseif (c <= 3.35e-87) tmp = (-1.0 / d) * (-b - ((a * c) / d)); elseif (c <= 7.2e+47) 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[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.4e+79], t$95$1, If[LessEqual[c, -1.2e-105], t$95$0, If[LessEqual[c, 3.35e-87], N[(N[(-1.0 / d), $MachinePrecision] * N[((-b) - N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.2e+47], 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{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\
\mathbf{if}\;c \leq -3.4 \cdot 10^{+79}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -1.2 \cdot 10^{-105}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 3.35 \cdot 10^{-87}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\
\mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if c < -3.40000000000000032e79 or 7.20000000000000015e47 < c Initial program 45.0%
*-un-lft-identity45.0%
add-sqr-sqrt45.0%
times-frac44.9%
hypot-def44.9%
fma-def44.9%
hypot-def69.3%
Applied egg-rr69.3%
Taylor expanded in c around inf 63.9%
associate-/l*65.5%
Simplified65.5%
Taylor expanded in c around inf 90.5%
if -3.40000000000000032e79 < c < -1.20000000000000007e-105 or 3.35e-87 < c < 7.20000000000000015e47Initial program 87.2%
if -1.20000000000000007e-105 < c < 3.35e-87Initial program 74.4%
*-un-lft-identity74.4%
add-sqr-sqrt74.4%
times-frac74.5%
hypot-def74.5%
fma-def74.5%
hypot-def88.4%
Applied egg-rr88.4%
Taylor expanded in d around -inf 60.4%
Taylor expanded in d around -inf 92.1%
Final simplification90.2%
(FPCore (a b c d)
:precision binary64
(if (or (<= c -6.8e-10)
(not
(or (<= c 3.8e-63)
(and (not (<= c 240000000000.0)) (<= c 7.2e+47)))))
(* (/ 1.0 c) (+ a (/ b (/ c d))))
(* (/ -1.0 d) (- (- b) (/ (* a c) d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6.8e-10) || !((c <= 3.8e-63) || (!(c <= 240000000000.0) && (c <= 7.2e+47)))) {
tmp = (1.0 / c) * (a + (b / (c / d)));
} else {
tmp = (-1.0 / d) * (-b - ((a * c) / d));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-6.8d-10)) .or. (.not. (c <= 3.8d-63) .or. (.not. (c <= 240000000000.0d0)) .and. (c <= 7.2d+47))) then
tmp = (1.0d0 / c) * (a + (b / (c / d)))
else
tmp = ((-1.0d0) / d) * (-b - ((a * c) / d))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6.8e-10) || !((c <= 3.8e-63) || (!(c <= 240000000000.0) && (c <= 7.2e+47)))) {
tmp = (1.0 / c) * (a + (b / (c / d)));
} else {
tmp = (-1.0 / d) * (-b - ((a * c) / d));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -6.8e-10) or not ((c <= 3.8e-63) or (not (c <= 240000000000.0) and (c <= 7.2e+47))): tmp = (1.0 / c) * (a + (b / (c / d))) else: tmp = (-1.0 / d) * (-b - ((a * c) / d)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -6.8e-10) || !((c <= 3.8e-63) || (!(c <= 240000000000.0) && (c <= 7.2e+47)))) tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d)))); else tmp = Float64(Float64(-1.0 / d) * Float64(Float64(-b) - Float64(Float64(a * c) / d))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -6.8e-10) || ~(((c <= 3.8e-63) || (~((c <= 240000000000.0)) && (c <= 7.2e+47))))) tmp = (1.0 / c) * (a + (b / (c / d))); else tmp = (-1.0 / d) * (-b - ((a * c) / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -6.8e-10], N[Not[Or[LessEqual[c, 3.8e-63], And[N[Not[LessEqual[c, 240000000000.0]], $MachinePrecision], LessEqual[c, 7.2e+47]]]], $MachinePrecision]], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 / d), $MachinePrecision] * N[((-b) - N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.8 \cdot 10^{-10} \lor \neg \left(c \leq 3.8 \cdot 10^{-63} \lor \neg \left(c \leq 240000000000\right) \land c \leq 7.2 \cdot 10^{+47}\right):\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\
\end{array}
\end{array}
if c < -6.8000000000000003e-10 or 3.80000000000000017e-63 < c < 2.4e11 or 7.20000000000000015e47 < c Initial program 56.7%
*-un-lft-identity56.7%
add-sqr-sqrt56.7%
times-frac56.6%
hypot-def56.6%
fma-def56.6%
hypot-def75.1%
Applied egg-rr75.1%
Taylor expanded in c around inf 58.1%
associate-/l*59.3%
Simplified59.3%
Taylor expanded in c around inf 86.7%
if -6.8000000000000003e-10 < c < 3.80000000000000017e-63 or 2.4e11 < c < 7.20000000000000015e47Initial program 76.0%
*-un-lft-identity76.0%
add-sqr-sqrt76.0%
times-frac76.0%
hypot-def76.0%
fma-def76.0%
hypot-def88.9%
Applied egg-rr88.9%
Taylor expanded in d around -inf 56.7%
Taylor expanded in d around -inf 84.5%
Final simplification85.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ b d) (* c (/ (/ a d) d)))))
(if (<= d -8.4e+89)
t_0
(if (<= d -7.2e+64)
(/ a c)
(if (or (<= d -85000000000000.0) (not (<= d 5.9e+26)))
t_0
(* (/ 1.0 c) (+ a (/ b (/ c d)))))))))
double code(double a, double b, double c, double d) {
double t_0 = (b / d) + (c * ((a / d) / d));
double tmp;
if (d <= -8.4e+89) {
tmp = t_0;
} else if (d <= -7.2e+64) {
tmp = a / c;
} else if ((d <= -85000000000000.0) || !(d <= 5.9e+26)) {
tmp = t_0;
} else {
tmp = (1.0 / c) * (a + (b / (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = (b / d) + (c * ((a / d) / d))
if (d <= (-8.4d+89)) then
tmp = t_0
else if (d <= (-7.2d+64)) then
tmp = a / c
else if ((d <= (-85000000000000.0d0)) .or. (.not. (d <= 5.9d+26))) then
tmp = t_0
else
tmp = (1.0d0 / c) * (a + (b / (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b / d) + (c * ((a / d) / d));
double tmp;
if (d <= -8.4e+89) {
tmp = t_0;
} else if (d <= -7.2e+64) {
tmp = a / c;
} else if ((d <= -85000000000000.0) || !(d <= 5.9e+26)) {
tmp = t_0;
} else {
tmp = (1.0 / c) * (a + (b / (c / d)));
}
return tmp;
}
def code(a, b, c, d): t_0 = (b / d) + (c * ((a / d) / d)) tmp = 0 if d <= -8.4e+89: tmp = t_0 elif d <= -7.2e+64: tmp = a / c elif (d <= -85000000000000.0) or not (d <= 5.9e+26): tmp = t_0 else: tmp = (1.0 / c) * (a + (b / (c / d))) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b / d) + Float64(c * Float64(Float64(a / d) / d))) tmp = 0.0 if (d <= -8.4e+89) tmp = t_0; elseif (d <= -7.2e+64) tmp = Float64(a / c); elseif ((d <= -85000000000000.0) || !(d <= 5.9e+26)) tmp = t_0; else tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b / d) + (c * ((a / d) / d)); tmp = 0.0; if (d <= -8.4e+89) tmp = t_0; elseif (d <= -7.2e+64) tmp = a / c; elseif ((d <= -85000000000000.0) || ~((d <= 5.9e+26))) tmp = t_0; else tmp = (1.0 / c) * (a + (b / (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(c * N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -8.4e+89], t$95$0, If[LessEqual[d, -7.2e+64], N[(a / c), $MachinePrecision], If[Or[LessEqual[d, -85000000000000.0], N[Not[LessEqual[d, 5.9e+26]], $MachinePrecision]], t$95$0, N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\
\mathbf{if}\;d \leq -8.4 \cdot 10^{+89}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq -7.2 \cdot 10^{+64}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq -85000000000000 \lor \neg \left(d \leq 5.9 \cdot 10^{+26}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\
\end{array}
\end{array}
if d < -8.39999999999999945e89 or -7.20000000000000027e64 < d < -8.5e13 or 5.9000000000000003e26 < d Initial program 58.7%
Taylor expanded in c around 0 79.0%
associate-/l*77.3%
associate-/r/80.0%
Simplified80.0%
*-un-lft-identity80.0%
pow280.0%
times-frac80.8%
Applied egg-rr80.8%
associate-*l/80.9%
*-lft-identity80.9%
Simplified80.9%
if -8.39999999999999945e89 < d < -7.20000000000000027e64Initial program 61.5%
Taylor expanded in c around inf 100.0%
if -8.5e13 < d < 5.9000000000000003e26Initial program 71.1%
*-un-lft-identity71.1%
add-sqr-sqrt71.1%
times-frac71.1%
hypot-def71.1%
fma-def71.1%
hypot-def84.6%
Applied egg-rr84.6%
Taylor expanded in c around inf 53.1%
associate-/l*52.5%
Simplified52.5%
Taylor expanded in c around inf 87.4%
Final simplification84.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* (/ 1.0 c) (+ a (/ b (/ c d))))))
(if (<= c -1e-9)
t_0
(if (<= c 3.4e-63)
(+ (/ b d) (/ (/ (* a c) d) d))
(if (or (<= c 2.6e+22) (not (<= c 7.2e+47)))
t_0
(+ (/ b d) (* c (/ (/ a d) d))))))))
double code(double a, double b, double c, double d) {
double t_0 = (1.0 / c) * (a + (b / (c / d)));
double tmp;
if (c <= -1e-9) {
tmp = t_0;
} else if (c <= 3.4e-63) {
tmp = (b / d) + (((a * c) / d) / d);
} else if ((c <= 2.6e+22) || !(c <= 7.2e+47)) {
tmp = t_0;
} else {
tmp = (b / d) + (c * ((a / 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) :: t_0
real(8) :: tmp
t_0 = (1.0d0 / c) * (a + (b / (c / d)))
if (c <= (-1d-9)) then
tmp = t_0
else if (c <= 3.4d-63) then
tmp = (b / d) + (((a * c) / d) / d)
else if ((c <= 2.6d+22) .or. (.not. (c <= 7.2d+47))) then
tmp = t_0
else
tmp = (b / d) + (c * ((a / d) / d))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (1.0 / c) * (a + (b / (c / d)));
double tmp;
if (c <= -1e-9) {
tmp = t_0;
} else if (c <= 3.4e-63) {
tmp = (b / d) + (((a * c) / d) / d);
} else if ((c <= 2.6e+22) || !(c <= 7.2e+47)) {
tmp = t_0;
} else {
tmp = (b / d) + (c * ((a / d) / d));
}
return tmp;
}
def code(a, b, c, d): t_0 = (1.0 / c) * (a + (b / (c / d))) tmp = 0 if c <= -1e-9: tmp = t_0 elif c <= 3.4e-63: tmp = (b / d) + (((a * c) / d) / d) elif (c <= 2.6e+22) or not (c <= 7.2e+47): tmp = t_0 else: tmp = (b / d) + (c * ((a / d) / d)) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d)))) tmp = 0.0 if (c <= -1e-9) tmp = t_0; elseif (c <= 3.4e-63) tmp = Float64(Float64(b / d) + Float64(Float64(Float64(a * c) / d) / d)); elseif ((c <= 2.6e+22) || !(c <= 7.2e+47)) tmp = t_0; else tmp = Float64(Float64(b / d) + Float64(c * Float64(Float64(a / d) / d))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (1.0 / c) * (a + (b / (c / d))); tmp = 0.0; if (c <= -1e-9) tmp = t_0; elseif (c <= 3.4e-63) tmp = (b / d) + (((a * c) / d) / d); elseif ((c <= 2.6e+22) || ~((c <= 7.2e+47))) tmp = t_0; else tmp = (b / d) + (c * ((a / d) / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1e-9], t$95$0, If[LessEqual[c, 3.4e-63], N[(N[(b / d), $MachinePrecision] + N[(N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[c, 2.6e+22], N[Not[LessEqual[c, 7.2e+47]], $MachinePrecision]], t$95$0, N[(N[(b / d), $MachinePrecision] + N[(c * N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\
\mathbf{if}\;c \leq -1 \cdot 10^{-9}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 3.4 \cdot 10^{-63}:\\
\;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 2.6 \cdot 10^{+22} \lor \neg \left(c \leq 7.2 \cdot 10^{+47}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\
\end{array}
\end{array}
if c < -1.00000000000000006e-9 or 3.39999999999999998e-63 < c < 2.6e22 or 7.20000000000000015e47 < c Initial program 57.9%
*-un-lft-identity57.9%
add-sqr-sqrt57.9%
times-frac57.8%
hypot-def57.8%
fma-def57.8%
hypot-def75.8%
Applied egg-rr75.8%
Taylor expanded in c around inf 57.9%
associate-/l*59.1%
Simplified59.1%
Taylor expanded in c around inf 85.7%
if -1.00000000000000006e-9 < c < 3.39999999999999998e-63Initial program 77.2%
Taylor expanded in c around 0 82.7%
associate-/l*81.0%
associate-/r/80.2%
Simplified80.2%
pow280.2%
associate-*l/82.7%
*-commutative82.7%
associate-/r*84.7%
*-commutative84.7%
Applied egg-rr84.7%
if 2.6e22 < c < 7.20000000000000015e47Initial program 43.8%
Taylor expanded in c around 0 72.7%
associate-/l*72.7%
associate-/r/72.7%
Simplified72.7%
*-un-lft-identity72.7%
pow272.7%
times-frac86.4%
Applied egg-rr86.4%
associate-*l/86.4%
*-lft-identity86.4%
Simplified86.4%
Final simplification85.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -9.8e+88) (not (<= d 4.2e+31))) (/ b d) (* (/ 1.0 c) (+ a (/ b (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9.8e+88) || !(d <= 4.2e+31)) {
tmp = b / d;
} else {
tmp = (1.0 / c) * (a + (b / (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-9.8d+88)) .or. (.not. (d <= 4.2d+31))) then
tmp = b / d
else
tmp = (1.0d0 / c) * (a + (b / (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9.8e+88) || !(d <= 4.2e+31)) {
tmp = b / d;
} else {
tmp = (1.0 / c) * (a + (b / (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -9.8e+88) or not (d <= 4.2e+31): tmp = b / d else: tmp = (1.0 / c) * (a + (b / (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -9.8e+88) || !(d <= 4.2e+31)) tmp = Float64(b / d); else tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -9.8e+88) || ~((d <= 4.2e+31))) tmp = b / d; else tmp = (1.0 / c) * (a + (b / (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9.8e+88], N[Not[LessEqual[d, 4.2e+31]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.8 \cdot 10^{+88} \lor \neg \left(d \leq 4.2 \cdot 10^{+31}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\
\end{array}
\end{array}
if d < -9.8000000000000005e88 or 4.19999999999999958e31 < d Initial program 56.3%
Taylor expanded in c around 0 76.0%
if -9.8000000000000005e88 < d < 4.19999999999999958e31Initial program 71.1%
*-un-lft-identity71.1%
add-sqr-sqrt71.1%
times-frac71.0%
hypot-def71.0%
fma-def71.0%
hypot-def84.6%
Applied egg-rr84.6%
Taylor expanded in c around inf 51.1%
associate-/l*50.5%
Simplified50.5%
Taylor expanded in c around inf 82.9%
Final simplification80.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -9e+88) (not (<= d 1.8e+31))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9e+88) || !(d <= 1.8e+31)) {
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 <= (-9d+88)) .or. (.not. (d <= 1.8d+31))) 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 <= -9e+88) || !(d <= 1.8e+31)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -9e+88) or not (d <= 1.8e+31): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -9e+88) || !(d <= 1.8e+31)) 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 <= -9e+88) || ~((d <= 1.8e+31))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9e+88], N[Not[LessEqual[d, 1.8e+31]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9 \cdot 10^{+88} \lor \neg \left(d \leq 1.8 \cdot 10^{+31}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -9e88 or 1.79999999999999998e31 < d Initial program 56.3%
Taylor expanded in c around 0 76.0%
if -9e88 < d < 1.79999999999999998e31Initial program 71.1%
Taylor expanded in c around inf 67.3%
Final simplification70.5%
(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 65.6%
Taylor expanded in c around inf 48.2%
Final simplification48.2%
(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 2023334
(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))))