Average Error: 43.5 → 0.7
Time: 33.3s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\mathsf{fma}\left({im}^{5}, \frac{1}{60}, \mathsf{fma}\left(\frac{1}{3}, im \cdot im, 2\right) \cdot im\right) \cdot \left(\left(-0.5\right) \cdot \sin re\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\mathsf{fma}\left({im}^{5}, \frac{1}{60}, \mathsf{fma}\left(\frac{1}{3}, im \cdot im, 2\right) \cdot im\right) \cdot \left(\left(-0.5\right) \cdot \sin re\right)
double f(double re, double im) {
        double r8409578 = 0.5;
        double r8409579 = re;
        double r8409580 = sin(r8409579);
        double r8409581 = r8409578 * r8409580;
        double r8409582 = im;
        double r8409583 = -r8409582;
        double r8409584 = exp(r8409583);
        double r8409585 = exp(r8409582);
        double r8409586 = r8409584 - r8409585;
        double r8409587 = r8409581 * r8409586;
        return r8409587;
}

double f(double re, double im) {
        double r8409588 = im;
        double r8409589 = 5.0;
        double r8409590 = pow(r8409588, r8409589);
        double r8409591 = 0.016666666666666666;
        double r8409592 = 0.3333333333333333;
        double r8409593 = r8409588 * r8409588;
        double r8409594 = 2.0;
        double r8409595 = fma(r8409592, r8409593, r8409594);
        double r8409596 = r8409595 * r8409588;
        double r8409597 = fma(r8409590, r8409591, r8409596);
        double r8409598 = 0.5;
        double r8409599 = -r8409598;
        double r8409600 = re;
        double r8409601 = sin(r8409600);
        double r8409602 = r8409599 * r8409601;
        double r8409603 = r8409597 * r8409602;
        return r8409603;
}

Error

Bits error versus re

Bits error versus im

Target

Original43.5
Target0.3
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\sin 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 \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 43.5

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

    \[\leadsto \left(0.5 \cdot \sin 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.7

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

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

Reproduce

herbie shell --seed 2019164 +o rules:numerics
(FPCore (re im)
  :name "math.cos on complex, imaginary part"

  :herbie-target
  (if (< (fabs im) 1) (- (* (sin re) (+ (+ im (* (* (* 1/6 im) im) im)) (* (* (* (* (* 1/120 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

  (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))