\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\left(\mathsf{fma}\left(\left(im \cdot im\right) \cdot \frac{-1}{3}, im, \frac{-1}{60} \cdot {im}^{5}\right) - \left(im + im\right)\right) \cdot \left(0.5 \cdot \sin re\right)double f(double re, double im) {
double r6203488 = 0.5;
double r6203489 = re;
double r6203490 = sin(r6203489);
double r6203491 = r6203488 * r6203490;
double r6203492 = im;
double r6203493 = -r6203492;
double r6203494 = exp(r6203493);
double r6203495 = exp(r6203492);
double r6203496 = r6203494 - r6203495;
double r6203497 = r6203491 * r6203496;
return r6203497;
}
double f(double re, double im) {
double r6203498 = im;
double r6203499 = r6203498 * r6203498;
double r6203500 = -0.3333333333333333;
double r6203501 = r6203499 * r6203500;
double r6203502 = -0.016666666666666666;
double r6203503 = 5.0;
double r6203504 = pow(r6203498, r6203503);
double r6203505 = r6203502 * r6203504;
double r6203506 = fma(r6203501, r6203498, r6203505);
double r6203507 = r6203498 + r6203498;
double r6203508 = r6203506 - r6203507;
double r6203509 = 0.5;
double r6203510 = re;
double r6203511 = sin(r6203510);
double r6203512 = r6203509 * r6203511;
double r6203513 = r6203508 * r6203512;
return r6203513;
}




Bits error versus re




Bits error versus im
| Original | 43.7 |
|---|---|
| Target | 0.3 |
| Herbie | 0.7 |
Initial program 43.7
Taylor expanded around 0 0.7
Simplified0.7
rmApplied fma-udef0.7
Applied associate--r+0.7
Simplified0.7
Final simplification0.7
herbie shell --seed 2019171 +o rules:numerics
(FPCore (re im)
:name "math.cos on complex, imaginary part"
:herbie-target
(if (< (fabs im) 1.0) (- (* (sin re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))