Average Error: 57.8 → 0.9
Time: 28.6s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{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 - 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 r3066519 = 0.5;
        double r3066520 = re;
        double r3066521 = cos(r3066520);
        double r3066522 = r3066519 * r3066521;
        double r3066523 = 0.0;
        double r3066524 = im;
        double r3066525 = r3066523 - r3066524;
        double r3066526 = exp(r3066525);
        double r3066527 = exp(r3066524);
        double r3066528 = r3066526 - r3066527;
        double r3066529 = r3066522 * r3066528;
        return r3066529;
}

double f(double re, double im) {
        double r3066530 = -0.3333333333333333;
        double r3066531 = im;
        double r3066532 = r3066531 * r3066531;
        double r3066533 = r3066531 * r3066532;
        double r3066534 = r3066530 * r3066533;
        double r3066535 = 5.0;
        double r3066536 = pow(r3066531, r3066535);
        double r3066537 = 0.016666666666666666;
        double r3066538 = r3066531 + r3066531;
        double r3066539 = fma(r3066536, r3066537, r3066538);
        double r3066540 = r3066534 - r3066539;
        double r3066541 = 0.5;
        double r3066542 = re;
        double r3066543 = cos(r3066542);
        double r3066544 = r3066541 * r3066543;
        double r3066545 = r3066540 * r3066544;
        return r3066545;
}

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}{\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 2019154 +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))))