Average Error: 25.5 → 14.5
Time: 5.0s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le 1.5173701027657723 \cdot 10^{98}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1} \cdot \frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{b \cdot c - a \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{-1 \cdot a}{\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}\;d \le 1.5173701027657723 \cdot 10^{98}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1} \cdot \frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{b \cdot c - a \cdot d}}\\

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

\end{array}
double f(double a, double b, double c, double d) {
        double r76506 = b;
        double r76507 = c;
        double r76508 = r76506 * r76507;
        double r76509 = a;
        double r76510 = d;
        double r76511 = r76509 * r76510;
        double r76512 = r76508 - r76511;
        double r76513 = r76507 * r76507;
        double r76514 = r76510 * r76510;
        double r76515 = r76513 + r76514;
        double r76516 = r76512 / r76515;
        return r76516;
}

double f(double a, double b, double c, double d) {
        double r76517 = d;
        double r76518 = 1.5173701027657723e+98;
        bool r76519 = r76517 <= r76518;
        double r76520 = 1.0;
        double r76521 = c;
        double r76522 = hypot(r76521, r76517);
        double r76523 = r76522 * r76520;
        double r76524 = r76520 / r76523;
        double r76525 = b;
        double r76526 = r76525 * r76521;
        double r76527 = a;
        double r76528 = r76527 * r76517;
        double r76529 = r76526 - r76528;
        double r76530 = r76522 / r76529;
        double r76531 = r76520 / r76530;
        double r76532 = r76524 * r76531;
        double r76533 = -1.0;
        double r76534 = r76533 * r76527;
        double r76535 = r76534 / r76522;
        double r76536 = pow(r76535, r76520);
        double r76537 = r76519 ? r76532 : r76536;
        return r76537;
}

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.5
Target0.5
Herbie14.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 d < 1.5173701027657723e+98

    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. Simplified14.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 clear-num14.0

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

    if 1.5173701027657723e+98 < d

    1. Initial program 39.2

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

      \[\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-identity39.2

      \[\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-frac39.2

      \[\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. Simplified39.2

      \[\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. Simplified26.3

      \[\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 pow126.3

      \[\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 pow126.3

      \[\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-down26.3

      \[\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. Simplified26.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}\]
    13. Taylor expanded around 0 16.8

      \[\leadsto {\left(\frac{\color{blue}{-1 \cdot a}}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification14.5

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

Reproduce

herbie shell --seed 2020035 +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))))