Average Error: 25.5 → 23.9
Time: 18.3s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{b \cdot c}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} - \frac{d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} \cdot a}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
double f(double a, double b, double c, double d) {
        double r5841012 = b;
        double r5841013 = c;
        double r5841014 = r5841012 * r5841013;
        double r5841015 = a;
        double r5841016 = d;
        double r5841017 = r5841015 * r5841016;
        double r5841018 = r5841014 - r5841017;
        double r5841019 = r5841013 * r5841013;
        double r5841020 = r5841016 * r5841016;
        double r5841021 = r5841019 + r5841020;
        double r5841022 = r5841018 / r5841021;
        return r5841022;
}

double f(double a, double b, double c, double d) {
        double r5841023 = b;
        double r5841024 = c;
        double r5841025 = r5841023 * r5841024;
        double r5841026 = d;
        double r5841027 = r5841024 * r5841024;
        double r5841028 = fma(r5841026, r5841026, r5841027);
        double r5841029 = sqrt(r5841028);
        double r5841030 = r5841025 / r5841029;
        double r5841031 = r5841026 / r5841029;
        double r5841032 = a;
        double r5841033 = r5841031 * r5841032;
        double r5841034 = r5841030 - r5841033;
        double r5841035 = r5841034 / r5841029;
        return r5841035;
}

\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{b \cdot c}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} - \frac{d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} \cdot a}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}

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. Simplified25.5

    \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{(d \cdot d + \left(c \cdot c\right))_*}}\]
  3. Using strategy rm
  4. Applied add-sqr-sqrt25.5

    \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
  5. Applied associate-/r*25.5

    \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
  6. Taylor expanded around inf 25.5

    \[\leadsto \frac{\frac{\color{blue}{b \cdot c - a \cdot d}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
  7. Using strategy rm
  8. Applied div-sub25.5

    \[\leadsto \frac{\color{blue}{\frac{b \cdot c}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} - \frac{a \cdot d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
  9. Using strategy rm
  10. Applied *-un-lft-identity25.5

    \[\leadsto \frac{\frac{b \cdot c}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} - \frac{a \cdot d}{\color{blue}{1 \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
  11. Applied times-frac23.9

    \[\leadsto \frac{\frac{b \cdot c}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} - \color{blue}{\frac{a}{1} \cdot \frac{d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
  12. Simplified23.9

    \[\leadsto \frac{\frac{b \cdot c}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} - \color{blue}{a} \cdot \frac{d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
  13. Final simplification23.9

    \[\leadsto \frac{\frac{b \cdot c}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} - \frac{d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} \cdot a}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]

Reproduce

herbie shell --seed 2019102 +o rules:numerics
(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))))