Average Error: 58.0 → 0.8
Time: 36.7s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left(\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right) - \mathsf{fma}\left(2, im, \left({im}^{5} \cdot \frac{1}{60}\right)\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)
\left(\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right) - \mathsf{fma}\left(2, im, \left({im}^{5} \cdot \frac{1}{60}\right)\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r7775054 = 0.5;
        double r7775055 = re;
        double r7775056 = cos(r7775055);
        double r7775057 = r7775054 * r7775056;
        double r7775058 = 0.0;
        double r7775059 = im;
        double r7775060 = r7775058 - r7775059;
        double r7775061 = exp(r7775060);
        double r7775062 = exp(r7775059);
        double r7775063 = r7775061 - r7775062;
        double r7775064 = r7775057 * r7775063;
        return r7775064;
}

double f(double re, double im) {
        double r7775065 = -0.3333333333333333;
        double r7775066 = im;
        double r7775067 = r7775066 * r7775066;
        double r7775068 = r7775066 * r7775067;
        double r7775069 = r7775065 * r7775068;
        double r7775070 = 2.0;
        double r7775071 = 5.0;
        double r7775072 = pow(r7775066, r7775071);
        double r7775073 = 0.016666666666666666;
        double r7775074 = r7775072 * r7775073;
        double r7775075 = fma(r7775070, r7775066, r7775074);
        double r7775076 = r7775069 - r7775075;
        double r7775077 = 0.5;
        double r7775078 = re;
        double r7775079 = cos(r7775078);
        double r7775080 = r7775077 * r7775079;
        double r7775081 = r7775076 * r7775080;
        return r7775081;
}

Error

Bits error versus re

Bits error versus im

Target

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

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

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

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

Reproduce

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