Average Error: 26.9 → 26.9
Time: 3.0s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d}
double f(double a, double b, double c, double d) {
        double r105731 = a;
        double r105732 = c;
        double r105733 = r105731 * r105732;
        double r105734 = b;
        double r105735 = d;
        double r105736 = r105734 * r105735;
        double r105737 = r105733 + r105736;
        double r105738 = r105732 * r105732;
        double r105739 = r105735 * r105735;
        double r105740 = r105738 + r105739;
        double r105741 = r105737 / r105740;
        return r105741;
}

double f(double a, double b, double c, double d) {
        double r105742 = b;
        double r105743 = d;
        double r105744 = r105742 * r105743;
        double r105745 = a;
        double r105746 = c;
        double r105747 = r105745 * r105746;
        double r105748 = r105744 + r105747;
        double r105749 = r105746 * r105746;
        double r105750 = r105743 * r105743;
        double r105751 = r105749 + r105750;
        double r105752 = r105748 / r105751;
        return r105752;
}

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.9
Target0.4
Herbie26.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 26.9

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

    \[\leadsto \frac{\color{blue}{b \cdot d + a \cdot c}}{c \cdot c + d \cdot d}\]
  4. Final simplification26.9

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

Reproduce

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