
(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
(let* ((t_0 (/ 1.0 (hypot c d))))
(if (<= d -5.7e+147)
(* (/ d (hypot c d)) (/ b (hypot c d)))
(if (<= d 7.5e+110)
(* t_0 (* c (/ (fma b (/ d c) a) (hypot c d))))
(* t_0 (+ b (* a (/ c d))))))))
double code(double a, double b, double c, double d) {
double t_0 = 1.0 / hypot(c, d);
double tmp;
if (d <= -5.7e+147) {
tmp = (d / hypot(c, d)) * (b / hypot(c, d));
} else if (d <= 7.5e+110) {
tmp = t_0 * (c * (fma(b, (d / c), a) / hypot(c, d)));
} else {
tmp = t_0 * (b + (a * (c / d)));
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(1.0 / hypot(c, d)) tmp = 0.0 if (d <= -5.7e+147) tmp = Float64(Float64(d / hypot(c, d)) * Float64(b / hypot(c, d))); elseif (d <= 7.5e+110) tmp = Float64(t_0 * Float64(c * Float64(fma(b, Float64(d / c), a) / hypot(c, d)))); else tmp = Float64(t_0 * Float64(b + Float64(a * Float64(c / d)))); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.7e+147], N[(N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7.5e+110], N[(t$95$0 * N[(c * N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;d \leq -5.7 \cdot 10^{+147}:\\
\;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq 7.5 \cdot 10^{+110}:\\
\;\;\;\;t\_0 \cdot \left(c \cdot \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{\mathsf{hypot}\left(c, d\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(b + a \cdot \frac{c}{d}\right)\\
\end{array}
\end{array}
if d < -5.69999999999999991e147Initial program 25.1%
Taylor expanded in a around 0 25.1%
*-commutative25.1%
add-sqr-sqrt25.1%
hypot-undefine25.1%
hypot-undefine25.1%
times-frac97.4%
Applied egg-rr97.4%
if -5.69999999999999991e147 < d < 7.5e110Initial program 67.8%
Taylor expanded in c around inf 64.7%
associate-/l*64.2%
Simplified64.2%
*-un-lft-identity64.2%
add-sqr-sqrt64.2%
hypot-undefine64.2%
hypot-undefine64.2%
times-frac78.2%
+-commutative78.2%
fma-define78.2%
Applied egg-rr78.2%
associate-/l*95.0%
Simplified95.0%
if 7.5e110 < d Initial program 45.1%
*-un-lft-identity45.1%
associate-*r/45.1%
fma-define45.1%
add-sqr-sqrt45.1%
times-frac45.0%
fma-define45.0%
hypot-define45.0%
fma-define45.0%
fma-define45.0%
hypot-define59.8%
Applied egg-rr59.8%
Taylor expanded in c around 0 79.8%
associate-/l*91.5%
Simplified91.5%
Final simplification94.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ 1.0 (hypot c d))))
(if (<= (/ (+ (* c a) (* d b)) (+ (* c c) (* d d))) 1e+241)
(* t_0 (/ (fma a c (* d b)) (hypot c d)))
(* t_0 (* c (/ (* b (+ (/ d c) (/ a b))) (hypot c d)))))))
double code(double a, double b, double c, double d) {
double t_0 = 1.0 / hypot(c, d);
double tmp;
if ((((c * a) + (d * b)) / ((c * c) + (d * d))) <= 1e+241) {
tmp = t_0 * (fma(a, c, (d * b)) / hypot(c, d));
} else {
tmp = t_0 * (c * ((b * ((d / c) + (a / b))) / hypot(c, d)));
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(1.0 / hypot(c, d)) tmp = 0.0 if (Float64(Float64(Float64(c * a) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))) <= 1e+241) tmp = Float64(t_0 * Float64(fma(a, c, Float64(d * b)) / hypot(c, d))); else tmp = Float64(t_0 * Float64(c * Float64(Float64(b * Float64(Float64(d / c) + Float64(a / b))) / hypot(c, d)))); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+241], N[(t$95$0 * N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(c * N[(N[(b * N[(N[(d / c), $MachinePrecision] + N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;\frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d} \leq 10^{+241}:\\
\;\;\;\;t\_0 \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(c \cdot \frac{b \cdot \left(\frac{d}{c} + \frac{a}{b}\right)}{\mathsf{hypot}\left(c, d\right)}\right)\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.0000000000000001e241Initial program 74.6%
*-un-lft-identity74.6%
associate-*r/74.6%
fma-define74.6%
add-sqr-sqrt74.5%
times-frac74.5%
fma-define74.5%
hypot-define74.5%
fma-define74.5%
fma-define74.5%
hypot-define96.4%
Applied egg-rr96.4%
if 1.0000000000000001e241 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 14.2%
Taylor expanded in c around inf 14.2%
associate-/l*14.2%
Simplified14.2%
*-un-lft-identity14.2%
add-sqr-sqrt14.2%
hypot-undefine14.2%
hypot-undefine14.2%
times-frac20.4%
+-commutative20.4%
fma-define20.4%
Applied egg-rr20.4%
associate-/l*76.6%
Simplified76.6%
Taylor expanded in b around inf 59.5%
Final simplification86.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ 1.0 (hypot c d))) (t_1 (+ b (* a (/ c d)))))
(if (<= d -6.6e+121)
(/ t_1 d)
(if (<= d -2.3e-77)
(/ (+ (* c a) (* d b)) (fma c c (* d d)))
(if (<= d -9.2e-275)
(/ (+ a (* b (/ d c))) c)
(if (<= d 5.8e+110)
(* t_0 (* c (/ (* b (+ (/ d c) (/ a b))) (hypot c d))))
(* t_0 t_1)))))))
double code(double a, double b, double c, double d) {
double t_0 = 1.0 / hypot(c, d);
double t_1 = b + (a * (c / d));
double tmp;
if (d <= -6.6e+121) {
tmp = t_1 / d;
} else if (d <= -2.3e-77) {
tmp = ((c * a) + (d * b)) / fma(c, c, (d * d));
} else if (d <= -9.2e-275) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 5.8e+110) {
tmp = t_0 * (c * ((b * ((d / c) + (a / b))) / hypot(c, d)));
} else {
tmp = t_0 * t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(1.0 / hypot(c, d)) t_1 = Float64(b + Float64(a * Float64(c / d))) tmp = 0.0 if (d <= -6.6e+121) tmp = Float64(t_1 / d); elseif (d <= -2.3e-77) tmp = Float64(Float64(Float64(c * a) + Float64(d * b)) / fma(c, c, Float64(d * d))); elseif (d <= -9.2e-275) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (d <= 5.8e+110) tmp = Float64(t_0 * Float64(c * Float64(Float64(b * Float64(Float64(d / c) + Float64(a / b))) / hypot(c, d)))); else tmp = Float64(t_0 * t_1); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -6.6e+121], N[(t$95$1 / d), $MachinePrecision], If[LessEqual[d, -2.3e-77], N[(N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -9.2e-275], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.8e+110], N[(t$95$0 * N[(c * N[(N[(b * N[(N[(d / c), $MachinePrecision] + N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * t$95$1), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := b + a \cdot \frac{c}{d}\\
\mathbf{if}\;d \leq -6.6 \cdot 10^{+121}:\\
\;\;\;\;\frac{t\_1}{d}\\
\mathbf{elif}\;d \leq -2.3 \cdot 10^{-77}:\\
\;\;\;\;\frac{c \cdot a + d \cdot b}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;d \leq -9.2 \cdot 10^{-275}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 5.8 \cdot 10^{+110}:\\
\;\;\;\;t\_0 \cdot \left(c \cdot \frac{b \cdot \left(\frac{d}{c} + \frac{a}{b}\right)}{\mathsf{hypot}\left(c, d\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot t\_1\\
\end{array}
\end{array}
if d < -6.59999999999999958e121Initial program 27.1%
Taylor expanded in d around inf 90.6%
associate-/l*92.9%
Simplified92.9%
if -6.59999999999999958e121 < d < -2.29999999999999999e-77Initial program 86.0%
fma-define86.0%
fma-define86.1%
Simplified86.1%
fma-define86.1%
+-commutative86.1%
Applied egg-rr86.1%
if -2.29999999999999999e-77 < d < -9.19999999999999959e-275Initial program 63.3%
Taylor expanded in c around inf 90.4%
associate-/l*90.5%
Simplified90.5%
if -9.19999999999999959e-275 < d < 5.7999999999999999e110Initial program 63.1%
Taylor expanded in c around inf 61.0%
associate-/l*60.0%
Simplified60.0%
*-un-lft-identity60.0%
add-sqr-sqrt60.0%
hypot-undefine60.0%
hypot-undefine60.0%
times-frac76.0%
+-commutative76.0%
fma-define76.0%
Applied egg-rr76.0%
associate-/l*94.3%
Simplified94.3%
Taylor expanded in b around inf 87.8%
if 5.7999999999999999e110 < d Initial program 45.1%
*-un-lft-identity45.1%
associate-*r/45.1%
fma-define45.1%
add-sqr-sqrt45.1%
times-frac45.0%
fma-define45.0%
hypot-define45.0%
fma-define45.0%
fma-define45.0%
hypot-define59.8%
Applied egg-rr59.8%
Taylor expanded in c around 0 79.8%
associate-/l*91.5%
Simplified91.5%
Final simplification89.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* c a) (* d b)) (+ (* c c) (* d d))))
(t_1 (+ b (* a (/ c d)))))
(if (<= d -1.1e+123)
(/ t_1 d)
(if (<= d -3.3e-80)
t_0
(if (<= d 9e-118)
(/ (+ a (* b (/ d c))) c)
(if (<= d 1.5e+79) t_0 (* (/ 1.0 (hypot c d)) t_1)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d));
double t_1 = b + (a * (c / d));
double tmp;
if (d <= -1.1e+123) {
tmp = t_1 / d;
} else if (d <= -3.3e-80) {
tmp = t_0;
} else if (d <= 9e-118) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 1.5e+79) {
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 = ((c * a) + (d * b)) / ((c * c) + (d * d));
double t_1 = b + (a * (c / d));
double tmp;
if (d <= -1.1e+123) {
tmp = t_1 / d;
} else if (d <= -3.3e-80) {
tmp = t_0;
} else if (d <= 9e-118) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 1.5e+79) {
tmp = t_0;
} else {
tmp = (1.0 / Math.hypot(c, d)) * t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d)) t_1 = b + (a * (c / d)) tmp = 0 if d <= -1.1e+123: tmp = t_1 / d elif d <= -3.3e-80: tmp = t_0 elif d <= 9e-118: tmp = (a + (b * (d / c))) / c elif d <= 1.5e+79: 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(c * a) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(b + Float64(a * Float64(c / d))) tmp = 0.0 if (d <= -1.1e+123) tmp = Float64(t_1 / d); elseif (d <= -3.3e-80) tmp = t_0; elseif (d <= 9e-118) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (d <= 1.5e+79) 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 = ((c * a) + (d * b)) / ((c * c) + (d * d)); t_1 = b + (a * (c / d)); tmp = 0.0; if (d <= -1.1e+123) tmp = t_1 / d; elseif (d <= -3.3e-80) tmp = t_0; elseif (d <= 9e-118) tmp = (a + (b * (d / c))) / c; elseif (d <= 1.5e+79) 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[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.1e+123], N[(t$95$1 / d), $MachinePrecision], If[LessEqual[d, -3.3e-80], t$95$0, If[LessEqual[d, 9e-118], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.5e+79], 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{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\
t_1 := b + a \cdot \frac{c}{d}\\
\mathbf{if}\;d \leq -1.1 \cdot 10^{+123}:\\
\;\;\;\;\frac{t\_1}{d}\\
\mathbf{elif}\;d \leq -3.3 \cdot 10^{-80}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 9 \cdot 10^{-118}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.5 \cdot 10^{+79}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot t\_1\\
\end{array}
\end{array}
if d < -1.09999999999999996e123Initial program 27.1%
Taylor expanded in d around inf 90.6%
associate-/l*92.9%
Simplified92.9%
if -1.09999999999999996e123 < d < -3.3e-80 or 9.0000000000000001e-118 < d < 1.49999999999999987e79Initial program 83.9%
if -3.3e-80 < d < 9.0000000000000001e-118Initial program 58.4%
Taylor expanded in c around inf 88.8%
associate-/l*89.1%
Simplified89.1%
if 1.49999999999999987e79 < d Initial program 47.2%
*-un-lft-identity47.2%
associate-*r/47.2%
fma-define47.2%
add-sqr-sqrt47.2%
times-frac47.2%
fma-define47.2%
hypot-define47.2%
fma-define47.2%
fma-define47.2%
hypot-define59.6%
Applied egg-rr59.6%
Taylor expanded in c around 0 76.4%
associate-/l*86.1%
Simplified86.1%
Final simplification87.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (* c a) (* d b))) (t_1 (+ b (* a (/ c d)))))
(if (<= d -1.3e+122)
(/ t_1 d)
(if (<= d -2.9e-72)
(/ t_0 (fma c c (* d d)))
(if (<= d 3.5e-117)
(/ (+ a (* b (/ d c))) c)
(if (<= d 5e+81)
(/ t_0 (+ (* c c) (* d d)))
(* (/ 1.0 (hypot c d)) t_1)))))))
double code(double a, double b, double c, double d) {
double t_0 = (c * a) + (d * b);
double t_1 = b + (a * (c / d));
double tmp;
if (d <= -1.3e+122) {
tmp = t_1 / d;
} else if (d <= -2.9e-72) {
tmp = t_0 / fma(c, c, (d * d));
} else if (d <= 3.5e-117) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 5e+81) {
tmp = t_0 / ((c * c) + (d * d));
} else {
tmp = (1.0 / hypot(c, d)) * t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(c * a) + Float64(d * b)) t_1 = Float64(b + Float64(a * Float64(c / d))) tmp = 0.0 if (d <= -1.3e+122) tmp = Float64(t_1 / d); elseif (d <= -2.9e-72) tmp = Float64(t_0 / fma(c, c, Float64(d * d))); elseif (d <= 3.5e-117) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (d <= 5e+81) tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(Float64(1.0 / hypot(c, d)) * t_1); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.3e+122], N[(t$95$1 / d), $MachinePrecision], If[LessEqual[d, -2.9e-72], N[(t$95$0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.5e-117], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5e+81], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot a + d \cdot b\\
t_1 := b + a \cdot \frac{c}{d}\\
\mathbf{if}\;d \leq -1.3 \cdot 10^{+122}:\\
\;\;\;\;\frac{t\_1}{d}\\
\mathbf{elif}\;d \leq -2.9 \cdot 10^{-72}:\\
\;\;\;\;\frac{t\_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;d \leq 3.5 \cdot 10^{-117}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 5 \cdot 10^{+81}:\\
\;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot t\_1\\
\end{array}
\end{array}
if d < -1.30000000000000004e122Initial program 27.1%
Taylor expanded in d around inf 90.6%
associate-/l*92.9%
Simplified92.9%
if -1.30000000000000004e122 < d < -2.89999999999999998e-72Initial program 86.0%
fma-define86.0%
fma-define86.1%
Simplified86.1%
fma-define86.1%
+-commutative86.1%
Applied egg-rr86.1%
if -2.89999999999999998e-72 < d < 3.4999999999999998e-117Initial program 58.4%
Taylor expanded in c around inf 88.8%
associate-/l*89.1%
Simplified89.1%
if 3.4999999999999998e-117 < d < 4.9999999999999998e81Initial program 80.8%
if 4.9999999999999998e81 < d Initial program 47.2%
*-un-lft-identity47.2%
associate-*r/47.2%
fma-define47.2%
add-sqr-sqrt47.2%
times-frac47.2%
fma-define47.2%
hypot-define47.2%
fma-define47.2%
fma-define47.2%
hypot-define59.6%
Applied egg-rr59.6%
Taylor expanded in c around 0 76.4%
associate-/l*86.1%
Simplified86.1%
Final simplification87.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* c a) (* d b)) (+ (* c c) (* d d))))
(t_1 (/ (+ b (* a (/ c d))) d)))
(if (<= d -1.85e+124)
t_1
(if (<= d -1.9e-75)
t_0
(if (<= d 2.4e-117)
(/ (+ a (* b (/ d c))) c)
(if (<= d 2.9e+74) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d));
double t_1 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -1.85e+124) {
tmp = t_1;
} else if (d <= -1.9e-75) {
tmp = t_0;
} else if (d <= 2.4e-117) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 2.9e+74) {
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 = ((c * a) + (d * b)) / ((c * c) + (d * d))
t_1 = (b + (a * (c / d))) / d
if (d <= (-1.85d+124)) then
tmp = t_1
else if (d <= (-1.9d-75)) then
tmp = t_0
else if (d <= 2.4d-117) then
tmp = (a + (b * (d / c))) / c
else if (d <= 2.9d+74) 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 = ((c * a) + (d * b)) / ((c * c) + (d * d));
double t_1 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -1.85e+124) {
tmp = t_1;
} else if (d <= -1.9e-75) {
tmp = t_0;
} else if (d <= 2.4e-117) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 2.9e+74) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d)) t_1 = (b + (a * (c / d))) / d tmp = 0 if d <= -1.85e+124: tmp = t_1 elif d <= -1.9e-75: tmp = t_0 elif d <= 2.4e-117: tmp = (a + (b * (d / c))) / c elif d <= 2.9e+74: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * a) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(b + Float64(a * Float64(c / d))) / d) tmp = 0.0 if (d <= -1.85e+124) tmp = t_1; elseif (d <= -1.9e-75) tmp = t_0; elseif (d <= 2.4e-117) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (d <= 2.9e+74) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d)); t_1 = (b + (a * (c / d))) / d; tmp = 0.0; if (d <= -1.85e+124) tmp = t_1; elseif (d <= -1.9e-75) tmp = t_0; elseif (d <= 2.4e-117) tmp = (a + (b * (d / c))) / c; elseif (d <= 2.9e+74) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.85e+124], t$95$1, If[LessEqual[d, -1.9e-75], t$95$0, If[LessEqual[d, 2.4e-117], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.9e+74], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\
t_1 := \frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{if}\;d \leq -1.85 \cdot 10^{+124}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -1.9 \cdot 10^{-75}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.4 \cdot 10^{-117}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.9 \cdot 10^{+74}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.85000000000000004e124 or 2.9000000000000002e74 < d Initial program 37.1%
Taylor expanded in d around inf 83.5%
associate-/l*89.4%
Simplified89.4%
if -1.85000000000000004e124 < d < -1.89999999999999997e-75 or 2.40000000000000014e-117 < d < 2.9000000000000002e74Initial program 83.9%
if -1.89999999999999997e-75 < d < 2.40000000000000014e-117Initial program 58.4%
Taylor expanded in c around inf 88.8%
associate-/l*89.1%
Simplified89.1%
Final simplification87.7%
(FPCore (a b c d)
:precision binary64
(if (<= d -5.7e-52)
(/ b d)
(if (<= d -2.1e-308)
(/ a c)
(if (<= d 4.4e-274)
(/ (* b (/ d c)) c)
(if (<= d 1.25e-9) (/ a c) (/ b d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -5.7e-52) {
tmp = b / d;
} else if (d <= -2.1e-308) {
tmp = a / c;
} else if (d <= 4.4e-274) {
tmp = (b * (d / c)) / c;
} else if (d <= 1.25e-9) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-5.7d-52)) then
tmp = b / d
else if (d <= (-2.1d-308)) then
tmp = a / c
else if (d <= 4.4d-274) then
tmp = (b * (d / c)) / c
else if (d <= 1.25d-9) then
tmp = a / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -5.7e-52) {
tmp = b / d;
} else if (d <= -2.1e-308) {
tmp = a / c;
} else if (d <= 4.4e-274) {
tmp = (b * (d / c)) / c;
} else if (d <= 1.25e-9) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -5.7e-52: tmp = b / d elif d <= -2.1e-308: tmp = a / c elif d <= 4.4e-274: tmp = (b * (d / c)) / c elif d <= 1.25e-9: tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -5.7e-52) tmp = Float64(b / d); elseif (d <= -2.1e-308) tmp = Float64(a / c); elseif (d <= 4.4e-274) tmp = Float64(Float64(b * Float64(d / c)) / c); elseif (d <= 1.25e-9) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -5.7e-52) tmp = b / d; elseif (d <= -2.1e-308) tmp = a / c; elseif (d <= 4.4e-274) tmp = (b * (d / c)) / c; elseif (d <= 1.25e-9) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -5.7e-52], N[(b / d), $MachinePrecision], If[LessEqual[d, -2.1e-308], N[(a / c), $MachinePrecision], If[LessEqual[d, 4.4e-274], N[(N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.25e-9], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.7 \cdot 10^{-52}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -2.1 \cdot 10^{-308}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 4.4 \cdot 10^{-274}:\\
\;\;\;\;\frac{b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.25 \cdot 10^{-9}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -5.6999999999999997e-52 or 1.25e-9 < d Initial program 54.4%
Taylor expanded in c around 0 62.1%
if -5.6999999999999997e-52 < d < -2.1e-308 or 4.3999999999999999e-274 < d < 1.25e-9Initial program 63.4%
Taylor expanded in c around inf 71.2%
if -2.1e-308 < d < 4.3999999999999999e-274Initial program 59.7%
Taylor expanded in c around inf 61.0%
Taylor expanded in a around 0 60.4%
associate-*r/82.4%
Simplified82.4%
Final simplification66.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5e+63) (not (<= d 1.1e+18))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5e+63) || !(d <= 1.1e+18)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-5d+63)) .or. (.not. (d <= 1.1d+18))) then
tmp = b / d
else
tmp = (a + (b * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5e+63) || !(d <= 1.1e+18)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5e+63) or not (d <= 1.1e+18): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5e+63) || !(d <= 1.1e+18)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -5e+63) || ~((d <= 1.1e+18))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5e+63], N[Not[LessEqual[d, 1.1e+18]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5 \cdot 10^{+63} \lor \neg \left(d \leq 1.1 \cdot 10^{+18}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -5.00000000000000011e63 or 1.1e18 < d Initial program 47.1%
Taylor expanded in c around 0 69.7%
if -5.00000000000000011e63 < d < 1.1e18Initial program 66.6%
Taylor expanded in c around inf 78.9%
associate-/l*79.1%
Simplified79.1%
Final simplification75.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5.5e-17) (not (<= d 9.5e+17))) (/ (+ b (* a (/ c d))) d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5.5e-17) || !(d <= 9.5e+17)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-5.5d-17)) .or. (.not. (d <= 9.5d+17))) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a + (b * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5.5e-17) || !(d <= 9.5e+17)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5.5e-17) or not (d <= 9.5e+17): tmp = (b + (a * (c / d))) / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5.5e-17) || !(d <= 9.5e+17)) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -5.5e-17) || ~((d <= 9.5e+17))) tmp = (b + (a * (c / d))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5.5e-17], N[Not[LessEqual[d, 9.5e+17]], $MachinePrecision]], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.5 \cdot 10^{-17} \lor \neg \left(d \leq 9.5 \cdot 10^{+17}\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -5.50000000000000001e-17 or 9.5e17 < d Initial program 51.0%
Taylor expanded in d around inf 76.9%
associate-/l*81.0%
Simplified81.0%
if -5.50000000000000001e-17 < d < 9.5e17Initial program 65.5%
Taylor expanded in c around inf 82.9%
associate-/l*83.2%
Simplified83.2%
Final simplification82.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.92e+152) (not (<= d 3e+213))) (/ a d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.92e+152) || !(d <= 3e+213)) {
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 <= (-1.92d+152)) .or. (.not. (d <= 3d+213))) 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 <= -1.92e+152) || !(d <= 3e+213)) {
tmp = a / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.92e+152) or not (d <= 3e+213): tmp = a / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.92e+152) || !(d <= 3e+213)) 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 <= -1.92e+152) || ~((d <= 3e+213))) tmp = a / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.92e+152], N[Not[LessEqual[d, 3e+213]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.92 \cdot 10^{+152} \lor \neg \left(d \leq 3 \cdot 10^{+213}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -1.92000000000000008e152 or 3.0000000000000001e213 < d Initial program 34.9%
*-un-lft-identity34.9%
associate-*r/34.9%
fma-define34.9%
add-sqr-sqrt34.9%
times-frac34.9%
fma-define34.9%
hypot-define34.9%
fma-define34.9%
fma-define34.9%
hypot-define66.2%
Applied egg-rr66.2%
Taylor expanded in c around 0 42.5%
associate-/l*46.3%
Simplified46.3%
Taylor expanded in c around inf 21.9%
if -1.92000000000000008e152 < d < 3.0000000000000001e213Initial program 64.8%
Taylor expanded in c around inf 49.6%
Final simplification44.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5.7e-52) (not (<= d 1.25e-10))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5.7e-52) || !(d <= 1.25e-10)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-5.7d-52)) .or. (.not. (d <= 1.25d-10))) then
tmp = b / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5.7e-52) || !(d <= 1.25e-10)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5.7e-52) or not (d <= 1.25e-10): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5.7e-52) || !(d <= 1.25e-10)) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -5.7e-52) || ~((d <= 1.25e-10))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5.7e-52], N[Not[LessEqual[d, 1.25e-10]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.7 \cdot 10^{-52} \lor \neg \left(d \leq 1.25 \cdot 10^{-10}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -5.6999999999999997e-52 or 1.25000000000000008e-10 < d Initial program 54.4%
Taylor expanded in c around 0 62.1%
if -5.6999999999999997e-52 < d < 1.25000000000000008e-10Initial program 63.3%
Taylor expanded in c around inf 68.5%
Final simplification65.2%
(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 58.8%
Taylor expanded in c around inf 40.6%
Final simplification40.6%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024067
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))