\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02158053869181151412925956378785485867411:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(-{\left(\cos x\right)}^{3}, {\left(\cos x\right)}^{3}, {1}^{6}\right)}{{1}^{3} + {\left(\cos x\right)}^{3}}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}\\
\mathbf{elif}\;x \le 0.02151506493380623760702796687382942764089:\\
\;\;\;\;\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} - \sqrt[3]{\mathsf{log1p}\left(\mathsf{expm1}\left({\left({\left(\cos x\right)}^{3}\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 r68514 = 1.0;
double r68515 = x;
double r68516 = cos(r68515);
double r68517 = r68514 - r68516;
double r68518 = sin(r68515);
double r68519 = r68517 / r68518;
return r68519;
}
double f(double x) {
double r68520 = x;
double r68521 = -0.021580538691811514;
bool r68522 = r68520 <= r68521;
double r68523 = cos(r68520);
double r68524 = 3.0;
double r68525 = pow(r68523, r68524);
double r68526 = -r68525;
double r68527 = 1.0;
double r68528 = 6.0;
double r68529 = pow(r68527, r68528);
double r68530 = fma(r68526, r68525, r68529);
double r68531 = pow(r68527, r68524);
double r68532 = r68531 + r68525;
double r68533 = r68530 / r68532;
double r68534 = r68527 * r68523;
double r68535 = fma(r68523, r68523, r68534);
double r68536 = fma(r68527, r68527, r68535);
double r68537 = sin(r68520);
double r68538 = r68536 * r68537;
double r68539 = r68533 / r68538;
double r68540 = 0.021515064933806238;
bool r68541 = r68520 <= r68540;
double r68542 = 0.041666666666666664;
double r68543 = pow(r68520, r68524);
double r68544 = 0.004166666666666667;
double r68545 = 5.0;
double r68546 = pow(r68520, r68545);
double r68547 = 0.5;
double r68548 = r68547 * r68520;
double r68549 = fma(r68544, r68546, r68548);
double r68550 = fma(r68542, r68543, r68549);
double r68551 = pow(r68525, r68524);
double r68552 = expm1(r68551);
double r68553 = log1p(r68552);
double r68554 = cbrt(r68553);
double r68555 = r68531 - r68554;
double r68556 = r68555 / r68538;
double r68557 = r68541 ? r68550 : r68556;
double r68558 = r68522 ? r68539 : r68557;
return r68558;
}




Bits error versus x
| Original | 29.5 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.021580538691811514Initial program 0.8
rmApplied flip3--0.9
Applied associate-/l/0.9
Simplified0.9
rmApplied flip--1.3
Simplified1.0
if -0.021580538691811514 < x < 0.021515064933806238Initial program 60.0
Taylor expanded around 0 0.0
Simplified0.0
if 0.021515064933806238 < x Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied add-cbrt-cube1.0
Simplified1.0
rmApplied log1p-expm1-u1.0
Final simplification0.5
herbie shell --seed 2020002 +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)))