Average Error: 57.9 → 0.8
Time: 36.2s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left(\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right) - \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right) \cdot \left(0.5 \cdot \cos re\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\left(\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right) - \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r3044682 = 0.5;
        double r3044683 = re;
        double r3044684 = cos(r3044683);
        double r3044685 = r3044682 * r3044684;
        double r3044686 = 0.0;
        double r3044687 = im;
        double r3044688 = r3044686 - r3044687;
        double r3044689 = exp(r3044688);
        double r3044690 = exp(r3044687);
        double r3044691 = r3044689 - r3044690;
        double r3044692 = r3044685 * r3044691;
        return r3044692;
}

double f(double re, double im) {
        double r3044693 = -0.3333333333333333;
        double r3044694 = im;
        double r3044695 = r3044694 * r3044694;
        double r3044696 = r3044694 * r3044695;
        double r3044697 = r3044693 * r3044696;
        double r3044698 = 5.0;
        double r3044699 = pow(r3044694, r3044698);
        double r3044700 = 0.016666666666666666;
        double r3044701 = r3044694 + r3044694;
        double r3044702 = fma(r3044699, r3044700, r3044701);
        double r3044703 = r3044697 - r3044702;
        double r3044704 = 0.5;
        double r3044705 = re;
        double r3044706 = cos(r3044705);
        double r3044707 = r3044704 * r3044706;
        double r3044708 = r3044703 * r3044707;
        return r3044708;
}

Error

Bits error versus re

Bits error versus im

Target

Original57.9
Target0.3
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\cos re \cdot \left(\left(im + \left(\left(\frac{1}{6} \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(\frac{1}{120} \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 57.9

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

    \[\leadsto \left(0.5 \cdot \cos 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 \cos re\right) \cdot \color{blue}{\left(\left(\left(im \cdot im\right) \cdot im\right) \cdot \frac{-1}{3} - \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right)}\]
  4. Final simplification0.8

    \[\leadsto \left(\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right) - \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right) \cdot \left(0.5 \cdot \cos re\right)\]

Reproduce

herbie shell --seed 2019152 +o rules:numerics
(FPCore (re im)
  :name "math.sin on complex, imaginary part"

  :herbie-target
  (if (< (fabs im) 1) (- (* (cos re) (+ (+ im (* (* (* 1/6 im) im) im)) (* (* (* (* (* 1/120 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im))))

  (* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im))))