Average Error: 26.4 → 12.6
Time: 5.8s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -5.3927648088213951 \cdot 10^{132}:\\ \;\;\;\;{\left(\frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\\ \mathbf{elif}\;c \le -1.2987370292207596 \cdot 10^{-142}:\\ \;\;\;\;\frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{c}} - \frac{a}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{d}}\\ \mathbf{elif}\;c \le 6.1765680479198497 \cdot 10^{-128}:\\ \;\;\;\;{\left(\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\\ \mathbf{elif}\;c \le 1.45382927677037052 \cdot 10^{189}:\\ \;\;\;\;{\left(\frac{\frac{c}{\frac{{\left(\sqrt{\mathsf{hypot}\left(c, d\right)}\right)}^{3}}{b}} - \frac{d}{\frac{{\left(\sqrt{\mathsf{hypot}\left(c, d\right)}\right)}^{3}}{a}}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}\right)}^{1}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{b}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \le -5.3927648088213951 \cdot 10^{132}:\\
\;\;\;\;{\left(\frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\\

\mathbf{elif}\;c \le -1.2987370292207596 \cdot 10^{-142}:\\
\;\;\;\;\frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{c}} - \frac{a}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{d}}\\

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

\mathbf{elif}\;c \le 1.45382927677037052 \cdot 10^{189}:\\
\;\;\;\;{\left(\frac{\frac{c}{\frac{{\left(\sqrt{\mathsf{hypot}\left(c, d\right)}\right)}^{3}}{b}} - \frac{d}{\frac{{\left(\sqrt{\mathsf{hypot}\left(c, d\right)}\right)}^{3}}{a}}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}\right)}^{1}\\

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

\end{array}
double f(double a, double b, double c, double d) {
        double r136357 = b;
        double r136358 = c;
        double r136359 = r136357 * r136358;
        double r136360 = a;
        double r136361 = d;
        double r136362 = r136360 * r136361;
        double r136363 = r136359 - r136362;
        double r136364 = r136358 * r136358;
        double r136365 = r136361 * r136361;
        double r136366 = r136364 + r136365;
        double r136367 = r136363 / r136366;
        return r136367;
}

double f(double a, double b, double c, double d) {
        double r136368 = c;
        double r136369 = -5.392764808821395e+132;
        bool r136370 = r136368 <= r136369;
        double r136371 = -1.0;
        double r136372 = b;
        double r136373 = r136371 * r136372;
        double r136374 = d;
        double r136375 = hypot(r136368, r136374);
        double r136376 = r136373 / r136375;
        double r136377 = 1.0;
        double r136378 = pow(r136376, r136377);
        double r136379 = -1.2987370292207596e-142;
        bool r136380 = r136368 <= r136379;
        double r136381 = r136374 * r136374;
        double r136382 = fma(r136368, r136368, r136381);
        double r136383 = r136382 / r136368;
        double r136384 = r136372 / r136383;
        double r136385 = a;
        double r136386 = r136382 / r136374;
        double r136387 = r136385 / r136386;
        double r136388 = r136384 - r136387;
        double r136389 = 6.17656804791985e-128;
        bool r136390 = r136368 <= r136389;
        double r136391 = r136372 * r136368;
        double r136392 = r136385 * r136374;
        double r136393 = r136391 - r136392;
        double r136394 = r136393 / r136375;
        double r136395 = r136394 / r136375;
        double r136396 = pow(r136395, r136377);
        double r136397 = 1.4538292767703705e+189;
        bool r136398 = r136368 <= r136397;
        double r136399 = sqrt(r136375);
        double r136400 = 3.0;
        double r136401 = pow(r136399, r136400);
        double r136402 = r136401 / r136372;
        double r136403 = r136368 / r136402;
        double r136404 = r136401 / r136385;
        double r136405 = r136374 / r136404;
        double r136406 = r136403 - r136405;
        double r136407 = r136406 / r136399;
        double r136408 = pow(r136407, r136377);
        double r136409 = r136372 / r136375;
        double r136410 = pow(r136409, r136377);
        double r136411 = r136398 ? r136408 : r136410;
        double r136412 = r136390 ? r136396 : r136411;
        double r136413 = r136380 ? r136388 : r136412;
        double r136414 = r136370 ? r136378 : r136413;
        return r136414;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

Original26.4
Target0.5
Herbie12.6
\[\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 5 regimes
  2. if c < -5.392764808821395e+132

    1. Initial program 44.3

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
    5. Applied times-frac44.3

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Simplified44.3

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1} \cdot \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}\]
    8. Using strategy rm
    9. Applied pow129.0

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

      \[\leadsto \color{blue}{{\left(\frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1}\right)}^{1}} \cdot {\left(\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\]
    11. Applied pow-prod-down29.0

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

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

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

    if -5.392764808821395e+132 < c < -1.2987370292207596e-142

    1. Initial program 16.4

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

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
    4. Simplified13.8

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

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

    if -1.2987370292207596e-142 < c < 6.17656804791985e-128

    1. Initial program 22.6

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

      \[\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 *-un-lft-identity22.6

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
    5. Applied times-frac22.6

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

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1} \cdot \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}\]
    8. Using strategy rm
    9. Applied pow112.4

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

      \[\leadsto \color{blue}{{\left(\frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1}\right)}^{1}} \cdot {\left(\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\]
    11. Applied pow-prod-down12.4

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

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

    if 6.17656804791985e-128 < c < 1.4538292767703705e+189

    1. Initial program 21.0

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
    5. Applied times-frac21.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Simplified21.0

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1} \cdot \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}\]
    8. Using strategy rm
    9. Applied pow113.2

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

      \[\leadsto \color{blue}{{\left(\frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1}\right)}^{1}} \cdot {\left(\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\]
    11. Applied pow-prod-down13.2

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

      \[\leadsto {\color{blue}{\left(\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\right)}}^{1}\]
    13. Using strategy rm
    14. Applied add-sqr-sqrt13.3

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

      \[\leadsto {\color{blue}{\left(\frac{\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}\right)}}^{1}\]
    16. Using strategy rm
    17. Applied div-sub13.4

      \[\leadsto {\left(\frac{\frac{\color{blue}{\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right)} - \frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}\right)}^{1}\]
    18. Applied div-sub13.4

      \[\leadsto {\left(\frac{\color{blue}{\frac{\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right)}}{\sqrt{\mathsf{hypot}\left(c, d\right)}} - \frac{\frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}\right)}^{1}\]
    19. Simplified11.9

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

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

    if 1.4538292767703705e+189 < c

    1. Initial program 44.5

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
    5. Applied times-frac44.5

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

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1} \cdot \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}\]
    8. Using strategy rm
    9. Applied pow132.0

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

      \[\leadsto \color{blue}{{\left(\frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1}\right)}^{1}} \cdot {\left(\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\]
    11. Applied pow-prod-down32.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -5.3927648088213951 \cdot 10^{132}:\\ \;\;\;\;{\left(\frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\\ \mathbf{elif}\;c \le -1.2987370292207596 \cdot 10^{-142}:\\ \;\;\;\;\frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{c}} - \frac{a}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{d}}\\ \mathbf{elif}\;c \le 6.1765680479198497 \cdot 10^{-128}:\\ \;\;\;\;{\left(\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\\ \mathbf{elif}\;c \le 1.45382927677037052 \cdot 10^{189}:\\ \;\;\;\;{\left(\frac{\frac{c}{\frac{{\left(\sqrt{\mathsf{hypot}\left(c, d\right)}\right)}^{3}}{b}} - \frac{d}{\frac{{\left(\sqrt{\mathsf{hypot}\left(c, d\right)}\right)}^{3}}{a}}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}\right)}^{1}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{b}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\\ \end{array}\]

Reproduce

herbie shell --seed 2020056 +o rules:numerics
(FPCore (a b c d)
  :name "Complex division, imag part"
  :precision binary64

  :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))))