\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0391915361306189591328319465901586227119:\\
\;\;\;\;\frac{1}{1 + \cos x} \cdot \left(\left(\left(1 + \cos x\right) \cdot \left(1 - \cos x\right)\right) \cdot \frac{1}{\sin x}\right)\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 5.238158504786694352056697354669267951977 \cdot 10^{-4}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{24}, {x}^{3}, \mathsf{fma}\left({x}^{5}, \frac{1}{240}, x \cdot \frac{1}{2}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left({\left(e^{\frac{1}{\sin x}}\right)}^{\left(1 - \cos x\right)}\right)\\
\end{array}double f(double x) {
double r37351 = 1.0;
double r37352 = x;
double r37353 = cos(r37352);
double r37354 = r37351 - r37353;
double r37355 = sin(r37352);
double r37356 = r37354 / r37355;
return r37356;
}
double f(double x) {
double r37357 = 1.0;
double r37358 = x;
double r37359 = cos(r37358);
double r37360 = r37357 - r37359;
double r37361 = sin(r37358);
double r37362 = r37360 / r37361;
double r37363 = -0.03919153613061896;
bool r37364 = r37362 <= r37363;
double r37365 = 1.0;
double r37366 = r37357 + r37359;
double r37367 = r37365 / r37366;
double r37368 = r37366 * r37360;
double r37369 = r37365 / r37361;
double r37370 = r37368 * r37369;
double r37371 = r37367 * r37370;
double r37372 = 0.0005238158504786694;
bool r37373 = r37362 <= r37372;
double r37374 = 0.041666666666666664;
double r37375 = 3.0;
double r37376 = pow(r37358, r37375);
double r37377 = 5.0;
double r37378 = pow(r37358, r37377);
double r37379 = 0.004166666666666667;
double r37380 = 0.5;
double r37381 = r37358 * r37380;
double r37382 = fma(r37378, r37379, r37381);
double r37383 = fma(r37374, r37376, r37382);
double r37384 = exp(r37369);
double r37385 = pow(r37384, r37360);
double r37386 = log(r37385);
double r37387 = r37373 ? r37383 : r37386;
double r37388 = r37364 ? r37371 : r37387;
return r37388;
}




Bits error versus x
| Original | 30.3 |
|---|---|
| Target | 0.0 |
| Herbie | 1.0 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.03919153613061896Initial program 0.7
rmApplied clear-num0.8
rmApplied flip--1.2
Applied associate-/r/1.3
Applied add-cube-cbrt1.3
Applied times-frac1.3
Simplified0.9
Simplified0.9
if -0.03919153613061896 < (/ (- 1.0 (cos x)) (sin x)) < 0.0005238158504786694Initial program 59.2
Taylor expanded around 0 0.9
Simplified0.9
if 0.0005238158504786694 < (/ (- 1.0 (cos x)) (sin x)) Initial program 0.9
rmApplied clear-num1.0
rmApplied add-log-exp1.0
Simplified1.1
Final simplification1.0
herbie shell --seed 2019194 +o rules:numerics
(FPCore (x)
:name "tanhf (example 3.4)"
:herbie-expected 2
:herbie-target
(tan (/ x 2.0))
(/ (- 1.0 (cos x)) (sin x)))