\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\mathsf{fma}\left(\left({im}^{5}\right), \frac{-1}{60}, \left(im \cdot -2 + im \cdot \left(im \cdot \left(im \cdot \frac{-1}{3}\right)\right)\right)\right) \cdot \left(0.5 \cdot \sin re\right)double f(double re, double im) {
double r44135079 = 0.5;
double r44135080 = re;
double r44135081 = sin(r44135080);
double r44135082 = r44135079 * r44135081;
double r44135083 = im;
double r44135084 = -r44135083;
double r44135085 = exp(r44135084);
double r44135086 = exp(r44135083);
double r44135087 = r44135085 - r44135086;
double r44135088 = r44135082 * r44135087;
return r44135088;
}
double f(double re, double im) {
double r44135089 = im;
double r44135090 = 5.0;
double r44135091 = pow(r44135089, r44135090);
double r44135092 = -0.016666666666666666;
double r44135093 = -2.0;
double r44135094 = r44135089 * r44135093;
double r44135095 = -0.3333333333333333;
double r44135096 = r44135089 * r44135095;
double r44135097 = r44135089 * r44135096;
double r44135098 = r44135089 * r44135097;
double r44135099 = r44135094 + r44135098;
double r44135100 = fma(r44135091, r44135092, r44135099);
double r44135101 = 0.5;
double r44135102 = re;
double r44135103 = sin(r44135102);
double r44135104 = r44135101 * r44135103;
double r44135105 = r44135100 * r44135104;
return r44135105;
}




Bits error versus re




Bits error versus im
| Original | 43.2 |
|---|---|
| Target | 0.3 |
| Herbie | 0.8 |
Initial program 43.2
Taylor expanded around 0 0.8
Simplified0.8
rmApplied sub-neg0.8
Applied distribute-rgt-in0.8
Simplified0.8
Final simplification0.8
herbie shell --seed 2019125 +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))))