
(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 (* (/ (- b (* d (/ a c))) (hypot d c)) (/ c (hypot d c)))))
(if (<= c -5.8e+28)
t_0
(if (<= c -7.5e-27)
(fma
(/ c (hypot c d))
(/ b (- c))
(* (/ (/ d (hypot d c)) (hypot d c)) (- a)))
(if (or (<= c -2.4e-72) (not (<= c 2.8e-50)))
t_0
(/ (- (* b (/ c d)) a) d))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b - (d * (a / c))) / hypot(d, c)) * (c / hypot(d, c));
double tmp;
if (c <= -5.8e+28) {
tmp = t_0;
} else if (c <= -7.5e-27) {
tmp = fma((c / hypot(c, d)), (b / -c), (((d / hypot(d, c)) / hypot(d, c)) * -a));
} else if ((c <= -2.4e-72) || !(c <= 2.8e-50)) {
tmp = t_0;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b - Float64(d * Float64(a / c))) / hypot(d, c)) * Float64(c / hypot(d, c))) tmp = 0.0 if (c <= -5.8e+28) tmp = t_0; elseif (c <= -7.5e-27) tmp = fma(Float64(c / hypot(c, d)), Float64(b / Float64(-c)), Float64(Float64(Float64(d / hypot(d, c)) / hypot(d, c)) * Float64(-a))); elseif ((c <= -2.4e-72) || !(c <= 2.8e-50)) tmp = t_0; else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(c / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -5.8e+28], t$95$0, If[LessEqual[c, -7.5e-27], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / (-c)), $MachinePrecision] + N[(N[(N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[c, -2.4e-72], N[Not[LessEqual[c, 2.8e-50]], $MachinePrecision]], 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{b - d \cdot \frac{a}{c}}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{c}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{if}\;c \leq -5.8 \cdot 10^{+28}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -7.5 \cdot 10^{-27}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{-c}, \frac{\frac{d}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)} \cdot \left(-a\right)\right)\\
\mathbf{elif}\;c \leq -2.4 \cdot 10^{-72} \lor \neg \left(c \leq 2.8 \cdot 10^{-50}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -5.8000000000000002e28 or -7.50000000000000029e-27 < c < -2.4e-72 or 2.7999999999999998e-50 < c Initial program 54.4%
Taylor expanded in b around inf 50.9%
mul-1-neg50.9%
unsub-neg50.9%
associate-/l*48.8%
Simplified48.8%
Taylor expanded in c around inf 54.4%
mul-1-neg54.4%
*-commutative54.4%
associate-*r/54.4%
distribute-lft-neg-in54.4%
cancel-sign-sub-inv54.4%
Simplified54.4%
*-commutative54.4%
+-commutative54.4%
add-sqr-sqrt54.4%
hypot-undefine54.4%
hypot-undefine54.4%
times-frac96.4%
Applied egg-rr96.4%
if -5.8000000000000002e28 < c < -7.50000000000000029e-27Initial program 64.1%
div-sub64.1%
*-commutative64.1%
add-sqr-sqrt64.1%
times-frac64.3%
fma-neg64.3%
hypot-define64.3%
hypot-define64.3%
associate-/l*65.7%
add-sqr-sqrt65.7%
pow265.7%
hypot-define65.7%
Applied egg-rr65.7%
*-un-lft-identity65.7%
add-sqr-sqrt65.7%
sqrt-unprod58.8%
sqr-neg58.8%
unpow258.8%
hypot-undefine58.8%
hypot-undefine58.8%
add-sqr-sqrt58.8%
+-commutative58.8%
add-sqr-sqrt58.8%
hypot-undefine58.8%
hypot-undefine58.8%
unpow258.8%
unpow258.8%
hypot-undefine58.8%
hypot-undefine58.8%
add-sqr-sqrt58.8%
+-commutative58.8%
add-sqr-sqrt58.8%
hypot-undefine58.8%
hypot-undefine58.8%
unpow258.8%
Applied egg-rr99.9%
associate-*l/99.9%
*-lft-identity99.9%
Simplified99.9%
Taylor expanded in c around -inf 91.1%
associate-*r/91.1%
neg-mul-191.1%
Simplified91.1%
if -2.4e-72 < c < 2.7999999999999998e-50Initial program 75.9%
div-sub68.8%
*-commutative68.8%
add-sqr-sqrt68.8%
times-frac65.2%
fma-neg65.2%
hypot-define65.2%
hypot-define67.2%
associate-/l*69.7%
add-sqr-sqrt69.7%
pow269.7%
hypot-define69.7%
Applied egg-rr69.7%
Taylor expanded in d around inf 92.5%
associate-/l*92.5%
Simplified92.5%
Final simplification94.6%
(FPCore (a b c d) :precision binary64 (fma (/ c (hypot c d)) (/ b (hypot c d)) (* (/ (/ d (hypot d c)) (hypot d c)) (- a))))
double code(double a, double b, double c, double d) {
return fma((c / hypot(c, d)), (b / hypot(c, d)), (((d / hypot(d, c)) / hypot(d, c)) * -a));
}
function code(a, b, c, d) return fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(Float64(Float64(d / hypot(d, c)) / hypot(d, c)) * Float64(-a))) end
code[a_, b_, c_, d_] := N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{\frac{d}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)} \cdot \left(-a\right)\right)
\end{array}
Initial program 63.3%
div-sub60.6%
*-commutative60.6%
add-sqr-sqrt60.6%
times-frac61.8%
fma-neg61.8%
hypot-define61.8%
hypot-define73.6%
associate-/l*75.0%
add-sqr-sqrt75.0%
pow275.0%
hypot-define75.0%
Applied egg-rr75.0%
*-un-lft-identity75.0%
add-sqr-sqrt75.0%
sqrt-unprod64.2%
sqr-neg64.2%
unpow264.2%
hypot-undefine64.2%
hypot-undefine64.2%
add-sqr-sqrt64.2%
+-commutative64.2%
add-sqr-sqrt64.2%
hypot-undefine64.2%
hypot-undefine64.2%
unpow264.2%
unpow264.2%
hypot-undefine64.2%
hypot-undefine64.2%
add-sqr-sqrt64.2%
+-commutative64.2%
add-sqr-sqrt64.2%
hypot-undefine64.2%
hypot-undefine64.2%
unpow264.2%
Applied egg-rr93.1%
associate-*l/93.1%
*-lft-identity93.1%
Simplified93.1%
Final simplification93.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.25e-73) (not (<= c 3.4e-50))) (* (/ (- b (* d (/ a c))) (hypot d c)) (/ c (hypot d c))) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.25e-73) || !(c <= 3.4e-50)) {
tmp = ((b - (d * (a / c))) / hypot(d, c)) * (c / hypot(d, c));
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.25e-73) || !(c <= 3.4e-50)) {
tmp = ((b - (d * (a / c))) / Math.hypot(d, c)) * (c / Math.hypot(d, c));
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.25e-73) or not (c <= 3.4e-50): tmp = ((b - (d * (a / c))) / math.hypot(d, c)) * (c / math.hypot(d, c)) else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.25e-73) || !(c <= 3.4e-50)) tmp = Float64(Float64(Float64(b - Float64(d * Float64(a / c))) / hypot(d, c)) * Float64(c / hypot(d, 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 <= -2.25e-73) || ~((c <= 3.4e-50))) tmp = ((b - (d * (a / c))) / hypot(d, c)) * (c / hypot(d, c)); else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.25e-73], N[Not[LessEqual[c, 3.4e-50]], $MachinePrecision]], N[(N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(c / N[Sqrt[d ^ 2 + c ^ 2], $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 -2.25 \cdot 10^{-73} \lor \neg \left(c \leq 3.4 \cdot 10^{-50}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{c}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -2.25e-73 or 3.40000000000000014e-50 < c Initial program 55.3%
Taylor expanded in b around inf 52.1%
mul-1-neg52.1%
unsub-neg52.1%
associate-/l*49.5%
Simplified49.5%
Taylor expanded in c around inf 55.3%
mul-1-neg55.3%
*-commutative55.3%
associate-*r/54.6%
distribute-lft-neg-in54.6%
cancel-sign-sub-inv54.6%
Simplified54.6%
*-commutative54.6%
+-commutative54.6%
add-sqr-sqrt54.6%
hypot-undefine54.6%
hypot-undefine54.6%
times-frac93.0%
Applied egg-rr93.0%
if -2.25e-73 < c < 3.40000000000000014e-50Initial program 75.9%
div-sub68.8%
*-commutative68.8%
add-sqr-sqrt68.8%
times-frac65.2%
fma-neg65.2%
hypot-define65.2%
hypot-define67.2%
associate-/l*69.7%
add-sqr-sqrt69.7%
pow269.7%
hypot-define69.7%
Applied egg-rr69.7%
Taylor expanded in d around inf 92.5%
associate-/l*92.5%
Simplified92.5%
Final simplification92.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (* d (/ a c))) c)))
(if (<= c -6.2e+68)
t_0
(if (<= c 2.5e-78)
(/ (- (* b (/ c d)) a) d)
(if (<= c 8.6e+63) (/ (- (* c b) (* d a)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -6.2e+68) {
tmp = t_0;
} else if (c <= 2.5e-78) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 8.6e+63) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
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 = (b - (d * (a / c))) / c
if (c <= (-6.2d+68)) then
tmp = t_0
else if (c <= 2.5d-78) then
tmp = ((b * (c / d)) - a) / d
else if (c <= 8.6d+63) then
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -6.2e+68) {
tmp = t_0;
} else if (c <= 2.5e-78) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 8.6e+63) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b - (d * (a / c))) / c tmp = 0 if c <= -6.2e+68: tmp = t_0 elif c <= 2.5e-78: tmp = ((b * (c / d)) - a) / d elif c <= 8.6e+63: tmp = ((c * b) - (d * a)) / ((c * c) + (d * d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(d * Float64(a / c))) / c) tmp = 0.0 if (c <= -6.2e+68) tmp = t_0; elseif (c <= 2.5e-78) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (c <= 8.6e+63) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b - (d * (a / c))) / c; tmp = 0.0; if (c <= -6.2e+68) tmp = t_0; elseif (c <= 2.5e-78) tmp = ((b * (c / d)) - a) / d; elseif (c <= 8.6e+63) tmp = ((c * b) - (d * a)) / ((c * c) + (d * d)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -6.2e+68], t$95$0, If[LessEqual[c, 2.5e-78], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8.6e+63], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -6.2 \cdot 10^{+68}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.5 \cdot 10^{-78}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 8.6 \cdot 10^{+63}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -6.1999999999999997e68 or 8.6000000000000001e63 < c Initial program 42.6%
div-sub42.6%
*-commutative42.6%
add-sqr-sqrt42.6%
times-frac49.6%
fma-neg49.6%
hypot-define49.6%
hypot-define77.7%
associate-/l*79.6%
add-sqr-sqrt79.6%
pow279.6%
hypot-define79.6%
Applied egg-rr79.6%
Taylor expanded in c around inf 77.4%
mul-1-neg77.4%
*-commutative77.4%
associate-*r/86.0%
distribute-lft-neg-in86.0%
cancel-sign-sub-inv86.0%
Simplified86.0%
if -6.1999999999999997e68 < c < 2.4999999999999998e-78Initial program 72.4%
div-sub66.6%
*-commutative66.6%
add-sqr-sqrt66.6%
times-frac63.7%
fma-neg63.7%
hypot-define63.7%
hypot-define66.8%
associate-/l*67.6%
add-sqr-sqrt67.6%
pow267.6%
hypot-define67.6%
Applied egg-rr67.6%
Taylor expanded in d around inf 83.7%
associate-/l*85.3%
Simplified85.3%
if 2.4999999999999998e-78 < c < 8.6000000000000001e63Initial program 84.8%
Final simplification85.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.1e+34) (not (<= d 1.1e-20))) (/ (- (* b (/ c d)) a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.1e+34) || !(d <= 1.1e-20)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-3.1d+34)) .or. (.not. (d <= 1.1d-20))) then
tmp = ((b * (c / d)) - a) / d
else
tmp = (b - (a * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.1e+34) || !(d <= 1.1e-20)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.1e+34) or not (d <= 1.1e-20): tmp = ((b * (c / d)) - a) / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.1e+34) || !(d <= 1.1e-20)) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -3.1e+34) || ~((d <= 1.1e-20))) tmp = ((b * (c / d)) - a) / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.1e+34], N[Not[LessEqual[d, 1.1e-20]], $MachinePrecision]], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.1 \cdot 10^{+34} \lor \neg \left(d \leq 1.1 \cdot 10^{-20}\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -3.09999999999999977e34 or 1.09999999999999995e-20 < d Initial program 50.1%
div-sub50.1%
*-commutative50.1%
add-sqr-sqrt50.1%
times-frac51.0%
fma-neg51.0%
hypot-define51.0%
hypot-define59.1%
associate-/l*64.6%
add-sqr-sqrt64.6%
pow264.6%
hypot-define64.6%
Applied egg-rr64.6%
Taylor expanded in d around inf 73.6%
associate-/l*78.2%
Simplified78.2%
if -3.09999999999999977e34 < d < 1.09999999999999995e-20Initial program 77.8%
Taylor expanded in c around inf 84.7%
remove-double-neg84.7%
mul-1-neg84.7%
neg-mul-184.7%
distribute-lft-in84.7%
mul-1-neg84.7%
distribute-neg-in84.7%
mul-1-neg84.7%
remove-double-neg84.7%
unsub-neg84.7%
associate-/l*85.3%
Simplified85.3%
Final simplification81.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -7.7e+34) (not (<= d 1.5e-20))) (/ a (- d)) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.7e+34) || !(d <= 1.5e-20)) {
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 <= (-7.7d+34)) .or. (.not. (d <= 1.5d-20))) 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 <= -7.7e+34) || !(d <= 1.5e-20)) {
tmp = a / -d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -7.7e+34) or not (d <= 1.5e-20): tmp = a / -d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -7.7e+34) || !(d <= 1.5e-20)) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -7.7e+34) || ~((d <= 1.5e-20))) tmp = a / -d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7.7e+34], N[Not[LessEqual[d, 1.5e-20]], $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 -7.7 \cdot 10^{+34} \lor \neg \left(d \leq 1.5 \cdot 10^{-20}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -7.6999999999999999e34 or 1.50000000000000014e-20 < d Initial program 50.1%
Taylor expanded in c around 0 71.0%
associate-*r/71.0%
neg-mul-171.0%
Simplified71.0%
if -7.6999999999999999e34 < d < 1.50000000000000014e-20Initial program 77.8%
Taylor expanded in c around inf 84.7%
remove-double-neg84.7%
mul-1-neg84.7%
neg-mul-184.7%
distribute-lft-in84.7%
mul-1-neg84.7%
distribute-neg-in84.7%
mul-1-neg84.7%
remove-double-neg84.7%
unsub-neg84.7%
associate-/l*85.3%
Simplified85.3%
Final simplification77.9%
(FPCore (a b c d) :precision binary64 (if (<= d -4e+27) (- (/ (* c (/ b d)) d) (/ a d)) (if (<= d 4.3e-21) (/ (- b (* a (/ d c))) c) (/ (- (* b (/ c d)) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4e+27) {
tmp = ((c * (b / d)) / d) - (a / d);
} else if (d <= 4.3e-21) {
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 (d <= (-4d+27)) then
tmp = ((c * (b / d)) / d) - (a / d)
else if (d <= 4.3d-21) 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 (d <= -4e+27) {
tmp = ((c * (b / d)) / d) - (a / d);
} else if (d <= 4.3e-21) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -4e+27: tmp = ((c * (b / d)) / d) - (a / d) elif d <= 4.3e-21: 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 (d <= -4e+27) tmp = Float64(Float64(Float64(c * Float64(b / d)) / d) - Float64(a / d)); elseif (d <= 4.3e-21) 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 (d <= -4e+27) tmp = ((c * (b / d)) / d) - (a / d); elseif (d <= 4.3e-21) tmp = (b - (a * (d / c))) / c; else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -4e+27], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.3e-21], 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}\;d \leq -4 \cdot 10^{+27}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d}}{d} - \frac{a}{d}\\
\mathbf{elif}\;d \leq 4.3 \cdot 10^{-21}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if d < -4.0000000000000001e27Initial program 51.8%
div-sub51.8%
*-commutative51.8%
add-sqr-sqrt51.8%
times-frac51.8%
fma-neg51.8%
hypot-define51.8%
hypot-define54.3%
associate-/l*63.1%
add-sqr-sqrt63.1%
pow263.1%
hypot-define63.1%
Applied egg-rr63.1%
Taylor expanded in d around inf 75.8%
associate-/l*80.8%
Simplified80.8%
clear-num80.7%
un-div-inv80.8%
Applied egg-rr80.8%
div-sub80.8%
associate-/r/80.8%
Applied egg-rr80.8%
if -4.0000000000000001e27 < d < 4.2999999999999998e-21Initial program 77.8%
Taylor expanded in c around inf 84.7%
remove-double-neg84.7%
mul-1-neg84.7%
neg-mul-184.7%
distribute-lft-in84.7%
mul-1-neg84.7%
distribute-neg-in84.7%
mul-1-neg84.7%
remove-double-neg84.7%
unsub-neg84.7%
associate-/l*85.3%
Simplified85.3%
if 4.2999999999999998e-21 < d Initial program 48.6%
div-sub48.6%
*-commutative48.6%
add-sqr-sqrt48.6%
times-frac50.3%
fma-neg50.3%
hypot-define50.3%
hypot-define63.4%
associate-/l*65.9%
add-sqr-sqrt65.9%
pow265.9%
hypot-define65.9%
Applied egg-rr65.9%
Taylor expanded in d around inf 71.7%
associate-/l*75.9%
Simplified75.9%
Final simplification81.6%
(FPCore (a b c d) :precision binary64 (if (<= d -8.2e+26) (/ (- (* c (/ b d)) a) d) (if (<= d 2e-24) (/ (- b (* a (/ d c))) c) (/ (- (* b (/ c d)) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -8.2e+26) {
tmp = ((c * (b / d)) - a) / d;
} else if (d <= 2e-24) {
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 (d <= (-8.2d+26)) then
tmp = ((c * (b / d)) - a) / d
else if (d <= 2d-24) 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 (d <= -8.2e+26) {
tmp = ((c * (b / d)) - a) / d;
} else if (d <= 2e-24) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -8.2e+26: tmp = ((c * (b / d)) - a) / d elif d <= 2e-24: 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 (d <= -8.2e+26) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); elseif (d <= 2e-24) 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 (d <= -8.2e+26) tmp = ((c * (b / d)) - a) / d; elseif (d <= 2e-24) tmp = (b - (a * (d / c))) / c; else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -8.2e+26], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 2e-24], 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}\;d \leq -8.2 \cdot 10^{+26}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{elif}\;d \leq 2 \cdot 10^{-24}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if d < -8.19999999999999967e26Initial program 51.8%
Taylor expanded in c around 0 75.5%
+-commutative75.5%
mul-1-neg75.5%
unsub-neg75.5%
unpow275.5%
associate-/r*75.8%
div-sub75.8%
*-commutative75.8%
associate-/l*80.8%
Simplified80.8%
if -8.19999999999999967e26 < d < 1.99999999999999985e-24Initial program 77.8%
Taylor expanded in c around inf 84.7%
remove-double-neg84.7%
mul-1-neg84.7%
neg-mul-184.7%
distribute-lft-in84.7%
mul-1-neg84.7%
distribute-neg-in84.7%
mul-1-neg84.7%
remove-double-neg84.7%
unsub-neg84.7%
associate-/l*85.3%
Simplified85.3%
if 1.99999999999999985e-24 < d Initial program 48.6%
div-sub48.6%
*-commutative48.6%
add-sqr-sqrt48.6%
times-frac50.3%
fma-neg50.3%
hypot-define50.3%
hypot-define63.4%
associate-/l*65.9%
add-sqr-sqrt65.9%
pow265.9%
hypot-define65.9%
Applied egg-rr65.9%
Taylor expanded in d around inf 71.7%
associate-/l*75.9%
Simplified75.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.28e+26) (not (<= d 3.3e-29))) (/ a (- d)) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.28e+26) || !(d <= 3.3e-29)) {
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.28d+26)) .or. (.not. (d <= 3.3d-29))) 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.28e+26) || !(d <= 3.3e-29)) {
tmp = a / -d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.28e+26) or not (d <= 3.3e-29): tmp = a / -d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.28e+26) || !(d <= 3.3e-29)) tmp = Float64(a / Float64(-d)); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.28e+26) || ~((d <= 3.3e-29))) tmp = a / -d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.28e+26], N[Not[LessEqual[d, 3.3e-29]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.28 \cdot 10^{+26} \lor \neg \left(d \leq 3.3 \cdot 10^{-29}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -1.28e26 or 3.30000000000000028e-29 < d Initial program 50.2%
Taylor expanded in c around 0 70.7%
associate-*r/70.7%
neg-mul-170.7%
Simplified70.7%
if -1.28e26 < d < 3.30000000000000028e-29Initial program 78.2%
Taylor expanded in c around inf 64.6%
Final simplification67.8%
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
return b / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = b / c
end function
public static double code(double a, double b, double c, double d) {
return b / c;
}
def code(a, b, c, d): return b / c
function code(a, b, c, d) return Float64(b / c) end
function tmp = code(a, b, c, d) tmp = b / c; end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{c}
\end{array}
Initial program 63.3%
Taylor expanded in c around inf 39.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 2024108
(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))))