\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 r101426 = 1.0;
double r101427 = x;
double r101428 = cos(r101427);
double r101429 = r101426 - r101428;
double r101430 = sin(r101427);
double r101431 = r101429 / r101430;
return r101431;
}
double f(double x) {
double r101432 = x;
double r101433 = -0.026676798341091105;
bool r101434 = r101432 <= r101433;
double r101435 = 1.0;
double r101436 = sin(r101432);
double r101437 = r101435 / r101436;
double r101438 = cos(r101432);
double r101439 = r101438 / r101436;
double r101440 = r101437 - r101439;
double r101441 = 0.022836634539273117;
bool r101442 = r101432 <= r101441;
double r101443 = 0.041666666666666664;
double r101444 = 3.0;
double r101445 = pow(r101432, r101444);
double r101446 = r101443 * r101445;
double r101447 = 0.004166666666666667;
double r101448 = 5.0;
double r101449 = pow(r101432, r101448);
double r101450 = r101447 * r101449;
double r101451 = 0.5;
double r101452 = r101451 * r101432;
double r101453 = r101450 + r101452;
double r101454 = r101446 + r101453;
double r101455 = pow(r101435, r101444);
double r101456 = pow(r101438, r101444);
double r101457 = r101455 - r101456;
double r101458 = exp(r101457);
double r101459 = log(r101458);
double r101460 = 2.0;
double r101461 = pow(r101438, r101460);
double r101462 = r101435 * r101435;
double r101463 = r101461 - r101462;
double r101464 = r101438 - r101435;
double r101465 = r101463 / r101464;
double r101466 = r101438 * r101465;
double r101467 = r101466 + r101462;
double r101468 = r101459 / r101467;
double r101469 = r101468 / r101436;
double r101470 = r101442 ? r101454 : r101469;
double r101471 = r101434 ? r101440 : r101470;
return r101471;
}




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)))