Average Error: 58.0 → 0.8
Time: 42.2s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left(-\cos re\right) \cdot \left(1.0 \cdot im + \mathsf{fma}\left(0.16666666666666666, im \cdot \left(im \cdot im\right), 0.008333333333333333 \cdot \left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \left(im \cdot im\right)\right)\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\left(-\cos re\right) \cdot \left(1.0 \cdot im + \mathsf{fma}\left(0.16666666666666666, im \cdot \left(im \cdot im\right), 0.008333333333333333 \cdot \left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \left(im \cdot im\right)\right)\right)\right)
double f(double re, double im) {
        double r9096592 = 0.5;
        double r9096593 = re;
        double r9096594 = cos(r9096593);
        double r9096595 = r9096592 * r9096594;
        double r9096596 = 0.0;
        double r9096597 = im;
        double r9096598 = r9096596 - r9096597;
        double r9096599 = exp(r9096598);
        double r9096600 = exp(r9096597);
        double r9096601 = r9096599 - r9096600;
        double r9096602 = r9096595 * r9096601;
        return r9096602;
}

double f(double re, double im) {
        double r9096603 = re;
        double r9096604 = cos(r9096603);
        double r9096605 = -r9096604;
        double r9096606 = 1.0;
        double r9096607 = im;
        double r9096608 = r9096606 * r9096607;
        double r9096609 = 0.16666666666666666;
        double r9096610 = r9096607 * r9096607;
        double r9096611 = r9096607 * r9096610;
        double r9096612 = 0.008333333333333333;
        double r9096613 = r9096611 * r9096610;
        double r9096614 = r9096612 * r9096613;
        double r9096615 = fma(r9096609, r9096611, r9096614);
        double r9096616 = r9096608 + r9096615;
        double r9096617 = r9096605 * r9096616;
        return r9096617;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.0
Target0.2
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 58.0

    \[\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(\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right) - \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)}\]
  4. Using strategy rm
  5. Applied add-log-exp1.0

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

    \[\leadsto \color{blue}{-\left(1.0 \cdot \left(im \cdot \cos re\right) + \left(0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + 0.008333333333333333 \cdot \left({im}^{5} \cdot \cos re\right)\right)\right)}\]
  7. Simplified0.8

    \[\leadsto \color{blue}{-\cos re \cdot \left(1.0 \cdot im + \mathsf{fma}\left(0.16666666666666666, im \cdot \left(im \cdot im\right), \left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \left(im \cdot im\right)\right) \cdot 0.008333333333333333\right)\right)}\]
  8. Final simplification0.8

    \[\leadsto \left(-\cos re\right) \cdot \left(1.0 \cdot im + \mathsf{fma}\left(0.16666666666666666, im \cdot \left(im \cdot im\right), 0.008333333333333333 \cdot \left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \left(im \cdot im\right)\right)\right)\right)\]

Reproduce

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