
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (a + (b * (d / c))) / c;
}
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(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); 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[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $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{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 79.1%
*-un-lft-identity79.1%
add-sqr-sqrt79.1%
times-frac79.1%
hypot-define79.2%
fma-define79.2%
hypot-define94.9%
Applied egg-rr94.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 c around inf 43.9%
+-commutative43.9%
associate-/l*55.3%
fma-define55.3%
Simplified55.3%
fma-undefine55.3%
Applied egg-rr55.3%
Final simplification86.9%
(FPCore (a b c d)
:precision binary64
(if (<= c -2.95e+91)
(/ (+ a (* b (/ d c))) c)
(if (<= c -1850.0)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= c 2.4e-133)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 2.8e+116)
(* (/ 1.0 (hypot c d)) (/ (* d (+ b (* a (/ c d)))) (hypot c d)))
(/ (* (fma -1.0 (* (/ b c) (/ d a)) -1.0) (- a)) c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.95e+91) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -1850.0) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 2.4e-133) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 2.8e+116) {
tmp = (1.0 / hypot(c, d)) * ((d * (b + (a * (c / d)))) / hypot(c, d));
} else {
tmp = (fma(-1.0, ((b / c) * (d / a)), -1.0) * -a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -2.95e+91) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= -1850.0) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 2.4e-133) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 2.8e+116) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(Float64(d * Float64(b + Float64(a * Float64(c / d)))) / hypot(c, d))); else tmp = Float64(Float64(fma(-1.0, Float64(Float64(b / c) * Float64(d / a)), -1.0) * Float64(-a)) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.95e+91], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1850.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, 2.4e-133], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.8e+116], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(d * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-1.0 * N[(N[(b / c), $MachinePrecision] * N[(d / a), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] * (-a)), $MachinePrecision] / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.95 \cdot 10^{+91}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -1850:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{-133}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 2.8 \cdot 10^{+116}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d \cdot \left(b + a \cdot \frac{c}{d}\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-1, \frac{b}{c} \cdot \frac{d}{a}, -1\right) \cdot \left(-a\right)}{c}\\
\end{array}
\end{array}
if c < -2.9500000000000001e91Initial program 40.8%
Taylor expanded in c around inf 82.2%
+-commutative82.2%
associate-/l*89.9%
fma-define89.9%
Simplified89.9%
fma-undefine89.9%
Applied egg-rr89.9%
if -2.9500000000000001e91 < c < -1850Initial program 75.2%
if -1850 < c < 2.4e-133Initial program 73.5%
Taylor expanded in d around inf 90.0%
if 2.4e-133 < c < 2.80000000000000004e116Initial program 75.0%
*-un-lft-identity75.0%
add-sqr-sqrt75.0%
times-frac75.0%
hypot-define75.0%
fma-define75.0%
hypot-define88.1%
Applied egg-rr88.1%
Taylor expanded in d around inf 80.7%
associate-*r/78.7%
+-commutative78.7%
fma-undefine78.7%
Simplified78.7%
fma-undefine78.7%
Applied egg-rr78.7%
if 2.80000000000000004e116 < c Initial program 32.8%
Taylor expanded in c around inf 74.6%
+-commutative74.6%
associate-/l*81.1%
fma-define81.1%
Simplified81.1%
Taylor expanded in a around -inf 74.4%
mul-1-neg74.4%
distribute-rgt-neg-in74.4%
fmm-def74.4%
*-commutative74.4%
times-frac83.3%
metadata-eval83.3%
Simplified83.3%
Final simplification85.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -4.2e+91)
(/ (+ a (* b (/ d c))) c)
(if (<= c -1800.0)
t_0
(if (<= c 4.2e-130)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 1.95e+83)
t_0
(/ (* (fma -1.0 (* (/ b c) (/ d a)) -1.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+91) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -1800.0) {
tmp = t_0;
} else if (c <= 4.2e-130) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 1.95e+83) {
tmp = t_0;
} else {
tmp = (fma(-1.0, ((b / c) * (d / a)), -1.0) * -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+91) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= -1800.0) tmp = t_0; elseif (c <= 4.2e-130) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 1.95e+83) tmp = t_0; else tmp = Float64(Float64(fma(-1.0, Float64(Float64(b / c) * Float64(d / a)), -1.0) * Float64(-a)) / c); end return 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+91], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1800.0], t$95$0, If[LessEqual[c, 4.2e-130], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.95e+83], t$95$0, N[(N[(N[(-1.0 * N[(N[(b / c), $MachinePrecision] * N[(d / a), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] * (-a)), $MachinePrecision] / 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^{+91}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -1800:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4.2 \cdot 10^{-130}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.95 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-1, \frac{b}{c} \cdot \frac{d}{a}, -1\right) \cdot \left(-a\right)}{c}\\
\end{array}
\end{array}
if c < -4.20000000000000015e91Initial program 40.8%
Taylor expanded in c around inf 82.2%
+-commutative82.2%
associate-/l*89.9%
fma-define89.9%
Simplified89.9%
fma-undefine89.9%
Applied egg-rr89.9%
if -4.20000000000000015e91 < c < -1800 or 4.20000000000000004e-130 < c < 1.9500000000000001e83Initial program 80.1%
if -1800 < c < 4.20000000000000004e-130Initial program 73.5%
Taylor expanded in d around inf 90.0%
if 1.9500000000000001e83 < c Initial program 34.9%
Taylor expanded in c around inf 71.1%
+-commutative71.1%
associate-/l*76.3%
fma-define76.3%
Simplified76.3%
Taylor expanded in a around -inf 71.0%
mul-1-neg71.0%
distribute-rgt-neg-in71.0%
fmm-def71.0%
*-commutative71.0%
times-frac77.9%
metadata-eval77.9%
Simplified77.9%
Final simplification85.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (+ a (* b (/ d c)))))
(if (<= c -2.45e+91)
(/ t_1 c)
(if (<= c -2500.0)
t_0
(if (<= c 4.8e-133)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 2.2e+61) 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 * (d / c));
double tmp;
if (c <= -2.45e+91) {
tmp = t_1 / c;
} else if (c <= -2500.0) {
tmp = t_0;
} else if (c <= 4.8e-133) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 2.2e+61) {
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 * (d / c));
double tmp;
if (c <= -2.45e+91) {
tmp = t_1 / c;
} else if (c <= -2500.0) {
tmp = t_0;
} else if (c <= 4.8e-133) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 2.2e+61) {
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 * (d / c)) tmp = 0 if c <= -2.45e+91: tmp = t_1 / c elif c <= -2500.0: tmp = t_0 elif c <= 4.8e-133: tmp = (b + ((a * c) / d)) / d elif c <= 2.2e+61: 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(d / c))) tmp = 0.0 if (c <= -2.45e+91) tmp = Float64(t_1 / c); elseif (c <= -2500.0) tmp = t_0; elseif (c <= 4.8e-133) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 2.2e+61) 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 * (d / c)); tmp = 0.0; if (c <= -2.45e+91) tmp = t_1 / c; elseif (c <= -2500.0) tmp = t_0; elseif (c <= 4.8e-133) tmp = (b + ((a * c) / d)) / d; elseif (c <= 2.2e+61) 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[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.45e+91], N[(t$95$1 / c), $MachinePrecision], If[LessEqual[c, -2500.0], t$95$0, If[LessEqual[c, 4.8e-133], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.2e+61], 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 + b \cdot \frac{d}{c}\\
\mathbf{if}\;c \leq -2.45 \cdot 10^{+91}:\\
\;\;\;\;\frac{t\_1}{c}\\
\mathbf{elif}\;c \leq -2500:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4.8 \cdot 10^{-133}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 2.2 \cdot 10^{+61}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot t\_1\\
\end{array}
\end{array}
if c < -2.45000000000000015e91Initial program 40.8%
Taylor expanded in c around inf 82.2%
+-commutative82.2%
associate-/l*89.9%
fma-define89.9%
Simplified89.9%
fma-undefine89.9%
Applied egg-rr89.9%
if -2.45000000000000015e91 < c < -2500 or 4.8e-133 < c < 2.2e61Initial program 81.7%
if -2500 < c < 4.8e-133Initial program 73.5%
Taylor expanded in d around inf 90.0%
if 2.2e61 < c Initial program 37.4%
*-un-lft-identity37.4%
add-sqr-sqrt37.4%
times-frac37.4%
hypot-define37.4%
fma-define37.4%
hypot-define57.7%
Applied egg-rr57.7%
Taylor expanded in d around inf 55.9%
associate-*r/42.9%
+-commutative42.9%
fma-undefine42.9%
Simplified42.9%
fma-undefine42.9%
Applied egg-rr42.9%
Taylor expanded in d around 0 70.3%
associate-*r/75.1%
Simplified75.1%
Final simplification85.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (/ (+ a (* b (/ d c))) c)))
(if (<= c -2e+91)
t_1
(if (<= c -7500.0)
t_0
(if (<= c 4e-131)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 1.08e+83) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (a + (b * (d / c))) / c;
double tmp;
if (c <= -2e+91) {
tmp = t_1;
} else if (c <= -7500.0) {
tmp = t_0;
} else if (c <= 4e-131) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 1.08e+83) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
t_1 = (a + (b * (d / c))) / c
if (c <= (-2d+91)) then
tmp = t_1
else if (c <= (-7500.0d0)) then
tmp = t_0
else if (c <= 4d-131) then
tmp = (b + ((a * c) / d)) / d
else if (c <= 1.08d+83) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (a + (b * (d / c))) / c;
double tmp;
if (c <= -2e+91) {
tmp = t_1;
} else if (c <= -7500.0) {
tmp = t_0;
} else if (c <= 4e-131) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 1.08e+83) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = (a + (b * (d / c))) / c tmp = 0 if c <= -2e+91: tmp = t_1 elif c <= -7500.0: tmp = t_0 elif c <= 4e-131: tmp = (b + ((a * c) / d)) / d elif c <= 1.08e+83: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(a + Float64(b * Float64(d / c))) / c) tmp = 0.0 if (c <= -2e+91) tmp = t_1; elseif (c <= -7500.0) tmp = t_0; elseif (c <= 4e-131) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 1.08e+83) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); t_1 = (a + (b * (d / c))) / c; tmp = 0.0; if (c <= -2e+91) tmp = t_1; elseif (c <= -7500.0) tmp = t_0; elseif (c <= 4e-131) tmp = (b + ((a * c) / d)) / d; elseif (c <= 1.08e+83) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2e+91], t$95$1, If[LessEqual[c, -7500.0], t$95$0, If[LessEqual[c, 4e-131], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.08e+83], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{if}\;c \leq -2 \cdot 10^{+91}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -7500:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4 \cdot 10^{-131}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.08 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -2.00000000000000016e91 or 1.08e83 < c Initial program 37.5%
Taylor expanded in c around inf 76.0%
+-commutative76.0%
associate-/l*82.3%
fma-define82.3%
Simplified82.3%
fma-undefine82.3%
Applied egg-rr82.3%
if -2.00000000000000016e91 < c < -7500 or 3.9999999999999999e-131 < c < 1.08e83Initial program 80.1%
if -7500 < c < 3.9999999999999999e-131Initial program 73.5%
Taylor expanded in d around inf 90.0%
Final simplification84.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -7e+34) (not (<= d 390000000000.0))) (/ (+ b (* c (/ a d))) d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7e+34) || !(d <= 390000000000.0)) {
tmp = (b + (c * (a / 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 <= (-7d+34)) .or. (.not. (d <= 390000000000.0d0))) then
tmp = (b + (c * (a / 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 <= -7e+34) || !(d <= 390000000000.0)) {
tmp = (b + (c * (a / d))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -7e+34) or not (d <= 390000000000.0): tmp = (b + (c * (a / d))) / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -7e+34) || !(d <= 390000000000.0)) tmp = Float64(Float64(b + Float64(c * Float64(a / 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 <= -7e+34) || ~((d <= 390000000000.0))) tmp = (b + (c * (a / d))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7e+34], N[Not[LessEqual[d, 390000000000.0]], $MachinePrecision]], N[(N[(b + N[(c * N[(a / 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 -7 \cdot 10^{+34} \lor \neg \left(d \leq 390000000000\right):\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -6.99999999999999996e34 or 3.9e11 < d Initial program 51.0%
Taylor expanded in d around inf 76.8%
associate-/l*80.3%
Simplified80.3%
Taylor expanded in a around 0 76.8%
*-commutative76.8%
associate-/l*81.0%
Simplified81.0%
if -6.99999999999999996e34 < d < 3.9e11Initial program 74.8%
Taylor expanded in c around inf 79.4%
+-commutative79.4%
associate-/l*79.4%
fma-define79.4%
Simplified79.4%
fma-undefine79.4%
Applied egg-rr79.4%
Final simplification80.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.5e+35) (not (<= d 10000000000000.0))) (/ (+ b (* c (/ a d))) d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.5e+35) || !(d <= 10000000000000.0)) {
tmp = (b + (c * (a / 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 <= (-2.5d+35)) .or. (.not. (d <= 10000000000000.0d0))) then
tmp = (b + (c * (a / 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 <= -2.5e+35) || !(d <= 10000000000000.0)) {
tmp = (b + (c * (a / d))) / d;
} else {
tmp = (a + ((b * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.5e+35) or not (d <= 10000000000000.0): tmp = (b + (c * (a / d))) / d else: tmp = (a + ((b * d) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.5e+35) || !(d <= 10000000000000.0)) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); else tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.5e+35) || ~((d <= 10000000000000.0))) tmp = (b + (c * (a / d))) / d; else tmp = (a + ((b * d) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.5e+35], N[Not[LessEqual[d, 10000000000000.0]], $MachinePrecision]], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.5 \cdot 10^{+35} \lor \neg \left(d \leq 10000000000000\right):\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -2.50000000000000011e35 or 1e13 < d Initial program 51.0%
Taylor expanded in d around inf 76.8%
associate-/l*80.3%
Simplified80.3%
Taylor expanded in a around 0 76.8%
*-commutative76.8%
associate-/l*81.0%
Simplified81.0%
if -2.50000000000000011e35 < d < 1e13Initial program 74.8%
Taylor expanded in c around inf 79.4%
*-commutative79.4%
Simplified79.4%
Final simplification80.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.02e+35) (not (<= d 1.18e+14))) (/ (+ b (* a (/ c d))) d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.02e+35) || !(d <= 1.18e+14)) {
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 <= (-1.02d+35)) .or. (.not. (d <= 1.18d+14))) 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 <= -1.02e+35) || !(d <= 1.18e+14)) {
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 <= -1.02e+35) or not (d <= 1.18e+14): 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 <= -1.02e+35) || !(d <= 1.18e+14)) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.02e+35) || ~((d <= 1.18e+14))) 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, -1.02e+35], N[Not[LessEqual[d, 1.18e+14]], $MachinePrecision]], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.02 \cdot 10^{+35} \lor \neg \left(d \leq 1.18 \cdot 10^{+14}\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.02000000000000007e35 or 1.18e14 < d Initial program 51.0%
Taylor expanded in d around inf 76.8%
associate-/l*80.3%
Simplified80.3%
if -1.02000000000000007e35 < d < 1.18e14Initial program 74.8%
Taylor expanded in c around inf 79.4%
*-commutative79.4%
Simplified79.4%
Final simplification79.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2e+34) (not (<= d 1.5e+15))) (/ b d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2e+34) || !(d <= 1.5e+15)) {
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 <= (-2d+34)) .or. (.not. (d <= 1.5d+15))) 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 <= -2e+34) || !(d <= 1.5e+15)) {
tmp = b / d;
} else {
tmp = (a + ((b * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2e+34) or not (d <= 1.5e+15): tmp = b / d else: tmp = (a + ((b * d) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2e+34) || !(d <= 1.5e+15)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2e+34) || ~((d <= 1.5e+15))) tmp = b / d; else tmp = (a + ((b * d) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2e+34], N[Not[LessEqual[d, 1.5e+15]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2 \cdot 10^{+34} \lor \neg \left(d \leq 1.5 \cdot 10^{+15}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.99999999999999989e34 or 1.5e15 < d Initial program 51.0%
Taylor expanded in c around 0 64.8%
if -1.99999999999999989e34 < d < 1.5e15Initial program 74.8%
Taylor expanded in c around inf 79.4%
*-commutative79.4%
Simplified79.4%
Final simplification72.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.25e+34) (not (<= d 13500000000000.0))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.25e+34) || !(d <= 13500000000000.0)) {
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 <= (-1.25d+34)) .or. (.not. (d <= 13500000000000.0d0))) 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 <= -1.25e+34) || !(d <= 13500000000000.0)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.25e+34) or not (d <= 13500000000000.0): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.25e+34) || !(d <= 13500000000000.0)) 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 <= -1.25e+34) || ~((d <= 13500000000000.0))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.25e+34], N[Not[LessEqual[d, 13500000000000.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.25 \cdot 10^{+34} \lor \neg \left(d \leq 13500000000000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -1.25e34 or 1.35e13 < d Initial program 51.0%
Taylor expanded in c around 0 64.8%
if -1.25e34 < d < 1.35e13Initial program 74.8%
Taylor expanded in c around inf 62.9%
Final simplification63.8%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 63.1%
Taylor expanded in c around inf 39.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 2024157
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(! :herbie-platform default (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))))