Average Error: 57.8 → 0.9
Time: 1.2m
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 r22882188 = 0.5;
        double r22882189 = re;
        double r22882190 = cos(r22882189);
        double r22882191 = r22882188 * r22882190;
        double r22882192 = 0.0;
        double r22882193 = im;
        double r22882194 = r22882192 - r22882193;
        double r22882195 = exp(r22882194);
        double r22882196 = exp(r22882193);
        double r22882197 = r22882195 - r22882196;
        double r22882198 = r22882191 * r22882197;
        return r22882198;
}

double f(double re, double im) {
        double r22882199 = im;
        double r22882200 = 5.0;
        double r22882201 = pow(r22882199, r22882200);
        double r22882202 = -0.016666666666666666;
        double r22882203 = r22882201 * r22882202;
        double r22882204 = 2.0;
        double r22882205 = 0.3333333333333333;
        double r22882206 = r22882205 * r22882199;
        double r22882207 = r22882199 * r22882206;
        double r22882208 = r22882204 + r22882207;
        double r22882209 = r22882199 * r22882208;
        double r22882210 = r22882203 - r22882209;
        double r22882211 = 0.5;
        double r22882212 = re;
        double r22882213 = cos(r22882212);
        double r22882214 = r22882211 * r22882213;
        double r22882215 = r22882210 * r22882214;
        return r22882215;
}

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

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

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

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