Average Error: 26.1 → 22.8
Time: 10.5s
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 r3201051 = b;
        double r3201052 = c;
        double r3201053 = r3201051 * r3201052;
        double r3201054 = a;
        double r3201055 = d;
        double r3201056 = r3201054 * r3201055;
        double r3201057 = r3201053 - r3201056;
        double r3201058 = r3201052 * r3201052;
        double r3201059 = r3201055 * r3201055;
        double r3201060 = r3201058 + r3201059;
        double r3201061 = r3201057 / r3201060;
        return r3201061;
}

double f(double a, double b, double c, double d) {
        double r3201062 = c;
        double r3201063 = r3201062 * r3201062;
        double r3201064 = d;
        double r3201065 = r3201064 * r3201064;
        double r3201066 = r3201063 + r3201065;
        double r3201067 = sqrt(r3201066);
        double r3201068 = r3201062 / r3201067;
        double r3201069 = b;
        double r3201070 = r3201068 * r3201069;
        double r3201071 = a;
        double r3201072 = r3201064 / r3201067;
        double r3201073 = r3201071 * r3201072;
        double r3201074 = r3201070 - r3201073;
        double r3201075 = r3201074 / r3201067;
        return r3201075;
}

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

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
  2. Using strategy rm
  3. Applied add-sqr-sqrt26.1

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

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

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

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

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

    \[\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 *-un-lft-identity24.5

    \[\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}}\]
  13. Applied sqrt-prod24.5

    \[\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}}\]
  14. Applied times-frac22.8

    \[\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}}\]
  15. Simplified22.8

    \[\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}}\]
  16. Final simplification22.8

    \[\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 2019133 
(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))))