Average Error: 25.7 → 0.5
Time: 8.3s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\sqrt{1} \cdot \frac{\frac{c}{\mathsf{hypot}\left(d, c\right)} \cdot b - \frac{d}{\mathsf{hypot}\left(d, c\right)} \cdot a}{\mathsf{hypot}\left(d, c\right)}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\sqrt{1} \cdot \frac{\frac{c}{\mathsf{hypot}\left(d, c\right)} \cdot b - \frac{d}{\mathsf{hypot}\left(d, c\right)} \cdot a}{\mathsf{hypot}\left(d, c\right)}
double f(double a, double b, double c, double d) {
        double r81423 = b;
        double r81424 = c;
        double r81425 = r81423 * r81424;
        double r81426 = a;
        double r81427 = d;
        double r81428 = r81426 * r81427;
        double r81429 = r81425 - r81428;
        double r81430 = r81424 * r81424;
        double r81431 = r81427 * r81427;
        double r81432 = r81430 + r81431;
        double r81433 = r81429 / r81432;
        return r81433;
}

double f(double a, double b, double c, double d) {
        double r81434 = 1.0;
        double r81435 = sqrt(r81434);
        double r81436 = c;
        double r81437 = d;
        double r81438 = hypot(r81437, r81436);
        double r81439 = r81436 / r81438;
        double r81440 = b;
        double r81441 = r81439 * r81440;
        double r81442 = r81437 / r81438;
        double r81443 = a;
        double r81444 = r81442 * r81443;
        double r81445 = r81441 - r81444;
        double r81446 = r81445 / r81438;
        double r81447 = r81435 * r81446;
        return r81447;
}

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

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

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

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

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

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

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

    \[\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 *-un-lft-identity16.6

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

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

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

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

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

    \[\leadsto \frac{\sqrt{1}}{1} \cdot \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)}\]
  17. Simplified9.1

    \[\leadsto \frac{\sqrt{1}}{1} \cdot \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)}\]
  18. Simplified1.0

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

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

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

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

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

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

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

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

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

Reproduce

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