\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0328316610415967866:\\
\;\;\;\;\log \left(\sqrt{e^{\frac{e^{\log \left(1 - \cos x\right)}}{\sin x}}}\right) + \log \left(\sqrt{e^{\frac{e^{\log \left(1 - \cos x\right)}}{\sin x}}}\right)\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 4.742529791284501 \cdot 10^{-8}:\\
\;\;\;\;\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{e^{\log \left(1 - \cos x\right)}}{\sin x}\right)\right)\\
\end{array}double f(double x) {
double r56498 = 1.0;
double r56499 = x;
double r56500 = cos(r56499);
double r56501 = r56498 - r56500;
double r56502 = sin(r56499);
double r56503 = r56501 / r56502;
return r56503;
}
double f(double x) {
double r56504 = 1.0;
double r56505 = x;
double r56506 = cos(r56505);
double r56507 = r56504 - r56506;
double r56508 = sin(r56505);
double r56509 = r56507 / r56508;
double r56510 = -0.03283166104159679;
bool r56511 = r56509 <= r56510;
double r56512 = log(r56507);
double r56513 = exp(r56512);
double r56514 = r56513 / r56508;
double r56515 = exp(r56514);
double r56516 = sqrt(r56515);
double r56517 = log(r56516);
double r56518 = r56517 + r56517;
double r56519 = 4.7425297912845007e-08;
bool r56520 = r56509 <= r56519;
double r56521 = 0.041666666666666664;
double r56522 = 3.0;
double r56523 = pow(r56505, r56522);
double r56524 = 0.004166666666666667;
double r56525 = 5.0;
double r56526 = pow(r56505, r56525);
double r56527 = 0.5;
double r56528 = r56527 * r56505;
double r56529 = fma(r56524, r56526, r56528);
double r56530 = fma(r56521, r56523, r56529);
double r56531 = expm1(r56514);
double r56532 = log1p(r56531);
double r56533 = r56520 ? r56530 : r56532;
double r56534 = r56511 ? r56518 : r56533;
return r56534;
}




Bits error versus x
| Original | 29.9 |
|---|---|
| Target | 0 |
| Herbie | 0.9 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.03283166104159679Initial program 0.8
rmApplied add-log-exp0.8
rmApplied add-exp-log0.8
rmApplied add-sqr-sqrt1.0
Applied log-prod0.9
if -0.03283166104159679 < (/ (- 1.0 (cos x)) (sin x)) < 4.7425297912845007e-08Initial program 59.6
Taylor expanded around 0 0.6
Simplified0.6
if 4.7425297912845007e-08 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.2
rmApplied add-log-exp1.4
rmApplied add-exp-log1.5
rmApplied rem-log-exp1.2
rmApplied log1p-expm1-u1.4
Final simplification0.9
herbie shell --seed 2020064 +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)))