Average Error: 26.8 → 26.8
Time: 28.2s
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 r6018724 = a;
        double r6018725 = c;
        double r6018726 = r6018724 * r6018725;
        double r6018727 = b;
        double r6018728 = d;
        double r6018729 = r6018727 * r6018728;
        double r6018730 = r6018726 + r6018729;
        double r6018731 = r6018725 * r6018725;
        double r6018732 = r6018728 * r6018728;
        double r6018733 = r6018731 + r6018732;
        double r6018734 = r6018730 / r6018733;
        return r6018734;
}

double f(double a, double b, double c, double d) {
        double r6018735 = 1.0;
        double r6018736 = c;
        double r6018737 = r6018736 * r6018736;
        double r6018738 = d;
        double r6018739 = r6018738 * r6018738;
        double r6018740 = r6018737 + r6018739;
        double r6018741 = sqrt(r6018740);
        double r6018742 = r6018735 / r6018741;
        double r6018743 = b;
        double r6018744 = r6018743 * r6018738;
        double r6018745 = a;
        double r6018746 = r6018745 * r6018736;
        double r6018747 = r6018744 + r6018746;
        double r6018748 = r6018747 / r6018741;
        double r6018749 = r6018742 * r6018748;
        return r6018749;
}

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.8
Target0.5
Herbie26.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 26.8

    \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
  2. Using strategy rm
  3. Applied add-sqr-sqrt26.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 *-un-lft-identity26.8

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

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

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