Average Error: 26.2 → 16.9
Time: 37.9s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}
double f(double a, double b, double c, double d) {
        double r7949635 = b;
        double r7949636 = c;
        double r7949637 = r7949635 * r7949636;
        double r7949638 = a;
        double r7949639 = d;
        double r7949640 = r7949638 * r7949639;
        double r7949641 = r7949637 - r7949640;
        double r7949642 = r7949636 * r7949636;
        double r7949643 = r7949639 * r7949639;
        double r7949644 = r7949642 + r7949643;
        double r7949645 = r7949641 / r7949644;
        return r7949645;
}

double f(double a, double b, double c, double d) {
        double r7949646 = c;
        double r7949647 = b;
        double r7949648 = r7949646 * r7949647;
        double r7949649 = d;
        double r7949650 = a;
        double r7949651 = r7949649 * r7949650;
        double r7949652 = r7949648 - r7949651;
        double r7949653 = hypot(r7949646, r7949649);
        double r7949654 = r7949652 / r7949653;
        double r7949655 = 1.0;
        double r7949656 = hypot(r7949649, r7949646);
        double r7949657 = r7949655 / r7949656;
        double r7949658 = r7949654 * r7949657;
        return r7949658;
}

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.2
Target0.5
Herbie16.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 26.2

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
  2. Simplified26.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-num26.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-identity26.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-sqrt26.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-frac26.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-cbrt26.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-frac26.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. Simplified26.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.9

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

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

Reproduce

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