Average Error: 37.6 → 15.1
Time: 3.0m
Precision: 64
Internal Precision: 2432
\[\tan \left(x + \varepsilon\right) - \tan x\]
↓
\[\begin{array}{l}
\mathbf{if}\;\varepsilon \le -3.088211040495327 \cdot 10^{-21}:\\
\;\;\;\;\frac{\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}\\
\mathbf{if}\;\varepsilon \le 1.4236706257213858 \cdot 10^{-17}:\\
\;\;\;\;\varepsilon + \left({\varepsilon}^{3} \cdot {x}^{2} + {\varepsilon}^{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{\left(\tan x\right)}^{3} + {\left(\tan \varepsilon\right)}^{3}}{\left(\tan \varepsilon \cdot \tan \varepsilon - \tan x \cdot \left(\tan \varepsilon - \tan x\right)\right) \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)} - \tan x\\
\end{array}\]
Target
| Original | 37.6 |
|---|
| Target | 14.9 |
|---|
| Herbie | 15.1 |
|---|
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]
Derivation
- Split input into 3 regimes
if eps < -3.088211040495327e-21
Initial program 29.9
\[\tan \left(x + \varepsilon\right) - \tan x\]
- Using strategy
rm Applied tan-quot29.8
\[\leadsto \tan \left(x + \varepsilon\right) - \color{blue}{\frac{\sin x}{\cos x}}\]
Applied tan-sum1.2
\[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \frac{\sin x}{\cos x}\]
Applied frac-sub1.3
\[\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--1.4
\[\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}\]
if -3.088211040495327e-21 < eps < 1.4236706257213858e-17
Initial program 46.3
\[\tan \left(x + \varepsilon\right) - \tan x\]
Taylor expanded around 0 30.4
\[\leadsto \color{blue}{\varepsilon + \left({\varepsilon}^{3} \cdot {x}^{2} + {\varepsilon}^{2} \cdot x\right)}\]
if 1.4236706257213858e-17 < eps
Initial program 29.6
\[\tan \left(x + \varepsilon\right) - \tan x\]
- Using strategy
rm Applied tan-sum1.0
\[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x\]
- Using strategy
rm Applied flip3-+1.2
\[\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 associate-/l/1.2
\[\leadsto \color{blue}{\frac{{\left(\tan x\right)}^{3} + {\left(\tan \varepsilon\right)}^{3}}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan x + \left(\tan \varepsilon \cdot \tan \varepsilon - \tan x \cdot \tan \varepsilon\right)\right)}} - \tan x\]
Applied simplify1.2
\[\leadsto \frac{{\left(\tan x\right)}^{3} + {\left(\tan \varepsilon\right)}^{3}}{\color{blue}{\left(\tan \varepsilon \cdot \tan \varepsilon - \tan x \cdot \left(\tan \varepsilon - \tan x\right)\right) \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}} - \tan x\]
- Recombined 3 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1063154770 1824007522 645063331 41291047 494775821 1237684644)'
(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)))