Average Error: 58.2 → 0.6
Time: 28.9s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[-\mathsf{fma}\left(\left(1.0 \cdot im\right), \left(\cos re\right), \left(\cos re \cdot \left({im}^{5} \cdot 0.008333333333333333 + \left(\left(im \cdot im\right) \cdot im\right) \cdot 0.16666666666666666\right)\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
-\mathsf{fma}\left(\left(1.0 \cdot im\right), \left(\cos re\right), \left(\cos re \cdot \left({im}^{5} \cdot 0.008333333333333333 + \left(\left(im \cdot im\right) \cdot im\right) \cdot 0.16666666666666666\right)\right)\right)
double f(double re, double im) {
        double r2608482 = 0.5;
        double r2608483 = re;
        double r2608484 = cos(r2608483);
        double r2608485 = r2608482 * r2608484;
        double r2608486 = 0.0;
        double r2608487 = im;
        double r2608488 = r2608486 - r2608487;
        double r2608489 = exp(r2608488);
        double r2608490 = exp(r2608487);
        double r2608491 = r2608489 - r2608490;
        double r2608492 = r2608485 * r2608491;
        return r2608492;
}

double f(double re, double im) {
        double r2608493 = 1.0;
        double r2608494 = im;
        double r2608495 = r2608493 * r2608494;
        double r2608496 = re;
        double r2608497 = cos(r2608496);
        double r2608498 = 5.0;
        double r2608499 = pow(r2608494, r2608498);
        double r2608500 = 0.008333333333333333;
        double r2608501 = r2608499 * r2608500;
        double r2608502 = r2608494 * r2608494;
        double r2608503 = r2608502 * r2608494;
        double r2608504 = 0.16666666666666666;
        double r2608505 = r2608503 * r2608504;
        double r2608506 = r2608501 + r2608505;
        double r2608507 = r2608497 * r2608506;
        double r2608508 = fma(r2608495, r2608497, r2608507);
        double r2608509 = -r2608508;
        return r2608509;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.2
Target0.2
Herbie0.6
\[\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 58.2

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

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

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(-\mathsf{fma}\left(\frac{1}{3}, \left(im \cdot \left(im \cdot im\right)\right), \left(\mathsf{fma}\left(\frac{1}{60}, \left({im}^{5}\right), \left(2 \cdot im\right)\right)\right)\right)\right)}\]
  4. Taylor expanded around -inf 0.6

    \[\leadsto \color{blue}{-\left(1.0 \cdot \left(im \cdot \cos re\right) + \left(0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + 0.008333333333333333 \cdot \left({im}^{5} \cdot \cos re\right)\right)\right)}\]
  5. Simplified0.6

    \[\leadsto \color{blue}{-\mathsf{fma}\left(\left(1.0 \cdot im\right), \left(\cos re\right), \left(\cos re \cdot \left(0.16666666666666666 \cdot \left(im \cdot \left(im \cdot im\right)\right) + 0.008333333333333333 \cdot {im}^{5}\right)\right)\right)}\]
  6. Final simplification0.6

    \[\leadsto -\mathsf{fma}\left(\left(1.0 \cdot im\right), \left(\cos re\right), \left(\cos re \cdot \left({im}^{5} \cdot 0.008333333333333333 + \left(\left(im \cdot im\right) \cdot im\right) \cdot 0.16666666666666666\right)\right)\right)\]

Reproduce

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