Average Error: 25.7 → 17.3
Time: 14.2s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -8.222702384414015 \cdot 10^{+149}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \le 2.1496090707043887 \cdot 10^{+133}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \le -8.222702384414015 \cdot 10^{+149}:\\
\;\;\;\;\frac{b}{c}\\

\mathbf{elif}\;c \le 2.1496090707043887 \cdot 10^{+133}:\\
\;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\

\end{array}
double f(double a, double b, double c, double d) {
        double r4837913 = b;
        double r4837914 = c;
        double r4837915 = r4837913 * r4837914;
        double r4837916 = a;
        double r4837917 = d;
        double r4837918 = r4837916 * r4837917;
        double r4837919 = r4837915 - r4837918;
        double r4837920 = r4837914 * r4837914;
        double r4837921 = r4837917 * r4837917;
        double r4837922 = r4837920 + r4837921;
        double r4837923 = r4837919 / r4837922;
        return r4837923;
}

double f(double a, double b, double c, double d) {
        double r4837924 = c;
        double r4837925 = -8.222702384414015e+149;
        bool r4837926 = r4837924 <= r4837925;
        double r4837927 = b;
        double r4837928 = r4837927 / r4837924;
        double r4837929 = 2.1496090707043887e+133;
        bool r4837930 = r4837924 <= r4837929;
        double r4837931 = r4837927 * r4837924;
        double r4837932 = d;
        double r4837933 = a;
        double r4837934 = r4837932 * r4837933;
        double r4837935 = r4837931 - r4837934;
        double r4837936 = r4837924 * r4837924;
        double r4837937 = r4837932 * r4837932;
        double r4837938 = r4837936 + r4837937;
        double r4837939 = sqrt(r4837938);
        double r4837940 = r4837935 / r4837939;
        double r4837941 = r4837940 / r4837939;
        double r4837942 = r4837930 ? r4837941 : r4837928;
        double r4837943 = r4837926 ? r4837928 : r4837942;
        return r4837943;
}

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.7
Target0.4
Herbie17.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 2 regimes
  2. if c < -8.222702384414015e+149 or 2.1496090707043887e+133 < c

    1. Initial program 42.8

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

      \[\leadsto \frac{\color{blue}{b}}{\sqrt{c \cdot c + d \cdot d}}\]
    6. Taylor expanded around inf 14.1

      \[\leadsto \frac{b}{\color{blue}{c}}\]

    if -8.222702384414015e+149 < c < 2.1496090707043887e+133

    1. Initial program 18.7

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

      \[\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}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification17.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -8.222702384414015 \cdot 10^{+149}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \le 2.1496090707043887 \cdot 10^{+133}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array}\]

Reproduce

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