Average Error: 43.2 → 0.8
Time: 32.7s
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 r7296592 = 0.5;
        double r7296593 = re;
        double r7296594 = sin(r7296593);
        double r7296595 = r7296592 * r7296594;
        double r7296596 = im;
        double r7296597 = -r7296596;
        double r7296598 = exp(r7296597);
        double r7296599 = exp(r7296596);
        double r7296600 = r7296598 - r7296599;
        double r7296601 = r7296595 * r7296600;
        return r7296601;
}

double f(double re, double im) {
        double r7296602 = 0.5;
        double r7296603 = re;
        double r7296604 = sin(r7296603);
        double r7296605 = r7296602 * r7296604;
        double r7296606 = im;
        double r7296607 = -2.0;
        double r7296608 = -0.3333333333333333;
        double r7296609 = r7296606 * r7296606;
        double r7296610 = r7296608 * r7296609;
        double r7296611 = r7296607 + r7296610;
        double r7296612 = r7296606 * r7296611;
        double r7296613 = -0.016666666666666666;
        double r7296614 = 5.0;
        double r7296615 = pow(r7296606, r7296614);
        double r7296616 = r7296613 * r7296615;
        double r7296617 = r7296612 + r7296616;
        double r7296618 = r7296605 * r7296617;
        return r7296618;
}

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

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