Average Error: 43.5 → 0.9
Time: 8.7s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(-0.166666666666666657 \cdot \left(\sin re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(1, \sin re \cdot im, {\left({\left(\sqrt[3]{0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)}\right)}^{6}\right)}^{\frac{1}{3}} \cdot \sqrt[3]{0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)}\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(-0.166666666666666657 \cdot \left(\sin re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(1, \sin re \cdot im, {\left({\left(\sqrt[3]{0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)}\right)}^{6}\right)}^{\frac{1}{3}} \cdot \sqrt[3]{0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)}\right)
double f(double re, double im) {
        double r242542 = 0.5;
        double r242543 = re;
        double r242544 = sin(r242543);
        double r242545 = r242542 * r242544;
        double r242546 = im;
        double r242547 = -r242546;
        double r242548 = exp(r242547);
        double r242549 = exp(r242546);
        double r242550 = r242548 - r242549;
        double r242551 = r242545 * r242550;
        return r242551;
}

double f(double re, double im) {
        double r242552 = 0.16666666666666666;
        double r242553 = re;
        double r242554 = sin(r242553);
        double r242555 = im;
        double r242556 = 3.0;
        double r242557 = pow(r242555, r242556);
        double r242558 = r242554 * r242557;
        double r242559 = r242552 * r242558;
        double r242560 = -r242559;
        double r242561 = 1.0;
        double r242562 = r242554 * r242555;
        double r242563 = 0.008333333333333333;
        double r242564 = 5.0;
        double r242565 = pow(r242555, r242564);
        double r242566 = r242554 * r242565;
        double r242567 = r242563 * r242566;
        double r242568 = cbrt(r242567);
        double r242569 = 6.0;
        double r242570 = pow(r242568, r242569);
        double r242571 = 0.3333333333333333;
        double r242572 = pow(r242570, r242571);
        double r242573 = r242572 * r242568;
        double r242574 = fma(r242561, r242562, r242573);
        double r242575 = r242560 - r242574;
        return r242575;
}

Error

Bits error versus re

Bits error versus im

Target

Original43.5
Target0.3
Herbie0.9
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\sin re \cdot \left(\left(im + \left(\left(0.166666666666666657 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.00833333333333333322 \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 43.5

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
  2. Taylor expanded around 0 0.8

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(-\left(\frac{1}{3} \cdot {im}^{3} + \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\right)}\]
  3. Simplified0.8

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(\left(-\frac{1}{3} \cdot {im}^{3}\right) - \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)}\]
  4. Taylor expanded around inf 0.8

    \[\leadsto \color{blue}{-\left(0.166666666666666657 \cdot \left(\sin re \cdot {im}^{3}\right) + \left(1 \cdot \left(\sin re \cdot im\right) + 0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\right)}\]
  5. Simplified0.8

    \[\leadsto \color{blue}{\left(-0.166666666666666657 \cdot \left(\sin re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(1, \sin re \cdot im, 0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)\right)}\]
  6. Using strategy rm
  7. Applied add-cube-cbrt0.8

    \[\leadsto \left(-0.166666666666666657 \cdot \left(\sin re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(1, \sin re \cdot im, \color{blue}{\left(\sqrt[3]{0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)} \cdot \sqrt[3]{0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)}\right) \cdot \sqrt[3]{0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)}}\right)\]
  8. Using strategy rm
  9. Applied pow1/35.7

    \[\leadsto \left(-0.166666666666666657 \cdot \left(\sin re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(1, \sin re \cdot im, \left(\sqrt[3]{0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)} \cdot \color{blue}{{\left(0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)\right)}^{\frac{1}{3}}}\right) \cdot \sqrt[3]{0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)}\right)\]
  10. Applied pow1/35.7

    \[\leadsto \left(-0.166666666666666657 \cdot \left(\sin re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(1, \sin re \cdot im, \left(\color{blue}{{\left(0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)\right)}^{\frac{1}{3}}} \cdot {\left(0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)\right)}^{\frac{1}{3}}\right) \cdot \sqrt[3]{0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)}\right)\]
  11. Applied pow-prod-down0.9

    \[\leadsto \left(-0.166666666666666657 \cdot \left(\sin re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(1, \sin re \cdot im, \color{blue}{{\left(\left(0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)\right) \cdot \left(0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\right)}^{\frac{1}{3}}} \cdot \sqrt[3]{0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)}\right)\]
  12. Simplified0.9

    \[\leadsto \left(-0.166666666666666657 \cdot \left(\sin re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(1, \sin re \cdot im, {\color{blue}{\left({\left(\sqrt[3]{0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)}\right)}^{6}\right)}}^{\frac{1}{3}} \cdot \sqrt[3]{0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)}\right)\]
  13. Final simplification0.9

    \[\leadsto \left(-0.166666666666666657 \cdot \left(\sin re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(1, \sin re \cdot im, {\left({\left(\sqrt[3]{0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)}\right)}^{6}\right)}^{\frac{1}{3}} \cdot \sqrt[3]{0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)}\right)\]

Reproduce

herbie shell --seed 2020060 +o rules:numerics
(FPCore (re im)
  :name "math.cos on complex, imaginary part"
  :precision binary64

  :herbie-target
  (if (< (fabs im) 1) (- (* (sin re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

  (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))