Average Error: 30.1 → 0.5
Time: 2.8m
Precision: 64
Internal Precision: 2432
\[\frac{1 - \cos x}{\sin x}\]
↓
\[\begin{array}{l}
\mathbf{if}\;x \le -0.0006848976318816709:\\
\;\;\;\;\frac{\frac{\sin x \cdot \sin x}{1 + \cos x}}{\sin x}\\
\mathbf{if}\;x \le 4185100.604392328:\\
\;\;\;\;\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.1 |
|---|
| Target | 0.3 |
|---|
| Herbie | 0.5 |
|---|
\[\tan \left(\frac{x}{2}\right)\]
Derivation
- Split input into 2 regimes
if x < -0.0006848976318816709 or 4185100.604392328 < x
Initial program 0.9
\[\frac{1 - \cos x}{\sin x}\]
- Using strategy
rm Applied flip--1.4
\[\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}\]
if -0.0006848976318816709 < x < 4185100.604392328
Initial program 59.8
\[\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)}\]
- Recombined 2 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1062930989 876886121 3990119081 3032829768 3060892583 1929069376)'
(FPCore (x)
:name "tanhf (example 3.4)"
:herbie-expected 1
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))