Average Error: 58.2 → 0.6
Time: 35.9s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\mathsf{fma}\left(\frac{-1}{3}, im \cdot \left(im \cdot im\right), \mathsf{fma}\left(im, -2, {im}^{5} \cdot \frac{-1}{60}\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)
\mathsf{fma}\left(\frac{-1}{3}, im \cdot \left(im \cdot im\right), \mathsf{fma}\left(im, -2, {im}^{5} \cdot \frac{-1}{60}\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r3623051 = 0.5;
        double r3623052 = re;
        double r3623053 = cos(r3623052);
        double r3623054 = r3623051 * r3623053;
        double r3623055 = 0.0;
        double r3623056 = im;
        double r3623057 = r3623055 - r3623056;
        double r3623058 = exp(r3623057);
        double r3623059 = exp(r3623056);
        double r3623060 = r3623058 - r3623059;
        double r3623061 = r3623054 * r3623060;
        return r3623061;
}

double f(double re, double im) {
        double r3623062 = -0.3333333333333333;
        double r3623063 = im;
        double r3623064 = r3623063 * r3623063;
        double r3623065 = r3623063 * r3623064;
        double r3623066 = -2.0;
        double r3623067 = 5.0;
        double r3623068 = pow(r3623063, r3623067);
        double r3623069 = -0.016666666666666666;
        double r3623070 = r3623068 * r3623069;
        double r3623071 = fma(r3623063, r3623066, r3623070);
        double r3623072 = fma(r3623062, r3623065, r3623071);
        double r3623073 = 0.5;
        double r3623074 = re;
        double r3623075 = cos(r3623074);
        double r3623076 = r3623073 * r3623075;
        double r3623077 = r3623072 * r3623076;
        return r3623077;
}

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}{\mathsf{fma}\left(\frac{-1}{3}, im \cdot \left(im \cdot im\right), \mathsf{fma}\left(im, -2, \frac{-1}{60} \cdot {im}^{5}\right)\right)}\]
  4. Final simplification0.6

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

Reproduce

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