Average Error: 26.0 → 26.0
Time: 12.6s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
double f(double a, double b, double c, double d) {
        double r67879 = a;
        double r67880 = c;
        double r67881 = r67879 * r67880;
        double r67882 = b;
        double r67883 = d;
        double r67884 = r67882 * r67883;
        double r67885 = r67881 + r67884;
        double r67886 = r67880 * r67880;
        double r67887 = r67883 * r67883;
        double r67888 = r67886 + r67887;
        double r67889 = r67885 / r67888;
        return r67889;
}

double f(double a, double b, double c, double d) {
        double r67890 = a;
        double r67891 = c;
        double r67892 = r67890 * r67891;
        double r67893 = b;
        double r67894 = d;
        double r67895 = r67893 * r67894;
        double r67896 = r67892 + r67895;
        double r67897 = r67891 * r67891;
        double r67898 = r67894 * r67894;
        double r67899 = r67897 + r67898;
        double r67900 = r67896 / r67899;
        return r67900;
}

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.0
Target0.5
Herbie26.0
\[\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.0

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

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

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

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

Reproduce

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