
(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
(let* ((t_0 (/ c (hypot c d))) (t_1 (/ b (hypot c d))))
(if (<= d -3.75e+28)
(fma t_0 t_1 (/ (- a) d))
(if (<= d -5e-109)
(fma t_0 t_1 (* (/ d (pow (hypot c d) 2.0)) (- a)))
(if (<= d 2.45e-147)
(/ (- b (/ (* d a) c)) c)
(* (/ (- (/ (* c b) d) a) (hypot d c)) (/ d (hypot d c))))))))
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 tmp;
if (d <= -3.75e+28) {
tmp = fma(t_0, t_1, (-a / d));
} else if (d <= -5e-109) {
tmp = fma(t_0, t_1, ((d / pow(hypot(c, d), 2.0)) * -a));
} else if (d <= 2.45e-147) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = ((((c * b) / d) - a) / hypot(d, c)) * (d / hypot(d, c));
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(c / hypot(c, d)) t_1 = Float64(b / hypot(c, d)) tmp = 0.0 if (d <= -3.75e+28) tmp = fma(t_0, t_1, Float64(Float64(-a) / d)); elseif (d <= -5e-109) tmp = fma(t_0, t_1, Float64(Float64(d / (hypot(c, d) ^ 2.0)) * Float64(-a))); elseif (d <= 2.45e-147) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); else tmp = Float64(Float64(Float64(Float64(Float64(c * b) / d) - a) / hypot(d, c)) * Float64(d / hypot(d, c))); 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]}, If[LessEqual[d, -3.75e+28], N[(t$95$0 * t$95$1 + N[((-a) / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5e-109], 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], If[LessEqual[d, 2.45e-147], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\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)}\\
\mathbf{if}\;d \leq -3.75 \cdot 10^{+28}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, t\_1, \frac{-a}{d}\right)\\
\mathbf{elif}\;d \leq -5 \cdot 10^{-109}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, t\_1, \frac{d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \cdot \left(-a\right)\right)\\
\mathbf{elif}\;d \leq 2.45 \cdot 10^{-147}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{d}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}
\end{array}
if d < -3.7499999999999999e28Initial program 40.0%
div-sub40.0%
*-commutative40.0%
add-sqr-sqrt40.0%
times-frac42.5%
fma-neg42.4%
hypot-define42.4%
hypot-define54.2%
associate-/l*67.6%
add-sqr-sqrt67.6%
pow267.6%
hypot-define67.6%
Applied egg-rr67.6%
Taylor expanded in d around inf 92.1%
if -3.7499999999999999e28 < d < -5.0000000000000002e-109Initial program 82.9%
div-sub83.0%
*-commutative83.0%
add-sqr-sqrt83.0%
times-frac80.3%
fma-neg80.3%
hypot-define80.3%
hypot-define96.2%
associate-/l*96.2%
add-sqr-sqrt96.2%
pow296.2%
hypot-define96.2%
Applied egg-rr96.2%
if -5.0000000000000002e-109 < d < 2.45000000000000002e-147Initial program 70.0%
Taylor expanded in c around inf 95.3%
remove-double-neg95.3%
mul-1-neg95.3%
neg-mul-195.3%
distribute-lft-in95.3%
distribute-lft-in95.3%
mul-1-neg95.3%
unsub-neg95.3%
neg-mul-195.3%
mul-1-neg95.3%
remove-double-neg95.3%
associate-/l*95.0%
Simplified95.0%
Taylor expanded in a around 0 95.3%
if 2.45000000000000002e-147 < d Initial program 47.1%
Taylor expanded in d around inf 47.0%
associate-/l*45.4%
Simplified45.4%
*-commutative45.4%
add-sqr-sqrt45.4%
hypot-undefine45.4%
hypot-undefine45.4%
times-frac94.4%
*-commutative94.4%
associate-*l/88.6%
hypot-undefine57.1%
+-commutative57.1%
hypot-undefine88.6%
hypot-undefine57.1%
+-commutative57.1%
hypot-undefine88.6%
Applied egg-rr88.6%
Final simplification92.4%
(FPCore (a b c d)
:precision binary64
(if (<= d -8.5e+42)
(fma (/ c (hypot c d)) (/ b (hypot c d)) (/ (- a) d))
(if (<= d -3.5e-228)
(* (/ 1.0 (hypot c d)) (/ (fma b c (* d (- a))) (hypot c d)))
(if (<= d 1.55e-151)
(/ (- b (/ (* d a) c)) c)
(* (/ (- (/ (* c b) d) a) (hypot d c)) (/ d (hypot d c)))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -8.5e+42) {
tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (-a / d));
} else if (d <= -3.5e-228) {
tmp = (1.0 / hypot(c, d)) * (fma(b, c, (d * -a)) / hypot(c, d));
} else if (d <= 1.55e-151) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = ((((c * b) / d) - a) / hypot(d, c)) * (d / hypot(d, c));
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -8.5e+42) tmp = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(Float64(-a) / d)); elseif (d <= -3.5e-228) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(b, c, Float64(d * Float64(-a))) / hypot(c, d))); elseif (d <= 1.55e-151) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); else tmp = Float64(Float64(Float64(Float64(Float64(c * b) / d) - a) / hypot(d, c)) * Float64(d / hypot(d, c))); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -8.5e+42], 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, -3.5e-228], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.55e-151], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -8.5 \cdot 10^{+42}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\
\mathbf{elif}\;d \leq -3.5 \cdot 10^{-228}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq 1.55 \cdot 10^{-151}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{d}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}
\end{array}
if d < -8.5000000000000003e42Initial program 36.1%
div-sub36.1%
*-commutative36.1%
add-sqr-sqrt36.1%
times-frac38.7%
fma-neg38.7%
hypot-define38.7%
hypot-define51.2%
associate-/l*65.5%
add-sqr-sqrt65.5%
pow265.5%
hypot-define65.5%
Applied egg-rr65.5%
Taylor expanded in d around inf 91.6%
if -8.5000000000000003e42 < d < -3.49999999999999975e-228Initial program 76.9%
*-un-lft-identity76.9%
add-sqr-sqrt76.9%
times-frac76.9%
hypot-define76.9%
fma-neg76.9%
distribute-rgt-neg-in76.9%
hypot-define92.7%
Applied egg-rr92.7%
if -3.49999999999999975e-228 < d < 1.54999999999999992e-151Initial program 71.5%
Taylor expanded in c around inf 98.0%
remove-double-neg98.0%
mul-1-neg98.0%
neg-mul-198.0%
distribute-lft-in98.0%
distribute-lft-in98.0%
mul-1-neg98.0%
unsub-neg98.0%
neg-mul-198.0%
mul-1-neg98.0%
remove-double-neg98.0%
associate-/l*97.6%
Simplified97.6%
Taylor expanded in a around 0 98.0%
if 1.54999999999999992e-151 < d Initial program 47.1%
Taylor expanded in d around inf 47.0%
associate-/l*45.4%
Simplified45.4%
*-commutative45.4%
add-sqr-sqrt45.4%
hypot-undefine45.4%
hypot-undefine45.4%
times-frac94.4%
*-commutative94.4%
associate-*l/88.6%
hypot-undefine57.1%
+-commutative57.1%
hypot-undefine88.6%
hypot-undefine57.1%
+-commutative57.1%
hypot-undefine88.6%
Applied egg-rr88.6%
Final simplification92.4%
(FPCore (a b c d)
:precision binary64
(if (<= d -2.7e+94)
(fma (/ c (hypot c d)) (/ b (hypot c d)) (/ (- a) d))
(if (or (<= d -1.66e-40) (not (<= d 1.12e-153)))
(* (/ (- (/ (* c b) d) a) (hypot d c)) (/ d (hypot d c)))
(/ (- b (/ (* d a) c)) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.7e+94) {
tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (-a / d));
} else if ((d <= -1.66e-40) || !(d <= 1.12e-153)) {
tmp = ((((c * b) / d) - a) / hypot(d, c)) * (d / hypot(d, c));
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -2.7e+94) tmp = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(Float64(-a) / d)); elseif ((d <= -1.66e-40) || !(d <= 1.12e-153)) tmp = Float64(Float64(Float64(Float64(Float64(c * b) / d) - a) / hypot(d, c)) * Float64(d / hypot(d, c))); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.7e+94], 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[Or[LessEqual[d, -1.66e-40], N[Not[LessEqual[d, 1.12e-153]], $MachinePrecision]], N[(N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.7 \cdot 10^{+94}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\
\mathbf{elif}\;d \leq -1.66 \cdot 10^{-40} \lor \neg \left(d \leq 1.12 \cdot 10^{-153}\right):\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{d}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -2.7000000000000001e94Initial program 32.7%
div-sub32.7%
*-commutative32.7%
add-sqr-sqrt32.7%
times-frac35.9%
fma-neg35.9%
hypot-define35.9%
hypot-define49.6%
associate-/l*60.3%
add-sqr-sqrt60.3%
pow260.3%
hypot-define60.3%
Applied egg-rr60.3%
Taylor expanded in d around inf 94.5%
if -2.7000000000000001e94 < d < -1.6600000000000001e-40 or 1.12000000000000005e-153 < d Initial program 53.9%
Taylor expanded in d around inf 53.9%
associate-/l*51.9%
Simplified51.9%
*-commutative51.9%
add-sqr-sqrt51.9%
hypot-undefine51.9%
hypot-undefine51.9%
times-frac92.7%
*-commutative92.7%
associate-*l/89.3%
hypot-undefine63.7%
+-commutative63.7%
hypot-undefine89.3%
hypot-undefine63.7%
+-commutative63.7%
hypot-undefine89.3%
Applied egg-rr89.3%
if -1.6600000000000001e-40 < d < 1.12000000000000005e-153Initial program 71.3%
Taylor expanded in c around inf 93.9%
remove-double-neg93.9%
mul-1-neg93.9%
neg-mul-193.9%
distribute-lft-in93.9%
distribute-lft-in93.9%
mul-1-neg93.9%
unsub-neg93.9%
neg-mul-193.9%
mul-1-neg93.9%
remove-double-neg93.9%
associate-/l*93.5%
Simplified93.5%
Taylor expanded in a around 0 93.9%
Final simplification91.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.66e-40) (not (<= d 3.2e-147))) (* (/ (- (/ (* c b) d) a) (hypot d c)) (/ d (hypot d c))) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.66e-40) || !(d <= 3.2e-147)) {
tmp = ((((c * b) / d) - a) / hypot(d, c)) * (d / hypot(d, c));
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.66e-40) || !(d <= 3.2e-147)) {
tmp = ((((c * b) / d) - a) / Math.hypot(d, c)) * (d / Math.hypot(d, c));
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.66e-40) or not (d <= 3.2e-147): tmp = ((((c * b) / d) - a) / math.hypot(d, c)) * (d / math.hypot(d, c)) else: tmp = (b - ((d * a) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.66e-40) || !(d <= 3.2e-147)) tmp = Float64(Float64(Float64(Float64(Float64(c * b) / d) - a) / hypot(d, c)) * Float64(d / hypot(d, c))); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.66e-40) || ~((d <= 3.2e-147))) tmp = ((((c * b) / d) - a) / hypot(d, c)) * (d / hypot(d, c)); else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.66e-40], N[Not[LessEqual[d, 3.2e-147]], $MachinePrecision]], N[(N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.66 \cdot 10^{-40} \lor \neg \left(d \leq 3.2 \cdot 10^{-147}\right):\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{d}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -1.6600000000000001e-40 or 3.19999999999999979e-147 < d Initial program 49.3%
Taylor expanded in d around inf 49.2%
associate-/l*47.6%
Simplified47.6%
*-commutative47.6%
add-sqr-sqrt47.6%
hypot-undefine47.6%
hypot-undefine47.6%
times-frac93.7%
*-commutative93.7%
associate-*l/87.3%
hypot-undefine58.2%
+-commutative58.2%
hypot-undefine87.3%
hypot-undefine58.2%
+-commutative58.2%
hypot-undefine87.3%
Applied egg-rr87.3%
if -1.6600000000000001e-40 < d < 3.19999999999999979e-147Initial program 71.3%
Taylor expanded in c around inf 93.9%
remove-double-neg93.9%
mul-1-neg93.9%
neg-mul-193.9%
distribute-lft-in93.9%
distribute-lft-in93.9%
mul-1-neg93.9%
unsub-neg93.9%
neg-mul-193.9%
mul-1-neg93.9%
remove-double-neg93.9%
associate-/l*93.5%
Simplified93.5%
Taylor expanded in a around 0 93.9%
Final simplification89.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.9e-8) (not (<= d 4.6e-79))) (/ (- (* b (/ c d)) a) d) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.9e-8) || !(d <= 4.6e-79)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-4.9d-8)) .or. (.not. (d <= 4.6d-79))) then
tmp = ((b * (c / d)) - a) / d
else
tmp = (b - ((d * a) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.9e-8) || !(d <= 4.6e-79)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.9e-8) or not (d <= 4.6e-79): tmp = ((b * (c / d)) - a) / d else: tmp = (b - ((d * a) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.9e-8) || !(d <= 4.6e-79)) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4.9e-8) || ~((d <= 4.6e-79))) tmp = ((b * (c / d)) - a) / d; else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.9e-8], N[Not[LessEqual[d, 4.6e-79]], $MachinePrecision]], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.9 \cdot 10^{-8} \lor \neg \left(d \leq 4.6 \cdot 10^{-79}\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -4.9000000000000002e-8 or 4.60000000000000023e-79 < d Initial program 43.1%
Taylor expanded in c around 0 71.8%
+-commutative71.8%
mul-1-neg71.8%
unsub-neg71.8%
unpow271.8%
associate-/r*75.0%
div-sub74.9%
associate-/l*80.4%
Simplified80.4%
if -4.9000000000000002e-8 < d < 4.60000000000000023e-79Initial program 71.9%
Taylor expanded in c around inf 86.6%
remove-double-neg86.6%
mul-1-neg86.6%
neg-mul-186.6%
distribute-lft-in86.6%
distribute-lft-in86.6%
mul-1-neg86.6%
unsub-neg86.6%
neg-mul-186.6%
mul-1-neg86.6%
remove-double-neg86.6%
associate-/l*85.9%
Simplified85.9%
Taylor expanded in a around 0 86.6%
Final simplification83.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.00335) (not (<= d 5e-79))) (/ (- a) d) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.00335) || !(d <= 5e-79)) {
tmp = -a / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-0.00335d0)) .or. (.not. (d <= 5d-79))) then
tmp = -a / d
else
tmp = (b - ((d * a) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.00335) || !(d <= 5e-79)) {
tmp = -a / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.00335) or not (d <= 5e-79): tmp = -a / d else: tmp = (b - ((d * a) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.00335) || !(d <= 5e-79)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -0.00335) || ~((d <= 5e-79))) tmp = -a / d; else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.00335], N[Not[LessEqual[d, 5e-79]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.00335 \lor \neg \left(d \leq 5 \cdot 10^{-79}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -0.00335000000000000011 or 4.99999999999999999e-79 < d Initial program 43.1%
Taylor expanded in c around 0 66.5%
associate-*r/66.5%
neg-mul-166.5%
Simplified66.5%
if -0.00335000000000000011 < d < 4.99999999999999999e-79Initial program 71.9%
Taylor expanded in c around inf 86.6%
remove-double-neg86.6%
mul-1-neg86.6%
neg-mul-186.6%
distribute-lft-in86.6%
distribute-lft-in86.6%
mul-1-neg86.6%
unsub-neg86.6%
neg-mul-186.6%
mul-1-neg86.6%
remove-double-neg86.6%
associate-/l*85.9%
Simplified85.9%
Taylor expanded in a around 0 86.6%
Final simplification76.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.125) (not (<= d 5e-79))) (/ (- a) d) (/ (- b (/ a (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.125) || !(d <= 5e-79)) {
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 ((d <= (-0.125d0)) .or. (.not. (d <= 5d-79))) 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 ((d <= -0.125) || !(d <= 5e-79)) {
tmp = -a / d;
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.125) or not (d <= 5e-79): tmp = -a / d else: tmp = (b - (a / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.125) || !(d <= 5e-79)) tmp = Float64(Float64(-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 ((d <= -0.125) || ~((d <= 5e-79))) tmp = -a / d; else tmp = (b - (a / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.125], N[Not[LessEqual[d, 5e-79]], $MachinePrecision]], 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}\;d \leq -0.125 \lor \neg \left(d \leq 5 \cdot 10^{-79}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -0.125 or 4.99999999999999999e-79 < d Initial program 43.1%
Taylor expanded in c around 0 66.5%
associate-*r/66.5%
neg-mul-166.5%
Simplified66.5%
if -0.125 < d < 4.99999999999999999e-79Initial program 71.9%
Taylor expanded in c around inf 86.6%
remove-double-neg86.6%
mul-1-neg86.6%
neg-mul-186.6%
distribute-lft-in86.6%
distribute-lft-in86.6%
mul-1-neg86.6%
unsub-neg86.6%
neg-mul-186.6%
mul-1-neg86.6%
remove-double-neg86.6%
associate-/l*85.9%
Simplified85.9%
clear-num86.0%
un-div-inv86.0%
Applied egg-rr86.0%
Final simplification76.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.135) (not (<= d 4.9e-80))) (/ (- a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.135) || !(d <= 4.9e-80)) {
tmp = -a / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-0.135d0)) .or. (.not. (d <= 4.9d-80))) then
tmp = -a / d
else
tmp = (b - (a * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.135) || !(d <= 4.9e-80)) {
tmp = -a / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.135) or not (d <= 4.9e-80): tmp = -a / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.135) || !(d <= 4.9e-80)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -0.135) || ~((d <= 4.9e-80))) tmp = -a / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.135], N[Not[LessEqual[d, 4.9e-80]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.135 \lor \neg \left(d \leq 4.9 \cdot 10^{-80}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -0.13500000000000001 or 4.8999999999999999e-80 < d Initial program 43.1%
Taylor expanded in c around 0 66.5%
associate-*r/66.5%
neg-mul-166.5%
Simplified66.5%
if -0.13500000000000001 < d < 4.8999999999999999e-80Initial program 71.9%
Taylor expanded in c around inf 86.6%
remove-double-neg86.6%
mul-1-neg86.6%
neg-mul-186.6%
distribute-lft-in86.6%
distribute-lft-in86.6%
mul-1-neg86.6%
unsub-neg86.6%
neg-mul-186.6%
mul-1-neg86.6%
remove-double-neg86.6%
associate-/l*85.9%
Simplified85.9%
Final simplification76.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -6.4e-59) (not (<= c 3.5e-26))) (/ b c) (/ (- a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6.4e-59) || !(c <= 3.5e-26)) {
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 <= (-6.4d-59)) .or. (.not. (c <= 3.5d-26))) 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 <= -6.4e-59) || !(c <= 3.5e-26)) {
tmp = b / c;
} else {
tmp = -a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -6.4e-59) or not (c <= 3.5e-26): tmp = b / c else: tmp = -a / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -6.4e-59) || !(c <= 3.5e-26)) tmp = Float64(b / c); else tmp = Float64(Float64(-a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -6.4e-59) || ~((c <= 3.5e-26))) tmp = b / c; else tmp = -a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -6.4e-59], N[Not[LessEqual[c, 3.5e-26]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[((-a) / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.4 \cdot 10^{-59} \lor \neg \left(c \leq 3.5 \cdot 10^{-26}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{d}\\
\end{array}
\end{array}
if c < -6.3999999999999998e-59 or 3.49999999999999985e-26 < c Initial program 47.4%
Taylor expanded in c around inf 62.4%
if -6.3999999999999998e-59 < c < 3.49999999999999985e-26Initial program 70.7%
Taylor expanded in c around 0 69.8%
associate-*r/69.8%
neg-mul-169.8%
Simplified69.8%
Final simplification65.6%
(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 57.6%
Taylor expanded in c around inf 40.8%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024083
(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))))