
(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 8 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) (/ (fma a (/ c d) b) 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 = fma(a, (c / d), b) / 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(fma(a, Float64(c / d), b) / d); else tmp = t_1; 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]}, 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[(a * N[(c / d), $MachinePrecision] + b), $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{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{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%
+-commutative79.3%
associate-/l*86.1%
fma-define86.1%
Simplified86.1%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY) (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d)) (/ (+ a (* d (/ b 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 = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = (a + (d * (b / 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(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(a + Float64(d * Float64(b / 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[(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 + N[(d * N[(b / 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{\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 + d \cdot \frac{b}{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 74.9%
add-sqr-sqrt74.9%
associate-/r*75.0%
fma-define75.0%
hypot-define75.0%
hypot-define94.2%
Applied egg-rr94.2%
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%
*-commutative44.4%
associate-/l*56.4%
Applied egg-rr56.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma a (/ c d) b) d))
(t_1 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -3.1e+108)
t_0
(if (<= d -1.5e+84)
(/ (+ a (* d (/ b 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 = fma(a, (c / d), b) / 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 + (d * (b / 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;
}
function code(a, b, c, d) t_0 = Float64(fma(a, Float64(c / d), b) / 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(d * Float64(b / 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
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * N[(c / d), $MachinePrecision] + b), $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[(d * N[(b / 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{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{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 + d \cdot \frac{b}{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%
+-commutative77.9%
associate-/l*82.8%
fma-define82.8%
Simplified82.8%
if -3.1000000000000001e108 < d < -1.49999999999999998e84Initial program 23.7%
Taylor expanded in c around inf 67.6%
*-commutative67.6%
associate-/l*100.0%
Applied egg-rr100.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
(let* ((t_0 (/ (+ a (* d (/ b c))) c)))
(if (<= c -6.2e-51)
t_0
(if (<= c 1.16e-110)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 6.4e+42) (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (a + (d * (b / c))) / c;
double tmp;
if (c <= -6.2e-51) {
tmp = t_0;
} else if (c <= 1.16e-110) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 6.4e+42) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} 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) :: tmp
t_0 = (a + (d * (b / c))) / c
if (c <= (-6.2d-51)) then
tmp = t_0
else if (c <= 1.16d-110) then
tmp = (b + ((a * c) / d)) / d
else if (c <= 6.4d+42) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
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 = (a + (d * (b / c))) / c;
double tmp;
if (c <= -6.2e-51) {
tmp = t_0;
} else if (c <= 1.16e-110) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 6.4e+42) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a + (d * (b / c))) / c tmp = 0 if c <= -6.2e-51: tmp = t_0 elif c <= 1.16e-110: tmp = (b + ((a * c) / d)) / d elif c <= 6.4e+42: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a + Float64(d * Float64(b / c))) / c) tmp = 0.0 if (c <= -6.2e-51) tmp = t_0; elseif (c <= 1.16e-110) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 6.4e+42) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a + (d * (b / c))) / c; tmp = 0.0; if (c <= -6.2e-51) tmp = t_0; elseif (c <= 1.16e-110) tmp = (b + ((a * c) / d)) / d; elseif (c <= 6.4e+42) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -6.2e-51], t$95$0, If[LessEqual[c, 1.16e-110], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 6.4e+42], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{if}\;c \leq -6.2 \cdot 10^{-51}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.16 \cdot 10^{-110}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 6.4 \cdot 10^{+42}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -6.1999999999999995e-51 or 6.40000000000000004e42 < c Initial program 51.8%
Taylor expanded in c around inf 79.9%
*-commutative79.9%
associate-/l*84.2%
Applied egg-rr84.2%
if -6.1999999999999995e-51 < c < 1.16000000000000001e-110Initial program 71.9%
Taylor expanded in d around inf 86.2%
if 1.16000000000000001e-110 < c < 6.40000000000000004e42Initial program 90.7%
(FPCore (a b c d) :precision binary64 (if (or (<= c -6.2e-51) (not (<= c 2.9e-50))) (/ (+ 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 <= 2.9e-50)) {
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 <= 2.9d-50))) 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 <= 2.9e-50)) {
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 <= 2.9e-50): 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 <= 2.9e-50)) 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 <= 2.9e-50))) 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, 2.9e-50]], $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 2.9 \cdot 10^{-50}\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 2.90000000000000008e-50 < c Initial program 54.9%
Taylor expanded in c around inf 79.2%
*-commutative79.2%
associate-/l*83.2%
Applied egg-rr83.2%
if -6.1999999999999995e-51 < c < 2.90000000000000008e-50Initial program 74.0%
Taylor expanded in d around inf 84.6%
Final simplification83.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4e+109) (not (<= d 1850000000000.0))) (/ b d) (/ (+ a (* d (/ b c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4e+109) || !(d <= 1850000000000.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 <= (-4d+109)) .or. (.not. (d <= 1850000000000.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 <= -4e+109) || !(d <= 1850000000000.0)) {
tmp = b / d;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4e+109) or not (d <= 1850000000000.0): tmp = b / d else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4e+109) || !(d <= 1850000000000.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 <= -4e+109) || ~((d <= 1850000000000.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, -4e+109], N[Not[LessEqual[d, 1850000000000.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 -4 \cdot 10^{+109} \lor \neg \left(d \leq 1850000000000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if d < -3.99999999999999993e109 or 1.85e12 < d Initial program 48.4%
Taylor expanded in c around 0 73.5%
if -3.99999999999999993e109 < d < 1.85e12Initial program 71.1%
Taylor expanded in c around inf 81.9%
*-commutative81.9%
associate-/l*82.6%
Applied egg-rr82.6%
Final simplification79.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -8.5e-34) (not (<= d 11000000.0))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -8.5e-34) || !(d <= 11000000.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 <= (-8.5d-34)) .or. (.not. (d <= 11000000.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 <= -8.5e-34) || !(d <= 11000000.0)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -8.5e-34) or not (d <= 11000000.0): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -8.5e-34) || !(d <= 11000000.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 <= -8.5e-34) || ~((d <= 11000000.0))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -8.5e-34], N[Not[LessEqual[d, 11000000.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -8.5 \cdot 10^{-34} \lor \neg \left(d \leq 11000000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -8.5000000000000001e-34 or 1.1e7 < d Initial program 55.3%
Taylor expanded in c around 0 64.0%
if -8.5000000000000001e-34 < d < 1.1e7Initial 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))))