Average Error: 36.9 → 7.3
Time: 1.3m
Precision: 64
Internal precision: 2432
\[\tan \left(x + \varepsilon\right) - \tan x\]
⬇
\[\begin{array}{l}
\mathbf{if}\;\varepsilon \le -1.2423933280735359 \cdot 10^{-26}:\\
\;\;\;\;\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}\\
\mathbf{if}\;\varepsilon \le 6.648853381887418 \cdot 10^{-19}:\\
\;\;\;\;{\varepsilon}^{3} \cdot {x}^{2} + \left(\varepsilon + {\varepsilon}^{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\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}\\
\end{array}\]
Target
| Original | 36.9 |
| Comparison | 27.9 |
| Herbie | 7.3 |
\[ \frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)} \]
Derivation
- Split input into 2 regimes.
-
if eps < -1.2423933280735359e-26 or 6.648853381887418e-19 < eps
Initial program 30.3
\[\tan \left(x + \varepsilon\right) - \tan x\]
- Using strategy
rm
Applied tan-quot 30.2
\[\leadsto \tan \left(x + \varepsilon\right) - \color{blue}{\frac{\sin x}{\cos x}}\]
Applied tan-sum 1.5
\[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \frac{\sin x}{\cos x}\]
Applied frac-sub 1.6
\[\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}}\]
if -1.2423933280735359e-26 < eps < 6.648853381887418e-19
Initial program 44.8
\[\tan \left(x + \varepsilon\right) - \tan x\]
Taylor expanded around 0 14.3
\[\leadsto \color{blue}{{\varepsilon}^{3} \cdot {x}^{2} + \left(\varepsilon + {\varepsilon}^{2} \cdot x\right)}\]
- Recombined 2 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie shell --seed '#(2329929097 3210370195 3111198779 2406363002 3511342718 2136436390)'
(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)))