Average Error: 25.9 → 25.8
Time: 12.9s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}
double f(double a, double b, double c, double d) {
        double r83601 = a;
        double r83602 = c;
        double r83603 = r83601 * r83602;
        double r83604 = b;
        double r83605 = d;
        double r83606 = r83604 * r83605;
        double r83607 = r83603 + r83606;
        double r83608 = r83602 * r83602;
        double r83609 = r83605 * r83605;
        double r83610 = r83608 + r83609;
        double r83611 = r83607 / r83610;
        return r83611;
}

double f(double a, double b, double c, double d) {
        double r83612 = a;
        double r83613 = c;
        double r83614 = r83612 * r83613;
        double r83615 = b;
        double r83616 = d;
        double r83617 = r83615 * r83616;
        double r83618 = r83614 + r83617;
        double r83619 = r83613 * r83613;
        double r83620 = r83616 * r83616;
        double r83621 = r83619 + r83620;
        double r83622 = sqrt(r83621);
        double r83623 = r83618 / r83622;
        double r83624 = r83623 / r83622;
        return r83624;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original25.9
Target0.5
Herbie25.8
\[\begin{array}{l} \mathbf{if}\;\left|d\right| \lt \left|c\right|:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array}\]

Derivation

  1. Initial program 25.9

    \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
  2. Using strategy rm
  3. Applied add-sqr-sqrt25.9

    \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
  4. Applied associate-/r*25.8

    \[\leadsto \color{blue}{\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
  5. Final simplification25.8

    \[\leadsto \frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]

Reproduce

herbie shell --seed 2019325 
(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))))