Average Error: 25.6 → 25.5
Time: 2.2m
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 r26293365 = b;
        double r26293366 = c;
        double r26293367 = r26293365 * r26293366;
        double r26293368 = a;
        double r26293369 = d;
        double r26293370 = r26293368 * r26293369;
        double r26293371 = r26293367 - r26293370;
        double r26293372 = r26293366 * r26293366;
        double r26293373 = r26293369 * r26293369;
        double r26293374 = r26293372 + r26293373;
        double r26293375 = r26293371 / r26293374;
        return r26293375;
}

double f(double a, double b, double c, double d) {
        double r26293376 = b;
        double r26293377 = c;
        double r26293378 = r26293376 * r26293377;
        double r26293379 = a;
        double r26293380 = d;
        double r26293381 = r26293379 * r26293380;
        double r26293382 = r26293378 - r26293381;
        double r26293383 = r26293377 * r26293377;
        double r26293384 = r26293380 * r26293380;
        double r26293385 = r26293383 + r26293384;
        double r26293386 = sqrt(r26293385);
        double r26293387 = r26293382 / r26293386;
        double r26293388 = r26293387 / r26293386;
        return r26293388;
}

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.6
Target0.6
Herbie25.5
\[\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 25.6

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

    \[\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*25.5

    \[\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. Using strategy rm
  6. Applied *-un-lft-identity25.5

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

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

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