Average Error: 26.1 → 0.8
Time: 13.5s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot b - d \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot b - d \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}
double f(double a, double b, double c, double d) {
        double r79914 = b;
        double r79915 = c;
        double r79916 = r79914 * r79915;
        double r79917 = a;
        double r79918 = d;
        double r79919 = r79917 * r79918;
        double r79920 = r79916 - r79919;
        double r79921 = r79915 * r79915;
        double r79922 = r79918 * r79918;
        double r79923 = r79921 + r79922;
        double r79924 = r79920 / r79923;
        return r79924;
}

double f(double a, double b, double c, double d) {
        double r79925 = c;
        double r79926 = d;
        double r79927 = hypot(r79925, r79926);
        double r79928 = r79925 / r79927;
        double r79929 = b;
        double r79930 = r79928 * r79929;
        double r79931 = a;
        double r79932 = r79931 / r79927;
        double r79933 = r79926 * r79932;
        double r79934 = r79930 - r79933;
        double r79935 = r79934 / r79927;
        return r79935;
}

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.1
Target0.4
Herbie0.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. Initial program 26.1

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

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

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

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

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

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

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

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

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

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

    \[\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}\]
  14. Using strategy rm
  15. Applied div-sub17.0

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

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

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

    \[\leadsto {\left(\frac{\frac{c}{\frac{\mathsf{hypot}\left(c, d\right)}{\color{blue}{1 \cdot b}}} - d \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\]
  20. Applied *-un-lft-identity1.3

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

    \[\leadsto {\left(\frac{\frac{c}{\color{blue}{\frac{1}{1} \cdot \frac{\mathsf{hypot}\left(c, d\right)}{b}}} - d \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\right)}^{1}\]
  22. Applied *-un-lft-identity1.3

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

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

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

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

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

Reproduce

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