\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \leq -0.019856612798463034:\\
\;\;\;\;\frac{\frac{\log \left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}{1 \cdot 1 + \cos x \cdot \left(1 + \cos x\right)}}{\sin x}\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \leq 0:\\
\;\;\;\;0.041666666666666664 \cdot {x}^{3} + \left(0.004166666666666667 \cdot {x}^{5} + x \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;e^{\log \left(\frac{1 - \cos x}{\sin x}\right)}\\
\end{array}(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (sin x)))
(FPCore (x)
:precision binary64
(if (<= (/ (- 1.0 (cos x)) (sin x)) -0.019856612798463034)
(/
(/
(log (exp (- (pow 1.0 3.0) (pow (cos x) 3.0))))
(+ (* 1.0 1.0) (* (cos x) (+ 1.0 (cos x)))))
(sin x))
(if (<= (/ (- 1.0 (cos x)) (sin x)) 0.0)
(+
(* 0.041666666666666664 (pow x 3.0))
(+ (* 0.004166666666666667 (pow x 5.0)) (* x 0.5)))
(exp (log (/ (- 1.0 (cos x)) (sin x)))))))double code(double x) {
return (((double) (1.0 - ((double) cos(x)))) / ((double) sin(x)));
}
double code(double x) {
double tmp;
if (((((double) (1.0 - ((double) cos(x)))) / ((double) sin(x))) <= -0.019856612798463034)) {
tmp = ((((double) log(((double) exp(((double) (((double) pow(1.0, 3.0)) - ((double) pow(((double) cos(x)), 3.0)))))))) / ((double) (((double) (1.0 * 1.0)) + ((double) (((double) cos(x)) * ((double) (1.0 + ((double) cos(x))))))))) / ((double) sin(x)));
} else {
double tmp_1;
if (((((double) (1.0 - ((double) cos(x)))) / ((double) sin(x))) <= 0.0)) {
tmp_1 = ((double) (((double) (0.041666666666666664 * ((double) pow(x, 3.0)))) + ((double) (((double) (0.004166666666666667 * ((double) pow(x, 5.0)))) + ((double) (x * 0.5))))));
} else {
tmp_1 = ((double) exp(((double) log((((double) (1.0 - ((double) cos(x)))) / ((double) sin(x)))))));
}
tmp = tmp_1;
}
return tmp;
}




Bits error versus x
Results
| Original | 30.5 |
|---|---|
| Target | 0.0 |
| Herbie | 0.8 |
if (/.f64 (-.f64 1.0 (cos.f64 x)) (sin.f64 x)) < -0.019856612798463034Initial program 0.8
rmApplied flip3--_binary640.9
Simplified0.9
rmApplied add-log-exp_binary640.9
Applied add-log-exp_binary640.9
Applied diff-log_binary641.0
Simplified0.9
if -0.019856612798463034 < (/.f64 (-.f64 1.0 (cos.f64 x)) (sin.f64 x)) < 0.0Initial program 59.9
Taylor expanded around 0 0.4
Simplified0.4
if 0.0 < (/.f64 (-.f64 1.0 (cos.f64 x)) (sin.f64 x)) Initial program 1.5
rmApplied add-exp-log_binary641.5
Applied add-exp-log_binary641.5
Applied div-exp_binary641.6
Simplified1.5
Final simplification0.8
herbie shell --seed 2020205
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2.0))
(/ (- 1.0 (cos x)) (sin x)))