Average Error: 25.7 → 22.4
Time: 10.3s
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 - 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{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot b - 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 r5367841 = b;
        double r5367842 = c;
        double r5367843 = r5367841 * r5367842;
        double r5367844 = a;
        double r5367845 = d;
        double r5367846 = r5367844 * r5367845;
        double r5367847 = r5367843 - r5367846;
        double r5367848 = r5367842 * r5367842;
        double r5367849 = r5367845 * r5367845;
        double r5367850 = r5367848 + r5367849;
        double r5367851 = r5367847 / r5367850;
        return r5367851;
}

double f(double a, double b, double c, double d) {
        double r5367852 = c;
        double r5367853 = r5367852 * r5367852;
        double r5367854 = d;
        double r5367855 = r5367854 * r5367854;
        double r5367856 = r5367853 + r5367855;
        double r5367857 = sqrt(r5367856);
        double r5367858 = r5367852 / r5367857;
        double r5367859 = b;
        double r5367860 = r5367858 * r5367859;
        double r5367861 = a;
        double r5367862 = r5367854 / r5367857;
        double r5367863 = r5367861 * r5367862;
        double r5367864 = r5367860 - r5367863;
        double r5367865 = r5367864 / r5367857;
        return r5367865;
}

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.6
Herbie22.4
\[\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. Using strategy rm
  3. Applied add-sqr-sqrt25.7

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

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

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

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

    \[\leadsto \frac{\frac{b \cdot c}{\color{blue}{\sqrt{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}}\]
  10. Applied times-frac24.0

    \[\leadsto \frac{\color{blue}{\frac{b}{\sqrt{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}}\]
  11. Simplified24.0

    \[\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}}\]
  12. Using strategy rm
  13. Applied *-un-lft-identity24.0

    \[\leadsto \frac{b \cdot \frac{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}}\]
  14. Applied sqrt-prod24.0

    \[\leadsto \frac{b \cdot \frac{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}}\]
  15. Applied times-frac22.4

    \[\leadsto \frac{b \cdot \frac{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}}\]
  16. Simplified22.4

    \[\leadsto \frac{b \cdot \frac{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}}\]
  17. Final simplification22.4

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

Reproduce

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