
(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 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (+ b (* a (/ c d)))))
(if (<= d -1.65e+49)
(/ t_1 d)
(if (<= d -2.2e-118)
t_0
(if (<= d 1.25e-156)
(/ (+ a (* b (/ d c))) c)
(if (<= d 7e+81) t_0 (/ t_1 (hypot c d))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = b + (a * (c / d));
double tmp;
if (d <= -1.65e+49) {
tmp = t_1 / d;
} else if (d <= -2.2e-118) {
tmp = t_0;
} else if (d <= 1.25e-156) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 7e+81) {
tmp = t_0;
} else {
tmp = t_1 / hypot(c, d);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = b + (a * (c / d));
double tmp;
if (d <= -1.65e+49) {
tmp = t_1 / d;
} else if (d <= -2.2e-118) {
tmp = t_0;
} else if (d <= 1.25e-156) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 7e+81) {
tmp = t_0;
} else {
tmp = t_1 / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = b + (a * (c / d)) tmp = 0 if d <= -1.65e+49: tmp = t_1 / d elif d <= -2.2e-118: tmp = t_0 elif d <= 1.25e-156: tmp = (a + (b * (d / c))) / c elif d <= 7e+81: tmp = t_0 else: tmp = t_1 / math.hypot(c, d) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(b + Float64(a * Float64(c / d))) tmp = 0.0 if (d <= -1.65e+49) tmp = Float64(t_1 / d); elseif (d <= -2.2e-118) tmp = t_0; elseif (d <= 1.25e-156) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (d <= 7e+81) tmp = t_0; else tmp = Float64(t_1 / hypot(c, d)); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); t_1 = b + (a * (c / d)); tmp = 0.0; if (d <= -1.65e+49) tmp = t_1 / d; elseif (d <= -2.2e-118) tmp = t_0; elseif (d <= 1.25e-156) tmp = (a + (b * (d / c))) / c; elseif (d <= 7e+81) tmp = t_0; else tmp = t_1 / hypot(c, d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.65e+49], N[(t$95$1 / d), $MachinePrecision], If[LessEqual[d, -2.2e-118], t$95$0, If[LessEqual[d, 1.25e-156], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 7e+81], t$95$0, N[(t$95$1 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := b + a \cdot \frac{c}{d}\\
\mathbf{if}\;d \leq -1.65 \cdot 10^{+49}:\\
\;\;\;\;\frac{t\_1}{d}\\
\mathbf{elif}\;d \leq -2.2 \cdot 10^{-118}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.25 \cdot 10^{-156}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 7 \cdot 10^{+81}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -1.6499999999999999e49Initial program 48.2%
Taylor expanded in d around inf 88.0%
associate-/l*91.4%
Simplified91.4%
if -1.6499999999999999e49 < d < -2.19999999999999984e-118 or 1.25000000000000002e-156 < d < 7.0000000000000001e81Initial program 81.1%
if -2.19999999999999984e-118 < d < 1.25000000000000002e-156Initial program 65.9%
*-un-lft-identity65.9%
add-sqr-sqrt65.9%
times-frac65.9%
hypot-define65.9%
fma-define65.8%
hypot-define80.4%
Applied egg-rr80.4%
Taylor expanded in c around inf 92.3%
associate-/l*93.2%
Simplified93.2%
if 7.0000000000000001e81 < d Initial program 40.3%
*-un-lft-identity40.3%
add-sqr-sqrt40.3%
times-frac40.4%
hypot-define40.4%
fma-define40.4%
hypot-define59.1%
Applied egg-rr59.1%
*-commutative59.1%
associate-*l/59.0%
div-inv59.1%
fma-undefine59.0%
*-commutative59.0%
fma-define59.1%
*-commutative59.1%
Applied egg-rr59.1%
Taylor expanded in c around 0 79.5%
associate-/l*82.8%
Simplified82.8%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 1e+306) (/ (/ (fma c a (* b d)) (hypot c 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))) <= 1e+306) {
tmp = (fma(c, a, (b * d)) / hypot(c, 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))) <= 1e+306) tmp = Float64(Float64(fma(c, a, Float64(b * d)) / hypot(c, 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], 1e+306], N[(N[(N[(c * a + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $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 10^{+306}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{\mathsf{hypot}\left(c, 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))) < 1.00000000000000002e306Initial program 79.5%
*-un-lft-identity79.5%
add-sqr-sqrt79.5%
times-frac79.5%
hypot-define79.5%
fma-define79.5%
hypot-define96.2%
Applied egg-rr96.2%
*-commutative96.2%
associate-*l/96.3%
div-inv96.4%
fma-undefine96.5%
*-commutative96.5%
fma-define96.4%
*-commutative96.4%
Applied egg-rr96.4%
if 1.00000000000000002e306 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 12.4%
*-un-lft-identity12.4%
add-sqr-sqrt12.4%
times-frac12.4%
hypot-define12.4%
fma-define12.4%
hypot-define18.3%
Applied egg-rr18.3%
Taylor expanded in c around inf 51.8%
associate-/l*57.7%
Simplified57.7%
Final simplification86.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -2.05e+48)
(/ (+ b (* a (/ c d))) d)
(if (<= d -8.5e-122)
t_0
(if (<= d 2.9e-162)
(/ (+ a (* b (/ d c))) c)
(if (<= d 1.7e+79) t_0 (/ (+ b (* a (* c (/ 1.0 d)))) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -2.05e+48) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -8.5e-122) {
tmp = t_0;
} else if (d <= 2.9e-162) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 1.7e+79) {
tmp = t_0;
} else {
tmp = (b + (a * (c * (1.0 / 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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (d <= (-2.05d+48)) then
tmp = (b + (a * (c / d))) / d
else if (d <= (-8.5d-122)) then
tmp = t_0
else if (d <= 2.9d-162) then
tmp = (a + (b * (d / c))) / c
else if (d <= 1.7d+79) then
tmp = t_0
else
tmp = (b + (a * (c * (1.0d0 / d)))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -2.05e+48) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -8.5e-122) {
tmp = t_0;
} else if (d <= 2.9e-162) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 1.7e+79) {
tmp = t_0;
} else {
tmp = (b + (a * (c * (1.0 / d)))) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -2.05e+48: tmp = (b + (a * (c / d))) / d elif d <= -8.5e-122: tmp = t_0 elif d <= 2.9e-162: tmp = (a + (b * (d / c))) / c elif d <= 1.7e+79: tmp = t_0 else: tmp = (b + (a * (c * (1.0 / d)))) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (d <= -2.05e+48) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= -8.5e-122) tmp = t_0; elseif (d <= 2.9e-162) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (d <= 1.7e+79) tmp = t_0; else tmp = Float64(Float64(b + Float64(a * Float64(c * Float64(1.0 / d)))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -2.05e+48) tmp = (b + (a * (c / d))) / d; elseif (d <= -8.5e-122) tmp = t_0; elseif (d <= 2.9e-162) tmp = (a + (b * (d / c))) / c; elseif (d <= 1.7e+79) tmp = t_0; else tmp = (b + (a * (c * (1.0 / d)))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.05e+48], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -8.5e-122], t$95$0, If[LessEqual[d, 2.9e-162], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.7e+79], t$95$0, N[(N[(b + N[(a * N[(c * N[(1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -2.05 \cdot 10^{+48}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq -8.5 \cdot 10^{-122}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.9 \cdot 10^{-162}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.7 \cdot 10^{+79}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \left(c \cdot \frac{1}{d}\right)}{d}\\
\end{array}
\end{array}
if d < -2.0500000000000001e48Initial program 48.2%
Taylor expanded in d around inf 88.0%
associate-/l*91.4%
Simplified91.4%
if -2.0500000000000001e48 < d < -8.50000000000000003e-122 or 2.9000000000000001e-162 < d < 1.70000000000000016e79Initial program 81.1%
if -8.50000000000000003e-122 < d < 2.9000000000000001e-162Initial program 65.9%
*-un-lft-identity65.9%
add-sqr-sqrt65.9%
times-frac65.9%
hypot-define65.9%
fma-define65.8%
hypot-define80.4%
Applied egg-rr80.4%
Taylor expanded in c around inf 92.3%
associate-/l*93.2%
Simplified93.2%
if 1.70000000000000016e79 < d Initial program 40.3%
Taylor expanded in d around inf 79.3%
associate-/l*82.5%
Simplified82.5%
div-inv82.6%
Applied egg-rr82.6%
(FPCore (a b c d) :precision binary64 (if (or (<= c -7.5e+89) (not (<= c 3900000000000.0))) (/ (+ a (* d (/ b c))) c) (/ (+ b (* a (* c (/ 1.0 d)))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -7.5e+89) || !(c <= 3900000000000.0)) {
tmp = (a + (d * (b / c))) / c;
} else {
tmp = (b + (a * (c * (1.0 / d)))) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-7.5d+89)) .or. (.not. (c <= 3900000000000.0d0))) then
tmp = (a + (d * (b / c))) / c
else
tmp = (b + (a * (c * (1.0d0 / d)))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -7.5e+89) || !(c <= 3900000000000.0)) {
tmp = (a + (d * (b / c))) / c;
} else {
tmp = (b + (a * (c * (1.0 / d)))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -7.5e+89) or not (c <= 3900000000000.0): tmp = (a + (d * (b / c))) / c else: tmp = (b + (a * (c * (1.0 / d)))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -7.5e+89) || !(c <= 3900000000000.0)) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); else tmp = Float64(Float64(b + Float64(a * Float64(c * Float64(1.0 / d)))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -7.5e+89) || ~((c <= 3900000000000.0))) tmp = (a + (d * (b / c))) / c; else tmp = (b + (a * (c * (1.0 / d)))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -7.5e+89], N[Not[LessEqual[c, 3900000000000.0]], $MachinePrecision]], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a * N[(c * N[(1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.5 \cdot 10^{+89} \lor \neg \left(c \leq 3900000000000\right):\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \left(c \cdot \frac{1}{d}\right)}{d}\\
\end{array}
\end{array}
if c < -7.49999999999999947e89 or 3.9e12 < c Initial program 52.5%
Taylor expanded in c around inf 77.2%
*-commutative77.2%
Simplified77.2%
associate-/l*80.4%
Applied egg-rr80.4%
if -7.49999999999999947e89 < c < 3.9e12Initial program 68.2%
Taylor expanded in d around inf 82.8%
associate-/l*82.9%
Simplified82.9%
div-inv82.9%
Applied egg-rr82.9%
Final simplification81.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4e+91) (not (<= c 4000000000000.0))) (/ (+ a (* d (/ b c))) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4e+91) || !(c <= 4000000000000.0)) {
tmp = (a + (d * (b / c))) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-4d+91)) .or. (.not. (c <= 4000000000000.0d0))) then
tmp = (a + (d * (b / c))) / c
else
tmp = (b + (a * (c / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4e+91) || !(c <= 4000000000000.0)) {
tmp = (a + (d * (b / c))) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4e+91) or not (c <= 4000000000000.0): tmp = (a + (d * (b / c))) / c else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -4e+91) || !(c <= 4000000000000.0)) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -4e+91) || ~((c <= 4000000000000.0))) tmp = (a + (d * (b / c))) / c; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4e+91], N[Not[LessEqual[c, 4000000000000.0]], $MachinePrecision]], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4 \cdot 10^{+91} \lor \neg \left(c \leq 4000000000000\right):\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if c < -4.00000000000000032e91 or 4e12 < c Initial program 52.5%
Taylor expanded in c around inf 77.2%
*-commutative77.2%
Simplified77.2%
associate-/l*80.4%
Applied egg-rr80.4%
if -4.00000000000000032e91 < c < 4e12Initial program 68.2%
Taylor expanded in d around inf 82.8%
associate-/l*82.9%
Simplified82.9%
Final simplification81.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.05e+49) (not (<= d 1.6e+29))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.05e+49) || !(d <= 1.6e+29)) {
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 <= (-1.05d+49)) .or. (.not. (d <= 1.6d+29))) 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 <= -1.05e+49) || !(d <= 1.6e+29)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.05e+49) or not (d <= 1.6e+29): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.05e+49) || !(d <= 1.6e+29)) 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 <= -1.05e+49) || ~((d <= 1.6e+29))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.05e+49], N[Not[LessEqual[d, 1.6e+29]], $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 -1.05 \cdot 10^{+49} \lor \neg \left(d \leq 1.6 \cdot 10^{+29}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.05000000000000005e49 or 1.59999999999999993e29 < d Initial program 49.2%
Taylor expanded in c around 0 73.7%
if -1.05000000000000005e49 < d < 1.59999999999999993e29Initial program 72.1%
*-un-lft-identity72.1%
add-sqr-sqrt72.1%
times-frac72.2%
hypot-define72.2%
fma-define72.2%
hypot-define81.6%
Applied egg-rr81.6%
Taylor expanded in c around inf 75.7%
associate-/l*76.2%
Simplified76.2%
Final simplification75.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -9.2e+30) (not (<= d 8.4e+24))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9.2e+30) || !(d <= 8.4e+24)) {
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 <= (-9.2d+30)) .or. (.not. (d <= 8.4d+24))) 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 <= -9.2e+30) || !(d <= 8.4e+24)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -9.2e+30) or not (d <= 8.4e+24): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -9.2e+30) || !(d <= 8.4e+24)) 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 <= -9.2e+30) || ~((d <= 8.4e+24))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9.2e+30], N[Not[LessEqual[d, 8.4e+24]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.2 \cdot 10^{+30} \lor \neg \left(d \leq 8.4 \cdot 10^{+24}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -9.2e30 or 8.4000000000000005e24 < d Initial program 50.0%
Taylor expanded in c around 0 73.4%
if -9.2e30 < d < 8.4000000000000005e24Initial program 71.7%
Taylor expanded in c around inf 62.5%
Final simplification67.5%
(FPCore (a b c d) :precision binary64 (if (<= d -2e+156) (/ a d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2e+156) {
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 <= (-2d+156)) 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 <= -2e+156) {
tmp = a / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -2e+156: tmp = a / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -2e+156) 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 <= -2e+156) tmp = a / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -2e+156], N[(a / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2 \cdot 10^{+156}:\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -2e156Initial program 36.2%
*-un-lft-identity36.2%
add-sqr-sqrt36.2%
times-frac36.2%
hypot-define36.2%
fma-define36.2%
hypot-define65.7%
Applied egg-rr65.7%
Taylor expanded in c around inf 5.7%
Taylor expanded in d around inf 6.2%
Taylor expanded in a around inf 19.9%
if -2e156 < d Initial program 65.9%
Taylor expanded in c around inf 46.7%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 61.7%
Taylor expanded in c around inf 41.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 2024146
(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))))