\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
t_1 := 0.5 \cdot \sin re\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_0 \cdot t_1\\
\mathbf{elif}\;t_0 \leq 0.008696040391028559:\\
\;\;\;\;\left(\sin re \cdot {im}^{3}\right) \cdot -0.16666666666666666 - \sin re \cdot \left(im + 0.008333333333333333 \cdot {im}^{5}\right)\\
\mathbf{else}:\\
\;\;\;\;t_1 \cdot e^{\log t_0}\\
\end{array}
(FPCore (re im) :precision binary64 (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
(FPCore (re im)
:precision binary64
(let* ((t_0 (- (exp (- im)) (exp im))) (t_1 (* 0.5 (sin re))))
(if (<= t_0 (- INFINITY))
(* t_0 t_1)
(if (<= t_0 0.008696040391028559)
(-
(* (* (sin re) (pow im 3.0)) -0.16666666666666666)
(* (sin re) (+ im (* 0.008333333333333333 (pow im 5.0)))))
(* t_1 (exp (log t_0)))))))double code(double re, double im) {
return (0.5 * sin(re)) * (exp(-im) - exp(im));
}
double code(double re, double im) {
double t_0 = exp(-im) - exp(im);
double t_1 = 0.5 * sin(re);
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = t_0 * t_1;
} else if (t_0 <= 0.008696040391028559) {
tmp = ((sin(re) * pow(im, 3.0)) * -0.16666666666666666) - (sin(re) * (im + (0.008333333333333333 * pow(im, 5.0))));
} else {
tmp = t_1 * exp(log(t_0));
}
return tmp;
}




Bits error versus re




Bits error versus im
Results
| Original | 21.7 |
|---|---|
| Target | 0.2 |
| Herbie | 0.2 |
if (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < -inf.0Initial program 0.0
if -inf.0 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < 0.008696040391028559Initial program 43.1
Taylor expanded in im around 0 0.4
Simplified0.4
Taylor expanded in im around 0 0.4
Simplified0.4
if 0.008696040391028559 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) Initial program 0.1
Applied add-exp-log_binary640.1
Final simplification0.2
herbie shell --seed 2022068
(FPCore (re im)
:name "math.cos on complex, imaginary part"
:precision binary64
: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))))