Average Error: 44.0 → 0.8
Time: 29.9s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[-\mathsf{fma}\left(\sin re, {im}^{5} \cdot 0.008333333333333333, \mathsf{fma}\left(1.0, im \cdot \sin re, \left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \sin re\right) \cdot 0.16666666666666666\right)\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
-\mathsf{fma}\left(\sin re, {im}^{5} \cdot 0.008333333333333333, \mathsf{fma}\left(1.0, im \cdot \sin re, \left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \sin re\right) \cdot 0.16666666666666666\right)\right)
double f(double re, double im) {
        double r3431579 = 0.5;
        double r3431580 = re;
        double r3431581 = sin(r3431580);
        double r3431582 = r3431579 * r3431581;
        double r3431583 = im;
        double r3431584 = -r3431583;
        double r3431585 = exp(r3431584);
        double r3431586 = exp(r3431583);
        double r3431587 = r3431585 - r3431586;
        double r3431588 = r3431582 * r3431587;
        return r3431588;
}

double f(double re, double im) {
        double r3431589 = re;
        double r3431590 = sin(r3431589);
        double r3431591 = im;
        double r3431592 = 5.0;
        double r3431593 = pow(r3431591, r3431592);
        double r3431594 = 0.008333333333333333;
        double r3431595 = r3431593 * r3431594;
        double r3431596 = 1.0;
        double r3431597 = r3431591 * r3431590;
        double r3431598 = r3431591 * r3431591;
        double r3431599 = r3431591 * r3431598;
        double r3431600 = r3431599 * r3431590;
        double r3431601 = 0.16666666666666666;
        double r3431602 = r3431600 * r3431601;
        double r3431603 = fma(r3431596, r3431597, r3431602);
        double r3431604 = fma(r3431590, r3431595, r3431603);
        double r3431605 = -r3431604;
        return r3431605;
}

Error

Bits error versus re

Bits error versus im

Target

Original44.0
Target0.3
Herbie0.8
\[\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 44.0

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

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

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

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

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

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

Reproduce

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