\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02503568567500278133075575226484943414107:\\
\;\;\;\;\frac{1}{\frac{\sin x}{{1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}\right)\right)} \cdot \left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right)}\\
\mathbf{elif}\;x \le 0.02321496743503861925894682372017996385694:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{24}, {x}^{3}, \mathsf{fma}\left(\frac{1}{240}, {x}^{5}, \frac{1}{2} \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\sin x}{\log \left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)} \cdot \left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right)}\\
\end{array}double f(double x) {
double r68593 = 1.0;
double r68594 = x;
double r68595 = cos(r68594);
double r68596 = r68593 - r68595;
double r68597 = sin(r68594);
double r68598 = r68596 / r68597;
return r68598;
}
double f(double x) {
double r68599 = x;
double r68600 = -0.02503568567500278;
bool r68601 = r68599 <= r68600;
double r68602 = 1.0;
double r68603 = sin(r68599);
double r68604 = 1.0;
double r68605 = 3.0;
double r68606 = pow(r68604, r68605);
double r68607 = cos(r68599);
double r68608 = pow(r68607, r68605);
double r68609 = pow(r68608, r68605);
double r68610 = cbrt(r68609);
double r68611 = log1p(r68610);
double r68612 = expm1(r68611);
double r68613 = r68606 - r68612;
double r68614 = r68603 / r68613;
double r68615 = r68604 * r68604;
double r68616 = r68607 * r68607;
double r68617 = r68604 * r68607;
double r68618 = r68616 + r68617;
double r68619 = r68615 + r68618;
double r68620 = r68614 * r68619;
double r68621 = r68602 / r68620;
double r68622 = 0.02321496743503862;
bool r68623 = r68599 <= r68622;
double r68624 = 0.041666666666666664;
double r68625 = pow(r68599, r68605);
double r68626 = 0.004166666666666667;
double r68627 = 5.0;
double r68628 = pow(r68599, r68627);
double r68629 = 0.5;
double r68630 = r68629 * r68599;
double r68631 = fma(r68626, r68628, r68630);
double r68632 = fma(r68624, r68625, r68631);
double r68633 = r68606 - r68608;
double r68634 = exp(r68633);
double r68635 = log(r68634);
double r68636 = r68603 / r68635;
double r68637 = r68636 * r68619;
double r68638 = r68602 / r68637;
double r68639 = r68623 ? r68632 : r68638;
double r68640 = r68601 ? r68621 : r68639;
return r68640;
}




Bits error versus x
| Original | 30.3 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if x < -0.02503568567500278Initial program 0.9
rmApplied clear-num1.0
rmApplied flip3--1.0
Applied associate-/r/1.0
rmApplied expm1-log1p-u1.1
rmApplied add-cbrt-cube1.1
Simplified1.1
if -0.02503568567500278 < x < 0.02321496743503862Initial program 59.8
Taylor expanded around 0 0.0
Simplified0.0
if 0.02321496743503862 < x Initial program 0.9
rmApplied clear-num1.0
rmApplied flip3--1.1
Applied associate-/r/1.0
rmApplied add-log-exp1.1
Applied add-log-exp1.1
Applied diff-log1.2
Simplified1.1
Final simplification0.6
herbie shell --seed 2019362 +o rules:numerics
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))