\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\left(\frac{-1}{60} \cdot {im}^{5}\right) \cdot \left(0.5 \cdot \sin re\right) + \left(im \cdot \sin re\right) \cdot \left(\mathsf{fma}\left(\frac{-1}{3}, \left(im \cdot im\right), -2\right) \cdot 0.5\right)double f(double re, double im) {
double r46957518 = 0.5;
double r46957519 = re;
double r46957520 = sin(r46957519);
double r46957521 = r46957518 * r46957520;
double r46957522 = im;
double r46957523 = -r46957522;
double r46957524 = exp(r46957523);
double r46957525 = exp(r46957522);
double r46957526 = r46957524 - r46957525;
double r46957527 = r46957521 * r46957526;
return r46957527;
}
double f(double re, double im) {
double r46957528 = -0.016666666666666666;
double r46957529 = im;
double r46957530 = 5.0;
double r46957531 = pow(r46957529, r46957530);
double r46957532 = r46957528 * r46957531;
double r46957533 = 0.5;
double r46957534 = re;
double r46957535 = sin(r46957534);
double r46957536 = r46957533 * r46957535;
double r46957537 = r46957532 * r46957536;
double r46957538 = r46957529 * r46957535;
double r46957539 = -0.3333333333333333;
double r46957540 = r46957529 * r46957529;
double r46957541 = -2.0;
double r46957542 = fma(r46957539, r46957540, r46957541);
double r46957543 = r46957542 * r46957533;
double r46957544 = r46957538 * r46957543;
double r46957545 = r46957537 + r46957544;
return r46957545;
}




Bits error versus re




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