
(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 (if (<= (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) 6e+253) (* (/ 1.0 (hypot c d)) (/ (fma b c (* a (- d))) (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 tmp;
if ((((b * c) - (a * d)) / ((c * c) + (d * d))) <= 6e+253) {
tmp = (1.0 / hypot(c, d)) * (fma(b, c, (a * -d)) / hypot(c, d));
} else {
tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (a / -d));
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) <= 6e+253) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(b, c, Float64(a * Float64(-d))) / hypot(c, d))); else tmp = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a / Float64(-d))); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 6e+253], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(b * c + N[(a * (-d)), $MachinePrecision]), $MachinePrecision] / 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}
\mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \leq 6 \cdot 10^{+253}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(b, c, a \cdot \left(-d\right)\right)}{\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))) < 5.9999999999999996e253Initial program 79.4%
*-un-lft-identity79.4%
add-sqr-sqrt79.4%
times-frac79.4%
hypot-define79.4%
fma-neg79.4%
distribute-rgt-neg-in79.4%
hypot-define96.6%
Applied egg-rr96.6%
if 5.9999999999999996e253 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 11.0%
div-sub7.8%
*-commutative7.8%
add-sqr-sqrt7.8%
times-frac15.4%
fma-neg15.4%
hypot-define15.4%
hypot-define55.5%
associate-/l*64.2%
add-sqr-sqrt64.2%
pow264.2%
hypot-define64.2%
Applied egg-rr64.2%
Taylor expanded in d around inf 73.5%
Final simplification90.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma (/ c (hypot c d)) (/ b (hypot c d)) (/ a (- d)))))
(if (<= d -1.3e-60)
t_0
(if (<= d 1.7e-76)
(/ (- b (/ (* a d) c)) c)
(if (<= d 3.3e+69) (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma((c / hypot(c, d)), (b / hypot(c, d)), (a / -d));
double tmp;
if (d <= -1.3e-60) {
tmp = t_0;
} else if (d <= 1.7e-76) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 3.3e+69) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a / Float64(-d))) tmp = 0.0 if (d <= -1.3e-60) tmp = t_0; elseif (d <= 1.7e-76) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); elseif (d <= 3.3e+69) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; 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 / (-d)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.3e-60], t$95$0, If[LessEqual[d, 1.7e-76], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.3e+69], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\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}{-d}\right)\\
\mathbf{if}\;d \leq -1.3 \cdot 10^{-60}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.7 \cdot 10^{-76}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 3.3 \cdot 10^{+69}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.2999999999999999e-60 or 3.2999999999999999e69 < d Initial program 45.8%
div-sub45.8%
*-commutative45.8%
add-sqr-sqrt45.8%
times-frac49.5%
fma-neg49.5%
hypot-define49.5%
hypot-define64.2%
associate-/l*70.1%
add-sqr-sqrt70.1%
pow270.1%
hypot-define70.1%
Applied egg-rr70.1%
Taylor expanded in d around inf 89.2%
if -1.2999999999999999e-60 < d < 1.7e-76Initial program 67.9%
div-sub62.4%
*-commutative62.4%
add-sqr-sqrt62.4%
times-frac66.2%
fma-neg66.2%
hypot-define66.2%
hypot-define87.0%
associate-/l*88.1%
add-sqr-sqrt88.1%
pow288.1%
hypot-define88.1%
Applied egg-rr88.1%
Taylor expanded in c around inf 89.5%
mul-1-neg89.5%
*-commutative89.5%
associate-*r/84.4%
distribute-lft-neg-in84.4%
cancel-sign-sub-inv84.4%
Simplified84.4%
Taylor expanded in d around 0 89.5%
if 1.7e-76 < d < 3.2999999999999999e69Initial program 88.2%
Final simplification89.1%
(FPCore (a b c d)
:precision binary64
(if (<= c -2.6e+71)
(/ (- b (* d (/ a c))) c)
(if (<= c -3.9e-126)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
(if (<= c 3.8e+46)
(/ (- (* b (/ c d)) a) d)
(* (/ 1.0 (hypot c d)) (- b (* a (/ d c))))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.6e+71) {
tmp = (b - (d * (a / c))) / c;
} else if (c <= -3.9e-126) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (c <= 3.8e+46) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (1.0 / hypot(c, d)) * (b - (a * (d / c)));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.6e+71) {
tmp = (b - (d * (a / c))) / c;
} else if (c <= -3.9e-126) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (c <= 3.8e+46) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (1.0 / Math.hypot(c, d)) * (b - (a * (d / c)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.6e+71: tmp = (b - (d * (a / c))) / c elif c <= -3.9e-126: tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)) elif c <= 3.8e+46: tmp = ((b * (c / d)) - a) / d else: tmp = (1.0 / math.hypot(c, d)) * (b - (a * (d / c))) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.6e+71) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); elseif (c <= -3.9e-126) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 3.8e+46) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(b - Float64(a * Float64(d / c)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -2.6e+71) tmp = (b - (d * (a / c))) / c; elseif (c <= -3.9e-126) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); elseif (c <= 3.8e+46) tmp = ((b * (c / d)) - a) / d; else tmp = (1.0 / hypot(c, d)) * (b - (a * (d / c))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.6e+71], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -3.9e-126], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.8e+46], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.6 \cdot 10^{+71}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{elif}\;c \leq -3.9 \cdot 10^{-126}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 3.8 \cdot 10^{+46}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - a \cdot \frac{d}{c}\right)\\
\end{array}
\end{array}
if c < -2.59999999999999991e71Initial program 44.3%
div-sub44.3%
*-commutative44.3%
add-sqr-sqrt44.3%
times-frac49.5%
fma-neg49.5%
hypot-define49.5%
hypot-define85.4%
associate-/l*85.6%
add-sqr-sqrt85.6%
pow285.6%
hypot-define85.6%
Applied egg-rr85.6%
Taylor expanded in c around inf 85.2%
mul-1-neg85.2%
*-commutative85.2%
associate-*r/87.3%
distribute-lft-neg-in87.3%
cancel-sign-sub-inv87.3%
Simplified87.3%
if -2.59999999999999991e71 < c < -3.8999999999999998e-126Initial program 78.4%
if -3.8999999999999998e-126 < c < 3.7999999999999999e46Initial program 73.2%
Taylor expanded in c around 0 81.9%
+-commutative81.9%
mul-1-neg81.9%
unsub-neg81.9%
unpow281.9%
associate-/r*88.4%
div-sub91.4%
associate-/l*92.4%
fma-neg92.4%
Simplified92.4%
fma-undefine92.4%
unsub-neg92.4%
Applied egg-rr92.4%
if 3.7999999999999999e46 < c Initial program 48.5%
*-un-lft-identity48.5%
add-sqr-sqrt48.5%
times-frac48.5%
hypot-define48.5%
fma-neg48.5%
distribute-rgt-neg-in48.5%
hypot-define60.4%
Applied egg-rr60.4%
Taylor expanded in c around inf 76.2%
mul-1-neg76.2%
sub-neg76.2%
associate-/l*78.5%
Simplified78.5%
Final simplification86.2%
(FPCore (a b c d)
:precision binary64
(if (or (<= d -6e+85)
(and (not (<= d 8.2e-42))
(or (<= d 1000000000.0) (not (<= d 8e+99)))))
(/ a (- d))
(/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6e+85) || (!(d <= 8.2e-42) && ((d <= 1000000000.0) || !(d <= 8e+99)))) {
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 <= (-6d+85)) .or. (.not. (d <= 8.2d-42)) .and. (d <= 1000000000.0d0) .or. (.not. (d <= 8d+99))) 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 <= -6e+85) || (!(d <= 8.2e-42) && ((d <= 1000000000.0) || !(d <= 8e+99)))) {
tmp = a / -d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -6e+85) or (not (d <= 8.2e-42) and ((d <= 1000000000.0) or not (d <= 8e+99))): tmp = a / -d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -6e+85) || (!(d <= 8.2e-42) && ((d <= 1000000000.0) || !(d <= 8e+99)))) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -6e+85) || (~((d <= 8.2e-42)) && ((d <= 1000000000.0) || ~((d <= 8e+99))))) tmp = a / -d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6e+85], And[N[Not[LessEqual[d, 8.2e-42]], $MachinePrecision], Or[LessEqual[d, 1000000000.0], N[Not[LessEqual[d, 8e+99]], $MachinePrecision]]]], N[(a / (-d)), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6 \cdot 10^{+85} \lor \neg \left(d \leq 8.2 \cdot 10^{-42}\right) \land \left(d \leq 1000000000 \lor \neg \left(d \leq 8 \cdot 10^{+99}\right)\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -6.0000000000000001e85 or 8.2000000000000003e-42 < d < 1e9 or 7.9999999999999997e99 < d Initial program 43.8%
Taylor expanded in c around 0 74.8%
associate-*r/74.8%
neg-mul-174.8%
Simplified74.8%
if -6.0000000000000001e85 < d < 8.2000000000000003e-42 or 1e9 < d < 7.9999999999999997e99Initial program 71.7%
Taylor expanded in c around inf 75.2%
mul-1-neg75.2%
unsub-neg75.2%
associate-/l*75.4%
Simplified75.4%
Final simplification75.2%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.15e+65)
(/ (- b (* d (/ a c))) c)
(if (or (<= c -122000000000.0) (and (not (<= c -1e-102)) (<= c 3.45e+44)))
(/ (- (* b (/ c d)) a) d)
(/ (- b (* a (/ d c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.15e+65) {
tmp = (b - (d * (a / c))) / c;
} else if ((c <= -122000000000.0) || (!(c <= -1e-102) && (c <= 3.45e+44))) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-1.15d+65)) then
tmp = (b - (d * (a / c))) / c
else if ((c <= (-122000000000.0d0)) .or. (.not. (c <= (-1d-102))) .and. (c <= 3.45d+44)) then
tmp = ((b * (c / d)) - a) / d
else
tmp = (b - (a * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.15e+65) {
tmp = (b - (d * (a / c))) / c;
} else if ((c <= -122000000000.0) || (!(c <= -1e-102) && (c <= 3.45e+44))) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.15e+65: tmp = (b - (d * (a / c))) / c elif (c <= -122000000000.0) or (not (c <= -1e-102) and (c <= 3.45e+44)): tmp = ((b * (c / d)) - a) / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.15e+65) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); elseif ((c <= -122000000000.0) || (!(c <= -1e-102) && (c <= 3.45e+44))) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.15e+65) tmp = (b - (d * (a / c))) / c; elseif ((c <= -122000000000.0) || (~((c <= -1e-102)) && (c <= 3.45e+44))) tmp = ((b * (c / d)) - a) / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.15e+65], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[c, -122000000000.0], And[N[Not[LessEqual[c, -1e-102]], $MachinePrecision], LessEqual[c, 3.45e+44]]], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.15 \cdot 10^{+65}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{elif}\;c \leq -122000000000 \lor \neg \left(c \leq -1 \cdot 10^{-102}\right) \land c \leq 3.45 \cdot 10^{+44}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -1.15e65Initial program 44.3%
div-sub44.3%
*-commutative44.3%
add-sqr-sqrt44.3%
times-frac49.5%
fma-neg49.5%
hypot-define49.5%
hypot-define85.4%
associate-/l*85.6%
add-sqr-sqrt85.6%
pow285.6%
hypot-define85.6%
Applied egg-rr85.6%
Taylor expanded in c around inf 85.2%
mul-1-neg85.2%
*-commutative85.2%
associate-*r/87.3%
distribute-lft-neg-in87.3%
cancel-sign-sub-inv87.3%
Simplified87.3%
if -1.15e65 < c < -1.22e11 or -9.99999999999999933e-103 < c < 3.4499999999999999e44Initial program 73.1%
Taylor expanded in c around 0 78.1%
+-commutative78.1%
mul-1-neg78.1%
unsub-neg78.1%
unpow278.1%
associate-/r*83.7%
div-sub86.3%
associate-/l*88.7%
fma-neg88.7%
Simplified88.7%
fma-undefine88.7%
unsub-neg88.7%
Applied egg-rr88.7%
if -1.22e11 < c < -9.99999999999999933e-103 or 3.4499999999999999e44 < c Initial program 57.9%
Taylor expanded in c around inf 76.5%
mul-1-neg76.5%
unsub-neg76.5%
associate-/l*78.1%
Simplified78.1%
Final simplification85.4%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.75e+71)
(/ (- b (* d (/ a c))) c)
(if (<= c -8.4e-126)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
(if (<= c 4.5e+46) (/ (- (* b (/ c d)) a) d) (/ (- b (* a (/ d c))) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.75e+71) {
tmp = (b - (d * (a / c))) / c;
} else if (c <= -8.4e-126) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (c <= 4.5e+46) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-1.75d+71)) then
tmp = (b - (d * (a / c))) / c
else if (c <= (-8.4d-126)) then
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d))
else if (c <= 4.5d+46) then
tmp = ((b * (c / d)) - a) / d
else
tmp = (b - (a * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.75e+71) {
tmp = (b - (d * (a / c))) / c;
} else if (c <= -8.4e-126) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (c <= 4.5e+46) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.75e+71: tmp = (b - (d * (a / c))) / c elif c <= -8.4e-126: tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)) elif c <= 4.5e+46: tmp = ((b * (c / d)) - a) / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.75e+71) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); elseif (c <= -8.4e-126) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 4.5e+46) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.75e+71) tmp = (b - (d * (a / c))) / c; elseif (c <= -8.4e-126) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); elseif (c <= 4.5e+46) tmp = ((b * (c / d)) - a) / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.75e+71], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -8.4e-126], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.5e+46], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.75 \cdot 10^{+71}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{elif}\;c \leq -8.4 \cdot 10^{-126}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 4.5 \cdot 10^{+46}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -1.75e71Initial program 44.3%
div-sub44.3%
*-commutative44.3%
add-sqr-sqrt44.3%
times-frac49.5%
fma-neg49.5%
hypot-define49.5%
hypot-define85.4%
associate-/l*85.6%
add-sqr-sqrt85.6%
pow285.6%
hypot-define85.6%
Applied egg-rr85.6%
Taylor expanded in c around inf 85.2%
mul-1-neg85.2%
*-commutative85.2%
associate-*r/87.3%
distribute-lft-neg-in87.3%
cancel-sign-sub-inv87.3%
Simplified87.3%
if -1.75e71 < c < -8.3999999999999994e-126Initial program 78.4%
if -8.3999999999999994e-126 < c < 4.5000000000000001e46Initial program 73.2%
Taylor expanded in c around 0 81.9%
+-commutative81.9%
mul-1-neg81.9%
unsub-neg81.9%
unpow281.9%
associate-/r*88.4%
div-sub91.4%
associate-/l*92.4%
fma-neg92.4%
Simplified92.4%
fma-undefine92.4%
unsub-neg92.4%
Applied egg-rr92.4%
if 4.5000000000000001e46 < c Initial program 48.5%
Taylor expanded in c around inf 76.3%
mul-1-neg76.3%
unsub-neg76.3%
associate-/l*78.4%
Simplified78.4%
Final simplification86.2%
(FPCore (a b c d)
:precision binary64
(if (or (<= c -8.1e+40)
(not (or (<= c -3.2e-7) (and (not (<= c -1.2e-98)) (<= c 6.1e+45)))))
(/ b c)
(/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -8.1e+40) || !((c <= -3.2e-7) || (!(c <= -1.2e-98) && (c <= 6.1e+45)))) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-8.1d+40)) .or. (.not. (c <= (-3.2d-7)) .or. (.not. (c <= (-1.2d-98))) .and. (c <= 6.1d+45))) then
tmp = b / c
else
tmp = a / -d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -8.1e+40) || !((c <= -3.2e-7) || (!(c <= -1.2e-98) && (c <= 6.1e+45)))) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -8.1e+40) or not ((c <= -3.2e-7) or (not (c <= -1.2e-98) and (c <= 6.1e+45))): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -8.1e+40) || !((c <= -3.2e-7) || (!(c <= -1.2e-98) && (c <= 6.1e+45)))) tmp = Float64(b / c); else tmp = Float64(a / Float64(-d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -8.1e+40) || ~(((c <= -3.2e-7) || (~((c <= -1.2e-98)) && (c <= 6.1e+45))))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -8.1e+40], N[Not[Or[LessEqual[c, -3.2e-7], And[N[Not[LessEqual[c, -1.2e-98]], $MachinePrecision], LessEqual[c, 6.1e+45]]]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.1 \cdot 10^{+40} \lor \neg \left(c \leq -3.2 \cdot 10^{-7} \lor \neg \left(c \leq -1.2 \cdot 10^{-98}\right) \land c \leq 6.1 \cdot 10^{+45}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -8.0999999999999998e40 or -3.2000000000000001e-7 < c < -1.20000000000000002e-98 or 6.1e45 < c Initial program 51.4%
Taylor expanded in c around inf 72.8%
if -8.0999999999999998e40 < c < -3.2000000000000001e-7 or -1.20000000000000002e-98 < c < 6.1e45Initial program 73.8%
Taylor expanded in c around 0 67.3%
associate-*r/67.3%
neg-mul-167.3%
Simplified67.3%
Final simplification70.3%
(FPCore (a b c d) :precision binary64 (if (<= c -1.2e-98) (/ (- b (* d (/ a c))) c) (if (<= c 1.3e+44) (/ a (- d)) (/ (- b (* a (/ d c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.2e-98) {
tmp = (b - (d * (a / c))) / c;
} else if (c <= 1.3e+44) {
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 (c <= (-1.2d-98)) then
tmp = (b - (d * (a / c))) / c
else if (c <= 1.3d+44) 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 (c <= -1.2e-98) {
tmp = (b - (d * (a / c))) / c;
} else if (c <= 1.3e+44) {
tmp = a / -d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.2e-98: tmp = (b - (d * (a / c))) / c elif c <= 1.3e+44: tmp = a / -d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.2e-98) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); elseif (c <= 1.3e+44) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.2e-98) tmp = (b - (d * (a / c))) / c; elseif (c <= 1.3e+44) tmp = a / -d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.2e-98], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.3e+44], 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}\;c \leq -1.2 \cdot 10^{-98}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{elif}\;c \leq 1.3 \cdot 10^{+44}:\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -1.20000000000000002e-98Initial program 54.3%
div-sub54.3%
*-commutative54.3%
add-sqr-sqrt54.3%
times-frac59.9%
fma-neg59.9%
hypot-define59.9%
hypot-define84.0%
associate-/l*84.4%
add-sqr-sqrt84.4%
pow284.4%
hypot-define84.4%
Applied egg-rr84.4%
Taylor expanded in c around inf 75.9%
mul-1-neg75.9%
*-commutative75.9%
associate-*r/76.4%
distribute-lft-neg-in76.4%
cancel-sign-sub-inv76.4%
Simplified76.4%
if -1.20000000000000002e-98 < c < 1.3e44Initial program 74.4%
Taylor expanded in c around 0 68.1%
associate-*r/68.1%
neg-mul-168.1%
Simplified68.1%
if 1.3e44 < c Initial program 48.5%
Taylor expanded in c around inf 76.3%
mul-1-neg76.3%
unsub-neg76.3%
associate-/l*78.4%
Simplified78.4%
Final simplification73.4%
(FPCore (a b c d) :precision binary64 (if (<= c -2.2e-112) (/ (- b (/ (* a d) c)) c) (if (<= c 5.2e+44) (/ a (- d)) (/ (- b (* a (/ d c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.2e-112) {
tmp = (b - ((a * d) / c)) / c;
} else if (c <= 5.2e+44) {
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 (c <= (-2.2d-112)) then
tmp = (b - ((a * d) / c)) / c
else if (c <= 5.2d+44) 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 (c <= -2.2e-112) {
tmp = (b - ((a * d) / c)) / c;
} else if (c <= 5.2e+44) {
tmp = a / -d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.2e-112: tmp = (b - ((a * d) / c)) / c elif c <= 5.2e+44: tmp = a / -d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.2e-112) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); elseif (c <= 5.2e+44) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -2.2e-112) tmp = (b - ((a * d) / c)) / c; elseif (c <= 5.2e+44) tmp = a / -d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.2e-112], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 5.2e+44], 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}\;c \leq -2.2 \cdot 10^{-112}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{elif}\;c \leq 5.2 \cdot 10^{+44}:\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -2.20000000000000021e-112Initial program 54.8%
div-sub54.8%
*-commutative54.8%
add-sqr-sqrt54.8%
times-frac60.3%
fma-neg60.3%
hypot-define60.3%
hypot-define84.2%
associate-/l*84.6%
add-sqr-sqrt84.6%
pow284.6%
hypot-define84.6%
Applied egg-rr84.6%
Taylor expanded in c around inf 76.1%
mul-1-neg76.1%
*-commutative76.1%
associate-*r/75.7%
distribute-lft-neg-in75.7%
cancel-sign-sub-inv75.7%
Simplified75.7%
Taylor expanded in d around 0 76.1%
if -2.20000000000000021e-112 < c < 5.1999999999999998e44Initial program 74.2%
Taylor expanded in c around 0 68.7%
associate-*r/68.7%
neg-mul-168.7%
Simplified68.7%
if 5.1999999999999998e44 < c Initial program 48.5%
Taylor expanded in c around inf 76.3%
mul-1-neg76.3%
unsub-neg76.3%
associate-/l*78.4%
Simplified78.4%
Final simplification73.5%
(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 61.5%
Taylor expanded in c around inf 46.8%
Final simplification46.8%
(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 2024053
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))