Average Error: 25.8 → 16.2
Time: 42.0s
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 r9128661 = b;
        double r9128662 = c;
        double r9128663 = r9128661 * r9128662;
        double r9128664 = a;
        double r9128665 = d;
        double r9128666 = r9128664 * r9128665;
        double r9128667 = r9128663 - r9128666;
        double r9128668 = r9128662 * r9128662;
        double r9128669 = r9128665 * r9128665;
        double r9128670 = r9128668 + r9128669;
        double r9128671 = r9128667 / r9128670;
        return r9128671;
}

double f(double a, double b, double c, double d) {
        double r9128672 = c;
        double r9128673 = b;
        double r9128674 = r9128672 * r9128673;
        double r9128675 = d;
        double r9128676 = a;
        double r9128677 = r9128675 * r9128676;
        double r9128678 = r9128674 - r9128677;
        double r9128679 = hypot(r9128672, r9128675);
        double r9128680 = r9128678 / r9128679;
        double r9128681 = 1.0;
        double r9128682 = hypot(r9128675, r9128672);
        double r9128683 = r9128681 / r9128682;
        double r9128684 = r9128680 * r9128683;
        return r9128684;
}

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.8
Target0.4
Herbie16.2
\[\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.8

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

    \[\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 *-un-lft-identity25.8

    \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}\]
  5. Applied associate-/l*25.9

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

    \[\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)}}}\]
  8. Applied add-sqr-sqrt25.9

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

    \[\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}}}\]
  10. Applied add-cube-cbrt25.9

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

    \[\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}}}\]
  12. Simplified25.8

    \[\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}}\]
  13. Simplified16.2

    \[\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)}}\]
  14. Final simplification16.2

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