\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 r7719822 = 0.5;
double r7719823 = re;
double r7719824 = sin(r7719823);
double r7719825 = r7719822 * r7719824;
double r7719826 = im;
double r7719827 = -r7719826;
double r7719828 = exp(r7719827);
double r7719829 = exp(r7719826);
double r7719830 = r7719828 - r7719829;
double r7719831 = r7719825 * r7719830;
return r7719831;
}
double f(double re, double im) {
double r7719832 = 0.5;
double r7719833 = re;
double r7719834 = sin(r7719833);
double r7719835 = r7719832 * r7719834;
double r7719836 = im;
double r7719837 = 5.0;
double r7719838 = pow(r7719836, r7719837);
double r7719839 = 0.016666666666666666;
double r7719840 = r7719836 * r7719836;
double r7719841 = 0.3333333333333333;
double r7719842 = r7719840 * r7719841;
double r7719843 = r7719836 * r7719842;
double r7719844 = 2.0;
double r7719845 = r7719836 * r7719844;
double r7719846 = r7719843 + r7719845;
double r7719847 = fma(r7719838, r7719839, r7719846);
double r7719848 = r7719835 * r7719847;
double r7719849 = -r7719848;
return r7719849;
}




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))))