Average Error: 43.5 → 0.7
Time: 36.7s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[-\left(\sin re \cdot \left(0.008333333333333333 \cdot \left(\left(im \cdot im\right) \cdot \left(im \cdot \left(im \cdot im\right)\right)\right) + im \cdot 1.0\right) + \left(\sin re \cdot \left(im \cdot \left(im \cdot im\right)\right)\right) \cdot 0.16666666666666666\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
-\left(\sin re \cdot \left(0.008333333333333333 \cdot \left(\left(im \cdot im\right) \cdot \left(im \cdot \left(im \cdot im\right)\right)\right) + im \cdot 1.0\right) + \left(\sin re \cdot \left(im \cdot \left(im \cdot im\right)\right)\right) \cdot 0.16666666666666666\right)
double f(double re, double im) {
        double r7406897 = 0.5;
        double r7406898 = re;
        double r7406899 = sin(r7406898);
        double r7406900 = r7406897 * r7406899;
        double r7406901 = im;
        double r7406902 = -r7406901;
        double r7406903 = exp(r7406902);
        double r7406904 = exp(r7406901);
        double r7406905 = r7406903 - r7406904;
        double r7406906 = r7406900 * r7406905;
        return r7406906;
}

double f(double re, double im) {
        double r7406907 = re;
        double r7406908 = sin(r7406907);
        double r7406909 = 0.008333333333333333;
        double r7406910 = im;
        double r7406911 = r7406910 * r7406910;
        double r7406912 = r7406910 * r7406911;
        double r7406913 = r7406911 * r7406912;
        double r7406914 = r7406909 * r7406913;
        double r7406915 = 1.0;
        double r7406916 = r7406910 * r7406915;
        double r7406917 = r7406914 + r7406916;
        double r7406918 = r7406908 * r7406917;
        double r7406919 = r7406908 * r7406912;
        double r7406920 = 0.16666666666666666;
        double r7406921 = r7406919 * r7406920;
        double r7406922 = r7406918 + r7406921;
        double r7406923 = -r7406922;
        return r7406923;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original43.5
Target0.3
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\sin 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 \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 43.5

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

    \[\leadsto \left(0.5 \cdot \sin 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 \sin re\right) \cdot \color{blue}{\left(\frac{-1}{60} \cdot {im}^{5} + \left(im \cdot -2 + \frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)\right)\right)}\]
  4. Taylor expanded around -inf 0.7

    \[\leadsto \color{blue}{-\left(0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right) + \left(1.0 \cdot \left(\sin re \cdot im\right) + 0.008333333333333333 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\right)}\]
  5. Simplified0.7

    \[\leadsto \color{blue}{-\left(\left(\sin re \cdot \left(\left(im \cdot im\right) \cdot im\right)\right) \cdot 0.16666666666666666 + \sin re \cdot \left(1.0 \cdot im + 0.008333333333333333 \cdot \left(\left(im \cdot im\right) \cdot \left(\left(im \cdot im\right) \cdot im\right)\right)\right)\right)}\]
  6. Final simplification0.7

    \[\leadsto -\left(\sin re \cdot \left(0.008333333333333333 \cdot \left(\left(im \cdot im\right) \cdot \left(im \cdot \left(im \cdot im\right)\right)\right) + im \cdot 1.0\right) + \left(\sin re \cdot \left(im \cdot \left(im \cdot im\right)\right)\right) \cdot 0.16666666666666666\right)\]

Reproduce

herbie shell --seed 2019141 
(FPCore (re im)
  :name "math.cos on complex, imaginary part"

  :herbie-target
  (if (< (fabs im) 1) (- (* (sin re) (+ (+ im (* (* (* 1/6 im) im) im)) (* (* (* (* (* 1/120 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

  (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))