Average Error: 26.1 → 26.0
Time: 13.0s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{b \cdot c - a \cdot d}{\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 r5290659 = b;
        double r5290660 = c;
        double r5290661 = r5290659 * r5290660;
        double r5290662 = a;
        double r5290663 = d;
        double r5290664 = r5290662 * r5290663;
        double r5290665 = r5290661 - r5290664;
        double r5290666 = r5290660 * r5290660;
        double r5290667 = r5290663 * r5290663;
        double r5290668 = r5290666 + r5290667;
        double r5290669 = r5290665 / r5290668;
        return r5290669;
}

double f(double a, double b, double c, double d) {
        double r5290670 = b;
        double r5290671 = c;
        double r5290672 = r5290670 * r5290671;
        double r5290673 = a;
        double r5290674 = d;
        double r5290675 = r5290673 * r5290674;
        double r5290676 = r5290672 - r5290675;
        double r5290677 = r5290671 * r5290671;
        double r5290678 = r5290674 * r5290674;
        double r5290679 = r5290677 + r5290678;
        double r5290680 = sqrt(r5290679);
        double r5290681 = r5290676 / r5290680;
        double r5290682 = r5290681 / r5290680;
        return r5290682;
}

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.1
Target0.4
Herbie26.0
\[\begin{array}{l} \mathbf{if}\;\left|d\right| \lt \left|c\right|:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array}\]

Derivation

  1. Initial program 26.1

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

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

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

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

Reproduce

herbie shell --seed 2019163 
(FPCore (a b c d)
  :name "Complex division, imag part"

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))

  (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))