\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0161525551537130101:\\
\;\;\;\;\frac{\frac{\log \left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}}{\sin x}\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 8.0836609335251401 \cdot 10^{-5}:\\
\;\;\;\;\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{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \cos x \cdot \frac{1 \cdot 1 - {\left(\cos x\right)}^{2}}{1 - \cos x}\right)}}{\sin x}\\
\end{array}double f(double x) {
double r66561 = 1.0;
double r66562 = x;
double r66563 = cos(r66562);
double r66564 = r66561 - r66563;
double r66565 = sin(r66562);
double r66566 = r66564 / r66565;
return r66566;
}
double f(double x) {
double r66567 = 1.0;
double r66568 = x;
double r66569 = cos(r66568);
double r66570 = r66567 - r66569;
double r66571 = sin(r66568);
double r66572 = r66570 / r66571;
double r66573 = -0.01615255515371301;
bool r66574 = r66572 <= r66573;
double r66575 = 3.0;
double r66576 = pow(r66567, r66575);
double r66577 = pow(r66569, r66575);
double r66578 = r66576 - r66577;
double r66579 = exp(r66578);
double r66580 = log(r66579);
double r66581 = r66567 + r66569;
double r66582 = r66569 * r66581;
double r66583 = fma(r66567, r66567, r66582);
double r66584 = r66580 / r66583;
double r66585 = r66584 / r66571;
double r66586 = 8.08366093352514e-05;
bool r66587 = r66572 <= r66586;
double r66588 = 0.041666666666666664;
double r66589 = pow(r66568, r66575);
double r66590 = 0.004166666666666667;
double r66591 = 5.0;
double r66592 = pow(r66568, r66591);
double r66593 = 0.5;
double r66594 = r66593 * r66568;
double r66595 = fma(r66590, r66592, r66594);
double r66596 = fma(r66588, r66589, r66595);
double r66597 = r66567 * r66567;
double r66598 = 2.0;
double r66599 = pow(r66569, r66598);
double r66600 = r66597 - r66599;
double r66601 = r66600 / r66570;
double r66602 = r66569 * r66601;
double r66603 = fma(r66567, r66567, r66602);
double r66604 = r66578 / r66603;
double r66605 = r66604 / r66571;
double r66606 = r66587 ? r66596 : r66605;
double r66607 = r66574 ? r66585 : r66606;
return r66607;
}




Bits error versus x
| Original | 29.7 |
|---|---|
| Target | 0.0 |
| Herbie | 0.7 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.01615255515371301Initial program 0.8
rmApplied flip3--0.9
Simplified0.9
rmApplied add-log-exp1.0
Applied add-log-exp1.0
Applied diff-log1.0
Simplified0.9
if -0.01615255515371301 < (/ (- 1.0 (cos x)) (sin x)) < 8.08366093352514e-05Initial program 59.7
Taylor expanded around 0 0.4
Simplified0.4
if 8.08366093352514e-05 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.0
rmApplied flip3--1.1
Simplified1.1
rmApplied flip-+1.1
Simplified1.1
Final simplification0.7
herbie shell --seed 2020043 +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)))