Average Error: 57.9 → 0.8
Time: 38.8s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \frac{-1}{3} - \mathsf{fma}\left(2, im, {im}^{5} \cdot \frac{1}{60}\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(\left(im \cdot \left(im \cdot im\right)\right) \cdot \frac{-1}{3} - \mathsf{fma}\left(2, im, {im}^{5} \cdot \frac{1}{60}\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r5025629 = 0.5;
        double r5025630 = re;
        double r5025631 = cos(r5025630);
        double r5025632 = r5025629 * r5025631;
        double r5025633 = 0.0;
        double r5025634 = im;
        double r5025635 = r5025633 - r5025634;
        double r5025636 = exp(r5025635);
        double r5025637 = exp(r5025634);
        double r5025638 = r5025636 - r5025637;
        double r5025639 = r5025632 * r5025638;
        return r5025639;
}

double f(double re, double im) {
        double r5025640 = im;
        double r5025641 = r5025640 * r5025640;
        double r5025642 = r5025640 * r5025641;
        double r5025643 = -0.3333333333333333;
        double r5025644 = r5025642 * r5025643;
        double r5025645 = 2.0;
        double r5025646 = 5.0;
        double r5025647 = pow(r5025640, r5025646);
        double r5025648 = 0.016666666666666666;
        double r5025649 = r5025647 * r5025648;
        double r5025650 = fma(r5025645, r5025640, r5025649);
        double r5025651 = r5025644 - r5025650;
        double r5025652 = 0.5;
        double r5025653 = re;
        double r5025654 = cos(r5025653);
        double r5025655 = r5025652 * r5025654;
        double r5025656 = r5025651 * r5025655;
        return r5025656;
}

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(\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right) - \mathsf{fma}\left(2, im, \frac{1}{60} \cdot {im}^{5}\right)\right)}\]
  4. Final simplification0.8

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

Reproduce

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