Average Error: 26.0 → 26.2
Time: 11.6s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le 2.1596338989920688 \cdot 10^{+44}:\\ \;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \le 2.1596338989920688 \cdot 10^{+44}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\\

\end{array}
double f(double a, double b, double c, double d) {
        double r3977566 = b;
        double r3977567 = c;
        double r3977568 = r3977566 * r3977567;
        double r3977569 = a;
        double r3977570 = d;
        double r3977571 = r3977569 * r3977570;
        double r3977572 = r3977568 - r3977571;
        double r3977573 = r3977567 * r3977567;
        double r3977574 = r3977570 * r3977570;
        double r3977575 = r3977573 + r3977574;
        double r3977576 = r3977572 / r3977575;
        return r3977576;
}

double f(double a, double b, double c, double d) {
        double r3977577 = c;
        double r3977578 = 2.1596338989920688e+44;
        bool r3977579 = r3977577 <= r3977578;
        double r3977580 = b;
        double r3977581 = r3977580 * r3977577;
        double r3977582 = a;
        double r3977583 = d;
        double r3977584 = r3977582 * r3977583;
        double r3977585 = r3977581 - r3977584;
        double r3977586 = r3977577 * r3977577;
        double r3977587 = fma(r3977583, r3977583, r3977586);
        double r3977588 = sqrt(r3977587);
        double r3977589 = r3977585 / r3977588;
        double r3977590 = r3977589 / r3977588;
        double r3977591 = r3977580 / r3977588;
        double r3977592 = r3977579 ? r3977590 : r3977591;
        return r3977592;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

Original26.0
Target0.4
Herbie26.2
\[\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. Split input into 2 regimes
  2. if c < 2.1596338989920688e+44

    1. Initial program 23.3

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified23.3

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

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot \sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    5. Applied associate-/r*23.2

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    6. Taylor expanded around -inf 23.2

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

    if 2.1596338989920688e+44 < c

    1. Initial program 35.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified35.6

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

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot \sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    5. Applied associate-/r*35.5

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    6. Taylor expanded around inf 36.3

      \[\leadsto \frac{\color{blue}{b}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification26.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le 2.1596338989920688 \cdot 10^{+44}:\\ \;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\\ \end{array}\]

Reproduce

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