Average Error: 58.1 → 0.8
Time: 34.6s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(0.5 \cdot \cos re\right) \cdot \mathsf{fma}\left({im}^{5}, \frac{-1}{60}, \mathsf{fma}\left(im, -2, {im}^{3} \cdot \frac{-1}{3}\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(0.5 \cdot \cos re\right) \cdot \mathsf{fma}\left({im}^{5}, \frac{-1}{60}, \mathsf{fma}\left(im, -2, {im}^{3} \cdot \frac{-1}{3}\right)\right)
double f(double re, double im) {
        double r134974 = 0.5;
        double r134975 = re;
        double r134976 = cos(r134975);
        double r134977 = r134974 * r134976;
        double r134978 = 0.0;
        double r134979 = im;
        double r134980 = r134978 - r134979;
        double r134981 = exp(r134980);
        double r134982 = exp(r134979);
        double r134983 = r134981 - r134982;
        double r134984 = r134977 * r134983;
        return r134984;
}

double f(double re, double im) {
        double r134985 = 0.5;
        double r134986 = re;
        double r134987 = cos(r134986);
        double r134988 = r134985 * r134987;
        double r134989 = im;
        double r134990 = 5.0;
        double r134991 = pow(r134989, r134990);
        double r134992 = -0.016666666666666666;
        double r134993 = -2.0;
        double r134994 = 3.0;
        double r134995 = pow(r134989, r134994);
        double r134996 = -0.3333333333333333;
        double r134997 = r134995 * r134996;
        double r134998 = fma(r134989, r134993, r134997);
        double r134999 = fma(r134991, r134992, r134998);
        double r135000 = r134988 * r134999;
        return r135000;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.1
Target0.3
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\cos re \cdot \left(\left(im + \left(\left(0.1666666666666666574148081281236954964697 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333217685101601546193705872 \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.0 - im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 58.1

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

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

Reproduce

herbie shell --seed 2019303 +o rules:numerics
(FPCore (re im)
  :name "math.sin on complex, imaginary part"
  :precision binary64

  :herbie-target
  (if (< (fabs im) 1) (- (* (cos re) (+ (+ im (* (* (* 0.166666666666666657 im) im) im)) (* (* (* (* (* 0.00833333333333333322 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))

  (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))