Average Error: 43.3 → 0.7
Time: 17.0s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[-\left(0.166666666666666657 \cdot \left(\sin re \cdot {im}^{3}\right) + \left(1 \cdot \left(\sin re \cdot im\right) + 0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
-\left(0.166666666666666657 \cdot \left(\sin re \cdot {im}^{3}\right) + \left(1 \cdot \left(\sin re \cdot im\right) + 0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\right)
double f(double re, double im) {
        double r197318 = 0.5;
        double r197319 = re;
        double r197320 = sin(r197319);
        double r197321 = r197318 * r197320;
        double r197322 = im;
        double r197323 = -r197322;
        double r197324 = exp(r197323);
        double r197325 = exp(r197322);
        double r197326 = r197324 - r197325;
        double r197327 = r197321 * r197326;
        return r197327;
}

double f(double re, double im) {
        double r197328 = 0.16666666666666666;
        double r197329 = re;
        double r197330 = sin(r197329);
        double r197331 = im;
        double r197332 = 3.0;
        double r197333 = pow(r197331, r197332);
        double r197334 = r197330 * r197333;
        double r197335 = r197328 * r197334;
        double r197336 = 1.0;
        double r197337 = r197330 * r197331;
        double r197338 = r197336 * r197337;
        double r197339 = 0.008333333333333333;
        double r197340 = 5.0;
        double r197341 = pow(r197331, r197340);
        double r197342 = r197330 * r197341;
        double r197343 = r197339 * r197342;
        double r197344 = r197338 + r197343;
        double r197345 = r197335 + r197344;
        double r197346 = -r197345;
        return r197346;
}

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.3
Target0.3
Herbie0.7
\[\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.3

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

    \[\leadsto \color{blue}{-\left(0.166666666666666657 \cdot \left(\sin re \cdot {im}^{3}\right) + \left(1 \cdot \left(\sin re \cdot im\right) + 0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\right)}\]
  5. Final simplification0.7

    \[\leadsto -\left(0.166666666666666657 \cdot \left(\sin re \cdot {im}^{3}\right) + \left(1 \cdot \left(\sin re \cdot im\right) + 0.00833333333333333322 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\right)\]

Reproduce

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