Average Error: 58.0 → 0.7
Time: 34.8s
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 r4518035 = 0.5;
        double r4518036 = re;
        double r4518037 = cos(r4518036);
        double r4518038 = r4518035 * r4518037;
        double r4518039 = 0.0;
        double r4518040 = im;
        double r4518041 = r4518039 - r4518040;
        double r4518042 = exp(r4518041);
        double r4518043 = exp(r4518040);
        double r4518044 = r4518042 - r4518043;
        double r4518045 = r4518038 * r4518044;
        return r4518045;
}

double f(double re, double im) {
        double r4518046 = -0.3333333333333333;
        double r4518047 = im;
        double r4518048 = r4518047 * r4518047;
        double r4518049 = r4518047 * r4518048;
        double r4518050 = -2.0;
        double r4518051 = 5.0;
        double r4518052 = pow(r4518047, r4518051);
        double r4518053 = -0.016666666666666666;
        double r4518054 = r4518052 * r4518053;
        double r4518055 = fma(r4518047, r4518050, r4518054);
        double r4518056 = fma(r4518046, r4518049, r4518055);
        double r4518057 = 0.5;
        double r4518058 = re;
        double r4518059 = cos(r4518058);
        double r4518060 = r4518057 * r4518059;
        double r4518061 = r4518056 * r4518060;
        return r4518061;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.0
Target0.3
Herbie0.7
\[\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.0

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

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

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

    \[\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 2019151 +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))))