Average Error: 36.9 → 14.5
Time: 2.0m
Precision: 64
Internal Precision: 2432
\[\tan \left(x + \varepsilon\right) - \tan x\]
↓
\[\begin{array}{l}
\mathbf{if}\;\varepsilon \le -6.679506785351335 \cdot 10^{-12}:\\
\;\;\;\;\frac{\frac{{\left(\tan x\right)}^{3} + {\left(\tan \varepsilon\right)}^{3}}{\left(\tan \varepsilon - \tan x\right) \cdot \tan \varepsilon + \tan x \cdot \tan x}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{if}\;\varepsilon \le 1.5366040845210357 \cdot 10^{-61}:\\
\;\;\;\;\varepsilon + \left({\varepsilon}^{3} \cdot {x}^{2} + {\varepsilon}^{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x\right) \cdot \left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x\right) - \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right) \cdot \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right)}{\left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \cos x\right) \cdot \left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x + \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right)}\\
\end{array}\]
Target
| Original | 36.9 |
|---|
| Target | 14.9 |
|---|
| Herbie | 14.5 |
|---|
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]
Derivation
- Split input into 3 regimes
if eps < -6.679506785351335e-12
Initial program 29.0
\[\tan \left(x + \varepsilon\right) - \tan x\]
- Using strategy
rm Applied tan-sum0.6
\[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x\]
- Using strategy
rm Applied flip3-+0.8
\[\leadsto \frac{\color{blue}{\frac{{\left(\tan x\right)}^{3} + {\left(\tan \varepsilon\right)}^{3}}{\tan x \cdot \tan x + \left(\tan \varepsilon \cdot \tan \varepsilon - \tan x \cdot \tan \varepsilon\right)}}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\]
Applied simplify0.8
\[\leadsto \frac{\frac{{\left(\tan x\right)}^{3} + {\left(\tan \varepsilon\right)}^{3}}{\color{blue}{\left(\tan \varepsilon - \tan x\right) \cdot \tan \varepsilon + \tan x \cdot \tan x}}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\]
if -6.679506785351335e-12 < eps < 1.5366040845210357e-61
Initial program 45.8
\[\tan \left(x + \varepsilon\right) - \tan x\]
Taylor expanded around 0 28.8
\[\leadsto \color{blue}{\varepsilon + \left({\varepsilon}^{3} \cdot {x}^{2} + {\varepsilon}^{2} \cdot x\right)}\]
if 1.5366040845210357e-61 < eps
Initial program 30.6
\[\tan \left(x + \varepsilon\right) - \tan x\]
- Using strategy
rm Applied tan-quot30.4
\[\leadsto \tan \left(x + \varepsilon\right) - \color{blue}{\frac{\sin x}{\cos x}}\]
Applied tan-sum5.0
\[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \frac{\sin x}{\cos x}\]
Applied frac-sub5.0
\[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \cos x}}\]
- Using strategy
rm Applied flip--5.1
\[\leadsto \frac{\color{blue}{\frac{\left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x\right) \cdot \left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x\right) - \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right) \cdot \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right)}{\left(\tan x + \tan \varepsilon\right) \cdot \cos x + \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x}}}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \cos x}\]
Applied associate-/l/5.1
\[\leadsto \color{blue}{\frac{\left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x\right) \cdot \left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x\right) - \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right) \cdot \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right)}{\left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \cos x\right) \cdot \left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x + \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right)}}\]
- Recombined 3 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1063027428 1192549564 1443466578 604016274 3637110559 1698629644)'
(FPCore (x eps)
:name "2tan (problem 3.3.2)"
:herbie-expected 28
:herbie-target
(/ (sin eps) (* (cos x) (cos (+ x eps))))
(- (tan (+ x eps)) (tan x)))