Average Error: 25.9 → 0.6
Time: 14.5s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{c}{\mathsf{hypot}\left(d, c\right)} \cdot b - \frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}{\mathsf{hypot}\left(d, c\right)}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{c}{\mathsf{hypot}\left(d, c\right)} \cdot b - \frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}{\mathsf{hypot}\left(d, c\right)}
double f(double a, double b, double c, double d) {
        double r80413 = b;
        double r80414 = c;
        double r80415 = r80413 * r80414;
        double r80416 = a;
        double r80417 = d;
        double r80418 = r80416 * r80417;
        double r80419 = r80415 - r80418;
        double r80420 = r80414 * r80414;
        double r80421 = r80417 * r80417;
        double r80422 = r80420 + r80421;
        double r80423 = r80419 / r80422;
        return r80423;
}

double f(double a, double b, double c, double d) {
        double r80424 = c;
        double r80425 = d;
        double r80426 = hypot(r80425, r80424);
        double r80427 = r80424 / r80426;
        double r80428 = b;
        double r80429 = r80427 * r80428;
        double r80430 = a;
        double r80431 = r80426 / r80425;
        double r80432 = r80430 / r80431;
        double r80433 = r80429 - r80432;
        double r80434 = r80433 / r80426;
        return r80434;
}

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.9
Target0.5
Herbie0.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. Initial program 25.9

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
  2. Simplified25.9

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

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

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

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

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

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

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

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

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

    \[\leadsto {\color{blue}{\left(\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\right)}}^{1}\]
  14. Using strategy rm
  15. Applied div-sub16.6

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

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

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

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

Reproduce

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