Average Error: 43.5 → 0.7
Time: 35.7s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \left(-\sin re\right)\right) \cdot 0.16666666666666666 - \left(0.008333333333333333 \cdot \left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \left(im \cdot im\right)\right) + 1.0 \cdot im\right) \cdot \sin re\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \left(-\sin re\right)\right) \cdot 0.16666666666666666 - \left(0.008333333333333333 \cdot \left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \left(im \cdot im\right)\right) + 1.0 \cdot im\right) \cdot \sin re
double f(double re, double im) {
        double r6748594 = 0.5;
        double r6748595 = re;
        double r6748596 = sin(r6748595);
        double r6748597 = r6748594 * r6748596;
        double r6748598 = im;
        double r6748599 = -r6748598;
        double r6748600 = exp(r6748599);
        double r6748601 = exp(r6748598);
        double r6748602 = r6748600 - r6748601;
        double r6748603 = r6748597 * r6748602;
        return r6748603;
}

double f(double re, double im) {
        double r6748604 = im;
        double r6748605 = r6748604 * r6748604;
        double r6748606 = r6748604 * r6748605;
        double r6748607 = re;
        double r6748608 = sin(r6748607);
        double r6748609 = -r6748608;
        double r6748610 = r6748606 * r6748609;
        double r6748611 = 0.16666666666666666;
        double r6748612 = r6748610 * r6748611;
        double r6748613 = 0.008333333333333333;
        double r6748614 = r6748606 * r6748605;
        double r6748615 = r6748613 * r6748614;
        double r6748616 = 1.0;
        double r6748617 = r6748616 * r6748604;
        double r6748618 = r6748615 + r6748617;
        double r6748619 = r6748618 * r6748608;
        double r6748620 = r6748612 - r6748619;
        return r6748620;
}

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

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

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

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(\left(\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right) - \left(im + im\right)\right) - {im}^{5} \cdot \frac{1}{60}\right)}\]
  4. Taylor expanded around -inf 0.7

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

    \[\leadsto \color{blue}{\left(\left(\left(im \cdot im\right) \cdot im\right) \cdot \sin re\right) \cdot \left(-0.16666666666666666\right) - \sin re \cdot \left(1.0 \cdot im + 0.008333333333333333 \cdot \left(\left(\left(im \cdot im\right) \cdot im\right) \cdot \left(im \cdot im\right)\right)\right)}\]
  6. Final simplification0.7

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

Reproduce

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