
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d) :precision binary64 (if (<= (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) 2e+300) (/ (/ (- (fma a d (* b (- c)))) (hypot d c)) (hypot d c)) (- (/ b c) (/ (* d (/ a c)) c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((b * c) - (a * d)) / ((c * c) + (d * d))) <= 2e+300) {
tmp = (-fma(a, d, (b * -c)) / hypot(d, c)) / hypot(d, c);
} else {
tmp = (b / c) - ((d * (a / c)) / c);
}
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))) <= 2e+300) tmp = Float64(Float64(Float64(-fma(a, d, Float64(b * Float64(-c)))) / hypot(d, c)) / hypot(d, c)); else tmp = Float64(Float64(b / c) - Float64(Float64(d * Float64(a / c)) / c)); 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], 2e+300], N[(N[((-N[(a * d + N[(b * (-c)), $MachinePrecision]), $MachinePrecision]) / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(b / c), $MachinePrecision] - N[(N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+300}:\\
\;\;\;\;\frac{\frac{-\mathsf{fma}\left(a, d, b \cdot \left(-c\right)\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c} - \frac{d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 2.0000000000000001e300Initial program 75.5%
frac-2neg75.5%
div-inv75.5%
Applied egg-rr75.5%
*-commutative75.5%
neg-mul-175.5%
associate-/r*75.5%
metadata-eval75.5%
Simplified75.5%
associate-*r/75.5%
unpow275.5%
associate-/r*96.3%
fma-neg96.3%
distribute-rgt-neg-in96.3%
hypot-udef75.7%
unpow275.7%
unpow275.7%
unpow275.7%
unpow275.7%
+-commutative75.7%
hypot-def96.3%
hypot-udef75.7%
unpow275.7%
unpow275.7%
unpow275.7%
unpow275.7%
Applied egg-rr96.3%
if 2.0000000000000001e300 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 12.0%
Taylor expanded in c around inf 49.9%
*-un-lft-identity49.9%
metadata-eval49.9%
unpow249.9%
times-frac56.9%
metadata-eval56.9%
Applied egg-rr56.9%
associate-*l/56.8%
*-un-lft-identity56.8%
associate-/l*66.5%
Applied egg-rr66.5%
associate-/r/66.6%
Applied egg-rr66.6%
Final simplification89.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ b c) (* (* d (/ a c)) (/ -1.0 c)))))
(if (<= c -7.4e+102)
t_0
(if (<= c -1.8e-168)
(/ (fma b c (* a (- d))) (fma c c (* d d)))
(if (<= c 8.6e-188)
(/ (- a) d)
(if (<= c 2.4e+42)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = (b / c) + ((d * (a / c)) * (-1.0 / c));
double tmp;
if (c <= -7.4e+102) {
tmp = t_0;
} else if (c <= -1.8e-168) {
tmp = fma(b, c, (a * -d)) / fma(c, c, (d * d));
} else if (c <= 8.6e-188) {
tmp = -a / d;
} else if (c <= 2.4e+42) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b / c) + Float64(Float64(d * Float64(a / c)) * Float64(-1.0 / c))) tmp = 0.0 if (c <= -7.4e+102) tmp = t_0; elseif (c <= -1.8e-168) tmp = Float64(fma(b, c, Float64(a * Float64(-d))) / fma(c, c, Float64(d * d))); elseif (c <= 8.6e-188) tmp = Float64(Float64(-a) / d); elseif (c <= 2.4e+42) 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[(b / c), $MachinePrecision] + N[(N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -7.4e+102], t$95$0, If[LessEqual[c, -1.8e-168], N[(N[(b * c + N[(a * (-d)), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 8.6e-188], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 2.4e+42], 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 := \frac{b}{c} + \left(d \cdot \frac{a}{c}\right) \cdot \frac{-1}{c}\\
\mathbf{if}\;c \leq -7.4 \cdot 10^{+102}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq -1.8 \cdot 10^{-168}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, c, a \cdot \left(-d\right)\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;c \leq 8.6 \cdot 10^{-188}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{+42}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if c < -7.40000000000000045e102 or 2.3999999999999999e42 < c Initial program 34.3%
Taylor expanded in c around inf 73.7%
*-un-lft-identity73.7%
metadata-eval73.7%
unpow273.7%
times-frac81.5%
metadata-eval81.5%
Applied egg-rr81.5%
associate-/l*86.7%
associate-/r/87.7%
Applied egg-rr87.7%
if -7.40000000000000045e102 < c < -1.7999999999999999e-168Initial program 88.1%
fma-neg88.1%
distribute-rgt-neg-out88.1%
fma-def88.1%
Simplified88.1%
if -1.7999999999999999e-168 < c < 8.59999999999999975e-188Initial program 56.5%
Taylor expanded in c around 0 83.8%
associate-*r/83.8%
neg-mul-183.8%
Simplified83.8%
if 8.59999999999999975e-188 < c < 2.3999999999999999e42Initial program 81.8%
Final simplification85.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(t_1 (+ (/ b c) (* (* d (/ a c)) (/ -1.0 c)))))
(if (<= c -8.2e+102)
t_1
(if (<= c -9.5e-170)
t_0
(if (<= c 4.5e-184) (/ (- a) d) (if (<= c 2.4e+42) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double t_1 = (b / c) + ((d * (a / c)) * (-1.0 / c));
double tmp;
if (c <= -8.2e+102) {
tmp = t_1;
} else if (c <= -9.5e-170) {
tmp = t_0;
} else if (c <= 4.5e-184) {
tmp = -a / d;
} else if (c <= 2.4e+42) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d))
t_1 = (b / c) + ((d * (a / c)) * ((-1.0d0) / c))
if (c <= (-8.2d+102)) then
tmp = t_1
else if (c <= (-9.5d-170)) then
tmp = t_0
else if (c <= 4.5d-184) then
tmp = -a / d
else if (c <= 2.4d+42) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double t_1 = (b / c) + ((d * (a / c)) * (-1.0 / c));
double tmp;
if (c <= -8.2e+102) {
tmp = t_1;
} else if (c <= -9.5e-170) {
tmp = t_0;
} else if (c <= 4.5e-184) {
tmp = -a / d;
} else if (c <= 2.4e+42) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)) t_1 = (b / c) + ((d * (a / c)) * (-1.0 / c)) tmp = 0 if c <= -8.2e+102: tmp = t_1 elif c <= -9.5e-170: tmp = t_0 elif c <= 4.5e-184: tmp = -a / d elif c <= 2.4e+42: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(b / c) + Float64(Float64(d * Float64(a / c)) * Float64(-1.0 / c))) tmp = 0.0 if (c <= -8.2e+102) tmp = t_1; elseif (c <= -9.5e-170) tmp = t_0; elseif (c <= 4.5e-184) tmp = Float64(Float64(-a) / d); elseif (c <= 2.4e+42) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)); t_1 = (b / c) + ((d * (a / c)) * (-1.0 / c)); tmp = 0.0; if (c <= -8.2e+102) tmp = t_1; elseif (c <= -9.5e-170) tmp = t_0; elseif (c <= 4.5e-184) tmp = -a / d; elseif (c <= 2.4e+42) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / c), $MachinePrecision] + N[(N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -8.2e+102], t$95$1, If[LessEqual[c, -9.5e-170], t$95$0, If[LessEqual[c, 4.5e-184], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 2.4e+42], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{b}{c} + \left(d \cdot \frac{a}{c}\right) \cdot \frac{-1}{c}\\
\mathbf{if}\;c \leq -8.2 \cdot 10^{+102}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -9.5 \cdot 10^{-170}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 4.5 \cdot 10^{-184}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{+42}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if c < -8.1999999999999999e102 or 2.3999999999999999e42 < c Initial program 34.3%
Taylor expanded in c around inf 73.7%
*-un-lft-identity73.7%
metadata-eval73.7%
unpow273.7%
times-frac81.5%
metadata-eval81.5%
Applied egg-rr81.5%
associate-/l*86.7%
associate-/r/87.7%
Applied egg-rr87.7%
if -8.1999999999999999e102 < c < -9.5000000000000001e-170 or 4.5000000000000001e-184 < c < 2.3999999999999999e42Initial program 85.2%
if -9.5000000000000001e-170 < c < 4.5000000000000001e-184Initial program 56.5%
Taylor expanded in c around 0 83.8%
associate-*r/83.8%
neg-mul-183.8%
Simplified83.8%
Final simplification85.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (* b c) (+ (* c c) (* d d)))))
(if (<= c -9.6e+94)
(/ b c)
(if (<= c -4.1e-84)
t_0
(if (<= c 2.5e-66) (/ (- a) d) (if (<= c 3.8e+40) t_0 (/ b c)))))))
double code(double a, double b, double c, double d) {
double t_0 = (b * c) / ((c * c) + (d * d));
double tmp;
if (c <= -9.6e+94) {
tmp = b / c;
} else if (c <= -4.1e-84) {
tmp = t_0;
} else if (c <= 2.5e-66) {
tmp = -a / d;
} else if (c <= 3.8e+40) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = (b * c) / ((c * c) + (d * d))
if (c <= (-9.6d+94)) then
tmp = b / c
else if (c <= (-4.1d-84)) then
tmp = t_0
else if (c <= 2.5d-66) then
tmp = -a / d
else if (c <= 3.8d+40) then
tmp = t_0
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b * c) / ((c * c) + (d * d));
double tmp;
if (c <= -9.6e+94) {
tmp = b / c;
} else if (c <= -4.1e-84) {
tmp = t_0;
} else if (c <= 2.5e-66) {
tmp = -a / d;
} else if (c <= 3.8e+40) {
tmp = t_0;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b * c) / ((c * c) + (d * d)) tmp = 0 if c <= -9.6e+94: tmp = b / c elif c <= -4.1e-84: tmp = t_0 elif c <= 2.5e-66: tmp = -a / d elif c <= 3.8e+40: tmp = t_0 else: tmp = b / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b * c) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (c <= -9.6e+94) tmp = Float64(b / c); elseif (c <= -4.1e-84) tmp = t_0; elseif (c <= 2.5e-66) tmp = Float64(Float64(-a) / d); elseif (c <= 3.8e+40) tmp = t_0; else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b * c) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -9.6e+94) tmp = b / c; elseif (c <= -4.1e-84) tmp = t_0; elseif (c <= 2.5e-66) tmp = -a / d; elseif (c <= 3.8e+40) tmp = t_0; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -9.6e+94], N[(b / c), $MachinePrecision], If[LessEqual[c, -4.1e-84], t$95$0, If[LessEqual[c, 2.5e-66], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 3.8e+40], t$95$0, N[(b / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -9.6 \cdot 10^{+94}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -4.1 \cdot 10^{-84}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 2.5 \cdot 10^{-66}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 3.8 \cdot 10^{+40}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -9.5999999999999993e94 or 3.80000000000000004e40 < c Initial program 35.0%
Taylor expanded in c around inf 73.5%
if -9.5999999999999993e94 < c < -4.10000000000000005e-84 or 2.49999999999999981e-66 < c < 3.80000000000000004e40Initial program 90.3%
Taylor expanded in b around inf 66.7%
*-commutative66.7%
Simplified66.7%
if -4.10000000000000005e-84 < c < 2.49999999999999981e-66Initial program 66.4%
Taylor expanded in c around 0 70.7%
associate-*r/70.7%
neg-mul-170.7%
Simplified70.7%
Final simplification70.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (* b c) (+ (* c c) (* d d))))
(t_1 (- (/ b c) (* (/ a c) (/ d c)))))
(if (<= c -24000.0)
t_1
(if (<= c -2.8e-87)
t_0
(if (<= c 3.2e-66) (/ (- a) d) (if (<= c 3.9e+36) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = (b * c) / ((c * c) + (d * d));
double t_1 = (b / c) - ((a / c) * (d / c));
double tmp;
if (c <= -24000.0) {
tmp = t_1;
} else if (c <= -2.8e-87) {
tmp = t_0;
} else if (c <= 3.2e-66) {
tmp = -a / d;
} else if (c <= 3.9e+36) {
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) / ((c * c) + (d * d))
t_1 = (b / c) - ((a / c) * (d / c))
if (c <= (-24000.0d0)) then
tmp = t_1
else if (c <= (-2.8d-87)) then
tmp = t_0
else if (c <= 3.2d-66) then
tmp = -a / d
else if (c <= 3.9d+36) 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) / ((c * c) + (d * d));
double t_1 = (b / c) - ((a / c) * (d / c));
double tmp;
if (c <= -24000.0) {
tmp = t_1;
} else if (c <= -2.8e-87) {
tmp = t_0;
} else if (c <= 3.2e-66) {
tmp = -a / d;
} else if (c <= 3.9e+36) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b * c) / ((c * c) + (d * d)) t_1 = (b / c) - ((a / c) * (d / c)) tmp = 0 if c <= -24000.0: tmp = t_1 elif c <= -2.8e-87: tmp = t_0 elif c <= 3.2e-66: tmp = -a / d elif c <= 3.9e+36: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b * c) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))) tmp = 0.0 if (c <= -24000.0) tmp = t_1; elseif (c <= -2.8e-87) tmp = t_0; elseif (c <= 3.2e-66) tmp = Float64(Float64(-a) / d); elseif (c <= 3.9e+36) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b * c) / ((c * c) + (d * d)); t_1 = (b / c) - ((a / c) * (d / c)); tmp = 0.0; if (c <= -24000.0) tmp = t_1; elseif (c <= -2.8e-87) tmp = t_0; elseif (c <= 3.2e-66) tmp = -a / d; elseif (c <= 3.9e+36) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -24000.0], t$95$1, If[LessEqual[c, -2.8e-87], t$95$0, If[LessEqual[c, 3.2e-66], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 3.9e+36], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c}{c \cdot c + d \cdot d}\\
t_1 := \frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{if}\;c \leq -24000:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -2.8 \cdot 10^{-87}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 3.2 \cdot 10^{-66}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 3.9 \cdot 10^{+36}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if c < -24000 or 3.90000000000000021e36 < c Initial program 45.2%
Taylor expanded in c around inf 75.1%
*-commutative75.1%
unpow275.1%
times-frac86.4%
Applied egg-rr86.4%
if -24000 < c < -2.8000000000000001e-87 or 3.19999999999999982e-66 < c < 3.90000000000000021e36Initial program 88.3%
Taylor expanded in b around inf 68.5%
*-commutative68.5%
Simplified68.5%
if -2.8000000000000001e-87 < c < 3.19999999999999982e-66Initial program 66.4%
Taylor expanded in c around 0 70.7%
associate-*r/70.7%
neg-mul-170.7%
Simplified70.7%
Final simplification77.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (* b c) (+ (* c c) (* d d))))
(t_1 (- (/ b c) (/ (* d (/ a c)) c))))
(if (<= c -235.0)
t_1
(if (<= c -2.2e-85)
t_0
(if (<= c 1.7e-67) (/ (- a) d) (if (<= c 2.02e+37) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = (b * c) / ((c * c) + (d * d));
double t_1 = (b / c) - ((d * (a / c)) / c);
double tmp;
if (c <= -235.0) {
tmp = t_1;
} else if (c <= -2.2e-85) {
tmp = t_0;
} else if (c <= 1.7e-67) {
tmp = -a / d;
} else if (c <= 2.02e+37) {
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) / ((c * c) + (d * d))
t_1 = (b / c) - ((d * (a / c)) / c)
if (c <= (-235.0d0)) then
tmp = t_1
else if (c <= (-2.2d-85)) then
tmp = t_0
else if (c <= 1.7d-67) then
tmp = -a / d
else if (c <= 2.02d+37) 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) / ((c * c) + (d * d));
double t_1 = (b / c) - ((d * (a / c)) / c);
double tmp;
if (c <= -235.0) {
tmp = t_1;
} else if (c <= -2.2e-85) {
tmp = t_0;
} else if (c <= 1.7e-67) {
tmp = -a / d;
} else if (c <= 2.02e+37) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b * c) / ((c * c) + (d * d)) t_1 = (b / c) - ((d * (a / c)) / c) tmp = 0 if c <= -235.0: tmp = t_1 elif c <= -2.2e-85: tmp = t_0 elif c <= 1.7e-67: tmp = -a / d elif c <= 2.02e+37: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b * c) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(b / c) - Float64(Float64(d * Float64(a / c)) / c)) tmp = 0.0 if (c <= -235.0) tmp = t_1; elseif (c <= -2.2e-85) tmp = t_0; elseif (c <= 1.7e-67) tmp = Float64(Float64(-a) / d); elseif (c <= 2.02e+37) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b * c) / ((c * c) + (d * d)); t_1 = (b / c) - ((d * (a / c)) / c); tmp = 0.0; if (c <= -235.0) tmp = t_1; elseif (c <= -2.2e-85) tmp = t_0; elseif (c <= 1.7e-67) tmp = -a / d; elseif (c <= 2.02e+37) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / c), $MachinePrecision] - N[(N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -235.0], t$95$1, If[LessEqual[c, -2.2e-85], t$95$0, If[LessEqual[c, 1.7e-67], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 2.02e+37], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c}{c \cdot c + d \cdot d}\\
t_1 := \frac{b}{c} - \frac{d \cdot \frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -235:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -2.2 \cdot 10^{-85}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.7 \cdot 10^{-67}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 2.02 \cdot 10^{+37}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if c < -235 or 2.0199999999999999e37 < c Initial program 45.2%
Taylor expanded in c around inf 75.1%
*-un-lft-identity75.1%
metadata-eval75.1%
unpow275.1%
times-frac81.5%
metadata-eval81.5%
Applied egg-rr81.5%
associate-*l/81.5%
*-un-lft-identity81.5%
associate-/l*85.8%
Applied egg-rr85.8%
associate-/r/86.6%
Applied egg-rr86.6%
if -235 < c < -2.2e-85 or 1.70000000000000005e-67 < c < 2.0199999999999999e37Initial program 88.3%
Taylor expanded in b around inf 68.5%
*-commutative68.5%
Simplified68.5%
if -2.2e-85 < c < 1.70000000000000005e-67Initial program 66.4%
Taylor expanded in c around 0 70.7%
associate-*r/70.7%
neg-mul-170.7%
Simplified70.7%
Final simplification77.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -7.2e+85) (not (<= d 1.4e+23))) (/ (- a) d) (+ (/ b c) (* (/ (* a d) c) (/ -1.0 c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.2e+85) || !(d <= 1.4e+23)) {
tmp = -a / d;
} else {
tmp = (b / c) + (((a * d) / c) * (-1.0 / 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 <= (-7.2d+85)) .or. (.not. (d <= 1.4d+23))) then
tmp = -a / d
else
tmp = (b / c) + (((a * d) / c) * ((-1.0d0) / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.2e+85) || !(d <= 1.4e+23)) {
tmp = -a / d;
} else {
tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -7.2e+85) or not (d <= 1.4e+23): tmp = -a / d else: tmp = (b / c) + (((a * d) / c) * (-1.0 / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -7.2e+85) || !(d <= 1.4e+23)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b / c) + Float64(Float64(Float64(a * d) / c) * Float64(-1.0 / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -7.2e+85) || ~((d <= 1.4e+23))) tmp = -a / d; else tmp = (b / c) + (((a * d) / c) * (-1.0 / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7.2e+85], N[Not[LessEqual[d, 1.4e+23]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b / c), $MachinePrecision] + N[(N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision] * N[(-1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -7.2 \cdot 10^{+85} \lor \neg \left(d \leq 1.4 \cdot 10^{+23}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c} + \frac{a \cdot d}{c} \cdot \frac{-1}{c}\\
\end{array}
\end{array}
if d < -7.1999999999999996e85 or 1.4e23 < d Initial program 40.4%
Taylor expanded in c around 0 68.0%
associate-*r/68.0%
neg-mul-168.0%
Simplified68.0%
if -7.1999999999999996e85 < d < 1.4e23Initial program 72.0%
Taylor expanded in c around inf 72.3%
*-un-lft-identity72.3%
metadata-eval72.3%
unpow272.3%
times-frac78.9%
metadata-eval78.9%
Applied egg-rr78.9%
Final simplification74.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.4e+86) (not (<= d 2.35e+20))) (/ (- a) d) (- (/ b c) (/ (/ a (/ c d)) c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.4e+86) || !(d <= 2.35e+20)) {
tmp = -a / d;
} 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) :: tmp
if ((d <= (-1.4d+86)) .or. (.not. (d <= 2.35d+20))) then
tmp = -a / d
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 tmp;
if ((d <= -1.4e+86) || !(d <= 2.35e+20)) {
tmp = -a / d;
} else {
tmp = (b / c) - ((a / (c / d)) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.4e+86) or not (d <= 2.35e+20): tmp = -a / d else: tmp = (b / c) - ((a / (c / d)) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.4e+86) || !(d <= 2.35e+20)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b / c) - Float64(Float64(a / Float64(c / d)) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.4e+86) || ~((d <= 2.35e+20))) tmp = -a / d; else tmp = (b / c) - ((a / (c / d)) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.4e+86], N[Not[LessEqual[d, 2.35e+20]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b / c), $MachinePrecision] - N[(N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.4 \cdot 10^{+86} \lor \neg \left(d \leq 2.35 \cdot 10^{+20}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c} - \frac{\frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -1.40000000000000002e86 or 2.35e20 < d Initial program 40.4%
Taylor expanded in c around 0 68.0%
associate-*r/68.0%
neg-mul-168.0%
Simplified68.0%
if -1.40000000000000002e86 < d < 2.35e20Initial program 72.0%
Taylor expanded in c around inf 72.3%
*-un-lft-identity72.3%
metadata-eval72.3%
unpow272.3%
times-frac78.9%
metadata-eval78.9%
Applied egg-rr78.9%
associate-*l/78.8%
*-un-lft-identity78.8%
associate-/l*78.3%
Applied egg-rr78.3%
Final simplification74.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.15e-83) (not (<= c 6.4e-41))) (/ b c) (/ (- a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.15e-83) || !(c <= 6.4e-41)) {
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 <= (-1.15d-83)) .or. (.not. (c <= 6.4d-41))) 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 <= -1.15e-83) || !(c <= 6.4e-41)) {
tmp = b / c;
} else {
tmp = -a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.15e-83) or not (c <= 6.4e-41): tmp = b / c else: tmp = -a / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.15e-83) || !(c <= 6.4e-41)) tmp = Float64(b / c); else tmp = Float64(Float64(-a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.15e-83) || ~((c <= 6.4e-41))) tmp = b / c; else tmp = -a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.15e-83], N[Not[LessEqual[c, 6.4e-41]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[((-a) / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.15 \cdot 10^{-83} \lor \neg \left(c \leq 6.4 \cdot 10^{-41}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{d}\\
\end{array}
\end{array}
if c < -1.14999999999999995e-83 or 6.40000000000000024e-41 < c Initial program 55.3%
Taylor expanded in c around inf 64.1%
if -1.14999999999999995e-83 < c < 6.40000000000000024e-41Initial program 67.7%
Taylor expanded in c around 0 69.0%
associate-*r/69.0%
neg-mul-169.0%
Simplified69.0%
Final simplification66.1%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / 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 = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 60.4%
frac-2neg60.4%
div-inv60.3%
Applied egg-rr60.3%
*-commutative60.3%
neg-mul-160.3%
associate-/r*60.3%
metadata-eval60.3%
Simplified60.3%
associate-*r/60.4%
unpow260.4%
associate-/r*77.5%
fma-neg77.5%
distribute-rgt-neg-in77.5%
hypot-udef60.5%
unpow260.5%
unpow260.5%
unpow260.5%
unpow260.5%
+-commutative60.5%
hypot-def77.5%
hypot-udef60.5%
unpow260.5%
unpow260.5%
unpow260.5%
unpow260.5%
Applied egg-rr77.5%
Taylor expanded in c around -inf 31.2%
Taylor expanded in d around inf 11.6%
Final simplification11.6%
(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 60.4%
Taylor expanded in c around inf 43.6%
Final simplification43.6%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2023305
(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))))