
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(if (or (<= b -1.75e-9) (not (<= b 5.5e-32)))
(fma
(/ c (hypot c d))
(/ b (hypot c d))
(* a (/ (- d) (pow (hypot c d) 2.0))))
(* (/ (- (/ (* b c) d) a) (hypot c d)) (/ d (hypot c d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((b <= -1.75e-9) || !(b <= 5.5e-32)) {
tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (a * (-d / pow(hypot(c, d), 2.0))));
} else {
tmp = ((((b * c) / d) - a) / hypot(c, d)) * (d / hypot(c, d));
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((b <= -1.75e-9) || !(b <= 5.5e-32)) 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(Float64(Float64(b * c) / d) - a) / hypot(c, d)) * Float64(d / hypot(c, d))); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[b, -1.75e-9], N[Not[LessEqual[b, 5.5e-32]], $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[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.75 \cdot 10^{-9} \lor \neg \left(b \leq 5.5 \cdot 10^{-32}\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{\frac{b \cdot c}{d} - a}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if b < -1.75e-9 or 5.50000000000000024e-32 < b Initial program 55.9%
div-sub53.5%
*-commutative53.5%
add-sqr-sqrt53.5%
times-frac54.3%
fmm-def54.3%
hypot-define54.3%
hypot-define82.2%
associate-/l*85.5%
add-sqr-sqrt85.5%
pow285.5%
hypot-define85.5%
Applied egg-rr85.5%
if -1.75e-9 < b < 5.50000000000000024e-32Initial program 64.3%
Taylor expanded in d around inf 64.3%
sub-neg64.3%
sub-neg64.3%
*-commutative64.3%
associate-/l*64.3%
Simplified64.3%
*-commutative64.3%
add-sqr-sqrt64.3%
hypot-undefine64.3%
hypot-undefine64.3%
times-frac97.6%
associate-*r/96.1%
Applied egg-rr96.1%
Final simplification90.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* b c) (* d a))))
(if (<= (/ t_0 (+ (* c c) (* d d))) 2e+221)
(* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
(/ (- (* b (/ c d)) a) d))))
double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (d * a);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 2e+221) {
tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (d * a);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 2e+221) {
tmp = (1.0 / Math.hypot(c, d)) * (t_0 / Math.hypot(c, d));
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b * c) - (d * a) tmp = 0 if (t_0 / ((c * c) + (d * d))) <= 2e+221: tmp = (1.0 / math.hypot(c, d)) * (t_0 / math.hypot(c, d)) else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b * c) - Float64(d * a)) tmp = 0.0 if (Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) <= 2e+221) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d))); else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b * c) - (d * a); tmp = 0.0; if ((t_0 / ((c * c) + (d * d))) <= 2e+221) tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d)); else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e+221], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot c - d \cdot a\\
\mathbf{if}\;\frac{t\_0}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+221}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t\_0}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 2.0000000000000001e221Initial program 80.3%
*-un-lft-identity80.3%
add-sqr-sqrt80.3%
times-frac80.2%
hypot-define80.2%
hypot-define95.7%
Applied egg-rr95.7%
if 2.0000000000000001e221 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 15.6%
div-sub10.2%
*-commutative10.2%
add-sqr-sqrt10.2%
times-frac14.0%
fmm-def14.0%
hypot-define14.0%
hypot-define49.0%
associate-/l*55.5%
add-sqr-sqrt55.5%
pow255.5%
hypot-define55.5%
Applied egg-rr55.5%
Taylor expanded in d around inf 59.9%
div-sub59.9%
*-commutative59.9%
div-sub59.9%
*-commutative59.9%
associate-/l*66.3%
Simplified66.3%
Final simplification86.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.2e+110) (not (<= c 1.9e+204))) (/ (- b (* d (/ a c))) c) (* (/ (- (/ (* b c) d) a) (hypot c d)) (/ d (hypot c d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.2e+110) || !(c <= 1.9e+204)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = ((((b * c) / d) - a) / hypot(c, d)) * (d / hypot(c, d));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.2e+110) || !(c <= 1.9e+204)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = ((((b * c) / d) - a) / Math.hypot(c, d)) * (d / Math.hypot(c, d));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.2e+110) or not (c <= 1.9e+204): tmp = (b - (d * (a / c))) / c else: tmp = ((((b * c) / d) - a) / math.hypot(c, d)) * (d / math.hypot(c, d)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.2e+110) || !(c <= 1.9e+204)) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); else tmp = Float64(Float64(Float64(Float64(Float64(b * c) / d) - a) / hypot(c, d)) * Float64(d / hypot(c, d))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.2e+110) || ~((c <= 1.9e+204))) tmp = (b - (d * (a / c))) / c; else tmp = ((((b * c) / d) - a) / hypot(c, d)) * (d / hypot(c, d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.2e+110], N[Not[LessEqual[c, 1.9e+204]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.2 \cdot 10^{+110} \lor \neg \left(c \leq 1.9 \cdot 10^{+204}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if c < -2.19999999999999992e110 or 1.8999999999999999e204 < c Initial program 29.3%
Taylor expanded in c around inf 84.8%
mul-1-neg84.8%
unsub-neg84.8%
*-commutative84.8%
Simplified84.8%
associate-/l*88.0%
Applied egg-rr88.0%
if -2.19999999999999992e110 < c < 1.8999999999999999e204Initial program 70.3%
Taylor expanded in d around inf 66.8%
sub-neg66.8%
sub-neg66.8%
*-commutative66.8%
associate-/l*64.2%
Simplified64.2%
*-commutative64.2%
add-sqr-sqrt64.2%
hypot-undefine64.2%
hypot-undefine64.2%
times-frac89.8%
associate-*r/89.7%
Applied egg-rr89.7%
Final simplification89.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* d a)) (+ (* c c) (* d d))))
(t_1 (/ (- b (* d (/ a c))) c)))
(if (<= c -3.1e+122)
t_1
(if (<= c -3.3e-59)
t_0
(if (<= c 3.2e-68)
(/ (- (* (* b c) (/ 1.0 d)) a) d)
(if (<= c 4.7e+101) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (d * a)) / ((c * c) + (d * d));
double t_1 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -3.1e+122) {
tmp = t_1;
} else if (c <= -3.3e-59) {
tmp = t_0;
} else if (c <= 3.2e-68) {
tmp = (((b * c) * (1.0 / d)) - a) / d;
} else if (c <= 4.7e+101) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = ((b * c) - (d * a)) / ((c * c) + (d * d))
t_1 = (b - (d * (a / c))) / c
if (c <= (-3.1d+122)) then
tmp = t_1
else if (c <= (-3.3d-59)) then
tmp = t_0
else if (c <= 3.2d-68) then
tmp = (((b * c) * (1.0d0 / d)) - a) / d
else if (c <= 4.7d+101) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (d * a)) / ((c * c) + (d * d));
double t_1 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -3.1e+122) {
tmp = t_1;
} else if (c <= -3.3e-59) {
tmp = t_0;
} else if (c <= 3.2e-68) {
tmp = (((b * c) * (1.0 / d)) - a) / d;
} else if (c <= 4.7e+101) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (d * a)) / ((c * c) + (d * d)) t_1 = (b - (d * (a / c))) / c tmp = 0 if c <= -3.1e+122: tmp = t_1 elif c <= -3.3e-59: tmp = t_0 elif c <= 3.2e-68: tmp = (((b * c) * (1.0 / d)) - a) / d elif c <= 4.7e+101: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(b - Float64(d * Float64(a / c))) / c) tmp = 0.0 if (c <= -3.1e+122) tmp = t_1; elseif (c <= -3.3e-59) tmp = t_0; elseif (c <= 3.2e-68) tmp = Float64(Float64(Float64(Float64(b * c) * Float64(1.0 / d)) - a) / d); elseif (c <= 4.7e+101) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * c) - (d * a)) / ((c * c) + (d * d)); t_1 = (b - (d * (a / c))) / c; tmp = 0.0; if (c <= -3.1e+122) tmp = t_1; elseif (c <= -3.3e-59) tmp = t_0; elseif (c <= 3.2e-68) tmp = (((b * c) * (1.0 / d)) - a) / d; elseif (c <= 4.7e+101) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3.1e+122], t$95$1, If[LessEqual[c, -3.3e-59], t$95$0, If[LessEqual[c, 3.2e-68], N[(N[(N[(N[(b * c), $MachinePrecision] * N[(1.0 / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.7e+101], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - d \cdot a}{c \cdot c + d \cdot d}\\
t_1 := \frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -3.1 \cdot 10^{+122}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -3.3 \cdot 10^{-59}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 3.2 \cdot 10^{-68}:\\
\;\;\;\;\frac{\left(b \cdot c\right) \cdot \frac{1}{d} - a}{d}\\
\mathbf{elif}\;c \leq 4.7 \cdot 10^{+101}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -3.09999999999999999e122 or 4.69999999999999971e101 < c Initial program 34.1%
Taylor expanded in c around inf 79.6%
mul-1-neg79.6%
unsub-neg79.6%
*-commutative79.6%
Simplified79.6%
associate-/l*82.1%
Applied egg-rr82.1%
if -3.09999999999999999e122 < c < -3.29999999999999982e-59 or 3.1999999999999999e-68 < c < 4.69999999999999971e101Initial program 79.7%
if -3.29999999999999982e-59 < c < 3.1999999999999999e-68Initial program 68.9%
div-sub64.7%
*-commutative64.7%
add-sqr-sqrt64.7%
times-frac62.5%
fmm-def62.5%
hypot-define62.5%
hypot-define65.1%
associate-/l*69.1%
add-sqr-sqrt69.1%
pow269.1%
hypot-define69.1%
Applied egg-rr69.1%
Taylor expanded in d around inf 91.1%
div-sub91.0%
*-commutative91.0%
div-sub91.1%
*-commutative91.1%
associate-/l*90.2%
Simplified90.2%
associate-*r/91.1%
clear-num91.0%
Applied egg-rr91.0%
associate-/r/91.1%
Simplified91.1%
Final simplification85.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.2e-37) (not (<= c 86.0))) (/ (- b (* d (/ a c))) c) (/ (- (* (* b c) (/ 1.0 d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.2e-37) || !(c <= 86.0)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = (((b * c) * (1.0 / d)) - a) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-4.2d-37)) .or. (.not. (c <= 86.0d0))) then
tmp = (b - (d * (a / c))) / c
else
tmp = (((b * c) * (1.0d0 / d)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.2e-37) || !(c <= 86.0)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = (((b * c) * (1.0 / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4.2e-37) or not (c <= 86.0): tmp = (b - (d * (a / c))) / c else: tmp = (((b * c) * (1.0 / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -4.2e-37) || !(c <= 86.0)) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); else tmp = Float64(Float64(Float64(Float64(b * c) * Float64(1.0 / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -4.2e-37) || ~((c <= 86.0))) tmp = (b - (d * (a / c))) / c; else tmp = (((b * c) * (1.0 / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.2e-37], N[Not[LessEqual[c, 86.0]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(b * c), $MachinePrecision] * N[(1.0 / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.2 \cdot 10^{-37} \lor \neg \left(c \leq 86\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(b \cdot c\right) \cdot \frac{1}{d} - a}{d}\\
\end{array}
\end{array}
if c < -4.2000000000000002e-37 or 86 < c Initial program 52.5%
Taylor expanded in c around inf 73.8%
mul-1-neg73.8%
unsub-neg73.8%
*-commutative73.8%
Simplified73.8%
associate-/l*75.4%
Applied egg-rr75.4%
if -4.2000000000000002e-37 < c < 86Initial program 68.7%
div-sub65.0%
*-commutative65.0%
add-sqr-sqrt64.9%
times-frac63.0%
fmm-def63.0%
hypot-define63.0%
hypot-define65.3%
associate-/l*69.8%
add-sqr-sqrt69.8%
pow269.8%
hypot-define69.8%
Applied egg-rr69.8%
Taylor expanded in d around inf 87.2%
div-sub87.1%
*-commutative87.1%
div-sub87.2%
*-commutative87.2%
associate-/l*86.4%
Simplified86.4%
associate-*r/87.2%
clear-num87.1%
Applied egg-rr87.1%
associate-/r/87.2%
Simplified87.2%
Final simplification80.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.15e-32) (not (<= c 61.0))) (/ (- b (* d (/ a c))) c) (/ (- (/ (* b c) d) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.15e-32) || !(c <= 61.0)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = (((b * c) / d) - a) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-4.15d-32)) .or. (.not. (c <= 61.0d0))) then
tmp = (b - (d * (a / c))) / c
else
tmp = (((b * c) / d) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.15e-32) || !(c <= 61.0)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = (((b * c) / d) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4.15e-32) or not (c <= 61.0): tmp = (b - (d * (a / c))) / c else: tmp = (((b * c) / d) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -4.15e-32) || !(c <= 61.0)) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); else tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -4.15e-32) || ~((c <= 61.0))) tmp = (b - (d * (a / c))) / c; else tmp = (((b * c) / d) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.15e-32], N[Not[LessEqual[c, 61.0]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.15 \cdot 10^{-32} \lor \neg \left(c \leq 61\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -4.15000000000000006e-32 or 61 < c Initial program 52.5%
Taylor expanded in c around inf 73.8%
mul-1-neg73.8%
unsub-neg73.8%
*-commutative73.8%
Simplified73.8%
associate-/l*75.4%
Applied egg-rr75.4%
if -4.15000000000000006e-32 < c < 61Initial program 68.7%
div-sub65.0%
*-commutative65.0%
add-sqr-sqrt64.9%
times-frac63.0%
fmm-def63.0%
hypot-define63.0%
hypot-define65.3%
associate-/l*69.8%
add-sqr-sqrt69.8%
pow269.8%
hypot-define69.8%
Applied egg-rr69.8%
Taylor expanded in d around inf 87.2%
Final simplification80.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5.2e-32) (not (<= c 61.0))) (/ (- b (* d (/ a c))) c) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.2e-32) || !(c <= 61.0)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-5.2d-32)) .or. (.not. (c <= 61.0d0))) then
tmp = (b - (d * (a / c))) / c
else
tmp = ((b * (c / d)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.2e-32) || !(c <= 61.0)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5.2e-32) or not (c <= 61.0): tmp = (b - (d * (a / c))) / c else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5.2e-32) || !(c <= 61.0)) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -5.2e-32) || ~((c <= 61.0))) tmp = (b - (d * (a / c))) / c; else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5.2e-32], N[Not[LessEqual[c, 61.0]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.2 \cdot 10^{-32} \lor \neg \left(c \leq 61\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -5.1999999999999995e-32 or 61 < c Initial program 52.5%
Taylor expanded in c around inf 73.8%
mul-1-neg73.8%
unsub-neg73.8%
*-commutative73.8%
Simplified73.8%
associate-/l*75.4%
Applied egg-rr75.4%
if -5.1999999999999995e-32 < c < 61Initial program 68.7%
div-sub65.0%
*-commutative65.0%
add-sqr-sqrt64.9%
times-frac63.0%
fmm-def63.0%
hypot-define63.0%
hypot-define65.3%
associate-/l*69.8%
add-sqr-sqrt69.8%
pow269.8%
hypot-define69.8%
Applied egg-rr69.8%
Taylor expanded in d around inf 87.2%
div-sub87.1%
*-commutative87.1%
div-sub87.2%
*-commutative87.2%
associate-/l*86.4%
Simplified86.4%
Final simplification80.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -6.5e+43) (not (<= d 7.5e+91))) (/ a (- d)) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.5e+43) || !(d <= 7.5e+91)) {
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 <= (-6.5d+43)) .or. (.not. (d <= 7.5d+91))) 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 <= -6.5e+43) || !(d <= 7.5e+91)) {
tmp = a / -d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -6.5e+43) or not (d <= 7.5e+91): tmp = a / -d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -6.5e+43) || !(d <= 7.5e+91)) 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 <= -6.5e+43) || ~((d <= 7.5e+91))) tmp = a / -d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6.5e+43], N[Not[LessEqual[d, 7.5e+91]], $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 -6.5 \cdot 10^{+43} \lor \neg \left(d \leq 7.5 \cdot 10^{+91}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -6.4999999999999998e43 or 7.50000000000000033e91 < d Initial program 42.2%
Taylor expanded in c around 0 74.3%
associate-*r/74.3%
neg-mul-174.3%
Simplified74.3%
if -6.4999999999999998e43 < d < 7.50000000000000033e91Initial program 71.3%
div-sub68.5%
*-commutative68.5%
add-sqr-sqrt68.5%
times-frac69.8%
fmm-def69.8%
hypot-define69.8%
hypot-define88.2%
associate-/l*88.0%
add-sqr-sqrt88.0%
pow288.0%
hypot-define88.0%
Applied egg-rr88.0%
Taylor expanded in c around inf 71.3%
mul-1-neg71.3%
unsub-neg71.3%
associate-/l*71.8%
Simplified71.8%
Final simplification72.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -6e-49) (not (<= c 92.0))) (/ b c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6e-49) || !(c <= 92.0)) {
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 <= (-6d-49)) .or. (.not. (c <= 92.0d0))) 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 <= -6e-49) || !(c <= 92.0)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -6e-49) or not (c <= 92.0): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -6e-49) || !(c <= 92.0)) 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 <= -6e-49) || ~((c <= 92.0))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -6e-49], N[Not[LessEqual[c, 92.0]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6 \cdot 10^{-49} \lor \neg \left(c \leq 92\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -6e-49 or 92 < c Initial program 53.2%
Taylor expanded in c around inf 61.0%
if -6e-49 < c < 92Initial program 68.2%
Taylor expanded in c around 0 68.5%
associate-*r/68.5%
neg-mul-168.5%
Simplified68.5%
Final simplification64.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.9e+205) (not (<= d 1.66e+168))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.9e+205) || !(d <= 1.66e+168)) {
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 <= (-3.9d+205)) .or. (.not. (d <= 1.66d+168))) 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 <= -3.9e+205) || !(d <= 1.66e+168)) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.9e+205) or not (d <= 1.66e+168): tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.9e+205) || !(d <= 1.66e+168)) 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 <= -3.9e+205) || ~((d <= 1.66e+168))) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.9e+205], N[Not[LessEqual[d, 1.66e+168]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.9 \cdot 10^{+205} \lor \neg \left(d \leq 1.66 \cdot 10^{+168}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -3.8999999999999998e205 or 1.6600000000000001e168 < d Initial program 26.8%
Taylor expanded in c around 0 85.6%
associate-*r/85.6%
neg-mul-185.6%
Simplified85.6%
add-sqr-sqrt43.6%
sqrt-unprod41.7%
sqr-neg41.7%
sqrt-unprod14.7%
add-sqr-sqrt28.2%
*-un-lft-identity28.2%
Applied egg-rr28.2%
*-lft-identity28.2%
Simplified28.2%
if -3.8999999999999998e205 < d < 1.6600000000000001e168Initial program 68.7%
Taylor expanded in c around inf 48.2%
Final simplification44.0%
(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 60.0%
Taylor expanded in c around 0 43.5%
associate-*r/43.5%
neg-mul-143.5%
Simplified43.5%
add-sqr-sqrt20.5%
sqrt-unprod21.5%
sqr-neg21.5%
sqrt-unprod5.7%
add-sqr-sqrt9.6%
*-un-lft-identity9.6%
Applied egg-rr9.6%
*-lft-identity9.6%
Simplified9.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 2024160
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(! :herbie-platform default (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))))