
(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 (<= c -4.6e+69)
(/ (+ a (* d (/ b c))) c)
(if (<= c -7800.0)
(/ (+ b (* a (/ c d))) d)
(if (<= c -1.1e-74)
t_0
(if (<= c 6.8e-77)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 6.2e+117) t_0 (+ (/ a c) (/ (* b (/ d c)) c)))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -4.6e+69) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= -7800.0) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= -1.1e-74) {
tmp = t_0;
} else if (c <= 6.8e-77) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 6.2e+117) {
tmp = t_0;
} else {
tmp = (a / c) + ((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) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (c <= (-4.6d+69)) then
tmp = (a + (d * (b / c))) / c
else if (c <= (-7800.0d0)) then
tmp = (b + (a * (c / d))) / d
else if (c <= (-1.1d-74)) then
tmp = t_0
else if (c <= 6.8d-77) then
tmp = (b + ((a * c) / d)) / d
else if (c <= 6.2d+117) then
tmp = t_0
else
tmp = (a / c) + ((b * (d / c)) / c)
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 (c <= -4.6e+69) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= -7800.0) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= -1.1e-74) {
tmp = t_0;
} else if (c <= 6.8e-77) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 6.2e+117) {
tmp = t_0;
} else {
tmp = (a / c) + ((b * (d / c)) / c);
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -4.6e+69: tmp = (a + (d * (b / c))) / c elif c <= -7800.0: tmp = (b + (a * (c / d))) / d elif c <= -1.1e-74: tmp = t_0 elif c <= 6.8e-77: tmp = (b + ((a * c) / d)) / d elif c <= 6.2e+117: tmp = t_0 else: tmp = (a / c) + ((b * (d / c)) / c) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (c <= -4.6e+69) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); elseif (c <= -7800.0) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= -1.1e-74) tmp = t_0; elseif (c <= 6.8e-77) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 6.2e+117) tmp = t_0; else tmp = Float64(Float64(a / c) + Float64(Float64(b * Float64(d / c)) / c)); 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 (c <= -4.6e+69) tmp = (a + (d * (b / c))) / c; elseif (c <= -7800.0) tmp = (b + (a * (c / d))) / d; elseif (c <= -1.1e-74) tmp = t_0; elseif (c <= 6.8e-77) tmp = (b + ((a * c) / d)) / d; elseif (c <= 6.2e+117) tmp = t_0; else tmp = (a / c) + ((b * (d / c)) / c); 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[c, -4.6e+69], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -7800.0], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, -1.1e-74], t$95$0, If[LessEqual[c, 6.8e-77], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 6.2e+117], t$95$0, N[(N[(a / c), $MachinePrecision] + N[(N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $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}\;c \leq -4.6 \cdot 10^{+69}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq -7800:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq -1.1 \cdot 10^{-74}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 6.8 \cdot 10^{-77}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 6.2 \cdot 10^{+117}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -4.60000000000000033e69Initial program 39.0%
Taylor expanded in c around inf 68.6%
*-commutative68.6%
associate-/l*77.1%
Applied egg-rr77.1%
if -4.60000000000000033e69 < c < -7800Initial program 42.2%
Taylor expanded in d around inf 49.1%
associate-/l*66.4%
Simplified66.4%
if -7800 < c < -1.10000000000000005e-74 or 6.79999999999999966e-77 < c < 6.1999999999999995e117Initial program 91.1%
if -1.10000000000000005e-74 < c < 6.79999999999999966e-77Initial program 73.9%
Taylor expanded in d around inf 94.9%
if 6.1999999999999995e117 < c Initial program 34.7%
Taylor expanded in d around 0 74.3%
associate-/l*82.4%
Simplified82.4%
pow282.4%
associate-*r/74.3%
associate-/r*87.5%
associate-/l*95.5%
Applied egg-rr95.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (* a c) (* b d))))
(if (<= (/ t_0 (+ (* c c) (* d d))) 1e+275)
(* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
(/ (+ b (* c (/ a d))) d))))
double code(double a, double b, double c, double d) {
double t_0 = (a * c) + (b * d);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 1e+275) {
tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
} else {
tmp = (b + (c * (a / d))) / d;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = (a * c) + (b * d);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 1e+275) {
tmp = (1.0 / Math.hypot(c, d)) * (t_0 / Math.hypot(c, d));
} else {
tmp = (b + (c * (a / d))) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a * c) + (b * d) tmp = 0 if (t_0 / ((c * c) + (d * d))) <= 1e+275: tmp = (1.0 / math.hypot(c, d)) * (t_0 / math.hypot(c, d)) else: tmp = (b + (c * (a / d))) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a * c) + Float64(b * d)) tmp = 0.0 if (Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) <= 1e+275) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d))); else tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a * c) + (b * d); tmp = 0.0; if ((t_0 / ((c * c) + (d * d))) <= 1e+275) tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d)); else tmp = (b + (c * (a / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+275], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot c + b \cdot d\\
\mathbf{if}\;\frac{t\_0}{c \cdot c + d \cdot d} \leq 10^{+275}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t\_0}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 9.9999999999999996e274Initial program 82.2%
*-un-lft-identity82.2%
add-sqr-sqrt82.2%
times-frac82.2%
hypot-define82.2%
fma-define82.2%
hypot-define97.6%
Applied egg-rr97.6%
fma-undefine97.6%
+-commutative97.6%
Applied egg-rr97.6%
if 9.9999999999999996e274 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 15.0%
Taylor expanded in d around inf 53.6%
*-commutative53.6%
*-un-lft-identity53.6%
times-frac61.0%
Applied egg-rr61.0%
Final simplification87.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -1.8e+66)
(/ (+ b (* c (/ a d))) d)
(if (<= d -1.6e-122)
t_0
(if (<= d 3.5e-111)
(/ (+ a (* b (/ d c))) c)
(if (<= d 2.7e+52) t_0 (* (/ d (hypot c d)) (/ b (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 tmp;
if (d <= -1.8e+66) {
tmp = (b + (c * (a / d))) / d;
} else if (d <= -1.6e-122) {
tmp = t_0;
} else if (d <= 3.5e-111) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 2.7e+52) {
tmp = t_0;
} else {
tmp = (d / hypot(c, d)) * (b / 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 tmp;
if (d <= -1.8e+66) {
tmp = (b + (c * (a / d))) / d;
} else if (d <= -1.6e-122) {
tmp = t_0;
} else if (d <= 3.5e-111) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 2.7e+52) {
tmp = t_0;
} else {
tmp = (d / Math.hypot(c, d)) * (b / Math.hypot(c, d));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -1.8e+66: tmp = (b + (c * (a / d))) / d elif d <= -1.6e-122: tmp = t_0 elif d <= 3.5e-111: tmp = (a + (b * (d / c))) / c elif d <= 2.7e+52: tmp = t_0 else: tmp = (d / math.hypot(c, d)) * (b / 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))) tmp = 0.0 if (d <= -1.8e+66) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); elseif (d <= -1.6e-122) tmp = t_0; elseif (d <= 3.5e-111) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (d <= 2.7e+52) tmp = t_0; else tmp = Float64(Float64(d / hypot(c, d)) * Float64(b / 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)); tmp = 0.0; if (d <= -1.8e+66) tmp = (b + (c * (a / d))) / d; elseif (d <= -1.6e-122) tmp = t_0; elseif (d <= 3.5e-111) tmp = (a + (b * (d / c))) / c; elseif (d <= 2.7e+52) tmp = t_0; else tmp = (d / hypot(c, d)) * (b / 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]}, If[LessEqual[d, -1.8e+66], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -1.6e-122], t$95$0, If[LessEqual[d, 3.5e-111], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.7e+52], t$95$0, N[(N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $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 -1.8 \cdot 10^{+66}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{elif}\;d \leq -1.6 \cdot 10^{-122}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 3.5 \cdot 10^{-111}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.7 \cdot 10^{+52}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -1.8e66Initial program 39.2%
Taylor expanded in d around inf 71.3%
*-commutative71.3%
*-un-lft-identity71.3%
times-frac81.9%
Applied egg-rr81.9%
if -1.8e66 < d < -1.6000000000000001e-122 or 3.5e-111 < d < 2.7e52Initial program 85.8%
if -1.6000000000000001e-122 < d < 3.5e-111Initial program 76.1%
Taylor expanded in c around inf 95.1%
associate-/l*96.3%
Simplified96.3%
if 2.7e52 < d Initial program 46.8%
Taylor expanded in a around 0 46.3%
*-commutative46.3%
add-sqr-sqrt46.3%
hypot-undefine46.3%
hypot-undefine46.3%
times-frac85.7%
Applied egg-rr85.7%
Final simplification88.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -8.5e+66)
(/ (+ b (* c (/ a d))) d)
(if (<= d -1.95e-124)
t_0
(if (<= d 4.8e-112)
(/ (+ a (* b (/ d c))) c)
(if (<= d 1e+57) t_0 (+ (/ b d) (* a (/ c (pow d 2.0))))))))))
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 <= -8.5e+66) {
tmp = (b + (c * (a / d))) / d;
} else if (d <= -1.95e-124) {
tmp = t_0;
} else if (d <= 4.8e-112) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 1e+57) {
tmp = t_0;
} else {
tmp = (b / d) + (a * (c / pow(d, 2.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 * c) + (b * d)) / ((c * c) + (d * d))
if (d <= (-8.5d+66)) then
tmp = (b + (c * (a / d))) / d
else if (d <= (-1.95d-124)) then
tmp = t_0
else if (d <= 4.8d-112) then
tmp = (a + (b * (d / c))) / c
else if (d <= 1d+57) then
tmp = t_0
else
tmp = (b / d) + (a * (c / (d ** 2.0d0)))
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 <= -8.5e+66) {
tmp = (b + (c * (a / d))) / d;
} else if (d <= -1.95e-124) {
tmp = t_0;
} else if (d <= 4.8e-112) {
tmp = (a + (b * (d / c))) / c;
} else if (d <= 1e+57) {
tmp = t_0;
} else {
tmp = (b / d) + (a * (c / Math.pow(d, 2.0)));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -8.5e+66: tmp = (b + (c * (a / d))) / d elif d <= -1.95e-124: tmp = t_0 elif d <= 4.8e-112: tmp = (a + (b * (d / c))) / c elif d <= 1e+57: tmp = t_0 else: tmp = (b / d) + (a * (c / math.pow(d, 2.0))) 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 <= -8.5e+66) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); elseif (d <= -1.95e-124) tmp = t_0; elseif (d <= 4.8e-112) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (d <= 1e+57) tmp = t_0; else tmp = Float64(Float64(b / d) + Float64(a * Float64(c / (d ^ 2.0)))); 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 <= -8.5e+66) tmp = (b + (c * (a / d))) / d; elseif (d <= -1.95e-124) tmp = t_0; elseif (d <= 4.8e-112) tmp = (a + (b * (d / c))) / c; elseif (d <= 1e+57) tmp = t_0; else tmp = (b / d) + (a * (c / (d ^ 2.0))); 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, -8.5e+66], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -1.95e-124], t$95$0, If[LessEqual[d, 4.8e-112], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1e+57], t$95$0, N[(N[(b / d), $MachinePrecision] + N[(a * N[(c / N[Power[d, 2.0], $MachinePrecision]), $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 -8.5 \cdot 10^{+66}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{elif}\;d \leq -1.95 \cdot 10^{-124}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 4.8 \cdot 10^{-112}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 10^{+57}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + a \cdot \frac{c}{{d}^{2}}\\
\end{array}
\end{array}
if d < -8.5000000000000004e66Initial program 39.2%
Taylor expanded in d around inf 71.3%
*-commutative71.3%
*-un-lft-identity71.3%
times-frac81.9%
Applied egg-rr81.9%
if -8.5000000000000004e66 < d < -1.94999999999999996e-124 or 4.8000000000000001e-112 < d < 1.00000000000000005e57Initial program 85.0%
if -1.94999999999999996e-124 < d < 4.8000000000000001e-112Initial program 76.1%
Taylor expanded in c around inf 95.1%
associate-/l*96.3%
Simplified96.3%
if 1.00000000000000005e57 < d Initial program 45.6%
Taylor expanded in c around 0 83.5%
associate-/l*83.6%
Simplified83.6%
Final simplification87.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.45e+26) (not (<= d 5.8e-21))) (/ (+ b (* c (/ a d))) d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.45e+26) || !(d <= 5.8e-21)) {
tmp = (b + (c * (a / d))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-2.45d+26)) .or. (.not. (d <= 5.8d-21))) then
tmp = (b + (c * (a / d))) / d
else
tmp = (a + (b * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.45e+26) || !(d <= 5.8e-21)) {
tmp = (b + (c * (a / d))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.45e+26) or not (d <= 5.8e-21): tmp = (b + (c * (a / d))) / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.45e+26) || !(d <= 5.8e-21)) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.45e+26) || ~((d <= 5.8e-21))) tmp = (b + (c * (a / d))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.45e+26], N[Not[LessEqual[d, 5.8e-21]], $MachinePrecision]], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.45 \cdot 10^{+26} \lor \neg \left(d \leq 5.8 \cdot 10^{-21}\right):\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -2.44999999999999987e26 or 5.8e-21 < d Initial program 50.7%
Taylor expanded in d around inf 73.6%
*-commutative73.6%
*-un-lft-identity73.6%
times-frac78.2%
Applied egg-rr78.2%
if -2.44999999999999987e26 < d < 5.8e-21Initial program 78.8%
Taylor expanded in c around inf 87.0%
associate-/l*88.6%
Simplified88.6%
Final simplification83.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -9e+29) (not (<= d 3.5e-23))) (/ (+ b (* a (/ c d))) d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9e+29) || !(d <= 3.5e-23)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-9d+29)) .or. (.not. (d <= 3.5d-23))) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a + (b * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9e+29) || !(d <= 3.5e-23)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -9e+29) or not (d <= 3.5e-23): tmp = (b + (a * (c / d))) / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -9e+29) || !(d <= 3.5e-23)) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -9e+29) || ~((d <= 3.5e-23))) tmp = (b + (a * (c / d))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9e+29], N[Not[LessEqual[d, 3.5e-23]], $MachinePrecision]], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9 \cdot 10^{+29} \lor \neg \left(d \leq 3.5 \cdot 10^{-23}\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -9.0000000000000005e29 or 3.49999999999999993e-23 < d Initial program 50.7%
Taylor expanded in d around inf 73.6%
associate-/l*77.5%
Simplified77.5%
if -9.0000000000000005e29 < d < 3.49999999999999993e-23Initial program 78.8%
Taylor expanded in c around inf 87.0%
associate-/l*88.6%
Simplified88.6%
Final simplification82.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.6e+31) (not (<= d 1.25e+60))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.6e+31) || !(d <= 1.25e+60)) {
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.6d+31)) .or. (.not. (d <= 1.25d+60))) 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.6e+31) || !(d <= 1.25e+60)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.6e+31) or not (d <= 1.25e+60): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.6e+31) || !(d <= 1.25e+60)) 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.6e+31) || ~((d <= 1.25e+60))) 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.6e+31], N[Not[LessEqual[d, 1.25e+60]], $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.6 \cdot 10^{+31} \lor \neg \left(d \leq 1.25 \cdot 10^{+60}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.6e31 or 1.24999999999999994e60 < d Initial program 45.6%
Taylor expanded in c around 0 75.6%
if -1.6e31 < d < 1.24999999999999994e60Initial program 79.0%
Taylor expanded in c around inf 80.8%
associate-/l*82.2%
Simplified82.2%
Final simplification79.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5.6e+124) (not (<= c 0.0032))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.6e+124) || !(c <= 0.0032)) {
tmp = a / 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 <= (-5.6d+124)) .or. (.not. (c <= 0.0032d0))) then
tmp = a / 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 <= -5.6e+124) || !(c <= 0.0032)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5.6e+124) or not (c <= 0.0032): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5.6e+124) || !(c <= 0.0032)) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -5.6e+124) || ~((c <= 0.0032))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5.6e+124], N[Not[LessEqual[c, 0.0032]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.6 \cdot 10^{+124} \lor \neg \left(c \leq 0.0032\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -5.59999999999999999e124 or 0.00320000000000000015 < c Initial program 49.2%
Taylor expanded in c around inf 76.2%
if -5.59999999999999999e124 < c < 0.00320000000000000015Initial program 72.9%
Taylor expanded in c around 0 66.7%
Final simplification70.2%
(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 64.1%
Taylor expanded in c around inf 42.9%
(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 2024108
(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))))