Average Error: 43.4 → 0.7
Time: 36.7s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \left(-\sin re\right)\right) \cdot 0.16666666666666666 - \left(1.0 \cdot im + \left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \left(im \cdot im\right)\right) \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 \left(im \cdot im\right)\right) \cdot \left(-\sin re\right)\right) \cdot 0.16666666666666666 - \left(1.0 \cdot im + \left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \left(im \cdot im\right)\right) \cdot 0.008333333333333333\right) \cdot \sin re
double f(double re, double im) {
        double r8567305 = 0.5;
        double r8567306 = re;
        double r8567307 = sin(r8567306);
        double r8567308 = r8567305 * r8567307;
        double r8567309 = im;
        double r8567310 = -r8567309;
        double r8567311 = exp(r8567310);
        double r8567312 = exp(r8567309);
        double r8567313 = r8567311 - r8567312;
        double r8567314 = r8567308 * r8567313;
        return r8567314;
}

double f(double re, double im) {
        double r8567315 = im;
        double r8567316 = r8567315 * r8567315;
        double r8567317 = r8567315 * r8567316;
        double r8567318 = re;
        double r8567319 = sin(r8567318);
        double r8567320 = -r8567319;
        double r8567321 = r8567317 * r8567320;
        double r8567322 = 0.16666666666666666;
        double r8567323 = r8567321 * r8567322;
        double r8567324 = 1.0;
        double r8567325 = r8567324 * r8567315;
        double r8567326 = r8567317 * r8567316;
        double r8567327 = 0.008333333333333333;
        double r8567328 = r8567326 * r8567327;
        double r8567329 = r8567325 + r8567328;
        double r8567330 = r8567329 * r8567319;
        double r8567331 = r8567323 - r8567330;
        return r8567331;
}

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

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

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

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

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

Reproduce

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