Average Error: 26.0 → 26.0
Time: 15.0s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}
double f(double a, double b, double c, double d) {
        double r3067573 = a;
        double r3067574 = c;
        double r3067575 = r3067573 * r3067574;
        double r3067576 = b;
        double r3067577 = d;
        double r3067578 = r3067576 * r3067577;
        double r3067579 = r3067575 + r3067578;
        double r3067580 = r3067574 * r3067574;
        double r3067581 = r3067577 * r3067577;
        double r3067582 = r3067580 + r3067581;
        double r3067583 = r3067579 / r3067582;
        return r3067583;
}

double f(double a, double b, double c, double d) {
        double r3067584 = 1.0;
        double r3067585 = c;
        double r3067586 = r3067585 * r3067585;
        double r3067587 = d;
        double r3067588 = r3067587 * r3067587;
        double r3067589 = r3067586 + r3067588;
        double r3067590 = sqrt(r3067589);
        double r3067591 = r3067584 / r3067590;
        double r3067592 = b;
        double r3067593 = r3067592 * r3067587;
        double r3067594 = a;
        double r3067595 = r3067594 * r3067585;
        double r3067596 = r3067593 + r3067595;
        double r3067597 = r3067596 / r3067590;
        double r3067598 = r3067591 * r3067597;
        return r3067598;
}

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.0
Target0.5
Herbie26.0
\[\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.0

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

    \[\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 *-un-lft-identity26.0

    \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
  5. Applied times-frac26.0

    \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
  6. Final simplification26.0

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

Reproduce

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