Average Error: 30.2 → 0.5
Time: 1.2m
Precision: 64
Internal Precision: 2432
\[\frac{1 - \cos x}{\sin x}\]
↓
\[\begin{array}{l}
\mathbf{if}\;x \le -0.023802979002913602:\\
\;\;\;\;\frac{1}{\frac{\sin x}{1 - \cos x}}\\
\mathbf{if}\;x \le 2.1789124480322282 \cdot 10^{-26}:\\
\;\;\;\;\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 | 30.2 |
|---|
| Target | 0 |
|---|
| Herbie | 0.5 |
|---|
\[\tan \left(\frac{x}{2}\right)\]
Derivation
- Split input into 3 regimes
if x < -0.023802979002913602
Initial program 1.0
\[\frac{1 - \cos x}{\sin x}\]
- Using strategy
rm Applied clear-num1.0
\[\leadsto \color{blue}{\frac{1}{\frac{\sin x}{1 - \cos x}}}\]
if -0.023802979002913602 < x < 2.1789124480322282e-26
Initial program 60.2
\[\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 2.1789124480322282e-26 < x
Initial program 4.7
\[\frac{1 - \cos x}{\sin x}\]
- Using strategy
rm Applied flip--5.1
\[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{\sin x}\]
Applied simplify0.9
\[\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
herbie shell --seed '#(1063313015 2771194459 1594909340 1344785158 2223560818 546365448)'
(FPCore (x)
:name "tanhf (example 3.4)"
:herbie-expected 1
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))