Average Error: 26.2 → 13.6
Time: 4.9s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -1.0689057415946615 \cdot 10^{65}:\\ \;\;\;\;{\left(\frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\\ \mathbf{elif}\;c \le 1.5910699936696656 \cdot 10^{174}:\\ \;\;\;\;{\left(\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\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 -1.0689057415946615 \cdot 10^{65}:\\
\;\;\;\;{\left(\frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\\

\mathbf{elif}\;c \le 1.5910699936696656 \cdot 10^{174}:\\
\;\;\;\;{\left(\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\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 r120575 = b;
        double r120576 = c;
        double r120577 = r120575 * r120576;
        double r120578 = a;
        double r120579 = d;
        double r120580 = r120578 * r120579;
        double r120581 = r120577 - r120580;
        double r120582 = r120576 * r120576;
        double r120583 = r120579 * r120579;
        double r120584 = r120582 + r120583;
        double r120585 = r120581 / r120584;
        return r120585;
}

double f(double a, double b, double c, double d) {
        double r120586 = c;
        double r120587 = -1.0689057415946615e+65;
        bool r120588 = r120586 <= r120587;
        double r120589 = -1.0;
        double r120590 = b;
        double r120591 = r120589 * r120590;
        double r120592 = d;
        double r120593 = hypot(r120586, r120592);
        double r120594 = r120591 / r120593;
        double r120595 = 1.0;
        double r120596 = pow(r120594, r120595);
        double r120597 = 1.5910699936696656e+174;
        bool r120598 = r120586 <= r120597;
        double r120599 = r120590 * r120586;
        double r120600 = a;
        double r120601 = r120600 * r120592;
        double r120602 = r120599 - r120601;
        double r120603 = r120602 / r120593;
        double r120604 = r120603 / r120593;
        double r120605 = pow(r120604, r120595);
        double r120606 = r120590 / r120593;
        double r120607 = pow(r120606, r120595);
        double r120608 = r120598 ? r120605 : r120607;
        double r120609 = r120588 ? r120596 : r120608;
        return r120609;
}

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.2
Target0.5
Herbie13.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 3 regimes
  2. if c < -1.0689057415946615e+65

    1. Initial program 36.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt36.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-identity36.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-frac36.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. Simplified36.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. Simplified24.6

      \[\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 pow124.6

      \[\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 pow124.6

      \[\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-down24.6

      \[\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. Simplified24.5

      \[\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 18.3

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

    if -1.0689057415946615e+65 < c < 1.5910699936696656e+174

    1. Initial program 19.4

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

      \[\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-frac19.4

      \[\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. Simplified19.4

      \[\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.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 pow112.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 pow112.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-down12.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. 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}\]
    13. Using strategy rm
    14. Applied clear-num12.3

      \[\leadsto {\left(\frac{\color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{b \cdot c - a \cdot d}}}}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\]
    15. Using strategy rm
    16. Applied *-un-lft-identity12.3

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

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

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

    if 1.5910699936696656e+174 < c

    1. Initial program 46.2

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt46.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-identity46.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-frac46.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. Simplified46.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. Simplified33.7

      \[\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 pow133.7

      \[\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 pow133.7

      \[\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-down33.7

      \[\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. Simplified33.7

      \[\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.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -1.0689057415946615 \cdot 10^{65}:\\ \;\;\;\;{\left(\frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\\ \mathbf{elif}\;c \le 1.5910699936696656 \cdot 10^{174}:\\ \;\;\;\;{\left(\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\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 2020024 +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))))