
(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 11 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)) (- (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)) / -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(-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[Sqrt[d ^ 2 + c ^ 2], $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 \frac{\frac{d}{\mathsf{hypot}\left(d, c\right)}}{-\mathsf{hypot}\left(d, c\right)}\right)
\end{array}
Initial program 60.1%
div-sub58.4%
*-commutative58.4%
add-sqr-sqrt58.4%
times-frac61.5%
fma-neg61.5%
hypot-define61.5%
hypot-define78.2%
associate-/l*81.9%
add-sqr-sqrt81.9%
pow281.9%
hypot-define81.9%
Applied egg-rr81.9%
*-un-lft-identity81.9%
unpow281.9%
times-frac96.7%
hypot-undefine81.9%
+-commutative81.9%
hypot-define96.7%
hypot-undefine81.9%
+-commutative81.9%
hypot-define96.7%
Applied egg-rr96.7%
associate-*l/96.7%
*-lft-identity96.7%
Simplified96.7%
Final simplification96.7%
(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 (* a (/ d (- (pow (hypot c d) 2.0))))))
(t_3 (fma t_0 t_1 (/ a (- d)))))
(if (<= d -7e+131)
t_3
(if (<= d -9e-39)
t_2
(if (<= d 1e-183)
(* (/ (- c (* a (/ d b))) (hypot d c)) (/ b (hypot d c)))
(if (<= d 5.6e+147) 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, (a * (d / -pow(hypot(c, d), 2.0))));
double t_3 = fma(t_0, t_1, (a / -d));
double tmp;
if (d <= -7e+131) {
tmp = t_3;
} else if (d <= -9e-39) {
tmp = t_2;
} else if (d <= 1e-183) {
tmp = ((c - (a * (d / b))) / hypot(d, c)) * (b / hypot(d, c));
} else if (d <= 5.6e+147) {
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(a * Float64(d / Float64(-(hypot(c, d) ^ 2.0))))) t_3 = fma(t_0, t_1, Float64(a / Float64(-d))) tmp = 0.0 if (d <= -7e+131) tmp = t_3; elseif (d <= -9e-39) tmp = t_2; elseif (d <= 1e-183) tmp = Float64(Float64(Float64(c - Float64(a * Float64(d / b))) / hypot(d, c)) * Float64(b / hypot(d, c))); elseif (d <= 5.6e+147) 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[(a * N[(d / (-N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$0 * t$95$1 + N[(a / (-d)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -7e+131], t$95$3, If[LessEqual[d, -9e-39], t$95$2, If[LessEqual[d, 1e-183], N[(N[(N[(c - N[(a * N[(d / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5.6e+147], 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, a \cdot \frac{d}{-{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\
t_3 := \mathsf{fma}\left(t\_0, t\_1, \frac{a}{-d}\right)\\
\mathbf{if}\;d \leq -7 \cdot 10^{+131}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;d \leq -9 \cdot 10^{-39}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;d \leq 10^{-183}:\\
\;\;\;\;\frac{c - a \cdot \frac{d}{b}}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;d \leq 5.6 \cdot 10^{+147}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\end{array}
\end{array}
if d < -6.9999999999999998e131 or 5.6000000000000002e147 < d Initial program 31.5%
div-sub31.5%
*-commutative31.5%
add-sqr-sqrt31.5%
times-frac31.8%
fma-neg31.8%
hypot-define31.8%
hypot-define49.6%
associate-/l*53.9%
add-sqr-sqrt53.9%
pow253.9%
hypot-define53.9%
Applied egg-rr53.9%
Taylor expanded in d around inf 93.9%
if -6.9999999999999998e131 < d < -9.0000000000000002e-39 or 1.00000000000000001e-183 < d < 5.6000000000000002e147Initial program 72.4%
div-sub71.4%
*-commutative71.4%
add-sqr-sqrt71.4%
times-frac75.3%
fma-neg75.3%
hypot-define75.3%
hypot-define86.7%
associate-/l*92.9%
add-sqr-sqrt92.9%
pow292.9%
hypot-define92.9%
Applied egg-rr92.9%
if -9.0000000000000002e-39 < d < 1.00000000000000001e-183Initial program 64.9%
Taylor expanded in b around inf 63.8%
mul-1-neg63.8%
unsub-neg63.8%
associate-/l*63.9%
Simplified63.9%
*-commutative63.9%
+-commutative63.9%
add-sqr-sqrt63.9%
hypot-undefine63.9%
hypot-undefine63.9%
times-frac95.6%
Applied egg-rr95.6%
Final simplification94.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.12e+57) (not (<= d 8.5e+73))) (fma (/ c (hypot c d)) (/ b (hypot c d)) (/ a (- d))) (* (/ (- c (* a (/ d b))) (hypot d c)) (/ b (hypot d c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.12e+57) || !(d <= 8.5e+73)) {
tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (a / -d));
} else {
tmp = ((c - (a * (d / b))) / hypot(d, c)) * (b / hypot(d, c));
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.12e+57) || !(d <= 8.5e+73)) tmp = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a / Float64(-d))); else tmp = Float64(Float64(Float64(c - Float64(a * Float64(d / b))) / hypot(d, c)) * Float64(b / hypot(d, c))); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.12e+57], N[Not[LessEqual[d, 8.5e+73]], $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], N[(N[(N[(c - N[(a * N[(d / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.12 \cdot 10^{+57} \lor \neg \left(d \leq 8.5 \cdot 10^{+73}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{a}{-d}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c - a \cdot \frac{d}{b}}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}
\end{array}
if d < -1.12000000000000003e57 or 8.4999999999999998e73 < d Initial program 40.4%
div-sub40.4%
*-commutative40.4%
add-sqr-sqrt40.4%
times-frac42.9%
fma-neg42.9%
hypot-define42.9%
hypot-define57.6%
associate-/l*66.7%
add-sqr-sqrt66.7%
pow266.7%
hypot-define66.7%
Applied egg-rr66.7%
Taylor expanded in d around inf 88.8%
if -1.12000000000000003e57 < d < 8.4999999999999998e73Initial program 71.3%
Taylor expanded in b around inf 67.2%
mul-1-neg67.2%
unsub-neg67.2%
associate-/l*67.1%
Simplified67.1%
*-commutative67.1%
+-commutative67.1%
add-sqr-sqrt67.1%
hypot-undefine67.1%
hypot-undefine67.1%
times-frac91.1%
Applied egg-rr91.1%
Final simplification90.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* (/ (- c (* a (/ d b))) (hypot d c)) (/ b (hypot d c)))))
(if (<= c -1.02e-51)
t_0
(if (<= c 1.3e-210)
(/ (- (* b (/ c d)) a) d)
(if (<= c 3.4e-115)
t_0
(if (<= c 820000.0)
(/ (fma b c (* d (- a))) (fma d d (* c c)))
(if (<= c 2.4e+224) t_0 (/ (- b (* a (/ d c))) c))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c - (a * (d / b))) / hypot(d, c)) * (b / hypot(d, c));
double tmp;
if (c <= -1.02e-51) {
tmp = t_0;
} else if (c <= 1.3e-210) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 3.4e-115) {
tmp = t_0;
} else if (c <= 820000.0) {
tmp = fma(b, c, (d * -a)) / fma(d, d, (c * c));
} else if (c <= 2.4e+224) {
tmp = t_0;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c - Float64(a * Float64(d / b))) / hypot(d, c)) * Float64(b / hypot(d, c))) tmp = 0.0 if (c <= -1.02e-51) tmp = t_0; elseif (c <= 1.3e-210) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (c <= 3.4e-115) tmp = t_0; elseif (c <= 820000.0) tmp = Float64(fma(b, c, Float64(d * Float64(-a))) / fma(d, d, Float64(c * c))); elseif (c <= 2.4e+224) tmp = t_0; else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c - N[(a * N[(d / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.02e-51], t$95$0, If[LessEqual[c, 1.3e-210], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 3.4e-115], t$95$0, If[LessEqual[c, 820000.0], N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.4e+224], t$95$0, N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c - a \cdot \frac{d}{b}}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{if}\;c \leq -1.02 \cdot 10^{-51}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.3 \cdot 10^{-210}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 3.4 \cdot 10^{-115}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 820000:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{+224}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -1.01999999999999998e-51 or 1.2999999999999999e-210 < c < 3.3999999999999998e-115 or 8.2e5 < c < 2.40000000000000001e224Initial program 53.0%
Taylor expanded in b around inf 50.7%
mul-1-neg50.7%
unsub-neg50.7%
associate-/l*50.7%
Simplified50.7%
*-commutative50.7%
+-commutative50.7%
add-sqr-sqrt50.7%
hypot-undefine50.7%
hypot-undefine50.7%
times-frac89.9%
Applied egg-rr89.9%
if -1.01999999999999998e-51 < c < 1.2999999999999999e-210Initial program 69.9%
div-sub64.5%
*-commutative64.5%
add-sqr-sqrt64.5%
times-frac63.5%
fma-neg63.5%
hypot-define63.5%
hypot-define66.6%
associate-/l*76.6%
add-sqr-sqrt76.6%
pow276.6%
hypot-define76.6%
Applied egg-rr76.6%
Taylor expanded in c around 0 84.1%
*-commutative84.1%
unpow284.1%
associate-/l/91.8%
div-sub91.9%
Simplified91.9%
*-commutative91.9%
*-un-lft-identity91.9%
times-frac91.9%
Applied egg-rr91.9%
if 3.3999999999999998e-115 < c < 8.2e5Initial program 99.9%
fma-neg100.0%
distribute-rgt-neg-out100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
if 2.40000000000000001e224 < c Initial program 40.1%
Taylor expanded in c around inf 86.7%
remove-double-neg86.7%
mul-1-neg86.7%
neg-mul-186.7%
distribute-lft-in86.7%
mul-1-neg86.7%
distribute-neg-in86.7%
mul-1-neg86.7%
remove-double-neg86.7%
unsub-neg86.7%
associate-/l*99.9%
Simplified99.9%
Final simplification92.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
(if (<= d -1.32e+100)
(/ (- (* c (/ b d)) a) d)
(if (<= d -7.2e-44)
t_0
(if (<= d 460.0)
(/ (- b (* a (/ d c))) c)
(if (<= d 2.2e+79) t_0 (/ (- (* b (/ c d)) a) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.32e+100) {
tmp = ((c * (b / d)) - a) / d;
} else if (d <= -7.2e-44) {
tmp = t_0;
} else if (d <= 460.0) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 2.2e+79) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
if (d <= (-1.32d+100)) then
tmp = ((c * (b / d)) - a) / d
else if (d <= (-7.2d-44)) then
tmp = t_0
else if (d <= 460.0d0) then
tmp = (b - (a * (d / c))) / c
else if (d <= 2.2d+79) then
tmp = t_0
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 t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.32e+100) {
tmp = ((c * (b / d)) - a) / d;
} else if (d <= -7.2e-44) {
tmp = t_0;
} else if (d <= 460.0) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 2.2e+79) {
tmp = t_0;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)) tmp = 0 if d <= -1.32e+100: tmp = ((c * (b / d)) - a) / d elif d <= -7.2e-44: tmp = t_0 elif d <= 460.0: tmp = (b - (a * (d / c))) / c elif d <= 2.2e+79: tmp = t_0 else: tmp = ((b * (c / d)) - a) / d 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 (d <= -1.32e+100) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); elseif (d <= -7.2e-44) tmp = t_0; elseif (d <= 460.0) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 2.2e+79) tmp = t_0; else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); 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 (d <= -1.32e+100) tmp = ((c * (b / d)) - a) / d; elseif (d <= -7.2e-44) tmp = t_0; elseif (d <= 460.0) tmp = (b - (a * (d / c))) / c; elseif (d <= 2.2e+79) tmp = t_0; else tmp = ((b * (c / d)) - a) / d; 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[d, -1.32e+100], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -7.2e-44], t$95$0, If[LessEqual[d, 460.0], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.2e+79], t$95$0, N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -1.32 \cdot 10^{+100}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{elif}\;d \leq -7.2 \cdot 10^{-44}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 460:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.2 \cdot 10^{+79}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if d < -1.32e100Initial program 33.7%
Taylor expanded in c around 0 71.8%
+-commutative71.8%
mul-1-neg71.8%
unsub-neg71.8%
unpow271.8%
associate-/r*79.2%
div-sub79.2%
*-commutative79.2%
associate-/l*87.8%
Simplified87.8%
if -1.32e100 < d < -7.1999999999999998e-44 or 460 < d < 2.1999999999999999e79Initial program 86.2%
if -7.1999999999999998e-44 < d < 460Initial program 65.6%
Taylor expanded in c around inf 91.5%
remove-double-neg91.5%
mul-1-neg91.5%
neg-mul-191.5%
distribute-lft-in91.5%
mul-1-neg91.5%
distribute-neg-in91.5%
mul-1-neg91.5%
remove-double-neg91.5%
unsub-neg91.5%
associate-/l*92.3%
Simplified92.3%
if 2.1999999999999999e79 < d Initial program 38.1%
div-sub38.1%
*-commutative38.1%
add-sqr-sqrt38.1%
times-frac40.4%
fma-neg40.4%
hypot-define40.4%
hypot-define51.2%
associate-/l*63.2%
add-sqr-sqrt63.2%
pow263.2%
hypot-define63.2%
Applied egg-rr63.2%
Taylor expanded in c around 0 70.1%
*-commutative70.1%
unpow270.1%
associate-/l/71.7%
div-sub71.7%
Simplified71.7%
*-commutative71.7%
*-un-lft-identity71.7%
times-frac78.7%
Applied egg-rr78.7%
Final simplification88.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.6e-51) (not (<= c 1.1e-46))) (/ (- b (* a (/ d c))) c) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.6e-51) || !(c <= 1.1e-46)) {
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 <= (-1.6d-51)) .or. (.not. (c <= 1.1d-46))) 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 <= -1.6e-51) || !(c <= 1.1e-46)) {
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 <= -1.6e-51) or not (c <= 1.1e-46): 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 <= -1.6e-51) || !(c <= 1.1e-46)) 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 <= -1.6e-51) || ~((c <= 1.1e-46))) 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, -1.6e-51], N[Not[LessEqual[c, 1.1e-46]], $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 -1.6 \cdot 10^{-51} \lor \neg \left(c \leq 1.1 \cdot 10^{-46}\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 < -1.6e-51 or 1.1e-46 < c Initial program 54.5%
Taylor expanded in c around inf 80.5%
remove-double-neg80.5%
mul-1-neg80.5%
neg-mul-180.5%
distribute-lft-in80.5%
mul-1-neg80.5%
distribute-neg-in80.5%
mul-1-neg80.5%
remove-double-neg80.5%
unsub-neg80.5%
associate-/l*83.1%
Simplified83.1%
if -1.6e-51 < c < 1.1e-46Initial program 68.5%
div-sub64.1%
*-commutative64.1%
add-sqr-sqrt64.1%
times-frac63.3%
fma-neg63.3%
hypot-define63.4%
hypot-define66.6%
associate-/l*75.3%
add-sqr-sqrt75.3%
pow275.3%
hypot-define75.3%
Applied egg-rr75.3%
Taylor expanded in c around 0 77.3%
*-commutative77.3%
unpow277.3%
associate-/l/83.5%
div-sub83.6%
Simplified83.6%
*-commutative83.6%
*-un-lft-identity83.6%
times-frac83.7%
Applied egg-rr83.7%
Final simplification83.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.2e-51) (not (<= c 7.8e-47))) (/ (- b (* a (/ d c))) c) (/ (- (/ (* c b) d) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.2e-51) || !(c <= 7.8e-47)) {
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 ((c <= (-4.2d-51)) .or. (.not. (c <= 7.8d-47))) 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 ((c <= -4.2e-51) || !(c <= 7.8e-47)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = (((c * b) / d) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4.2e-51) or not (c <= 7.8e-47): 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 ((c <= -4.2e-51) || !(c <= 7.8e-47)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -4.2e-51) || ~((c <= 7.8e-47))) tmp = (b - (a * (d / c))) / c; else tmp = (((c * b) / d) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.2e-51], N[Not[LessEqual[c, 7.8e-47]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.2 \cdot 10^{-51} \lor \neg \left(c \leq 7.8 \cdot 10^{-47}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\
\end{array}
\end{array}
if c < -4.20000000000000003e-51 or 7.79999999999999956e-47 < c Initial program 54.5%
Taylor expanded in c around inf 80.5%
remove-double-neg80.5%
mul-1-neg80.5%
neg-mul-180.5%
distribute-lft-in80.5%
mul-1-neg80.5%
distribute-neg-in80.5%
mul-1-neg80.5%
remove-double-neg80.5%
unsub-neg80.5%
associate-/l*83.1%
Simplified83.1%
if -4.20000000000000003e-51 < c < 7.79999999999999956e-47Initial program 68.5%
div-sub64.1%
*-commutative64.1%
add-sqr-sqrt64.1%
times-frac63.3%
fma-neg63.3%
hypot-define63.4%
hypot-define66.6%
associate-/l*75.3%
add-sqr-sqrt75.3%
pow275.3%
hypot-define75.3%
Applied egg-rr75.3%
Taylor expanded in c around 0 77.3%
*-commutative77.3%
unpow277.3%
associate-/l/83.5%
div-sub83.6%
Simplified83.6%
Final simplification83.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -7.2e-51) (not (<= c 3.6e-48))) (/ (- b (* a (/ d c))) c) (/ (- (* c (/ b d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -7.2e-51) || !(c <= 3.6e-48)) {
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 ((c <= (-7.2d-51)) .or. (.not. (c <= 3.6d-48))) 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 ((c <= -7.2e-51) || !(c <= 3.6e-48)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -7.2e-51) or not (c <= 3.6e-48): 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 ((c <= -7.2e-51) || !(c <= 3.6e-48)) 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 ((c <= -7.2e-51) || ~((c <= 3.6e-48))) tmp = (b - (a * (d / c))) / c; else tmp = ((c * (b / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -7.2e-51], N[Not[LessEqual[c, 3.6e-48]], $MachinePrecision]], 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}\;c \leq -7.2 \cdot 10^{-51} \lor \neg \left(c \leq 3.6 \cdot 10^{-48}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if c < -7.2000000000000001e-51 or 3.6000000000000002e-48 < c Initial program 54.5%
Taylor expanded in c around inf 80.5%
remove-double-neg80.5%
mul-1-neg80.5%
neg-mul-180.5%
distribute-lft-in80.5%
mul-1-neg80.5%
distribute-neg-in80.5%
mul-1-neg80.5%
remove-double-neg80.5%
unsub-neg80.5%
associate-/l*83.1%
Simplified83.1%
if -7.2000000000000001e-51 < c < 3.6000000000000002e-48Initial program 68.5%
Taylor expanded in c around 0 77.3%
+-commutative77.3%
mul-1-neg77.3%
unsub-neg77.3%
unpow277.3%
associate-/r*83.5%
div-sub83.6%
*-commutative83.6%
associate-/l*81.8%
Simplified81.8%
Final simplification82.6%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3e-51) (not (<= c 1.5e-212))) (/ (- b (* a (/ d c))) c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3e-51) || !(c <= 1.5e-212)) {
tmp = (b - (a * (d / c))) / 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 <= (-3d-51)) .or. (.not. (c <= 1.5d-212))) then
tmp = (b - (a * (d / c))) / 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 <= -3e-51) || !(c <= 1.5e-212)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3e-51) or not (c <= 1.5e-212): tmp = (b - (a * (d / c))) / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3e-51) || !(c <= 1.5e-212)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(a / Float64(-d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -3e-51) || ~((c <= 1.5e-212))) tmp = (b - (a * (d / c))) / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3e-51], N[Not[LessEqual[c, 1.5e-212]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3 \cdot 10^{-51} \lor \neg \left(c \leq 1.5 \cdot 10^{-212}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -3.00000000000000002e-51 or 1.5000000000000001e-212 < c Initial program 55.7%
Taylor expanded in c around inf 75.9%
remove-double-neg75.9%
mul-1-neg75.9%
neg-mul-175.9%
distribute-lft-in75.9%
mul-1-neg75.9%
distribute-neg-in75.9%
mul-1-neg75.9%
remove-double-neg75.9%
unsub-neg75.9%
associate-/l*78.7%
Simplified78.7%
if -3.00000000000000002e-51 < c < 1.5000000000000001e-212Initial program 69.9%
Taylor expanded in c around 0 81.9%
associate-*r/81.9%
neg-mul-181.9%
Simplified81.9%
Final simplification79.7%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.4e-51) (not (<= c 2.8e-50))) (/ b c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.4e-51) || !(c <= 2.8e-50)) {
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 <= (-2.4d-51)) .or. (.not. (c <= 2.8d-50))) 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 <= -2.4e-51) || !(c <= 2.8e-50)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.4e-51) or not (c <= 2.8e-50): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.4e-51) || !(c <= 2.8e-50)) 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 <= -2.4e-51) || ~((c <= 2.8e-50))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.4e-51], N[Not[LessEqual[c, 2.8e-50]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.4 \cdot 10^{-51} \lor \neg \left(c \leq 2.8 \cdot 10^{-50}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -2.4e-51 or 2.7999999999999998e-50 < c Initial program 54.5%
Taylor expanded in c around inf 67.8%
if -2.4e-51 < c < 2.7999999999999998e-50Initial program 68.5%
Taylor expanded in c around 0 73.9%
associate-*r/73.9%
neg-mul-173.9%
Simplified73.9%
Final simplification70.2%
(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 60.1%
Taylor expanded in c around inf 45.9%
(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 2024096
(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))))