Average Error: 43.4 → 0.8
Time: 17.4s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\sin re \cdot \left(\left(-{im}^{3} \cdot \frac{6004799503160661}{36028797018963968}\right) - \left(\frac{4803839602528529}{576460752303423488} \cdot {im}^{5} + 1 \cdot im\right)\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\sin re \cdot \left(\left(-{im}^{3} \cdot \frac{6004799503160661}{36028797018963968}\right) - \left(\frac{4803839602528529}{576460752303423488} \cdot {im}^{5} + 1 \cdot im\right)\right)
double f(double re, double im) {
        double r153446 = 0.5;
        double r153447 = re;
        double r153448 = sin(r153447);
        double r153449 = r153446 * r153448;
        double r153450 = im;
        double r153451 = -r153450;
        double r153452 = exp(r153451);
        double r153453 = exp(r153450);
        double r153454 = r153452 - r153453;
        double r153455 = r153449 * r153454;
        return r153455;
}

double f(double re, double im) {
        double r153456 = re;
        double r153457 = sin(r153456);
        double r153458 = im;
        double r153459 = 3.0;
        double r153460 = pow(r153458, r153459);
        double r153461 = 6004799503160661.0;
        double r153462 = 3.602879701896397e+16;
        double r153463 = r153461 / r153462;
        double r153464 = r153460 * r153463;
        double r153465 = -r153464;
        double r153466 = 4803839602528529.0;
        double r153467 = 5.764607523034235e+17;
        double r153468 = r153466 / r153467;
        double r153469 = 5.0;
        double r153470 = pow(r153458, r153469);
        double r153471 = r153468 * r153470;
        double r153472 = 1.0;
        double r153473 = r153472 * r153458;
        double r153474 = r153471 + r153473;
        double r153475 = r153465 - r153474;
        double r153476 = r153457 * r153475;
        return r153476;
}

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.2
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\sin re \cdot \left(\left(im + \left(\left(0.1666666666666666574148081281236954964697 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333217685101601546193705872 \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. Simplified43.4

    \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)}\]
  3. Taylor expanded around 0 0.8

    \[\leadsto \left(\frac{1}{2} \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)}\]
  4. Taylor expanded around inf 0.8

    \[\leadsto \color{blue}{-\left(0.1666666666666666574148081281236954964697 \cdot \left(\sin re \cdot {im}^{3}\right) + \left(1 \cdot \left(\sin re \cdot im\right) + 0.008333333333333333217685101601546193705872 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\right)}\]
  5. Simplified0.8

    \[\leadsto \color{blue}{-\left(\frac{6004799503160661}{36028797018963968} \cdot \left(\sin re \cdot {im}^{3}\right) + \left(1 \cdot \left(\sin re \cdot im\right) + \frac{4803839602528529}{576460752303423488} \cdot \left(\sin re \cdot {im}^{5}\right)\right)\right)}\]
  6. Final simplification0.8

    \[\leadsto \sin re \cdot \left(\left(-{im}^{3} \cdot \frac{6004799503160661}{36028797018963968}\right) - \left(\frac{4803839602528529}{576460752303423488} \cdot {im}^{5} + 1 \cdot im\right)\right)\]

Reproduce

herbie shell --seed 2019304 
(FPCore (re im)
  :name "math.cos on complex, imaginary part"
  :precision binary64

  :herbie-target
  (if (< (fabs im) 1) (- (* (sin re) (+ (+ im (* (* (* 0.166666666666666657 im) im) im)) (* (* (* (* (* 0.00833333333333333322 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

  (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))