
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * 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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * 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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d) :precision binary64 (fma (/ c (hypot c d)) (/ b (hypot c d)) (* a (* (/ d (hypot d c)) (/ -1.0 (hypot d c))))))
double code(double a, double b, double c, double d) {
return fma((c / hypot(c, d)), (b / hypot(c, d)), (a * ((d / hypot(d, c)) * (-1.0 / hypot(d, c)))));
}
function code(a, b, c, d) return fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a * Float64(Float64(d / hypot(d, c)) * Float64(-1.0 / hypot(d, c))))) end
code[a_, b_, c_, d_] := N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(a * N[(N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \left(\frac{d}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{-1}{\mathsf{hypot}\left(d, c\right)}\right)\right)
\end{array}
Initial program 63.6%
div-sub61.1%
*-commutative61.1%
add-sqr-sqrt61.1%
times-frac65.3%
fma-neg65.3%
hypot-define65.3%
hypot-define79.7%
associate-/l*82.9%
add-sqr-sqrt82.9%
pow282.9%
hypot-define82.9%
Applied egg-rr82.9%
Applied egg-rr96.0%
Final simplification96.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0
(fma
(/ c (hypot c d))
(/ b (hypot c d))
(* a (/ (- d) (pow (hypot c d) 2.0)))))
(t_1 (/ (- (* c (/ b d)) a) d)))
(if (<= d -4.4e+164)
t_1
(if (<= d -2.85e-162)
t_0
(if (<= d 2.1e-116)
(/ (- b (* a (/ d c))) c)
(if (<= d 7.2e+128) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma((c / hypot(c, d)), (b / hypot(c, d)), (a * (-d / pow(hypot(c, d), 2.0))));
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -4.4e+164) {
tmp = t_1;
} else if (d <= -2.85e-162) {
tmp = t_0;
} else if (d <= 2.1e-116) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 7.2e+128) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a * Float64(Float64(-d) / (hypot(c, d) ^ 2.0)))) t_1 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -4.4e+164) tmp = t_1; elseif (d <= -2.85e-162) tmp = t_0; elseif (d <= 2.1e-116) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 7.2e+128) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(a * N[((-d) / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -4.4e+164], t$95$1, If[LessEqual[d, -2.85e-162], t$95$0, If[LessEqual[d, 2.1e-116], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 7.2e+128], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\
t_1 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -4.4 \cdot 10^{+164}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -2.85 \cdot 10^{-162}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{-116}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 7.2 \cdot 10^{+128}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -4.40000000000000011e164 or 7.20000000000000054e128 < d Initial program 44.6%
Taylor expanded in c around 0 71.6%
+-commutative71.6%
mul-1-neg71.6%
unsub-neg71.6%
unpow271.6%
associate-/r*74.9%
div-sub74.9%
*-commutative74.9%
associate-/l*91.3%
Simplified91.3%
if -4.40000000000000011e164 < d < -2.8499999999999999e-162 or 2.0999999999999999e-116 < d < 7.20000000000000054e128Initial program 70.7%
div-sub70.7%
*-commutative70.7%
add-sqr-sqrt70.7%
times-frac75.0%
fma-neg75.0%
hypot-define75.0%
hypot-define86.7%
associate-/l*90.5%
add-sqr-sqrt90.5%
pow290.5%
hypot-define90.5%
Applied egg-rr90.5%
if -2.8499999999999999e-162 < d < 2.0999999999999999e-116Initial program 65.7%
Taylor expanded in c around inf 92.2%
remove-double-neg92.2%
mul-1-neg92.2%
neg-mul-192.2%
distribute-lft-in92.2%
mul-1-neg92.2%
distribute-neg-in92.2%
mul-1-neg92.2%
remove-double-neg92.2%
unsub-neg92.2%
associate-/l*92.3%
Simplified92.3%
Final simplification91.2%
(FPCore (a b c d)
:precision binary64
(if (or (<= d -3.5e+100) (not (<= d 1.8e+128)))
(/ (- (* c (/ b d)) a) d)
(fma
(/ c (hypot c d))
(/ b (hypot c d))
(/ (/ (* d a) (hypot d c)) (- (hypot d c))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.5e+100) || !(d <= 1.8e+128)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (((d * a) / hypot(d, c)) / -hypot(d, c)));
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.5e+100) || !(d <= 1.8e+128)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); else tmp = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(Float64(Float64(d * a) / hypot(d, c)) / Float64(-hypot(d, c)))); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.5e+100], N[Not[LessEqual[d, 1.8e+128]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(d * a), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / (-N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.5 \cdot 10^{+100} \lor \neg \left(d \leq 1.8 \cdot 10^{+128}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{\frac{d \cdot a}{\mathsf{hypot}\left(d, c\right)}}{-\mathsf{hypot}\left(d, c\right)}\right)\\
\end{array}
\end{array}
if d < -3.49999999999999976e100 or 1.80000000000000014e128 < d Initial program 39.7%
Taylor expanded in c around 0 70.0%
+-commutative70.0%
mul-1-neg70.0%
unsub-neg70.0%
unpow270.0%
associate-/r*72.8%
div-sub72.8%
*-commutative72.8%
associate-/l*86.8%
Simplified86.8%
if -3.49999999999999976e100 < d < 1.80000000000000014e128Initial program 71.6%
div-sub68.2%
*-commutative68.2%
add-sqr-sqrt68.2%
times-frac72.7%
fma-neg72.7%
hypot-define72.7%
hypot-define87.1%
associate-/l*87.6%
add-sqr-sqrt87.6%
pow287.6%
hypot-define87.6%
Applied egg-rr87.6%
Applied egg-rr97.3%
Final simplification94.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (pow (hypot c d) 2.0)) (t_1 (/ (- (* c (/ b d)) a) d)))
(if (<= d -1.4e+115)
t_1
(if (<= d -3.6e-55)
(fma c (/ b t_0) (* a (/ (- d) t_0)))
(if (<= d 1.32e-61)
(/ (- b (* a (/ d c))) c)
(if (<= d 2e+122)
(/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = pow(hypot(c, d), 2.0);
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -1.4e+115) {
tmp = t_1;
} else if (d <= -3.6e-55) {
tmp = fma(c, (b / t_0), (a * (-d / t_0)));
} else if (d <= 1.32e-61) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 2e+122) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = hypot(c, d) ^ 2.0 t_1 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -1.4e+115) tmp = t_1; elseif (d <= -3.6e-55) tmp = fma(c, Float64(b / t_0), Float64(a * Float64(Float64(-d) / t_0))); elseif (d <= 1.32e-61) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 2e+122) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.4e+115], t$95$1, If[LessEqual[d, -3.6e-55], N[(c * N[(b / t$95$0), $MachinePrecision] + N[(a * N[((-d) / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.32e-61], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2e+122], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}\\
t_1 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -1.4 \cdot 10^{+115}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -3.6 \cdot 10^{-55}:\\
\;\;\;\;\mathsf{fma}\left(c, \frac{b}{t\_0}, a \cdot \frac{-d}{t\_0}\right)\\
\mathbf{elif}\;d \leq 1.32 \cdot 10^{-61}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 2 \cdot 10^{+122}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.4e115 or 2.00000000000000003e122 < d Initial program 42.0%
Taylor expanded in c around 0 69.6%
+-commutative69.6%
mul-1-neg69.6%
unsub-neg69.6%
unpow269.6%
associate-/r*72.6%
div-sub72.6%
*-commutative72.6%
associate-/l*87.4%
Simplified87.4%
if -1.4e115 < d < -3.6000000000000001e-55Initial program 67.1%
div-sub67.1%
*-commutative67.1%
associate-/l*76.1%
fma-neg76.1%
add-sqr-sqrt76.1%
pow276.1%
hypot-define76.1%
associate-/l*87.0%
add-sqr-sqrt87.0%
pow287.0%
hypot-define87.0%
Applied egg-rr87.0%
if -3.6000000000000001e-55 < d < 1.32000000000000002e-61Initial program 66.5%
Taylor expanded in c around inf 88.6%
remove-double-neg88.6%
mul-1-neg88.6%
neg-mul-188.6%
distribute-lft-in88.6%
mul-1-neg88.6%
distribute-neg-in88.6%
mul-1-neg88.6%
remove-double-neg88.6%
unsub-neg88.6%
associate-/l*88.7%
Simplified88.7%
if 1.32000000000000002e-61 < d < 2.00000000000000003e122Initial program 82.3%
Final simplification87.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d))))
(t_1 (/ (- (* c (/ b d)) a) d)))
(if (<= d -2.7e+83)
t_1
(if (<= d -7e-56)
t_0
(if (<= d 1e-61)
(/ (- b (* a (/ d c))) c)
(if (<= d 1.35e+123) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -2.7e+83) {
tmp = t_1;
} else if (d <= -7e-56) {
tmp = t_0;
} else if (d <= 1e-61) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 1.35e+123) {
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 = ((c * b) - (d * a)) / ((c * c) + (d * d))
t_1 = ((c * (b / d)) - a) / d
if (d <= (-2.7d+83)) then
tmp = t_1
else if (d <= (-7d-56)) then
tmp = t_0
else if (d <= 1d-61) then
tmp = (b - (a * (d / c))) / c
else if (d <= 1.35d+123) 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 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -2.7e+83) {
tmp = t_1;
} else if (d <= -7e-56) {
tmp = t_0;
} else if (d <= 1e-61) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 1.35e+123) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)) t_1 = ((c * (b / d)) - a) / d tmp = 0 if d <= -2.7e+83: tmp = t_1 elif d <= -7e-56: tmp = t_0 elif d <= 1e-61: tmp = (b - (a * (d / c))) / c elif d <= 1.35e+123: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -2.7e+83) tmp = t_1; elseif (d <= -7e-56) tmp = t_0; elseif (d <= 1e-61) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 1.35e+123) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)); t_1 = ((c * (b / d)) - a) / d; tmp = 0.0; if (d <= -2.7e+83) tmp = t_1; elseif (d <= -7e-56) tmp = t_0; elseif (d <= 1e-61) tmp = (b - (a * (d / c))) / c; elseif (d <= 1.35e+123) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.7e+83], t$95$1, If[LessEqual[d, -7e-56], t$95$0, If[LessEqual[d, 1e-61], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.35e+123], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
t_1 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -2.7 \cdot 10^{+83}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -7 \cdot 10^{-56}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 10^{-61}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.35 \cdot 10^{+123}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -2.70000000000000007e83 or 1.35000000000000007e123 < d Initial program 39.6%
Taylor expanded in c around 0 67.1%
+-commutative67.1%
mul-1-neg67.1%
unsub-neg67.1%
unpow267.1%
associate-/r*69.8%
div-sub69.8%
*-commutative69.8%
associate-/l*85.9%
Simplified85.9%
if -2.70000000000000007e83 < d < -6.9999999999999996e-56 or 1e-61 < d < 1.35000000000000007e123Initial program 81.9%
if -6.9999999999999996e-56 < d < 1e-61Initial program 66.2%
Taylor expanded in c around inf 89.3%
remove-double-neg89.3%
mul-1-neg89.3%
neg-mul-189.3%
distribute-lft-in89.3%
mul-1-neg89.3%
distribute-neg-in89.3%
mul-1-neg89.3%
remove-double-neg89.3%
unsub-neg89.3%
associate-/l*89.4%
Simplified89.4%
Final simplification86.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5e+20) (not (<= d 1.05e+68))) (/ a (- d)) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5e+20) || !(d <= 1.05e+68)) {
tmp = a / -d;
} else {
tmp = (b - (a * (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 <= (-5d+20)) .or. (.not. (d <= 1.05d+68))) then
tmp = a / -d
else
tmp = (b - (a * (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 <= -5e+20) || !(d <= 1.05e+68)) {
tmp = a / -d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5e+20) or not (d <= 1.05e+68): tmp = a / -d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5e+20) || !(d <= 1.05e+68)) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -5e+20) || ~((d <= 1.05e+68))) tmp = a / -d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5e+20], N[Not[LessEqual[d, 1.05e+68]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5 \cdot 10^{+20} \lor \neg \left(d \leq 1.05 \cdot 10^{+68}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -5e20 or 1.05e68 < d Initial program 48.6%
Taylor expanded in c around 0 68.2%
associate-*r/68.2%
neg-mul-168.2%
Simplified68.2%
if -5e20 < d < 1.05e68Initial program 72.0%
Taylor expanded in c around inf 78.4%
remove-double-neg78.4%
mul-1-neg78.4%
neg-mul-178.4%
distribute-lft-in78.4%
mul-1-neg78.4%
distribute-neg-in78.4%
mul-1-neg78.4%
remove-double-neg78.4%
unsub-neg78.4%
associate-/l*78.4%
Simplified78.4%
Final simplification74.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.3e-55) (not (<= d 5.2e-38))) (/ (- (* b (/ c d)) a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.3e-55) || !(d <= 5.2e-38)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-1.3d-55)) .or. (.not. (d <= 5.2d-38))) then
tmp = ((b * (c / d)) - a) / d
else
tmp = (b - (a * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.3e-55) || !(d <= 5.2e-38)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.3e-55) or not (d <= 5.2e-38): tmp = ((b * (c / d)) - a) / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.3e-55) || !(d <= 5.2e-38)) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.3e-55) || ~((d <= 5.2e-38))) tmp = ((b * (c / d)) - a) / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.3e-55], N[Not[LessEqual[d, 5.2e-38]], $MachinePrecision]], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.3 \cdot 10^{-55} \lor \neg \left(d \leq 5.2 \cdot 10^{-38}\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.2999999999999999e-55 or 5.20000000000000022e-38 < d Initial program 60.8%
div-sub60.8%
*-commutative60.8%
add-sqr-sqrt60.8%
times-frac63.2%
fma-neg63.2%
hypot-define63.2%
hypot-define73.4%
associate-/l*79.3%
add-sqr-sqrt79.3%
pow279.3%
hypot-define79.3%
Applied egg-rr79.3%
Taylor expanded in d around inf 64.9%
associate-/l*72.1%
Simplified72.1%
if -1.2999999999999999e-55 < d < 5.20000000000000022e-38Initial program 66.8%
Taylor expanded in c around inf 88.7%
remove-double-neg88.7%
mul-1-neg88.7%
neg-mul-188.7%
distribute-lft-in88.7%
mul-1-neg88.7%
distribute-neg-in88.7%
mul-1-neg88.7%
remove-double-neg88.7%
unsub-neg88.7%
associate-/l*88.8%
Simplified88.8%
Final simplification79.9%
(FPCore (a b c d) :precision binary64 (if (<= d -1.3e-55) (/ (- (* b (/ c d)) a) d) (if (<= d 3.6e-38) (/ (- b (* a (/ d c))) c) (/ (- (* c (/ b d)) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.3e-55) {
tmp = ((b * (c / d)) - a) / d;
} else if (d <= 3.6e-38) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((c * (b / d)) - 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 <= (-1.3d-55)) then
tmp = ((b * (c / d)) - a) / d
else if (d <= 3.6d-38) then
tmp = (b - (a * (d / c))) / c
else
tmp = ((c * (b / d)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.3e-55) {
tmp = ((b * (c / d)) - a) / d;
} else if (d <= 3.6e-38) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.3e-55: tmp = ((b * (c / d)) - a) / d elif d <= 3.6e-38: tmp = (b - (a * (d / c))) / c else: tmp = ((c * (b / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.3e-55) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (d <= 3.6e-38) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.3e-55) tmp = ((b * (c / d)) - a) / d; elseif (d <= 3.6e-38) tmp = (b - (a * (d / c))) / c; else tmp = ((c * (b / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.3e-55], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 3.6e-38], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.3 \cdot 10^{-55}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;d \leq 3.6 \cdot 10^{-38}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if d < -1.2999999999999999e-55Initial program 52.6%
div-sub52.6%
*-commutative52.6%
add-sqr-sqrt52.6%
times-frac55.9%
fma-neg55.9%
hypot-define55.9%
hypot-define64.9%
associate-/l*75.4%
add-sqr-sqrt75.4%
pow275.4%
hypot-define75.4%
Applied egg-rr75.4%
Taylor expanded in d around inf 65.3%
associate-/l*70.2%
Simplified70.2%
if -1.2999999999999999e-55 < d < 3.6000000000000001e-38Initial program 66.8%
Taylor expanded in c around inf 88.7%
remove-double-neg88.7%
mul-1-neg88.7%
neg-mul-188.7%
distribute-lft-in88.7%
mul-1-neg88.7%
distribute-neg-in88.7%
mul-1-neg88.7%
remove-double-neg88.7%
unsub-neg88.7%
associate-/l*88.8%
Simplified88.8%
if 3.6000000000000001e-38 < d Initial program 67.9%
Taylor expanded in c around 0 64.8%
+-commutative64.8%
mul-1-neg64.8%
unsub-neg64.8%
unpow264.8%
associate-/r*64.5%
div-sub64.5%
*-commutative64.5%
associate-/l*73.9%
Simplified73.9%
Final simplification80.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.75e-42) (not (<= d 3e-61))) (/ a (- d)) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.75e-42) || !(d <= 3e-61)) {
tmp = a / -d;
} else {
tmp = b / 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.75d-42)) .or. (.not. (d <= 3d-61))) then
tmp = a / -d
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.75e-42) || !(d <= 3e-61)) {
tmp = a / -d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.75e-42) or not (d <= 3e-61): tmp = a / -d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.75e-42) || !(d <= 3e-61)) tmp = Float64(a / Float64(-d)); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.75e-42) || ~((d <= 3e-61))) tmp = a / -d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.75e-42], N[Not[LessEqual[d, 3e-61]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.75 \cdot 10^{-42} \lor \neg \left(d \leq 3 \cdot 10^{-61}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -1.7500000000000001e-42 or 3.00000000000000012e-61 < d Initial program 61.1%
Taylor expanded in c around 0 58.3%
associate-*r/58.3%
neg-mul-158.3%
Simplified58.3%
if -1.7500000000000001e-42 < d < 3.00000000000000012e-61Initial program 66.5%
Taylor expanded in c around inf 69.9%
Final simplification63.7%
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
return b / 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 = b / c
end function
public static double code(double a, double b, double c, double d) {
return b / c;
}
def code(a, b, c, d): return b / c
function code(a, b, c, d) return Float64(b / c) end
function tmp = code(a, b, c, d) tmp = b / c; end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{c}
\end{array}
Initial program 63.6%
Taylor expanded in c around inf 43.8%
Final simplification43.8%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (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 = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (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 = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (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(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * 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 = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (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[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * 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{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024077
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))