Average Error: 26.3 → 26.3
Time: 14.0s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le 1.937670017341036534919481795915749319496 \cdot 10^{62}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{d \cdot d + c \cdot c}} \cdot \left(b \cdot c - d \cdot a\right)}{\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 1.937670017341036534919481795915749319496 \cdot 10^{62}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{d \cdot d + c \cdot c}} \cdot \left(b \cdot c - d \cdot a\right)}{\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 r6362476 = b;
        double r6362477 = c;
        double r6362478 = r6362476 * r6362477;
        double r6362479 = a;
        double r6362480 = d;
        double r6362481 = r6362479 * r6362480;
        double r6362482 = r6362478 - r6362481;
        double r6362483 = r6362477 * r6362477;
        double r6362484 = r6362480 * r6362480;
        double r6362485 = r6362483 + r6362484;
        double r6362486 = r6362482 / r6362485;
        return r6362486;
}

double f(double a, double b, double c, double d) {
        double r6362487 = d;
        double r6362488 = 1.9376700173410365e+62;
        bool r6362489 = r6362487 <= r6362488;
        double r6362490 = 1.0;
        double r6362491 = r6362487 * r6362487;
        double r6362492 = c;
        double r6362493 = r6362492 * r6362492;
        double r6362494 = r6362491 + r6362493;
        double r6362495 = sqrt(r6362494);
        double r6362496 = r6362490 / r6362495;
        double r6362497 = b;
        double r6362498 = r6362497 * r6362492;
        double r6362499 = a;
        double r6362500 = r6362487 * r6362499;
        double r6362501 = r6362498 - r6362500;
        double r6362502 = r6362496 * r6362501;
        double r6362503 = r6362502 / r6362495;
        double r6362504 = -r6362499;
        double r6362505 = r6362504 / r6362495;
        double r6362506 = r6362489 ? r6362503 : r6362505;
        return r6362506;
}

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.3
Target0.5
Herbie26.3
\[\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 < 1.9376700173410365e+62

    1. Initial program 23.4

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

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

    if 1.9376700173410365e+62 < d

    1. Initial program 37.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \le 1.937670017341036534919481795915749319496 \cdot 10^{62}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{d \cdot d + c \cdot c}} \cdot \left(b \cdot c - d \cdot a\right)}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\sqrt{d \cdot d + c \cdot c}}\\ \end{array}\]

Reproduce

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