Average Error: 25.8 → 25.8
Time: 22.9s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{b \cdot d + a \cdot c}{\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 r30244916 = a;
        double r30244917 = c;
        double r30244918 = r30244916 * r30244917;
        double r30244919 = b;
        double r30244920 = d;
        double r30244921 = r30244919 * r30244920;
        double r30244922 = r30244918 + r30244921;
        double r30244923 = r30244917 * r30244917;
        double r30244924 = r30244920 * r30244920;
        double r30244925 = r30244923 + r30244924;
        double r30244926 = r30244922 / r30244925;
        return r30244926;
}

double f(double a, double b, double c, double d) {
        double r30244927 = b;
        double r30244928 = d;
        double r30244929 = r30244927 * r30244928;
        double r30244930 = a;
        double r30244931 = c;
        double r30244932 = r30244930 * r30244931;
        double r30244933 = r30244929 + r30244932;
        double r30244934 = r30244931 * r30244931;
        double r30244935 = r30244928 * r30244928;
        double r30244936 = r30244934 + r30244935;
        double r30244937 = sqrt(r30244936);
        double r30244938 = r30244933 / r30244937;
        double r30244939 = r30244938 / r30244937;
        return r30244939;
}

\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

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.8

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

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

Reproduce

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