(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 d) (/ c d) (/ b d))))
(if (<= d -1.1870115366769325e+154)
t_0
(if (<= d -3.283521020638581e-106)
(fma b (/ d (fma d d (* c c))) (* c (/ a (pow (hypot d c) 2.0))))
(if (<= d 2.670610561569208e-71)
(fma (/ d c) (/ b c) (/ a c))
(if (<= d 1.2722428837589733e+140)
(/ (/ (fma a c (* d b)) (hypot c d)) (hypot c d))
t_0))))))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 / d), (c / d), (b / d));
double tmp;
if (d <= -1.1870115366769325e+154) {
tmp = t_0;
} else if (d <= -3.283521020638581e-106) {
tmp = fma(b, (d / fma(d, d, (c * c))), (c * (a / pow(hypot(d, c), 2.0))));
} else if (d <= 2.670610561569208e-71) {
tmp = fma((d / c), (b / c), (a / c));
} else if (d <= 1.2722428837589733e+140) {
tmp = (fma(a, c, (d * b)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = t_0;
}
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 = fma(Float64(a / d), Float64(c / d), Float64(b / d)) tmp = 0.0 if (d <= -1.1870115366769325e+154) tmp = t_0; elseif (d <= -3.283521020638581e-106) tmp = fma(b, Float64(d / fma(d, d, Float64(c * c))), Float64(c * Float64(a / (hypot(d, c) ^ 2.0)))); elseif (d <= 2.670610561569208e-71) tmp = fma(Float64(d / c), Float64(b / c), Float64(a / c)); elseif (d <= 1.2722428837589733e+140) tmp = Float64(Float64(fma(a, c, Float64(d * b)) / hypot(c, d)) / hypot(c, d)); else tmp = t_0; 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[(a / d), $MachinePrecision] * N[(c / d), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.1870115366769325e+154], t$95$0, If[LessEqual[d, -3.283521020638581e-106], N[(b * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(c * N[(a / N[Power[N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.670610561569208e-71], N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision] + N[(a / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.2722428837589733e+140], 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], t$95$0]]]]]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{a}{d}, \frac{c}{d}, \frac{b}{d}\right)\\
\mathbf{if}\;d \leq -1.1870115366769325 \cdot 10^{+154}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq -3.283521020638581 \cdot 10^{-106}:\\
\;\;\;\;\mathsf{fma}\left(b, \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}, c \cdot \frac{a}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}\right)\\
\mathbf{elif}\;d \leq 2.670610561569208 \cdot 10^{-71}:\\
\;\;\;\;\mathsf{fma}\left(\frac{d}{c}, \frac{b}{c}, \frac{a}{c}\right)\\
\mathbf{elif}\;d \leq 1.2722428837589733 \cdot 10^{+140}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.5 |
|---|---|
| Target | 0.5 |
| Herbie | 11.3 |
if d < -1.1870115366769325e154 or 1.2722428837589733e140 < d Initial program 44.2
Applied egg-rr29.5
Taylor expanded in c around 0 15.6
Simplified7.7
if -1.1870115366769325e154 < d < -3.283521020638581e-106Initial program 16.9
Taylor expanded in a around 0 16.9
Simplified14.1
Applied egg-rr14.1
if -3.283521020638581e-106 < d < 2.67061056156920781e-71Initial program 21.7
Applied egg-rr12.5
Taylor expanded in c around inf 12.3
Simplified11.0
if 2.67061056156920781e-71 < d < 1.2722428837589733e140Initial program 18.8
Applied egg-rr14.4
Applied egg-rr14.3
Final simplification11.3
herbie shell --seed 2022150
(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))))