Average Error: 26.0 → 12.8
Time: 56.1s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -1.01458341645274 \cdot 10^{+165}:\\ \;\;\;\;\frac{-b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \le 2.0408764461888536 \cdot 10^{+156}:\\ \;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{b \cdot c - a \cdot d}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \le -1.01458341645274 \cdot 10^{+165}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \le 2.0408764461888536 \cdot 10^{+156}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{b \cdot c - a \cdot d}}}{\mathsf{hypot}\left(c, d\right)}\\

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

\end{array}
double f(double a, double b, double c, double d) {
        double r27106636 = b;
        double r27106637 = c;
        double r27106638 = r27106636 * r27106637;
        double r27106639 = a;
        double r27106640 = d;
        double r27106641 = r27106639 * r27106640;
        double r27106642 = r27106638 - r27106641;
        double r27106643 = r27106637 * r27106637;
        double r27106644 = r27106640 * r27106640;
        double r27106645 = r27106643 + r27106644;
        double r27106646 = r27106642 / r27106645;
        return r27106646;
}

double f(double a, double b, double c, double d) {
        double r27106647 = c;
        double r27106648 = -1.01458341645274e+165;
        bool r27106649 = r27106647 <= r27106648;
        double r27106650 = b;
        double r27106651 = -r27106650;
        double r27106652 = d;
        double r27106653 = hypot(r27106647, r27106652);
        double r27106654 = r27106651 / r27106653;
        double r27106655 = 2.0408764461888536e+156;
        bool r27106656 = r27106647 <= r27106655;
        double r27106657 = 1.0;
        double r27106658 = r27106650 * r27106647;
        double r27106659 = a;
        double r27106660 = r27106659 * r27106652;
        double r27106661 = r27106658 - r27106660;
        double r27106662 = r27106653 / r27106661;
        double r27106663 = r27106657 / r27106662;
        double r27106664 = r27106663 / r27106653;
        double r27106665 = r27106650 / r27106653;
        double r27106666 = r27106656 ? r27106664 : r27106665;
        double r27106667 = r27106649 ? r27106654 : r27106666;
        return r27106667;
}

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

Original26.0
Target0.4
Herbie12.8
\[\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 3 regimes
  2. if c < -1.01458341645274e+165

    1. Initial program 44.3

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

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

      \[\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 fma-neg44.3

      \[\leadsto \frac{\frac{\color{blue}{\mathsf{fma}\left(b, c, \left(-a \cdot d\right)\right)}}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Using strategy rm
    8. Applied hypot-def44.3

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

      \[\leadsto \frac{\color{blue}{-1 \cdot b}}{\mathsf{hypot}\left(c, d\right)}\]
    10. Simplified12.7

      \[\leadsto \frac{\color{blue}{-b}}{\mathsf{hypot}\left(c, d\right)}\]

    if -1.01458341645274e+165 < c < 2.0408764461888536e+156

    1. Initial program 19.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt19.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*19.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 fma-neg19.5

      \[\leadsto \frac{\frac{\color{blue}{\mathsf{fma}\left(b, c, \left(-a \cdot d\right)\right)}}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Using strategy rm
    8. Applied hypot-def19.5

      \[\leadsto \frac{\frac{\mathsf{fma}\left(b, c, \left(-a \cdot d\right)\right)}{\sqrt{c \cdot c + d \cdot d}}}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity19.5

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \mathsf{fma}\left(b, c, \left(-a \cdot d\right)\right)}}{\sqrt{c \cdot c + d \cdot d}}}{\mathsf{hypot}\left(c, d\right)}\]
    11. Applied associate-/l*19.6

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{\mathsf{fma}\left(b, c, \left(-a \cdot d\right)\right)}}}}{\mathsf{hypot}\left(c, d\right)}\]
    12. Simplified12.6

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

    if 2.0408764461888536e+156 < c

    1. Initial program 44.7

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

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

      \[\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 fma-neg44.7

      \[\leadsto \frac{\frac{\color{blue}{\mathsf{fma}\left(b, c, \left(-a \cdot d\right)\right)}}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Using strategy rm
    8. Applied hypot-def44.7

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

      \[\leadsto \frac{\color{blue}{b}}{\mathsf{hypot}\left(c, d\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification12.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -1.01458341645274 \cdot 10^{+165}:\\ \;\;\;\;\frac{-b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \le 2.0408764461888536 \cdot 10^{+156}:\\ \;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{b \cdot c - a \cdot d}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \end{array}\]

Reproduce

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