
(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 (<= d -7e+59)
(+ (/ b d) (* c (/ (/ a d) d)))
(if (<= d -1.15e-167)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 8.4e-105)
(* (/ -1.0 c) (- (- a) (/ (* b d) c)))
(if (<= d 4.2e+27)
(* (fma a c (* b d)) (/ 1.0 (pow (hypot c d) 2.0)))
(/ (+ b (/ a (/ d c))) (hypot c d)))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -7e+59) {
tmp = (b / d) + (c * ((a / d) / d));
} else if (d <= -1.15e-167) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 8.4e-105) {
tmp = (-1.0 / c) * (-a - ((b * d) / c));
} else if (d <= 4.2e+27) {
tmp = fma(a, c, (b * d)) * (1.0 / pow(hypot(c, d), 2.0));
} else {
tmp = (b + (a / (d / c))) / hypot(c, d);
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -7e+59) tmp = Float64(Float64(b / d) + Float64(c * Float64(Float64(a / d) / d))); elseif (d <= -1.15e-167) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 8.4e-105) tmp = Float64(Float64(-1.0 / c) * Float64(Float64(-a) - Float64(Float64(b * d) / c))); elseif (d <= 4.2e+27) tmp = Float64(fma(a, c, Float64(b * d)) * Float64(1.0 / (hypot(c, d) ^ 2.0))); else tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / hypot(c, d)); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -7e+59], N[(N[(b / d), $MachinePrecision] + N[(c * N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.15e-167], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 8.4e-105], N[(N[(-1.0 / c), $MachinePrecision] * N[((-a) - N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.2e+27], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -7 \cdot 10^{+59}:\\
\;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\
\mathbf{elif}\;d \leq -1.15 \cdot 10^{-167}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 8.4 \cdot 10^{-105}:\\
\;\;\;\;\frac{-1}{c} \cdot \left(\left(-a\right) - \frac{b \cdot d}{c}\right)\\
\mathbf{elif}\;d \leq 4.2 \cdot 10^{+27}:\\
\;\;\;\;\mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -7e59Initial program 51.2%
Taylor expanded in c around 0 86.6%
associate-/l*83.7%
associate-/r/88.7%
Simplified88.7%
*-un-lft-identity88.7%
pow288.7%
times-frac92.8%
Applied egg-rr92.8%
associate-*l/92.8%
*-un-lft-identity92.8%
Applied egg-rr92.8%
if -7e59 < d < -1.1500000000000001e-167Initial program 84.3%
if -1.1500000000000001e-167 < d < 8.3999999999999999e-105Initial program 66.6%
*-un-lft-identity66.6%
add-sqr-sqrt66.6%
times-frac66.6%
hypot-def66.7%
fma-def66.7%
hypot-def85.6%
Applied egg-rr85.6%
Taylor expanded in c around -inf 55.4%
Taylor expanded in c around -inf 92.6%
if 8.3999999999999999e-105 < d < 4.19999999999999989e27Initial program 87.9%
div-inv88.0%
fma-def88.0%
add-sqr-sqrt88.0%
pow288.0%
hypot-def88.0%
Applied egg-rr88.0%
if 4.19999999999999989e27 < d Initial program 53.0%
*-un-lft-identity53.0%
add-sqr-sqrt53.0%
times-frac53.0%
hypot-def53.0%
fma-def53.0%
hypot-def73.0%
Applied egg-rr73.0%
associate-*l/73.1%
*-un-lft-identity73.1%
Applied egg-rr73.1%
Taylor expanded in c around 0 90.1%
associate-/l*91.7%
Simplified91.7%
Final simplification90.4%
(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 77.7%
*-un-lft-identity77.7%
add-sqr-sqrt77.7%
times-frac77.7%
hypot-def77.7%
fma-def77.7%
hypot-def96.1%
Applied egg-rr96.1%
associate-*l/96.4%
*-un-lft-identity96.4%
Applied egg-rr96.4%
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 2.0%
*-commutative2.0%
Simplified2.0%
add-sqr-sqrt2.0%
hypot-udef2.0%
hypot-udef2.0%
times-frac52.0%
Applied egg-rr52.0%
Final simplification89.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -2.35e+60)
(+ (/ b d) (* c (/ (/ a d) d)))
(if (<= d -1.15e-167)
t_0
(if (<= d 1.6e-105)
(* (/ -1.0 c) (- (- a) (/ (* b d) c)))
(if (<= d 5.7e+35) t_0 (/ (+ b (/ a (/ d c))) (hypot c d))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -2.35e+60) {
tmp = (b / d) + (c * ((a / d) / d));
} else if (d <= -1.15e-167) {
tmp = t_0;
} else if (d <= 1.6e-105) {
tmp = (-1.0 / c) * (-a - ((b * d) / c));
} else if (d <= 5.7e+35) {
tmp = t_0;
} else {
tmp = (b + (a / (d / c))) / hypot(c, d);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -2.35e+60) {
tmp = (b / d) + (c * ((a / d) / d));
} else if (d <= -1.15e-167) {
tmp = t_0;
} else if (d <= 1.6e-105) {
tmp = (-1.0 / c) * (-a - ((b * d) / c));
} else if (d <= 5.7e+35) {
tmp = t_0;
} else {
tmp = (b + (a / (d / c))) / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -2.35e+60: tmp = (b / d) + (c * ((a / d) / d)) elif d <= -1.15e-167: tmp = t_0 elif d <= 1.6e-105: tmp = (-1.0 / c) * (-a - ((b * d) / c)) elif d <= 5.7e+35: tmp = t_0 else: tmp = (b + (a / (d / c))) / math.hypot(c, d) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (d <= -2.35e+60) tmp = Float64(Float64(b / d) + Float64(c * Float64(Float64(a / d) / d))); elseif (d <= -1.15e-167) tmp = t_0; elseif (d <= 1.6e-105) tmp = Float64(Float64(-1.0 / c) * Float64(Float64(-a) - Float64(Float64(b * d) / c))); elseif (d <= 5.7e+35) tmp = t_0; else tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / hypot(c, d)); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -2.35e+60) tmp = (b / d) + (c * ((a / d) / d)); elseif (d <= -1.15e-167) tmp = t_0; elseif (d <= 1.6e-105) tmp = (-1.0 / c) * (-a - ((b * d) / c)); elseif (d <= 5.7e+35) tmp = t_0; else tmp = (b + (a / (d / c))) / hypot(c, d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.35e+60], N[(N[(b / d), $MachinePrecision] + N[(c * N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.15e-167], t$95$0, If[LessEqual[d, 1.6e-105], N[(N[(-1.0 / c), $MachinePrecision] * N[((-a) - N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5.7e+35], t$95$0, N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -2.35 \cdot 10^{+60}:\\
\;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\
\mathbf{elif}\;d \leq -1.15 \cdot 10^{-167}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 1.6 \cdot 10^{-105}:\\
\;\;\;\;\frac{-1}{c} \cdot \left(\left(-a\right) - \frac{b \cdot d}{c}\right)\\
\mathbf{elif}\;d \leq 5.7 \cdot 10^{+35}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -2.3499999999999999e60Initial program 51.2%
Taylor expanded in c around 0 86.6%
associate-/l*83.7%
associate-/r/88.7%
Simplified88.7%
*-un-lft-identity88.7%
pow288.7%
times-frac92.8%
Applied egg-rr92.8%
associate-*l/92.8%
*-un-lft-identity92.8%
Applied egg-rr92.8%
if -2.3499999999999999e60 < d < -1.1500000000000001e-167 or 1.59999999999999991e-105 < d < 5.69999999999999993e35Initial program 85.7%
if -1.1500000000000001e-167 < d < 1.59999999999999991e-105Initial program 66.6%
*-un-lft-identity66.6%
add-sqr-sqrt66.6%
times-frac66.6%
hypot-def66.7%
fma-def66.7%
hypot-def85.6%
Applied egg-rr85.6%
Taylor expanded in c around -inf 55.4%
Taylor expanded in c around -inf 92.6%
if 5.69999999999999993e35 < d Initial program 52.2%
*-un-lft-identity52.2%
add-sqr-sqrt52.2%
times-frac52.2%
hypot-def52.2%
fma-def52.2%
hypot-def72.5%
Applied egg-rr72.5%
associate-*l/72.6%
*-un-lft-identity72.6%
Applied egg-rr72.6%
Taylor expanded in c around 0 89.9%
associate-/l*91.6%
Simplified91.6%
Final simplification90.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (+ (/ b d) (* c (/ (/ a d) d)))))
(if (<= d -1.65e+52)
t_1
(if (<= d -1.15e-167)
t_0
(if (<= d 1.18e-105)
(* (/ -1.0 c) (- (- a) (/ (* b d) c)))
(if (<= d 7.5e+28) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (b / d) + (c * ((a / d) / d));
double tmp;
if (d <= -1.65e+52) {
tmp = t_1;
} else if (d <= -1.15e-167) {
tmp = t_0;
} else if (d <= 1.18e-105) {
tmp = (-1.0 / c) * (-a - ((b * d) / c));
} else if (d <= 7.5e+28) {
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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
t_1 = (b / d) + (c * ((a / d) / d))
if (d <= (-1.65d+52)) then
tmp = t_1
else if (d <= (-1.15d-167)) then
tmp = t_0
else if (d <= 1.18d-105) then
tmp = ((-1.0d0) / c) * (-a - ((b * d) / c))
else if (d <= 7.5d+28) 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 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (b / d) + (c * ((a / d) / d));
double tmp;
if (d <= -1.65e+52) {
tmp = t_1;
} else if (d <= -1.15e-167) {
tmp = t_0;
} else if (d <= 1.18e-105) {
tmp = (-1.0 / c) * (-a - ((b * d) / c));
} else if (d <= 7.5e+28) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = (b / d) + (c * ((a / d) / d)) tmp = 0 if d <= -1.65e+52: tmp = t_1 elif d <= -1.15e-167: tmp = t_0 elif d <= 1.18e-105: tmp = (-1.0 / c) * (-a - ((b * d) / c)) elif d <= 7.5e+28: tmp = t_0 else: tmp = t_1 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))) t_1 = Float64(Float64(b / d) + Float64(c * Float64(Float64(a / d) / d))) tmp = 0.0 if (d <= -1.65e+52) tmp = t_1; elseif (d <= -1.15e-167) tmp = t_0; elseif (d <= 1.18e-105) tmp = Float64(Float64(-1.0 / c) * Float64(Float64(-a) - Float64(Float64(b * d) / c))); elseif (d <= 7.5e+28) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); t_1 = (b / d) + (c * ((a / d) / d)); tmp = 0.0; if (d <= -1.65e+52) tmp = t_1; elseif (d <= -1.15e-167) tmp = t_0; elseif (d <= 1.18e-105) tmp = (-1.0 / c) * (-a - ((b * d) / c)); elseif (d <= 7.5e+28) tmp = t_0; else tmp = t_1; 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]}, Block[{t$95$1 = N[(N[(b / d), $MachinePrecision] + N[(c * N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.65e+52], t$95$1, If[LessEqual[d, -1.15e-167], t$95$0, If[LessEqual[d, 1.18e-105], N[(N[(-1.0 / c), $MachinePrecision] * N[((-a) - N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7.5e+28], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\
\mathbf{if}\;d \leq -1.65 \cdot 10^{+52}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d \leq -1.15 \cdot 10^{-167}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 1.18 \cdot 10^{-105}:\\
\;\;\;\;\frac{-1}{c} \cdot \left(\left(-a\right) - \frac{b \cdot d}{c}\right)\\
\mathbf{elif}\;d \leq 7.5 \cdot 10^{+28}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if d < -1.65e52 or 7.4999999999999998e28 < d Initial program 52.2%
Taylor expanded in c around 0 84.8%
associate-/l*83.6%
associate-/r/85.8%
Simplified85.8%
*-un-lft-identity85.8%
pow285.8%
times-frac91.3%
Applied egg-rr91.3%
associate-*l/91.3%
*-un-lft-identity91.3%
Applied egg-rr91.3%
if -1.65e52 < d < -1.1500000000000001e-167 or 1.1799999999999999e-105 < d < 7.4999999999999998e28Initial program 85.5%
if -1.1500000000000001e-167 < d < 1.1799999999999999e-105Initial program 66.6%
*-un-lft-identity66.6%
add-sqr-sqrt66.6%
times-frac66.6%
hypot-def66.7%
fma-def66.7%
hypot-def85.6%
Applied egg-rr85.6%
Taylor expanded in c around -inf 55.4%
Taylor expanded in c around -inf 92.6%
Final simplification90.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.8e-69) (not (<= d 3.25e-68))) (+ (/ b d) (* c (/ (/ a d) d))) (* (/ -1.0 c) (- (- a) (/ (* b d) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.8e-69) || !(d <= 3.25e-68)) {
tmp = (b / d) + (c * ((a / 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 <= (-1.8d-69)) .or. (.not. (d <= 3.25d-68))) then
tmp = (b / d) + (c * ((a / 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 <= -1.8e-69) || !(d <= 3.25e-68)) {
tmp = (b / d) + (c * ((a / d) / d));
} else {
tmp = (-1.0 / c) * (-a - ((b * d) / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.8e-69) or not (d <= 3.25e-68): tmp = (b / d) + (c * ((a / d) / d)) else: tmp = (-1.0 / c) * (-a - ((b * d) / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.8e-69) || !(d <= 3.25e-68)) tmp = Float64(Float64(b / d) + Float64(c * Float64(Float64(a / d) / d))); else tmp = Float64(Float64(-1.0 / c) * Float64(Float64(-a) - Float64(Float64(b * d) / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.8e-69) || ~((d <= 3.25e-68))) tmp = (b / d) + (c * ((a / 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, -1.8e-69], N[Not[LessEqual[d, 3.25e-68]], $MachinePrecision]], N[(N[(b / d), $MachinePrecision] + N[(c * N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision]), $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 -1.8 \cdot 10^{-69} \lor \neg \left(d \leq 3.25 \cdot 10^{-68}\right):\\
\;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{c} \cdot \left(\left(-a\right) - \frac{b \cdot d}{c}\right)\\
\end{array}
\end{array}
if d < -1.80000000000000009e-69 or 3.2499999999999999e-68 < d Initial program 61.9%
Taylor expanded in c around 0 76.5%
associate-/l*75.7%
associate-/r/77.2%
Simplified77.2%
*-un-lft-identity77.2%
pow277.2%
times-frac80.8%
Applied egg-rr80.8%
associate-*l/80.8%
*-un-lft-identity80.8%
Applied egg-rr80.8%
if -1.80000000000000009e-69 < d < 3.2499999999999999e-68Initial program 73.1%
*-un-lft-identity73.1%
add-sqr-sqrt73.1%
times-frac73.0%
hypot-def73.1%
fma-def73.1%
hypot-def87.7%
Applied egg-rr87.7%
Taylor expanded in c around -inf 54.6%
Taylor expanded in c around -inf 89.5%
Final simplification84.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.7e-69) (not (<= d 1.28e-70))) (+ (/ b d) (* c (/ (/ a d) d))) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.7e-69) || !(d <= 1.28e-70)) {
tmp = (b / d) + (c * ((a / d) / 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 <= (-1.7d-69)) .or. (.not. (d <= 1.28d-70))) then
tmp = (b / d) + (c * ((a / d) / 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 <= -1.7e-69) || !(d <= 1.28e-70)) {
tmp = (b / d) + (c * ((a / d) / d));
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.7e-69) or not (d <= 1.28e-70): tmp = (b / d) + (c * ((a / d) / d)) else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.7e-69) || !(d <= 1.28e-70)) tmp = Float64(Float64(b / d) + Float64(c * Float64(Float64(a / d) / d))); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.7e-69) || ~((d <= 1.28e-70))) tmp = (b / d) + (c * ((a / d) / d)); else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.7e-69], N[Not[LessEqual[d, 1.28e-70]], $MachinePrecision]], N[(N[(b / d), $MachinePrecision] + N[(c * N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.7 \cdot 10^{-69} \lor \neg \left(d \leq 1.28 \cdot 10^{-70}\right):\\
\;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -1.70000000000000004e-69 or 1.28e-70 < d Initial program 61.9%
Taylor expanded in c around 0 76.5%
associate-/l*75.7%
associate-/r/77.2%
Simplified77.2%
*-un-lft-identity77.2%
pow277.2%
times-frac80.8%
Applied egg-rr80.8%
associate-*l/80.8%
*-un-lft-identity80.8%
Applied egg-rr80.8%
if -1.70000000000000004e-69 < d < 1.28e-70Initial program 73.1%
Taylor expanded in c around inf 65.1%
Final simplification74.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.0095) (not (<= d 1.35e-19))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.0095) || !(d <= 1.35e-19)) {
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 <= (-0.0095d0)) .or. (.not. (d <= 1.35d-19))) 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 <= -0.0095) || !(d <= 1.35e-19)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.0095) or not (d <= 1.35e-19): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.0095) || !(d <= 1.35e-19)) 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 <= -0.0095) || ~((d <= 1.35e-19))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.0095], N[Not[LessEqual[d, 1.35e-19]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.0095 \lor \neg \left(d \leq 1.35 \cdot 10^{-19}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -0.00949999999999999976 or 1.35e-19 < d Initial program 58.8%
Taylor expanded in c around 0 74.6%
if -0.00949999999999999976 < d < 1.35e-19Initial program 73.5%
Taylor expanded in c around inf 58.1%
Final simplification66.4%
(FPCore (a b c d) :precision binary64 (if (<= d 4.4e+126) (/ a c) (/ a d)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= 4.4e+126) {
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 <= 4.4d+126) 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 <= 4.4e+126) {
tmp = a / c;
} else {
tmp = a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= 4.4e+126: tmp = a / c else: tmp = a / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= 4.4e+126) 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 <= 4.4e+126) tmp = a / c; else tmp = a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, 4.4e+126], N[(a / c), $MachinePrecision], N[(a / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq 4.4 \cdot 10^{+126}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{d}\\
\end{array}
\end{array}
if d < 4.39999999999999997e126Initial program 70.7%
Taylor expanded in c around inf 40.9%
if 4.39999999999999997e126 < d Initial program 41.7%
*-un-lft-identity41.7%
add-sqr-sqrt41.7%
times-frac41.7%
hypot-def41.7%
fma-def41.7%
hypot-def68.2%
Applied egg-rr68.2%
Taylor expanded in c around -inf 3.0%
Taylor expanded in d around -inf 3.8%
+-commutative3.8%
Simplified3.8%
Taylor expanded in b around 0 19.2%
Final simplification37.5%
(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 66.1%
Taylor expanded in c around inf 35.4%
Final simplification35.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 2023320
(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))))