Average Error: 29.5 → 0.6
Time: 55.5s
Precision: 64
Internal precision: 2432
\[\frac{1 - \cos x}{\sin x}\]
⬇
\[\begin{array}{l}
\mathbf{if}\;x \le -3.859884253300168 \cdot 10^{-07}:\\
\;\;\;\;\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)\\
\mathbf{if}\;x \le 3.0084490837019413 \cdot 10^{-50}:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\sin x \cdot \sin x}{1 + \cos x}}{\sin x}\\
\end{array}\]
Target
| Original | 29.5 |
| Comparison | 0.0 |
| Herbie | 0.6 |
\[ \tan \left(\frac{x}{2}\right) \]
Derivation
- Split input into 3 regimes.
-
if x < -3.859884253300168e-07
Initial program 1.3
\[\frac{1 - \cos x}{\sin x}\]
- Using strategy
rm
Applied add-log-exp 1.4
\[\leadsto \color{blue}{\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)}\]
if -3.859884253300168e-07 < x < 3.0084490837019413e-50
Initial program 60.3
\[\frac{1 - \cos x}{\sin x}\]
Taylor expanded around 0 0.0
\[\leadsto \color{blue}{\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)}\]
if 3.0084490837019413e-50 < x
Initial program 7.8
\[\frac{1 - \cos x}{\sin x}\]
- Using strategy
rm
Applied flip-- 8.2
\[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{\sin x}\]
Applied simplify 0.8
\[\leadsto \frac{\frac{\color{blue}{\sin x \cdot \sin x}}{1 + \cos x}}{\sin x}\]
- Recombined 3 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie shell --seed '#(2329929097 3210370195 3111198779 2406363002 3511342718 2136436390)'
(FPCore (x)
:name "tanhf (example 3.4)"
:herbie-expected 1
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))