\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0190087476176216581:\\
\;\;\;\;\frac{1}{\frac{\sin x}{1 - \cos x}}\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 4.47527012274922384 \cdot 10^{-5}:\\
\;\;\;\;\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(\log \left(e^{1 - \cos x}\right)\right)}}{\sin x}\\
\end{array}double f(double x) {
double r62615 = 1.0;
double r62616 = x;
double r62617 = cos(r62616);
double r62618 = r62615 - r62617;
double r62619 = sin(r62616);
double r62620 = r62618 / r62619;
return r62620;
}
double f(double x) {
double r62621 = 1.0;
double r62622 = x;
double r62623 = cos(r62622);
double r62624 = r62621 - r62623;
double r62625 = sin(r62622);
double r62626 = r62624 / r62625;
double r62627 = -0.019008747617621658;
bool r62628 = r62626 <= r62627;
double r62629 = 1.0;
double r62630 = r62625 / r62624;
double r62631 = r62629 / r62630;
double r62632 = 4.475270122749224e-05;
bool r62633 = r62626 <= r62632;
double r62634 = 0.041666666666666664;
double r62635 = 3.0;
double r62636 = pow(r62622, r62635);
double r62637 = r62634 * r62636;
double r62638 = 0.004166666666666667;
double r62639 = 5.0;
double r62640 = pow(r62622, r62639);
double r62641 = r62638 * r62640;
double r62642 = 0.5;
double r62643 = r62642 * r62622;
double r62644 = r62641 + r62643;
double r62645 = r62637 + r62644;
double r62646 = exp(r62624);
double r62647 = log(r62646);
double r62648 = log(r62647);
double r62649 = exp(r62648);
double r62650 = r62649 / r62625;
double r62651 = r62633 ? r62645 : r62650;
double r62652 = r62628 ? r62631 : r62651;
return r62652;
}




Bits error versus x
Results
| Original | 30.2 |
|---|---|
| Target | 0 |
| Herbie | 0.7 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.019008747617621658Initial program 0.8
rmApplied clear-num0.8
if -0.019008747617621658 < (/ (- 1.0 (cos x)) (sin x)) < 4.475270122749224e-05Initial program 59.6
Taylor expanded around 0 0.4
if 4.475270122749224e-05 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.0
rmApplied add-exp-log1.0
rmApplied add-log-exp1.2
Applied add-log-exp1.2
Applied diff-log1.4
Simplified1.2
Final simplification0.7
herbie shell --seed 2020021
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))