Average Error: 37.4 → 15.8
Time: 34.4s
Precision: 64
$\tan \left(x + \varepsilon\right) - \tan x$
$\begin{array}{l} \mathbf{if}\;\varepsilon \le -6.314638657513539 \cdot 10^{-20}:\\ \;\;\;\;\frac{\frac{\left(\tan x - \tan \varepsilon\right) \cdot \left(\tan \varepsilon + \tan x\right)}{\tan x - \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{elif}\;\varepsilon \le 2.0475257736193414 \cdot 10^{-113}:\\ \;\;\;\;\varepsilon + \left(x \cdot \varepsilon\right) \cdot \left(x + \varepsilon\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan \varepsilon + \tan x}{1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}} - \tan x\\ \end{array}$
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -6.314638657513539 \cdot 10^{-20}:\\
\;\;\;\;\frac{\frac{\left(\tan x - \tan \varepsilon\right) \cdot \left(\tan \varepsilon + \tan x\right)}{\tan x - \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\

\mathbf{elif}\;\varepsilon \le 2.0475257736193414 \cdot 10^{-113}:\\
\;\;\;\;\varepsilon + \left(x \cdot \varepsilon\right) \cdot \left(x + \varepsilon\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\tan \varepsilon + \tan x}{1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}} - \tan x\\

\end{array}
double f(double x, double eps) {
double r18542766 = x;
double r18542767 = eps;
double r18542768 = r18542766 + r18542767;
double r18542769 = tan(r18542768);
double r18542770 = tan(r18542766);
double r18542771 = r18542769 - r18542770;
return r18542771;
}


double f(double x, double eps) {
double r18542772 = eps;
double r18542773 = -6.314638657513539e-20;
bool r18542774 = r18542772 <= r18542773;
double r18542775 = x;
double r18542776 = tan(r18542775);
double r18542777 = tan(r18542772);
double r18542778 = r18542776 - r18542777;
double r18542779 = r18542777 + r18542776;
double r18542780 = r18542778 * r18542779;
double r18542781 = r18542780 / r18542778;
double r18542782 = 1.0;
double r18542783 = r18542776 * r18542777;
double r18542784 = r18542782 - r18542783;
double r18542785 = r18542781 / r18542784;
double r18542786 = r18542785 - r18542776;
double r18542787 = 2.0475257736193414e-113;
bool r18542788 = r18542772 <= r18542787;
double r18542789 = r18542775 * r18542772;
double r18542790 = r18542775 + r18542772;
double r18542791 = r18542789 * r18542790;
double r18542792 = r18542772 + r18542791;
double r18542793 = sin(r18542775);
double r18542794 = r18542793 * r18542777;
double r18542795 = cos(r18542775);
double r18542796 = r18542794 / r18542795;
double r18542797 = r18542782 - r18542796;
double r18542798 = r18542779 / r18542797;
double r18542799 = r18542798 - r18542776;
double r18542800 = r18542788 ? r18542792 : r18542799;
double r18542801 = r18542774 ? r18542786 : r18542800;
return r18542801;
}



# Try it out

Results

 In Out
Enter valid numbers for all inputs

# Derivation

1. Split input into 3 regimes
2. ## if eps < -6.314638657513539e-20

1. Initial program 30.1

$\tan \left(x + \varepsilon\right) - \tan x$
2. Using strategy rm
3. Applied tan-sum1.1

$\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x$
4. Using strategy rm
5. Applied flip-+1.2

$\leadsto \frac{\color{blue}{\frac{\tan x \cdot \tan x - \tan \varepsilon \cdot \tan \varepsilon}{\tan x - \tan \varepsilon}}}{1 - \tan x \cdot \tan \varepsilon} - \tan x$
6. Simplified1.1

$\leadsto \frac{\frac{\color{blue}{\left(\tan x - \tan \varepsilon\right) \cdot \left(\tan x + \tan \varepsilon\right)}}{\tan x - \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x$

## if -6.314638657513539e-20 < eps < 2.0475257736193414e-113

1. Initial program 46.9

$\tan \left(x + \varepsilon\right) - \tan x$
2. Taylor expanded around 0 31.3

$\leadsto \color{blue}{{x}^{2} \cdot \varepsilon + \left(x \cdot {\varepsilon}^{2} + \varepsilon\right)}$
3. Simplified31.3

$\leadsto \color{blue}{\left(x + \varepsilon\right) \cdot \left(x \cdot \varepsilon\right) + \varepsilon}$

## if 2.0475257736193414e-113 < eps

1. Initial program 32.0

$\tan \left(x + \varepsilon\right) - \tan x$
2. Using strategy rm
3. Applied tan-sum9.4

$\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x$
4. Using strategy rm
5. Applied tan-quot9.4

$\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\frac{\sin x}{\cos x}} \cdot \tan \varepsilon} - \tan x$
6. Applied associate-*l/9.4

$\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\frac{\sin x \cdot \tan \varepsilon}{\cos x}}} - \tan x$
3. Recombined 3 regimes into one program.
4. Final simplification15.8

$\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \le -6.314638657513539 \cdot 10^{-20}:\\ \;\;\;\;\frac{\frac{\left(\tan x - \tan \varepsilon\right) \cdot \left(\tan \varepsilon + \tan x\right)}{\tan x - \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{elif}\;\varepsilon \le 2.0475257736193414 \cdot 10^{-113}:\\ \;\;\;\;\varepsilon + \left(x \cdot \varepsilon\right) \cdot \left(x + \varepsilon\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan \varepsilon + \tan x}{1 - \frac{\sin x \cdot \tan \varepsilon}{\cos x}} - \tan x\\ \end{array}$

# Reproduce

herbie shell --seed 1
(FPCore (x eps)
:name "tan(x+eps)-tan(x)"
(- (tan (+ x eps)) (tan x)))