Average Error: 25.9 → 25.9
Time: 4.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 r104987 = a;
        double r104988 = c;
        double r104989 = r104987 * r104988;
        double r104990 = b;
        double r104991 = d;
        double r104992 = r104990 * r104991;
        double r104993 = r104989 + r104992;
        double r104994 = r104988 * r104988;
        double r104995 = r104991 * r104991;
        double r104996 = r104994 + r104995;
        double r104997 = r104993 / r104996;
        return r104997;
}

double f(double a, double b, double c, double d) {
        double r104998 = a;
        double r104999 = c;
        double r105000 = r104998 * r104999;
        double r105001 = b;
        double r105002 = d;
        double r105003 = r105001 * r105002;
        double r105004 = r105000 + r105003;
        double r105005 = r104999 * r104999;
        double r105006 = r105002 * r105002;
        double r105007 = r105005 + r105006;
        double r105008 = sqrt(r105007);
        double r105009 = r105004 / r105008;
        double r105010 = r105009 / r105008;
        return r105010;
}

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.4
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. Final simplification25.9

    \[\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 2019318 
(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))))