Average Error: 26.3 → 26.3
Time: 3.9s
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 r119624 = b;
        double r119625 = c;
        double r119626 = r119624 * r119625;
        double r119627 = a;
        double r119628 = d;
        double r119629 = r119627 * r119628;
        double r119630 = r119626 - r119629;
        double r119631 = r119625 * r119625;
        double r119632 = r119628 * r119628;
        double r119633 = r119631 + r119632;
        double r119634 = r119630 / r119633;
        return r119634;
}

double f(double a, double b, double c, double d) {
        double r119635 = b;
        double r119636 = c;
        double r119637 = r119635 * r119636;
        double r119638 = a;
        double r119639 = d;
        double r119640 = r119638 * r119639;
        double r119641 = r119637 - r119640;
        double r119642 = r119636 * r119636;
        double r119643 = r119639 * r119639;
        double r119644 = r119642 + r119643;
        double r119645 = sqrt(r119644);
        double r119646 = r119641 / r119645;
        double r119647 = r119646 / r119645;
        return r119647;
}

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

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

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

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

    \[\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 2020083 
(FPCore (a b c d)
  :name "Complex division, imag part"
  :precision binary64

  :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))))