Average Error: 26.0 → 12.8
Time: 10.5s
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 r2045783 = b;
        double r2045784 = c;
        double r2045785 = r2045783 * r2045784;
        double r2045786 = a;
        double r2045787 = d;
        double r2045788 = r2045786 * r2045787;
        double r2045789 = r2045785 - r2045788;
        double r2045790 = r2045784 * r2045784;
        double r2045791 = r2045787 * r2045787;
        double r2045792 = r2045790 + r2045791;
        double r2045793 = r2045789 / r2045792;
        return r2045793;
}

double f(double a, double b, double c, double d) {
        double r2045794 = c;
        double r2045795 = -1.01458341645274e+165;
        bool r2045796 = r2045794 <= r2045795;
        double r2045797 = b;
        double r2045798 = -r2045797;
        double r2045799 = d;
        double r2045800 = hypot(r2045794, r2045799);
        double r2045801 = r2045798 / r2045800;
        double r2045802 = 2.0408764461888536e+156;
        bool r2045803 = r2045794 <= r2045802;
        double r2045804 = 1.0;
        double r2045805 = r2045797 * r2045794;
        double r2045806 = a;
        double r2045807 = r2045806 * r2045799;
        double r2045808 = r2045805 - r2045807;
        double r2045809 = r2045800 / r2045808;
        double r2045810 = r2045804 / r2045809;
        double r2045811 = r2045810 / r2045800;
        double r2045812 = r2045797 / r2045800;
        double r2045813 = r2045803 ? r2045811 : r2045812;
        double r2045814 = r2045796 ? r2045801 : r2045813;
        return r2045814;
}

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 clear-num19.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)}\]
    11. Simplified12.6

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(c, d\right)}{c \cdot b - d \cdot a}}}}{\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))))