Average Error: 26.3 → 26.3
Time: 12.6s
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 r5516819 = a;
        double r5516820 = c;
        double r5516821 = r5516819 * r5516820;
        double r5516822 = b;
        double r5516823 = d;
        double r5516824 = r5516822 * r5516823;
        double r5516825 = r5516821 + r5516824;
        double r5516826 = r5516820 * r5516820;
        double r5516827 = r5516823 * r5516823;
        double r5516828 = r5516826 + r5516827;
        double r5516829 = r5516825 / r5516828;
        return r5516829;
}

double f(double a, double b, double c, double d) {
        double r5516830 = 1.0;
        double r5516831 = c;
        double r5516832 = r5516831 * r5516831;
        double r5516833 = d;
        double r5516834 = r5516833 * r5516833;
        double r5516835 = r5516832 + r5516834;
        double r5516836 = sqrt(r5516835);
        double r5516837 = r5516830 / r5516836;
        double r5516838 = b;
        double r5516839 = r5516838 * r5516833;
        double r5516840 = a;
        double r5516841 = r5516840 * r5516831;
        double r5516842 = r5516839 + r5516841;
        double r5516843 = r5516842 / r5516836;
        double r5516844 = r5516837 * r5516843;
        return r5516844;
}

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

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

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

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

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

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