Average Error: 26.1 → 25.3
Time: 3.6s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} = -\infty:\\ \;\;\;\;\frac{-1 \cdot b}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \le 6.3661068469165699 \cdot 10^{269}:\\ \;\;\;\;\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} = -\infty:\\
\;\;\;\;\frac{-1 \cdot b}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{elif}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \le 6.3661068469165699 \cdot 10^{269}:\\
\;\;\;\;\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\

\end{array}
double f(double a, double b, double c, double d) {
        double r113983 = b;
        double r113984 = c;
        double r113985 = r113983 * r113984;
        double r113986 = a;
        double r113987 = d;
        double r113988 = r113986 * r113987;
        double r113989 = r113985 - r113988;
        double r113990 = r113984 * r113984;
        double r113991 = r113987 * r113987;
        double r113992 = r113990 + r113991;
        double r113993 = r113989 / r113992;
        return r113993;
}

double f(double a, double b, double c, double d) {
        double r113994 = b;
        double r113995 = c;
        double r113996 = r113994 * r113995;
        double r113997 = a;
        double r113998 = d;
        double r113999 = r113997 * r113998;
        double r114000 = r113996 - r113999;
        double r114001 = r113995 * r113995;
        double r114002 = r113998 * r113998;
        double r114003 = r114001 + r114002;
        double r114004 = r114000 / r114003;
        double r114005 = -inf.0;
        bool r114006 = r114004 <= r114005;
        double r114007 = -1.0;
        double r114008 = r114007 * r113994;
        double r114009 = sqrt(r114003);
        double r114010 = r114008 / r114009;
        double r114011 = 6.36610684691657e+269;
        bool r114012 = r114004 <= r114011;
        double r114013 = 1.0;
        double r114014 = r114013 / r114009;
        double r114015 = r114000 / r114009;
        double r114016 = r114014 * r114015;
        double r114017 = r113994 / r114009;
        double r114018 = r114012 ? r114016 : r114017;
        double r114019 = r114006 ? r114010 : r114018;
        return r114019;
}

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.1
Target0.5
Herbie25.3
\[\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 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) < -inf.0

    1. Initial program 64.0

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

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

      \[\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. Taylor expanded around -inf 51.9

      \[\leadsto \frac{\color{blue}{-1 \cdot b}}{\sqrt{c \cdot c + d \cdot d}}\]

    if -inf.0 < (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) < 6.36610684691657e+269

    1. Initial program 12.0

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied clear-num12.1

      \[\leadsto \color{blue}{\frac{1}{\frac{c \cdot c + d \cdot d}{b \cdot c - a \cdot d}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity12.1

      \[\leadsto \frac{1}{\frac{c \cdot c + d \cdot d}{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}}\]
    6. Applied add-sqr-sqrt12.1

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}{1 \cdot \left(b \cdot c - a \cdot d\right)}}\]
    7. Applied times-frac12.1

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{c \cdot c + d \cdot d}}{1} \cdot \frac{\sqrt{c \cdot c + d \cdot d}}{b \cdot c - a \cdot d}}}\]
    8. Applied add-cube-cbrt12.1

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{\sqrt{c \cdot c + d \cdot d}}{1} \cdot \frac{\sqrt{c \cdot c + d \cdot d}}{b \cdot c - a \cdot d}}\]
    9. Applied times-frac12.1

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{\sqrt{c \cdot c + d \cdot d}}{1}} \cdot \frac{\sqrt[3]{1}}{\frac{\sqrt{c \cdot c + d \cdot d}}{b \cdot c - a \cdot d}}}\]
    10. Simplified12.1

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}}} \cdot \frac{\sqrt[3]{1}}{\frac{\sqrt{c \cdot c + d \cdot d}}{b \cdot c - a \cdot d}}\]
    11. Simplified12.0

      \[\leadsto \frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \color{blue}{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]

    if 6.36610684691657e+269 < (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))

    1. Initial program 61.5

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt61.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*61.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. Taylor expanded around inf 59.8

      \[\leadsto \frac{\color{blue}{b}}{\sqrt{c \cdot c + d \cdot d}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification25.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} = -\infty:\\ \;\;\;\;\frac{-1 \cdot b}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \le 6.3661068469165699 \cdot 10^{269}:\\ \;\;\;\;\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020018 
(FPCore (a b c d)
  :name "Complex division, imag part"
  :precision binary64

  :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))))