Average Error: 25.6 → 25.5
Time: 2.4m
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 r25570490 = b;
        double r25570491 = c;
        double r25570492 = r25570490 * r25570491;
        double r25570493 = a;
        double r25570494 = d;
        double r25570495 = r25570493 * r25570494;
        double r25570496 = r25570492 - r25570495;
        double r25570497 = r25570491 * r25570491;
        double r25570498 = r25570494 * r25570494;
        double r25570499 = r25570497 + r25570498;
        double r25570500 = r25570496 / r25570499;
        return r25570500;
}

double f(double a, double b, double c, double d) {
        double r25570501 = b;
        double r25570502 = c;
        double r25570503 = r25570501 * r25570502;
        double r25570504 = a;
        double r25570505 = d;
        double r25570506 = r25570504 * r25570505;
        double r25570507 = r25570503 - r25570506;
        double r25570508 = r25570502 * r25570502;
        double r25570509 = r25570505 * r25570505;
        double r25570510 = r25570508 + r25570509;
        double r25570511 = sqrt(r25570510);
        double r25570512 = r25570507 / r25570511;
        double r25570513 = r25570512 / r25570511;
        return r25570513;
}

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