
(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 11 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))) INFINITY) (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d)) (* (/ c (hypot c d)) (/ a (hypot c d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = (c / hypot(c, d)) * (a / hypot(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))) <= Inf) tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(c / hypot(c, d)) * Float64(a / hypot(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], Infinity], N[(N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $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 \infty:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 80.4%
*-un-lft-identity80.4%
associate-*r/80.4%
fma-define80.4%
add-sqr-sqrt80.4%
times-frac80.3%
fma-define80.3%
hypot-define80.4%
fma-define80.4%
fma-define80.4%
hypot-define94.9%
Applied egg-rr94.9%
associate-*l/95.0%
*-un-lft-identity95.0%
Applied egg-rr95.0%
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 a around inf 1.1%
*-commutative1.1%
rem-square-sqrt1.1%
unpow21.1%
unpow21.1%
hypot-undefine1.1%
unpow21.1%
unpow21.1%
hypot-undefine1.1%
unpow21.1%
hypot-undefine1.1%
unpow21.1%
unpow21.1%
+-commutative1.1%
unpow21.1%
unpow21.1%
hypot-define1.1%
Simplified1.1%
hypot-undefine1.1%
+-commutative1.1%
hypot-undefine1.1%
pow21.1%
times-frac62.4%
Applied egg-rr62.4%
Final simplification87.9%
(FPCore (a b c d)
:precision binary64
(if (<= d -170.0)
(/ (- (- b) (* c (/ a d))) (hypot c d))
(if (<= d 1.05e-24)
(+ (/ a c) (/ (/ (* b d) c) c))
(if (<= d 2.85e+76)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(* (/ 1.0 (hypot c d)) (+ b (* a (/ c d))))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -170.0) {
tmp = (-b - (c * (a / d))) / hypot(c, d);
} else if (d <= 1.05e-24) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 2.85e+76) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (1.0 / hypot(c, d)) * (b + (a * (c / d)));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -170.0) {
tmp = (-b - (c * (a / d))) / Math.hypot(c, d);
} else if (d <= 1.05e-24) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 2.85e+76) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (1.0 / Math.hypot(c, d)) * (b + (a * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -170.0: tmp = (-b - (c * (a / d))) / math.hypot(c, d) elif d <= 1.05e-24: tmp = (a / c) + (((b * d) / c) / c) elif d <= 2.85e+76: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) else: tmp = (1.0 / math.hypot(c, d)) * (b + (a * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -170.0) tmp = Float64(Float64(Float64(-b) - Float64(c * Float64(a / d))) / hypot(c, d)); elseif (d <= 1.05e-24) tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); elseif (d <= 2.85e+76) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(b + Float64(a * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -170.0) tmp = (-b - (c * (a / d))) / hypot(c, d); elseif (d <= 1.05e-24) tmp = (a / c) + (((b * d) / c) / c); elseif (d <= 2.85e+76) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); else tmp = (1.0 / hypot(c, d)) * (b + (a * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -170.0], N[(N[((-b) - N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.05e-24], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.85e+76], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -170:\\
\;\;\;\;\frac{\left(-b\right) - c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq 1.05 \cdot 10^{-24}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.85 \cdot 10^{+76}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + a \cdot \frac{c}{d}\right)\\
\end{array}
\end{array}
if d < -170Initial program 50.2%
*-un-lft-identity50.2%
associate-*r/50.2%
fma-define50.2%
add-sqr-sqrt50.2%
times-frac50.1%
fma-define50.1%
hypot-define50.1%
fma-define50.1%
fma-define50.1%
hypot-define63.8%
Applied egg-rr63.8%
Taylor expanded in d around -inf 71.0%
frac-2neg71.0%
metadata-eval71.0%
associate-*l/71.1%
Applied egg-rr77.6%
if -170 < d < 1.05e-24Initial program 69.3%
Taylor expanded in c around inf 80.2%
associate-/l*77.1%
Simplified77.1%
pow277.1%
associate-*r/80.2%
associate-/r*86.7%
Applied egg-rr86.7%
if 1.05e-24 < d < 2.85000000000000002e76Initial program 94.4%
if 2.85000000000000002e76 < d Initial program 53.8%
*-un-lft-identity53.8%
associate-*r/53.8%
fma-define53.8%
add-sqr-sqrt53.8%
times-frac53.8%
fma-define53.8%
hypot-define53.8%
fma-define53.8%
fma-define53.8%
hypot-define68.0%
Applied egg-rr68.0%
Taylor expanded in c around 0 78.8%
associate-/l*86.5%
Simplified86.5%
Final simplification84.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* c (/ a d))))
(if (<= d -26000.0)
(/ (- (- b) t_0) (hypot c d))
(if (<= d 1e-24)
(+ (/ a c) (/ (/ (* b d) c) c))
(if (<= d 7e+91)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(+ (/ b d) (* t_0 (/ 1.0 d))))))))
double code(double a, double b, double c, double d) {
double t_0 = c * (a / d);
double tmp;
if (d <= -26000.0) {
tmp = (-b - t_0) / hypot(c, d);
} else if (d <= 1e-24) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 7e+91) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (b / d) + (t_0 * (1.0 / d));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = c * (a / d);
double tmp;
if (d <= -26000.0) {
tmp = (-b - t_0) / Math.hypot(c, d);
} else if (d <= 1e-24) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 7e+91) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (b / d) + (t_0 * (1.0 / d));
}
return tmp;
}
def code(a, b, c, d): t_0 = c * (a / d) tmp = 0 if d <= -26000.0: tmp = (-b - t_0) / math.hypot(c, d) elif d <= 1e-24: tmp = (a / c) + (((b * d) / c) / c) elif d <= 7e+91: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) else: tmp = (b / d) + (t_0 * (1.0 / d)) return tmp
function code(a, b, c, d) t_0 = Float64(c * Float64(a / d)) tmp = 0.0 if (d <= -26000.0) tmp = Float64(Float64(Float64(-b) - t_0) / hypot(c, d)); elseif (d <= 1e-24) tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); elseif (d <= 7e+91) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(Float64(b / d) + Float64(t_0 * Float64(1.0 / d))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = c * (a / d); tmp = 0.0; if (d <= -26000.0) tmp = (-b - t_0) / hypot(c, d); elseif (d <= 1e-24) tmp = (a / c) + (((b * d) / c) / c); elseif (d <= 7e+91) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); else tmp = (b / d) + (t_0 * (1.0 / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -26000.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1e-24], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7e+91], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(t$95$0 * N[(1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \frac{a}{d}\\
\mathbf{if}\;d \leq -26000:\\
\;\;\;\;\frac{\left(-b\right) - t\_0}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq 10^{-24}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 7 \cdot 10^{+91}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + t\_0 \cdot \frac{1}{d}\\
\end{array}
\end{array}
if d < -26000Initial program 50.2%
*-un-lft-identity50.2%
associate-*r/50.2%
fma-define50.2%
add-sqr-sqrt50.2%
times-frac50.1%
fma-define50.1%
hypot-define50.1%
fma-define50.1%
fma-define50.1%
hypot-define63.8%
Applied egg-rr63.8%
Taylor expanded in d around -inf 71.0%
frac-2neg71.0%
metadata-eval71.0%
associate-*l/71.1%
Applied egg-rr77.6%
if -26000 < d < 9.99999999999999924e-25Initial program 69.3%
Taylor expanded in c around inf 80.2%
associate-/l*77.1%
Simplified77.1%
pow277.1%
associate-*r/80.2%
associate-/r*86.7%
Applied egg-rr86.7%
if 9.99999999999999924e-25 < d < 7.00000000000000001e91Initial program 94.9%
if 7.00000000000000001e91 < d Initial program 52.0%
Taylor expanded in c around 0 75.8%
*-un-lft-identity75.8%
unpow275.8%
times-frac77.8%
*-commutative77.8%
associate-/l*85.7%
Applied egg-rr85.7%
Final simplification84.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ b d) (* (* c (/ a d)) (/ 1.0 d)))))
(if (<= d -1150.0)
t_0
(if (<= d 4e-24)
(+ (/ a c) (/ (/ (* b d) c) c))
(if (<= d 7.3e+90) (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b / d) + ((c * (a / d)) * (1.0 / d));
double tmp;
if (d <= -1150.0) {
tmp = t_0;
} else if (d <= 4e-24) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 7.3e+90) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = (b / d) + ((c * (a / d)) * (1.0d0 / d))
if (d <= (-1150.0d0)) then
tmp = t_0
else if (d <= 4d-24) then
tmp = (a / c) + (((b * d) / c) / c)
else if (d <= 7.3d+90) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b / d) + ((c * (a / d)) * (1.0 / d));
double tmp;
if (d <= -1150.0) {
tmp = t_0;
} else if (d <= 4e-24) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 7.3e+90) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b / d) + ((c * (a / d)) * (1.0 / d)) tmp = 0 if d <= -1150.0: tmp = t_0 elif d <= 4e-24: tmp = (a / c) + (((b * d) / c) / c) elif d <= 7.3e+90: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b / d) + Float64(Float64(c * Float64(a / d)) * Float64(1.0 / d))) tmp = 0.0 if (d <= -1150.0) tmp = t_0; elseif (d <= 4e-24) tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); elseif (d <= 7.3e+90) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b / d) + ((c * (a / d)) * (1.0 / d)); tmp = 0.0; if (d <= -1150.0) tmp = t_0; elseif (d <= 4e-24) tmp = (a / c) + (((b * d) / c) / c); elseif (d <= 7.3e+90) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] * N[(1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1150.0], t$95$0, If[LessEqual[d, 4e-24], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7.3e+90], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{d} + \left(c \cdot \frac{a}{d}\right) \cdot \frac{1}{d}\\
\mathbf{if}\;d \leq -1150:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 4 \cdot 10^{-24}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 7.3 \cdot 10^{+90}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1150 or 7.29999999999999995e90 < d Initial program 50.9%
Taylor expanded in c around 0 71.9%
*-un-lft-identity71.9%
unpow271.9%
times-frac73.8%
*-commutative73.8%
associate-/l*80.8%
Applied egg-rr80.8%
if -1150 < d < 3.99999999999999969e-24Initial program 69.3%
Taylor expanded in c around inf 80.2%
associate-/l*77.1%
Simplified77.1%
pow277.1%
associate-*r/80.2%
associate-/r*86.7%
Applied egg-rr86.7%
if 3.99999999999999969e-24 < d < 7.29999999999999995e90Initial program 94.9%
Final simplification84.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -145000.0) (not (<= d 0.0145))) (+ (/ b d) (* (* c (/ a d)) (/ 1.0 d))) (+ (/ a c) (/ (/ (* b d) c) c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -145000.0) || !(d <= 0.0145)) {
tmp = (b / d) + ((c * (a / d)) * (1.0 / d));
} 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) :: tmp
if ((d <= (-145000.0d0)) .or. (.not. (d <= 0.0145d0))) then
tmp = (b / d) + ((c * (a / d)) * (1.0d0 / d))
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 tmp;
if ((d <= -145000.0) || !(d <= 0.0145)) {
tmp = (b / d) + ((c * (a / d)) * (1.0 / d));
} else {
tmp = (a / c) + (((b * d) / c) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -145000.0) or not (d <= 0.0145): tmp = (b / d) + ((c * (a / d)) * (1.0 / d)) else: tmp = (a / c) + (((b * d) / c) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -145000.0) || !(d <= 0.0145)) tmp = Float64(Float64(b / d) + Float64(Float64(c * Float64(a / d)) * Float64(1.0 / d))); else tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -145000.0) || ~((d <= 0.0145))) tmp = (b / d) + ((c * (a / d)) * (1.0 / d)); else tmp = (a / c) + (((b * d) / c) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -145000.0], N[Not[LessEqual[d, 0.0145]], $MachinePrecision]], N[(N[(b / d), $MachinePrecision] + N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] * N[(1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -145000 \lor \neg \left(d \leq 0.0145\right):\\
\;\;\;\;\frac{b}{d} + \left(c \cdot \frac{a}{d}\right) \cdot \frac{1}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -145000 or 0.0145000000000000007 < d Initial program 56.0%
Taylor expanded in c around 0 72.0%
*-un-lft-identity72.0%
unpow272.0%
times-frac73.7%
*-commutative73.7%
associate-/l*79.9%
Applied egg-rr79.9%
if -145000 < d < 0.0145000000000000007Initial program 70.3%
Taylor expanded in c around inf 79.8%
associate-/l*76.8%
Simplified76.8%
pow276.8%
associate-*r/79.8%
associate-/r*85.9%
Applied egg-rr85.9%
Final simplification82.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -82000.0) (not (<= d 1.9e+21))) (/ b d) (* (/ 1.0 c) (+ a (* b (/ d c))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -82000.0) || !(d <= 1.9e+21)) {
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 <= (-82000.0d0)) .or. (.not. (d <= 1.9d+21))) 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 <= -82000.0) || !(d <= 1.9e+21)) {
tmp = b / d;
} else {
tmp = (1.0 / c) * (a + (b * (d / c)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -82000.0) or not (d <= 1.9e+21): 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 <= -82000.0) || !(d <= 1.9e+21)) tmp = Float64(b / d); else tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b * Float64(d / c)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -82000.0) || ~((d <= 1.9e+21))) 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, -82000.0], N[Not[LessEqual[d, 1.9e+21]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -82000 \lor \neg \left(d \leq 1.9 \cdot 10^{+21}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + b \cdot \frac{d}{c}\right)\\
\end{array}
\end{array}
if d < -82000 or 1.9e21 < d Initial program 55.0%
Taylor expanded in c around 0 65.0%
if -82000 < d < 1.9e21Initial program 70.9%
*-un-lft-identity70.9%
associate-*r/70.9%
fma-define70.9%
add-sqr-sqrt70.9%
times-frac70.9%
fma-define70.9%
hypot-define71.0%
fma-define71.0%
fma-define70.9%
hypot-define81.8%
Applied egg-rr81.8%
Taylor expanded in c around inf 46.8%
associate-/l*46.3%
Simplified46.3%
Taylor expanded in c around inf 84.2%
Final simplification74.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -40000.0) (not (<= d 6.4))) (* (+ b (* c (/ a d))) (/ 1.0 d)) (* (/ 1.0 c) (+ a (* b (/ d c))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -40000.0) || !(d <= 6.4)) {
tmp = (b + (c * (a / d))) * (1.0 / 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 <= (-40000.0d0)) .or. (.not. (d <= 6.4d0))) then
tmp = (b + (c * (a / d))) * (1.0d0 / 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 <= -40000.0) || !(d <= 6.4)) {
tmp = (b + (c * (a / d))) * (1.0 / d);
} else {
tmp = (1.0 / c) * (a + (b * (d / c)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -40000.0) or not (d <= 6.4): tmp = (b + (c * (a / d))) * (1.0 / d) else: tmp = (1.0 / c) * (a + (b * (d / c))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -40000.0) || !(d <= 6.4)) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) * Float64(1.0 / d)); else tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b * Float64(d / c)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -40000.0) || ~((d <= 6.4))) tmp = (b + (c * (a / d))) * (1.0 / d); else tmp = (1.0 / c) * (a + (b * (d / c))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -40000.0], N[Not[LessEqual[d, 6.4]], $MachinePrecision]], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / d), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -40000 \lor \neg \left(d \leq 6.4\right):\\
\;\;\;\;\left(b + c \cdot \frac{a}{d}\right) \cdot \frac{1}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + b \cdot \frac{d}{c}\right)\\
\end{array}
\end{array}
if d < -4e4 or 6.4000000000000004 < d Initial program 56.0%
Taylor expanded in c around 0 72.0%
*-un-lft-identity72.0%
unpow272.0%
times-frac73.7%
*-commutative73.7%
associate-/l*79.9%
Applied egg-rr79.9%
+-commutative79.9%
*-commutative79.9%
div-inv79.8%
distribute-rgt-out79.8%
Applied egg-rr79.8%
if -4e4 < d < 6.4000000000000004Initial program 70.3%
*-un-lft-identity70.3%
associate-*r/70.3%
fma-define70.2%
add-sqr-sqrt70.2%
times-frac70.2%
fma-define70.2%
hypot-define70.3%
fma-define70.3%
fma-define70.2%
hypot-define81.4%
Applied egg-rr81.4%
Taylor expanded in c around inf 47.9%
associate-/l*47.4%
Simplified47.4%
Taylor expanded in c around inf 85.3%
Final simplification82.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -82000.0) (not (<= d 380.0))) (* (+ b (* c (/ a d))) (/ 1.0 d)) (+ (/ a c) (/ (/ (* b d) c) c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -82000.0) || !(d <= 380.0)) {
tmp = (b + (c * (a / d))) * (1.0 / d);
} 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) :: tmp
if ((d <= (-82000.0d0)) .or. (.not. (d <= 380.0d0))) then
tmp = (b + (c * (a / d))) * (1.0d0 / d)
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 tmp;
if ((d <= -82000.0) || !(d <= 380.0)) {
tmp = (b + (c * (a / d))) * (1.0 / d);
} else {
tmp = (a / c) + (((b * d) / c) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -82000.0) or not (d <= 380.0): tmp = (b + (c * (a / d))) * (1.0 / d) else: tmp = (a / c) + (((b * d) / c) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -82000.0) || !(d <= 380.0)) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) * Float64(1.0 / d)); else tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -82000.0) || ~((d <= 380.0))) tmp = (b + (c * (a / d))) * (1.0 / d); else tmp = (a / c) + (((b * d) / c) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -82000.0], N[Not[LessEqual[d, 380.0]], $MachinePrecision]], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / d), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -82000 \lor \neg \left(d \leq 380\right):\\
\;\;\;\;\left(b + c \cdot \frac{a}{d}\right) \cdot \frac{1}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -82000 or 380 < d Initial program 56.0%
Taylor expanded in c around 0 72.0%
*-un-lft-identity72.0%
unpow272.0%
times-frac73.7%
*-commutative73.7%
associate-/l*79.9%
Applied egg-rr79.9%
+-commutative79.9%
*-commutative79.9%
div-inv79.8%
distribute-rgt-out79.8%
Applied egg-rr79.8%
if -82000 < d < 380Initial program 70.3%
Taylor expanded in c around inf 79.8%
associate-/l*76.8%
Simplified76.8%
pow276.8%
associate-*r/79.8%
associate-/r*85.9%
Applied egg-rr85.9%
Final simplification82.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -50000.0) (not (<= d 4.3e+20))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -50000.0) || !(d <= 4.3e+20)) {
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 <= (-50000.0d0)) .or. (.not. (d <= 4.3d+20))) 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 <= -50000.0) || !(d <= 4.3e+20)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -50000.0) or not (d <= 4.3e+20): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -50000.0) || !(d <= 4.3e+20)) 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 <= -50000.0) || ~((d <= 4.3e+20))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -50000.0], N[Not[LessEqual[d, 4.3e+20]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -50000 \lor \neg \left(d \leq 4.3 \cdot 10^{+20}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -5e4 or 4.3e20 < d Initial program 55.0%
Taylor expanded in c around 0 65.0%
if -5e4 < d < 4.3e20Initial program 70.9%
Taylor expanded in c around inf 64.8%
Final simplification64.9%
(FPCore (a b c d) :precision binary64 (if (<= d 2e+218) (/ a c) (/ a d)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= 2e+218) {
tmp = a / c;
} else {
tmp = a / 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 (d <= 2d+218) then
tmp = a / c
else
tmp = a / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= 2e+218) {
tmp = a / c;
} else {
tmp = a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= 2e+218: tmp = a / c else: tmp = a / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= 2e+218) tmp = Float64(a / c); else tmp = Float64(a / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= 2e+218) tmp = a / c; else tmp = a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, 2e+218], N[(a / c), $MachinePrecision], N[(a / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq 2 \cdot 10^{+218}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{d}\\
\end{array}
\end{array}
if d < 2.00000000000000017e218Initial program 63.4%
Taylor expanded in c around inf 44.6%
if 2.00000000000000017e218 < d Initial program 57.1%
*-un-lft-identity57.1%
associate-*r/57.1%
fma-define57.1%
add-sqr-sqrt57.1%
times-frac57.1%
fma-define57.1%
hypot-define57.1%
fma-define57.1%
fma-define57.1%
hypot-define72.5%
Applied egg-rr72.5%
Taylor expanded in d around -inf 57.3%
Taylor expanded in c around -inf 39.4%
Final simplification44.1%
(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.8%
Taylor expanded in c around inf 41.7%
Final simplification41.7%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024044
(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))))