(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* d (* (/ 1.0 (hypot c d)) (/ a (hypot c d)))))
(t_1 (- (/ b c) t_0)))
(if (<= c -7.017566576847787e+131)
t_1
(if (<= c -2.9482117005194184e-127)
(- (/ c (* (hypot c d) (/ (hypot c d) b))) t_0)
(if (<= c 5.71825753163984e-152)
(fma b (/ (/ c d) d) (/ (- a) d))
(if (<= c 2.4464143950090505e+137)
(-
(/ c (/ (fma c c (* d d)) b))
(/ (* a (/ d (hypot d c))) (hypot d c)))
t_1))))))double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
double code(double a, double b, double c, double d) {
double t_0 = d * ((1.0 / hypot(c, d)) * (a / hypot(c, d)));
double t_1 = (b / c) - t_0;
double tmp;
if (c <= -7.017566576847787e+131) {
tmp = t_1;
} else if (c <= -2.9482117005194184e-127) {
tmp = (c / (hypot(c, d) * (hypot(c, d) / b))) - t_0;
} else if (c <= 5.71825753163984e-152) {
tmp = fma(b, ((c / d) / d), (-a / d));
} else if (c <= 2.4464143950090505e+137) {
tmp = (c / (fma(c, c, (d * d)) / b)) - ((a * (d / hypot(d, c))) / hypot(d, c));
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function code(a, b, c, d) t_0 = Float64(d * Float64(Float64(1.0 / hypot(c, d)) * Float64(a / hypot(c, d)))) t_1 = Float64(Float64(b / c) - t_0) tmp = 0.0 if (c <= -7.017566576847787e+131) tmp = t_1; elseif (c <= -2.9482117005194184e-127) tmp = Float64(Float64(c / Float64(hypot(c, d) * Float64(hypot(c, d) / b))) - t_0); elseif (c <= 5.71825753163984e-152) tmp = fma(b, Float64(Float64(c / d) / d), Float64(Float64(-a) / d)); elseif (c <= 2.4464143950090505e+137) tmp = Float64(Float64(c / Float64(fma(c, c, Float64(d * d)) / b)) - Float64(Float64(a * Float64(d / hypot(d, c))) / hypot(d, c))); else tmp = t_1; end return tmp 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]
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / c), $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[c, -7.017566576847787e+131], t$95$1, If[LessEqual[c, -2.9482117005194184e-127], N[(N[(c / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] * N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], If[LessEqual[c, 5.71825753163984e-152], N[(b * N[(N[(c / d), $MachinePrecision] / d), $MachinePrecision] + N[((-a) / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.4464143950090505e+137], N[(N[(c / N[(N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] - N[(N[(a * N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := d \cdot \left(\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\right)\\
t_1 := \frac{b}{c} - t_0\\
\mathbf{if}\;c \leq -7.017566576847787 \cdot 10^{+131}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -2.9482117005194184 \cdot 10^{-127}:\\
\;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right) \cdot \frac{\mathsf{hypot}\left(c, d\right)}{b}} - t_0\\
\mathbf{elif}\;c \leq 5.71825753163984 \cdot 10^{-152}:\\
\;\;\;\;\mathsf{fma}\left(b, \frac{\frac{c}{d}}{d}, \frac{-a}{d}\right)\\
\mathbf{elif}\;c \leq 2.4464143950090505 \cdot 10^{+137}:\\
\;\;\;\;\frac{c}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{b}} - \frac{a \cdot \frac{d}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.6 |
|---|---|
| Target | 0.4 |
| Herbie | 7.4 |
if c < -7.0175665768477871e131 or 2.44641439500905046e137 < c Initial program 43.6
Simplified43.6
Taylor expanded in a around 0 43.6
Simplified42.2
Applied egg-rr36.7
Taylor expanded in c around inf 7.1
if -7.0175665768477871e131 < c < -2.94821170051941835e-127Initial program 16.3
Simplified16.3
Taylor expanded in a around 0 16.3
Simplified16.7
Applied egg-rr12.7
Applied egg-rr10.7
if -2.94821170051941835e-127 < c < 5.71825753163984014e-152Initial program 24.0
Simplified24.0
Taylor expanded in d around inf 10.5
Simplified7.2
if 5.71825753163984014e-152 < c < 2.44641439500905046e137Initial program 17.3
Simplified17.3
Taylor expanded in a around 0 17.3
Simplified17.8
Applied egg-rr13.3
Applied egg-rr5.2
Final simplification7.4
herbie shell --seed 2022151
(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))))