\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0242859294884205483:\\
\;\;\;\;\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\sin x}}{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}\\
\mathbf{elif}\;x \le 0.0212898443058771626:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{\log \left(\sqrt{1 - \cos x}\right)}}{\frac{\sin x}{\sqrt{1 - \cos x}}}\\
\end{array}double f(double x) {
double r43344 = 1.0;
double r43345 = x;
double r43346 = cos(r43345);
double r43347 = r43344 - r43346;
double r43348 = sin(r43345);
double r43349 = r43347 / r43348;
return r43349;
}
double f(double x) {
double r43350 = x;
double r43351 = -0.02428592948842055;
bool r43352 = r43350 <= r43351;
double r43353 = 1.0;
double r43354 = 3.0;
double r43355 = pow(r43353, r43354);
double r43356 = cos(r43350);
double r43357 = pow(r43356, r43354);
double r43358 = r43355 - r43357;
double r43359 = sin(r43350);
double r43360 = r43358 / r43359;
double r43361 = r43353 * r43353;
double r43362 = r43356 * r43356;
double r43363 = r43353 * r43356;
double r43364 = r43362 + r43363;
double r43365 = r43361 + r43364;
double r43366 = r43360 / r43365;
double r43367 = 0.021289844305877163;
bool r43368 = r43350 <= r43367;
double r43369 = 0.041666666666666664;
double r43370 = pow(r43350, r43354);
double r43371 = r43369 * r43370;
double r43372 = 0.004166666666666667;
double r43373 = 5.0;
double r43374 = pow(r43350, r43373);
double r43375 = r43372 * r43374;
double r43376 = 0.5;
double r43377 = r43376 * r43350;
double r43378 = r43375 + r43377;
double r43379 = r43371 + r43378;
double r43380 = r43353 - r43356;
double r43381 = sqrt(r43380);
double r43382 = log(r43381);
double r43383 = exp(r43382);
double r43384 = r43359 / r43381;
double r43385 = r43383 / r43384;
double r43386 = r43368 ? r43379 : r43385;
double r43387 = r43352 ? r43366 : r43386;
return r43387;
}




Bits error versus x
Results
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if x < -0.02428592948842055Initial program 0.9
rmApplied div-inv1.0
rmApplied flip3--1.1
Applied associate-*l/1.1
Simplified1.0
if -0.02428592948842055 < x < 0.021289844305877163Initial program 59.8
Taylor expanded around 0 0.0
if 0.021289844305877163 < x Initial program 0.9
rmApplied add-exp-log0.9
rmApplied add-sqr-sqrt1.2
Applied log-prod1.2
Applied exp-sum1.2
Applied associate-/l*1.2
Simplified1.2
Final simplification0.6
herbie shell --seed 2020081
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))