Average Error: 43.7 → 0.8
Time: 26.1s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(\left(\left(im \cdot im\right) \cdot im\right) \cdot \sin re\right) \cdot \left(-0.16666666666666666\right) - \left({im}^{5} \cdot \left(0.008333333333333333 \cdot \sin re\right) + \left(1.0 \cdot \sin re\right) \cdot im\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(\left(\left(im \cdot im\right) \cdot im\right) \cdot \sin re\right) \cdot \left(-0.16666666666666666\right) - \left({im}^{5} \cdot \left(0.008333333333333333 \cdot \sin re\right) + \left(1.0 \cdot \sin re\right) \cdot im\right)
double f(double re, double im) {
        double r4387655 = 0.5;
        double r4387656 = re;
        double r4387657 = sin(r4387656);
        double r4387658 = r4387655 * r4387657;
        double r4387659 = im;
        double r4387660 = -r4387659;
        double r4387661 = exp(r4387660);
        double r4387662 = exp(r4387659);
        double r4387663 = r4387661 - r4387662;
        double r4387664 = r4387658 * r4387663;
        return r4387664;
}

double f(double re, double im) {
        double r4387665 = im;
        double r4387666 = r4387665 * r4387665;
        double r4387667 = r4387666 * r4387665;
        double r4387668 = re;
        double r4387669 = sin(r4387668);
        double r4387670 = r4387667 * r4387669;
        double r4387671 = 0.16666666666666666;
        double r4387672 = -r4387671;
        double r4387673 = r4387670 * r4387672;
        double r4387674 = 5.0;
        double r4387675 = pow(r4387665, r4387674);
        double r4387676 = 0.008333333333333333;
        double r4387677 = r4387676 * r4387669;
        double r4387678 = r4387675 * r4387677;
        double r4387679 = 1.0;
        double r4387680 = r4387679 * r4387669;
        double r4387681 = r4387680 * r4387665;
        double r4387682 = r4387678 + r4387681;
        double r4387683 = r4387673 - r4387682;
        return r4387683;
}

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.7
Target0.3
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.7

    \[\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(\left(im + im\right) + {im}^{5} \cdot \frac{1}{60}\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(-0.16666666666666666 \cdot \left(\left(\left(im \cdot im\right) \cdot im\right) \cdot \sin re\right)\right) - \left(\left(\sin re \cdot 0.008333333333333333\right) \cdot {im}^{5} + \left(1.0 \cdot \sin re\right) \cdot im\right)}\]
  6. Final simplification0.8

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

Reproduce

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