Average Error: 26.0 → 13.4
Time: 15.0s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -9.293826114497670869139658346683561592978 \cdot 10^{210}:\\ \;\;\;\;\frac{-1}{\mathsf{hypot}\left(d, c\right)} \cdot b\\ \mathbf{elif}\;c \le 1.15056779942975516580562280806905910555 \cdot 10^{182}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{1}{\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 -9.293826114497670869139658346683561592978 \cdot 10^{210}:\\
\;\;\;\;\frac{-1}{\mathsf{hypot}\left(d, c\right)} \cdot b\\

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

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

\end{array}
double f(double a, double b, double c, double d) {
        double r5727973 = b;
        double r5727974 = c;
        double r5727975 = r5727973 * r5727974;
        double r5727976 = a;
        double r5727977 = d;
        double r5727978 = r5727976 * r5727977;
        double r5727979 = r5727975 - r5727978;
        double r5727980 = r5727974 * r5727974;
        double r5727981 = r5727977 * r5727977;
        double r5727982 = r5727980 + r5727981;
        double r5727983 = r5727979 / r5727982;
        return r5727983;
}

double f(double a, double b, double c, double d) {
        double r5727984 = c;
        double r5727985 = -9.293826114497671e+210;
        bool r5727986 = r5727984 <= r5727985;
        double r5727987 = -1.0;
        double r5727988 = d;
        double r5727989 = hypot(r5727988, r5727984);
        double r5727990 = r5727987 / r5727989;
        double r5727991 = b;
        double r5727992 = r5727990 * r5727991;
        double r5727993 = 1.1505677994297552e+182;
        bool r5727994 = r5727984 <= r5727993;
        double r5727995 = r5727991 * r5727984;
        double r5727996 = a;
        double r5727997 = r5727988 * r5727996;
        double r5727998 = r5727995 - r5727997;
        double r5727999 = r5727998 / r5727989;
        double r5728000 = r5727999 / r5727989;
        double r5728001 = 1.0;
        double r5728002 = r5728001 / r5727989;
        double r5728003 = r5727991 * r5728002;
        double r5728004 = r5727994 ? r5728000 : r5728003;
        double r5728005 = r5727986 ? r5727992 : r5728004;
        return r5728005;
}

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.0
Target0.5
Herbie13.4
\[\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 < -9.293826114497671e+210

    1. Initial program 41.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified41.6

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

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

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(d, d, c \cdot c\right)}{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}}\]
    7. Applied add-sqr-sqrt41.6

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{b \cdot c - a \cdot d}}}\]
    9. Applied add-cube-cbrt41.6

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{b \cdot c - a \cdot d}}\]
    10. Applied times-frac41.6

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{1}} \cdot \frac{\sqrt[3]{1}}{\frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{b \cdot c - a \cdot d}}}\]
    11. Simplified41.6

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

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

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

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

    if -9.293826114497671e+210 < c < 1.1505677994297552e+182

    1. Initial program 22.3

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified22.3

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

      \[\leadsto \color{blue}{\frac{1}{\frac{\mathsf{fma}\left(d, d, c \cdot c\right)}{b \cdot c - a \cdot d}}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity22.4

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(d, d, c \cdot c\right)}{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}}\]
    7. Applied add-sqr-sqrt22.4

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{b \cdot c - a \cdot d}}}\]
    9. Applied add-cube-cbrt22.4

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{b \cdot c - a \cdot d}}\]
    10. Applied times-frac22.3

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{1}} \cdot \frac{\sqrt[3]{1}}{\frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{b \cdot c - a \cdot d}}}\]
    11. Simplified22.3

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \color{blue}{\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}\]
    13. Using strategy rm
    14. Applied associate-*r/14.0

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

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

    if 1.1505677994297552e+182 < c

    1. Initial program 42.1

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified42.1

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

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

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(d, d, c \cdot c\right)}{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}}\]
    7. Applied add-sqr-sqrt42.1

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{b \cdot c - a \cdot d}}}\]
    9. Applied add-cube-cbrt42.1

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{b \cdot c - a \cdot d}}\]
    10. Applied times-frac42.1

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{1}} \cdot \frac{\sqrt[3]{1}}{\frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{b \cdot c - a \cdot d}}}\]
    11. Simplified42.1

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(d, c\right)}} \cdot \frac{\sqrt[3]{1}}{\frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{b \cdot c - a \cdot d}}\]
    12. Simplified29.5

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

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

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

Reproduce

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