
(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 10 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 (* (/ d (hypot c d)) (/ b (hypot c d)))))
(if (<= d -1.2e+84)
t_1
(if (<= d -2.1e-35)
t_0
(if (<= d 4.8e-86)
(/ (+ a (/ (* b d) c)) c)
(if (<= d 1.8e+75)
t_0
(if (<= d 5.8e+136) (/ (+ b (* a (/ c d))) 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 = (d / hypot(c, d)) * (b / hypot(c, d));
double tmp;
if (d <= -1.2e+84) {
tmp = t_1;
} else if (d <= -2.1e-35) {
tmp = t_0;
} else if (d <= 4.8e-86) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 1.8e+75) {
tmp = t_0;
} else if (d <= 5.8e+136) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = 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 = (d / Math.hypot(c, d)) * (b / Math.hypot(c, d));
double tmp;
if (d <= -1.2e+84) {
tmp = t_1;
} else if (d <= -2.1e-35) {
tmp = t_0;
} else if (d <= 4.8e-86) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 1.8e+75) {
tmp = t_0;
} else if (d <= 5.8e+136) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = (d / math.hypot(c, d)) * (b / math.hypot(c, d)) tmp = 0 if d <= -1.2e+84: tmp = t_1 elif d <= -2.1e-35: tmp = t_0 elif d <= 4.8e-86: tmp = (a + ((b * d) / c)) / c elif d <= 1.8e+75: tmp = t_0 elif d <= 5.8e+136: tmp = (b + (a * (c / d))) / d 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(d / hypot(c, d)) * Float64(b / hypot(c, d))) tmp = 0.0 if (d <= -1.2e+84) tmp = t_1; elseif (d <= -2.1e-35) tmp = t_0; elseif (d <= 4.8e-86) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif (d <= 1.8e+75) tmp = t_0; elseif (d <= 5.8e+136) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); 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 = (d / hypot(c, d)) * (b / hypot(c, d)); tmp = 0.0; if (d <= -1.2e+84) tmp = t_1; elseif (d <= -2.1e-35) tmp = t_0; elseif (d <= 4.8e-86) tmp = (a + ((b * d) / c)) / c; elseif (d <= 1.8e+75) tmp = t_0; elseif (d <= 5.8e+136) tmp = (b + (a * (c / d))) / d; 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[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.2e+84], t$95$1, If[LessEqual[d, -2.1e-35], t$95$0, If[LessEqual[d, 4.8e-86], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.8e+75], t$95$0, If[LessEqual[d, 5.8e+136], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], 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{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;d \leq -1.2 \cdot 10^{+84}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -2.1 \cdot 10^{-35}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 4.8 \cdot 10^{-86}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.8 \cdot 10^{+75}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 5.8 \cdot 10^{+136}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.2e84 or 5.79999999999999949e136 < d Initial program 36.4%
Taylor expanded in a around 0 34.2%
*-commutative34.2%
add-sqr-sqrt34.2%
hypot-undefine34.2%
hypot-undefine34.2%
times-frac84.9%
Applied egg-rr84.9%
if -1.2e84 < d < -2.1e-35 or 4.80000000000000026e-86 < d < 1.8e75Initial program 87.5%
if -2.1e-35 < d < 4.80000000000000026e-86Initial program 68.5%
Taylor expanded in c around inf 93.3%
if 1.8e75 < d < 5.79999999999999949e136Initial program 51.5%
Taylor expanded in d around inf 79.3%
associate-/l*86.1%
Simplified86.1%
(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 (/ c d))) 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 / (c / d))) / 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(c / d))) / 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[(c / d), $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 + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 74.9%
*-un-lft-identity74.9%
add-sqr-sqrt74.9%
times-frac74.9%
hypot-define74.9%
fma-define74.9%
hypot-define93.9%
Applied egg-rr93.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 44.4%
associate-/l*56.4%
Simplified56.4%
clear-num56.4%
un-div-inv56.4%
Applied egg-rr56.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ b (* a (/ c d))) d))
(t_1 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -3.1e+108)
t_0
(if (<= d -1.5e+84)
(/ (+ a (* b (/ d c))) c)
(if (<= d -9.5e-36)
t_1
(if (<= d 1.56e-86)
(/ (+ a (/ (* b d) c)) c)
(if (<= d 3.6e+79) t_1 t_0)))))))
double code(double a, double b, double c, double d) {
double t_0 = (b + (a * (c / d))) / d;
double t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -3.1e+108) {
tmp = t_0;
} else if (d <= -1.5e+84) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= -9.5e-36) {
tmp = t_1;
} else if (d <= 1.56e-86) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 3.6e+79) {
tmp = t_1;
} else {
tmp = t_0;
}
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 + (a * (c / d))) / d
t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (d <= (-3.1d+108)) then
tmp = t_0
else if (d <= (-1.5d+84)) then
tmp = (a + (b * (d / c))) / c
else if (d <= (-9.5d-36)) then
tmp = t_1
else if (d <= 1.56d-86) then
tmp = (a + ((b * d) / c)) / c
else if (d <= 3.6d+79) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b + (a * (c / d))) / d;
double t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -3.1e+108) {
tmp = t_0;
} else if (d <= -1.5e+84) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= -9.5e-36) {
tmp = t_1;
} else if (d <= 1.56e-86) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 3.6e+79) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b + (a * (c / d))) / d t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -3.1e+108: tmp = t_0 elif d <= -1.5e+84: tmp = (a + (b * (d / c))) / c elif d <= -9.5e-36: tmp = t_1 elif d <= 1.56e-86: tmp = (a + ((b * d) / c)) / c elif d <= 3.6e+79: tmp = t_1 else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b + Float64(a * Float64(c / d))) / d) t_1 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (d <= -3.1e+108) tmp = t_0; elseif (d <= -1.5e+84) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (d <= -9.5e-36) tmp = t_1; elseif (d <= 1.56e-86) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif (d <= 3.6e+79) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b + (a * (c / d))) / d; t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -3.1e+108) tmp = t_0; elseif (d <= -1.5e+84) tmp = (a + (b * (d / c))) / c; elseif (d <= -9.5e-36) tmp = t_1; elseif (d <= 1.56e-86) tmp = (a + ((b * d) / c)) / c; elseif (d <= 3.6e+79) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $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[d, -3.1e+108], t$95$0, If[LessEqual[d, -1.5e+84], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, -9.5e-36], t$95$1, If[LessEqual[d, 1.56e-86], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.6e+79], t$95$1, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b + a \cdot \frac{c}{d}}{d}\\
t_1 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -3.1 \cdot 10^{+108}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.5 \cdot 10^{+84}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq -9.5 \cdot 10^{-36}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 1.56 \cdot 10^{-86}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 3.6 \cdot 10^{+79}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -3.1000000000000001e108 or 3.5999999999999999e79 < d Initial program 40.0%
Taylor expanded in d around inf 77.9%
associate-/l*82.8%
Simplified82.8%
if -3.1000000000000001e108 < d < -1.49999999999999998e84Initial program 23.7%
Taylor expanded in c around inf 67.6%
associate-/l*100.0%
Simplified100.0%
if -1.49999999999999998e84 < d < -9.5000000000000003e-36 or 1.5599999999999999e-86 < d < 3.5999999999999999e79Initial program 87.5%
if -9.5000000000000003e-36 < d < 1.5599999999999999e-86Initial program 68.5%
Taylor expanded in c around inf 93.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -6.2e-51) (not (<= c 1.1e-46))) (/ (+ a (* d (/ b c))) c) (/ (+ b (/ (* a c) d)) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6.2e-51) || !(c <= 1.1e-46)) {
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 <= (-6.2d-51)) .or. (.not. (c <= 1.1d-46))) 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 <= -6.2e-51) || !(c <= 1.1e-46)) {
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 <= -6.2e-51) or not (c <= 1.1e-46): 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 <= -6.2e-51) || !(c <= 1.1e-46)) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); else tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -6.2e-51) || ~((c <= 1.1e-46))) 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, -6.2e-51], N[Not[LessEqual[c, 1.1e-46]], $MachinePrecision]], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.2 \cdot 10^{-51} \lor \neg \left(c \leq 1.1 \cdot 10^{-46}\right):\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\end{array}
\end{array}
if c < -6.1999999999999995e-51 or 1.1e-46 < c Initial program 54.9%
Taylor expanded in c around inf 79.2%
associate-/l*82.5%
Simplified82.5%
clear-num82.5%
un-div-inv82.6%
Applied egg-rr82.6%
associate-/r/83.2%
Applied egg-rr83.2%
if -6.1999999999999995e-51 < c < 1.1e-46Initial program 74.0%
Taylor expanded in d around inf 84.6%
Final simplification83.7%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.35e-51) (not (<= c 1.25e-46))) (/ (+ a (* d (/ b c))) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.35e-51) || !(c <= 1.25e-46)) {
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 <= (-2.35d-51)) .or. (.not. (c <= 1.25d-46))) 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 <= -2.35e-51) || !(c <= 1.25e-46)) {
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 <= -2.35e-51) or not (c <= 1.25e-46): 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 <= -2.35e-51) || !(c <= 1.25e-46)) 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 <= -2.35e-51) || ~((c <= 1.25e-46))) 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, -2.35e-51], N[Not[LessEqual[c, 1.25e-46]], $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 -2.35 \cdot 10^{-51} \lor \neg \left(c \leq 1.25 \cdot 10^{-46}\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 < -2.3499999999999999e-51 or 1.24999999999999998e-46 < c Initial program 54.9%
Taylor expanded in c around inf 79.2%
associate-/l*82.5%
Simplified82.5%
clear-num82.5%
un-div-inv82.6%
Applied egg-rr82.6%
associate-/r/83.2%
Applied egg-rr83.2%
if -2.3499999999999999e-51 < c < 1.24999999999999998e-46Initial program 74.0%
Taylor expanded in d around inf 84.6%
associate-/l*84.6%
Simplified84.6%
Final simplification83.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5.5e+107) (not (<= d 1300000000000.0))) (/ b d) (/ (+ a (/ b (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5.5e+107) || !(d <= 1300000000000.0)) {
tmp = b / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-5.5d+107)) .or. (.not. (d <= 1300000000000.0d0))) then
tmp = b / d
else
tmp = (a + (b / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5.5e+107) || !(d <= 1300000000000.0)) {
tmp = b / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5.5e+107) or not (d <= 1300000000000.0): tmp = b / d else: tmp = (a + (b / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5.5e+107) || !(d <= 1300000000000.0)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -5.5e+107) || ~((d <= 1300000000000.0))) tmp = b / d; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5.5e+107], N[Not[LessEqual[d, 1300000000000.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.5 \cdot 10^{+107} \lor \neg \left(d \leq 1300000000000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -5.5000000000000003e107 or 1.3e12 < d Initial program 48.4%
Taylor expanded in c around 0 73.5%
if -5.5000000000000003e107 < d < 1.3e12Initial program 71.1%
Taylor expanded in c around inf 81.9%
associate-/l*82.6%
Simplified82.6%
clear-num82.6%
un-div-inv82.6%
Applied egg-rr82.6%
Final simplification79.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.08e+108) (not (<= d 230000000000.0))) (/ b d) (/ (+ a (* d (/ b c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.08e+108) || !(d <= 230000000000.0)) {
tmp = b / d;
} else {
tmp = (a + (d * (b / 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.08d+108)) .or. (.not. (d <= 230000000000.0d0))) then
tmp = b / d
else
tmp = (a + (d * (b / 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.08e+108) || !(d <= 230000000000.0)) {
tmp = b / d;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.08e+108) or not (d <= 230000000000.0): tmp = b / d else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.08e+108) || !(d <= 230000000000.0)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.08e+108) || ~((d <= 230000000000.0))) tmp = b / d; else tmp = (a + (d * (b / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.08e+108], N[Not[LessEqual[d, 230000000000.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.08 \cdot 10^{+108} \lor \neg \left(d \leq 230000000000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if d < -1.0800000000000001e108 or 2.3e11 < d Initial program 48.4%
Taylor expanded in c around 0 73.5%
if -1.0800000000000001e108 < d < 2.3e11Initial program 71.1%
Taylor expanded in c around inf 81.9%
associate-/l*82.6%
Simplified82.6%
clear-num82.6%
un-div-inv82.6%
Applied egg-rr82.6%
associate-/r/82.6%
Applied egg-rr82.6%
Final simplification79.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.05e+108) (not (<= d 440000.0))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.05e+108) || !(d <= 440000.0)) {
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+108)) .or. (.not. (d <= 440000.0d0))) 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+108) || !(d <= 440000.0)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.05e+108) or not (d <= 440000.0): 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+108) || !(d <= 440000.0)) 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+108) || ~((d <= 440000.0))) 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+108], N[Not[LessEqual[d, 440000.0]], $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^{+108} \lor \neg \left(d \leq 440000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.05000000000000005e108 or 4.4e5 < d Initial program 48.4%
Taylor expanded in c around 0 73.5%
if -1.05000000000000005e108 < d < 4.4e5Initial program 71.1%
Taylor expanded in c around inf 81.9%
associate-/l*82.6%
Simplified82.6%
Final simplification79.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3e-34) (not (<= d 4200000.0))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3e-34) || !(d <= 4200000.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 <= (-3d-34)) .or. (.not. (d <= 4200000.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 <= -3e-34) || !(d <= 4200000.0)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3e-34) or not (d <= 4200000.0): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3e-34) || !(d <= 4200000.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 <= -3e-34) || ~((d <= 4200000.0))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3e-34], N[Not[LessEqual[d, 4200000.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3 \cdot 10^{-34} \lor \neg \left(d \leq 4200000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -3e-34 or 4.2e6 < d Initial program 55.3%
Taylor expanded in c around 0 64.0%
if -3e-34 < d < 4.2e6Initial program 69.8%
Taylor expanded in c around inf 79.1%
Final simplification71.6%
(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.6%
Taylor expanded in c around inf 49.7%
(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 2024096
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))