Average Error: 29.7 → 0.5
Time: 34.9s
Precision: 64
Internal precision: 2432
\[\frac{1 - \cos x}{\sin x}\]
⬇
\[\begin{array}{l}
\mathbf{if}\;x \le -0.009369761232765748:\\
\;\;\;\;\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)\\
\mathbf{if}\;x \le 0.06423521200938427:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)\\
\end{array}\]
Target
| Original | 29.7 |
| Comparison | 0.0 |
| Herbie | 0.5 |
\[ \tan \left(\frac{x}{2}\right) \]
Derivation
- Split input into 3 regimes.
-
if x < -0.009369761232765748
Initial program 1.0
\[\frac{1 - \cos x}{\sin x}\]
- Using strategy
rm
Applied add-log-exp 1.1
\[\leadsto \color{blue}{\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)}\]
if -0.009369761232765748 < x < 0.06423521200938427
Initial program 59.8
\[\frac{1 - \cos x}{\sin x}\]
Applied taylor 0.0
\[\leadsto \frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\]
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 0.06423521200938427 < x
Initial program 0.9
\[\frac{1 - \cos x}{\sin x}\]
- Using strategy
rm
Applied add-log-exp 1.0
\[\leadsto \color{blue}{\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)}\]
- Recombined 3 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie shell --seed '#(1067488128 1186562765 67428877 2948030040 4169093828 3206893112)'
(FPCore (x)
:name "tanhf (example 3.4)"
:herbie-expected 1
:target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))