
(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)))))
(if (<= t_0 -5e+300)
(+ (/ b d) (* (/ c d) (/ a d)))
(if (<= t_0 INFINITY)
(/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d))
(+ (/ a c) (* (/ d c) (/ b 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 (t_0 <= -5e+300) {
tmp = (b / d) + ((c / d) * (a / d));
} else if (t_0 <= ((double) INFINITY)) {
tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = (a / c) + ((d / c) * (b / 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 (t_0 <= -5e+300) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); elseif (t_0 <= Inf) tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / 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[t$95$0, -5e+300], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, Infinity], N[(N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{+300}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{elif}\;t_0 \leq \infty:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < -5.00000000000000026e300Initial program 54.3%
Taylor expanded in c around 0 71.9%
unpow271.9%
times-frac86.2%
Simplified86.2%
if -5.00000000000000026e300 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 77.9%
*-un-lft-identity77.9%
add-sqr-sqrt77.9%
times-frac77.8%
hypot-def77.8%
fma-def77.8%
hypot-def95.0%
Applied egg-rr95.0%
associate-*l/95.3%
*-un-lft-identity95.3%
Applied egg-rr95.3%
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 46.3%
unpow246.3%
times-frac58.2%
Simplified58.2%
Final simplification88.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -2.9e+68)
(/ (- (- b) (/ c (/ d a))) (hypot c d))
(if (<= d -1.1e-129)
t_0
(if (<= d 3.7e-87)
(+ (/ a c) (/ 1.0 (* (/ c d) (/ c b))))
(if (<= d 8.4e+43) t_0 (+ (/ b d) (* (/ c d) (/ a 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.9e+68) {
tmp = (-b - (c / (d / a))) / hypot(c, d);
} else if (d <= -1.1e-129) {
tmp = t_0;
} else if (d <= 3.7e-87) {
tmp = (a / c) + (1.0 / ((c / d) * (c / b)));
} else if (d <= 8.4e+43) {
tmp = t_0;
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -2.9e+68) {
tmp = (-b - (c / (d / a))) / Math.hypot(c, d);
} else if (d <= -1.1e-129) {
tmp = t_0;
} else if (d <= 3.7e-87) {
tmp = (a / c) + (1.0 / ((c / d) * (c / b)));
} else if (d <= 8.4e+43) {
tmp = t_0;
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -2.9e+68: tmp = (-b - (c / (d / a))) / math.hypot(c, d) elif d <= -1.1e-129: tmp = t_0 elif d <= 3.7e-87: tmp = (a / c) + (1.0 / ((c / d) * (c / b))) elif d <= 8.4e+43: tmp = t_0 else: tmp = (b / d) + ((c / d) * (a / 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.9e+68) tmp = Float64(Float64(Float64(-b) - Float64(c / Float64(d / a))) / hypot(c, d)); elseif (d <= -1.1e-129) tmp = t_0; elseif (d <= 3.7e-87) tmp = Float64(Float64(a / c) + Float64(1.0 / Float64(Float64(c / d) * Float64(c / b)))); elseif (d <= 8.4e+43) tmp = t_0; else tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / 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.9e+68) tmp = (-b - (c / (d / a))) / hypot(c, d); elseif (d <= -1.1e-129) tmp = t_0; elseif (d <= 3.7e-87) tmp = (a / c) + (1.0 / ((c / d) * (c / b))); elseif (d <= 8.4e+43) tmp = t_0; else tmp = (b / d) + ((c / d) * (a / 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.9e+68], N[(N[((-b) - N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.1e-129], t$95$0, If[LessEqual[d, 3.7e-87], N[(N[(a / c), $MachinePrecision] + N[(1.0 / N[(N[(c / d), $MachinePrecision] * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 8.4e+43], t$95$0, N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -2.9 \cdot 10^{+68}:\\
\;\;\;\;\frac{\left(-b\right) - \frac{c}{\frac{d}{a}}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq -1.1 \cdot 10^{-129}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 3.7 \cdot 10^{-87}:\\
\;\;\;\;\frac{a}{c} + \frac{1}{\frac{c}{d} \cdot \frac{c}{b}}\\
\mathbf{elif}\;d \leq 8.4 \cdot 10^{+43}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\end{array}
\end{array}
if d < -2.90000000000000011e68Initial program 26.8%
*-un-lft-identity26.8%
add-sqr-sqrt26.8%
times-frac26.8%
hypot-def26.8%
fma-def26.8%
hypot-def50.3%
Applied egg-rr50.3%
associate-*l/50.4%
*-un-lft-identity50.4%
Applied egg-rr50.4%
Taylor expanded in d around -inf 72.5%
distribute-lft-out72.5%
associate-/l*79.3%
Simplified79.3%
if -2.90000000000000011e68 < d < -1.10000000000000001e-129 or 3.7000000000000002e-87 < d < 8.40000000000000007e43Initial program 85.7%
if -1.10000000000000001e-129 < d < 3.7000000000000002e-87Initial program 69.5%
Taylor expanded in c around inf 86.6%
unpow286.6%
times-frac87.1%
Simplified87.1%
clear-num87.0%
clear-num87.1%
frac-times88.4%
metadata-eval88.4%
Applied egg-rr88.4%
if 8.40000000000000007e43 < d Initial program 46.3%
Taylor expanded in c around 0 80.5%
unpow280.5%
times-frac86.3%
Simplified86.3%
Final simplification85.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ b d) (* (/ c d) (/ a d))))
(t_1 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -4e+48)
(+ (/ a c) (/ (* d (/ b c)) c))
(if (<= c -82.0)
t_0
(if (<= c -1.8e-151)
t_1
(if (<= c 3.6e-164)
t_0
(if (<= c 1.9e+56)
t_1
(+ (/ a c) (/ 1.0 (* (/ c d) (/ c b)))))))))))
double code(double a, double b, double c, double d) {
double t_0 = (b / d) + ((c / d) * (a / d));
double t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -4e+48) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= -82.0) {
tmp = t_0;
} else if (c <= -1.8e-151) {
tmp = t_1;
} else if (c <= 3.6e-164) {
tmp = t_0;
} else if (c <= 1.9e+56) {
tmp = t_1;
} else {
tmp = (a / c) + (1.0 / ((c / d) * (c / b)));
}
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 = (b / d) + ((c / d) * (a / d))
t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (c <= (-4d+48)) then
tmp = (a / c) + ((d * (b / c)) / c)
else if (c <= (-82.0d0)) then
tmp = t_0
else if (c <= (-1.8d-151)) then
tmp = t_1
else if (c <= 3.6d-164) then
tmp = t_0
else if (c <= 1.9d+56) then
tmp = t_1
else
tmp = (a / c) + (1.0d0 / ((c / d) * (c / b)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b / d) + ((c / d) * (a / d));
double t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -4e+48) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= -82.0) {
tmp = t_0;
} else if (c <= -1.8e-151) {
tmp = t_1;
} else if (c <= 3.6e-164) {
tmp = t_0;
} else if (c <= 1.9e+56) {
tmp = t_1;
} else {
tmp = (a / c) + (1.0 / ((c / d) * (c / b)));
}
return tmp;
}
def code(a, b, c, d): t_0 = (b / d) + ((c / d) * (a / d)) t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -4e+48: tmp = (a / c) + ((d * (b / c)) / c) elif c <= -82.0: tmp = t_0 elif c <= -1.8e-151: tmp = t_1 elif c <= 3.6e-164: tmp = t_0 elif c <= 1.9e+56: tmp = t_1 else: tmp = (a / c) + (1.0 / ((c / d) * (c / b))) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))) t_1 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (c <= -4e+48) tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); elseif (c <= -82.0) tmp = t_0; elseif (c <= -1.8e-151) tmp = t_1; elseif (c <= 3.6e-164) tmp = t_0; elseif (c <= 1.9e+56) tmp = t_1; else tmp = Float64(Float64(a / c) + Float64(1.0 / Float64(Float64(c / d) * Float64(c / b)))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b / d) + ((c / d) * (a / d)); t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -4e+48) tmp = (a / c) + ((d * (b / c)) / c); elseif (c <= -82.0) tmp = t_0; elseif (c <= -1.8e-151) tmp = t_1; elseif (c <= 3.6e-164) tmp = t_0; elseif (c <= 1.9e+56) tmp = t_1; else tmp = (a / c) + (1.0 / ((c / d) * (c / b))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = 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, -4e+48], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -82.0], t$95$0, If[LessEqual[c, -1.8e-151], t$95$1, If[LessEqual[c, 3.6e-164], t$95$0, If[LessEqual[c, 1.9e+56], t$95$1, N[(N[(a / c), $MachinePrecision] + N[(1.0 / N[(N[(c / d), $MachinePrecision] * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
t_1 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -4 \cdot 10^{+48}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq -82:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq -1.8 \cdot 10^{-151}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq 3.6 \cdot 10^{-164}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{+56}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{1}{\frac{c}{d} \cdot \frac{c}{b}}\\
\end{array}
\end{array}
if c < -4.00000000000000018e48Initial program 40.8%
Taylor expanded in c around inf 79.6%
unpow279.6%
times-frac88.5%
Simplified88.5%
associate-*l/90.0%
Applied egg-rr90.0%
if -4.00000000000000018e48 < c < -82 or -1.80000000000000016e-151 < c < 3.59999999999999994e-164Initial program 62.2%
Taylor expanded in c around 0 81.1%
unpow281.1%
times-frac88.0%
Simplified88.0%
if -82 < c < -1.80000000000000016e-151 or 3.59999999999999994e-164 < c < 1.89999999999999998e56Initial program 84.7%
if 1.89999999999999998e56 < c Initial program 50.7%
Taylor expanded in c around inf 82.8%
unpow282.8%
times-frac85.1%
Simplified85.1%
clear-num85.1%
clear-num85.2%
frac-times85.2%
metadata-eval85.2%
Applied egg-rr85.2%
Final simplification86.9%
(FPCore (a b c d)
:precision binary64
(if (<= c -4e+48)
(+ (/ a c) (/ (* d (/ b c)) c))
(if (<= c 10.0)
(+ (/ b d) (* (/ c d) (/ a d)))
(+ (/ a c) (/ 1.0 (* (/ c d) (/ c b)))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4e+48) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= 10.0) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (a / c) + (1.0 / ((c / d) * (c / b)));
}
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+48)) then
tmp = (a / c) + ((d * (b / c)) / c)
else if (c <= 10.0d0) then
tmp = (b / d) + ((c / d) * (a / d))
else
tmp = (a / c) + (1.0d0 / ((c / d) * (c / b)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4e+48) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= 10.0) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (a / c) + (1.0 / ((c / d) * (c / b)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -4e+48: tmp = (a / c) + ((d * (b / c)) / c) elif c <= 10.0: tmp = (b / d) + ((c / d) * (a / d)) else: tmp = (a / c) + (1.0 / ((c / d) * (c / b))) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -4e+48) tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); elseif (c <= 10.0) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); else tmp = Float64(Float64(a / c) + Float64(1.0 / Float64(Float64(c / d) * Float64(c / b)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -4e+48) tmp = (a / c) + ((d * (b / c)) / c); elseif (c <= 10.0) tmp = (b / d) + ((c / d) * (a / d)); else tmp = (a / c) + (1.0 / ((c / d) * (c / b))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -4e+48], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 10.0], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(1.0 / N[(N[(c / d), $MachinePrecision] * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4 \cdot 10^{+48}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq 10:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{1}{\frac{c}{d} \cdot \frac{c}{b}}\\
\end{array}
\end{array}
if c < -4.00000000000000018e48Initial program 40.8%
Taylor expanded in c around inf 79.6%
unpow279.6%
times-frac88.5%
Simplified88.5%
associate-*l/90.0%
Applied egg-rr90.0%
if -4.00000000000000018e48 < c < 10Initial program 74.5%
Taylor expanded in c around 0 76.6%
unpow276.6%
times-frac80.3%
Simplified80.3%
if 10 < c Initial program 56.9%
Taylor expanded in c around inf 75.3%
unpow275.3%
times-frac76.9%
Simplified76.9%
clear-num76.9%
clear-num77.0%
frac-times77.0%
metadata-eval77.0%
Applied egg-rr77.0%
Final simplification81.7%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3.3e+43) (not (<= c 2.7e-28))) (+ (/ a c) (* (/ d c) (/ b c))) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.3e+43) || !(c <= 2.7e-28)) {
tmp = (a / c) + ((d / c) * (b / 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 ((c <= (-3.3d+43)) .or. (.not. (c <= 2.7d-28))) then
tmp = (a / c) + ((d / c) * (b / 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 ((c <= -3.3e+43) || !(c <= 2.7e-28)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3.3e+43) or not (c <= 2.7e-28): tmp = (a / c) + ((d / c) * (b / c)) else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.3e+43) || !(c <= 2.7e-28)) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -3.3e+43) || ~((c <= 2.7e-28))) tmp = (a / c) + ((d / c) * (b / c)); else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.3e+43], N[Not[LessEqual[c, 2.7e-28]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.3 \cdot 10^{+43} \lor \neg \left(c \leq 2.7 \cdot 10^{-28}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -3.3000000000000001e43 or 2.6999999999999999e-28 < c Initial program 50.9%
Taylor expanded in c around inf 74.0%
unpow274.0%
times-frac78.8%
Simplified78.8%
if -3.3000000000000001e43 < c < 2.6999999999999999e-28Initial program 74.8%
Taylor expanded in c around 0 71.3%
Final simplification75.1%
(FPCore (a b c d) :precision binary64 (if (<= c -3.1e+43) (+ (/ a c) (/ (* d (/ b c)) c)) (if (<= c 2.8e-32) (/ b d) (+ (/ a c) (* (/ d c) (/ b c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.1e+43) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= 2.8e-32) {
tmp = b / d;
} else {
tmp = (a / c) + ((d / c) * (b / 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 (c <= (-3.1d+43)) then
tmp = (a / c) + ((d * (b / c)) / c)
else if (c <= 2.8d-32) then
tmp = b / d
else
tmp = (a / c) + ((d / c) * (b / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.1e+43) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= 2.8e-32) {
tmp = b / d;
} else {
tmp = (a / c) + ((d / c) * (b / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3.1e+43: tmp = (a / c) + ((d * (b / c)) / c) elif c <= 2.8e-32: tmp = b / d else: tmp = (a / c) + ((d / c) * (b / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3.1e+43) tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); elseif (c <= 2.8e-32) tmp = Float64(b / d); else tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -3.1e+43) tmp = (a / c) + ((d * (b / c)) / c); elseif (c <= 2.8e-32) tmp = b / d; else tmp = (a / c) + ((d / c) * (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.1e+43], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.8e-32], N[(b / d), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.1 \cdot 10^{+43}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq 2.8 \cdot 10^{-32}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\end{array}
\end{array}
if c < -3.1000000000000002e43Initial program 41.6%
Taylor expanded in c around inf 76.2%
unpow276.2%
times-frac84.6%
Simplified84.6%
associate-*l/86.0%
Applied egg-rr86.0%
if -3.1000000000000002e43 < c < 2.7999999999999999e-32Initial program 74.8%
Taylor expanded in c around 0 71.3%
if 2.7999999999999999e-32 < c Initial program 59.3%
Taylor expanded in c around inf 72.1%
unpow272.1%
times-frac73.6%
Simplified73.6%
Final simplification75.5%
(FPCore (a b c d)
:precision binary64
(if (<= c -6.5e+50)
(+ (/ a c) (/ (* d (/ b c)) c))
(if (<= c 9.5)
(+ (/ b d) (* (/ c d) (/ a d)))
(+ (/ a c) (* (/ d c) (/ b c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.5e+50) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= 9.5) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (a / c) + ((d / c) * (b / 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 (c <= (-6.5d+50)) then
tmp = (a / c) + ((d * (b / c)) / c)
else if (c <= 9.5d0) then
tmp = (b / d) + ((c / d) * (a / d))
else
tmp = (a / c) + ((d / c) * (b / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.5e+50) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= 9.5) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (a / c) + ((d / c) * (b / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -6.5e+50: tmp = (a / c) + ((d * (b / c)) / c) elif c <= 9.5: tmp = (b / d) + ((c / d) * (a / d)) else: tmp = (a / c) + ((d / c) * (b / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -6.5e+50) tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); elseif (c <= 9.5) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); else tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -6.5e+50) tmp = (a / c) + ((d * (b / c)) / c); elseif (c <= 9.5) tmp = (b / d) + ((c / d) * (a / d)); else tmp = (a / c) + ((d / c) * (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -6.5e+50], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 9.5], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.5 \cdot 10^{+50}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq 9.5:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\end{array}
\end{array}
if c < -6.5000000000000003e50Initial program 40.8%
Taylor expanded in c around inf 79.6%
unpow279.6%
times-frac88.5%
Simplified88.5%
associate-*l/90.0%
Applied egg-rr90.0%
if -6.5000000000000003e50 < c < 9.5Initial program 74.5%
Taylor expanded in c around 0 76.6%
unpow276.6%
times-frac80.3%
Simplified80.3%
if 9.5 < c Initial program 56.9%
Taylor expanded in c around inf 75.3%
unpow275.3%
times-frac76.9%
Simplified76.9%
Final simplification81.7%
(FPCore (a b c d) :precision binary64 (if (<= c -3.3e+43) (/ a c) (if (<= c 2.7e-30) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.3e+43) {
tmp = a / c;
} else if (c <= 2.7e-30) {
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 (c <= (-3.3d+43)) then
tmp = a / c
else if (c <= 2.7d-30) 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 (c <= -3.3e+43) {
tmp = a / c;
} else if (c <= 2.7e-30) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3.3e+43: tmp = a / c elif c <= 2.7e-30: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3.3e+43) tmp = Float64(a / c); elseif (c <= 2.7e-30) 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 (c <= -3.3e+43) tmp = a / c; elseif (c <= 2.7e-30) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.3e+43], N[(a / c), $MachinePrecision], If[LessEqual[c, 2.7e-30], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.3 \cdot 10^{+43}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 2.7 \cdot 10^{-30}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -3.3000000000000001e43 or 2.69999999999999987e-30 < c Initial program 50.9%
Taylor expanded in c around inf 70.3%
if -3.3000000000000001e43 < c < 2.69999999999999987e-30Initial program 74.8%
Taylor expanded in c around 0 71.3%
Final simplification70.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 62.5%
Taylor expanded in c around inf 46.0%
Final simplification46.0%
(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 2023229
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))