Average Error: 25.4 → 25.5
Time: 44.4s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{1}{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)} \cdot \left(b \cdot c - a \cdot d\right)\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{1}{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)} \cdot \left(b \cdot c - a \cdot d\right)
double f(double a, double b, double c, double d) {
        double r24776768 = b;
        double r24776769 = c;
        double r24776770 = r24776768 * r24776769;
        double r24776771 = a;
        double r24776772 = d;
        double r24776773 = r24776771 * r24776772;
        double r24776774 = r24776770 - r24776773;
        double r24776775 = r24776769 * r24776769;
        double r24776776 = r24776772 * r24776772;
        double r24776777 = r24776775 + r24776776;
        double r24776778 = r24776774 / r24776777;
        return r24776778;
}

double f(double a, double b, double c, double d) {
        double r24776779 = 1.0;
        double r24776780 = d;
        double r24776781 = c;
        double r24776782 = r24776781 * r24776781;
        double r24776783 = fma(r24776780, r24776780, r24776782);
        double r24776784 = r24776779 / r24776783;
        double r24776785 = b;
        double r24776786 = r24776785 * r24776781;
        double r24776787 = a;
        double r24776788 = r24776787 * r24776780;
        double r24776789 = r24776786 - r24776788;
        double r24776790 = r24776784 * r24776789;
        return r24776790;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

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

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
  2. Simplified25.4

    \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}}\]
  3. Using strategy rm
  4. Applied div-inv25.5

    \[\leadsto \color{blue}{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}}\]
  5. Final simplification25.5

    \[\leadsto \frac{1}{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)} \cdot \left(b \cdot c - a \cdot d\right)\]

Reproduce

herbie shell --seed 2019125 +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))))