\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.01419821707705988360348481336359327542596:\\
\;\;\;\;\frac{\left({1}^{3} - {\left(\cos x\right)}^{3}\right) \cdot \frac{1}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 2.589932435073376851492402139776061176235 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{24}, {x}^{3}, \mathsf{fma}\left({x}^{5}, \frac{1}{240}, \frac{1}{2} \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{e^{\log \left({1}^{3} - \log \left(e^{{\left(\cos x\right)}^{3}}\right)\right)}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}\\
\end{array}double f(double x) {
double r81019 = 1.0;
double r81020 = x;
double r81021 = cos(r81020);
double r81022 = r81019 - r81021;
double r81023 = sin(r81020);
double r81024 = r81022 / r81023;
return r81024;
}
double f(double x) {
double r81025 = 1.0;
double r81026 = x;
double r81027 = cos(r81026);
double r81028 = r81025 - r81027;
double r81029 = sin(r81026);
double r81030 = r81028 / r81029;
double r81031 = -0.014198217077059884;
bool r81032 = r81030 <= r81031;
double r81033 = 3.0;
double r81034 = pow(r81025, r81033);
double r81035 = pow(r81027, r81033);
double r81036 = r81034 - r81035;
double r81037 = 1.0;
double r81038 = r81025 + r81027;
double r81039 = r81025 * r81025;
double r81040 = fma(r81027, r81038, r81039);
double r81041 = r81037 / r81040;
double r81042 = r81036 * r81041;
double r81043 = r81042 / r81029;
double r81044 = 2.589932435073377e-05;
bool r81045 = r81030 <= r81044;
double r81046 = 0.041666666666666664;
double r81047 = pow(r81026, r81033);
double r81048 = 5.0;
double r81049 = pow(r81026, r81048);
double r81050 = 0.004166666666666667;
double r81051 = 0.5;
double r81052 = r81051 * r81026;
double r81053 = fma(r81049, r81050, r81052);
double r81054 = fma(r81046, r81047, r81053);
double r81055 = exp(r81035);
double r81056 = log(r81055);
double r81057 = r81034 - r81056;
double r81058 = log(r81057);
double r81059 = exp(r81058);
double r81060 = r81059 / r81040;
double r81061 = r81060 / r81029;
double r81062 = r81045 ? r81054 : r81061;
double r81063 = r81032 ? r81043 : r81062;
return r81063;
}




Bits error versus x
| Original | 30.2 |
|---|---|
| Target | 0.0 |
| Herbie | 0.7 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.014198217077059884Initial program 0.8
rmApplied flip3--0.9
Simplified0.9
rmApplied div-inv1.0
Simplified1.0
if -0.014198217077059884 < (/ (- 1.0 (cos x)) (sin x)) < 2.589932435073377e-05Initial program 59.8
Taylor expanded around 0 0.3
Simplified0.3
if 2.589932435073377e-05 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.1
rmApplied flip3--1.2
Simplified1.2
rmApplied add-exp-log1.2
rmApplied add-log-exp1.3
Final simplification0.7
herbie shell --seed 2019174 +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)))