\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0328316610415967866 \lor \neg \left(\frac{1 - \cos x}{\sin x} \le 4.742529791284501 \cdot 10^{-8}\right):\\
\;\;\;\;\log \left(\sqrt{e^{\frac{e^{\log \left(1 - \cos x\right)}}{\sin x}}}\right) + \frac{\frac{1}{\sin x}}{2} \cdot \left(1 - \cos x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\end{array}double f(double x) {
double r82425 = 1.0;
double r82426 = x;
double r82427 = cos(r82426);
double r82428 = r82425 - r82427;
double r82429 = sin(r82426);
double r82430 = r82428 / r82429;
return r82430;
}
double f(double x) {
double r82431 = 1.0;
double r82432 = x;
double r82433 = cos(r82432);
double r82434 = r82431 - r82433;
double r82435 = sin(r82432);
double r82436 = r82434 / r82435;
double r82437 = -0.03283166104159679;
bool r82438 = r82436 <= r82437;
double r82439 = 4.7425297912845007e-08;
bool r82440 = r82436 <= r82439;
double r82441 = !r82440;
bool r82442 = r82438 || r82441;
double r82443 = log(r82434);
double r82444 = exp(r82443);
double r82445 = r82444 / r82435;
double r82446 = exp(r82445);
double r82447 = sqrt(r82446);
double r82448 = log(r82447);
double r82449 = 1.0;
double r82450 = r82449 / r82435;
double r82451 = 2.0;
double r82452 = r82450 / r82451;
double r82453 = r82452 * r82434;
double r82454 = r82448 + r82453;
double r82455 = 0.041666666666666664;
double r82456 = 3.0;
double r82457 = pow(r82432, r82456);
double r82458 = r82455 * r82457;
double r82459 = 0.004166666666666667;
double r82460 = 5.0;
double r82461 = pow(r82432, r82460);
double r82462 = r82459 * r82461;
double r82463 = 0.5;
double r82464 = r82463 * r82432;
double r82465 = r82462 + r82464;
double r82466 = r82458 + r82465;
double r82467 = r82442 ? r82454 : r82466;
return r82467;
}




Bits error versus x
Results
| Original | 29.9 |
|---|---|
| Target | 0 |
| Herbie | 0.9 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.03283166104159679 or 4.7425297912845007e-08 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.0
rmApplied add-log-exp1.1
rmApplied add-exp-log1.1
rmApplied add-sqr-sqrt1.4
Applied log-prod1.3
rmApplied div-inv1.3
Applied exp-prod1.3
Applied sqrt-pow11.3
Applied log-pow1.2
Simplified1.2
if -0.03283166104159679 < (/ (- 1.0 (cos x)) (sin x)) < 4.7425297912845007e-08Initial program 59.6
Taylor expanded around 0 0.6
Final simplification0.9
herbie shell --seed 2020064
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))