Average Error: 25.8 → 25.8
Time: 13.4s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{d \cdot b + c \cdot a}}}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{d \cdot b + c \cdot a}}}{\sqrt{c \cdot c + d \cdot d}}
double f(double a, double b, double c, double d) {
        double r88832 = a;
        double r88833 = c;
        double r88834 = r88832 * r88833;
        double r88835 = b;
        double r88836 = d;
        double r88837 = r88835 * r88836;
        double r88838 = r88834 + r88837;
        double r88839 = r88833 * r88833;
        double r88840 = r88836 * r88836;
        double r88841 = r88839 + r88840;
        double r88842 = r88838 / r88841;
        return r88842;
}

double f(double a, double b, double c, double d) {
        double r88843 = 1.0;
        double r88844 = c;
        double r88845 = r88844 * r88844;
        double r88846 = d;
        double r88847 = r88846 * r88846;
        double r88848 = r88845 + r88847;
        double r88849 = sqrt(r88848);
        double r88850 = b;
        double r88851 = r88846 * r88850;
        double r88852 = a;
        double r88853 = r88844 * r88852;
        double r88854 = r88851 + r88853;
        double r88855 = r88849 / r88854;
        double r88856 = r88843 / r88855;
        double r88857 = r88856 / r88849;
        return r88857;
}

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. Simplified25.8

    \[\leadsto \color{blue}{\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d}}\]
  3. Using strategy rm
  4. Applied add-sqr-sqrt25.8

    \[\leadsto \frac{b \cdot d + a \cdot c}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
  5. Applied associate-/r*25.7

    \[\leadsto \color{blue}{\frac{\frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
  6. Simplified25.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}}\]
  7. Using strategy rm
  8. Applied clear-num25.8

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

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

Reproduce

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