\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02667679834109110484363647231020877370611:\\
\;\;\;\;\frac{1}{\sin x} - \frac{\cos x}{\sin x}\\
\mathbf{elif}\;x \le 0.02283663453927311723368198670414130901918:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\log \left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}{\cos x \cdot \frac{{\left(\cos x\right)}^{2} - 1 \cdot 1}{\cos x - 1} + 1 \cdot 1}}{\sin x}\\
\end{array}double f(double x) {
double r68424 = 1.0;
double r68425 = x;
double r68426 = cos(r68425);
double r68427 = r68424 - r68426;
double r68428 = sin(r68425);
double r68429 = r68427 / r68428;
return r68429;
}
double f(double x) {
double r68430 = x;
double r68431 = -0.026676798341091105;
bool r68432 = r68430 <= r68431;
double r68433 = 1.0;
double r68434 = sin(r68430);
double r68435 = r68433 / r68434;
double r68436 = cos(r68430);
double r68437 = r68436 / r68434;
double r68438 = r68435 - r68437;
double r68439 = 0.022836634539273117;
bool r68440 = r68430 <= r68439;
double r68441 = 0.041666666666666664;
double r68442 = 3.0;
double r68443 = pow(r68430, r68442);
double r68444 = r68441 * r68443;
double r68445 = 0.004166666666666667;
double r68446 = 5.0;
double r68447 = pow(r68430, r68446);
double r68448 = r68445 * r68447;
double r68449 = 0.5;
double r68450 = r68449 * r68430;
double r68451 = r68448 + r68450;
double r68452 = r68444 + r68451;
double r68453 = pow(r68433, r68442);
double r68454 = pow(r68436, r68442);
double r68455 = r68453 - r68454;
double r68456 = exp(r68455);
double r68457 = log(r68456);
double r68458 = 2.0;
double r68459 = pow(r68436, r68458);
double r68460 = r68433 * r68433;
double r68461 = r68459 - r68460;
double r68462 = r68436 - r68433;
double r68463 = r68461 / r68462;
double r68464 = r68436 * r68463;
double r68465 = r68464 + r68460;
double r68466 = r68457 / r68465;
double r68467 = r68466 / r68434;
double r68468 = r68440 ? r68452 : r68467;
double r68469 = r68432 ? r68438 : r68468;
return r68469;
}




Bits error versus x
Results
| Original | 29.9 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if x < -0.026676798341091105Initial program 0.9
rmApplied div-sub1.1
if -0.026676798341091105 < x < 0.022836634539273117Initial program 60.0
Taylor expanded around 0 0.0
if 0.022836634539273117 < x Initial program 1.0
rmApplied flip3--1.1
Simplified1.1
rmApplied add-log-exp1.1
Applied add-log-exp1.1
Applied diff-log1.2
Simplified1.1
rmApplied flip-+1.1
Simplified1.1
Final simplification0.6
herbie shell --seed 2019322
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))