Average Error: 25.6 → 25.5
Time: 32.0s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le 6.443252805869156 \cdot 10^{+104}:\\ \;\;\;\;\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.443252805869156 \cdot 10^{+104}:\\
\;\;\;\;\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 r12491585 = b;
        double r12491586 = c;
        double r12491587 = r12491585 * r12491586;
        double r12491588 = a;
        double r12491589 = d;
        double r12491590 = r12491588 * r12491589;
        double r12491591 = r12491587 - r12491590;
        double r12491592 = r12491586 * r12491586;
        double r12491593 = r12491589 * r12491589;
        double r12491594 = r12491592 + r12491593;
        double r12491595 = r12491591 / r12491594;
        return r12491595;
}

double f(double a, double b, double c, double d) {
        double r12491596 = c;
        double r12491597 = 6.443252805869156e+104;
        bool r12491598 = r12491596 <= r12491597;
        double r12491599 = b;
        double r12491600 = r12491599 * r12491596;
        double r12491601 = a;
        double r12491602 = d;
        double r12491603 = r12491601 * r12491602;
        double r12491604 = r12491600 - r12491603;
        double r12491605 = r12491602 * r12491602;
        double r12491606 = r12491596 * r12491596;
        double r12491607 = r12491605 + r12491606;
        double r12491608 = sqrt(r12491607);
        double r12491609 = r12491604 / r12491608;
        double r12491610 = r12491609 / r12491608;
        double r12491611 = r12491599 / r12491608;
        double r12491612 = r12491598 ? r12491610 : r12491611;
        return r12491612;
}

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.6
Target0.4
Herbie25.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.443252805869156e+104

    1. Initial program 22.4

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

      \[\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*22.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 6.443252805869156e+104 < c

    1. Initial program 41.1

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

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

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