\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \leq -0.013822936471103725:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\sin x \cdot \left(1 \cdot 1 + \cos x \cdot \left(1 + \cos x\right)\right)}\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \leq 0.00023223782787987925:\\
\;\;\;\;\left(0.041666666666666664 \cdot {x}^{3} + 0.004166666666666667 \cdot {x}^{5}\right) + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)\\
\end{array}(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (sin x)))
(FPCore (x)
:precision binary64
(if (<= (/ (- 1.0 (cos x)) (sin x)) -0.013822936471103725)
(/
(- (pow 1.0 3.0) (pow (cos x) 3.0))
(* (sin x) (+ (* 1.0 1.0) (* (cos x) (+ 1.0 (cos x))))))
(if (<= (/ (- 1.0 (cos x)) (sin x)) 0.00023223782787987925)
(+
(+
(* 0.041666666666666664 (pow x 3.0))
(* 0.004166666666666667 (pow x 5.0)))
(* x 0.5))
(log (exp (/ (- 1.0 (cos x)) (sin x)))))))double code(double x) {
return (((double) (1.0 - ((double) cos(x)))) / ((double) sin(x)));
}
double code(double x) {
double tmp;
if (((((double) (1.0 - ((double) cos(x)))) / ((double) sin(x))) <= -0.013822936471103725)) {
tmp = (((double) (((double) pow(1.0, 3.0)) - ((double) pow(((double) cos(x)), 3.0)))) / ((double) (((double) sin(x)) * ((double) (((double) (1.0 * 1.0)) + ((double) (((double) cos(x)) * ((double) (1.0 + ((double) cos(x)))))))))));
} else {
double tmp_1;
if (((((double) (1.0 - ((double) cos(x)))) / ((double) sin(x))) <= 0.00023223782787987925)) {
tmp_1 = ((double) (((double) (((double) (0.041666666666666664 * ((double) pow(x, 3.0)))) + ((double) (0.004166666666666667 * ((double) pow(x, 5.0)))))) + ((double) (x * 0.5))));
} else {
tmp_1 = ((double) log(((double) exp((((double) (1.0 - ((double) cos(x)))) / ((double) sin(x)))))));
}
tmp = tmp_1;
}
return tmp;
}




Bits error versus x
Results
| Original | 30.7 |
|---|---|
| Target | 0 |
| Herbie | 0.6 |
if (/.f64 (-.f64 1.0 (cos.f64 x)) (sin.f64 x)) < -0.0138229364711037247Initial program 0.9
rmApplied flip3--_binary641.0
Applied associate-/l/_binary641.0
Simplified1.0
if -0.0138229364711037247 < (/.f64 (-.f64 1.0 (cos.f64 x)) (sin.f64 x)) < 2.32237827879879253e-4Initial program 59.9
Taylor expanded around 0 0.1
Simplified0.1
rmApplied associate-+r+_binary640.1
if 2.32237827879879253e-4 < (/.f64 (-.f64 1.0 (cos.f64 x)) (sin.f64 x)) Initial program 1.0
rmApplied add-log-exp_binary641.1
Final simplification0.6
herbie shell --seed 2020210
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2.0))
(/ (- 1.0 (cos x)) (sin x)))