Average Error: 25.2 → 16.1
Time: 13.2s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}
double f(double a, double b, double c, double d) {
        double r3324128 = b;
        double r3324129 = c;
        double r3324130 = r3324128 * r3324129;
        double r3324131 = a;
        double r3324132 = d;
        double r3324133 = r3324131 * r3324132;
        double r3324134 = r3324130 - r3324133;
        double r3324135 = r3324129 * r3324129;
        double r3324136 = r3324132 * r3324132;
        double r3324137 = r3324135 + r3324136;
        double r3324138 = r3324134 / r3324137;
        return r3324138;
}

double f(double a, double b, double c, double d) {
        double r3324139 = 1.0;
        double r3324140 = d;
        double r3324141 = c;
        double r3324142 = hypot(r3324140, r3324141);
        double r3324143 = r3324139 / r3324142;
        double r3324144 = b;
        double r3324145 = r3324141 * r3324144;
        double r3324146 = a;
        double r3324147 = r3324140 * r3324146;
        double r3324148 = r3324145 - r3324147;
        double r3324149 = r3324148 / r3324142;
        double r3324150 = r3324143 * r3324149;
        return r3324150;
}

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.2
Target0.5
Herbie16.1
\[\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.2

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
  2. Simplified25.2

    \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}}\]
  3. Using strategy rm
  4. Applied clear-num25.3

    \[\leadsto \color{blue}{\frac{1}{\frac{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}{b \cdot c - a \cdot d}}}\]
  5. Using strategy rm
  6. Applied *-un-lft-identity25.3

    \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}}\]
  7. Applied add-sqr-sqrt25.3

    \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)} \cdot \sqrt{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}}}{1 \cdot \left(b \cdot c - a \cdot d\right)}}\]
  8. Applied times-frac25.3

    \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}}{b \cdot c - a \cdot d}}}\]
  9. Applied add-cube-cbrt25.3

    \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{\sqrt{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}}{b \cdot c - a \cdot d}}\]
  10. Applied times-frac25.2

    \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{\sqrt{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}}{1}} \cdot \frac{\sqrt[3]{1}}{\frac{\sqrt{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}}{b \cdot c - a \cdot d}}}\]
  11. Simplified25.2

    \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(d, c\right)}} \cdot \frac{\sqrt[3]{1}}{\frac{\sqrt{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}}{b \cdot c - a \cdot d}}\]
  12. Simplified16.1

    \[\leadsto \frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \color{blue}{\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}\]
  13. Final simplification16.1

    \[\leadsto \frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}\]

Reproduce

herbie shell --seed 2019129 +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))))