Average Error: 25.8 → 25.8
Time: 16.0s
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 r5662059 = a;
        double r5662060 = c;
        double r5662061 = r5662059 * r5662060;
        double r5662062 = b;
        double r5662063 = d;
        double r5662064 = r5662062 * r5662063;
        double r5662065 = r5662061 + r5662064;
        double r5662066 = r5662060 * r5662060;
        double r5662067 = r5662063 * r5662063;
        double r5662068 = r5662066 + r5662067;
        double r5662069 = r5662065 / r5662068;
        return r5662069;
}

double f(double a, double b, double c, double d) {
        double r5662070 = 1.0;
        double r5662071 = c;
        double r5662072 = r5662071 * r5662071;
        double r5662073 = d;
        double r5662074 = r5662073 * r5662073;
        double r5662075 = r5662072 + r5662074;
        double r5662076 = sqrt(r5662075);
        double r5662077 = r5662070 / r5662076;
        double r5662078 = b;
        double r5662079 = r5662078 * r5662073;
        double r5662080 = a;
        double r5662081 = r5662080 * r5662071;
        double r5662082 = r5662079 + r5662081;
        double r5662083 = r5662077 * r5662082;
        double r5662084 = r5662083 / r5662076;
        return r5662084;
}

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.8
Target0.4
Herbie25.8
\[\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.8

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

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

    \[\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-inv25.8

    \[\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 simplification25.8

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