Average Error: 57.9 → 0.8
Time: 34.8s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\mathsf{fma}\left(\frac{-1}{3}, im \cdot \left(im \cdot im\right), \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(\frac{-1}{3}, im \cdot \left(im \cdot im\right), \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 r5494265 = 0.5;
        double r5494266 = re;
        double r5494267 = cos(r5494266);
        double r5494268 = r5494265 * r5494267;
        double r5494269 = 0.0;
        double r5494270 = im;
        double r5494271 = r5494269 - r5494270;
        double r5494272 = exp(r5494271);
        double r5494273 = exp(r5494270);
        double r5494274 = r5494272 - r5494273;
        double r5494275 = r5494268 * r5494274;
        return r5494275;
}

double f(double re, double im) {
        double r5494276 = -0.3333333333333333;
        double r5494277 = im;
        double r5494278 = r5494277 * r5494277;
        double r5494279 = r5494277 * r5494278;
        double r5494280 = -2.0;
        double r5494281 = 5.0;
        double r5494282 = pow(r5494277, r5494281);
        double r5494283 = -0.016666666666666666;
        double r5494284 = r5494282 * r5494283;
        double r5494285 = fma(r5494277, r5494280, r5494284);
        double r5494286 = fma(r5494276, r5494279, r5494285);
        double r5494287 = 0.5;
        double r5494288 = re;
        double r5494289 = cos(r5494288);
        double r5494290 = r5494287 * r5494289;
        double r5494291 = r5494286 * r5494290;
        return r5494291;
}

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

    \[\leadsto \mathsf{fma}\left(\frac{-1}{3}, im \cdot \left(im \cdot im\right), \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 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))))