\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.00408598860077935295:\\
\;\;\;\;\log \left(e^{\frac{1}{\sin x} - \frac{\cos x}{\sin x}}\right)\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le -0.0:\\
\;\;\;\;\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}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left({\left(\cos x\right)}^{3}\right)\right)}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}\\
\end{array}double f(double x) {
double r63934 = 1.0;
double r63935 = x;
double r63936 = cos(r63935);
double r63937 = r63934 - r63936;
double r63938 = sin(r63935);
double r63939 = r63937 / r63938;
return r63939;
}
double f(double x) {
double r63940 = 1.0;
double r63941 = x;
double r63942 = cos(r63941);
double r63943 = r63940 - r63942;
double r63944 = sin(r63941);
double r63945 = r63943 / r63944;
double r63946 = -0.004085988600779353;
bool r63947 = r63945 <= r63946;
double r63948 = r63940 / r63944;
double r63949 = r63942 / r63944;
double r63950 = r63948 - r63949;
double r63951 = exp(r63950);
double r63952 = log(r63951);
double r63953 = -0.0;
bool r63954 = r63945 <= r63953;
double r63955 = 0.041666666666666664;
double r63956 = 3.0;
double r63957 = pow(r63941, r63956);
double r63958 = 0.004166666666666667;
double r63959 = 5.0;
double r63960 = pow(r63941, r63959);
double r63961 = 0.5;
double r63962 = r63961 * r63941;
double r63963 = fma(r63958, r63960, r63962);
double r63964 = fma(r63955, r63957, r63963);
double r63965 = pow(r63940, r63956);
double r63966 = pow(r63942, r63956);
double r63967 = log1p(r63966);
double r63968 = expm1(r63967);
double r63969 = r63965 - r63968;
double r63970 = r63940 * r63942;
double r63971 = fma(r63942, r63942, r63970);
double r63972 = fma(r63940, r63940, r63971);
double r63973 = r63972 * r63944;
double r63974 = r63969 / r63973;
double r63975 = r63954 ? r63964 : r63974;
double r63976 = r63947 ? r63952 : r63975;
return r63976;
}




Bits error versus x
| Original | 30.3 |
|---|---|
| Target | 0 |
| Herbie | 0.8 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.004085988600779353Initial program 0.9
rmApplied add-log-exp1.1
rmApplied div-sub1.2
if -0.004085988600779353 < (/ (- 1.0 (cos x)) (sin x)) < -0.0Initial program 60.1
Taylor expanded around 0 0.1
Simplified0.1
if -0.0 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.5
rmApplied flip3--1.6
Applied associate-/l/1.6
Simplified1.7
rmApplied expm1-log1p-u1.7
Final simplification0.8
herbie shell --seed 2020027 +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)))