\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0350875129794391352:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right) \cdot \sin x}\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 0.00153222520976908894:\\
\;\;\;\;\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}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1 - \cos x}{\sin x}\right)\right)\\
\end{array}double f(double x) {
double r63384 = 1.0;
double r63385 = x;
double r63386 = cos(r63385);
double r63387 = r63384 - r63386;
double r63388 = sin(r63385);
double r63389 = r63387 / r63388;
return r63389;
}
double f(double x) {
double r63390 = 1.0;
double r63391 = x;
double r63392 = cos(r63391);
double r63393 = r63390 - r63392;
double r63394 = sin(r63391);
double r63395 = r63393 / r63394;
double r63396 = -0.035087512979439135;
bool r63397 = r63395 <= r63396;
double r63398 = 3.0;
double r63399 = pow(r63390, r63398);
double r63400 = pow(r63392, r63398);
double r63401 = r63399 - r63400;
double r63402 = r63390 + r63392;
double r63403 = r63390 * r63390;
double r63404 = fma(r63392, r63402, r63403);
double r63405 = r63404 * r63394;
double r63406 = r63401 / r63405;
double r63407 = 0.001532225209769089;
bool r63408 = r63395 <= r63407;
double r63409 = 0.041666666666666664;
double r63410 = pow(r63391, r63398);
double r63411 = 0.004166666666666667;
double r63412 = 5.0;
double r63413 = pow(r63391, r63412);
double r63414 = 0.5;
double r63415 = r63414 * r63391;
double r63416 = fma(r63411, r63413, r63415);
double r63417 = fma(r63409, r63410, r63416);
double r63418 = expm1(r63395);
double r63419 = log1p(r63418);
double r63420 = r63408 ? r63417 : r63419;
double r63421 = r63397 ? r63406 : r63420;
return r63421;
}




Bits error versus x
| Original | 30.3 |
|---|---|
| Target | 0 |
| Herbie | 0.8 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.035087512979439135Initial program 0.7
rmApplied clear-num0.8
rmApplied add-log-exp1.0
rmApplied associate-/r/1.0
Applied exp-prod1.0
Applied log-pow0.9
Simplified0.8
rmApplied flip3--0.9
Applied frac-times0.9
Simplified0.9
Simplified0.8
if -0.035087512979439135 < (/ (- 1.0 (cos x)) (sin x)) < 0.001532225209769089Initial program 59.4
Taylor expanded around 0 0.7
Simplified0.7
if 0.001532225209769089 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.0
rmApplied log1p-expm1-u1.0
Final simplification0.8
herbie shell --seed 2020039 +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)))