\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\left(\mathsf{fma}\left(\left(\left(im \cdot im\right) \cdot \left(im \cdot im\right)\right) \cdot im, \frac{-1}{60}, \frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)\right) - \left(im + im\right)\right) \cdot \left(0.5 \cdot \sin re\right)double f(double re, double im) {
double r6198497 = 0.5;
double r6198498 = re;
double r6198499 = sin(r6198498);
double r6198500 = r6198497 * r6198499;
double r6198501 = im;
double r6198502 = -r6198501;
double r6198503 = exp(r6198502);
double r6198504 = exp(r6198501);
double r6198505 = r6198503 - r6198504;
double r6198506 = r6198500 * r6198505;
return r6198506;
}
double f(double re, double im) {
double r6198507 = im;
double r6198508 = r6198507 * r6198507;
double r6198509 = r6198508 * r6198508;
double r6198510 = r6198509 * r6198507;
double r6198511 = -0.016666666666666666;
double r6198512 = -0.3333333333333333;
double r6198513 = r6198507 * r6198508;
double r6198514 = r6198512 * r6198513;
double r6198515 = fma(r6198510, r6198511, r6198514);
double r6198516 = r6198507 + r6198507;
double r6198517 = r6198515 - r6198516;
double r6198518 = 0.5;
double r6198519 = re;
double r6198520 = sin(r6198519);
double r6198521 = r6198518 * r6198520;
double r6198522 = r6198517 * r6198521;
return r6198522;
}




Bits error versus re




Bits error versus im
| Original | 43.3 |
|---|---|
| Target | 0.3 |
| Herbie | 0.7 |
Initial program 43.3
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 2019146 +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))))