\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\
\mathbf{if}\;c \leq -4.2044927924302215 \cdot 10^{+81}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := b \cdot d + c \cdot a\\
t_2 := d \cdot d + c \cdot c\\
\mathbf{if}\;c \leq -5.831437032843926 \cdot 10^{-31}:\\
\;\;\;\;\frac{t_1}{t_2}\\
\mathbf{elif}\;c \leq -6.071421943859113 \cdot 10^{-88}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_3 := \sqrt{t_2}\\
\mathbf{if}\;c \leq -2.567158710874279 \cdot 10^{-166}:\\
\;\;\;\;\frac{\frac{1}{\frac{t_3}{t_1}}}{t_3}\\
\mathbf{elif}\;c \leq 8.191619328525054 \cdot 10^{-172}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 1.2016013962778195 \cdot 10^{+76}:\\
\;\;\;\;t_1 \cdot \frac{\frac{1}{t_3}}{t_3}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}\\
\end{array}\\
\end{array}
(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 (+ (/ a c) (/ (/ b c) (/ c d)))))
(if (<= c -4.2044927924302215e+81)
t_0
(let* ((t_1 (+ (* b d) (* c a))) (t_2 (+ (* d d) (* c c))))
(if (<= c -5.831437032843926e-31)
(/ t_1 t_2)
(if (<= c -6.071421943859113e-88)
(+ (/ b d) (/ (* c a) (* d d)))
(let* ((t_3 (sqrt t_2)))
(if (<= c -2.567158710874279e-166)
(/ (/ 1.0 (/ t_3 t_1)) t_3)
(if (<= c 8.191619328525054e-172)
(/ b d)
(if (<= c 1.2016013962778195e+76)
(* t_1 (/ (/ 1.0 t_3) t_3))
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 = (a / c) + ((b / c) / (c / d));
double tmp;
if (c <= -4.2044927924302215e+81) {
tmp = t_0;
} else {
double t_1 = (b * d) + (c * a);
double t_2 = (d * d) + (c * c);
double tmp_1;
if (c <= -5.831437032843926e-31) {
tmp_1 = t_1 / t_2;
} else if (c <= -6.071421943859113e-88) {
tmp_1 = (b / d) + ((c * a) / (d * d));
} else {
double t_3 = sqrt(t_2);
double tmp_2;
if (c <= -2.567158710874279e-166) {
tmp_2 = (1.0 / (t_3 / t_1)) / t_3;
} else if (c <= 8.191619328525054e-172) {
tmp_2 = b / d;
} else if (c <= 1.2016013962778195e+76) {
tmp_2 = t_1 * ((1.0 / t_3) / t_3);
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
}
tmp = tmp_1;
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.6 |
|---|---|
| Target | 0.4 |
| Herbie | 14.2 |
if c < -4.20449279243022152e81 or 1.20160139627781954e76 < c Initial program 37.2
rmApplied add-sqr-sqrt_binary6437.2
Applied associate-/r*_binary6437.2
Simplified37.2
Taylor expanded around 0 16.3
Simplified15.8
rmApplied *-un-lft-identity_binary6415.8
Applied times-frac_binary6414.5
Applied associate-/r*_binary6411.0
Simplified11.0
if -4.20449279243022152e81 < c < -5.8314370328439262e-31Initial program 16.6
rmApplied add-sqr-sqrt_binary6416.6
Applied associate-/r*_binary6416.5
Simplified16.5
rmApplied associate-/l/_binary6416.6
Simplified16.6
if -5.8314370328439262e-31 < c < -6.07142194385911326e-88Initial program 13.6
Taylor expanded around 0 26.9
Simplified26.9
if -6.07142194385911326e-88 < c < -2.5671587108743e-166Initial program 15.3
rmApplied add-sqr-sqrt_binary6415.3
Applied associate-/r*_binary6415.3
Simplified15.3
rmApplied clear-num_binary6415.3
if -2.5671587108743e-166 < c < 8.1916193285250536e-172Initial program 23.4
Taylor expanded around 0 14.7
if 8.1916193285250536e-172 < c < 1.20160139627781954e76Initial program 15.6
rmApplied add-sqr-sqrt_binary6415.6
Applied associate-/r*_binary6415.5
Simplified15.5
rmApplied *-un-lft-identity_binary6415.5
Applied div-inv_binary6415.6
Applied times-frac_binary6415.7
Final simplification14.2
herbie shell --seed 2021205
(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))))