\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 r34685829 = 0.5;
double r34685830 = re;
double r34685831 = sin(r34685830);
double r34685832 = r34685829 * r34685831;
double r34685833 = im;
double r34685834 = -r34685833;
double r34685835 = exp(r34685834);
double r34685836 = exp(r34685833);
double r34685837 = r34685835 - r34685836;
double r34685838 = r34685832 * r34685837;
return r34685838;
}
double f(double re, double im) {
double r34685839 = im;
double r34685840 = 5.0;
double r34685841 = pow(r34685839, r34685840);
double r34685842 = -0.016666666666666666;
double r34685843 = -2.0;
double r34685844 = r34685839 * r34685843;
double r34685845 = -0.3333333333333333;
double r34685846 = r34685839 * r34685845;
double r34685847 = r34685839 * r34685846;
double r34685848 = r34685839 * r34685847;
double r34685849 = r34685844 + r34685848;
double r34685850 = fma(r34685841, r34685842, r34685849);
double r34685851 = 0.5;
double r34685852 = re;
double r34685853 = sin(r34685852);
double r34685854 = r34685851 * r34685853;
double r34685855 = r34685850 * r34685854;
return r34685855;
}




Bits error versus re




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