Average Error: 57.8 → 0.9
Time: 37.5s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\mathsf{fma}\left(im \cdot \left(im \cdot im\right), \frac{-1}{3}, \mathsf{fma}\left(im, -2, {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)
\mathsf{fma}\left(im \cdot \left(im \cdot im\right), \frac{-1}{3}, \mathsf{fma}\left(im, -2, {im}^{5} \cdot \frac{-1}{60}\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r8046110 = 0.5;
        double r8046111 = re;
        double r8046112 = cos(r8046111);
        double r8046113 = r8046110 * r8046112;
        double r8046114 = 0.0;
        double r8046115 = im;
        double r8046116 = r8046114 - r8046115;
        double r8046117 = exp(r8046116);
        double r8046118 = exp(r8046115);
        double r8046119 = r8046117 - r8046118;
        double r8046120 = r8046113 * r8046119;
        return r8046120;
}

double f(double re, double im) {
        double r8046121 = im;
        double r8046122 = r8046121 * r8046121;
        double r8046123 = r8046121 * r8046122;
        double r8046124 = -0.3333333333333333;
        double r8046125 = -2.0;
        double r8046126 = 5.0;
        double r8046127 = pow(r8046121, r8046126);
        double r8046128 = -0.016666666666666666;
        double r8046129 = r8046127 * r8046128;
        double r8046130 = fma(r8046121, r8046125, r8046129);
        double r8046131 = fma(r8046123, r8046124, r8046130);
        double r8046132 = 0.5;
        double r8046133 = re;
        double r8046134 = cos(r8046133);
        double r8046135 = r8046132 * r8046134;
        double r8046136 = r8046131 * r8046135;
        return r8046136;
}

Error

Bits error versus re

Bits error versus im

Target

Original57.8
Target0.3
Herbie0.9
\[\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.8

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

    \[\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.9

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\mathsf{fma}\left(\left(im \cdot im\right) \cdot im, \frac{-1}{3}, \mathsf{fma}\left(im, -2, \frac{-1}{60} \cdot {im}^{5}\right)\right)}\]
  4. Final simplification0.9

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

Reproduce

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