
(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 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 2e+285) (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d)) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 2e+285) {
tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = (b + (a * (c / d))) / d;
}
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))) <= 2e+285) tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); 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], 2e+285], 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[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+285}:\\
\;\;\;\;\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{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 2e285Initial program 80.7%
*-un-lft-identity80.7%
add-sqr-sqrt80.7%
times-frac80.6%
hypot-define80.6%
fma-define80.6%
hypot-define96.6%
Applied egg-rr96.6%
associate-*l/96.8%
*-un-lft-identity96.8%
Applied egg-rr96.8%
if 2e285 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 16.3%
Taylor expanded in d around inf 53.9%
associate-/l*61.5%
Simplified61.5%
Final simplification87.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -1.86e+30)
(/ (+ b (/ (* a c) d)) d)
(if (<= d -1.45e-158)
t_0
(if (<= d 2.6e-93)
(/ (+ a (/ (* b d) c)) c)
(if (<= d 2.7e+84)
t_0
(/ (+ b (* c (- (/ a d) (* b (/ c (pow d 2.0)))))) 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.86e+30) {
tmp = (b + ((a * c) / d)) / d;
} else if (d <= -1.45e-158) {
tmp = t_0;
} else if (d <= 2.6e-93) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 2.7e+84) {
tmp = t_0;
} else {
tmp = (b + (c * ((a / d) - (b * (c / pow(d, 2.0)))))) / 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) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (d <= (-1.86d+30)) then
tmp = (b + ((a * c) / d)) / d
else if (d <= (-1.45d-158)) then
tmp = t_0
else if (d <= 2.6d-93) then
tmp = (a + ((b * d) / c)) / c
else if (d <= 2.7d+84) then
tmp = t_0
else
tmp = (b + (c * ((a / d) - (b * (c / (d ** 2.0d0)))))) / d
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 <= -1.86e+30) {
tmp = (b + ((a * c) / d)) / d;
} else if (d <= -1.45e-158) {
tmp = t_0;
} else if (d <= 2.6e-93) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 2.7e+84) {
tmp = t_0;
} else {
tmp = (b + (c * ((a / d) - (b * (c / Math.pow(d, 2.0)))))) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -1.86e+30: tmp = (b + ((a * c) / d)) / d elif d <= -1.45e-158: tmp = t_0 elif d <= 2.6e-93: tmp = (a + ((b * d) / c)) / c elif d <= 2.7e+84: tmp = t_0 else: tmp = (b + (c * ((a / d) - (b * (c / math.pow(d, 2.0)))))) / 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.86e+30) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (d <= -1.45e-158) tmp = t_0; elseif (d <= 2.6e-93) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif (d <= 2.7e+84) tmp = t_0; else tmp = Float64(Float64(b + Float64(c * Float64(Float64(a / d) - Float64(b * Float64(c / (d ^ 2.0)))))) / 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.86e+30) tmp = (b + ((a * c) / d)) / d; elseif (d <= -1.45e-158) tmp = t_0; elseif (d <= 2.6e-93) tmp = (a + ((b * d) / c)) / c; elseif (d <= 2.7e+84) tmp = t_0; else tmp = (b + (c * ((a / d) - (b * (c / (d ^ 2.0)))))) / 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.86e+30], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -1.45e-158], t$95$0, If[LessEqual[d, 2.6e-93], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.7e+84], t$95$0, N[(N[(b + N[(c * N[(N[(a / d), $MachinePrecision] - N[(b * N[(c / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $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.86 \cdot 10^{+30}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;d \leq -1.45 \cdot 10^{-158}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.6 \cdot 10^{-93}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.7 \cdot 10^{+84}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b + c \cdot \left(\frac{a}{d} - b \cdot \frac{c}{{d}^{2}}\right)}{d}\\
\end{array}
\end{array}
if d < -1.8600000000000001e30Initial program 53.0%
Taylor expanded in d around inf 79.7%
if -1.8600000000000001e30 < d < -1.4499999999999999e-158 or 2.5999999999999998e-93 < d < 2.7e84Initial program 85.8%
if -1.4499999999999999e-158 < d < 2.5999999999999998e-93Initial program 66.0%
Taylor expanded in c around inf 91.2%
if 2.7e84 < d Initial program 44.7%
Taylor expanded in d around -inf 70.2%
Taylor expanded in c around 0 83.4%
+-commutative83.4%
mul-1-neg83.4%
unsub-neg83.4%
associate-/l*92.8%
Simplified92.8%
Final simplification87.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -1.86e+30)
(/ (+ b (/ (* a c) d)) d)
(if (<= d -1.48e-158)
t_0
(if (<= d 2.1e-96)
(/ (+ a (/ (* b d) c)) c)
(if (<= d 8e+84) t_0 (/ (+ b (* a (/ c d))) 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.86e+30) {
tmp = (b + ((a * c) / d)) / d;
} else if (d <= -1.48e-158) {
tmp = t_0;
} else if (d <= 2.1e-96) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 8e+84) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (d <= (-1.86d+30)) then
tmp = (b + ((a * c) / d)) / d
else if (d <= (-1.48d-158)) then
tmp = t_0
else if (d <= 2.1d-96) then
tmp = (a + ((b * d) / c)) / c
else if (d <= 8d+84) then
tmp = t_0
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 t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.86e+30) {
tmp = (b + ((a * c) / d)) / d;
} else if (d <= -1.48e-158) {
tmp = t_0;
} else if (d <= 2.1e-96) {
tmp = (a + ((b * d) / c)) / c;
} else if (d <= 8e+84) {
tmp = t_0;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -1.86e+30: tmp = (b + ((a * c) / d)) / d elif d <= -1.48e-158: tmp = t_0 elif d <= 2.1e-96: tmp = (a + ((b * d) / c)) / c elif d <= 8e+84: tmp = t_0 else: tmp = (b + (a * (c / d))) / 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.86e+30) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (d <= -1.48e-158) tmp = t_0; elseif (d <= 2.1e-96) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif (d <= 8e+84) tmp = t_0; else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / 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.86e+30) tmp = (b + ((a * c) / d)) / d; elseif (d <= -1.48e-158) tmp = t_0; elseif (d <= 2.1e-96) tmp = (a + ((b * d) / c)) / c; elseif (d <= 8e+84) tmp = t_0; else tmp = (b + (a * (c / d))) / 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.86e+30], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -1.48e-158], t$95$0, If[LessEqual[d, 2.1e-96], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 8e+84], t$95$0, N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $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.86 \cdot 10^{+30}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;d \leq -1.48 \cdot 10^{-158}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{-96}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 8 \cdot 10^{+84}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if d < -1.8600000000000001e30Initial program 53.0%
Taylor expanded in d around inf 79.7%
if -1.8600000000000001e30 < d < -1.48e-158 or 2.10000000000000001e-96 < d < 8.00000000000000046e84Initial program 85.8%
if -1.48e-158 < d < 2.10000000000000001e-96Initial program 66.0%
Taylor expanded in c around inf 91.2%
if 8.00000000000000046e84 < d Initial program 44.7%
Taylor expanded in d around inf 82.0%
associate-/l*91.2%
Simplified91.2%
Final simplification87.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.4e+59) (not (<= d 5.5e+41))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.4e+59) || !(d <= 5.5e+41)) {
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.4d+59)) .or. (.not. (d <= 5.5d+41))) 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.4e+59) || !(d <= 5.5e+41)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.4e+59) or not (d <= 5.5e+41): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.4e+59) || !(d <= 5.5e+41)) 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.4e+59) || ~((d <= 5.5e+41))) 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.4e+59], N[Not[LessEqual[d, 5.5e+41]], $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.4 \cdot 10^{+59} \lor \neg \left(d \leq 5.5 \cdot 10^{+41}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -2.4000000000000002e59 or 5.5000000000000003e41 < d Initial program 51.6%
Taylor expanded in c around 0 73.1%
if -2.4000000000000002e59 < d < 5.5000000000000003e41Initial program 73.5%
Taylor expanded in c around inf 76.2%
associate-/l*75.6%
Simplified75.6%
Final simplification74.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.45e+59) (not (<= d 9.5e+41))) (/ b d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.45e+59) || !(d <= 9.5e+41)) {
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.45d+59)) .or. (.not. (d <= 9.5d+41))) 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.45e+59) || !(d <= 9.5e+41)) {
tmp = b / d;
} else {
tmp = (a + ((b * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.45e+59) or not (d <= 9.5e+41): tmp = b / d else: tmp = (a + ((b * d) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.45e+59) || !(d <= 9.5e+41)) 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 <= -2.45e+59) || ~((d <= 9.5e+41))) 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.45e+59], N[Not[LessEqual[d, 9.5e+41]], $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 -2.45 \cdot 10^{+59} \lor \neg \left(d \leq 9.5 \cdot 10^{+41}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -2.45000000000000004e59 or 9.4999999999999996e41 < d Initial program 51.6%
Taylor expanded in c around 0 73.1%
if -2.45000000000000004e59 < d < 9.4999999999999996e41Initial program 73.5%
Taylor expanded in c around inf 76.2%
Final simplification74.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5.5e-11) (not (<= c 3.2e+36))) (/ (+ a (* b (/ d c))) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.5e-11) || !(c <= 3.2e+36)) {
tmp = (a + (b * (d / 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 <= (-5.5d-11)) .or. (.not. (c <= 3.2d+36))) then
tmp = (a + (b * (d / 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 <= -5.5e-11) || !(c <= 3.2e+36)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5.5e-11) or not (c <= 3.2e+36): tmp = (a + (b * (d / c))) / c else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5.5e-11) || !(c <= 3.2e+36)) tmp = Float64(Float64(a + Float64(b * Float64(d / 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 <= -5.5e-11) || ~((c <= 3.2e+36))) tmp = (a + (b * (d / c))) / c; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5.5e-11], N[Not[LessEqual[c, 3.2e+36]], $MachinePrecision]], N[(N[(a + N[(b * N[(d / 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 -5.5 \cdot 10^{-11} \lor \neg \left(c \leq 3.2 \cdot 10^{+36}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if c < -5.49999999999999975e-11 or 3.1999999999999999e36 < c Initial program 52.7%
Taylor expanded in c around inf 77.0%
associate-/l*79.0%
Simplified79.0%
if -5.49999999999999975e-11 < c < 3.1999999999999999e36Initial program 74.2%
Taylor expanded in d around inf 84.1%
associate-/l*84.4%
Simplified84.4%
Final simplification81.9%
(FPCore (a b c d) :precision binary64 (if (<= c -2.4e-9) (/ (+ a (* d (/ b c))) c) (if (<= c 7.5e+36) (/ (+ b (* a (/ c d))) d) (/ (+ a (* b (/ d c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.4e-9) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= 7.5e+36) {
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 (c <= (-2.4d-9)) then
tmp = (a + (d * (b / c))) / c
else if (c <= 7.5d+36) 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 (c <= -2.4e-9) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= 7.5e+36) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.4e-9: tmp = (a + (d * (b / c))) / c elif c <= 7.5e+36: 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 (c <= -2.4e-9) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); elseif (c <= 7.5e+36) 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 (c <= -2.4e-9) tmp = (a + (d * (b / c))) / c; elseif (c <= 7.5e+36) tmp = (b + (a * (c / d))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.4e-9], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 7.5e+36], 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}\;c \leq -2.4 \cdot 10^{-9}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq 7.5 \cdot 10^{+36}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -2.4e-9Initial program 67.5%
Taylor expanded in c around inf 80.3%
*-commutative80.3%
*-un-lft-identity80.3%
times-frac83.4%
Applied egg-rr83.4%
if -2.4e-9 < c < 7.50000000000000054e36Initial program 74.2%
Taylor expanded in d around inf 84.1%
associate-/l*84.4%
Simplified84.4%
if 7.50000000000000054e36 < c Initial program 35.5%
Taylor expanded in c around inf 73.2%
associate-/l*75.6%
Simplified75.6%
Final simplification82.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.5e-34) (not (<= c 1.75e-10))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.5e-34) || !(c <= 1.75e-10)) {
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 <= (-1.5d-34)) .or. (.not. (c <= 1.75d-10))) 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 <= -1.5e-34) || !(c <= 1.75e-10)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.5e-34) or not (c <= 1.75e-10): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.5e-34) || !(c <= 1.75e-10)) 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 <= -1.5e-34) || ~((c <= 1.75e-10))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.5e-34], N[Not[LessEqual[c, 1.75e-10]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.5 \cdot 10^{-34} \lor \neg \left(c \leq 1.75 \cdot 10^{-10}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -1.5e-34 or 1.7499999999999999e-10 < c Initial program 56.0%
Taylor expanded in c around inf 62.3%
if -1.5e-34 < c < 1.7499999999999999e-10Initial program 74.0%
Taylor expanded in c around 0 71.2%
Final simplification66.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 64.4%
Taylor expanded in c around inf 39.9%
Final simplification39.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 2024130
(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))))