\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\begin{array}{l}
\mathbf{if}\;e^{-im} - e^{im} \leq 4.026223700770437 \cdot 10^{-06}:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(\left(im \cdot -2 - 0.3333333333333333 \cdot {im}^{3}\right) + {im}^{5} \cdot -0.016666666666666666\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot e^{\log \left(e^{-im} - e^{im}\right)}\\
\end{array}(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(FPCore (re im)
:precision binary64
(if (<= (- (exp (- im)) (exp im)) 4.026223700770437e-06)
(*
(* 0.5 (cos re))
(+
(- (* im -2.0) (* 0.3333333333333333 (pow im 3.0)))
(* (pow im 5.0) -0.016666666666666666)))
(* (* 0.5 (cos re)) (exp (log (- (exp (- im)) (exp im)))))))double code(double re, double im) {
return (0.5 * cos(re)) * (exp(0.0 - im) - exp(im));
}
double code(double re, double im) {
double tmp;
if ((exp(-im) - exp(im)) <= 4.026223700770437e-06) {
tmp = (0.5 * cos(re)) * (((im * -2.0) - (0.3333333333333333 * pow(im, 3.0))) + (pow(im, 5.0) * -0.016666666666666666));
} else {
tmp = (0.5 * cos(re)) * exp(log(exp(-im) - exp(im)));
}
return tmp;
}




Bits error versus re




Bits error versus im
Results
| Original | 58.0 |
|---|---|
| Target | 0.3 |
| Herbie | 0.6 |
if (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 4.02622370077e-6Initial program 58.7
Simplified58.7
Taylor expanded around 0 0.5
Simplified0.5
if 4.02622370077e-6 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) Initial program 4.7
Simplified4.7
rmApplied add-exp-log_binary64_28084.9
Final simplification0.6
herbie shell --seed 2020292
(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))))