
(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
(if (<= c -1.32e+174)
(/ (- b (* a (/ d c))) c)
(if (or (<= c -3.1e-153) (not (<= c 3.4e-136)))
(fma
(/ c (hypot c d))
(/ b (hypot c d))
(* a (/ (- d) (pow (hypot c d) 2.0))))
(/ (- (* b (/ c d)) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.32e+174) {
tmp = (b - (a * (d / c))) / c;
} else if ((c <= -3.1e-153) || !(c <= 3.4e-136)) {
tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (a * (-d / pow(hypot(c, d), 2.0))));
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.32e+174) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif ((c <= -3.1e-153) || !(c <= 3.4e-136)) tmp = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a * Float64(Float64(-d) / (hypot(c, d) ^ 2.0)))); else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.32e+174], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[c, -3.1e-153], N[Not[LessEqual[c, 3.4e-136]], $MachinePrecision]], 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], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.32 \cdot 10^{+174}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -3.1 \cdot 10^{-153} \lor \neg \left(c \leq 3.4 \cdot 10^{-136}\right):\\
\;\;\;\;\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)\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -1.31999999999999999e174Initial program 32.2%
Taylor expanded in c around inf 70.6%
remove-double-neg70.6%
mul-1-neg70.6%
neg-mul-170.6%
distribute-lft-in70.6%
mul-1-neg70.6%
distribute-neg-in70.6%
mul-1-neg70.6%
remove-double-neg70.6%
unsub-neg70.6%
associate-/l*96.3%
Simplified96.3%
if -1.31999999999999999e174 < c < -3.09999999999999995e-153 or 3.4e-136 < c Initial program 67.9%
div-sub67.9%
*-commutative67.9%
add-sqr-sqrt67.9%
times-frac73.4%
fma-neg73.4%
hypot-define73.4%
hypot-define87.3%
associate-/l*87.5%
add-sqr-sqrt87.5%
pow287.5%
hypot-define87.5%
Applied egg-rr87.5%
if -3.09999999999999995e-153 < c < 3.4e-136Initial program 73.9%
div-sub68.1%
*-commutative68.1%
add-sqr-sqrt68.1%
times-frac66.4%
fma-neg66.4%
hypot-define66.4%
hypot-define67.8%
associate-/l*69.3%
add-sqr-sqrt69.3%
pow269.3%
hypot-define69.3%
Applied egg-rr69.3%
Taylor expanded in d around inf 93.7%
associate-/l*95.0%
Simplified95.0%
Final simplification90.9%
(FPCore (a b c d)
:precision binary64
(if (<= c -6.2e-47)
(/ (- b (* a (/ d c))) c)
(if (<= c 1.7e-136)
(/ (- (* b (/ c d)) a) d)
(if (<= c 1.7e+74)
(/ (- (* c b) (* a d)) (+ (* c c) (* d d)))
(/ (- b (/ a (/ c d))) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.2e-47) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= 1.7e-136) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 1.7e+74) {
tmp = ((c * b) - (a * d)) / ((c * c) + (d * d));
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-6.2d-47)) then
tmp = (b - (a * (d / c))) / c
else if (c <= 1.7d-136) then
tmp = ((b * (c / d)) - a) / d
else if (c <= 1.7d+74) then
tmp = ((c * b) - (a * d)) / ((c * c) + (d * d))
else
tmp = (b - (a / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.2e-47) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= 1.7e-136) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 1.7e+74) {
tmp = ((c * b) - (a * d)) / ((c * c) + (d * d));
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -6.2e-47: tmp = (b - (a * (d / c))) / c elif c <= 1.7e-136: tmp = ((b * (c / d)) - a) / d elif c <= 1.7e+74: tmp = ((c * b) - (a * d)) / ((c * c) + (d * d)) else: tmp = (b - (a / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -6.2e-47) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (c <= 1.7e-136) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (c <= 1.7e+74) tmp = Float64(Float64(Float64(c * b) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -6.2e-47) tmp = (b - (a * (d / c))) / c; elseif (c <= 1.7e-136) tmp = ((b * (c / d)) - a) / d; elseif (c <= 1.7e+74) tmp = ((c * b) - (a * d)) / ((c * c) + (d * d)); else tmp = (b - (a / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -6.2e-47], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.7e-136], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.7e+74], N[(N[(N[(c * b), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.2 \cdot 10^{-47}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 1.7 \cdot 10^{-136}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.7 \cdot 10^{+74}:\\
\;\;\;\;\frac{c \cdot b - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -6.1999999999999996e-47Initial program 53.1%
Taylor expanded in c around inf 71.7%
remove-double-neg71.7%
mul-1-neg71.7%
neg-mul-171.7%
distribute-lft-in71.7%
mul-1-neg71.7%
distribute-neg-in71.7%
mul-1-neg71.7%
remove-double-neg71.7%
unsub-neg71.7%
associate-/l*83.5%
Simplified83.5%
if -6.1999999999999996e-47 < c < 1.7e-136Initial program 71.9%
div-sub67.4%
*-commutative67.4%
add-sqr-sqrt67.4%
times-frac67.1%
fma-neg67.1%
hypot-define67.1%
hypot-define69.8%
associate-/l*71.9%
add-sqr-sqrt71.9%
pow271.9%
hypot-define71.9%
Applied egg-rr71.9%
Taylor expanded in d around inf 90.2%
associate-/l*90.8%
Simplified90.8%
if 1.7e-136 < c < 1.7e74Initial program 85.7%
if 1.7e74 < c Initial program 49.8%
Taylor expanded in c around inf 83.9%
remove-double-neg83.9%
mul-1-neg83.9%
neg-mul-183.9%
distribute-lft-in83.9%
mul-1-neg83.9%
distribute-neg-in83.9%
mul-1-neg83.9%
remove-double-neg83.9%
unsub-neg83.9%
associate-/l*88.5%
Simplified88.5%
clear-num88.5%
un-div-inv88.6%
Applied egg-rr88.6%
Final simplification87.5%
(FPCore (a b c d) :precision binary64 (if (<= c -2.75e+215) (* (/ d c) (/ a (- c))) (if (or (<= c -1.45e-64) (not (<= c 8.4e-57))) (/ b c) (/ a (- d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.75e+215) {
tmp = (d / c) * (a / -c);
} else if ((c <= -1.45e-64) || !(c <= 8.4e-57)) {
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.75d+215)) then
tmp = (d / c) * (a / -c)
else if ((c <= (-1.45d-64)) .or. (.not. (c <= 8.4d-57))) 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.75e+215) {
tmp = (d / c) * (a / -c);
} else if ((c <= -1.45e-64) || !(c <= 8.4e-57)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.75e+215: tmp = (d / c) * (a / -c) elif (c <= -1.45e-64) or not (c <= 8.4e-57): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.75e+215) tmp = Float64(Float64(d / c) * Float64(a / Float64(-c))); elseif ((c <= -1.45e-64) || !(c <= 8.4e-57)) 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.75e+215) tmp = (d / c) * (a / -c); elseif ((c <= -1.45e-64) || ~((c <= 8.4e-57))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.75e+215], N[(N[(d / c), $MachinePrecision] * N[(a / (-c)), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[c, -1.45e-64], N[Not[LessEqual[c, 8.4e-57]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.75 \cdot 10^{+215}:\\
\;\;\;\;\frac{d}{c} \cdot \frac{a}{-c}\\
\mathbf{elif}\;c \leq -1.45 \cdot 10^{-64} \lor \neg \left(c \leq 8.4 \cdot 10^{-57}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -2.75e215Initial program 45.7%
Taylor expanded in c around inf 62.0%
remove-double-neg62.0%
mul-1-neg62.0%
neg-mul-162.0%
distribute-lft-in62.0%
distribute-lft-in62.0%
neg-mul-162.0%
mul-1-neg62.0%
remove-double-neg62.0%
associate-*r/62.0%
associate-*r*62.0%
neg-mul-162.0%
Simplified62.0%
Taylor expanded in d around inf 95.6%
+-commutative95.6%
mul-1-neg95.6%
unsub-neg95.6%
Simplified95.6%
Taylor expanded in d around inf 53.8%
associate-*r/53.8%
mul-1-neg53.8%
*-commutative53.8%
Simplified53.8%
associate-/l/45.9%
distribute-lft-neg-in45.9%
times-frac83.4%
Applied egg-rr83.4%
if -2.75e215 < c < -1.4499999999999999e-64 or 8.3999999999999998e-57 < c Initial program 61.1%
Taylor expanded in c around inf 62.7%
if -1.4499999999999999e-64 < c < 8.3999999999999998e-57Initial program 73.2%
Taylor expanded in c around 0 70.2%
associate-*r/70.2%
neg-mul-170.2%
Simplified70.2%
Final simplification67.7%
(FPCore (a b c d) :precision binary64 (if (<= c -2.8e+215) (/ (* a (/ (- d) c)) c) (if (or (<= c -6e-65) (not (<= c 1.4e-56))) (/ b c) (/ a (- d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.8e+215) {
tmp = (a * (-d / c)) / c;
} else if ((c <= -6e-65) || !(c <= 1.4e-56)) {
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.8d+215)) then
tmp = (a * (-d / c)) / c
else if ((c <= (-6d-65)) .or. (.not. (c <= 1.4d-56))) 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.8e+215) {
tmp = (a * (-d / c)) / c;
} else if ((c <= -6e-65) || !(c <= 1.4e-56)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.8e+215: tmp = (a * (-d / c)) / c elif (c <= -6e-65) or not (c <= 1.4e-56): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.8e+215) tmp = Float64(Float64(a * Float64(Float64(-d) / c)) / c); elseif ((c <= -6e-65) || !(c <= 1.4e-56)) 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.8e+215) tmp = (a * (-d / c)) / c; elseif ((c <= -6e-65) || ~((c <= 1.4e-56))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.8e+215], N[(N[(a * N[((-d) / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[c, -6e-65], N[Not[LessEqual[c, 1.4e-56]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.8 \cdot 10^{+215}:\\
\;\;\;\;\frac{a \cdot \frac{-d}{c}}{c}\\
\mathbf{elif}\;c \leq -6 \cdot 10^{-65} \lor \neg \left(c \leq 1.4 \cdot 10^{-56}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -2.8e215Initial program 45.7%
Taylor expanded in c around inf 62.0%
remove-double-neg62.0%
mul-1-neg62.0%
neg-mul-162.0%
distribute-lft-in62.0%
distribute-lft-in62.0%
neg-mul-162.0%
mul-1-neg62.0%
remove-double-neg62.0%
associate-*r/62.0%
associate-*r*62.0%
neg-mul-162.0%
Simplified62.0%
Taylor expanded in d around inf 95.6%
+-commutative95.6%
mul-1-neg95.6%
unsub-neg95.6%
Simplified95.6%
Taylor expanded in d around inf 53.8%
mul-1-neg53.8%
associate-*r/83.5%
distribute-rgt-neg-in83.5%
distribute-neg-frac283.5%
Simplified83.5%
if -2.8e215 < c < -5.99999999999999996e-65 or 1.39999999999999997e-56 < c Initial program 61.1%
Taylor expanded in c around inf 62.7%
if -5.99999999999999996e-65 < c < 1.39999999999999997e-56Initial program 73.2%
Taylor expanded in c around 0 70.2%
associate-*r/70.2%
neg-mul-170.2%
Simplified70.2%
Final simplification67.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.5e-96) (not (<= c 2.3e-63))) (/ (- b (* a (/ d c))) c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.5e-96) || !(c <= 2.3e-63)) {
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 <= (-4.5d-96)) .or. (.not. (c <= 2.3d-63))) 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 <= -4.5e-96) || !(c <= 2.3e-63)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4.5e-96) or not (c <= 2.3e-63): tmp = (b - (a * (d / c))) / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -4.5e-96) || !(c <= 2.3e-63)) 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 <= -4.5e-96) || ~((c <= 2.3e-63))) tmp = (b - (a * (d / c))) / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.5e-96], N[Not[LessEqual[c, 2.3e-63]], $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 -4.5 \cdot 10^{-96} \lor \neg \left(c \leq 2.3 \cdot 10^{-63}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -4.5e-96 or 2.3e-63 < c Initial program 60.1%
Taylor expanded in c around inf 74.4%
remove-double-neg74.4%
mul-1-neg74.4%
neg-mul-174.4%
distribute-lft-in74.4%
mul-1-neg74.4%
distribute-neg-in74.4%
mul-1-neg74.4%
remove-double-neg74.4%
unsub-neg74.4%
associate-/l*81.6%
Simplified81.6%
if -4.5e-96 < c < 2.3e-63Initial program 71.9%
Taylor expanded in c around 0 72.4%
associate-*r/72.4%
neg-mul-172.4%
Simplified72.4%
Final simplification77.9%
(FPCore (a b c d) :precision binary64 (if (<= c -5.8e-96) (/ (- b (* a (/ d c))) c) (if (<= c 4.9e-59) (/ a (- d)) (/ (- b (/ a (/ c d))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.8e-96) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= 4.9e-59) {
tmp = a / -d;
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-5.8d-96)) then
tmp = (b - (a * (d / c))) / c
else if (c <= 4.9d-59) then
tmp = a / -d
else
tmp = (b - (a / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.8e-96) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= 4.9e-59) {
tmp = a / -d;
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -5.8e-96: tmp = (b - (a * (d / c))) / c elif c <= 4.9e-59: tmp = a / -d else: tmp = (b - (a / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -5.8e-96) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (c <= 4.9e-59) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -5.8e-96) tmp = (b - (a * (d / c))) / c; elseif (c <= 4.9e-59) tmp = a / -d; else tmp = (b - (a / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.8e-96], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 4.9e-59], N[(a / (-d)), $MachinePrecision], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.8 \cdot 10^{-96}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 4.9 \cdot 10^{-59}:\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -5.79999999999999987e-96Initial program 56.3%
Taylor expanded in c around inf 69.8%
remove-double-neg69.8%
mul-1-neg69.8%
neg-mul-169.8%
distribute-lft-in69.8%
mul-1-neg69.8%
distribute-neg-in69.8%
mul-1-neg69.8%
remove-double-neg69.8%
unsub-neg69.8%
associate-/l*80.5%
Simplified80.5%
if -5.79999999999999987e-96 < c < 4.89999999999999977e-59Initial program 71.9%
Taylor expanded in c around 0 72.4%
associate-*r/72.4%
neg-mul-172.4%
Simplified72.4%
if 4.89999999999999977e-59 < c Initial program 64.7%
Taylor expanded in c around inf 80.0%
remove-double-neg80.0%
mul-1-neg80.0%
neg-mul-180.0%
distribute-lft-in80.0%
mul-1-neg80.0%
distribute-neg-in80.0%
mul-1-neg80.0%
remove-double-neg80.0%
unsub-neg80.0%
associate-/l*82.9%
Simplified82.9%
clear-num82.8%
un-div-inv82.9%
Applied egg-rr82.9%
Final simplification77.9%
(FPCore (a b c d) :precision binary64 (if (<= c -6.2e-47) (/ (- b (* a (/ d c))) c) (if (<= c 1.6e-58) (/ (- (* b (/ c d)) a) d) (/ (- b (/ a (/ c d))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.2e-47) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= 1.6e-58) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-6.2d-47)) then
tmp = (b - (a * (d / c))) / c
else if (c <= 1.6d-58) then
tmp = ((b * (c / d)) - a) / d
else
tmp = (b - (a / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.2e-47) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= 1.6e-58) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -6.2e-47: tmp = (b - (a * (d / c))) / c elif c <= 1.6e-58: tmp = ((b * (c / d)) - a) / d else: tmp = (b - (a / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -6.2e-47) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (c <= 1.6e-58) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -6.2e-47) tmp = (b - (a * (d / c))) / c; elseif (c <= 1.6e-58) tmp = ((b * (c / d)) - a) / d; else tmp = (b - (a / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -6.2e-47], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.6e-58], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.2 \cdot 10^{-47}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 1.6 \cdot 10^{-58}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -6.1999999999999996e-47Initial program 53.1%
Taylor expanded in c around inf 71.7%
remove-double-neg71.7%
mul-1-neg71.7%
neg-mul-171.7%
distribute-lft-in71.7%
mul-1-neg71.7%
distribute-neg-in71.7%
mul-1-neg71.7%
remove-double-neg71.7%
unsub-neg71.7%
associate-/l*83.5%
Simplified83.5%
if -6.1999999999999996e-47 < c < 1.6e-58Initial program 73.0%
div-sub69.1%
*-commutative69.1%
add-sqr-sqrt69.1%
times-frac69.7%
fma-neg69.7%
hypot-define69.7%
hypot-define72.0%
associate-/l*73.9%
add-sqr-sqrt73.9%
pow273.9%
hypot-define73.9%
Applied egg-rr73.9%
Taylor expanded in d around inf 88.2%
associate-/l*88.7%
Simplified88.7%
if 1.6e-58 < c Initial program 64.7%
Taylor expanded in c around inf 80.0%
remove-double-neg80.0%
mul-1-neg80.0%
neg-mul-180.0%
distribute-lft-in80.0%
mul-1-neg80.0%
distribute-neg-in80.0%
mul-1-neg80.0%
remove-double-neg80.0%
unsub-neg80.0%
associate-/l*82.9%
Simplified82.9%
clear-num82.8%
un-div-inv82.9%
Applied egg-rr82.9%
Final simplification85.6%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.4e-65) (not (<= c 1.4e-56))) (/ b c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.4e-65) || !(c <= 1.4e-56)) {
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-65)) .or. (.not. (c <= 1.4d-56))) 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-65) || !(c <= 1.4e-56)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.4e-65) or not (c <= 1.4e-56): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.4e-65) || !(c <= 1.4e-56)) 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-65) || ~((c <= 1.4e-56))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.4e-65], N[Not[LessEqual[c, 1.4e-56]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.4 \cdot 10^{-65} \lor \neg \left(c \leq 1.4 \cdot 10^{-56}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -2.4000000000000002e-65 or 1.39999999999999997e-56 < c Initial program 58.7%
Taylor expanded in c around inf 62.2%
if -2.4000000000000002e-65 < c < 1.39999999999999997e-56Initial program 73.2%
Taylor expanded in c around 0 70.2%
associate-*r/70.2%
neg-mul-170.2%
Simplified70.2%
Final simplification65.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.45e+117) (not (<= d 7.2e+95))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.45e+117) || !(d <= 7.2e+95)) {
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.45d+117)) .or. (.not. (d <= 7.2d+95))) 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.45e+117) || !(d <= 7.2e+95)) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.45e+117) or not (d <= 7.2e+95): tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.45e+117) || !(d <= 7.2e+95)) tmp = Float64(a / d); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.45e+117) || ~((d <= 7.2e+95))) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.45e+117], N[Not[LessEqual[d, 7.2e+95]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.45 \cdot 10^{+117} \lor \neg \left(d \leq 7.2 \cdot 10^{+95}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -1.45000000000000014e117 or 7.19999999999999955e95 < d Initial program 42.7%
Taylor expanded in c around 0 73.4%
+-commutative73.4%
mul-1-neg73.4%
unsub-neg73.4%
unpow273.4%
associate-/r*82.7%
div-sub82.7%
*-commutative82.7%
associate-/l*85.4%
Simplified85.4%
clear-num85.1%
inv-pow85.1%
fma-neg85.1%
add-sqr-sqrt40.1%
sqrt-unprod56.3%
sqr-neg56.3%
sqrt-unprod20.0%
add-sqr-sqrt42.7%
Applied egg-rr42.7%
unpow-142.7%
Simplified42.7%
Taylor expanded in d around inf 30.8%
if -1.45000000000000014e117 < d < 7.19999999999999955e95Initial program 74.6%
Taylor expanded in c around inf 53.4%
Final simplification46.5%
(FPCore (a b c d) :precision binary64 (/ a d))
double code(double a, double b, double c, double d) {
return a / d;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / d
end function
public static double code(double a, double b, double c, double d) {
return a / d;
}
def code(a, b, c, d): return a / d
function code(a, b, c, d) return Float64(a / d) end
function tmp = code(a, b, c, d) tmp = a / d; end
code[a_, b_, c_, d_] := N[(a / d), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{d}
\end{array}
Initial program 64.9%
Taylor expanded in c around 0 44.9%
+-commutative44.9%
mul-1-neg44.9%
unsub-neg44.9%
unpow244.9%
associate-/r*49.8%
div-sub49.9%
*-commutative49.9%
associate-/l*50.4%
Simplified50.4%
clear-num50.3%
inv-pow50.3%
fma-neg50.3%
add-sqr-sqrt23.5%
sqrt-unprod30.9%
sqr-neg30.9%
sqrt-unprod10.8%
add-sqr-sqrt22.9%
Applied egg-rr22.9%
unpow-122.9%
Simplified22.9%
Taylor expanded in d around inf 11.6%
Final simplification11.6%
(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 2024059
(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))))