\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.01816359460916088:\\
\;\;\;\;\frac{1}{\sin x} - \cos x \cdot \frac{1}{\sin x}\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 6.0277248497108966 \cdot 10^{-4}:\\
\;\;\;\;0.041666666666666671 \cdot {x}^{3} + \left(0.00416666666666666661 \cdot {x}^{5} + 0.5 \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{\frac{e^{\log \left(1 - \cos x\right)}}{\sin x}}\right)\\
\end{array}double f(double x) {
double r56043 = 1.0;
double r56044 = x;
double r56045 = cos(r56044);
double r56046 = r56043 - r56045;
double r56047 = sin(r56044);
double r56048 = r56046 / r56047;
return r56048;
}
double f(double x) {
double r56049 = 1.0;
double r56050 = x;
double r56051 = cos(r56050);
double r56052 = r56049 - r56051;
double r56053 = sin(r56050);
double r56054 = r56052 / r56053;
double r56055 = -0.01816359460916088;
bool r56056 = r56054 <= r56055;
double r56057 = r56049 / r56053;
double r56058 = 1.0;
double r56059 = r56058 / r56053;
double r56060 = r56051 * r56059;
double r56061 = r56057 - r56060;
double r56062 = 0.0006027724849710897;
bool r56063 = r56054 <= r56062;
double r56064 = 0.04166666666666667;
double r56065 = 3.0;
double r56066 = pow(r56050, r56065);
double r56067 = r56064 * r56066;
double r56068 = 0.004166666666666667;
double r56069 = 5.0;
double r56070 = pow(r56050, r56069);
double r56071 = r56068 * r56070;
double r56072 = 0.5;
double r56073 = r56072 * r56050;
double r56074 = r56071 + r56073;
double r56075 = r56067 + r56074;
double r56076 = log(r56052);
double r56077 = exp(r56076);
double r56078 = r56077 / r56053;
double r56079 = exp(r56078);
double r56080 = log(r56079);
double r56081 = r56063 ? r56075 : r56080;
double r56082 = r56056 ? r56061 : r56081;
return r56082;
}




Bits error versus x
Results
| Original | 30.3 |
|---|---|
| Target | 0.0 |
| Herbie | 0.7 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.01816359460916088Initial program 0.8
rmApplied div-sub1.0
rmApplied div-inv0.9
if -0.01816359460916088 < (/ (- 1.0 (cos x)) (sin x)) < 0.0006027724849710897Initial program 59.6
rmApplied div-sub59.6
Taylor expanded around 0 0.5
if 0.0006027724849710897 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.0
rmApplied add-log-exp1.1
rmApplied add-exp-log1.1
Final simplification0.7
herbie shell --seed 2020034
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))