Average Error: 26.1 → 26.0
Time: 26.2s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le 7.672387965946080977078573905755541784636 \cdot 10^{87}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{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 7.672387965946080977078573905755541784636 \cdot 10^{87}:\\
\;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{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 r7012386 = b;
        double r7012387 = c;
        double r7012388 = r7012386 * r7012387;
        double r7012389 = a;
        double r7012390 = d;
        double r7012391 = r7012389 * r7012390;
        double r7012392 = r7012388 - r7012391;
        double r7012393 = r7012387 * r7012387;
        double r7012394 = r7012390 * r7012390;
        double r7012395 = r7012393 + r7012394;
        double r7012396 = r7012392 / r7012395;
        return r7012396;
}

double f(double a, double b, double c, double d) {
        double r7012397 = d;
        double r7012398 = 7.672387965946081e+87;
        bool r7012399 = r7012397 <= r7012398;
        double r7012400 = b;
        double r7012401 = c;
        double r7012402 = r7012400 * r7012401;
        double r7012403 = a;
        double r7012404 = r7012397 * r7012403;
        double r7012405 = r7012402 - r7012404;
        double r7012406 = r7012397 * r7012397;
        double r7012407 = r7012401 * r7012401;
        double r7012408 = r7012406 + r7012407;
        double r7012409 = sqrt(r7012408);
        double r7012410 = r7012405 / r7012409;
        double r7012411 = r7012410 / r7012409;
        double r7012412 = -r7012403;
        double r7012413 = r7012412 / r7012409;
        double r7012414 = r7012399 ? r7012411 : r7012413;
        return r7012414;
}

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.4
Herbie26.0
\[\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 < 7.672387965946081e+87

    1. Initial program 23.1

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

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

    if 7.672387965946081e+87 < d

    1. Initial program 38.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \le 7.672387965946080977078573905755541784636 \cdot 10^{87}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\sqrt{d \cdot d + c \cdot 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))))