Average Error: 57.8 → 0.7
Time: 1.7m
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left({im}^{5} \cdot \frac{-1}{60} - im \cdot \left(2 + im \cdot \left(\frac{1}{3} \cdot im\right)\right)\right) \cdot \left(0.5 \cdot \cos re\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\left({im}^{5} \cdot \frac{-1}{60} - im \cdot \left(2 + im \cdot \left(\frac{1}{3} \cdot im\right)\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r39135740 = 0.5;
        double r39135741 = re;
        double r39135742 = cos(r39135741);
        double r39135743 = r39135740 * r39135742;
        double r39135744 = 0.0;
        double r39135745 = im;
        double r39135746 = r39135744 - r39135745;
        double r39135747 = exp(r39135746);
        double r39135748 = exp(r39135745);
        double r39135749 = r39135747 - r39135748;
        double r39135750 = r39135743 * r39135749;
        return r39135750;
}

double f(double re, double im) {
        double r39135751 = im;
        double r39135752 = 5.0;
        double r39135753 = pow(r39135751, r39135752);
        double r39135754 = -0.016666666666666666;
        double r39135755 = r39135753 * r39135754;
        double r39135756 = 2.0;
        double r39135757 = 0.3333333333333333;
        double r39135758 = r39135757 * r39135751;
        double r39135759 = r39135751 * r39135758;
        double r39135760 = r39135756 + r39135759;
        double r39135761 = r39135751 * r39135760;
        double r39135762 = r39135755 - r39135761;
        double r39135763 = 0.5;
        double r39135764 = re;
        double r39135765 = cos(r39135764);
        double r39135766 = r39135763 * r39135765;
        double r39135767 = r39135762 * r39135766;
        return r39135767;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original57.8
Target0.3
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\cos 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 \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 57.8

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

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

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

Reproduce

herbie shell --seed 2019125 
(FPCore (re im)
  :name "math.sin on complex, imaginary part"

  :herbie-target
  (if (< (fabs im) 1) (- (* (cos re) (+ (+ im (* (* (* 1/6 im) im) im)) (* (* (* (* (* 1/120 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im))))

  (* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im))))