Average Error: 25.8 → 12.8
Time: 14.9s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -1.4037038847053747 \cdot 10^{+154}:\\ \;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \le 1.8584161242035747 \cdot 10^{+93}:\\ \;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(d, c\right)}{b \cdot c - a \cdot d}}}{\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 -1.4037038847053747 \cdot 10^{+154}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\

\mathbf{elif}\;c \le 1.8584161242035747 \cdot 10^{+93}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(d, c\right)}{b \cdot c - a \cdot d}}}{\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 r1960697 = b;
        double r1960698 = c;
        double r1960699 = r1960697 * r1960698;
        double r1960700 = a;
        double r1960701 = d;
        double r1960702 = r1960700 * r1960701;
        double r1960703 = r1960699 - r1960702;
        double r1960704 = r1960698 * r1960698;
        double r1960705 = r1960701 * r1960701;
        double r1960706 = r1960704 + r1960705;
        double r1960707 = r1960703 / r1960706;
        return r1960707;
}

double f(double a, double b, double c, double d) {
        double r1960708 = c;
        double r1960709 = -1.4037038847053747e+154;
        bool r1960710 = r1960708 <= r1960709;
        double r1960711 = b;
        double r1960712 = -r1960711;
        double r1960713 = d;
        double r1960714 = hypot(r1960713, r1960708);
        double r1960715 = r1960712 / r1960714;
        double r1960716 = 1.8584161242035747e+93;
        bool r1960717 = r1960708 <= r1960716;
        double r1960718 = 1.0;
        double r1960719 = r1960711 * r1960708;
        double r1960720 = a;
        double r1960721 = r1960720 * r1960713;
        double r1960722 = r1960719 - r1960721;
        double r1960723 = r1960714 / r1960722;
        double r1960724 = r1960718 / r1960723;
        double r1960725 = r1960724 / r1960714;
        double r1960726 = r1960711 / r1960714;
        double r1960727 = r1960717 ? r1960725 : r1960726;
        double r1960728 = r1960710 ? r1960715 : r1960727;
        return r1960728;
}

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.8
Target0.4
Herbie12.8
\[\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.4037038847053747e+154

    1. Initial program 43.9

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified43.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-sqrt43.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*43.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-udef43.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, c \cdot c\right)}}\]
    8. Applied hypot-def43.9

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(d, c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
    9. Using strategy rm
    10. Applied fma-udef43.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-def27.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.2

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

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

    if -1.4037038847053747e+154 < c < 1.8584161242035747e+93

    1. Initial program 18.9

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified18.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-sqrt18.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*18.8

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

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

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

      \[\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-def11.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. Using strategy rm
    13. Applied clear-num11.8

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

    if 1.8584161242035747e+93 < c

    1. Initial program 37.5

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified37.5

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

      \[\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*37.5

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

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

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

      \[\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-def24.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 15.9

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

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

Reproduce

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