Average Error: 26.0 → 13.0
Time: 8.9s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -6.603705426560988 \cdot 10^{+145}:\\ \;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \le 7.75132925369235 \cdot 10^{+139}:\\ \;\;\;\;\frac{\left(b \cdot c - d \cdot a\right) \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \le -6.603705426560988 \cdot 10^{+145}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\

\mathbf{elif}\;c \le 7.75132925369235 \cdot 10^{+139}:\\
\;\;\;\;\frac{\left(b \cdot c - d \cdot a\right) \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(d, c\right)}\\

\end{array}
double f(double a, double b, double c, double d) {
        double r1750462 = b;
        double r1750463 = c;
        double r1750464 = r1750462 * r1750463;
        double r1750465 = a;
        double r1750466 = d;
        double r1750467 = r1750465 * r1750466;
        double r1750468 = r1750464 - r1750467;
        double r1750469 = r1750463 * r1750463;
        double r1750470 = r1750466 * r1750466;
        double r1750471 = r1750469 + r1750470;
        double r1750472 = r1750468 / r1750471;
        return r1750472;
}

double f(double a, double b, double c, double d) {
        double r1750473 = c;
        double r1750474 = -6.603705426560988e+145;
        bool r1750475 = r1750473 <= r1750474;
        double r1750476 = b;
        double r1750477 = -r1750476;
        double r1750478 = d;
        double r1750479 = hypot(r1750478, r1750473);
        double r1750480 = r1750477 / r1750479;
        double r1750481 = 7.75132925369235e+139;
        bool r1750482 = r1750473 <= r1750481;
        double r1750483 = r1750476 * r1750473;
        double r1750484 = a;
        double r1750485 = r1750478 * r1750484;
        double r1750486 = r1750483 - r1750485;
        double r1750487 = 1.0;
        double r1750488 = r1750487 / r1750479;
        double r1750489 = r1750486 * r1750488;
        double r1750490 = r1750489 / r1750479;
        double r1750491 = r1750476 / r1750479;
        double r1750492 = r1750482 ? r1750490 : r1750491;
        double r1750493 = r1750475 ? r1750480 : r1750492;
        return r1750493;
}

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
Herbie13.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 3 regimes
  2. if c < -6.603705426560988e+145

    1. Initial program 43.7

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified43.7

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt43.7

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot \sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    5. Applied associate-/r*43.7

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    6. Using strategy rm
    7. Applied fma-udef43.7

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}\]
    8. Applied hypot-def43.7

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\color{blue}{\mathsf{hypot}\left(d, c\right)}}\]
    9. Taylor expanded around -inf 14.1

      \[\leadsto \frac{\color{blue}{-1 \cdot b}}{\mathsf{hypot}\left(d, c\right)}\]
    10. Simplified14.1

      \[\leadsto \frac{\color{blue}{-b}}{\mathsf{hypot}\left(d, c\right)}\]

    if -6.603705426560988e+145 < c < 7.75132925369235e+139

    1. Initial program 19.0

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified19.0

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt19.0

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot \sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    5. Applied associate-/r*19.0

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    6. Using strategy rm
    7. Applied fma-udef19.0

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}\]
    8. Applied hypot-def18.9

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\color{blue}{\mathsf{hypot}\left(d, c\right)}}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity18.9

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\color{blue}{1 \cdot \mathsf{hypot}\left(d, c\right)}}\]
    11. Applied associate-/r*18.9

      \[\leadsto \color{blue}{\frac{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{1}}{\mathsf{hypot}\left(d, c\right)}}\]
    12. Simplified12.3

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}}{\mathsf{hypot}\left(d, c\right)}\]
    13. Using strategy rm
    14. Applied div-inv12.4

      \[\leadsto \frac{\color{blue}{\left(c \cdot b - d \cdot a\right) \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}}}{\mathsf{hypot}\left(d, c\right)}\]

    if 7.75132925369235e+139 < c

    1. Initial program 42.9

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified42.9

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt42.9

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot \sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    5. Applied associate-/r*42.9

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    6. Using strategy rm
    7. Applied fma-udef42.9

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}\]
    8. Applied hypot-def42.9

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\color{blue}{\mathsf{hypot}\left(d, c\right)}}\]
    9. Taylor expanded around inf 15.2

      \[\leadsto \frac{\color{blue}{b}}{\mathsf{hypot}\left(d, c\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -6.603705426560988 \cdot 10^{+145}:\\ \;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \le 7.75132925369235 \cdot 10^{+139}:\\ \;\;\;\;\frac{\left(b \cdot c - d \cdot a\right) \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2019156 +o rules:numerics
(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))))