Average Error: 25.7 → 25.7
Time: 17.7s
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}}\]
\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 r3914367 = a;
        double r3914368 = c;
        double r3914369 = r3914367 * r3914368;
        double r3914370 = b;
        double r3914371 = d;
        double r3914372 = r3914370 * r3914371;
        double r3914373 = r3914369 + r3914372;
        double r3914374 = r3914368 * r3914368;
        double r3914375 = r3914371 * r3914371;
        double r3914376 = r3914374 + r3914375;
        double r3914377 = r3914373 / r3914376;
        return r3914377;
}

double f(double a, double b, double c, double d) {
        double r3914378 = b;
        double r3914379 = d;
        double r3914380 = r3914378 * r3914379;
        double r3914381 = a;
        double r3914382 = c;
        double r3914383 = r3914381 * r3914382;
        double r3914384 = r3914380 + r3914383;
        double r3914385 = r3914382 * r3914382;
        double r3914386 = r3914379 * r3914379;
        double r3914387 = r3914385 + r3914386;
        double r3914388 = sqrt(r3914387);
        double r3914389 = r3914384 / r3914388;
        double r3914390 = r3914389 / r3914388;
        return r3914390;
}

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

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

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

    \[\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. Using strategy rm
  8. Applied un-div-inv25.7

    \[\leadsto \frac{\color{blue}{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  9. Final simplification25.7

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