\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\begin{array}{l}
\mathbf{if}\;\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
t_0 \leq -\infty \lor \neg \left(t_0 \leq 0.008696040391028559\right)
\end{array}:\\
\;\;\;\;\cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{0.5}{e^{im}}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\cos re \cdot {im}^{3}\right) \cdot -0.16666666666666666 + \left(\cos re \cdot {im}^{5}\right) \cdot -0.008333333333333333\right) - im \cdot \cos re\\
\end{array}
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(FPCore (re im)
:precision binary64
(if (let* ((t_0 (- (exp (- im)) (exp im))))
(or (<= t_0 (- INFINITY)) (not (<= t_0 0.008696040391028559))))
(* (cos re) (fma (exp im) -0.5 (/ 0.5 (exp im))))
(-
(+
(* (* (cos re) (pow im 3.0)) -0.16666666666666666)
(* (* (cos re) (pow im 5.0)) -0.008333333333333333))
(* im (cos re)))))double code(double re, double im) {
return (0.5 * cos(re)) * (exp(0.0 - im) - exp(im));
}
double code(double re, double im) {
double t_0 = exp(-im) - exp(im);
double tmp;
if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 0.008696040391028559)) {
tmp = cos(re) * fma(exp(im), -0.5, (0.5 / exp(im)));
} else {
tmp = (((cos(re) * pow(im, 3.0)) * -0.16666666666666666) + ((cos(re) * pow(im, 5.0)) * -0.008333333333333333)) - (im * cos(re));
}
return tmp;
}




Bits error versus re




Bits error versus im
| Original | 29.3 |
|---|---|
| Target | 0.1 |
| Herbie | 0.2 |
if (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < -inf.0 or 0.008696040391028559 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) Initial program 0.0
Simplified0.0
if -inf.0 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 0.008696040391028559Initial program 58.3
Simplified58.3
Taylor expanded in im around 0 0.4
Final simplification0.2
herbie shell --seed 2022068
(FPCore (re im)
:name "math.sin on complex, imaginary part"
:precision binary64
:herbie-target
(if (< (fabs im) 1.0) (- (* (cos re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))