Average Error: 25.5 → 23.9
Time: 24.7s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{b \cdot 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 r19000184 = b;
        double r19000185 = c;
        double r19000186 = r19000184 * r19000185;
        double r19000187 = a;
        double r19000188 = d;
        double r19000189 = r19000187 * r19000188;
        double r19000190 = r19000186 - r19000189;
        double r19000191 = r19000185 * r19000185;
        double r19000192 = r19000188 * r19000188;
        double r19000193 = r19000191 + r19000192;
        double r19000194 = r19000190 / r19000193;
        return r19000194;
}

double f(double a, double b, double c, double d) {
        double r19000195 = b;
        double r19000196 = c;
        double r19000197 = r19000195 * r19000196;
        double r19000198 = r19000196 * r19000196;
        double r19000199 = d;
        double r19000200 = r19000199 * r19000199;
        double r19000201 = r19000198 + r19000200;
        double r19000202 = sqrt(r19000201);
        double r19000203 = r19000197 / r19000202;
        double r19000204 = a;
        double r19000205 = r19000199 / r19000202;
        double r19000206 = r19000204 * r19000205;
        double r19000207 = r19000203 - r19000206;
        double r19000208 = r19000207 / r19000202;
        return r19000208;
}

\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{b \cdot 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}}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

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

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

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

    \[\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. Taylor expanded around inf 25.5

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

    \[\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}}\]
  8. Using strategy rm
  9. Applied *-un-lft-identity25.5

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

    \[\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}}\]
  11. Applied times-frac23.9

    \[\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}}\]
  12. Simplified23.9

    \[\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}}\]
  13. Final simplification23.9

    \[\leadsto \frac{\frac{b \cdot 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 2019102 
(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))))