Average Error: 31.2 → 0.7
Time: 1.2m
Precision: 64
Internal Precision: 2432
\[\frac{1 - \cos x}{\sin x}\]
↓
\[\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -2.2245851660549705 \cdot 10^{-16}:\\
\;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{\sin x}\\
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le 1.525723687674933 \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{e^{\log \left(1 - \cos x\right)}}{\sin x}\\
\end{array}\]
Target
| Original | 31.2 |
|---|
| Target | 0.0 |
|---|
| Herbie | 0.7 |
|---|
\[\tan \left(\frac{x}{2}\right)\]
Derivation
- Split input into 3 regimes
if (/ (- 1 (cos x)) (sin x)) < -2.2245851660549705e-16
Initial program 1.6
\[\frac{1 - \cos x}{\sin x}\]
- Using strategy
rm Applied add-exp-log1.6
\[\leadsto \frac{\color{blue}{e^{\log \left(1 - \cos x\right)}}}{\sin x}\]
if -2.2245851660549705e-16 < (/ (- 1 (cos x)) (sin x)) < 1.525723687674933e-07
Initial program 60.5
\[\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 1.525723687674933e-07 < (/ (- 1 (cos x)) (sin x))
Initial program 1.3
\[\frac{1 - \cos x}{\sin x}\]
- Using strategy
rm Applied add-exp-log1.3
\[\leadsto \frac{\color{blue}{e^{\log \left(1 - \cos x\right)}}}{\sin x}\]
- Recombined 3 regimes into one program.
Runtime
herbie shell --seed '#(212267722 3993171362 1093346726 3605783651 2106536041 3335990851)'
(FPCore (x)
:name "tanhf (example 3.4)"
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))