Average Error: 26.2 → 22.2
Time: 3.5s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{b \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - a \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{b \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - a \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}
double f(double a, double b, double c, double d) {
        double r123603 = b;
        double r123604 = c;
        double r123605 = r123603 * r123604;
        double r123606 = a;
        double r123607 = d;
        double r123608 = r123606 * r123607;
        double r123609 = r123605 - r123608;
        double r123610 = r123604 * r123604;
        double r123611 = r123607 * r123607;
        double r123612 = r123610 + r123611;
        double r123613 = r123609 / r123612;
        return r123613;
}

double f(double a, double b, double c, double d) {
        double r123614 = b;
        double r123615 = c;
        double r123616 = r123615 * r123615;
        double r123617 = d;
        double r123618 = r123617 * r123617;
        double r123619 = r123616 + r123618;
        double r123620 = sqrt(r123619);
        double r123621 = r123615 / r123620;
        double r123622 = r123614 * r123621;
        double r123623 = a;
        double r123624 = r123617 / r123620;
        double r123625 = r123623 * r123624;
        double r123626 = r123622 - r123625;
        double r123627 = r123626 / r123620;
        return r123627;
}

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.5
Herbie22.2
\[\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.2

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
  2. Using strategy rm
  3. Applied add-sqr-sqrt26.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 associate-/r*26.2

    \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
  5. Using strategy rm
  6. Applied div-sub26.2

    \[\leadsto \frac{\color{blue}{\frac{b \cdot c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  7. Using strategy rm
  8. Applied *-un-lft-identity26.2

    \[\leadsto \frac{\frac{b \cdot c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a \cdot d}{\sqrt{\color{blue}{1 \cdot \left(c \cdot c + d \cdot d\right)}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  9. Applied sqrt-prod26.2

    \[\leadsto \frac{\frac{b \cdot c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a \cdot d}{\color{blue}{\sqrt{1} \cdot \sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  10. Applied times-frac24.3

    \[\leadsto \frac{\frac{b \cdot c}{\sqrt{c \cdot c + d \cdot d}} - \color{blue}{\frac{a}{\sqrt{1}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  11. Simplified24.3

    \[\leadsto \frac{\frac{b \cdot c}{\sqrt{c \cdot c + d \cdot d}} - \color{blue}{a} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
  12. Using strategy rm
  13. Applied *-un-lft-identity24.3

    \[\leadsto \frac{\frac{b \cdot c}{\sqrt{\color{blue}{1 \cdot \left(c \cdot c + d \cdot d\right)}}} - a \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
  14. Applied sqrt-prod24.3

    \[\leadsto \frac{\frac{b \cdot c}{\color{blue}{\sqrt{1} \cdot \sqrt{c \cdot c + d \cdot d}}} - a \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
  15. Applied times-frac22.2

    \[\leadsto \frac{\color{blue}{\frac{b}{\sqrt{1}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}}} - a \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
  16. Simplified22.2

    \[\leadsto \frac{\color{blue}{b} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - a \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
  17. Final simplification22.2

    \[\leadsto \frac{b \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - a \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]

Reproduce

herbie shell --seed 2020033 
(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))))