Average Error: 43.5 → 0.8
Time: 29.8s
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 r8334457 = 0.5;
        double r8334458 = re;
        double r8334459 = sin(r8334458);
        double r8334460 = r8334457 * r8334459;
        double r8334461 = im;
        double r8334462 = -r8334461;
        double r8334463 = exp(r8334462);
        double r8334464 = exp(r8334461);
        double r8334465 = r8334463 - r8334464;
        double r8334466 = r8334460 * r8334465;
        return r8334466;
}

double f(double re, double im) {
        double r8334467 = im;
        double r8334468 = r8334467 * r8334467;
        double r8334469 = re;
        double r8334470 = sin(r8334469);
        double r8334471 = r8334470 * r8334467;
        double r8334472 = r8334468 * r8334471;
        double r8334473 = 0.16666666666666666;
        double r8334474 = -r8334473;
        double r8334475 = r8334472 * r8334474;
        double r8334476 = 1.0;
        double r8334477 = r8334476 * r8334471;
        double r8334478 = 5.0;
        double r8334479 = pow(r8334467, r8334478);
        double r8334480 = r8334479 * r8334470;
        double r8334481 = 0.008333333333333333;
        double r8334482 = r8334480 * r8334481;
        double r8334483 = r8334477 + r8334482;
        double r8334484 = r8334475 - r8334483;
        return r8334484;
}

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))))