
(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 9 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
(fma
(/ c (hypot c d))
(/ b (hypot c d))
(/ (- a) (/ (pow (hypot c d) 2.0) d)))))
(if (<= d -1.35e+154)
(/ (- a (* b (/ c d))) (hypot c d))
(if (<= d -6e-133)
t_0
(if (<= d 3.7e-178)
(+ (/ b c) (/ (/ -1.0 (/ c (* d a))) c))
(if (<= d 2.3e+149) t_0 (- (* (/ c d) (/ b d)) (/ a d))))))))
double code(double a, double b, double c, double d) {
double t_0 = fma((c / hypot(c, d)), (b / hypot(c, d)), (-a / (pow(hypot(c, d), 2.0) / d)));
double tmp;
if (d <= -1.35e+154) {
tmp = (a - (b * (c / d))) / hypot(c, d);
} else if (d <= -6e-133) {
tmp = t_0;
} else if (d <= 3.7e-178) {
tmp = (b / c) + ((-1.0 / (c / (d * a))) / c);
} else if (d <= 2.3e+149) {
tmp = t_0;
} else {
tmp = ((c / d) * (b / d)) - (a / d);
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(Float64(-a) / Float64((hypot(c, d) ^ 2.0) / d))) tmp = 0.0 if (d <= -1.35e+154) tmp = Float64(Float64(a - Float64(b * Float64(c / d))) / hypot(c, d)); elseif (d <= -6e-133) tmp = t_0; elseif (d <= 3.7e-178) tmp = Float64(Float64(b / c) + Float64(Float64(-1.0 / Float64(c / Float64(d * a))) / c)); elseif (d <= 2.3e+149) tmp = t_0; else tmp = Float64(Float64(Float64(c / d) * Float64(b / d)) - Float64(a / d)); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[((-a) / N[(N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.35e+154], N[(N[(a - N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -6e-133], t$95$0, If[LessEqual[d, 3.7e-178], N[(N[(b / c), $MachinePrecision] + N[(N[(-1.0 / N[(c / N[(d * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.3e+149], t$95$0, N[(N[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}\right)\\
\mathbf{if}\;d \leq -1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{a - b \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq -6 \cdot 10^{-133}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 3.7 \cdot 10^{-178}:\\
\;\;\;\;\frac{b}{c} + \frac{\frac{-1}{\frac{c}{d \cdot a}}}{c}\\
\mathbf{elif}\;d \leq 2.3 \cdot 10^{+149}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\
\end{array}
\end{array}
if d < -1.35000000000000003e154Initial program 39.3%
*-un-lft-identity39.3%
add-sqr-sqrt39.3%
times-frac39.3%
hypot-def39.3%
hypot-def63.5%
Applied egg-rr63.5%
associate-*l/63.5%
*-un-lft-identity63.5%
*-commutative63.5%
*-commutative63.5%
Applied egg-rr63.5%
Taylor expanded in d around -inf 88.3%
mul-1-neg88.3%
associate-*r/88.3%
sub-neg88.3%
Simplified88.3%
if -1.35000000000000003e154 < d < -6.00000000000000038e-133 or 3.70000000000000004e-178 < d < 2.2999999999999998e149Initial program 77.4%
div-sub76.6%
*-commutative76.6%
add-sqr-sqrt76.6%
times-frac79.9%
fma-neg79.9%
hypot-def79.9%
hypot-def91.3%
associate-/l*95.2%
add-sqr-sqrt95.2%
pow295.2%
hypot-def95.2%
Applied egg-rr95.2%
if -6.00000000000000038e-133 < d < 3.70000000000000004e-178Initial program 64.9%
Taylor expanded in c around inf 83.9%
+-commutative83.9%
mul-1-neg83.9%
unsub-neg83.9%
associate-/l*80.9%
unpow280.9%
associate-/l*92.2%
Simplified92.2%
clear-num92.3%
inv-pow92.3%
associate-/r/92.3%
Applied egg-rr92.3%
unpow-192.3%
associate-/l*93.3%
Simplified93.3%
inv-pow93.3%
associate-/r/94.8%
unpow-prod-down94.8%
inv-pow94.8%
Applied egg-rr94.8%
associate-*r/94.8%
*-rgt-identity94.8%
unpow-194.8%
associate-/l/95.4%
*-commutative95.4%
Simplified95.4%
if 2.2999999999999998e149 < d Initial program 28.5%
div-sub28.5%
*-commutative28.5%
add-sqr-sqrt28.5%
times-frac28.6%
fma-neg28.6%
hypot-def28.6%
hypot-def34.3%
associate-/l*38.6%
add-sqr-sqrt38.6%
pow238.6%
hypot-def38.6%
Applied egg-rr38.6%
Taylor expanded in c around 0 82.6%
+-commutative82.6%
mul-1-neg82.6%
unsub-neg82.6%
*-commutative82.6%
unpow282.6%
times-frac88.5%
Simplified88.5%
Final simplification93.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* b c) (* d a))))
(if (<= (/ t_0 (+ (* c c) (* d d))) 2e+307)
(/ (/ t_0 (hypot c d)) (hypot c d))
(- (/ b c) (* (/ a c) (/ d c))))))
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+307) {
tmp = (t_0 / hypot(c, d)) / hypot(c, d);
} else {
tmp = (b / c) - ((a / c) * (d / c));
}
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+307) {
tmp = (t_0 / Math.hypot(c, d)) / Math.hypot(c, d);
} else {
tmp = (b / c) - ((a / c) * (d / c));
}
return tmp;
}
def code(a, b, c, d): t_0 = (b * c) - (d * a) tmp = 0 if (t_0 / ((c * c) + (d * d))) <= 2e+307: tmp = (t_0 / math.hypot(c, d)) / math.hypot(c, d) else: tmp = (b / c) - ((a / c) * (d / c)) 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+307) tmp = Float64(Float64(t_0 / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))); 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+307) tmp = (t_0 / hypot(c, d)) / hypot(c, d); else tmp = (b / c) - ((a / c) * (d / c)); 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+307], N[(N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $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^{+307}:\\
\;\;\;\;\frac{\frac{t_0}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.99999999999999997e307Initial program 77.7%
*-un-lft-identity77.7%
add-sqr-sqrt77.7%
times-frac77.7%
hypot-def77.7%
hypot-def95.9%
Applied egg-rr95.9%
associate-*l/96.1%
*-un-lft-identity96.1%
*-commutative96.1%
*-commutative96.1%
Applied egg-rr96.1%
if 1.99999999999999997e307 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 6.1%
div-sub4.1%
*-commutative4.1%
add-sqr-sqrt4.1%
times-frac9.2%
fma-neg9.2%
hypot-def9.2%
hypot-def42.4%
associate-/l*48.0%
add-sqr-sqrt48.0%
pow248.0%
hypot-def48.0%
Applied egg-rr48.0%
Taylor expanded in c around inf 41.5%
fma-def41.5%
unpow241.5%
times-frac57.1%
fma-def57.1%
neg-mul-157.1%
+-commutative57.1%
sub-neg57.1%
Simplified57.1%
Final simplification88.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* d a)) (+ (* c c) (* d d)))))
(if (<= c -4.2e+63)
(/ (- (/ a (/ c d)) b) (hypot c d))
(if (<= c -9.5e-64)
t_0
(if (<= c 8.2e-113)
(* (- a (* b (/ c d))) (/ -1.0 d))
(if (<= c 1.75e+46) t_0 (- (/ b c) (* (/ a c) (/ d c)))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (d * a)) / ((c * c) + (d * d));
double tmp;
if (c <= -4.2e+63) {
tmp = ((a / (c / d)) - b) / hypot(c, d);
} else if (c <= -9.5e-64) {
tmp = t_0;
} else if (c <= 8.2e-113) {
tmp = (a - (b * (c / d))) * (-1.0 / d);
} else if (c <= 1.75e+46) {
tmp = t_0;
} else {
tmp = (b / c) - ((a / c) * (d / c));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (d * a)) / ((c * c) + (d * d));
double tmp;
if (c <= -4.2e+63) {
tmp = ((a / (c / d)) - b) / Math.hypot(c, d);
} else if (c <= -9.5e-64) {
tmp = t_0;
} else if (c <= 8.2e-113) {
tmp = (a - (b * (c / d))) * (-1.0 / d);
} else if (c <= 1.75e+46) {
tmp = t_0;
} else {
tmp = (b / c) - ((a / c) * (d / c));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (d * a)) / ((c * c) + (d * d)) tmp = 0 if c <= -4.2e+63: tmp = ((a / (c / d)) - b) / math.hypot(c, d) elif c <= -9.5e-64: tmp = t_0 elif c <= 8.2e-113: tmp = (a - (b * (c / d))) * (-1.0 / d) elif c <= 1.75e+46: tmp = t_0 else: tmp = (b / c) - ((a / c) * (d / c)) 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))) tmp = 0.0 if (c <= -4.2e+63) tmp = Float64(Float64(Float64(a / Float64(c / d)) - b) / hypot(c, d)); elseif (c <= -9.5e-64) tmp = t_0; elseif (c <= 8.2e-113) tmp = Float64(Float64(a - Float64(b * Float64(c / d))) * Float64(-1.0 / d)); elseif (c <= 1.75e+46) tmp = t_0; else tmp = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * c) - (d * a)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -4.2e+63) tmp = ((a / (c / d)) - b) / hypot(c, d); elseif (c <= -9.5e-64) tmp = t_0; elseif (c <= 8.2e-113) tmp = (a - (b * (c / d))) * (-1.0 / d); elseif (c <= 1.75e+46) tmp = t_0; else tmp = (b / c) - ((a / c) * (d / c)); 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]}, If[LessEqual[c, -4.2e+63], N[(N[(N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -9.5e-64], t$95$0, If[LessEqual[c, 8.2e-113], N[(N[(a - N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.75e+46], t$95$0, N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -4.2 \cdot 10^{+63}:\\
\;\;\;\;\frac{\frac{a}{\frac{c}{d}} - b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -9.5 \cdot 10^{-64}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 8.2 \cdot 10^{-113}:\\
\;\;\;\;\left(a - b \cdot \frac{c}{d}\right) \cdot \frac{-1}{d}\\
\mathbf{elif}\;c \leq 1.75 \cdot 10^{+46}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\end{array}
\end{array}
if c < -4.2000000000000004e63Initial program 34.5%
*-un-lft-identity34.5%
add-sqr-sqrt34.5%
times-frac34.5%
hypot-def34.5%
hypot-def63.4%
Applied egg-rr63.4%
associate-*l/63.6%
*-un-lft-identity63.6%
*-commutative63.6%
*-commutative63.6%
Applied egg-rr63.6%
Taylor expanded in c around -inf 80.9%
+-commutative80.9%
neg-mul-180.9%
unsub-neg80.9%
associate-/l*85.9%
Simplified85.9%
if -4.2000000000000004e63 < c < -9.50000000000000043e-64 or 8.1999999999999999e-113 < c < 1.74999999999999992e46Initial program 84.2%
if -9.50000000000000043e-64 < c < 8.1999999999999999e-113Initial program 71.7%
*-un-lft-identity71.7%
add-sqr-sqrt71.7%
times-frac71.8%
hypot-def71.8%
hypot-def83.5%
Applied egg-rr83.5%
Taylor expanded in d around -inf 55.2%
mul-1-neg55.2%
unsub-neg55.2%
associate-/l*56.2%
Simplified56.2%
Taylor expanded in d around -inf 90.1%
Taylor expanded in b around 0 90.1%
associate-*r/90.2%
Simplified90.2%
if 1.74999999999999992e46 < c Initial program 43.7%
div-sub43.7%
*-commutative43.7%
add-sqr-sqrt43.7%
times-frac48.1%
fma-neg48.1%
hypot-def48.1%
hypot-def77.7%
associate-/l*74.8%
add-sqr-sqrt74.8%
pow274.8%
hypot-def74.8%
Applied egg-rr74.8%
Taylor expanded in c around inf 74.3%
fma-def74.3%
unpow274.3%
times-frac86.7%
fma-def86.7%
neg-mul-186.7%
+-commutative86.7%
sub-neg86.7%
Simplified86.7%
Final simplification87.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* d a)) (+ (* c c) (* d d)))))
(if (<= c -9.6e+62)
(+ (/ b c) (/ -1.0 (/ (/ c d) (/ a c))))
(if (<= c -7e-64)
t_0
(if (<= c 1.65e-106)
(* (- a (* b (/ c d))) (/ -1.0 d))
(if (<= c 1.75e+46) t_0 (- (/ b c) (* (/ a c) (/ d c)))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (d * a)) / ((c * c) + (d * d));
double tmp;
if (c <= -9.6e+62) {
tmp = (b / c) + (-1.0 / ((c / d) / (a / c)));
} else if (c <= -7e-64) {
tmp = t_0;
} else if (c <= 1.65e-106) {
tmp = (a - (b * (c / d))) * (-1.0 / d);
} else if (c <= 1.75e+46) {
tmp = t_0;
} else {
tmp = (b / c) - ((a / c) * (d / c));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = ((b * c) - (d * a)) / ((c * c) + (d * d))
if (c <= (-9.6d+62)) then
tmp = (b / c) + ((-1.0d0) / ((c / d) / (a / c)))
else if (c <= (-7d-64)) then
tmp = t_0
else if (c <= 1.65d-106) then
tmp = (a - (b * (c / d))) * ((-1.0d0) / d)
else if (c <= 1.75d+46) then
tmp = t_0
else
tmp = (b / c) - ((a / c) * (d / c))
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 tmp;
if (c <= -9.6e+62) {
tmp = (b / c) + (-1.0 / ((c / d) / (a / c)));
} else if (c <= -7e-64) {
tmp = t_0;
} else if (c <= 1.65e-106) {
tmp = (a - (b * (c / d))) * (-1.0 / d);
} else if (c <= 1.75e+46) {
tmp = t_0;
} else {
tmp = (b / c) - ((a / c) * (d / c));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (d * a)) / ((c * c) + (d * d)) tmp = 0 if c <= -9.6e+62: tmp = (b / c) + (-1.0 / ((c / d) / (a / c))) elif c <= -7e-64: tmp = t_0 elif c <= 1.65e-106: tmp = (a - (b * (c / d))) * (-1.0 / d) elif c <= 1.75e+46: tmp = t_0 else: tmp = (b / c) - ((a / c) * (d / c)) 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))) tmp = 0.0 if (c <= -9.6e+62) tmp = Float64(Float64(b / c) + Float64(-1.0 / Float64(Float64(c / d) / Float64(a / c)))); elseif (c <= -7e-64) tmp = t_0; elseif (c <= 1.65e-106) tmp = Float64(Float64(a - Float64(b * Float64(c / d))) * Float64(-1.0 / d)); elseif (c <= 1.75e+46) tmp = t_0; else tmp = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * c) - (d * a)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -9.6e+62) tmp = (b / c) + (-1.0 / ((c / d) / (a / c))); elseif (c <= -7e-64) tmp = t_0; elseif (c <= 1.65e-106) tmp = (a - (b * (c / d))) * (-1.0 / d); elseif (c <= 1.75e+46) tmp = t_0; else tmp = (b / c) - ((a / c) * (d / c)); 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]}, If[LessEqual[c, -9.6e+62], N[(N[(b / c), $MachinePrecision] + N[(-1.0 / N[(N[(c / d), $MachinePrecision] / N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -7e-64], t$95$0, If[LessEqual[c, 1.65e-106], N[(N[(a - N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.75e+46], t$95$0, N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -9.6 \cdot 10^{+62}:\\
\;\;\;\;\frac{b}{c} + \frac{-1}{\frac{\frac{c}{d}}{\frac{a}{c}}}\\
\mathbf{elif}\;c \leq -7 \cdot 10^{-64}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.65 \cdot 10^{-106}:\\
\;\;\;\;\left(a - b \cdot \frac{c}{d}\right) \cdot \frac{-1}{d}\\
\mathbf{elif}\;c \leq 1.75 \cdot 10^{+46}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\end{array}
\end{array}
if c < -9.6e62Initial program 34.5%
Taylor expanded in c around inf 76.0%
+-commutative76.0%
mul-1-neg76.0%
unsub-neg76.0%
associate-/l*76.3%
unpow276.3%
associate-/l*81.1%
Simplified81.1%
clear-num81.1%
inv-pow81.1%
associate-/r/81.0%
Applied egg-rr81.0%
unpow-181.0%
associate-/l*85.6%
Simplified85.6%
if -9.6e62 < c < -7.0000000000000006e-64 or 1.65000000000000008e-106 < c < 1.74999999999999992e46Initial program 84.2%
if -7.0000000000000006e-64 < c < 1.65000000000000008e-106Initial program 71.7%
*-un-lft-identity71.7%
add-sqr-sqrt71.7%
times-frac71.8%
hypot-def71.8%
hypot-def83.5%
Applied egg-rr83.5%
Taylor expanded in d around -inf 55.2%
mul-1-neg55.2%
unsub-neg55.2%
associate-/l*56.2%
Simplified56.2%
Taylor expanded in d around -inf 90.1%
Taylor expanded in b around 0 90.1%
associate-*r/90.2%
Simplified90.2%
if 1.74999999999999992e46 < c Initial program 43.7%
div-sub43.7%
*-commutative43.7%
add-sqr-sqrt43.7%
times-frac48.1%
fma-neg48.1%
hypot-def48.1%
hypot-def77.7%
associate-/l*74.8%
add-sqr-sqrt74.8%
pow274.8%
hypot-def74.8%
Applied egg-rr74.8%
Taylor expanded in c around inf 74.3%
fma-def74.3%
unpow274.3%
times-frac86.7%
fma-def86.7%
neg-mul-186.7%
+-commutative86.7%
sub-neg86.7%
Simplified86.7%
Final simplification87.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.65e-18) (not (<= c 1.2e+69))) (/ b c) (* (- a (* b (/ c d))) (/ -1.0 d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.65e-18) || !(c <= 1.2e+69)) {
tmp = b / c;
} else {
tmp = (a - (b * (c / d))) * (-1.0 / 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.65d-18)) .or. (.not. (c <= 1.2d+69))) then
tmp = b / c
else
tmp = (a - (b * (c / d))) * ((-1.0d0) / d)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.65e-18) || !(c <= 1.2e+69)) {
tmp = b / c;
} else {
tmp = (a - (b * (c / d))) * (-1.0 / d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.65e-18) or not (c <= 1.2e+69): tmp = b / c else: tmp = (a - (b * (c / d))) * (-1.0 / d) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.65e-18) || !(c <= 1.2e+69)) tmp = Float64(b / c); else tmp = Float64(Float64(a - Float64(b * Float64(c / d))) * Float64(-1.0 / d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.65e-18) || ~((c <= 1.2e+69))) tmp = b / c; else tmp = (a - (b * (c / d))) * (-1.0 / d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.65e-18], N[Not[LessEqual[c, 1.2e+69]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(N[(a - N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / d), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.65 \cdot 10^{-18} \lor \neg \left(c \leq 1.2 \cdot 10^{+69}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\left(a - b \cdot \frac{c}{d}\right) \cdot \frac{-1}{d}\\
\end{array}
\end{array}
if c < -1.6500000000000001e-18 or 1.2000000000000001e69 < c Initial program 49.1%
Taylor expanded in c around inf 70.9%
if -1.6500000000000001e-18 < c < 1.2000000000000001e69Initial program 74.0%
*-un-lft-identity74.0%
add-sqr-sqrt74.0%
times-frac74.0%
hypot-def74.1%
hypot-def84.9%
Applied egg-rr84.9%
Taylor expanded in d around -inf 49.1%
mul-1-neg49.1%
unsub-neg49.1%
associate-/l*49.8%
Simplified49.8%
Taylor expanded in d around -inf 81.8%
Taylor expanded in b around 0 81.8%
associate-*r/81.8%
Simplified81.8%
Final simplification77.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4e-20) (not (<= c 1.32e+17))) (- (/ b c) (* (/ a c) (/ d c))) (* (- a (* b (/ c d))) (/ -1.0 d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4e-20) || !(c <= 1.32e+17)) {
tmp = (b / c) - ((a / c) * (d / c));
} else {
tmp = (a - (b * (c / d))) * (-1.0 / 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 <= (-4d-20)) .or. (.not. (c <= 1.32d+17))) then
tmp = (b / c) - ((a / c) * (d / c))
else
tmp = (a - (b * (c / d))) * ((-1.0d0) / d)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4e-20) || !(c <= 1.32e+17)) {
tmp = (b / c) - ((a / c) * (d / c));
} else {
tmp = (a - (b * (c / d))) * (-1.0 / d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4e-20) or not (c <= 1.32e+17): tmp = (b / c) - ((a / c) * (d / c)) else: tmp = (a - (b * (c / d))) * (-1.0 / d) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -4e-20) || !(c <= 1.32e+17)) tmp = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))); else tmp = Float64(Float64(a - Float64(b * Float64(c / d))) * Float64(-1.0 / d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -4e-20) || ~((c <= 1.32e+17))) tmp = (b / c) - ((a / c) * (d / c)); else tmp = (a - (b * (c / d))) * (-1.0 / d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4e-20], N[Not[LessEqual[c, 1.32e+17]], $MachinePrecision]], N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a - N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / d), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4 \cdot 10^{-20} \lor \neg \left(c \leq 1.32 \cdot 10^{+17}\right):\\
\;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{else}:\\
\;\;\;\;\left(a - b \cdot \frac{c}{d}\right) \cdot \frac{-1}{d}\\
\end{array}
\end{array}
if c < -3.99999999999999978e-20 or 1.32e17 < c Initial program 50.0%
div-sub50.1%
*-commutative50.1%
add-sqr-sqrt50.1%
times-frac54.0%
fma-neg54.0%
hypot-def54.0%
hypot-def81.9%
associate-/l*80.7%
add-sqr-sqrt80.7%
pow280.7%
hypot-def80.7%
Applied egg-rr80.7%
Taylor expanded in c around inf 74.3%
fma-def74.3%
unpow274.3%
times-frac83.1%
fma-def83.1%
neg-mul-183.1%
+-commutative83.1%
sub-neg83.1%
Simplified83.1%
if -3.99999999999999978e-20 < c < 1.32e17Initial program 74.3%
*-un-lft-identity74.3%
add-sqr-sqrt74.3%
times-frac74.4%
hypot-def74.4%
hypot-def85.0%
Applied egg-rr85.0%
Taylor expanded in d around -inf 50.4%
mul-1-neg50.4%
unsub-neg50.4%
associate-/l*51.2%
Simplified51.2%
Taylor expanded in d around -inf 83.1%
Taylor expanded in b around 0 83.1%
associate-*r/83.1%
Simplified83.1%
Final simplification83.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.1e+15) (not (<= d 8e-19))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.1e+15) || !(d <= 8e-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 <= (-2.1d+15)) .or. (.not. (d <= 8d-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 <= -2.1e+15) || !(d <= 8e-19)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.1e+15) or not (d <= 8e-19): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.1e+15) || !(d <= 8e-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 <= -2.1e+15) || ~((d <= 8e-19))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.1e+15], N[Not[LessEqual[d, 8e-19]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.1 \cdot 10^{+15} \lor \neg \left(d \leq 8 \cdot 10^{-19}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -2.1e15 or 7.9999999999999998e-19 < d Initial program 59.8%
Taylor expanded in c around 0 67.2%
associate-*r/67.2%
neg-mul-167.2%
Simplified67.2%
if -2.1e15 < d < 7.9999999999999998e-19Initial program 67.0%
Taylor expanded in c around inf 66.8%
Final simplification67.0%
(FPCore (a b c d) :precision binary64 (if (<= d -9.5e+158) (/ a d) (if (<= d 9e+89) (/ b c) (/ a d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -9.5e+158) {
tmp = a / d;
} else if (d <= 9e+89) {
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 (d <= (-9.5d+158)) then
tmp = a / d
else if (d <= 9d+89) 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 (d <= -9.5e+158) {
tmp = a / d;
} else if (d <= 9e+89) {
tmp = b / c;
} else {
tmp = a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -9.5e+158: tmp = a / d elif d <= 9e+89: tmp = b / c else: tmp = a / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -9.5e+158) tmp = Float64(a / d); elseif (d <= 9e+89) tmp = Float64(b / c); else tmp = Float64(a / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -9.5e+158) tmp = a / d; elseif (d <= 9e+89) tmp = b / c; else tmp = a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -9.5e+158], N[(a / d), $MachinePrecision], If[LessEqual[d, 9e+89], N[(b / c), $MachinePrecision], N[(a / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.5 \cdot 10^{+158}:\\
\;\;\;\;\frac{a}{d}\\
\mathbf{elif}\;d \leq 9 \cdot 10^{+89}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{d}\\
\end{array}
\end{array}
if d < -9.49999999999999913e158 or 9e89 < d Initial program 43.3%
*-un-lft-identity43.3%
add-sqr-sqrt43.3%
times-frac43.3%
hypot-def43.3%
hypot-def67.0%
Applied egg-rr67.0%
Taylor expanded in d around -inf 52.3%
mul-1-neg52.3%
unsub-neg52.3%
associate-/l*52.3%
Simplified52.3%
Taylor expanded in c around 0 33.1%
if -9.49999999999999913e158 < d < 9e89Initial program 71.7%
Taylor expanded in c around inf 53.2%
Final simplification47.2%
(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 63.1%
*-un-lft-identity63.1%
add-sqr-sqrt63.1%
times-frac63.1%
hypot-def63.2%
hypot-def78.5%
Applied egg-rr78.5%
Taylor expanded in d around -inf 32.5%
mul-1-neg32.5%
unsub-neg32.5%
associate-/l*32.9%
Simplified32.9%
Taylor expanded in c around 0 12.2%
Final simplification12.2%
(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 2023271
(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))))