Average Error: 26.2 → 26.5
Time: 33.3s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le 6.467777198430207 \cdot 10^{+42}:\\ \;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\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}\;c \le 6.467777198430207 \cdot 10^{+42}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\

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

\end{array}
double f(double a, double b, double c, double d) {
        double r45917734 = b;
        double r45917735 = c;
        double r45917736 = r45917734 * r45917735;
        double r45917737 = a;
        double r45917738 = d;
        double r45917739 = r45917737 * r45917738;
        double r45917740 = r45917736 - r45917739;
        double r45917741 = r45917735 * r45917735;
        double r45917742 = r45917738 * r45917738;
        double r45917743 = r45917741 + r45917742;
        double r45917744 = r45917740 / r45917743;
        return r45917744;
}

double f(double a, double b, double c, double d) {
        double r45917745 = c;
        double r45917746 = 6.467777198430207e+42;
        bool r45917747 = r45917745 <= r45917746;
        double r45917748 = b;
        double r45917749 = r45917748 * r45917745;
        double r45917750 = a;
        double r45917751 = d;
        double r45917752 = r45917750 * r45917751;
        double r45917753 = r45917749 - r45917752;
        double r45917754 = r45917751 * r45917751;
        double r45917755 = r45917745 * r45917745;
        double r45917756 = r45917754 + r45917755;
        double r45917757 = sqrt(r45917756);
        double r45917758 = r45917753 / r45917757;
        double r45917759 = r45917758 / r45917757;
        double r45917760 = r45917748 / r45917757;
        double r45917761 = r45917747 ? r45917759 : r45917760;
        return r45917761;
}

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.2
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 2 regimes
  2. if c < 6.467777198430207e+42

    1. Initial program 23.7

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

      \[\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 6.467777198430207e+42 < c

    1. Initial program 34.3

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

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

      \[\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-inv34.3

      \[\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 inf 35.8

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

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

Reproduce

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