Average Error: 58.0 → 0.8
Time: 1.9m
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(\frac{-1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right) - \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right) \cdot \left(0.5 \cdot \cos re\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(\frac{-1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right) - \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r7607692 = 0.5;
        double r7607693 = re;
        double r7607694 = cos(r7607693);
        double r7607695 = r7607692 * r7607694;
        double r7607696 = 0.0;
        double r7607697 = im;
        double r7607698 = r7607696 - r7607697;
        double r7607699 = exp(r7607698);
        double r7607700 = exp(r7607697);
        double r7607701 = r7607699 - r7607700;
        double r7607702 = r7607695 * r7607701;
        return r7607702;
}

double f(double re, double im) {
        double r7607703 = -0.3333333333333333;
        double r7607704 = im;
        double r7607705 = r7607704 * r7607704;
        double r7607706 = r7607705 * r7607704;
        double r7607707 = r7607703 * r7607706;
        double r7607708 = 5.0;
        double r7607709 = pow(r7607704, r7607708);
        double r7607710 = 0.016666666666666666;
        double r7607711 = r7607704 + r7607704;
        double r7607712 = fma(r7607709, r7607710, r7607711);
        double r7607713 = r7607707 - r7607712;
        double r7607714 = 0.5;
        double r7607715 = re;
        double r7607716 = cos(r7607715);
        double r7607717 = r7607714 * r7607716;
        double r7607718 = r7607713 * r7607717;
        return r7607718;
}

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(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.0

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

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

Reproduce

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

  :herbie-target
  (if (< (fabs im) 1.0) (- (* (cos re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 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))))