Average Error: 26.4 → 23.7
Time: 7.1s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}
double f(double a, double b, double c, double d) {
        double r80854 = b;
        double r80855 = c;
        double r80856 = r80854 * r80855;
        double r80857 = a;
        double r80858 = d;
        double r80859 = r80857 * r80858;
        double r80860 = r80856 - r80859;
        double r80861 = r80855 * r80855;
        double r80862 = r80858 * r80858;
        double r80863 = r80861 + r80862;
        double r80864 = r80860 / r80863;
        return r80864;
}

double f(double a, double b, double c, double d) {
        double r80865 = b;
        double r80866 = c;
        double r80867 = r80866 * r80866;
        double r80868 = d;
        double r80869 = r80868 * r80868;
        double r80870 = r80867 + r80869;
        double r80871 = sqrt(r80870);
        double r80872 = r80865 / r80871;
        double r80873 = r80866 / r80871;
        double r80874 = r80872 * r80873;
        double r80875 = a;
        double r80876 = r80875 / r80871;
        double r80877 = r80868 / r80871;
        double r80878 = r80876 * r80877;
        double r80879 = r80874 - r80878;
        return r80879;
}

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.4
Target0.4
Herbie23.7
\[\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.4

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
  2. Using strategy rm
  3. Applied div-sub26.4

    \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
  4. Using strategy rm
  5. Applied add-sqr-sqrt26.4

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

    \[\leadsto \color{blue}{\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
  7. Using strategy rm
  8. Applied add-sqr-sqrt25.1

    \[\leadsto \frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
  9. Applied times-frac23.7

    \[\leadsto \frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \color{blue}{\frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}}\]
  10. Final simplification23.7

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

Reproduce

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