\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)-\mathsf{fma}\left(\left(0.16666666666666666 \cdot \sin re\right), \left(im \cdot \left(im \cdot im\right)\right), \left(\mathsf{fma}\left(\left(0.008333333333333333 \cdot \sin re\right), \left({im}^{5}\right), \left(1.0 \cdot \left(im \cdot \sin re\right)\right)\right)\right)\right)double f(double re, double im) {
double r3443389 = 0.5;
double r3443390 = re;
double r3443391 = sin(r3443390);
double r3443392 = r3443389 * r3443391;
double r3443393 = im;
double r3443394 = -r3443393;
double r3443395 = exp(r3443394);
double r3443396 = exp(r3443393);
double r3443397 = r3443395 - r3443396;
double r3443398 = r3443392 * r3443397;
return r3443398;
}
double f(double re, double im) {
double r3443399 = 0.16666666666666666;
double r3443400 = re;
double r3443401 = sin(r3443400);
double r3443402 = r3443399 * r3443401;
double r3443403 = im;
double r3443404 = r3443403 * r3443403;
double r3443405 = r3443403 * r3443404;
double r3443406 = 0.008333333333333333;
double r3443407 = r3443406 * r3443401;
double r3443408 = 5.0;
double r3443409 = pow(r3443403, r3443408);
double r3443410 = 1.0;
double r3443411 = r3443403 * r3443401;
double r3443412 = r3443410 * r3443411;
double r3443413 = fma(r3443407, r3443409, r3443412);
double r3443414 = fma(r3443402, r3443405, r3443413);
double r3443415 = -r3443414;
return r3443415;
}




Bits error versus re




Bits error versus im
| Original | 43.6 |
|---|---|
| Target | 0.3 |
| Herbie | 0.7 |
Initial program 43.6
Taylor expanded around 0 0.7
Simplified0.7
Taylor expanded around -inf 0.7
Simplified0.7
Final simplification0.7
herbie shell --seed 2019132 +o rules:numerics
(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))))