
(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 c) (* a d))))
(if (<= (/ t_0 (+ (* c c) (* d d))) 1.4e+237)
(* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
(fma (/ 1.0 (/ (hypot c d) c)) (/ b (hypot c d)) (/ (- a) d)))))
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))) <= 1.4e+237) {
tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
} else {
tmp = fma((1.0 / (hypot(c, d) / c)), (b / hypot(c, d)), (-a / d));
}
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))) <= 1.4e+237) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d))); else tmp = fma(Float64(1.0 / Float64(hypot(c, d) / c)), Float64(b / hypot(c, d)), Float64(Float64(-a) / d)); end return 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], 1.4e+237], 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[(1.0 / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[((-a) / d), $MachinePrecision]), $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 1.4 \cdot 10^{+237}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.39999999999999992e237Initial program 77.3%
*-un-lft-identity77.3%
add-sqr-sqrt77.3%
times-frac77.3%
hypot-def77.3%
hypot-def96.2%
Applied egg-rr96.2%
if 1.39999999999999992e237 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 19.3%
div-sub14.1%
*-commutative14.1%
add-sqr-sqrt14.1%
times-frac17.8%
fma-neg17.8%
hypot-def17.8%
hypot-def49.5%
associate-/l*57.1%
add-sqr-sqrt57.1%
pow257.1%
hypot-def57.1%
Applied egg-rr57.1%
clear-num57.1%
inv-pow57.1%
Applied egg-rr57.1%
unpow-157.1%
Simplified57.1%
Taylor expanded in c around 0 80.2%
Final simplification91.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* b c) (* a d))))
(if (<= (/ t_0 (+ (* c c) (* d d))) 1.4e+237)
(* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
(fma (/ c (hypot c d)) (/ b (hypot c d)) (/ (- a) d)))))
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))) <= 1.4e+237) {
tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
} else {
tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (-a / d));
}
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))) <= 1.4e+237) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d))); else tmp = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(Float64(-a) / d)); end return 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], 1.4e+237], 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[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[((-a) / d), $MachinePrecision]), $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 1.4 \cdot 10^{+237}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.39999999999999992e237Initial program 77.3%
*-un-lft-identity77.3%
add-sqr-sqrt77.3%
times-frac77.3%
hypot-def77.3%
hypot-def96.2%
Applied egg-rr96.2%
if 1.39999999999999992e237 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 19.3%
div-sub14.1%
*-commutative14.1%
add-sqr-sqrt14.1%
times-frac17.8%
fma-neg17.8%
hypot-def17.8%
hypot-def49.5%
associate-/l*57.1%
add-sqr-sqrt57.1%
pow257.1%
hypot-def57.1%
Applied egg-rr57.1%
Taylor expanded in c around 0 80.2%
Final simplification91.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* b c) (* a d))))
(if (<= (/ t_0 (+ (* c c) (* d d))) 2e+254)
(* (/ 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) - (a * d);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 2e+254) {
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) - (a * d);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 2e+254) {
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) - (a * d) tmp = 0 if (t_0 / ((c * c) + (d * d))) <= 2e+254: 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(a * d)) tmp = 0.0 if (Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) <= 2e+254) 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) - (a * d); tmp = 0.0; if ((t_0 / ((c * c) + (d * d))) <= 2e+254) 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[(a * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e+254], 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 - a \cdot d\\
\mathbf{if}\;\frac{t_0}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+254}:\\
\;\;\;\;\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))) < 1.9999999999999999e254Initial program 77.8%
*-un-lft-identity77.8%
add-sqr-sqrt77.8%
times-frac77.8%
hypot-def77.8%
hypot-def96.2%
Applied egg-rr96.2%
if 1.9999999999999999e254 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 15.1%
Taylor expanded in c around 0 46.3%
+-commutative46.3%
mul-1-neg46.3%
unsub-neg46.3%
unpow246.3%
times-frac61.6%
Simplified61.6%
associate-*r/61.6%
sub-div62.9%
Applied egg-rr62.9%
Final simplification86.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))))
(if (<= d -4.2e+66)
(- (* (/ c d) (/ b d)) (/ a d))
(if (<= d -9.8e-79)
t_0
(if (<= d 2.7e-127)
(/ (- b (* d (/ a c))) c)
(if (<= d 1.9e+81) t_0 (/ (- (* b (/ c d)) a) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -4.2e+66) {
tmp = ((c / d) * (b / d)) - (a / d);
} else if (d <= -9.8e-79) {
tmp = t_0;
} else if (d <= 2.7e-127) {
tmp = (b - (d * (a / c))) / c;
} else if (d <= 1.9e+81) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d))
if (d <= (-4.2d+66)) then
tmp = ((c / d) * (b / d)) - (a / d)
else if (d <= (-9.8d-79)) then
tmp = t_0
else if (d <= 2.7d-127) then
tmp = (b - (d * (a / c))) / c
else if (d <= 1.9d+81) then
tmp = t_0
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 t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -4.2e+66) {
tmp = ((c / d) * (b / d)) - (a / d);
} else if (d <= -9.8e-79) {
tmp = t_0;
} else if (d <= 2.7e-127) {
tmp = (b - (d * (a / c))) / c;
} else if (d <= 1.9e+81) {
tmp = t_0;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -4.2e+66: tmp = ((c / d) * (b / d)) - (a / d) elif d <= -9.8e-79: tmp = t_0 elif d <= 2.7e-127: tmp = (b - (d * (a / c))) / c elif d <= 1.9e+81: tmp = t_0 else: tmp = ((b * (c / d)) - a) / d 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))) tmp = 0.0 if (d <= -4.2e+66) tmp = Float64(Float64(Float64(c / d) * Float64(b / d)) - Float64(a / d)); elseif (d <= -9.8e-79) tmp = t_0; elseif (d <= 2.7e-127) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); elseif (d <= 1.9e+81) tmp = t_0; 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) - (a * d)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -4.2e+66) tmp = ((c / d) * (b / d)) - (a / d); elseif (d <= -9.8e-79) tmp = t_0; elseif (d <= 2.7e-127) tmp = (b - (d * (a / c))) / c; elseif (d <= 1.9e+81) tmp = t_0; else tmp = ((b * (c / d)) - a) / d; 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]}, If[LessEqual[d, -4.2e+66], N[(N[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -9.8e-79], t$95$0, If[LessEqual[d, 2.7e-127], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.9e+81], 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 \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -4.2 \cdot 10^{+66}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\
\mathbf{elif}\;d \leq -9.8 \cdot 10^{-79}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 2.7 \cdot 10^{-127}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{elif}\;d \leq 1.9 \cdot 10^{+81}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if d < -4.20000000000000011e66Initial program 20.0%
Taylor expanded in c around 0 63.0%
+-commutative63.0%
mul-1-neg63.0%
unsub-neg63.0%
unpow263.0%
times-frac81.0%
Simplified81.0%
if -4.20000000000000011e66 < d < -9.8000000000000001e-79 or 2.7e-127 < d < 1.9e81Initial program 84.6%
if -9.8000000000000001e-79 < d < 2.7e-127Initial program 70.9%
Taylor expanded in c around inf 71.9%
+-commutative71.9%
mul-1-neg71.9%
unsub-neg71.9%
unpow271.9%
times-frac80.4%
Simplified80.4%
add-cbrt-cube59.8%
pow259.8%
Applied egg-rr59.8%
unpow259.8%
add-cbrt-cube80.4%
associate-*r/80.3%
sub-div81.7%
Applied egg-rr81.7%
if 1.9e81 < d Initial program 30.5%
Taylor expanded in c around 0 75.3%
+-commutative75.3%
mul-1-neg75.3%
unsub-neg75.3%
unpow275.3%
times-frac85.5%
Simplified85.5%
associate-*r/85.5%
sub-div85.5%
Applied egg-rr85.5%
Final simplification83.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b (/ c d)) a) d)) (t_1 (- (/ b c) (* (/ a c) (/ d c)))))
(if (<= c -1.15e+91)
t_1
(if (<= c -3.6e+39)
t_0
(if (<= c -7.2e-36)
(/ c (+ (/ d (/ b d)) (/ c (/ b c))))
(if (<= c 100000000.0) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * (c / d)) - a) / d;
double t_1 = (b / c) - ((a / c) * (d / c));
double tmp;
if (c <= -1.15e+91) {
tmp = t_1;
} else if (c <= -3.6e+39) {
tmp = t_0;
} else if (c <= -7.2e-36) {
tmp = c / ((d / (b / d)) + (c / (b / c)));
} else if (c <= 100000000.0) {
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) / d
t_1 = (b / c) - ((a / c) * (d / c))
if (c <= (-1.15d+91)) then
tmp = t_1
else if (c <= (-3.6d+39)) then
tmp = t_0
else if (c <= (-7.2d-36)) then
tmp = c / ((d / (b / d)) + (c / (b / c)))
else if (c <= 100000000.0d0) 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) / d;
double t_1 = (b / c) - ((a / c) * (d / c));
double tmp;
if (c <= -1.15e+91) {
tmp = t_1;
} else if (c <= -3.6e+39) {
tmp = t_0;
} else if (c <= -7.2e-36) {
tmp = c / ((d / (b / d)) + (c / (b / c)));
} else if (c <= 100000000.0) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * (c / d)) - a) / d t_1 = (b / c) - ((a / c) * (d / c)) tmp = 0 if c <= -1.15e+91: tmp = t_1 elif c <= -3.6e+39: tmp = t_0 elif c <= -7.2e-36: tmp = c / ((d / (b / d)) + (c / (b / c))) elif c <= 100000000.0: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * Float64(c / d)) - a) / d) t_1 = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))) tmp = 0.0 if (c <= -1.15e+91) tmp = t_1; elseif (c <= -3.6e+39) tmp = t_0; elseif (c <= -7.2e-36) tmp = Float64(c / Float64(Float64(d / Float64(b / d)) + Float64(c / Float64(b / c)))); elseif (c <= 100000000.0) 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) / d; t_1 = (b / c) - ((a / c) * (d / c)); tmp = 0.0; if (c <= -1.15e+91) tmp = t_1; elseif (c <= -3.6e+39) tmp = t_0; elseif (c <= -7.2e-36) tmp = c / ((d / (b / d)) + (c / (b / c))); elseif (c <= 100000000.0) 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 * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.15e+91], t$95$1, If[LessEqual[c, -3.6e+39], t$95$0, If[LessEqual[c, -7.2e-36], N[(c / N[(N[(d / N[(b / d), $MachinePrecision]), $MachinePrecision] + N[(c / N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 100000000.0], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot \frac{c}{d} - a}{d}\\
t_1 := \frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{if}\;c \leq -1.15 \cdot 10^{+91}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -3.6 \cdot 10^{+39}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq -7.2 \cdot 10^{-36}:\\
\;\;\;\;\frac{c}{\frac{d}{\frac{b}{d}} + \frac{c}{\frac{b}{c}}}\\
\mathbf{elif}\;c \leq 100000000:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if c < -1.14999999999999996e91 or 1e8 < c Initial program 46.7%
Taylor expanded in c around inf 70.1%
+-commutative70.1%
mul-1-neg70.1%
unsub-neg70.1%
unpow270.1%
times-frac79.0%
Simplified79.0%
if -1.14999999999999996e91 < c < -3.59999999999999984e39 or -7.20000000000000064e-36 < c < 1e8Initial program 67.0%
Taylor expanded in c around 0 76.8%
+-commutative76.8%
mul-1-neg76.8%
unsub-neg76.8%
unpow276.8%
times-frac81.9%
Simplified81.9%
associate-*r/81.9%
sub-div83.4%
Applied egg-rr83.4%
if -3.59999999999999984e39 < c < -7.20000000000000064e-36Initial program 67.6%
div-sub67.6%
*-commutative67.6%
add-sqr-sqrt67.6%
times-frac68.2%
fma-neg68.2%
hypot-def68.2%
hypot-def93.0%
associate-/l*93.4%
add-sqr-sqrt93.4%
pow293.4%
hypot-def93.4%
Applied egg-rr93.4%
Taylor expanded in b around inf 48.8%
associate-/l*49.2%
+-commutative49.2%
unpow249.2%
unpow249.2%
Simplified49.2%
Taylor expanded in c around 0 49.2%
+-commutative49.2%
unpow249.2%
associate-/l*74.2%
unpow274.2%
associate-/l*74.5%
Simplified74.5%
Final simplification81.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.6e+91) (not (<= c 300000000.0))) (- (/ b c) (* (/ a c) (/ d c))) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.6e+91) || !(c <= 300000000.0)) {
tmp = (b / c) - ((a / c) * (d / 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 <= (-2.6d+91)) .or. (.not. (c <= 300000000.0d0))) then
tmp = (b / c) - ((a / c) * (d / 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 <= -2.6e+91) || !(c <= 300000000.0)) {
tmp = (b / c) - ((a / c) * (d / c));
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.6e+91) or not (c <= 300000000.0): tmp = (b / c) - ((a / c) * (d / c)) else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.6e+91) || !(c <= 300000000.0)) tmp = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(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.6e+91) || ~((c <= 300000000.0))) tmp = (b / c) - ((a / c) * (d / c)); else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.6e+91], N[Not[LessEqual[c, 300000000.0]], $MachinePrecision]], N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $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.6 \cdot 10^{+91} \lor \neg \left(c \leq 300000000\right):\\
\;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -2.6e91 or 3e8 < c Initial program 46.7%
Taylor expanded in c around inf 70.1%
+-commutative70.1%
mul-1-neg70.1%
unsub-neg70.1%
unpow270.1%
times-frac79.0%
Simplified79.0%
if -2.6e91 < c < 3e8Initial program 67.1%
Taylor expanded in c around 0 71.3%
+-commutative71.3%
mul-1-neg71.3%
unsub-neg71.3%
unpow271.3%
times-frac78.3%
Simplified78.3%
associate-*r/78.3%
sub-div79.7%
Applied egg-rr79.7%
Final simplification79.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -60000000.0) (not (<= d 1.25e+68))) (/ (- a) d) (/ (- b (* d (/ a c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -60000000.0) || !(d <= 1.25e+68)) {
tmp = -a / d;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-60000000.0d0)) .or. (.not. (d <= 1.25d+68))) then
tmp = -a / d
else
tmp = (b - (d * (a / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -60000000.0) || !(d <= 1.25e+68)) {
tmp = -a / d;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -60000000.0) or not (d <= 1.25e+68): tmp = -a / d else: tmp = (b - (d * (a / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -60000000.0) || !(d <= 1.25e+68)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -60000000.0) || ~((d <= 1.25e+68))) tmp = -a / d; else tmp = (b - (d * (a / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -60000000.0], N[Not[LessEqual[d, 1.25e+68]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -60000000 \lor \neg \left(d \leq 1.25 \cdot 10^{+68}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if d < -6e7 or 1.2500000000000001e68 < d Initial program 37.2%
Taylor expanded in c around 0 69.3%
associate-*r/69.3%
neg-mul-169.3%
Simplified69.3%
if -6e7 < d < 1.2500000000000001e68Initial program 77.3%
Taylor expanded in c around inf 64.7%
+-commutative64.7%
mul-1-neg64.7%
unsub-neg64.7%
unpow264.7%
times-frac70.4%
Simplified70.4%
add-cbrt-cube50.1%
pow250.1%
Applied egg-rr50.1%
unpow250.1%
add-cbrt-cube70.4%
associate-*r/70.4%
sub-div71.2%
Applied egg-rr71.2%
Final simplification70.4%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.15e+91) (not (<= c 80000000.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 <= -1.15e+91) || !(c <= 80000000.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 <= (-1.15d+91)) .or. (.not. (c <= 80000000.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 <= -1.15e+91) || !(c <= 80000000.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 <= -1.15e+91) or not (c <= 80000000.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 <= -1.15e+91) || !(c <= 80000000.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 <= -1.15e+91) || ~((c <= 80000000.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, -1.15e+91], N[Not[LessEqual[c, 80000000.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 -1.15 \cdot 10^{+91} \lor \neg \left(c \leq 80000000\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 < -1.14999999999999996e91 or 8e7 < c Initial program 46.7%
Taylor expanded in c around inf 70.1%
+-commutative70.1%
mul-1-neg70.1%
unsub-neg70.1%
unpow270.1%
times-frac79.0%
Simplified79.0%
add-cbrt-cube59.7%
pow259.7%
Applied egg-rr59.7%
unpow259.7%
add-cbrt-cube79.0%
associate-*r/78.9%
sub-div78.9%
Applied egg-rr78.9%
if -1.14999999999999996e91 < c < 8e7Initial program 67.1%
Taylor expanded in c around 0 71.3%
+-commutative71.3%
mul-1-neg71.3%
unsub-neg71.3%
unpow271.3%
times-frac78.3%
Simplified78.3%
associate-*r/78.3%
sub-div79.7%
Applied egg-rr79.7%
Final simplification79.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -26000000.0) (not (<= d 1.05e+19))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -26000000.0) || !(d <= 1.05e+19)) {
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 <= (-26000000.0d0)) .or. (.not. (d <= 1.05d+19))) 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 <= -26000000.0) || !(d <= 1.05e+19)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -26000000.0) or not (d <= 1.05e+19): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -26000000.0) || !(d <= 1.05e+19)) 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 <= -26000000.0) || ~((d <= 1.05e+19))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -26000000.0], N[Not[LessEqual[d, 1.05e+19]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -26000000 \lor \neg \left(d \leq 1.05 \cdot 10^{+19}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -2.6e7 or 1.05e19 < d Initial program 38.9%
Taylor expanded in c around 0 67.4%
associate-*r/67.4%
neg-mul-167.4%
Simplified67.4%
if -2.6e7 < d < 1.05e19Initial program 79.1%
Taylor expanded in c around inf 56.6%
Final simplification61.9%
(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 59.4%
Taylor expanded in c around inf 38.4%
Final simplification38.4%
(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 2023238
(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))))