Average Error: 25.8 → 25.8
Time: 13.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 r4932027 = a;
        double r4932028 = c;
        double r4932029 = r4932027 * r4932028;
        double r4932030 = b;
        double r4932031 = d;
        double r4932032 = r4932030 * r4932031;
        double r4932033 = r4932029 + r4932032;
        double r4932034 = r4932028 * r4932028;
        double r4932035 = r4932031 * r4932031;
        double r4932036 = r4932034 + r4932035;
        double r4932037 = r4932033 / r4932036;
        return r4932037;
}

double f(double a, double b, double c, double d) {
        double r4932038 = 1.0;
        double r4932039 = c;
        double r4932040 = r4932039 * r4932039;
        double r4932041 = d;
        double r4932042 = r4932041 * r4932041;
        double r4932043 = r4932040 + r4932042;
        double r4932044 = sqrt(r4932043);
        double r4932045 = r4932038 / r4932044;
        double r4932046 = b;
        double r4932047 = r4932046 * r4932041;
        double r4932048 = a;
        double r4932049 = r4932048 * r4932039;
        double r4932050 = r4932047 + r4932049;
        double r4932051 = r4932045 * r4932050;
        double r4932052 = r4932051 / r4932044;
        return r4932052;
}

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