Average Error: 25.6 → 1.1
Time: 20.6s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\left({\left(\sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}\right)}^{3} + \left(-{\left(\sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}\right)}^{3}\right)\right) \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)} + \mathsf{fma}\left(b, \frac{c}{\mathsf{hypot}\left(d, c\right)}, -{\left(\sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}\right)}^{3}\right) \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\left({\left(\sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}\right)}^{3} + \left(-{\left(\sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}\right)}^{3}\right)\right) \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)} + \mathsf{fma}\left(b, \frac{c}{\mathsf{hypot}\left(d, c\right)}, -{\left(\sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}\right)}^{3}\right) \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}
double f(double a, double b, double c, double d) {
        double r114698 = b;
        double r114699 = c;
        double r114700 = r114698 * r114699;
        double r114701 = a;
        double r114702 = d;
        double r114703 = r114701 * r114702;
        double r114704 = r114700 - r114703;
        double r114705 = r114699 * r114699;
        double r114706 = r114702 * r114702;
        double r114707 = r114705 + r114706;
        double r114708 = r114704 / r114707;
        return r114708;
}

double f(double a, double b, double c, double d) {
        double r114709 = a;
        double r114710 = d;
        double r114711 = c;
        double r114712 = hypot(r114710, r114711);
        double r114713 = r114712 / r114710;
        double r114714 = r114709 / r114713;
        double r114715 = cbrt(r114714);
        double r114716 = 3.0;
        double r114717 = pow(r114715, r114716);
        double r114718 = -r114717;
        double r114719 = r114717 + r114718;
        double r114720 = 1.0;
        double r114721 = r114720 / r114712;
        double r114722 = r114719 * r114721;
        double r114723 = b;
        double r114724 = r114711 / r114712;
        double r114725 = fma(r114723, r114724, r114718);
        double r114726 = r114725 * r114721;
        double r114727 = r114722 + r114726;
        return r114727;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

Original25.6
Target0.4
Herbie1.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.6

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

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

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

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

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

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

    \[\leadsto \frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \color{blue}{\frac{b \cdot c - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}\]
  9. Using strategy rm
  10. Applied div-sub16.6

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

    \[\leadsto \frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \left(\frac{b \cdot c}{\mathsf{hypot}\left(d, c\right)} - \color{blue}{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}\right)\]
  12. Using strategy rm
  13. Applied add-cube-cbrt9.6

    \[\leadsto \frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \left(\frac{b \cdot c}{\mathsf{hypot}\left(d, c\right)} - \color{blue}{\left(\sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}} \cdot \sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}\right) \cdot \sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}}\right)\]
  14. Applied *-un-lft-identity9.6

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

    \[\leadsto \frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \left(\color{blue}{\frac{b}{1} \cdot \frac{c}{\mathsf{hypot}\left(d, c\right)}} - \left(\sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}} \cdot \sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}\right) \cdot \sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}\right)\]
  16. Applied prod-diff1.1

    \[\leadsto \frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \color{blue}{\left(\mathsf{fma}\left(\frac{b}{1}, \frac{c}{\mathsf{hypot}\left(d, c\right)}, -\sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}} \cdot \left(\sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}} \cdot \sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}, \sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}} \cdot \sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}, \sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}} \cdot \left(\sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}} \cdot \sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}\right)\right)\right)}\]
  17. Applied distribute-rgt-in1.1

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

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

    \[\leadsto \frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \mathsf{fma}\left(b, \frac{c}{\mathsf{hypot}\left(d, c\right)}, -{\left(\sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}\right)}^{3}\right) + \color{blue}{\left(\left(-{\left(\sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}\right)}^{3}\right) + {\left(\sqrt[3]{\frac{a}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}}\right)}^{3}\right) \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}}\]
  20. Final simplification1.1

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

Reproduce

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