Average Error: 26.4 → 17.0
Time: 16.4s
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 r4982318 = b;
        double r4982319 = c;
        double r4982320 = r4982318 * r4982319;
        double r4982321 = a;
        double r4982322 = d;
        double r4982323 = r4982321 * r4982322;
        double r4982324 = r4982320 - r4982323;
        double r4982325 = r4982319 * r4982319;
        double r4982326 = r4982322 * r4982322;
        double r4982327 = r4982325 + r4982326;
        double r4982328 = r4982324 / r4982327;
        return r4982328;
}

double f(double a, double b, double c, double d) {
        double r4982329 = 1.0;
        double r4982330 = d;
        double r4982331 = c;
        double r4982332 = hypot(r4982330, r4982331);
        double r4982333 = r4982329 / r4982332;
        double r4982334 = b;
        double r4982335 = r4982331 * r4982334;
        double r4982336 = a;
        double r4982337 = r4982330 * r4982336;
        double r4982338 = r4982335 - r4982337;
        double r4982339 = r4982338 / r4982332;
        double r4982340 = r4982333 * r4982339;
        return r4982340;
}

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.5
Herbie17.0
\[\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. Simplified26.4

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

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

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

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

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

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

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

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

    \[\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 simplification17.0

    \[\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 2019174 +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))))