Average Error: 26.4 → 26.3
Time: 3.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 r104862 = a;
        double r104863 = c;
        double r104864 = r104862 * r104863;
        double r104865 = b;
        double r104866 = d;
        double r104867 = r104865 * r104866;
        double r104868 = r104864 + r104867;
        double r104869 = r104863 * r104863;
        double r104870 = r104866 * r104866;
        double r104871 = r104869 + r104870;
        double r104872 = r104868 / r104871;
        return r104872;
}

double f(double a, double b, double c, double d) {
        double r104873 = a;
        double r104874 = c;
        double r104875 = r104873 * r104874;
        double r104876 = b;
        double r104877 = d;
        double r104878 = r104876 * r104877;
        double r104879 = r104875 + r104878;
        double r104880 = r104874 * r104874;
        double r104881 = r104877 * r104877;
        double r104882 = r104880 + r104881;
        double r104883 = sqrt(r104882);
        double r104884 = r104879 / r104883;
        double r104885 = r104884 / r104883;
        return r104885;
}

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

Original26.4
Target0.4
Herbie26.3
\[\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 26.4

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

    \[\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*26.3

    \[\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 simplification26.3

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