Average Error: 43.5 → 0.8
Time: 32.5s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(\left(im \cdot im\right) \cdot \left(\sin re \cdot im\right)\right) \cdot \left(-0.16666666666666666\right) - \left(1.0 \cdot \left(\sin re \cdot im\right) + \left({im}^{5} \cdot \sin re\right) \cdot 0.008333333333333333\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(\left(im \cdot im\right) \cdot \left(\sin re \cdot im\right)\right) \cdot \left(-0.16666666666666666\right) - \left(1.0 \cdot \left(\sin re \cdot im\right) + \left({im}^{5} \cdot \sin re\right) \cdot 0.008333333333333333\right)
double f(double re, double im) {
        double r8486143 = 0.5;
        double r8486144 = re;
        double r8486145 = sin(r8486144);
        double r8486146 = r8486143 * r8486145;
        double r8486147 = im;
        double r8486148 = -r8486147;
        double r8486149 = exp(r8486148);
        double r8486150 = exp(r8486147);
        double r8486151 = r8486149 - r8486150;
        double r8486152 = r8486146 * r8486151;
        return r8486152;
}

double f(double re, double im) {
        double r8486153 = im;
        double r8486154 = r8486153 * r8486153;
        double r8486155 = re;
        double r8486156 = sin(r8486155);
        double r8486157 = r8486156 * r8486153;
        double r8486158 = r8486154 * r8486157;
        double r8486159 = 0.16666666666666666;
        double r8486160 = -r8486159;
        double r8486161 = r8486158 * r8486160;
        double r8486162 = 1.0;
        double r8486163 = r8486162 * r8486157;
        double r8486164 = 5.0;
        double r8486165 = pow(r8486153, r8486164);
        double r8486166 = r8486165 * r8486156;
        double r8486167 = 0.008333333333333333;
        double r8486168 = r8486166 * r8486167;
        double r8486169 = r8486163 + r8486168;
        double r8486170 = r8486161 - r8486169;
        return r8486170;
}

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

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

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right) - \left(im + \left(im + {im}^{5} \cdot \frac{1}{60}\right)\right)\right)}\]
  4. Taylor expanded around inf 0.8

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

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

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

Reproduce

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