Average Error: 26.5 → 26.5
Time: 23.8s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -7.846283352613039 \cdot 10^{+90}:\\ \;\;\;\;-\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;c \le 5.2422713568197025 \cdot 10^{+36}:\\ \;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \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}\;c \le -7.846283352613039 \cdot 10^{+90}:\\
\;\;\;\;-\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{elif}\;c \le 5.2422713568197025 \cdot 10^{+36}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \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 r5984230 = b;
        double r5984231 = c;
        double r5984232 = r5984230 * r5984231;
        double r5984233 = a;
        double r5984234 = d;
        double r5984235 = r5984233 * r5984234;
        double r5984236 = r5984232 - r5984235;
        double r5984237 = r5984231 * r5984231;
        double r5984238 = r5984234 * r5984234;
        double r5984239 = r5984237 + r5984238;
        double r5984240 = r5984236 / r5984239;
        return r5984240;
}

double f(double a, double b, double c, double d) {
        double r5984241 = c;
        double r5984242 = -7.846283352613039e+90;
        bool r5984243 = r5984241 <= r5984242;
        double r5984244 = b;
        double r5984245 = r5984241 * r5984241;
        double r5984246 = d;
        double r5984247 = r5984246 * r5984246;
        double r5984248 = r5984245 + r5984247;
        double r5984249 = sqrt(r5984248);
        double r5984250 = r5984244 / r5984249;
        double r5984251 = -r5984250;
        double r5984252 = 5.2422713568197025e+36;
        bool r5984253 = r5984241 <= r5984252;
        double r5984254 = r5984244 * r5984241;
        double r5984255 = a;
        double r5984256 = r5984255 * r5984246;
        double r5984257 = r5984254 - r5984256;
        double r5984258 = r5984257 / r5984249;
        double r5984259 = r5984258 / r5984249;
        double r5984260 = r5984253 ? r5984259 : r5984250;
        double r5984261 = r5984243 ? r5984251 : r5984260;
        return r5984261;
}

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.5
Target0.5
Herbie26.5
\[\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 < -7.846283352613039e+90

    1. Initial program 39.2

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

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

      \[\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 38.1

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

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

    if -7.846283352613039e+90 < c < 5.2422713568197025e+36

    1. Initial program 18.9

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

      \[\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.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}}}\]

    if 5.2422713568197025e+36 < c

    1. Initial program 35.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -7.846283352613039 \cdot 10^{+90}:\\ \;\;\;\;-\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;c \le 5.2422713568197025 \cdot 10^{+36}:\\ \;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \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 2019165 
(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))))