\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0201136423449840597:\\
\;\;\;\;\frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{\frac{\sin x}{\sqrt{1 - \cos x}}}\\
\mathbf{elif}\;x \le 0.0224978003073234255:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - \cos x\right) \cdot \frac{1}{\sin x}\\
\end{array}double code(double x) {
return ((1.0 - cos(x)) / sin(x));
}
double code(double x) {
double VAR;
if ((x <= -0.02011364234498406)) {
VAR = (sqrt(log(exp((1.0 - cos(x))))) / (sin(x) / sqrt((1.0 - cos(x)))));
} else {
double VAR_1;
if ((x <= 0.022497800307323425)) {
VAR_1 = ((0.041666666666666664 * pow(x, 3.0)) + ((0.004166666666666667 * pow(x, 5.0)) + (0.5 * x)));
} else {
VAR_1 = ((1.0 - cos(x)) * (1.0 / sin(x)));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus x
Results
| Original | 29.5 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if x < -0.02011364234498406Initial program 1.0
rmApplied add-log-exp1.2
Applied add-log-exp1.2
Applied diff-log1.4
Simplified1.2
rmApplied add-sqr-sqrt1.4
Applied associate-/l*1.3
Simplified1.2
if -0.02011364234498406 < x < 0.022497800307323425Initial program 59.8
Taylor expanded around 0 0.0
if 0.022497800307323425 < x Initial program 0.9
rmApplied div-inv1.0
Final simplification0.6
herbie shell --seed 2020102
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))