
(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 8 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 (/ 1.0 (hypot c d))) (t_1 (- (* b c) (* a d))))
(if (<= (/ t_1 (+ (* c c) (* d d))) 2e+183)
(* t_0 (/ t_1 (hypot c d)))
(- (* t_0 (/ b (/ (hypot c d) c))) (/ a d)))))
double code(double a, double b, double c, double d) {
double t_0 = 1.0 / hypot(c, d);
double t_1 = (b * c) - (a * d);
double tmp;
if ((t_1 / ((c * c) + (d * d))) <= 2e+183) {
tmp = t_0 * (t_1 / hypot(c, d));
} else {
tmp = (t_0 * (b / (hypot(c, d) / c))) - (a / d);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = 1.0 / Math.hypot(c, d);
double t_1 = (b * c) - (a * d);
double tmp;
if ((t_1 / ((c * c) + (d * d))) <= 2e+183) {
tmp = t_0 * (t_1 / Math.hypot(c, d));
} else {
tmp = (t_0 * (b / (Math.hypot(c, d) / c))) - (a / d);
}
return tmp;
}
def code(a, b, c, d): t_0 = 1.0 / math.hypot(c, d) t_1 = (b * c) - (a * d) tmp = 0 if (t_1 / ((c * c) + (d * d))) <= 2e+183: tmp = t_0 * (t_1 / math.hypot(c, d)) else: tmp = (t_0 * (b / (math.hypot(c, d) / c))) - (a / d) return tmp
function code(a, b, c, d) t_0 = Float64(1.0 / hypot(c, d)) t_1 = Float64(Float64(b * c) - Float64(a * d)) tmp = 0.0 if (Float64(t_1 / Float64(Float64(c * c) + Float64(d * d))) <= 2e+183) tmp = Float64(t_0 * Float64(t_1 / hypot(c, d))); else tmp = Float64(Float64(t_0 * Float64(b / Float64(hypot(c, d) / c))) - Float64(a / d)); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = 1.0 / hypot(c, d); t_1 = (b * c) - (a * d); tmp = 0.0; if ((t_1 / ((c * c) + (d * d))) <= 2e+183) tmp = t_0 * (t_1 / hypot(c, d)); else tmp = (t_0 * (b / (hypot(c, d) / c))) - (a / d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$1 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e+183], N[(t$95$0 * N[(t$95$1 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * N[(b / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := b \cdot c - a \cdot d\\
\mathbf{if}\;\frac{t_1}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+183}:\\
\;\;\;\;t_0 \cdot \frac{t_1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}} - \frac{a}{d}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.99999999999999989e183Initial program 78.4%
*-un-lft-identity78.4%
add-sqr-sqrt78.4%
times-frac78.4%
hypot-def78.4%
hypot-def96.6%
Applied egg-rr96.6%
if 1.99999999999999989e183 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 15.5%
div-sub14.9%
*-un-lft-identity14.9%
add-sqr-sqrt14.9%
times-frac14.9%
fma-neg14.9%
hypot-def14.9%
hypot-def16.3%
associate-/l*23.7%
add-sqr-sqrt23.7%
pow223.7%
hypot-def23.7%
Applied egg-rr23.7%
fma-neg23.7%
associate-/l*62.7%
associate-/r/62.7%
*-commutative62.7%
Simplified62.7%
Taylor expanded in d around inf 74.3%
Final simplification91.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* b c) (* a d))))
(if (<= (/ t_0 (+ (* c c) (* d d))) INFINITY)
(* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
(/ (- b (* a (/ d c))) c))))
double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (a * d);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= ((double) INFINITY)) {
tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (a * d);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= Double.POSITIVE_INFINITY) {
tmp = (1.0 / Math.hypot(c, d)) * (t_0 / Math.hypot(c, d));
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b * c) - (a * d) tmp = 0 if (t_0 / ((c * c) + (d * d))) <= math.inf: tmp = (1.0 / math.hypot(c, d)) * (t_0 / math.hypot(c, d)) else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b * c) - Float64(a * d)) tmp = 0.0 if (Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) <= Inf) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d))); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b * c) - (a * d); tmp = 0.0; if ((t_0 / ((c * c) + (d * d))) <= Inf) tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d)); else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], 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[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot c - a \cdot d\\
\mathbf{if}\;\frac{t_0}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 76.3%
*-un-lft-identity76.3%
add-sqr-sqrt76.3%
times-frac76.3%
hypot-def76.3%
hypot-def94.6%
Applied egg-rr94.6%
if +inf.0 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 0.0%
Taylor expanded in c around inf 51.1%
+-commutative51.1%
mul-1-neg51.1%
unsub-neg51.1%
unpow251.1%
times-frac57.8%
Simplified57.8%
Taylor expanded in b around 0 51.1%
+-commutative51.1%
associate-*r/51.1%
*-commutative51.1%
neg-mul-151.1%
distribute-lft-neg-in51.1%
unpow251.1%
times-frac57.8%
distribute-neg-frac57.8%
cancel-sign-sub-inv57.8%
*-commutative57.8%
associate-*l/57.8%
div-sub57.8%
Simplified57.8%
Final simplification88.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* (- (* b c) (* a d)) (/ 1.0 (+ (* c c) (* d d)))))
(t_1 (/ (- (* c (/ b d)) a) d)))
(if (<= d -2.45e+64)
t_1
(if (<= d -4.8e-104)
t_0
(if (<= d 3.6e-148)
(/ (- b (* a (/ d c))) c)
(if (<= d 3.2e+71) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) * (1.0 / ((c * c) + (d * d)));
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -2.45e+64) {
tmp = t_1;
} else if (d <= -4.8e-104) {
tmp = t_0;
} else if (d <= 3.6e-148) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 3.2e+71) {
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) - (a * d)) * (1.0d0 / ((c * c) + (d * d)))
t_1 = ((c * (b / d)) - a) / d
if (d <= (-2.45d+64)) then
tmp = t_1
else if (d <= (-4.8d-104)) then
tmp = t_0
else if (d <= 3.6d-148) then
tmp = (b - (a * (d / c))) / c
else if (d <= 3.2d+71) 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) - (a * d)) * (1.0 / ((c * c) + (d * d)));
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -2.45e+64) {
tmp = t_1;
} else if (d <= -4.8e-104) {
tmp = t_0;
} else if (d <= 3.6e-148) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 3.2e+71) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (a * d)) * (1.0 / ((c * c) + (d * d))) t_1 = ((c * (b / d)) - a) / d tmp = 0 if d <= -2.45e+64: tmp = t_1 elif d <= -4.8e-104: tmp = t_0 elif d <= 3.6e-148: tmp = (b - (a * (d / c))) / c elif d <= 3.2e+71: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) * Float64(1.0 / Float64(Float64(c * c) + Float64(d * d)))) t_1 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -2.45e+64) tmp = t_1; elseif (d <= -4.8e-104) tmp = t_0; elseif (d <= 3.6e-148) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 3.2e+71) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * c) - (a * d)) * (1.0 / ((c * c) + (d * d))); t_1 = ((c * (b / d)) - a) / d; tmp = 0.0; if (d <= -2.45e+64) tmp = t_1; elseif (d <= -4.8e-104) tmp = t_0; elseif (d <= 3.6e-148) tmp = (b - (a * (d / c))) / c; elseif (d <= 3.2e+71) 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[(a * d), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.45e+64], t$95$1, If[LessEqual[d, -4.8e-104], t$95$0, If[LessEqual[d, 3.6e-148], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.2e+71], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(b \cdot c - a \cdot d\right) \cdot \frac{1}{c \cdot c + d \cdot d}\\
t_1 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -2.45 \cdot 10^{+64}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d \leq -4.8 \cdot 10^{-104}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 3.6 \cdot 10^{-148}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 3.2 \cdot 10^{+71}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if d < -2.4500000000000001e64 or 3.20000000000000023e71 < d Initial program 42.3%
Taylor expanded in c around 0 74.9%
+-commutative74.9%
mul-1-neg74.9%
unsub-neg74.9%
unpow274.9%
times-frac86.1%
Simplified86.1%
associate-*l/87.2%
sub-div87.2%
Applied egg-rr87.2%
if -2.4500000000000001e64 < d < -4.8000000000000001e-104 or 3.5999999999999998e-148 < d < 3.20000000000000023e71Initial program 86.5%
clear-num86.4%
associate-/r/86.7%
add-sqr-sqrt86.6%
pow286.6%
hypot-def86.6%
Applied egg-rr86.6%
unpow286.6%
hypot-udef86.6%
hypot-udef86.6%
add-sqr-sqrt86.7%
Applied egg-rr86.7%
if -4.8000000000000001e-104 < d < 3.5999999999999998e-148Initial program 68.6%
Taylor expanded in c around inf 83.3%
+-commutative83.3%
mul-1-neg83.3%
unsub-neg83.3%
unpow283.3%
times-frac86.5%
Simplified86.5%
Taylor expanded in b around 0 83.3%
+-commutative83.3%
associate-*r/83.3%
*-commutative83.3%
neg-mul-183.3%
distribute-lft-neg-in83.3%
unpow283.3%
times-frac86.5%
distribute-neg-frac86.5%
cancel-sign-sub-inv86.5%
*-commutative86.5%
associate-*l/87.7%
div-sub89.3%
Simplified89.3%
Final simplification87.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(t_1 (/ (- (* c (/ b d)) a) d)))
(if (<= d -2.6e+64)
t_1
(if (<= d -1.6e-105)
t_0
(if (<= d 3.3e-149)
(/ (- b (* a (/ d c))) c)
(if (<= d 6.8e+73) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -2.6e+64) {
tmp = t_1;
} else if (d <= -1.6e-105) {
tmp = t_0;
} else if (d <= 3.3e-149) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 6.8e+73) {
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) - (a * d)) / ((c * c) + (d * d))
t_1 = ((c * (b / d)) - a) / d
if (d <= (-2.6d+64)) then
tmp = t_1
else if (d <= (-1.6d-105)) then
tmp = t_0
else if (d <= 3.3d-149) then
tmp = (b - (a * (d / c))) / c
else if (d <= 6.8d+73) 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) - (a * d)) / ((c * c) + (d * d));
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -2.6e+64) {
tmp = t_1;
} else if (d <= -1.6e-105) {
tmp = t_0;
} else if (d <= 3.3e-149) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 6.8e+73) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)) t_1 = ((c * (b / d)) - a) / d tmp = 0 if d <= -2.6e+64: tmp = t_1 elif d <= -1.6e-105: tmp = t_0 elif d <= 3.3e-149: tmp = (b - (a * (d / c))) / c elif d <= 6.8e+73: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -2.6e+64) tmp = t_1; elseif (d <= -1.6e-105) tmp = t_0; elseif (d <= 3.3e-149) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 6.8e+73) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)); t_1 = ((c * (b / d)) - a) / d; tmp = 0.0; if (d <= -2.6e+64) tmp = t_1; elseif (d <= -1.6e-105) tmp = t_0; elseif (d <= 3.3e-149) tmp = (b - (a * (d / c))) / c; elseif (d <= 6.8e+73) 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[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.6e+64], t$95$1, If[LessEqual[d, -1.6e-105], t$95$0, If[LessEqual[d, 3.3e-149], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 6.8e+73], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -2.6 \cdot 10^{+64}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d \leq -1.6 \cdot 10^{-105}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 3.3 \cdot 10^{-149}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 6.8 \cdot 10^{+73}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if d < -2.59999999999999997e64 or 6.8000000000000003e73 < d Initial program 42.3%
Taylor expanded in c around 0 74.9%
+-commutative74.9%
mul-1-neg74.9%
unsub-neg74.9%
unpow274.9%
times-frac86.1%
Simplified86.1%
associate-*l/87.2%
sub-div87.2%
Applied egg-rr87.2%
if -2.59999999999999997e64 < d < -1.59999999999999991e-105 or 3.30000000000000017e-149 < d < 6.8000000000000003e73Initial program 86.5%
if -1.59999999999999991e-105 < d < 3.30000000000000017e-149Initial program 68.6%
Taylor expanded in c around inf 83.3%
+-commutative83.3%
mul-1-neg83.3%
unsub-neg83.3%
unpow283.3%
times-frac86.5%
Simplified86.5%
Taylor expanded in b around 0 83.3%
+-commutative83.3%
associate-*r/83.3%
*-commutative83.3%
neg-mul-183.3%
distribute-lft-neg-in83.3%
unpow283.3%
times-frac86.5%
distribute-neg-frac86.5%
cancel-sign-sub-inv86.5%
*-commutative86.5%
associate-*l/87.7%
div-sub89.3%
Simplified89.3%
Final simplification87.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -9.6e+57) (not (<= d 1.55e+25))) (- (/ a d)) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9.6e+57) || !(d <= 1.55e+25)) {
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 <= (-9.6d+57)) .or. (.not. (d <= 1.55d+25))) 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 <= -9.6e+57) || !(d <= 1.55e+25)) {
tmp = -(a / d);
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -9.6e+57) or not (d <= 1.55e+25): tmp = -(a / d) else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -9.6e+57) || !(d <= 1.55e+25)) 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 <= -9.6e+57) || ~((d <= 1.55e+25))) tmp = -(a / d); else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9.6e+57], N[Not[LessEqual[d, 1.55e+25]], $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 -9.6 \cdot 10^{+57} \lor \neg \left(d \leq 1.55 \cdot 10^{+25}\right):\\
\;\;\;\;-\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -9.60000000000000019e57 or 1.5499999999999999e25 < d Initial program 45.4%
Taylor expanded in c around 0 70.2%
associate-*r/70.2%
neg-mul-170.2%
Simplified70.2%
if -9.60000000000000019e57 < d < 1.5499999999999999e25Initial program 76.5%
Taylor expanded in c around inf 69.5%
+-commutative69.5%
mul-1-neg69.5%
unsub-neg69.5%
unpow269.5%
times-frac72.5%
Simplified72.5%
Taylor expanded in b around 0 69.5%
+-commutative69.5%
associate-*r/69.5%
*-commutative69.5%
neg-mul-169.5%
distribute-lft-neg-in69.5%
unpow269.5%
times-frac72.5%
distribute-neg-frac72.5%
cancel-sign-sub-inv72.5%
*-commutative72.5%
associate-*l/73.2%
div-sub74.7%
Simplified74.7%
Final simplification72.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.00032) (not (<= d 5.5e+21))) (/ (- (* c (/ b d)) a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.00032) || !(d <= 5.5e+21)) {
tmp = ((c * (b / 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 <= (-0.00032d0)) .or. (.not. (d <= 5.5d+21))) then
tmp = ((c * (b / 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 <= -0.00032) || !(d <= 5.5e+21)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.00032) or not (d <= 5.5e+21): tmp = ((c * (b / d)) - a) / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.00032) || !(d <= 5.5e+21)) tmp = Float64(Float64(Float64(c * Float64(b / 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 <= -0.00032) || ~((d <= 5.5e+21))) tmp = ((c * (b / d)) - a) / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.00032], N[Not[LessEqual[d, 5.5e+21]], $MachinePrecision]], N[(N[(N[(c * N[(b / 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 -0.00032 \lor \neg \left(d \leq 5.5 \cdot 10^{+21}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -3.20000000000000026e-4 or 5.5e21 < d Initial program 51.1%
Taylor expanded in c around 0 72.4%
+-commutative72.4%
mul-1-neg72.4%
unsub-neg72.4%
unpow272.4%
times-frac81.4%
Simplified81.4%
associate-*l/82.3%
sub-div82.3%
Applied egg-rr82.3%
if -3.20000000000000026e-4 < d < 5.5e21Initial program 75.4%
Taylor expanded in c around inf 73.3%
+-commutative73.3%
mul-1-neg73.3%
unsub-neg73.3%
unpow273.3%
times-frac76.0%
Simplified76.0%
Taylor expanded in b around 0 73.3%
+-commutative73.3%
associate-*r/73.3%
*-commutative73.3%
neg-mul-173.3%
distribute-lft-neg-in73.3%
unpow273.3%
times-frac76.0%
distribute-neg-frac76.0%
cancel-sign-sub-inv76.0%
*-commutative76.0%
associate-*l/76.8%
div-sub78.5%
Simplified78.5%
Final simplification80.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.00033) (not (<= d 1.12e-40))) (- (/ a d)) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.00033) || !(d <= 1.12e-40)) {
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 <= (-0.00033d0)) .or. (.not. (d <= 1.12d-40))) 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 <= -0.00033) || !(d <= 1.12e-40)) {
tmp = -(a / d);
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.00033) or not (d <= 1.12e-40): tmp = -(a / d) else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.00033) || !(d <= 1.12e-40)) tmp = Float64(-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 <= -0.00033) || ~((d <= 1.12e-40))) tmp = -(a / d); else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.00033], N[Not[LessEqual[d, 1.12e-40]], $MachinePrecision]], (-N[(a / d), $MachinePrecision]), N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.00033 \lor \neg \left(d \leq 1.12 \cdot 10^{-40}\right):\\
\;\;\;\;-\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -3.3e-4 or 1.1200000000000001e-40 < d Initial program 54.4%
Taylor expanded in c around 0 63.7%
associate-*r/63.7%
neg-mul-163.7%
Simplified63.7%
if -3.3e-4 < d < 1.1200000000000001e-40Initial program 74.2%
Taylor expanded in c around inf 68.2%
Final simplification65.7%
(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.2%
Taylor expanded in c around inf 40.9%
Final simplification40.9%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2023261
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:herbie-target
(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))))