
(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
(if (<= c -1.45e+69)
(/ (+ a (* d (* b (/ 1.0 c)))) c)
(if (<= c -1.12e-108)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= c 3.5e-119)
(/ (+ b (* a (/ c d))) d)
(if (<= c 4.5e+39)
(/ (fma a c (* b d)) (fma c c (* d d)))
(if (<= c 1.2e+87)
(+ (/ b d) (/ a (* d (/ d c))))
(/ (+ a (* b (/ d c))) c)))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.45e+69) {
tmp = (a + (d * (b * (1.0 / c)))) / c;
} else if (c <= -1.12e-108) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 3.5e-119) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 4.5e+39) {
tmp = fma(a, c, (b * d)) / fma(c, c, (d * d));
} else if (c <= 1.2e+87) {
tmp = (b / d) + (a / (d * (d / c)));
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.45e+69) tmp = Float64(Float64(a + Float64(d * Float64(b * Float64(1.0 / c)))) / c); elseif (c <= -1.12e-108) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 3.5e-119) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 4.5e+39) tmp = Float64(fma(a, c, Float64(b * d)) / fma(c, c, Float64(d * d))); elseif (c <= 1.2e+87) tmp = Float64(Float64(b / d) + Float64(a / Float64(d * Float64(d / c)))); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.45e+69], N[(N[(a + N[(d * N[(b * N[(1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.12e-108], 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, 3.5e-119], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.5e+39], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.2e+87], N[(N[(b / d), $MachinePrecision] + N[(a / N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.45 \cdot 10^{+69}:\\
\;\;\;\;\frac{a + d \cdot \left(b \cdot \frac{1}{c}\right)}{c}\\
\mathbf{elif}\;c \leq -1.12 \cdot 10^{-108}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 3.5 \cdot 10^{-119}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 4.5 \cdot 10^{+39}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;c \leq 1.2 \cdot 10^{+87}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -1.4499999999999999e69Initial program 36.7%
Taylor expanded in c around inf 73.0%
div-inv73.0%
*-commutative73.0%
associate-*l*81.7%
Applied egg-rr81.7%
if -1.4499999999999999e69 < c < -1.11999999999999992e-108Initial program 92.2%
if -1.11999999999999992e-108 < c < 3.5e-119Initial program 67.7%
Taylor expanded in d around inf 91.1%
associate-/l*92.5%
Simplified92.5%
if 3.5e-119 < c < 4.49999999999999996e39Initial program 88.2%
fma-define88.2%
fma-define88.2%
Simplified88.2%
if 4.49999999999999996e39 < c < 1.19999999999999991e87Initial program 39.4%
Taylor expanded in c around 0 58.6%
associate-/l*64.7%
Simplified64.7%
pow264.7%
clear-num64.6%
un-div-inv64.7%
pow264.7%
Applied egg-rr64.7%
pow264.7%
*-un-lft-identity64.7%
times-frac76.0%
Applied egg-rr76.0%
if 1.19999999999999991e87 < c Initial program 34.1%
Taylor expanded in c around inf 80.7%
associate-/l*86.3%
Simplified86.3%
Final simplification87.7%
(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 (* d (* b (/ 1.0 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 = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (a + (d * (b * (1.0 / 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(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(a + Float64(d * Float64(b * Float64(1.0 / 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[(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[(d * N[(b * N[(1.0 / c), $MachinePrecision]), $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 + d \cdot \left(b \cdot \frac{1}{c}\right)}{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.5%
*-un-lft-identity74.5%
associate-*r/74.5%
fma-define74.5%
add-sqr-sqrt74.5%
times-frac74.6%
fma-define74.6%
hypot-define74.6%
fma-define74.6%
fma-define74.6%
hypot-define92.7%
Applied egg-rr92.7%
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 45.7%
div-inv45.7%
*-commutative45.7%
associate-*l*57.9%
Applied egg-rr57.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -1.65e+69)
(/ (+ a (* d (* b (/ 1.0 c)))) c)
(if (<= c -6.6e-109)
t_0
(if (<= c 1.16e-119)
(/ (+ b (* a (/ c d))) d)
(if (<= c 4.5e+39)
t_0
(if (<= c 1.2e+87)
(+ (/ b d) (/ a (* d (/ d c))))
(/ (+ a (* 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 <= -1.65e+69) {
tmp = (a + (d * (b * (1.0 / c)))) / c;
} else if (c <= -6.6e-109) {
tmp = t_0;
} else if (c <= 1.16e-119) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 4.5e+39) {
tmp = t_0;
} else if (c <= 1.2e+87) {
tmp = (b / d) + (a / (d * (d / c)));
} 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) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (c <= (-1.65d+69)) then
tmp = (a + (d * (b * (1.0d0 / c)))) / c
else if (c <= (-6.6d-109)) then
tmp = t_0
else if (c <= 1.16d-119) then
tmp = (b + (a * (c / d))) / d
else if (c <= 4.5d+39) then
tmp = t_0
else if (c <= 1.2d+87) then
tmp = (b / d) + (a / (d * (d / c)))
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 t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -1.65e+69) {
tmp = (a + (d * (b * (1.0 / c)))) / c;
} else if (c <= -6.6e-109) {
tmp = t_0;
} else if (c <= 1.16e-119) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 4.5e+39) {
tmp = t_0;
} else if (c <= 1.2e+87) {
tmp = (b / d) + (a / (d * (d / c)));
} else {
tmp = (a + (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 <= -1.65e+69: tmp = (a + (d * (b * (1.0 / c)))) / c elif c <= -6.6e-109: tmp = t_0 elif c <= 1.16e-119: tmp = (b + (a * (c / d))) / d elif c <= 4.5e+39: tmp = t_0 elif c <= 1.2e+87: tmp = (b / d) + (a / (d * (d / c))) else: tmp = (a + (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 <= -1.65e+69) tmp = Float64(Float64(a + Float64(d * Float64(b * Float64(1.0 / c)))) / c); elseif (c <= -6.6e-109) tmp = t_0; elseif (c <= 1.16e-119) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 4.5e+39) tmp = t_0; elseif (c <= 1.2e+87) tmp = Float64(Float64(b / d) + Float64(a / Float64(d * Float64(d / c)))); else tmp = Float64(Float64(a + 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 <= -1.65e+69) tmp = (a + (d * (b * (1.0 / c)))) / c; elseif (c <= -6.6e-109) tmp = t_0; elseif (c <= 1.16e-119) tmp = (b + (a * (c / d))) / d; elseif (c <= 4.5e+39) tmp = t_0; elseif (c <= 1.2e+87) tmp = (b / d) + (a / (d * (d / c))); else tmp = (a + (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, -1.65e+69], N[(N[(a + N[(d * N[(b * N[(1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -6.6e-109], t$95$0, If[LessEqual[c, 1.16e-119], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.5e+39], t$95$0, If[LessEqual[c, 1.2e+87], N[(N[(b / d), $MachinePrecision] + N[(a / N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $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 -1.65 \cdot 10^{+69}:\\
\;\;\;\;\frac{a + d \cdot \left(b \cdot \frac{1}{c}\right)}{c}\\
\mathbf{elif}\;c \leq -6.6 \cdot 10^{-109}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.16 \cdot 10^{-119}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 4.5 \cdot 10^{+39}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.2 \cdot 10^{+87}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -1.6499999999999999e69Initial program 36.7%
Taylor expanded in c around inf 73.0%
div-inv73.0%
*-commutative73.0%
associate-*l*81.7%
Applied egg-rr81.7%
if -1.6499999999999999e69 < c < -6.59999999999999981e-109 or 1.16e-119 < c < 4.49999999999999996e39Initial program 90.4%
if -6.59999999999999981e-109 < c < 1.16e-119Initial program 67.7%
Taylor expanded in d around inf 91.1%
associate-/l*92.5%
Simplified92.5%
if 4.49999999999999996e39 < c < 1.19999999999999991e87Initial program 39.4%
Taylor expanded in c around 0 58.6%
associate-/l*64.7%
Simplified64.7%
pow264.7%
clear-num64.6%
un-div-inv64.7%
pow264.7%
Applied egg-rr64.7%
pow264.7%
*-un-lft-identity64.7%
times-frac76.0%
Applied egg-rr76.0%
if 1.19999999999999991e87 < c Initial program 34.1%
Taylor expanded in c around inf 80.7%
associate-/l*86.3%
Simplified86.3%
Final simplification87.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.8e+30) (not (<= d 1.56e+41))) (/ (+ b (* a (/ c d))) d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.8e+30) || !(d <= 1.56e+41)) {
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 <= (-1.8d+30)) .or. (.not. (d <= 1.56d+41))) 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 <= -1.8e+30) || !(d <= 1.56e+41)) {
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 <= -1.8e+30) or not (d <= 1.56e+41): 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 <= -1.8e+30) || !(d <= 1.56e+41)) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.8e+30) || ~((d <= 1.56e+41))) 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, -1.8e+30], N[Not[LessEqual[d, 1.56e+41]], $MachinePrecision]], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.8 \cdot 10^{+30} \lor \neg \left(d \leq 1.56 \cdot 10^{+41}\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.8000000000000001e30 or 1.56e41 < d Initial program 51.3%
Taylor expanded in d around inf 79.1%
associate-/l*82.6%
Simplified82.6%
if -1.8000000000000001e30 < d < 1.56e41Initial program 67.1%
Taylor expanded in c around inf 79.1%
Final simplification80.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.05e+30) (not (<= d 3.1e+40))) (/ b d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.05e+30) || !(d <= 3.1e+40)) {
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+30)) .or. (.not. (d <= 3.1d+40))) 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+30) || !(d <= 3.1e+40)) {
tmp = b / d;
} else {
tmp = (a + ((b * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.05e+30) or not (d <= 3.1e+40): 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+30) || !(d <= 3.1e+40)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.05e+30) || ~((d <= 3.1e+40))) 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+30], N[Not[LessEqual[d, 3.1e+40]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.05 \cdot 10^{+30} \lor \neg \left(d \leq 3.1 \cdot 10^{+40}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.05e30 or 3.0999999999999998e40 < d Initial program 51.3%
Taylor expanded in c around 0 70.1%
if -1.05e30 < d < 3.0999999999999998e40Initial program 67.1%
Taylor expanded in c around inf 79.1%
Final simplification75.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.05e+30) (not (<= d 8e+40))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.05e+30) || !(d <= 8e+40)) {
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 <= (-2.05d+30)) .or. (.not. (d <= 8d+40))) 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 <= -2.05e+30) || !(d <= 8e+40)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.05e+30) or not (d <= 8e+40): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.05e+30) || !(d <= 8e+40)) 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 <= -2.05e+30) || ~((d <= 8e+40))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.05e+30], N[Not[LessEqual[d, 8e+40]], $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 -2.05 \cdot 10^{+30} \lor \neg \left(d \leq 8 \cdot 10^{+40}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -2.05000000000000003e30 or 8.00000000000000024e40 < d Initial program 51.3%
Taylor expanded in c around 0 70.1%
if -2.05000000000000003e30 < d < 8.00000000000000024e40Initial program 67.1%
Taylor expanded in c around inf 79.1%
associate-/l*78.5%
Simplified78.5%
Final simplification74.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.45e+17) (not (<= d 9e+39))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.45e+17) || !(d <= 9e+39)) {
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 <= (-2.45d+17)) .or. (.not. (d <= 9d+39))) 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 <= -2.45e+17) || !(d <= 9e+39)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.45e+17) or not (d <= 9e+39): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.45e+17) || !(d <= 9e+39)) 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 <= -2.45e+17) || ~((d <= 9e+39))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.45e+17], N[Not[LessEqual[d, 9e+39]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.45 \cdot 10^{+17} \lor \neg \left(d \leq 9 \cdot 10^{+39}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -2.45e17 or 8.99999999999999991e39 < d Initial program 51.3%
Taylor expanded in c around 0 69.5%
if -2.45e17 < d < 8.99999999999999991e39Initial program 67.5%
Taylor expanded in c around inf 65.6%
Final simplification67.4%
(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 60.0%
Taylor expanded in c around inf 44.3%
(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 2024105
(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))))