Average Error: 58.2 → 0.7
Time: 54.9s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left({im}^{5} \cdot \frac{-1}{60} - im \cdot \left(2 + im \cdot \left(\frac{1}{3} \cdot im\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({im}^{5} \cdot \frac{-1}{60} - im \cdot \left(2 + im \cdot \left(\frac{1}{3} \cdot im\right)\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r10914880 = 0.5;
        double r10914881 = re;
        double r10914882 = cos(r10914881);
        double r10914883 = r10914880 * r10914882;
        double r10914884 = 0.0;
        double r10914885 = im;
        double r10914886 = r10914884 - r10914885;
        double r10914887 = exp(r10914886);
        double r10914888 = exp(r10914885);
        double r10914889 = r10914887 - r10914888;
        double r10914890 = r10914883 * r10914889;
        return r10914890;
}

double f(double re, double im) {
        double r10914891 = im;
        double r10914892 = 5.0;
        double r10914893 = pow(r10914891, r10914892);
        double r10914894 = -0.016666666666666666;
        double r10914895 = r10914893 * r10914894;
        double r10914896 = 2.0;
        double r10914897 = 0.3333333333333333;
        double r10914898 = r10914897 * r10914891;
        double r10914899 = r10914891 * r10914898;
        double r10914900 = r10914896 + r10914899;
        double r10914901 = r10914891 * r10914900;
        double r10914902 = r10914895 - r10914901;
        double r10914903 = 0.5;
        double r10914904 = re;
        double r10914905 = cos(r10914904);
        double r10914906 = r10914903 * r10914905;
        double r10914907 = r10914902 * r10914906;
        return r10914907;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original58.2
Target0.2
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.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.7

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

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

Reproduce

herbie shell --seed 2019121 
(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))))