\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\begin{array}{l}
t_0 := e^{-im}\\
t_1 := t_0 - e^{im}\\
\mathbf{if}\;t_1 \leq -0.06182422377168262:\\
\;\;\;\;\begin{array}{l}
t_2 := \sqrt{t_0}\\
\left(0.5 \cdot \cos re\right) \cdot \mathsf{fma}\left(t_2, t_2, -e^{im}\right)
\end{array}\\
\mathbf{elif}\;t_1 \leq 0.09698978473685482:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(-0.5 \cdot \left(\cos re \cdot \mathsf{fma}\left(0.016666666666666666, {im}^{5}, \mathsf{fma}\left(0.3333333333333333, {im}^{3}, \mathsf{fma}\left(im, 2, 0.0003968253968253968 \cdot {im}^{7}\right)\right)\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_1 \cdot \left(0.5 \cdot \sqrt[3]{{\cos re}^{3}}\right)\\
\end{array}
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(FPCore (re im)
:precision binary64
(let* ((t_0 (exp (- im))) (t_1 (- t_0 (exp im))))
(if (<= t_1 -0.06182422377168262)
(let* ((t_2 (sqrt t_0))) (* (* 0.5 (cos re)) (fma t_2 t_2 (- (exp im)))))
(if (<= t_1 0.09698978473685482)
(expm1
(log1p
(*
-0.5
(*
(cos re)
(fma
0.016666666666666666
(pow im 5.0)
(fma
0.3333333333333333
(pow im 3.0)
(fma im 2.0 (* 0.0003968253968253968 (pow im 7.0)))))))))
(* t_1 (* 0.5 (cbrt (pow (cos re) 3.0))))))))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);
double t_1 = t_0 - exp(im);
double tmp;
if (t_1 <= -0.06182422377168262) {
double t_2_1 = sqrt(t_0);
tmp = (0.5 * cos(re)) * fma(t_2_1, t_2_1, -exp(im));
} else if (t_1 <= 0.09698978473685482) {
tmp = expm1(log1p(-0.5 * (cos(re) * fma(0.016666666666666666, pow(im, 5.0), fma(0.3333333333333333, pow(im, 3.0), fma(im, 2.0, (0.0003968253968253968 * pow(im, 7.0))))))));
} else {
tmp = t_1 * (0.5 * cbrt(pow(cos(re), 3.0)));
}
return tmp;
}




Bits error versus re




Bits error versus im
| Original | 29.3 |
|---|---|
| Target | 0.1 |
| Herbie | 0.1 |
if (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < -0.06182422377168262Initial program 0.0
Applied add-sqr-sqrt_binary640.0
Applied fma-neg_binary640.0
if -0.06182422377168262 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 0.09698978473685482Initial program 58.9
Taylor expanded in im around 0 0.1
Simplified0.1
Applied expm1-log1p-u_binary640.1
Simplified0.1
if 0.09698978473685482 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) Initial program 0.0
Applied add-cbrt-cube_binary640.0
Simplified0.0
Final simplification0.1
herbie shell --seed 2022088
(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))))