Average Error: 43.3 → 0.8
Time: 32.0s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(0.5 \cdot \sin re\right) \cdot \left(im \cdot \left(-2 + \frac{-1}{3} \cdot \left(im \cdot im\right)\right) + \frac{-1}{60} \cdot {im}^{5}\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(0.5 \cdot \sin re\right) \cdot \left(im \cdot \left(-2 + \frac{-1}{3} \cdot \left(im \cdot im\right)\right) + \frac{-1}{60} \cdot {im}^{5}\right)
double f(double re, double im) {
        double r10709172 = 0.5;
        double r10709173 = re;
        double r10709174 = sin(r10709173);
        double r10709175 = r10709172 * r10709174;
        double r10709176 = im;
        double r10709177 = -r10709176;
        double r10709178 = exp(r10709177);
        double r10709179 = exp(r10709176);
        double r10709180 = r10709178 - r10709179;
        double r10709181 = r10709175 * r10709180;
        return r10709181;
}

double f(double re, double im) {
        double r10709182 = 0.5;
        double r10709183 = re;
        double r10709184 = sin(r10709183);
        double r10709185 = r10709182 * r10709184;
        double r10709186 = im;
        double r10709187 = -2.0;
        double r10709188 = -0.3333333333333333;
        double r10709189 = r10709186 * r10709186;
        double r10709190 = r10709188 * r10709189;
        double r10709191 = r10709187 + r10709190;
        double r10709192 = r10709186 * r10709191;
        double r10709193 = -0.016666666666666666;
        double r10709194 = 5.0;
        double r10709195 = pow(r10709186, r10709194);
        double r10709196 = r10709193 * r10709195;
        double r10709197 = r10709192 + r10709196;
        double r10709198 = r10709185 * r10709197;
        return r10709198;
}

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

    \[\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({im}^{5} \cdot \frac{-1}{60} + \left(-im \cdot \left(\left(im \cdot im\right) \cdot \frac{1}{3} + 2\right)\right)\right)}\]
  4. Final simplification0.8

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(im \cdot \left(-2 + \frac{-1}{3} \cdot \left(im \cdot im\right)\right) + \frac{-1}{60} \cdot {im}^{5}\right)\]

Reproduce

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