Average Error: 43.2 → 0.8
Time: 1.1m
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(\left(-im \cdot im\right) \cdot im\right) \cdot \left(\sin re \cdot 0.16666666666666666\right) - \left(1.0 \cdot im + {im}^{5} \cdot 0.008333333333333333\right) \cdot \sin re\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(\left(-im \cdot im\right) \cdot im\right) \cdot \left(\sin re \cdot 0.16666666666666666\right) - \left(1.0 \cdot im + {im}^{5} \cdot 0.008333333333333333\right) \cdot \sin re
double f(double re, double im) {
        double r94407262 = 0.5;
        double r94407263 = re;
        double r94407264 = sin(r94407263);
        double r94407265 = r94407262 * r94407264;
        double r94407266 = im;
        double r94407267 = -r94407266;
        double r94407268 = exp(r94407267);
        double r94407269 = exp(r94407266);
        double r94407270 = r94407268 - r94407269;
        double r94407271 = r94407265 * r94407270;
        return r94407271;
}

double f(double re, double im) {
        double r94407272 = im;
        double r94407273 = r94407272 * r94407272;
        double r94407274 = -r94407273;
        double r94407275 = r94407274 * r94407272;
        double r94407276 = re;
        double r94407277 = sin(r94407276);
        double r94407278 = 0.16666666666666666;
        double r94407279 = r94407277 * r94407278;
        double r94407280 = r94407275 * r94407279;
        double r94407281 = 1.0;
        double r94407282 = r94407281 * r94407272;
        double r94407283 = 5.0;
        double r94407284 = pow(r94407272, r94407283);
        double r94407285 = 0.008333333333333333;
        double r94407286 = r94407284 * r94407285;
        double r94407287 = r94407282 + r94407286;
        double r94407288 = r94407287 * r94407277;
        double r94407289 = r94407280 - r94407288;
        return r94407289;
}

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

    \[\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}{60} \cdot {im}^{5} - \left(\left(\frac{1}{3} \cdot im\right) \cdot im + 2\right) \cdot im\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\right) \cdot \left(im \cdot im\right)\right) \cdot \left(0.16666666666666666 \cdot \sin re\right) - \sin re \cdot \left(0.008333333333333333 \cdot {im}^{5} + 1.0 \cdot im\right)}\]
  6. Final simplification0.8

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

Reproduce

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