Average Error: 26.0 → 26.2
Time: 11.2s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -1.2109434524169916 \cdot 10^{+96}:\\ \;\;\;\;-\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 -1.2109434524169916 \cdot 10^{+96}:\\
\;\;\;\;-\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 r4760582 = b;
        double r4760583 = c;
        double r4760584 = r4760582 * r4760583;
        double r4760585 = a;
        double r4760586 = d;
        double r4760587 = r4760585 * r4760586;
        double r4760588 = r4760584 - r4760587;
        double r4760589 = r4760583 * r4760583;
        double r4760590 = r4760586 * r4760586;
        double r4760591 = r4760589 + r4760590;
        double r4760592 = r4760588 / r4760591;
        return r4760592;
}

double f(double a, double b, double c, double d) {
        double r4760593 = c;
        double r4760594 = -1.2109434524169916e+96;
        bool r4760595 = r4760593 <= r4760594;
        double r4760596 = b;
        double r4760597 = r4760593 * r4760593;
        double r4760598 = d;
        double r4760599 = r4760598 * r4760598;
        double r4760600 = r4760597 + r4760599;
        double r4760601 = sqrt(r4760600);
        double r4760602 = r4760596 / r4760601;
        double r4760603 = -r4760602;
        double r4760604 = 5.2422713568197025e+36;
        bool r4760605 = r4760593 <= r4760604;
        double r4760606 = r4760596 * r4760593;
        double r4760607 = a;
        double r4760608 = r4760607 * r4760598;
        double r4760609 = r4760606 - r4760608;
        double r4760610 = r4760609 / r4760601;
        double r4760611 = r4760610 / r4760601;
        double r4760612 = r4760605 ? r4760611 : r4760602;
        double r4760613 = r4760595 ? r4760603 : r4760612;
        return r4760613;
}

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.0
Target0.5
Herbie26.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 3 regimes
  2. if c < -1.2109434524169916e+96

    1. Initial program 39.0

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

      \[\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.2

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

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

    if -1.2109434524169916e+96 < c < 5.2422713568197025e+36

    1. Initial program 18.5

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

      \[\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.4

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

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

      \[\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.4

      \[\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.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -1.2109434524169916 \cdot 10^{+96}:\\ \;\;\;\;-\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))))