Average Error: 26.2 → 11.9
Time: 4.6s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -2.0951350871904923 \cdot 10^{187}:\\ \;\;\;\;1 \cdot \frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \le -4.18745680298238259 \cdot 10^{61}:\\ \;\;\;\;1 \cdot \left(\frac{1}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \left(\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}}\right)\right)\\ \mathbf{elif}\;c \le 2.1380990366988849 \cdot 10^{168}:\\ \;\;\;\;1 \cdot \frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \le -2.0951350871904923 \cdot 10^{187}:\\
\;\;\;\;1 \cdot \frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \le -4.18745680298238259 \cdot 10^{61}:\\
\;\;\;\;1 \cdot \left(\frac{1}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \left(\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}}\right)\right)\\

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

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

\end{array}
double f(double a, double b, double c, double d) {
        double r108876 = b;
        double r108877 = c;
        double r108878 = r108876 * r108877;
        double r108879 = a;
        double r108880 = d;
        double r108881 = r108879 * r108880;
        double r108882 = r108878 - r108881;
        double r108883 = r108877 * r108877;
        double r108884 = r108880 * r108880;
        double r108885 = r108883 + r108884;
        double r108886 = r108882 / r108885;
        return r108886;
}

double f(double a, double b, double c, double d) {
        double r108887 = c;
        double r108888 = -2.0951350871904923e+187;
        bool r108889 = r108887 <= r108888;
        double r108890 = 1.0;
        double r108891 = -1.0;
        double r108892 = b;
        double r108893 = r108891 * r108892;
        double r108894 = d;
        double r108895 = hypot(r108887, r108894);
        double r108896 = r108893 / r108895;
        double r108897 = r108890 * r108896;
        double r108898 = -4.1874568029823826e+61;
        bool r108899 = r108887 <= r108898;
        double r108900 = sqrt(r108895);
        double r108901 = r108890 / r108900;
        double r108902 = 3.0;
        double r108903 = pow(r108900, r108902);
        double r108904 = r108903 / r108892;
        double r108905 = r108887 / r108904;
        double r108906 = a;
        double r108907 = r108903 / r108906;
        double r108908 = r108894 / r108907;
        double r108909 = r108905 - r108908;
        double r108910 = r108901 * r108909;
        double r108911 = r108890 * r108910;
        double r108912 = 2.138099036698885e+168;
        bool r108913 = r108887 <= r108912;
        double r108914 = r108892 * r108887;
        double r108915 = r108906 * r108894;
        double r108916 = r108914 - r108915;
        double r108917 = r108916 / r108895;
        double r108918 = r108917 / r108895;
        double r108919 = r108890 * r108918;
        double r108920 = r108892 / r108895;
        double r108921 = r108890 * r108920;
        double r108922 = r108913 ? r108919 : r108921;
        double r108923 = r108899 ? r108911 : r108922;
        double r108924 = r108889 ? r108897 : r108923;
        return r108924;
}

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.4
Herbie11.9
\[\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 4 regimes
  2. if c < -2.0951350871904923e+187

    1. Initial program 43.3

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

      \[\leadsto \color{blue}{\left(1 \cdot \frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1}\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}\]
    10. Applied associate-*l*30.7

      \[\leadsto \color{blue}{1 \cdot \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)}\]
    11. Simplified30.7

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

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

    if -2.0951350871904923e+187 < c < -4.1874568029823826e+61

    1. Initial program 30.5

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

      \[\leadsto \color{blue}{\left(1 \cdot \frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1}\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}\]
    10. Applied associate-*l*19.7

      \[\leadsto \color{blue}{1 \cdot \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)}\]
    11. Simplified19.6

      \[\leadsto 1 \cdot \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}}\]
    12. Using strategy rm
    13. Applied *-un-lft-identity19.6

      \[\leadsto 1 \cdot \frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\color{blue}{1 \cdot \mathsf{hypot}\left(c, d\right)}}\]
    14. Applied add-sqr-sqrt19.8

      \[\leadsto 1 \cdot \frac{\frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{hypot}\left(c, d\right)} \cdot \sqrt{\mathsf{hypot}\left(c, d\right)}}}}{1 \cdot \mathsf{hypot}\left(c, d\right)}\]
    15. Applied *-un-lft-identity19.8

      \[\leadsto 1 \cdot \frac{\frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{\mathsf{hypot}\left(c, d\right)} \cdot \sqrt{\mathsf{hypot}\left(c, d\right)}}}{1 \cdot \mathsf{hypot}\left(c, d\right)}\]
    16. Applied times-frac19.8

      \[\leadsto 1 \cdot \frac{\color{blue}{\frac{1}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}}{1 \cdot \mathsf{hypot}\left(c, d\right)}\]
    17. Applied times-frac19.8

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

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

      \[\leadsto 1 \cdot \left(\frac{1}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}\right)\]
    20. Using strategy rm
    21. Applied div-sub19.8

      \[\leadsto 1 \cdot \left(\frac{1}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \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)}}\right)\]
    22. Applied div-sub19.8

      \[\leadsto 1 \cdot \left(\frac{1}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \color{blue}{\left(\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)}}\right)}\right)\]
    23. Simplified13.6

      \[\leadsto 1 \cdot \left(\frac{1}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \left(\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)}}\right)\right)\]
    24. Simplified11.7

      \[\leadsto 1 \cdot \left(\frac{1}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \left(\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}}}\right)\right)\]

    if -4.1874568029823826e+61 < c < 2.138099036698885e+168

    1. Initial program 19.7

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

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

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

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

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

      \[\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 *-un-lft-identity12.1

      \[\leadsto \color{blue}{\left(1 \cdot \frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1}\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}\]
    10. Applied associate-*l*12.1

      \[\leadsto \color{blue}{1 \cdot \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)}\]
    11. Simplified12.0

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

    if 2.138099036698885e+168 < c

    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. Simplified30.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 *-un-lft-identity30.6

      \[\leadsto \color{blue}{\left(1 \cdot \frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1}\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}\]
    10. Applied associate-*l*30.6

      \[\leadsto \color{blue}{1 \cdot \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)}\]
    11. Simplified30.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -2.0951350871904923 \cdot 10^{187}:\\ \;\;\;\;1 \cdot \frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \le -4.18745680298238259 \cdot 10^{61}:\\ \;\;\;\;1 \cdot \left(\frac{1}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \left(\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}}\right)\right)\\ \mathbf{elif}\;c \le 2.1380990366988849 \cdot 10^{168}:\\ \;\;\;\;1 \cdot \frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \end{array}\]

Reproduce

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