Average Error: 25.4 → 25.2
Time: 12.0s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le 3.241508515477217 \cdot 10^{+87}:\\ \;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\sqrt{d \cdot d + c \cdot c}}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \le 3.241508515477217 \cdot 10^{+87}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d + c \cdot c}\\

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

\end{array}
double f(double a, double b, double c, double d) {
        double r4578836 = b;
        double r4578837 = c;
        double r4578838 = r4578836 * r4578837;
        double r4578839 = a;
        double r4578840 = d;
        double r4578841 = r4578839 * r4578840;
        double r4578842 = r4578838 - r4578841;
        double r4578843 = r4578837 * r4578837;
        double r4578844 = r4578840 * r4578840;
        double r4578845 = r4578843 + r4578844;
        double r4578846 = r4578842 / r4578845;
        return r4578846;
}

double f(double a, double b, double c, double d) {
        double r4578847 = d;
        double r4578848 = 3.241508515477217e+87;
        bool r4578849 = r4578847 <= r4578848;
        double r4578850 = b;
        double r4578851 = c;
        double r4578852 = r4578850 * r4578851;
        double r4578853 = a;
        double r4578854 = r4578847 * r4578853;
        double r4578855 = r4578852 - r4578854;
        double r4578856 = r4578847 * r4578847;
        double r4578857 = r4578851 * r4578851;
        double r4578858 = r4578856 + r4578857;
        double r4578859 = r4578855 / r4578858;
        double r4578860 = -r4578853;
        double r4578861 = sqrt(r4578858);
        double r4578862 = r4578860 / r4578861;
        double r4578863 = r4578849 ? r4578859 : r4578862;
        return r4578863;
}

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

Original25.4
Target0.5
Herbie25.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 d < 3.241508515477217e+87

    1. Initial program 22.5

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]

    if 3.241508515477217e+87 < d

    1. Initial program 37.8

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

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

      \[\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 div-inv37.8

      \[\leadsto \frac{\color{blue}{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Taylor expanded around 0 37.0

      \[\leadsto \frac{\color{blue}{-1 \cdot a}}{\sqrt{c \cdot c + d \cdot d}}\]
    8. Simplified37.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \le 3.241508515477217 \cdot 10^{+87}:\\ \;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\sqrt{d \cdot d + c \cdot c}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019132 
(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))))