(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (/ (- (fma a c (* d b))) (hypot c d)) (- (hypot c d)))))
(if (<= c -3.951719848587527e+140)
(fma (/ d c) (/ b c) (/ a c))
(if (<= c -2.1020937544048643e-195)
t_0
(if (<= c 9.158472105652272e-177)
(+ (/ b d) (/ (* c a) (pow d 2.0)))
(if (<= c 7.712883155351153e+76)
t_0
(* (/ 1.0 (hypot c d)) (fma (/ d c) b a))))))))double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
double code(double a, double b, double c, double d) {
double t_0 = (-fma(a, c, (d * b)) / hypot(c, d)) / -hypot(c, d);
double tmp;
if (c <= -3.951719848587527e+140) {
tmp = fma((d / c), (b / c), (a / c));
} else if (c <= -2.1020937544048643e-195) {
tmp = t_0;
} else if (c <= 9.158472105652272e-177) {
tmp = (b / d) + ((c * a) / pow(d, 2.0));
} else if (c <= 7.712883155351153e+76) {
tmp = t_0;
} else {
tmp = (1.0 / hypot(c, d)) * fma((d / c), b, a);
}
return tmp;
}
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function code(a, b, c, d) t_0 = Float64(Float64(Float64(-fma(a, c, Float64(d * b))) / hypot(c, d)) / Float64(-hypot(c, d))) tmp = 0.0 if (c <= -3.951719848587527e+140) tmp = fma(Float64(d / c), Float64(b / c), Float64(a / c)); elseif (c <= -2.1020937544048643e-195) tmp = t_0; elseif (c <= 9.158472105652272e-177) tmp = Float64(Float64(b / d) + Float64(Float64(c * a) / (d ^ 2.0))); elseif (c <= 7.712883155351153e+76) tmp = t_0; else tmp = Float64(Float64(1.0 / hypot(c, d)) * fma(Float64(d / c), b, a)); end return tmp end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[((-N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision]) / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / (-N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision])), $MachinePrecision]}, If[LessEqual[c, -3.951719848587527e+140], N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision] + N[(a / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -2.1020937544048643e-195], t$95$0, If[LessEqual[c, 9.158472105652272e-177], N[(N[(b / d), $MachinePrecision] + N[(N[(c * a), $MachinePrecision] / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.712883155351153e+76], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision]), $MachinePrecision]]]]]]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{\frac{-\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{-\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;c \leq -3.951719848587527 \cdot 10^{+140}:\\
\;\;\;\;\mathsf{fma}\left(\frac{d}{c}, \frac{b}{c}, \frac{a}{c}\right)\\
\mathbf{elif}\;c \leq -2.1020937544048643 \cdot 10^{-195}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 9.158472105652272 \cdot 10^{-177}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}\\
\mathbf{elif}\;c \leq 7.712883155351153 \cdot 10^{+76}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \mathsf{fma}\left(\frac{d}{c}, b, a\right)\\
\end{array}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.8 |
|---|---|
| Target | 0.5 |
| Herbie | 10.4 |
if c < -3.9517198485875273e140Initial program 44.4
Simplified44.4
Applied egg-rr28.6
Taylor expanded in c around inf 15.1
Simplified7.6
if -3.9517198485875273e140 < c < -2.1020937544048643e-195 or 9.15847210565227231e-177 < c < 7.71288315535115255e76Initial program 16.3
Simplified16.3
Applied egg-rr11.2
Applied egg-rr11.1
if -2.1020937544048643e-195 < c < 9.15847210565227231e-177Initial program 23.3
Simplified23.3
Taylor expanded in c around 0 9.7
if 7.71288315535115255e76 < c Initial program 37.4
Simplified37.4
Applied egg-rr25.3
Taylor expanded in c around inf 14.1
Simplified11.1
Final simplification10.4
herbie shell --seed 2022153
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))