\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.01102096909057656733132990467538547818549:\\
\;\;\;\;\log \left(\sqrt{e^{\frac{1 - \cos x}{\sin x}}}\right) + \log \left(\sqrt{e^{\frac{1 - \cos x}{\sin x}}}\right)\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 7.852408454565184712722891724467899621231 \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{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(\cos x \cdot \frac{{\left(\cos x\right)}^{2} - 1 \cdot 1}{\cos x - 1} + 1 \cdot 1\right) \cdot \sin x}\\
\end{array}double f(double x) {
double r44216 = 1.0;
double r44217 = x;
double r44218 = cos(r44217);
double r44219 = r44216 - r44218;
double r44220 = sin(r44217);
double r44221 = r44219 / r44220;
return r44221;
}
double f(double x) {
double r44222 = 1.0;
double r44223 = x;
double r44224 = cos(r44223);
double r44225 = r44222 - r44224;
double r44226 = sin(r44223);
double r44227 = r44225 / r44226;
double r44228 = -0.011020969090576567;
bool r44229 = r44227 <= r44228;
double r44230 = exp(r44227);
double r44231 = sqrt(r44230);
double r44232 = log(r44231);
double r44233 = r44232 + r44232;
double r44234 = 7.852408454565185e-05;
bool r44235 = r44227 <= r44234;
double r44236 = 0.041666666666666664;
double r44237 = 3.0;
double r44238 = pow(r44223, r44237);
double r44239 = r44236 * r44238;
double r44240 = 0.004166666666666667;
double r44241 = 5.0;
double r44242 = pow(r44223, r44241);
double r44243 = r44240 * r44242;
double r44244 = 0.5;
double r44245 = r44244 * r44223;
double r44246 = r44243 + r44245;
double r44247 = r44239 + r44246;
double r44248 = pow(r44222, r44237);
double r44249 = pow(r44224, r44237);
double r44250 = r44248 - r44249;
double r44251 = 2.0;
double r44252 = pow(r44224, r44251);
double r44253 = r44222 * r44222;
double r44254 = r44252 - r44253;
double r44255 = r44224 - r44222;
double r44256 = r44254 / r44255;
double r44257 = r44224 * r44256;
double r44258 = r44257 + r44253;
double r44259 = r44258 * r44226;
double r44260 = r44250 / r44259;
double r44261 = r44235 ? r44247 : r44260;
double r44262 = r44229 ? r44233 : r44261;
return r44262;
}




Bits error versus x
Results
| Original | 29.5 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.011020969090576567Initial program 0.8
rmApplied add-log-exp0.9
rmApplied add-sqr-sqrt1.1
Applied log-prod1.1
if -0.011020969090576567 < (/ (- 1.0 (cos x)) (sin x)) < 7.852408454565185e-05Initial program 60.0
Taylor expanded around 0 0.2
if 7.852408454565185e-05 < (/ (- 1.0 (cos x)) (sin x)) Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied flip-+1.0
Simplified1.0
Final simplification0.6
herbie shell --seed 2020002
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))