\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)-\left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im \cdot \left(\left(im \cdot im\right) \cdot \frac{1}{3}\right) + im \cdot 2\right)double f(double re, double im) {
double r7856200 = 0.5;
double r7856201 = re;
double r7856202 = sin(r7856201);
double r7856203 = r7856200 * r7856202;
double r7856204 = im;
double r7856205 = -r7856204;
double r7856206 = exp(r7856205);
double r7856207 = exp(r7856204);
double r7856208 = r7856206 - r7856207;
double r7856209 = r7856203 * r7856208;
return r7856209;
}
double f(double re, double im) {
double r7856210 = 0.5;
double r7856211 = re;
double r7856212 = sin(r7856211);
double r7856213 = r7856210 * r7856212;
double r7856214 = im;
double r7856215 = 5.0;
double r7856216 = pow(r7856214, r7856215);
double r7856217 = 0.016666666666666666;
double r7856218 = r7856214 * r7856214;
double r7856219 = 0.3333333333333333;
double r7856220 = r7856218 * r7856219;
double r7856221 = r7856214 * r7856220;
double r7856222 = 2.0;
double r7856223 = r7856214 * r7856222;
double r7856224 = r7856221 + r7856223;
double r7856225 = fma(r7856216, r7856217, r7856224);
double r7856226 = r7856213 * r7856225;
double r7856227 = -r7856226;
return r7856227;
}




Bits error versus re




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