Average Error: 26.2 → 26.2
Time: 33.7s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \left(b \cdot d + a \cdot c\right)}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \left(b \cdot d + a \cdot c\right)}{\sqrt{c \cdot c + d \cdot d}}
double f(double a, double b, double c, double d) {
        double r9079917 = a;
        double r9079918 = c;
        double r9079919 = r9079917 * r9079918;
        double r9079920 = b;
        double r9079921 = d;
        double r9079922 = r9079920 * r9079921;
        double r9079923 = r9079919 + r9079922;
        double r9079924 = r9079918 * r9079918;
        double r9079925 = r9079921 * r9079921;
        double r9079926 = r9079924 + r9079925;
        double r9079927 = r9079923 / r9079926;
        return r9079927;
}

double f(double a, double b, double c, double d) {
        double r9079928 = 1.0;
        double r9079929 = c;
        double r9079930 = r9079929 * r9079929;
        double r9079931 = d;
        double r9079932 = r9079931 * r9079931;
        double r9079933 = r9079930 + r9079932;
        double r9079934 = sqrt(r9079933);
        double r9079935 = r9079928 / r9079934;
        double r9079936 = b;
        double r9079937 = r9079936 * r9079931;
        double r9079938 = a;
        double r9079939 = r9079938 * r9079929;
        double r9079940 = r9079937 + r9079939;
        double r9079941 = r9079935 * r9079940;
        double r9079942 = r9079941 / r9079934;
        return r9079942;
}

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

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

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

    \[\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. Using strategy rm
  6. Applied div-inv26.2

    \[\leadsto \frac{\color{blue}{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  7. Final simplification26.2

    \[\leadsto \frac{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \left(b \cdot d + a \cdot c\right)}{\sqrt{c \cdot c + d \cdot d}}\]

Reproduce

herbie shell --seed 2019121 
(FPCore (a b c d)
  :name "Complex division, real part"

  :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))))