Average Error: 30.2 → 0.5
Time: 50.5s
Precision: 64
Internal Precision: 2432
\[\frac{1 - \cos x}{\sin x}\]
↓
\[\begin{array}{l}
\mathbf{if}\;x \le -0.023971988296824055:\\
\;\;\;\;\left(1 - \cos x\right) \cdot \frac{1}{\sin x}\\
\mathbf{if}\;x \le 2.1644985647405667 \cdot 10^{-07}:\\
\;\;\;\;\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.0 |
|---|
| Herbie | 0.5 |
|---|
\[\tan \left(\frac{x}{2}\right)\]
Derivation
- Split input into 3 regimes
if x < -0.023971988296824055
Initial program 1.0
\[\frac{1 - \cos x}{\sin x}\]
- Using strategy
rm Applied div-inv1.0
\[\leadsto \color{blue}{\left(1 - \cos x\right) \cdot \frac{1}{\sin x}}\]
if -0.023971988296824055 < x < 2.1644985647405667e-07
Initial program 60.1
\[\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.1644985647405667e-07 < x
Initial program 1.3
\[\frac{1 - \cos x}{\sin x}\]
- Using strategy
rm Applied flip--1.8
\[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{\sin x}\]
Applied simplify1.0
\[\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 '#(1063282112 2455465480 4141627379 3773598652 1647277307 776739644)'
(FPCore (x)
:name "tanhf (example 3.4)"
:herbie-expected 1
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))