
(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 9 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)) (* (/ (/ d (hypot d c)) (hypot d c)) (- a))))
double code(double a, double b, double c, double d) {
return fma((c / hypot(c, d)), (b / hypot(c, d)), (((d / hypot(d, c)) / hypot(d, c)) * -a));
}
function code(a, b, c, d) return fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(Float64(Float64(d / hypot(d, c)) / hypot(d, c)) * Float64(-a))) 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[(N[(N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{\frac{d}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)} \cdot \left(-a\right)\right)
\end{array}
Initial program 56.8%
div-sub53.6%
*-commutative53.6%
add-sqr-sqrt53.6%
times-frac57.8%
fma-neg57.8%
hypot-define57.8%
hypot-define77.1%
associate-/l*81.9%
add-sqr-sqrt81.9%
pow281.9%
hypot-define81.9%
Applied egg-rr81.9%
*-un-lft-identity81.9%
unpow281.9%
times-frac97.6%
add-sqr-sqrt49.5%
sqrt-prod59.3%
sqr-neg59.3%
sqrt-unprod29.0%
add-sqr-sqrt60.8%
hypot-undefine57.9%
+-commutative57.9%
hypot-define60.8%
add-sqr-sqrt29.0%
sqrt-unprod59.3%
sqr-neg59.3%
sqrt-prod49.5%
add-sqr-sqrt97.6%
hypot-undefine82.0%
+-commutative82.0%
hypot-define97.6%
Applied egg-rr97.6%
associate-*l/97.6%
*-lft-identity97.6%
Simplified97.6%
Final simplification97.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ c (hypot c d)))
(t_1 (/ b (hypot c d)))
(t_2 (fma t_0 t_1 (* (/ d (pow (hypot c d) 2.0)) (- a))))
(t_3 (fma t_0 t_1 (/ a (- d)))))
(if (<= d -9e+153)
t_3
(if (<= d -1e-160)
t_2
(if (<= d 3.8e-168)
(/ (- b (/ (* d a) c)) c)
(if (<= d 1.3e+128) t_2 t_3))))))
double code(double a, double b, double c, double d) {
double t_0 = c / hypot(c, d);
double t_1 = b / hypot(c, d);
double t_2 = fma(t_0, t_1, ((d / pow(hypot(c, d), 2.0)) * -a));
double t_3 = fma(t_0, t_1, (a / -d));
double tmp;
if (d <= -9e+153) {
tmp = t_3;
} else if (d <= -1e-160) {
tmp = t_2;
} else if (d <= 3.8e-168) {
tmp = (b - ((d * a) / c)) / c;
} else if (d <= 1.3e+128) {
tmp = t_2;
} else {
tmp = t_3;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(c / hypot(c, d)) t_1 = Float64(b / hypot(c, d)) t_2 = fma(t_0, t_1, Float64(Float64(d / (hypot(c, d) ^ 2.0)) * Float64(-a))) t_3 = fma(t_0, t_1, Float64(a / Float64(-d))) tmp = 0.0 if (d <= -9e+153) tmp = t_3; elseif (d <= -1e-160) tmp = t_2; elseif (d <= 3.8e-168) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); elseif (d <= 1.3e+128) tmp = t_2; else tmp = t_3; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * t$95$1 + N[(N[(d / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$0 * t$95$1 + N[(a / (-d)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -9e+153], t$95$3, If[LessEqual[d, -1e-160], t$95$2, If[LessEqual[d, 3.8e-168], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.3e+128], t$95$2, t$95$3]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
t_2 := \mathsf{fma}\left(t\_0, t\_1, \frac{d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \cdot \left(-a\right)\right)\\
t_3 := \mathsf{fma}\left(t\_0, t\_1, \frac{a}{-d}\right)\\
\mathbf{if}\;d \leq -9 \cdot 10^{+153}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;d \leq -1 \cdot 10^{-160}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;d \leq 3.8 \cdot 10^{-168}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{elif}\;d \leq 1.3 \cdot 10^{+128}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\end{array}
\end{array}
if d < -9.0000000000000002e153 or 1.3e128 < d Initial program 30.5%
div-sub30.5%
*-commutative30.5%
add-sqr-sqrt30.5%
times-frac30.8%
fma-neg30.8%
hypot-define30.8%
hypot-define50.2%
associate-/l*51.4%
add-sqr-sqrt51.4%
pow251.4%
hypot-define51.4%
Applied egg-rr51.4%
Taylor expanded in d around inf 94.8%
if -9.0000000000000002e153 < d < -9.9999999999999999e-161 or 3.8e-168 < d < 1.3e128Initial program 69.1%
div-sub69.1%
*-commutative69.1%
add-sqr-sqrt69.1%
times-frac72.5%
fma-neg72.5%
hypot-define72.6%
hypot-define90.6%
associate-/l*98.0%
add-sqr-sqrt98.0%
pow298.0%
hypot-define98.0%
Applied egg-rr98.0%
if -9.9999999999999999e-161 < d < 3.8e-168Initial program 62.0%
Taylor expanded in c around inf 95.2%
associate-*r/95.2%
mul-1-neg95.2%
distribute-rgt-neg-out95.2%
Simplified95.2%
Final simplification96.4%
(FPCore (a b c d) :precision binary64 (if (<= (/ (- (* c b) (* d a)) (+ (* c c) (* d d))) 1e+277) (* (/ 1.0 (hypot c d)) (/ (fma b c (* a (- d))) (hypot c d))) (fma (/ c (hypot c d)) (/ b (hypot c d)) (/ a (- d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((c * b) - (d * a)) / ((c * c) + (d * d))) <= 1e+277) {
tmp = (1.0 / hypot(c, d)) * (fma(b, c, (a * -d)) / hypot(c, d));
} else {
tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (a / -d));
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))) <= 1e+277) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(b, c, Float64(a * Float64(-d))) / hypot(c, d))); else tmp = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a / Float64(-d))); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+277], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(b * c + N[(a * (-d)), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(a / (-d)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d} \leq 10^{+277}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(b, c, a \cdot \left(-d\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{a}{-d}\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1e277Initial program 75.9%
*-un-lft-identity75.9%
add-sqr-sqrt75.9%
times-frac75.8%
hypot-define75.9%
fma-neg75.9%
distribute-rgt-neg-in75.9%
hypot-define95.7%
Applied egg-rr95.7%
if 1e277 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 12.6%
div-sub11.1%
*-commutative11.1%
add-sqr-sqrt11.1%
times-frac19.8%
fma-neg19.8%
hypot-define19.8%
hypot-define54.9%
associate-/l*63.5%
add-sqr-sqrt63.5%
pow263.5%
hypot-define63.5%
Applied egg-rr63.5%
Taylor expanded in d around inf 71.2%
Final simplification88.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (* a (/ d c))) c))
(t_1 (fma (/ c (hypot c d)) (/ b (hypot c d)) (/ a (- d)))))
(if (<= d -7e-70)
t_1
(if (<= d 9e-198)
t_0
(if (<= d 5e-26)
(/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
(if (<= d 4.4e+22) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = (b - (a * (d / c))) / c;
double t_1 = fma((c / hypot(c, d)), (b / hypot(c, d)), (a / -d));
double tmp;
if (d <= -7e-70) {
tmp = t_1;
} else if (d <= 9e-198) {
tmp = t_0;
} else if (d <= 5e-26) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else if (d <= 4.4e+22) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(a * Float64(d / c))) / c) t_1 = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a / Float64(-d))) tmp = 0.0 if (d <= -7e-70) tmp = t_1; elseif (d <= 9e-198) tmp = t_0; elseif (d <= 5e-26) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 4.4e+22) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(a / (-d)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -7e-70], t$95$1, If[LessEqual[d, 9e-198], t$95$0, If[LessEqual[d, 5e-26], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.4e+22], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b - a \cdot \frac{d}{c}}{c}\\
t_1 := \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{a}{-d}\right)\\
\mathbf{if}\;d \leq -7 \cdot 10^{-70}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 9 \cdot 10^{-198}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 5 \cdot 10^{-26}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 4.4 \cdot 10^{+22}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -6.99999999999999949e-70 or 4.4e22 < d Initial program 47.2%
div-sub47.2%
*-commutative47.2%
add-sqr-sqrt47.2%
times-frac49.6%
fma-neg49.6%
hypot-define49.6%
hypot-define68.3%
associate-/l*75.2%
add-sqr-sqrt75.2%
pow275.2%
hypot-define75.2%
Applied egg-rr75.2%
Taylor expanded in d around inf 87.5%
if -6.99999999999999949e-70 < d < 8.9999999999999996e-198 or 5.00000000000000019e-26 < d < 4.4e22Initial program 61.0%
Taylor expanded in c around inf 91.9%
remove-double-neg91.9%
mul-1-neg91.9%
neg-mul-191.9%
distribute-lft-in91.9%
distribute-lft-in91.9%
mul-1-neg91.9%
unsub-neg91.9%
neg-mul-191.9%
mul-1-neg91.9%
remove-double-neg91.9%
associate-/l*92.0%
Simplified92.0%
if 8.9999999999999996e-198 < d < 5.00000000000000019e-26Initial program 86.5%
Final simplification88.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
(if (<= c -4.3e+85)
(/ (- b (* a (/ d c))) c)
(if (<= c -1e-123)
t_0
(if (<= c 1.6e-59)
(/ (- (* b (/ c d)) a) d)
(if (<= c 2.55e+63) t_0 (/ 1.0 (/ c (- b (* d (/ a c)))))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double tmp;
if (c <= -4.3e+85) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= -1e-123) {
tmp = t_0;
} else if (c <= 1.6e-59) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 2.55e+63) {
tmp = t_0;
} else {
tmp = 1.0 / (c / (b - (d * (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) :: t_0
real(8) :: tmp
t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
if (c <= (-4.3d+85)) then
tmp = (b - (a * (d / c))) / c
else if (c <= (-1d-123)) then
tmp = t_0
else if (c <= 1.6d-59) then
tmp = ((b * (c / d)) - a) / d
else if (c <= 2.55d+63) then
tmp = t_0
else
tmp = 1.0d0 / (c / (b - (d * (a / c))))
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 tmp;
if (c <= -4.3e+85) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= -1e-123) {
tmp = t_0;
} else if (c <= 1.6e-59) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 2.55e+63) {
tmp = t_0;
} else {
tmp = 1.0 / (c / (b - (d * (a / c))));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)) tmp = 0 if c <= -4.3e+85: tmp = (b - (a * (d / c))) / c elif c <= -1e-123: tmp = t_0 elif c <= 1.6e-59: tmp = ((b * (c / d)) - a) / d elif c <= 2.55e+63: tmp = t_0 else: tmp = 1.0 / (c / (b - (d * (a / c)))) 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))) tmp = 0.0 if (c <= -4.3e+85) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (c <= -1e-123) tmp = t_0; elseif (c <= 1.6e-59) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (c <= 2.55e+63) tmp = t_0; else tmp = Float64(1.0 / Float64(c / Float64(b - Float64(d * Float64(a / c))))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -4.3e+85) tmp = (b - (a * (d / c))) / c; elseif (c <= -1e-123) tmp = t_0; elseif (c <= 1.6e-59) tmp = ((b * (c / d)) - a) / d; elseif (c <= 2.55e+63) tmp = t_0; else tmp = 1.0 / (c / (b - (d * (a / c)))); 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]}, If[LessEqual[c, -4.3e+85], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1e-123], t$95$0, If[LessEqual[c, 1.6e-59], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.55e+63], t$95$0, N[(1.0 / N[(c / N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -4.3 \cdot 10^{+85}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -1 \cdot 10^{-123}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.6 \cdot 10^{-59}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 2.55 \cdot 10^{+63}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{c}{b - d \cdot \frac{a}{c}}}\\
\end{array}
\end{array}
if c < -4.2999999999999999e85Initial program 24.9%
Taylor expanded in c around inf 77.7%
remove-double-neg77.7%
mul-1-neg77.7%
neg-mul-177.7%
distribute-lft-in77.7%
distribute-lft-in77.7%
mul-1-neg77.7%
unsub-neg77.7%
neg-mul-177.7%
mul-1-neg77.7%
remove-double-neg77.7%
associate-/l*81.9%
Simplified81.9%
if -4.2999999999999999e85 < c < -1.0000000000000001e-123 or 1.6e-59 < c < 2.5499999999999999e63Initial program 80.9%
if -1.0000000000000001e-123 < c < 1.6e-59Initial program 66.1%
Taylor expanded in c around 0 84.0%
+-commutative84.0%
mul-1-neg84.0%
unsub-neg84.0%
unpow284.0%
associate-/r*92.3%
div-sub93.3%
associate-/l*93.4%
Simplified93.4%
if 2.5499999999999999e63 < c Initial program 39.7%
Taylor expanded in c around inf 86.7%
remove-double-neg86.7%
mul-1-neg86.7%
neg-mul-186.7%
distribute-lft-in86.7%
distribute-lft-in86.7%
mul-1-neg86.7%
unsub-neg86.7%
neg-mul-186.7%
mul-1-neg86.7%
remove-double-neg86.7%
associate-/l*88.3%
Simplified88.3%
clear-num88.1%
inv-pow88.1%
Applied egg-rr88.1%
unpow-188.1%
associate-*r/86.5%
remove-double-neg86.5%
distribute-neg-frac286.5%
associate-*l/90.0%
*-commutative90.0%
distribute-rgt-neg-in90.0%
distribute-frac-neg290.0%
remove-double-neg90.0%
Simplified90.0%
Final simplification87.7%
(FPCore (a b c d)
:precision binary64
(if (or (<= c -3.4e+103)
(not (or (<= c -1.1e+36) (and (not (<= c -8e-39)) (<= c 5.6e-58)))))
(/ (- b (* a (/ d c))) c)
(/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.4e+103) || !((c <= -1.1e+36) || (!(c <= -8e-39) && (c <= 5.6e-58)))) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((b * (c / 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 ((c <= (-3.4d+103)) .or. (.not. (c <= (-1.1d+36)) .or. (.not. (c <= (-8d-39))) .and. (c <= 5.6d-58))) then
tmp = (b - (a * (d / c))) / c
else
tmp = ((b * (c / d)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.4e+103) || !((c <= -1.1e+36) || (!(c <= -8e-39) && (c <= 5.6e-58)))) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3.4e+103) or not ((c <= -1.1e+36) or (not (c <= -8e-39) and (c <= 5.6e-58))): tmp = (b - (a * (d / c))) / c else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.4e+103) || !((c <= -1.1e+36) || (!(c <= -8e-39) && (c <= 5.6e-58)))) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -3.4e+103) || ~(((c <= -1.1e+36) || (~((c <= -8e-39)) && (c <= 5.6e-58))))) tmp = (b - (a * (d / c))) / c; else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.4e+103], N[Not[Or[LessEqual[c, -1.1e+36], And[N[Not[LessEqual[c, -8e-39]], $MachinePrecision], LessEqual[c, 5.6e-58]]]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.4 \cdot 10^{+103} \lor \neg \left(c \leq -1.1 \cdot 10^{+36} \lor \neg \left(c \leq -8 \cdot 10^{-39}\right) \land c \leq 5.6 \cdot 10^{-58}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -3.3999999999999998e103 or -1.1e36 < c < -7.99999999999999943e-39 or 5.6000000000000001e-58 < c Initial program 49.1%
Taylor expanded in c around inf 79.8%
remove-double-neg79.8%
mul-1-neg79.8%
neg-mul-179.8%
distribute-lft-in79.8%
distribute-lft-in79.8%
mul-1-neg79.8%
unsub-neg79.8%
neg-mul-179.8%
mul-1-neg79.8%
remove-double-neg79.8%
associate-/l*81.1%
Simplified81.1%
if -3.3999999999999998e103 < c < -1.1e36 or -7.99999999999999943e-39 < c < 5.6000000000000001e-58Initial program 65.1%
Taylor expanded in c around 0 80.3%
+-commutative80.3%
mul-1-neg80.3%
unsub-neg80.3%
unpow280.3%
associate-/r*86.9%
div-sub87.8%
associate-/l*89.4%
Simplified89.4%
Final simplification85.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ a (- d))))
(if (<= d -0.00021)
t_0
(if (<= d 7.2e+22)
(/ (- b (* a (/ d c))) c)
(if (or (<= d 1e+165) (not (<= d 1.8e+184)))
t_0
(/ (* d (/ b d)) c))))))
double code(double a, double b, double c, double d) {
double t_0 = a / -d;
double tmp;
if (d <= -0.00021) {
tmp = t_0;
} else if (d <= 7.2e+22) {
tmp = (b - (a * (d / c))) / c;
} else if ((d <= 1e+165) || !(d <= 1.8e+184)) {
tmp = t_0;
} else {
tmp = (d * (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) :: t_0
real(8) :: tmp
t_0 = a / -d
if (d <= (-0.00021d0)) then
tmp = t_0
else if (d <= 7.2d+22) then
tmp = (b - (a * (d / c))) / c
else if ((d <= 1d+165) .or. (.not. (d <= 1.8d+184))) then
tmp = t_0
else
tmp = (d * (b / d)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = a / -d;
double tmp;
if (d <= -0.00021) {
tmp = t_0;
} else if (d <= 7.2e+22) {
tmp = (b - (a * (d / c))) / c;
} else if ((d <= 1e+165) || !(d <= 1.8e+184)) {
tmp = t_0;
} else {
tmp = (d * (b / d)) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = a / -d tmp = 0 if d <= -0.00021: tmp = t_0 elif d <= 7.2e+22: tmp = (b - (a * (d / c))) / c elif (d <= 1e+165) or not (d <= 1.8e+184): tmp = t_0 else: tmp = (d * (b / d)) / c return tmp
function code(a, b, c, d) t_0 = Float64(a / Float64(-d)) tmp = 0.0 if (d <= -0.00021) tmp = t_0; elseif (d <= 7.2e+22) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif ((d <= 1e+165) || !(d <= 1.8e+184)) tmp = t_0; else tmp = Float64(Float64(d * Float64(b / d)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = a / -d; tmp = 0.0; if (d <= -0.00021) tmp = t_0; elseif (d <= 7.2e+22) tmp = (b - (a * (d / c))) / c; elseif ((d <= 1e+165) || ~((d <= 1.8e+184))) tmp = t_0; else tmp = (d * (b / d)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / (-d)), $MachinePrecision]}, If[LessEqual[d, -0.00021], t$95$0, If[LessEqual[d, 7.2e+22], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[d, 1e+165], N[Not[LessEqual[d, 1.8e+184]], $MachinePrecision]], t$95$0, N[(N[(d * N[(b / d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{-d}\\
\mathbf{if}\;d \leq -0.00021:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 7.2 \cdot 10^{+22}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 10^{+165} \lor \neg \left(d \leq 1.8 \cdot 10^{+184}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{d \cdot \frac{b}{d}}{c}\\
\end{array}
\end{array}
if d < -2.1000000000000001e-4 or 7.2e22 < d < 9.99999999999999899e164 or 1.80000000000000007e184 < d Initial program 44.1%
Taylor expanded in c around 0 68.4%
associate-*r/68.4%
neg-mul-168.4%
Simplified68.4%
if -2.1000000000000001e-4 < d < 7.2e22Initial program 69.5%
Taylor expanded in c around inf 81.3%
remove-double-neg81.3%
mul-1-neg81.3%
neg-mul-181.3%
distribute-lft-in81.3%
distribute-lft-in81.3%
mul-1-neg81.3%
unsub-neg81.3%
neg-mul-181.3%
mul-1-neg81.3%
remove-double-neg81.3%
associate-/l*81.4%
Simplified81.4%
if 9.99999999999999899e164 < d < 1.80000000000000007e184Initial program 28.1%
Taylor expanded in c around inf 70.4%
associate-*r/70.4%
mul-1-neg70.4%
distribute-rgt-neg-out70.4%
Simplified70.4%
Taylor expanded in d around inf 70.1%
+-commutative70.1%
mul-1-neg70.1%
unsub-neg70.1%
Simplified70.1%
Taylor expanded in b around inf 84.2%
Final simplification75.6%
(FPCore (a b c d)
:precision binary64
(if (or (<= c -2e+100)
(not (or (<= c -8e+33) (and (not (<= c -2e-21)) (<= c 4.6e-19)))))
(/ b c)
(/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2e+100) || !((c <= -8e+33) || (!(c <= -2e-21) && (c <= 4.6e-19)))) {
tmp = b / 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 ((c <= (-2d+100)) .or. (.not. (c <= (-8d+33)) .or. (.not. (c <= (-2d-21))) .and. (c <= 4.6d-19))) then
tmp = b / 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 ((c <= -2e+100) || !((c <= -8e+33) || (!(c <= -2e-21) && (c <= 4.6e-19)))) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2e+100) or not ((c <= -8e+33) or (not (c <= -2e-21) and (c <= 4.6e-19))): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2e+100) || !((c <= -8e+33) || (!(c <= -2e-21) && (c <= 4.6e-19)))) tmp = Float64(b / c); else tmp = Float64(a / Float64(-d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2e+100) || ~(((c <= -8e+33) || (~((c <= -2e-21)) && (c <= 4.6e-19))))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2e+100], N[Not[Or[LessEqual[c, -8e+33], And[N[Not[LessEqual[c, -2e-21]], $MachinePrecision], LessEqual[c, 4.6e-19]]]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2 \cdot 10^{+100} \lor \neg \left(c \leq -8 \cdot 10^{+33} \lor \neg \left(c \leq -2 \cdot 10^{-21}\right) \land c \leq 4.6 \cdot 10^{-19}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -2.00000000000000003e100 or -7.9999999999999996e33 < c < -1.99999999999999982e-21 or 4.5999999999999996e-19 < c Initial program 46.2%
Taylor expanded in c around inf 75.6%
if -2.00000000000000003e100 < c < -7.9999999999999996e33 or -1.99999999999999982e-21 < c < 4.5999999999999996e-19Initial program 66.1%
Taylor expanded in c around 0 62.2%
associate-*r/62.2%
neg-mul-162.2%
Simplified62.2%
Final simplification68.4%
(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 56.8%
Taylor expanded in c around inf 45.2%
Final simplification45.2%
(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 2024075
(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))))