Average Error: 43.6 → 0.8
Time: 17.0s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(0.5 \cdot \sin re\right) \cdot \left(\frac{-1}{3} \cdot {im}^{3} - \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(0.5 \cdot \sin re\right) \cdot \left(\frac{-1}{3} \cdot {im}^{3} - \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)
double f(double re, double im) {
        double r461276 = 0.5;
        double r461277 = re;
        double r461278 = sin(r461277);
        double r461279 = r461276 * r461278;
        double r461280 = im;
        double r461281 = -r461280;
        double r461282 = exp(r461281);
        double r461283 = exp(r461280);
        double r461284 = r461282 - r461283;
        double r461285 = r461279 * r461284;
        return r461285;
}

double f(double re, double im) {
        double r461286 = 0.5;
        double r461287 = re;
        double r461288 = sin(r461287);
        double r461289 = r461286 * r461288;
        double r461290 = -0.3333333333333333;
        double r461291 = im;
        double r461292 = 3.0;
        double r461293 = pow(r461291, r461292);
        double r461294 = r461290 * r461293;
        double r461295 = 0.016666666666666666;
        double r461296 = 5.0;
        double r461297 = pow(r461291, r461296);
        double r461298 = r461295 * r461297;
        double r461299 = 2.0;
        double r461300 = r461299 * r461291;
        double r461301 = r461298 + r461300;
        double r461302 = r461294 - r461301;
        double r461303 = r461289 * r461302;
        return r461303;
}

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.6
Target0.2
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\sin re \cdot \left(\left(im + \left(\left(0.166666666666666657 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.00833333333333333322 \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.6

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

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

Reproduce

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

  :herbie-target
  (if (< (fabs im) 1) (- (* (sin re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

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