Average Error: 58.0 → 0.9
Time: 1.1m
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.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.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 r5906380 = 0.5;
        double r5906381 = re;
        double r5906382 = cos(r5906381);
        double r5906383 = r5906380 * r5906382;
        double r5906384 = 0.0;
        double r5906385 = im;
        double r5906386 = r5906384 - r5906385;
        double r5906387 = exp(r5906386);
        double r5906388 = exp(r5906385);
        double r5906389 = r5906387 - r5906388;
        double r5906390 = r5906383 * r5906389;
        return r5906390;
}

double f(double re, double im) {
        double r5906391 = -0.3333333333333333;
        double r5906392 = im;
        double r5906393 = r5906392 * r5906392;
        double r5906394 = r5906392 * r5906393;
        double r5906395 = r5906391 * r5906394;
        double r5906396 = 5.0;
        double r5906397 = pow(r5906392, r5906396);
        double r5906398 = 0.016666666666666666;
        double r5906399 = r5906392 + r5906392;
        double r5906400 = fma(r5906397, r5906398, r5906399);
        double r5906401 = r5906395 - r5906400;
        double r5906402 = 0.5;
        double r5906403 = re;
        double r5906404 = cos(r5906403);
        double r5906405 = r5906402 * r5906404;
        double r5906406 = r5906401 * r5906405;
        return r5906406;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.0
Target0.3
Herbie0.9
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1.0:\\ \;\;\;\;-\cos re \cdot \left(\left(im + \left(\left(0.16666666666666666 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333 \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.0 - im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 58.0

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.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}{\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.9

    \[\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 2019165 +o rules:numerics
(FPCore (re im)
  :name "math.sin on complex, imaginary part"

  :herbie-target
  (if (< (fabs im) 1.0) (- (* (cos re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))

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