Average Error: 30.1 → 0.3
Time: 31.8s
Precision: 64
Internal Precision: 2432
\[\frac{1 - \cos x}{\sin x}\]
↓
\[\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.9924450125203637:\\
\;\;\;\;\frac{1}{\sin x} - \frac{\cos x}{\sin x}\\
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le +\infty:\\
\;\;\;\;(e^{\log_* (1 + \frac{\sin x}{1 + \cos x})} - 1)^*\\
\mathbf{else}:\\
\;\;\;\;(e^{\log_* (1 + \frac{\sin x}{1 + \cos x})} - 1)^*\\
\end{array}\]
Target
| Original | 30.1 |
|---|
| Target | 0.0 |
|---|
| Herbie | 0.3 |
|---|
\[\tan \left(\frac{x}{2}\right)\]
Derivation
- Split input into 2 regimes
if (/ (- 1 (cos x)) (sin x)) < -0.9924450125203637
Initial program 0.3
\[\frac{1 - \cos x}{\sin x}\]
- Using strategy
rm Applied div-sub0.3
\[\leadsto \color{blue}{\frac{1}{\sin x} - \frac{\cos x}{\sin x}}\]
if -0.9924450125203637 < (/ (- 1 (cos x)) (sin x))
Initial program 34.5
\[\frac{1 - \cos x}{\sin x}\]
- Using strategy
rm Applied flip--34.6
\[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{\sin x}\]
Applied simplify16.6
\[\leadsto \frac{\frac{\color{blue}{\sin x \cdot \sin x}}{1 + \cos x}}{\sin x}\]
- Using strategy
rm Applied expm1-log1p-u16.7
\[\leadsto \color{blue}{(e^{\log_* (1 + \frac{\frac{\sin x \cdot \sin x}{1 + \cos x}}{\sin x})} - 1)^*}\]
Applied simplify0.3
\[\leadsto (e^{\color{blue}{\log_* (1 + \frac{\sin x}{1 + \cos x})}} - 1)^*\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1070131407 1246090267 3027482374 2150728003 2026520792 2347815650)' +o rules:numerics
(FPCore (x)
:name "tanhf (example 3.4)"
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))