Average Error: 26.5 → 13.2
Time: 45.6s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -3.108106990901466 \cdot 10^{+219}:\\ \;\;\;\;-\frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \le 5.1185396129683884 \cdot 10^{+128}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\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 -3.108106990901466 \cdot 10^{+219}:\\
\;\;\;\;-\frac{b}{\mathsf{hypot}\left(d, c\right)}\\

\mathbf{elif}\;c \le 5.1185396129683884 \cdot 10^{+128}:\\
\;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\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 r15179506 = b;
        double r15179507 = c;
        double r15179508 = r15179506 * r15179507;
        double r15179509 = a;
        double r15179510 = d;
        double r15179511 = r15179509 * r15179510;
        double r15179512 = r15179508 - r15179511;
        double r15179513 = r15179507 * r15179507;
        double r15179514 = r15179510 * r15179510;
        double r15179515 = r15179513 + r15179514;
        double r15179516 = r15179512 / r15179515;
        return r15179516;
}

double f(double a, double b, double c, double d) {
        double r15179517 = c;
        double r15179518 = -3.108106990901466e+219;
        bool r15179519 = r15179517 <= r15179518;
        double r15179520 = b;
        double r15179521 = d;
        double r15179522 = hypot(r15179521, r15179517);
        double r15179523 = r15179520 / r15179522;
        double r15179524 = -r15179523;
        double r15179525 = 5.1185396129683884e+128;
        bool r15179526 = r15179517 <= r15179525;
        double r15179527 = r15179520 * r15179517;
        double r15179528 = a;
        double r15179529 = r15179521 * r15179528;
        double r15179530 = r15179527 - r15179529;
        double r15179531 = r15179530 / r15179522;
        double r15179532 = r15179531 / r15179522;
        double r15179533 = r15179526 ? r15179532 : r15179523;
        double r15179534 = r15179519 ? r15179524 : r15179533;
        return r15179534;
}

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.5
Target0.5
Herbie13.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 < -3.108106990901466e+219

    1. Initial program 42.3

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

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

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

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

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

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

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(d, c\right)}}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}\]
    11. Applied hypot-def31.3

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

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

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

    if -3.108106990901466e+219 < c < 5.1185396129683884e+128

    1. Initial program 22.0

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

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

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

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

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

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

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(d, c\right)}}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}\]
    11. Applied hypot-def13.1

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

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

    if 5.1185396129683884e+128 < c

    1. Initial program 41.3

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified41.3

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -3.108106990901466 \cdot 10^{+219}:\\ \;\;\;\;-\frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \le 5.1185396129683884 \cdot 10^{+128}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\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 2019120 +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))))