Average Error: 27.0 → 26.9
Time: 14.8s
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 r4689633 = b;
        double r4689634 = c;
        double r4689635 = r4689633 * r4689634;
        double r4689636 = a;
        double r4689637 = d;
        double r4689638 = r4689636 * r4689637;
        double r4689639 = r4689635 - r4689638;
        double r4689640 = r4689634 * r4689634;
        double r4689641 = r4689637 * r4689637;
        double r4689642 = r4689640 + r4689641;
        double r4689643 = r4689639 / r4689642;
        return r4689643;
}

double f(double a, double b, double c, double d) {
        double r4689644 = b;
        double r4689645 = c;
        double r4689646 = r4689644 * r4689645;
        double r4689647 = a;
        double r4689648 = d;
        double r4689649 = r4689647 * r4689648;
        double r4689650 = r4689646 - r4689649;
        double r4689651 = r4689645 * r4689645;
        double r4689652 = r4689648 * r4689648;
        double r4689653 = r4689651 + r4689652;
        double r4689654 = sqrt(r4689653);
        double r4689655 = r4689650 / r4689654;
        double r4689656 = r4689655 / r4689654;
        return r4689656;
}

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

Original27.0
Target0.4
Herbie26.9
\[\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 27.0

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

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

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

    \[\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 2019171 +o rules:numerics
(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))))