Average Error: 25.5 → 25.5
Time: 41.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}}\]
double f(double a, double b, double c, double d) {
        double r13065456 = b;
        double r13065457 = c;
        double r13065458 = r13065456 * r13065457;
        double r13065459 = a;
        double r13065460 = d;
        double r13065461 = r13065459 * r13065460;
        double r13065462 = r13065458 - r13065461;
        double r13065463 = r13065457 * r13065457;
        double r13065464 = r13065460 * r13065460;
        double r13065465 = r13065463 + r13065464;
        double r13065466 = r13065462 / r13065465;
        return r13065466;
}

double f(double a, double b, double c, double d) {
        double r13065467 = b;
        double r13065468 = c;
        double r13065469 = r13065467 * r13065468;
        double r13065470 = a;
        double r13065471 = d;
        double r13065472 = r13065470 * r13065471;
        double r13065473 = r13065469 - r13065472;
        double r13065474 = r13065468 * r13065468;
        double r13065475 = r13065471 * r13065471;
        double r13065476 = r13065474 + r13065475;
        double r13065477 = sqrt(r13065476);
        double r13065478 = r13065473 / r13065477;
        double r13065479 = r13065478 / r13065477;
        return r13065479;
}

\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}}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

Original25.5
Target0.4
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.5

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

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