Average Error: 25.9 → 25.9
Time: 14.7s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{a \cdot c + d \cdot b}{\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 + d \cdot b}{\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 r75586 = a;
        double r75587 = c;
        double r75588 = r75586 * r75587;
        double r75589 = b;
        double r75590 = d;
        double r75591 = r75589 * r75590;
        double r75592 = r75588 + r75591;
        double r75593 = r75587 * r75587;
        double r75594 = r75590 * r75590;
        double r75595 = r75593 + r75594;
        double r75596 = r75592 / r75595;
        return r75596;
}

double f(double a, double b, double c, double d) {
        double r75597 = a;
        double r75598 = c;
        double r75599 = r75597 * r75598;
        double r75600 = d;
        double r75601 = b;
        double r75602 = r75600 * r75601;
        double r75603 = r75599 + r75602;
        double r75604 = r75598 * r75598;
        double r75605 = r75600 * r75600;
        double r75606 = r75604 + r75605;
        double r75607 = sqrt(r75606);
        double r75608 = r75603 / r75607;
        double r75609 = r75608 / r75607;
        return r75609;
}

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.9
\[\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.9

    \[\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. Simplified25.9

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

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

Reproduce

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