Average Error: 25.3 → 22.1
Time: 11.1s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot b - \frac{a}{\frac{\sqrt{c \cdot c + d \cdot d}}{d}}}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot b - \frac{a}{\frac{\sqrt{c \cdot c + d \cdot d}}{d}}}{\sqrt{c \cdot c + d \cdot d}}
double f(double a, double b, double c, double d) {
        double r5397684 = b;
        double r5397685 = c;
        double r5397686 = r5397684 * r5397685;
        double r5397687 = a;
        double r5397688 = d;
        double r5397689 = r5397687 * r5397688;
        double r5397690 = r5397686 - r5397689;
        double r5397691 = r5397685 * r5397685;
        double r5397692 = r5397688 * r5397688;
        double r5397693 = r5397691 + r5397692;
        double r5397694 = r5397690 / r5397693;
        return r5397694;
}

double f(double a, double b, double c, double d) {
        double r5397695 = c;
        double r5397696 = r5397695 * r5397695;
        double r5397697 = d;
        double r5397698 = r5397697 * r5397697;
        double r5397699 = r5397696 + r5397698;
        double r5397700 = sqrt(r5397699);
        double r5397701 = r5397695 / r5397700;
        double r5397702 = b;
        double r5397703 = r5397701 * r5397702;
        double r5397704 = a;
        double r5397705 = r5397700 / r5397697;
        double r5397706 = r5397704 / r5397705;
        double r5397707 = r5397703 - r5397706;
        double r5397708 = r5397707 / r5397700;
        return r5397708;
}

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.3
Target0.5
Herbie22.1
\[\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.3

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

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

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

    \[\leadsto \frac{\frac{b \cdot c}{\color{blue}{1 \cdot \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}}\]
  9. Applied times-frac23.8

    \[\leadsto \frac{\color{blue}{\frac{b}{1} \cdot \frac{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}}\]
  10. Simplified23.8

    \[\leadsto \frac{\color{blue}{b} \cdot \frac{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}}\]
  11. Using strategy rm
  12. Applied associate-/l*22.1

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

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

Reproduce

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