Average Error: 43.8 → 0.9
Time: 28.4s
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 r9663636 = 0.5;
        double r9663637 = re;
        double r9663638 = sin(r9663637);
        double r9663639 = r9663636 * r9663638;
        double r9663640 = im;
        double r9663641 = -r9663640;
        double r9663642 = exp(r9663641);
        double r9663643 = exp(r9663640);
        double r9663644 = r9663642 - r9663643;
        double r9663645 = r9663639 * r9663644;
        return r9663645;
}

double f(double re, double im) {
        double r9663646 = im;
        double r9663647 = r9663646 * r9663646;
        double r9663648 = re;
        double r9663649 = sin(r9663648);
        double r9663650 = r9663649 * r9663646;
        double r9663651 = r9663647 * r9663650;
        double r9663652 = 0.16666666666666666;
        double r9663653 = -r9663652;
        double r9663654 = r9663651 * r9663653;
        double r9663655 = 1.0;
        double r9663656 = r9663655 * r9663650;
        double r9663657 = 5.0;
        double r9663658 = pow(r9663646, r9663657);
        double r9663659 = r9663658 * r9663649;
        double r9663660 = 0.008333333333333333;
        double r9663661 = r9663659 * r9663660;
        double r9663662 = r9663656 + r9663661;
        double r9663663 = r9663654 - r9663662;
        return r9663663;
}

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

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
  2. Taylor expanded around 0 0.9

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

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

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

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

    \[\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 2019168 
(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))))