Average Error: 43.5 → 0.9
Time: 9.0s
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 r282531 = 0.5;
        double r282532 = re;
        double r282533 = sin(r282532);
        double r282534 = r282531 * r282533;
        double r282535 = im;
        double r282536 = -r282535;
        double r282537 = exp(r282536);
        double r282538 = exp(r282535);
        double r282539 = r282537 - r282538;
        double r282540 = r282534 * r282539;
        return r282540;
}

double f(double re, double im) {
        double r282541 = 0.16666666666666666;
        double r282542 = re;
        double r282543 = sin(r282542);
        double r282544 = im;
        double r282545 = 3.0;
        double r282546 = pow(r282544, r282545);
        double r282547 = r282543 * r282546;
        double r282548 = r282541 * r282547;
        double r282549 = -r282548;
        double r282550 = 1.0;
        double r282551 = r282543 * r282544;
        double r282552 = 0.008333333333333333;
        double r282553 = 5.0;
        double r282554 = pow(r282544, r282553);
        double r282555 = r282543 * r282554;
        double r282556 = r282552 * r282555;
        double r282557 = cbrt(r282556);
        double r282558 = 6.0;
        double r282559 = pow(r282557, r282558);
        double r282560 = 0.3333333333333333;
        double r282561 = pow(r282559, r282560);
        double r282562 = r282561 * r282557;
        double r282563 = fma(r282550, r282551, r282562);
        double r282564 = r282549 - r282563;
        return r282564;
}

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))))