\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0205201251872303252:\\
\;\;\;\;\frac{e^{\log \left({1}^{3} - {\left(\cos x\right)}^{3}\right) - \log \left(\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)\right)}}{\sin x}\\
\mathbf{elif}\;x \le 0.0151211545277095353:\\
\;\;\;\;\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{e^{\log \left(\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, \frac{1 \cdot 1 - {\left(\cos x\right)}^{2}}{1 - \cos x}, 1 \cdot 1\right)}\right)}}{\sin x}\\
\end{array}double f(double x) {
double r59950 = 1.0;
double r59951 = x;
double r59952 = cos(r59951);
double r59953 = r59950 - r59952;
double r59954 = sin(r59951);
double r59955 = r59953 / r59954;
return r59955;
}
double f(double x) {
double r59956 = x;
double r59957 = -0.020520125187230325;
bool r59958 = r59956 <= r59957;
double r59959 = 1.0;
double r59960 = 3.0;
double r59961 = pow(r59959, r59960);
double r59962 = cos(r59956);
double r59963 = pow(r59962, r59960);
double r59964 = r59961 - r59963;
double r59965 = log(r59964);
double r59966 = r59959 + r59962;
double r59967 = r59959 * r59959;
double r59968 = fma(r59962, r59966, r59967);
double r59969 = log(r59968);
double r59970 = r59965 - r59969;
double r59971 = exp(r59970);
double r59972 = sin(r59956);
double r59973 = r59971 / r59972;
double r59974 = 0.015121154527709535;
bool r59975 = r59956 <= r59974;
double r59976 = 0.041666666666666664;
double r59977 = pow(r59956, r59960);
double r59978 = 0.004166666666666667;
double r59979 = 5.0;
double r59980 = pow(r59956, r59979);
double r59981 = 0.5;
double r59982 = r59981 * r59956;
double r59983 = fma(r59978, r59980, r59982);
double r59984 = fma(r59976, r59977, r59983);
double r59985 = 2.0;
double r59986 = pow(r59962, r59985);
double r59987 = r59967 - r59986;
double r59988 = r59959 - r59962;
double r59989 = r59987 / r59988;
double r59990 = fma(r59962, r59989, r59967);
double r59991 = r59964 / r59990;
double r59992 = log(r59991);
double r59993 = exp(r59992);
double r59994 = r59993 / r59972;
double r59995 = r59975 ? r59984 : r59994;
double r59996 = r59958 ? r59973 : r59995;
return r59996;
}




Bits error versus x
| Original | 30.4 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.020520125187230325Initial program 1.0
rmApplied flip3--1.1
Simplified1.1
rmApplied add-exp-log1.1
Applied add-exp-log1.1
Applied div-exp1.1
Simplified1.1
rmApplied log-div1.1
if -0.020520125187230325 < x < 0.015121154527709535Initial program 59.9
Taylor expanded around 0 0.0
Simplified0.0
if 0.015121154527709535 < x Initial program 0.9
rmApplied flip3--1.0
Simplified1.0
rmApplied add-exp-log1.0
Applied add-exp-log1.0
Applied div-exp1.1
Simplified1.0
rmApplied flip-+1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2020020 +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)))