
(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 (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 5e+299) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (* (/ -1.0 c) (- (- a) (/ b (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 5e+299) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (-1.0 / c) * (-a - (b / (c / 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))) <= 5e+299) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(-1.0 / c) * Float64(Float64(-a) - Float64(b / Float64(c / 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], 5e+299], 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[(-1.0 / c), $MachinePrecision] * N[((-a) - N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 5 \cdot 10^{+299}:\\
\;\;\;\;\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{-1}{c} \cdot \left(\left(-a\right) - \frac{b}{\frac{c}{d}}\right)\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 5.0000000000000003e299Initial program 76.4%
*-un-lft-identity76.4%
add-sqr-sqrt76.4%
times-frac76.4%
hypot-def76.5%
fma-def76.5%
hypot-def96.9%
Applied egg-rr96.9%
if 5.0000000000000003e299 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 12.6%
*-un-lft-identity12.6%
add-sqr-sqrt12.6%
times-frac12.6%
hypot-def12.6%
fma-def12.6%
hypot-def18.1%
Applied egg-rr18.1%
Taylor expanded in c around -inf 30.2%
neg-mul-130.2%
+-commutative30.2%
unsub-neg30.2%
mul-1-neg30.2%
associate-/l*35.2%
distribute-neg-frac35.2%
Simplified35.2%
Taylor expanded in c around -inf 67.6%
Final simplification90.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* (/ 1.0 c) (+ a (/ (* b d) c)))))
(if (<= d -2.6e+34)
(* (+ b (/ a (/ d c))) (/ -1.0 (hypot c d)))
(if (<= d 6e-175)
t_0
(if (<= d 8e+39)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 7.2e+68) t_0 (+ (/ b d) (/ (/ (* a c) d) d))))))))
double code(double a, double b, double c, double d) {
double t_0 = (1.0 / c) * (a + ((b * d) / c));
double tmp;
if (d <= -2.6e+34) {
tmp = (b + (a / (d / c))) * (-1.0 / hypot(c, d));
} else if (d <= 6e-175) {
tmp = t_0;
} else if (d <= 8e+39) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 7.2e+68) {
tmp = t_0;
} else {
tmp = (b / d) + (((a * c) / d) / d);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = (1.0 / c) * (a + ((b * d) / c));
double tmp;
if (d <= -2.6e+34) {
tmp = (b + (a / (d / c))) * (-1.0 / Math.hypot(c, d));
} else if (d <= 6e-175) {
tmp = t_0;
} else if (d <= 8e+39) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 7.2e+68) {
tmp = t_0;
} else {
tmp = (b / d) + (((a * c) / d) / d);
}
return tmp;
}
def code(a, b, c, d): t_0 = (1.0 / c) * (a + ((b * d) / c)) tmp = 0 if d <= -2.6e+34: tmp = (b + (a / (d / c))) * (-1.0 / math.hypot(c, d)) elif d <= 6e-175: tmp = t_0 elif d <= 8e+39: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif d <= 7.2e+68: tmp = t_0 else: tmp = (b / d) + (((a * c) / d) / d) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(1.0 / c) * Float64(a + Float64(Float64(b * d) / c))) tmp = 0.0 if (d <= -2.6e+34) tmp = Float64(Float64(b + Float64(a / Float64(d / c))) * Float64(-1.0 / hypot(c, d))); elseif (d <= 6e-175) tmp = t_0; elseif (d <= 8e+39) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 7.2e+68) tmp = t_0; else tmp = Float64(Float64(b / d) + Float64(Float64(Float64(a * c) / d) / d)); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (1.0 / c) * (a + ((b * d) / c)); tmp = 0.0; if (d <= -2.6e+34) tmp = (b + (a / (d / c))) * (-1.0 / hypot(c, d)); elseif (d <= 6e-175) tmp = t_0; elseif (d <= 8e+39) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (d <= 7.2e+68) tmp = t_0; else tmp = (b / d) + (((a * c) / d) / d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.6e+34], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6e-175], t$95$0, If[LessEqual[d, 8e+39], 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, 7.2e+68], t$95$0, N[(N[(b / d), $MachinePrecision] + N[(N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\mathbf{if}\;d \leq -2.6 \cdot 10^{+34}:\\
\;\;\;\;\left(b + \frac{a}{\frac{d}{c}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq 6 \cdot 10^{-175}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 8 \cdot 10^{+39}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 7.2 \cdot 10^{+68}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\
\end{array}
\end{array}
if d < -2.59999999999999997e34Initial program 44.3%
*-un-lft-identity44.3%
add-sqr-sqrt44.3%
times-frac44.4%
hypot-def44.4%
fma-def44.4%
hypot-def77.0%
Applied egg-rr77.0%
Taylor expanded in d around -inf 85.6%
neg-mul-185.6%
+-commutative85.6%
unsub-neg85.6%
mul-1-neg85.6%
associate-/l*89.8%
distribute-neg-frac89.8%
Simplified89.8%
if -2.59999999999999997e34 < d < 6e-175 or 7.99999999999999952e39 < d < 7.1999999999999998e68Initial program 64.4%
*-un-lft-identity64.4%
add-sqr-sqrt64.4%
times-frac64.5%
hypot-def64.5%
fma-def64.5%
hypot-def77.7%
Applied egg-rr77.7%
Taylor expanded in c around inf 46.3%
Taylor expanded in c around inf 86.8%
if 6e-175 < d < 7.99999999999999952e39Initial program 83.2%
if 7.1999999999999998e68 < d Initial program 48.1%
Taylor expanded in c around 0 77.1%
associate-/l*77.3%
associate-/r/77.2%
Simplified77.2%
pow277.2%
associate-*l/77.1%
associate-/r*87.3%
Applied egg-rr87.3%
Final simplification86.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* (/ 1.0 c) (+ a (/ (* b d) c))))
(t_1 (+ (/ b d) (/ (/ (* a c) d) d))))
(if (<= d -1.2e+34)
t_1
(if (<= d 6e-175)
t_0
(if (<= d 8e+39)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 1.4e+69) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = (1.0 / c) * (a + ((b * d) / c));
double t_1 = (b / d) + (((a * c) / d) / d);
double tmp;
if (d <= -1.2e+34) {
tmp = t_1;
} else if (d <= 6e-175) {
tmp = t_0;
} else if (d <= 8e+39) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 1.4e+69) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (1.0d0 / c) * (a + ((b * d) / c))
t_1 = (b / d) + (((a * c) / d) / d)
if (d <= (-1.2d+34)) then
tmp = t_1
else if (d <= 6d-175) then
tmp = t_0
else if (d <= 8d+39) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else if (d <= 1.4d+69) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (1.0 / c) * (a + ((b * d) / c));
double t_1 = (b / d) + (((a * c) / d) / d);
double tmp;
if (d <= -1.2e+34) {
tmp = t_1;
} else if (d <= 6e-175) {
tmp = t_0;
} else if (d <= 8e+39) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 1.4e+69) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = (1.0 / c) * (a + ((b * d) / c)) t_1 = (b / d) + (((a * c) / d) / d) tmp = 0 if d <= -1.2e+34: tmp = t_1 elif d <= 6e-175: tmp = t_0 elif d <= 8e+39: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif d <= 1.4e+69: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(1.0 / c) * Float64(a + Float64(Float64(b * d) / c))) t_1 = Float64(Float64(b / d) + Float64(Float64(Float64(a * c) / d) / d)) tmp = 0.0 if (d <= -1.2e+34) tmp = t_1; elseif (d <= 6e-175) tmp = t_0; elseif (d <= 8e+39) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 1.4e+69) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (1.0 / c) * (a + ((b * d) / c)); t_1 = (b / d) + (((a * c) / d) / d); tmp = 0.0; if (d <= -1.2e+34) tmp = t_1; elseif (d <= 6e-175) tmp = t_0; elseif (d <= 8e+39) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (d <= 1.4e+69) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / d), $MachinePrecision] + N[(N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.2e+34], t$95$1, If[LessEqual[d, 6e-175], t$95$0, If[LessEqual[d, 8e+39], 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.4e+69], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
t_1 := \frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\
\mathbf{if}\;d \leq -1.2 \cdot 10^{+34}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d \leq 6 \cdot 10^{-175}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 8 \cdot 10^{+39}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 1.4 \cdot 10^{+69}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if d < -1.19999999999999993e34 or 1.39999999999999991e69 < d Initial program 46.2%
Taylor expanded in c around 0 75.7%
associate-/l*75.9%
associate-/r/77.5%
Simplified77.5%
pow277.5%
associate-*l/75.7%
associate-/r*85.9%
Applied egg-rr85.9%
if -1.19999999999999993e34 < d < 6e-175 or 7.99999999999999952e39 < d < 1.39999999999999991e69Initial program 64.4%
*-un-lft-identity64.4%
add-sqr-sqrt64.4%
times-frac64.5%
hypot-def64.5%
fma-def64.5%
hypot-def77.7%
Applied egg-rr77.7%
Taylor expanded in c around inf 46.3%
Taylor expanded in c around inf 86.8%
if 6e-175 < d < 7.99999999999999952e39Initial program 83.2%
Final simplification85.7%
(FPCore (a b c d)
:precision binary64
(if (or (<= d -8e+33)
(not
(or (<= d 5400000000000.0) (and (not (<= d 7.5e+38)) (<= d 1e+69)))))
(/ b d)
(* (/ 1.0 c) (+ a (/ (* b d) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -8e+33) || !((d <= 5400000000000.0) || (!(d <= 7.5e+38) && (d <= 1e+69)))) {
tmp = b / d;
} else {
tmp = (1.0 / c) * (a + ((b * d) / c));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-8d+33)) .or. (.not. (d <= 5400000000000.0d0) .or. (.not. (d <= 7.5d+38)) .and. (d <= 1d+69))) then
tmp = b / d
else
tmp = (1.0d0 / c) * (a + ((b * d) / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -8e+33) || !((d <= 5400000000000.0) || (!(d <= 7.5e+38) && (d <= 1e+69)))) {
tmp = b / d;
} else {
tmp = (1.0 / c) * (a + ((b * d) / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -8e+33) or not ((d <= 5400000000000.0) or (not (d <= 7.5e+38) and (d <= 1e+69))): tmp = b / d else: tmp = (1.0 / c) * (a + ((b * d) / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -8e+33) || !((d <= 5400000000000.0) || (!(d <= 7.5e+38) && (d <= 1e+69)))) tmp = Float64(b / d); else tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(Float64(b * d) / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -8e+33) || ~(((d <= 5400000000000.0) || (~((d <= 7.5e+38)) && (d <= 1e+69))))) tmp = b / d; else tmp = (1.0 / c) * (a + ((b * d) / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -8e+33], N[Not[Or[LessEqual[d, 5400000000000.0], And[N[Not[LessEqual[d, 7.5e+38]], $MachinePrecision], LessEqual[d, 1e+69]]]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -8 \cdot 10^{+33} \lor \neg \left(d \leq 5400000000000 \lor \neg \left(d \leq 7.5 \cdot 10^{+38}\right) \land d \leq 10^{+69}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\end{array}
\end{array}
if d < -7.9999999999999996e33 or 5.4e12 < d < 7.4999999999999999e38 or 1.0000000000000001e69 < d Initial program 51.8%
Taylor expanded in c around 0 72.0%
if -7.9999999999999996e33 < d < 5.4e12 or 7.4999999999999999e38 < d < 1.0000000000000001e69Initial program 69.0%
*-un-lft-identity69.0%
add-sqr-sqrt69.0%
times-frac69.0%
hypot-def69.1%
fma-def69.1%
hypot-def80.1%
Applied egg-rr80.1%
Taylor expanded in c around inf 41.8%
Taylor expanded in c around inf 81.8%
Final simplification77.8%
(FPCore (a b c d)
:precision binary64
(if (or (<= d -6.2e+33)
(and (not (<= d 8e-5)) (or (<= d 8e+39) (not (<= d 7.2e+68)))))
(+ (/ b d) (/ (/ (* a c) d) d))
(* (/ 1.0 c) (+ a (/ (* b d) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.2e+33) || (!(d <= 8e-5) && ((d <= 8e+39) || !(d <= 7.2e+68)))) {
tmp = (b / d) + (((a * c) / d) / d);
} else {
tmp = (1.0 / c) * (a + ((b * d) / c));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-6.2d+33)) .or. (.not. (d <= 8d-5)) .and. (d <= 8d+39) .or. (.not. (d <= 7.2d+68))) then
tmp = (b / d) + (((a * c) / d) / d)
else
tmp = (1.0d0 / c) * (a + ((b * d) / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.2e+33) || (!(d <= 8e-5) && ((d <= 8e+39) || !(d <= 7.2e+68)))) {
tmp = (b / d) + (((a * c) / d) / d);
} else {
tmp = (1.0 / c) * (a + ((b * d) / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -6.2e+33) or (not (d <= 8e-5) and ((d <= 8e+39) or not (d <= 7.2e+68))): tmp = (b / d) + (((a * c) / d) / d) else: tmp = (1.0 / c) * (a + ((b * d) / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -6.2e+33) || (!(d <= 8e-5) && ((d <= 8e+39) || !(d <= 7.2e+68)))) tmp = Float64(Float64(b / d) + Float64(Float64(Float64(a * c) / d) / d)); else tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(Float64(b * d) / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -6.2e+33) || (~((d <= 8e-5)) && ((d <= 8e+39) || ~((d <= 7.2e+68))))) tmp = (b / d) + (((a * c) / d) / d); else tmp = (1.0 / c) * (a + ((b * d) / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6.2e+33], And[N[Not[LessEqual[d, 8e-5]], $MachinePrecision], Or[LessEqual[d, 8e+39], N[Not[LessEqual[d, 7.2e+68]], $MachinePrecision]]]], N[(N[(b / d), $MachinePrecision] + N[(N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.2 \cdot 10^{+33} \lor \neg \left(d \leq 8 \cdot 10^{-5}\right) \land \left(d \leq 8 \cdot 10^{+39} \lor \neg \left(d \leq 7.2 \cdot 10^{+68}\right)\right):\\
\;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\end{array}
\end{array}
if d < -6.2e33 or 8.00000000000000065e-5 < d < 7.99999999999999952e39 or 7.1999999999999998e68 < d Initial program 52.7%
Taylor expanded in c around 0 75.9%
associate-/l*75.2%
associate-/r/77.4%
Simplified77.4%
pow277.4%
associate-*l/75.9%
associate-/r*84.6%
Applied egg-rr84.6%
if -6.2e33 < d < 8.00000000000000065e-5 or 7.99999999999999952e39 < d < 7.1999999999999998e68Initial program 68.8%
*-un-lft-identity68.8%
add-sqr-sqrt68.8%
times-frac68.9%
hypot-def68.9%
fma-def68.9%
hypot-def79.6%
Applied egg-rr79.6%
Taylor expanded in c around inf 42.9%
Taylor expanded in c around inf 82.6%
Final simplification83.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.2e-89) (not (<= c 6.3e-18))) (* (/ -1.0 c) (- (- a) (/ b (/ c d)))) (+ (/ b d) (/ (/ (* a c) d) d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.2e-89) || !(c <= 6.3e-18)) {
tmp = (-1.0 / c) * (-a - (b / (c / d)));
} else {
tmp = (b / d) + (((a * c) / d) / d);
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-2.2d-89)) .or. (.not. (c <= 6.3d-18))) then
tmp = ((-1.0d0) / c) * (-a - (b / (c / d)))
else
tmp = (b / d) + (((a * c) / d) / d)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.2e-89) || !(c <= 6.3e-18)) {
tmp = (-1.0 / c) * (-a - (b / (c / d)));
} else {
tmp = (b / d) + (((a * c) / d) / d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.2e-89) or not (c <= 6.3e-18): tmp = (-1.0 / c) * (-a - (b / (c / d))) else: tmp = (b / d) + (((a * c) / d) / d) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.2e-89) || !(c <= 6.3e-18)) tmp = Float64(Float64(-1.0 / c) * Float64(Float64(-a) - Float64(b / Float64(c / d)))); else tmp = Float64(Float64(b / d) + Float64(Float64(Float64(a * c) / d) / d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.2e-89) || ~((c <= 6.3e-18))) tmp = (-1.0 / c) * (-a - (b / (c / d))); else tmp = (b / d) + (((a * c) / d) / d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.2e-89], N[Not[LessEqual[c, 6.3e-18]], $MachinePrecision]], N[(N[(-1.0 / c), $MachinePrecision] * N[((-a) - N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.2 \cdot 10^{-89} \lor \neg \left(c \leq 6.3 \cdot 10^{-18}\right):\\
\;\;\;\;\frac{-1}{c} \cdot \left(\left(-a\right) - \frac{b}{\frac{c}{d}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\
\end{array}
\end{array}
if c < -2.20000000000000012e-89 or 6.3000000000000004e-18 < c Initial program 53.5%
*-un-lft-identity53.5%
add-sqr-sqrt53.5%
times-frac53.5%
hypot-def53.5%
fma-def53.5%
hypot-def71.9%
Applied egg-rr71.9%
Taylor expanded in c around -inf 49.7%
neg-mul-149.7%
+-commutative49.7%
unsub-neg49.7%
mul-1-neg49.7%
associate-/l*51.6%
distribute-neg-frac51.6%
Simplified51.6%
Taylor expanded in c around -inf 75.8%
if -2.20000000000000012e-89 < c < 6.3000000000000004e-18Initial program 74.4%
Taylor expanded in c around 0 80.4%
associate-/l*80.7%
associate-/r/78.9%
Simplified78.9%
pow278.9%
associate-*l/80.4%
associate-/r*88.1%
Applied egg-rr88.1%
Final simplification80.8%
(FPCore (a b c d)
:precision binary64
(if (or (<= d -3.1e+34)
(not
(or (<= d 1850000000000.0)
(and (not (<= d 8e+39)) (<= d 1.05e+70)))))
(/ b d)
(/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.1e+34) || !((d <= 1850000000000.0) || (!(d <= 8e+39) && (d <= 1.05e+70)))) {
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 <= (-3.1d+34)) .or. (.not. (d <= 1850000000000.0d0) .or. (.not. (d <= 8d+39)) .and. (d <= 1.05d+70))) 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 <= -3.1e+34) || !((d <= 1850000000000.0) || (!(d <= 8e+39) && (d <= 1.05e+70)))) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.1e+34) or not ((d <= 1850000000000.0) or (not (d <= 8e+39) and (d <= 1.05e+70))): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.1e+34) || !((d <= 1850000000000.0) || (!(d <= 8e+39) && (d <= 1.05e+70)))) 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 <= -3.1e+34) || ~(((d <= 1850000000000.0) || (~((d <= 8e+39)) && (d <= 1.05e+70))))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.1e+34], N[Not[Or[LessEqual[d, 1850000000000.0], And[N[Not[LessEqual[d, 8e+39]], $MachinePrecision], LessEqual[d, 1.05e+70]]]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.1 \cdot 10^{+34} \lor \neg \left(d \leq 1850000000000 \lor \neg \left(d \leq 8 \cdot 10^{+39}\right) \land d \leq 1.05 \cdot 10^{+70}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -3.09999999999999977e34 or 1.85e12 < d < 7.99999999999999952e39 or 1.05000000000000004e70 < d Initial program 51.8%
Taylor expanded in c around 0 72.0%
if -3.09999999999999977e34 < d < 1.85e12 or 7.99999999999999952e39 < d < 1.05000000000000004e70Initial program 69.0%
Taylor expanded in c around inf 70.0%
Final simplification70.8%
(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.0%
Taylor expanded in c around inf 47.4%
Final simplification47.4%
(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 2023332
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:herbie-target
(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))))