2tan (problem 3.3.2)

Percentage Accurate: 42.3% → 99.3%
Time: 16.8s
Alternatives: 11
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \tan \left(x + \varepsilon\right) - \tan x \end{array} \]
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
double code(double x, double eps) {
	return tan((x + eps)) - tan(x);
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = tan((x + eps)) - tan(x)
end function
public static double code(double x, double eps) {
	return Math.tan((x + eps)) - Math.tan(x);
}
def code(x, eps):
	return math.tan((x + eps)) - math.tan(x)
function code(x, eps)
	return Float64(tan(Float64(x + eps)) - tan(x))
end
function tmp = code(x, eps)
	tmp = tan((x + eps)) - tan(x);
end
code[x_, eps_] := N[(N[Tan[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\tan \left(x + \varepsilon\right) - \tan x
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 11 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 42.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \tan \left(x + \varepsilon\right) - \tan x \end{array} \]
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
double code(double x, double eps) {
	return tan((x + eps)) - tan(x);
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = tan((x + eps)) - tan(x)
end function
public static double code(double x, double eps) {
	return Math.tan((x + eps)) - Math.tan(x);
}
def code(x, eps):
	return math.tan((x + eps)) - math.tan(x)
function code(x, eps)
	return Float64(tan(Float64(x + eps)) - tan(x))
end
function tmp = code(x, eps)
	tmp = tan((x + eps)) - tan(x);
end
code[x_, eps_] := N[(N[Tan[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\tan \left(x + \varepsilon\right) - \tan x
\end{array}

Alternative 1: 99.3% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ \mathbf{if}\;\varepsilon \leq -0.00019:\\ \;\;\;\;\frac{t_0}{1 + \left(1 + \left(-1 - \tan x \cdot \tan \varepsilon\right)\right)} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 2.9 \cdot 10^{-15}:\\ \;\;\;\;\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\frac{\cos \varepsilon \cdot \cos x}{\sin x}}} + \left(\frac{\varepsilon}{\frac{{\cos x}^{2}}{{\sin x}^{2}}} + \frac{\varepsilon \cdot \varepsilon}{\frac{{\cos x}^{3}}{{\sin x}^{3}}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{-\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} - \tan x\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps))))
   (if (<= eps -0.00019)
     (- (/ t_0 (+ 1.0 (+ 1.0 (- -1.0 (* (tan x) (tan eps)))))) (tan x))
     (if (<= eps 2.9e-15)
       (+
        (/
         (/ (sin eps) (cos eps))
         (- 1.0 (/ (sin eps) (/ (* (cos eps) (cos x)) (sin x)))))
        (+
         (/ eps (/ (pow (cos x) 2.0) (pow (sin x) 2.0)))
         (/ (* eps eps) (/ (pow (cos x) 3.0) (pow (sin x) 3.0)))))
       (- (/ t_0 (- (fma (tan x) (tan eps) -1.0))) (tan x))))))
double code(double x, double eps) {
	double t_0 = tan(x) + tan(eps);
	double tmp;
	if (eps <= -0.00019) {
		tmp = (t_0 / (1.0 + (1.0 + (-1.0 - (tan(x) * tan(eps)))))) - tan(x);
	} else if (eps <= 2.9e-15) {
		tmp = ((sin(eps) / cos(eps)) / (1.0 - (sin(eps) / ((cos(eps) * cos(x)) / sin(x))))) + ((eps / (pow(cos(x), 2.0) / pow(sin(x), 2.0))) + ((eps * eps) / (pow(cos(x), 3.0) / pow(sin(x), 3.0))));
	} else {
		tmp = (t_0 / -fma(tan(x), tan(eps), -1.0)) - tan(x);
	}
	return tmp;
}
function code(x, eps)
	t_0 = Float64(tan(x) + tan(eps))
	tmp = 0.0
	if (eps <= -0.00019)
		tmp = Float64(Float64(t_0 / Float64(1.0 + Float64(1.0 + Float64(-1.0 - Float64(tan(x) * tan(eps)))))) - tan(x));
	elseif (eps <= 2.9e-15)
		tmp = Float64(Float64(Float64(sin(eps) / cos(eps)) / Float64(1.0 - Float64(sin(eps) / Float64(Float64(cos(eps) * cos(x)) / sin(x))))) + Float64(Float64(eps / Float64((cos(x) ^ 2.0) / (sin(x) ^ 2.0))) + Float64(Float64(eps * eps) / Float64((cos(x) ^ 3.0) / (sin(x) ^ 3.0)))));
	else
		tmp = Float64(Float64(t_0 / Float64(-fma(tan(x), tan(eps), -1.0))) - tan(x));
	end
	return tmp
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.00019], N[(N[(t$95$0 / N[(1.0 + N[(1.0 + N[(-1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 2.9e-15], N[(N[(N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Sin[eps], $MachinePrecision] / N[(N[(N[Cos[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(eps / N[(N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(eps * eps), $MachinePrecision] / N[(N[Power[N[Cos[x], $MachinePrecision], 3.0], $MachinePrecision] / N[Power[N[Sin[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / (-N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision])), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -0.00019:\\
\;\;\;\;\frac{t_0}{1 + \left(1 + \left(-1 - \tan x \cdot \tan \varepsilon\right)\right)} - \tan x\\

\mathbf{elif}\;\varepsilon \leq 2.9 \cdot 10^{-15}:\\
\;\;\;\;\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\frac{\cos \varepsilon \cdot \cos x}{\sin x}}} + \left(\frac{\varepsilon}{\frac{{\cos x}^{2}}{{\sin x}^{2}}} + \frac{\varepsilon \cdot \varepsilon}{\frac{{\cos x}^{3}}{{\sin x}^{3}}}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{t_0}{-\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} - \tan x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if eps < -1.9000000000000001e-4

    1. Initial program 52.2%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.4%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.3%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr99.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.3%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.4%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.4%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified99.4%

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
    6. Step-by-step derivation
      1. expm1-log1p-u90.5%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan x \cdot \tan \varepsilon\right)\right)}} - \tan x \]
      2. expm1-udef90.5%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\left(e^{\mathsf{log1p}\left(\tan x \cdot \tan \varepsilon\right)} - 1\right)}} - \tan x \]
      3. log1p-udef90.5%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \left(e^{\color{blue}{\log \left(1 + \tan x \cdot \tan \varepsilon\right)}} - 1\right)} - \tan x \]
      4. add-exp-log99.4%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \left(\color{blue}{\left(1 + \tan x \cdot \tan \varepsilon\right)} - 1\right)} - \tan x \]
    7. Applied egg-rr99.4%

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

    if -1.9000000000000001e-4 < eps < 2.90000000000000019e-15

    1. Initial program 26.5%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum26.8%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv26.8%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg26.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr26.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg26.8%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/26.8%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity26.8%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified26.8%

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
    6. Taylor expanded in x around inf 26.8%

      \[\leadsto \color{blue}{\left(\frac{\sin \varepsilon}{\cos \varepsilon \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} + \frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)}\right) - \frac{\sin x}{\cos x}} \]
    7. Step-by-step derivation
      1. associate--l+57.6%

        \[\leadsto \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} + \left(\frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} - \frac{\sin x}{\cos x}\right)} \]
      2. associate-/r*57.6%

        \[\leadsto \color{blue}{\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}}} + \left(\frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} - \frac{\sin x}{\cos x}\right) \]
      3. *-commutative57.6%

        \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\color{blue}{\sin \varepsilon \cdot \sin x}}{\cos \varepsilon \cdot \cos x}} + \left(\frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} - \frac{\sin x}{\cos x}\right) \]
      4. associate-/l*57.6%

        \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \color{blue}{\frac{\sin \varepsilon}{\frac{\cos \varepsilon \cdot \cos x}{\sin x}}}} + \left(\frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \cos x}\right)} - \frac{\sin x}{\cos x}\right) \]
    8. Simplified57.6%

      \[\leadsto \color{blue}{\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\frac{\cos \varepsilon \cdot \cos x}{\sin x}}} + \left(\frac{\frac{\sin x}{\cos x}}{1 - \frac{\sin \varepsilon}{\frac{\cos \varepsilon \cdot \cos x}{\sin x}}} - \frac{\sin x}{\cos x}\right)} \]
    9. Taylor expanded in eps around 0 99.8%

      \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\frac{\cos \varepsilon \cdot \cos x}{\sin x}}} + \color{blue}{\left(\frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}} + \frac{{\varepsilon}^{2} \cdot {\sin x}^{3}}{{\cos x}^{3}}\right)} \]
    10. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\frac{\cos \varepsilon \cdot \cos x}{\sin x}}} + \left(\color{blue}{\frac{\varepsilon}{\frac{{\cos x}^{2}}{{\sin x}^{2}}}} + \frac{{\varepsilon}^{2} \cdot {\sin x}^{3}}{{\cos x}^{3}}\right) \]
      2. associate-/l*99.8%

        \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\frac{\cos \varepsilon \cdot \cos x}{\sin x}}} + \left(\frac{\varepsilon}{\frac{{\cos x}^{2}}{{\sin x}^{2}}} + \color{blue}{\frac{{\varepsilon}^{2}}{\frac{{\cos x}^{3}}{{\sin x}^{3}}}}\right) \]
      3. unpow299.8%

        \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\frac{\cos \varepsilon \cdot \cos x}{\sin x}}} + \left(\frac{\varepsilon}{\frac{{\cos x}^{2}}{{\sin x}^{2}}} + \frac{\color{blue}{\varepsilon \cdot \varepsilon}}{\frac{{\cos x}^{3}}{{\sin x}^{3}}}\right) \]
    11. Simplified99.8%

      \[\leadsto \frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\frac{\cos \varepsilon \cdot \cos x}{\sin x}}} + \color{blue}{\left(\frac{\varepsilon}{\frac{{\cos x}^{2}}{{\sin x}^{2}}} + \frac{\varepsilon \cdot \varepsilon}{\frac{{\cos x}^{3}}{{\sin x}^{3}}}\right)} \]

    if 2.90000000000000019e-15 < eps

    1. Initial program 52.5%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.1%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.1%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg98.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr98.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.1%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.1%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.1%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified99.1%

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
    6. Step-by-step derivation
      1. expm1-log1p-u87.0%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan x \cdot \tan \varepsilon\right)\right)}} - \tan x \]
      2. expm1-udef87.0%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\left(e^{\mathsf{log1p}\left(\tan x \cdot \tan \varepsilon\right)} - 1\right)}} - \tan x \]
      3. log1p-udef87.0%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \left(e^{\color{blue}{\log \left(1 + \tan x \cdot \tan \varepsilon\right)}} - 1\right)} - \tan x \]
      4. add-exp-log99.1%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \left(\color{blue}{\left(1 + \tan x \cdot \tan \varepsilon\right)} - 1\right)} - \tan x \]
    7. Applied egg-rr99.1%

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\left(\left(1 + \tan x \cdot \tan \varepsilon\right) - 1\right)}} - \tan x \]
    8. Step-by-step derivation
      1. associate--l+99.1%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\left(1 + \left(\tan x \cdot \tan \varepsilon - 1\right)\right)}} - \tan x \]
      2. fma-neg99.2%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \left(1 + \color{blue}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}\right)} - \tan x \]
      3. metadata-eval99.2%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \left(1 + \mathsf{fma}\left(\tan x, \tan \varepsilon, \color{blue}{-1}\right)\right)} - \tan x \]
    9. Simplified99.2%

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\left(1 + \mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)\right)}} - \tan x \]
    10. Step-by-step derivation
      1. sub-neg99.2%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \left(1 + \mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)\right)} + \left(-\tan x\right)} \]
      2. associate--r+99.2%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{\color{blue}{\left(1 - 1\right) - \mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}} + \left(-\tan x\right) \]
      3. metadata-eval99.2%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{\color{blue}{0} - \mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} + \left(-\tan x\right) \]
    11. Applied egg-rr99.2%

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{0 - \mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} + \left(-\tan x\right)} \]
    12. Step-by-step derivation
      1. sub-neg99.2%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{0 - \mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} - \tan x} \]
      2. sub0-neg99.2%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{\color{blue}{-\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}} - \tan x \]
    13. Simplified99.2%

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{-\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} - \tan x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -0.00019:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 + \left(1 + \left(-1 - \tan x \cdot \tan \varepsilon\right)\right)} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 2.9 \cdot 10^{-15}:\\ \;\;\;\;\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\frac{\cos \varepsilon \cdot \cos x}{\sin x}}} + \left(\frac{\varepsilon}{\frac{{\cos x}^{2}}{{\sin x}^{2}}} + \frac{\varepsilon \cdot \varepsilon}{\frac{{\cos x}^{3}}{{\sin x}^{3}}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{-\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} - \tan x\\ \end{array} \]

Alternative 2: 99.3% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ \mathbf{if}\;\varepsilon \leq -3.25 \cdot 10^{-9}:\\ \;\;\;\;\frac{t_0}{1 + \left(1 + \left(-1 - \tan x \cdot \tan \varepsilon\right)\right)} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 2.9 \cdot 10^{-15}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{-\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} - \tan x\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps))))
   (if (<= eps -3.25e-9)
     (- (/ t_0 (+ 1.0 (+ 1.0 (- -1.0 (* (tan x) (tan eps)))))) (tan x))
     (if (<= eps 2.9e-15)
       (+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
       (- (/ t_0 (- (fma (tan x) (tan eps) -1.0))) (tan x))))))
double code(double x, double eps) {
	double t_0 = tan(x) + tan(eps);
	double tmp;
	if (eps <= -3.25e-9) {
		tmp = (t_0 / (1.0 + (1.0 + (-1.0 - (tan(x) * tan(eps)))))) - tan(x);
	} else if (eps <= 2.9e-15) {
		tmp = eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	} else {
		tmp = (t_0 / -fma(tan(x), tan(eps), -1.0)) - tan(x);
	}
	return tmp;
}
function code(x, eps)
	t_0 = Float64(tan(x) + tan(eps))
	tmp = 0.0
	if (eps <= -3.25e-9)
		tmp = Float64(Float64(t_0 / Float64(1.0 + Float64(1.0 + Float64(-1.0 - Float64(tan(x) * tan(eps)))))) - tan(x));
	elseif (eps <= 2.9e-15)
		tmp = Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	else
		tmp = Float64(Float64(t_0 / Float64(-fma(tan(x), tan(eps), -1.0))) - tan(x));
	end
	return tmp
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -3.25e-9], N[(N[(t$95$0 / N[(1.0 + N[(1.0 + N[(-1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 2.9e-15], N[(eps + N[(eps * N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / (-N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision])), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -3.25 \cdot 10^{-9}:\\
\;\;\;\;\frac{t_0}{1 + \left(1 + \left(-1 - \tan x \cdot \tan \varepsilon\right)\right)} - \tan x\\

\mathbf{elif}\;\varepsilon \leq 2.9 \cdot 10^{-15}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\

\mathbf{else}:\\
\;\;\;\;\frac{t_0}{-\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} - \tan x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if eps < -3.2500000000000002e-9

    1. Initial program 52.9%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.4%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.3%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr99.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.3%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.4%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.4%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified99.4%

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
    6. Step-by-step derivation
      1. expm1-log1p-u90.6%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan x \cdot \tan \varepsilon\right)\right)}} - \tan x \]
      2. expm1-udef90.6%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\left(e^{\mathsf{log1p}\left(\tan x \cdot \tan \varepsilon\right)} - 1\right)}} - \tan x \]
      3. log1p-udef90.7%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \left(e^{\color{blue}{\log \left(1 + \tan x \cdot \tan \varepsilon\right)}} - 1\right)} - \tan x \]
      4. add-exp-log99.4%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \left(\color{blue}{\left(1 + \tan x \cdot \tan \varepsilon\right)} - 1\right)} - \tan x \]
    7. Applied egg-rr99.4%

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

    if -3.2500000000000002e-9 < eps < 2.90000000000000019e-15

    1. Initial program 25.9%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Taylor expanded in eps around 0 99.7%

      \[\leadsto \color{blue}{\varepsilon \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
    3. Step-by-step derivation
      1. cancel-sign-sub-inv99.7%

        \[\leadsto \varepsilon \cdot \color{blue}{\left(1 + \left(--1\right) \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
      2. metadata-eval99.7%

        \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{1} \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) \]
      3. *-lft-identity99.7%

        \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{\frac{{\sin x}^{2}}{{\cos x}^{2}}}\right) \]
      4. distribute-lft-in99.8%

        \[\leadsto \color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
      5. *-rgt-identity99.8%

        \[\leadsto \color{blue}{\varepsilon} + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} \]
    4. Simplified99.8%

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]

    if 2.90000000000000019e-15 < eps

    1. Initial program 52.5%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.1%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.1%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg98.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr98.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.1%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.1%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.1%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified99.1%

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
    6. Step-by-step derivation
      1. expm1-log1p-u87.0%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan x \cdot \tan \varepsilon\right)\right)}} - \tan x \]
      2. expm1-udef87.0%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\left(e^{\mathsf{log1p}\left(\tan x \cdot \tan \varepsilon\right)} - 1\right)}} - \tan x \]
      3. log1p-udef87.0%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \left(e^{\color{blue}{\log \left(1 + \tan x \cdot \tan \varepsilon\right)}} - 1\right)} - \tan x \]
      4. add-exp-log99.1%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \left(\color{blue}{\left(1 + \tan x \cdot \tan \varepsilon\right)} - 1\right)} - \tan x \]
    7. Applied egg-rr99.1%

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\left(\left(1 + \tan x \cdot \tan \varepsilon\right) - 1\right)}} - \tan x \]
    8. Step-by-step derivation
      1. associate--l+99.1%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\left(1 + \left(\tan x \cdot \tan \varepsilon - 1\right)\right)}} - \tan x \]
      2. fma-neg99.2%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \left(1 + \color{blue}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}\right)} - \tan x \]
      3. metadata-eval99.2%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \left(1 + \mathsf{fma}\left(\tan x, \tan \varepsilon, \color{blue}{-1}\right)\right)} - \tan x \]
    9. Simplified99.2%

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\left(1 + \mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)\right)}} - \tan x \]
    10. Step-by-step derivation
      1. sub-neg99.2%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \left(1 + \mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)\right)} + \left(-\tan x\right)} \]
      2. associate--r+99.2%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{\color{blue}{\left(1 - 1\right) - \mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}} + \left(-\tan x\right) \]
      3. metadata-eval99.2%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{\color{blue}{0} - \mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} + \left(-\tan x\right) \]
    11. Applied egg-rr99.2%

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{0 - \mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} + \left(-\tan x\right)} \]
    12. Step-by-step derivation
      1. sub-neg99.2%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{0 - \mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} - \tan x} \]
      2. sub0-neg99.2%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{\color{blue}{-\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}} - \tan x \]
    13. Simplified99.2%

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{-\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} - \tan x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -3.25 \cdot 10^{-9}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 + \left(1 + \left(-1 - \tan x \cdot \tan \varepsilon\right)\right)} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 2.9 \cdot 10^{-15}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{-\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} - \tan x\\ \end{array} \]

Alternative 3: 99.2% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x \cdot \tan \varepsilon\\ t_1 := \tan x + \tan \varepsilon\\ \mathbf{if}\;\varepsilon \leq -3.7 \cdot 10^{-9}:\\ \;\;\;\;\frac{t_1}{1 + \left(1 + \left(-1 - t_0\right)\right)} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 2.9 \cdot 10^{-15}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{1 - t_0} - \tan x\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (* (tan x) (tan eps))) (t_1 (+ (tan x) (tan eps))))
   (if (<= eps -3.7e-9)
     (- (/ t_1 (+ 1.0 (+ 1.0 (- -1.0 t_0)))) (tan x))
     (if (<= eps 2.9e-15)
       (+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
       (- (/ t_1 (- 1.0 t_0)) (tan x))))))
double code(double x, double eps) {
	double t_0 = tan(x) * tan(eps);
	double t_1 = tan(x) + tan(eps);
	double tmp;
	if (eps <= -3.7e-9) {
		tmp = (t_1 / (1.0 + (1.0 + (-1.0 - t_0)))) - tan(x);
	} else if (eps <= 2.9e-15) {
		tmp = eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	} else {
		tmp = (t_1 / (1.0 - t_0)) - tan(x);
	}
	return tmp;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = tan(x) * tan(eps)
    t_1 = tan(x) + tan(eps)
    if (eps <= (-3.7d-9)) then
        tmp = (t_1 / (1.0d0 + (1.0d0 + ((-1.0d0) - t_0)))) - tan(x)
    else if (eps <= 2.9d-15) then
        tmp = eps + (eps * ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
    else
        tmp = (t_1 / (1.0d0 - t_0)) - tan(x)
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double t_0 = Math.tan(x) * Math.tan(eps);
	double t_1 = Math.tan(x) + Math.tan(eps);
	double tmp;
	if (eps <= -3.7e-9) {
		tmp = (t_1 / (1.0 + (1.0 + (-1.0 - t_0)))) - Math.tan(x);
	} else if (eps <= 2.9e-15) {
		tmp = eps + (eps * (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
	} else {
		tmp = (t_1 / (1.0 - t_0)) - Math.tan(x);
	}
	return tmp;
}
def code(x, eps):
	t_0 = math.tan(x) * math.tan(eps)
	t_1 = math.tan(x) + math.tan(eps)
	tmp = 0
	if eps <= -3.7e-9:
		tmp = (t_1 / (1.0 + (1.0 + (-1.0 - t_0)))) - math.tan(x)
	elif eps <= 2.9e-15:
		tmp = eps + (eps * (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0)))
	else:
		tmp = (t_1 / (1.0 - t_0)) - math.tan(x)
	return tmp
function code(x, eps)
	t_0 = Float64(tan(x) * tan(eps))
	t_1 = Float64(tan(x) + tan(eps))
	tmp = 0.0
	if (eps <= -3.7e-9)
		tmp = Float64(Float64(t_1 / Float64(1.0 + Float64(1.0 + Float64(-1.0 - t_0)))) - tan(x));
	elseif (eps <= 2.9e-15)
		tmp = Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	else
		tmp = Float64(Float64(t_1 / Float64(1.0 - t_0)) - tan(x));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	t_0 = tan(x) * tan(eps);
	t_1 = tan(x) + tan(eps);
	tmp = 0.0;
	if (eps <= -3.7e-9)
		tmp = (t_1 / (1.0 + (1.0 + (-1.0 - t_0)))) - tan(x);
	elseif (eps <= 2.9e-15)
		tmp = eps + (eps * ((sin(x) ^ 2.0) / (cos(x) ^ 2.0)));
	else
		tmp = (t_1 / (1.0 - t_0)) - tan(x);
	end
	tmp_2 = tmp;
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -3.7e-9], N[(N[(t$95$1 / N[(1.0 + N[(1.0 + N[(-1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 2.9e-15], N[(eps + N[(eps * N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 / N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan x \cdot \tan \varepsilon\\
t_1 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -3.7 \cdot 10^{-9}:\\
\;\;\;\;\frac{t_1}{1 + \left(1 + \left(-1 - t_0\right)\right)} - \tan x\\

\mathbf{elif}\;\varepsilon \leq 2.9 \cdot 10^{-15}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\

\mathbf{else}:\\
\;\;\;\;\frac{t_1}{1 - t_0} - \tan x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if eps < -3.7e-9

    1. Initial program 52.9%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.4%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.3%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr99.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.3%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.4%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.4%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified99.4%

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
    6. Step-by-step derivation
      1. expm1-log1p-u90.6%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan x \cdot \tan \varepsilon\right)\right)}} - \tan x \]
      2. expm1-udef90.6%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\left(e^{\mathsf{log1p}\left(\tan x \cdot \tan \varepsilon\right)} - 1\right)}} - \tan x \]
      3. log1p-udef90.7%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \left(e^{\color{blue}{\log \left(1 + \tan x \cdot \tan \varepsilon\right)}} - 1\right)} - \tan x \]
      4. add-exp-log99.4%

        \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \left(\color{blue}{\left(1 + \tan x \cdot \tan \varepsilon\right)} - 1\right)} - \tan x \]
    7. Applied egg-rr99.4%

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

    if -3.7e-9 < eps < 2.90000000000000019e-15

    1. Initial program 25.9%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Taylor expanded in eps around 0 99.7%

      \[\leadsto \color{blue}{\varepsilon \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
    3. Step-by-step derivation
      1. cancel-sign-sub-inv99.7%

        \[\leadsto \varepsilon \cdot \color{blue}{\left(1 + \left(--1\right) \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
      2. metadata-eval99.7%

        \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{1} \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) \]
      3. *-lft-identity99.7%

        \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{\frac{{\sin x}^{2}}{{\cos x}^{2}}}\right) \]
      4. distribute-lft-in99.8%

        \[\leadsto \color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
      5. *-rgt-identity99.8%

        \[\leadsto \color{blue}{\varepsilon} + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} \]
    4. Simplified99.8%

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]

    if 2.90000000000000019e-15 < eps

    1. Initial program 52.5%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.1%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.1%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg98.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr98.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.1%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.1%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.1%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified99.1%

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -3.7 \cdot 10^{-9}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 + \left(1 + \left(-1 - \tan x \cdot \tan \varepsilon\right)\right)} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 2.9 \cdot 10^{-15}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \end{array} \]

Alternative 4: 99.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -2.3 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 2.9 \cdot 10^{-15}\right):\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= eps -2.3e-9) (not (<= eps 2.9e-15)))
   (- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x))
   (+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))))
double code(double x, double eps) {
	double tmp;
	if ((eps <= -2.3e-9) || !(eps <= 2.9e-15)) {
		tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
	} else {
		tmp = eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	}
	return tmp;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: tmp
    if ((eps <= (-2.3d-9)) .or. (.not. (eps <= 2.9d-15))) then
        tmp = ((tan(x) + tan(eps)) / (1.0d0 - (tan(x) * tan(eps)))) - tan(x)
    else
        tmp = eps + (eps * ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double tmp;
	if ((eps <= -2.3e-9) || !(eps <= 2.9e-15)) {
		tmp = ((Math.tan(x) + Math.tan(eps)) / (1.0 - (Math.tan(x) * Math.tan(eps)))) - Math.tan(x);
	} else {
		tmp = eps + (eps * (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
	}
	return tmp;
}
def code(x, eps):
	tmp = 0
	if (eps <= -2.3e-9) or not (eps <= 2.9e-15):
		tmp = ((math.tan(x) + math.tan(eps)) / (1.0 - (math.tan(x) * math.tan(eps)))) - math.tan(x)
	else:
		tmp = eps + (eps * (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0)))
	return tmp
function code(x, eps)
	tmp = 0.0
	if ((eps <= -2.3e-9) || !(eps <= 2.9e-15))
		tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x));
	else
		tmp = Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	tmp = 0.0;
	if ((eps <= -2.3e-9) || ~((eps <= 2.9e-15)))
		tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
	else
		tmp = eps + (eps * ((sin(x) ^ 2.0) / (cos(x) ^ 2.0)));
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[Or[LessEqual[eps, -2.3e-9], N[Not[LessEqual[eps, 2.9e-15]], $MachinePrecision]], N[(N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], N[(eps + N[(eps * N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.3 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 2.9 \cdot 10^{-15}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\

\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -2.2999999999999999e-9 or 2.90000000000000019e-15 < eps

    1. Initial program 52.7%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum99.3%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv99.2%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg99.2%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr99.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg99.2%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/99.3%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity99.3%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified99.3%

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]

    if -2.2999999999999999e-9 < eps < 2.90000000000000019e-15

    1. Initial program 25.9%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Taylor expanded in eps around 0 99.7%

      \[\leadsto \color{blue}{\varepsilon \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
    3. Step-by-step derivation
      1. cancel-sign-sub-inv99.7%

        \[\leadsto \varepsilon \cdot \color{blue}{\left(1 + \left(--1\right) \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
      2. metadata-eval99.7%

        \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{1} \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) \]
      3. *-lft-identity99.7%

        \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{\frac{{\sin x}^{2}}{{\cos x}^{2}}}\right) \]
      4. distribute-lft-in99.8%

        \[\leadsto \color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
      5. *-rgt-identity99.8%

        \[\leadsto \color{blue}{\varepsilon} + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} \]
    4. Simplified99.8%

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -2.3 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 2.9 \cdot 10^{-15}\right):\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \end{array} \]

Alternative 5: 77.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -2.55 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 0.00175\right):\\ \;\;\;\;\frac{\sin \left(\varepsilon + x\right)}{\cos \varepsilon - x \cdot \sin \varepsilon} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= eps -2.55e-5) (not (<= eps 0.00175)))
   (- (/ (sin (+ eps x)) (- (cos eps) (* x (sin eps)))) (tan x))
   (+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))))
double code(double x, double eps) {
	double tmp;
	if ((eps <= -2.55e-5) || !(eps <= 0.00175)) {
		tmp = (sin((eps + x)) / (cos(eps) - (x * sin(eps)))) - tan(x);
	} else {
		tmp = eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	}
	return tmp;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: tmp
    if ((eps <= (-2.55d-5)) .or. (.not. (eps <= 0.00175d0))) then
        tmp = (sin((eps + x)) / (cos(eps) - (x * sin(eps)))) - tan(x)
    else
        tmp = eps + (eps * ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double tmp;
	if ((eps <= -2.55e-5) || !(eps <= 0.00175)) {
		tmp = (Math.sin((eps + x)) / (Math.cos(eps) - (x * Math.sin(eps)))) - Math.tan(x);
	} else {
		tmp = eps + (eps * (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
	}
	return tmp;
}
def code(x, eps):
	tmp = 0
	if (eps <= -2.55e-5) or not (eps <= 0.00175):
		tmp = (math.sin((eps + x)) / (math.cos(eps) - (x * math.sin(eps)))) - math.tan(x)
	else:
		tmp = eps + (eps * (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0)))
	return tmp
function code(x, eps)
	tmp = 0.0
	if ((eps <= -2.55e-5) || !(eps <= 0.00175))
		tmp = Float64(Float64(sin(Float64(eps + x)) / Float64(cos(eps) - Float64(x * sin(eps)))) - tan(x));
	else
		tmp = Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	tmp = 0.0;
	if ((eps <= -2.55e-5) || ~((eps <= 0.00175)))
		tmp = (sin((eps + x)) / (cos(eps) - (x * sin(eps)))) - tan(x);
	else
		tmp = eps + (eps * ((sin(x) ^ 2.0) / (cos(x) ^ 2.0)));
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[Or[LessEqual[eps, -2.55e-5], N[Not[LessEqual[eps, 0.00175]], $MachinePrecision]], N[(N[(N[Sin[N[(eps + x), $MachinePrecision]], $MachinePrecision] / N[(N[Cos[eps], $MachinePrecision] - N[(x * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], N[(eps + N[(eps * N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.55 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 0.00175\right):\\
\;\;\;\;\frac{\sin \left(\varepsilon + x\right)}{\cos \varepsilon - x \cdot \sin \varepsilon} - \tan x\\

\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -2.54999999999999998e-5 or 0.00175000000000000004 < eps

    1. Initial program 52.7%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-quot52.6%

        \[\leadsto \color{blue}{\frac{\sin \left(x + \varepsilon\right)}{\cos \left(x + \varepsilon\right)}} - \tan x \]
    3. Applied egg-rr52.6%

      \[\leadsto \color{blue}{\frac{\sin \left(x + \varepsilon\right)}{\cos \left(x + \varepsilon\right)}} - \tan x \]
    4. Taylor expanded in x around 0 56.2%

      \[\leadsto \frac{\sin \left(x + \varepsilon\right)}{\color{blue}{\cos \varepsilon + -1 \cdot \left(x \cdot \sin \varepsilon\right)}} - \tan x \]
    5. Step-by-step derivation
      1. mul-1-neg56.2%

        \[\leadsto \frac{\sin \left(x + \varepsilon\right)}{\cos \varepsilon + \color{blue}{\left(-x \cdot \sin \varepsilon\right)}} - \tan x \]
      2. unsub-neg56.2%

        \[\leadsto \frac{\sin \left(x + \varepsilon\right)}{\color{blue}{\cos \varepsilon - x \cdot \sin \varepsilon}} - \tan x \]
      3. *-commutative56.2%

        \[\leadsto \frac{\sin \left(x + \varepsilon\right)}{\cos \varepsilon - \color{blue}{\sin \varepsilon \cdot x}} - \tan x \]
    6. Simplified56.2%

      \[\leadsto \frac{\sin \left(x + \varepsilon\right)}{\color{blue}{\cos \varepsilon - \sin \varepsilon \cdot x}} - \tan x \]

    if -2.54999999999999998e-5 < eps < 0.00175000000000000004

    1. Initial program 26.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Taylor expanded in eps around 0 99.2%

      \[\leadsto \color{blue}{\varepsilon \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
    3. Step-by-step derivation
      1. cancel-sign-sub-inv99.2%

        \[\leadsto \varepsilon \cdot \color{blue}{\left(1 + \left(--1\right) \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
      2. metadata-eval99.2%

        \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{1} \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) \]
      3. *-lft-identity99.2%

        \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{\frac{{\sin x}^{2}}{{\cos x}^{2}}}\right) \]
      4. distribute-lft-in99.2%

        \[\leadsto \color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
      5. *-rgt-identity99.2%

        \[\leadsto \color{blue}{\varepsilon} + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} \]
    4. Simplified99.2%

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification77.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -2.55 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 0.00175\right):\\ \;\;\;\;\frac{\sin \left(\varepsilon + x\right)}{\cos \varepsilon - x \cdot \sin \varepsilon} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \end{array} \]

Alternative 6: 77.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\sin \varepsilon}{\cos \varepsilon}\\ \mathbf{if}\;\varepsilon \leq -4 \cdot 10^{-6}:\\ \;\;\;\;t_0 \cdot {1}^{0.3333333333333333} + \left(-\tan x\right)\\ \mathbf{elif}\;\varepsilon \leq 0.0021:\\ \;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (/ (sin eps) (cos eps))))
   (if (<= eps -4e-6)
     (+ (* t_0 (pow 1.0 0.3333333333333333)) (- (tan x)))
     (if (<= eps 0.0021)
       (* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
       t_0))))
double code(double x, double eps) {
	double t_0 = sin(eps) / cos(eps);
	double tmp;
	if (eps <= -4e-6) {
		tmp = (t_0 * pow(1.0, 0.3333333333333333)) + -tan(x);
	} else if (eps <= 0.0021) {
		tmp = eps * (1.0 + (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sin(eps) / cos(eps)
    if (eps <= (-4d-6)) then
        tmp = (t_0 * (1.0d0 ** 0.3333333333333333d0)) + -tan(x)
    else if (eps <= 0.0021d0) then
        tmp = eps * (1.0d0 + ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double t_0 = Math.sin(eps) / Math.cos(eps);
	double tmp;
	if (eps <= -4e-6) {
		tmp = (t_0 * Math.pow(1.0, 0.3333333333333333)) + -Math.tan(x);
	} else if (eps <= 0.0021) {
		tmp = eps * (1.0 + (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, eps):
	t_0 = math.sin(eps) / math.cos(eps)
	tmp = 0
	if eps <= -4e-6:
		tmp = (t_0 * math.pow(1.0, 0.3333333333333333)) + -math.tan(x)
	elif eps <= 0.0021:
		tmp = eps * (1.0 + (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0)))
	else:
		tmp = t_0
	return tmp
function code(x, eps)
	t_0 = Float64(sin(eps) / cos(eps))
	tmp = 0.0
	if (eps <= -4e-6)
		tmp = Float64(Float64(t_0 * (1.0 ^ 0.3333333333333333)) + Float64(-tan(x)));
	elseif (eps <= 0.0021)
		tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, eps)
	t_0 = sin(eps) / cos(eps);
	tmp = 0.0;
	if (eps <= -4e-6)
		tmp = (t_0 * (1.0 ^ 0.3333333333333333)) + -tan(x);
	elseif (eps <= 0.0021)
		tmp = eps * (1.0 + ((sin(x) ^ 2.0) / (cos(x) ^ 2.0)));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -4e-6], N[(N[(t$95$0 * N[Power[1.0, 0.3333333333333333], $MachinePrecision]), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 0.0021], N[(eps * N[(1.0 + N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\sin \varepsilon}{\cos \varepsilon}\\
\mathbf{if}\;\varepsilon \leq -4 \cdot 10^{-6}:\\
\;\;\;\;t_0 \cdot {1}^{0.3333333333333333} + \left(-\tan x\right)\\

\mathbf{elif}\;\varepsilon \leq 0.0021:\\
\;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if eps < -3.99999999999999982e-6

    1. Initial program 52.9%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. add-cube-cbrt52.8%

        \[\leadsto \color{blue}{\left(\sqrt[3]{\tan \left(x + \varepsilon\right)} \cdot \sqrt[3]{\tan \left(x + \varepsilon\right)}\right) \cdot \sqrt[3]{\tan \left(x + \varepsilon\right)}} - \tan x \]
      2. pow352.7%

        \[\leadsto \color{blue}{{\left(\sqrt[3]{\tan \left(x + \varepsilon\right)}\right)}^{3}} - \tan x \]
      3. add-exp-log20.8%

        \[\leadsto {\color{blue}{\left(e^{\log \left(\sqrt[3]{\tan \left(x + \varepsilon\right)}\right)}\right)}}^{3} - \tan x \]
      4. pow-exp20.9%

        \[\leadsto \color{blue}{e^{\log \left(\sqrt[3]{\tan \left(x + \varepsilon\right)}\right) \cdot 3}} - \tan x \]
    3. Applied egg-rr20.9%

      \[\leadsto \color{blue}{e^{\log \left(\sqrt[3]{\tan \left(x + \varepsilon\right)}\right) \cdot 3}} - \tan x \]
    4. Taylor expanded in x around 0 55.6%

      \[\leadsto \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon} \cdot {1}^{0.3333333333333333}} - \tan x \]

    if -3.99999999999999982e-6 < eps < 0.00209999999999999987

    1. Initial program 26.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-sum27.3%

        \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      2. div-inv27.3%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. fma-neg27.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    3. Applied egg-rr27.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    4. Step-by-step derivation
      1. fma-neg27.3%

        \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
      2. associate-*r/27.3%

        \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
      3. *-rgt-identity27.3%

        \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
    5. Simplified27.3%

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
    6. Taylor expanded in eps around 0 99.2%

      \[\leadsto \color{blue}{\varepsilon \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
    7. Step-by-step derivation
      1. sub-neg99.2%

        \[\leadsto \varepsilon \cdot \color{blue}{\left(1 + \left(--1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)} \]
      2. mul-1-neg99.2%

        \[\leadsto \varepsilon \cdot \left(1 + \left(-\color{blue}{\left(-\frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}\right)\right) \]
      3. remove-double-neg99.2%

        \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{\frac{{\sin x}^{2}}{{\cos x}^{2}}}\right) \]
    8. Simplified99.2%

      \[\leadsto \color{blue}{\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]

    if 0.00209999999999999987 < eps

    1. Initial program 52.6%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Taylor expanded in x around 0 54.8%

      \[\leadsto \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification76.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -4 \cdot 10^{-6}:\\ \;\;\;\;\frac{\sin \varepsilon}{\cos \varepsilon} \cdot {1}^{0.3333333333333333} + \left(-\tan x\right)\\ \mathbf{elif}\;\varepsilon \leq 0.0021:\\ \;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin \varepsilon}{\cos \varepsilon}\\ \end{array} \]

Alternative 7: 77.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\sin \varepsilon}{\cos \varepsilon}\\ \mathbf{if}\;\varepsilon \leq -9 \cdot 10^{-6}:\\ \;\;\;\;t_0 \cdot {1}^{0.3333333333333333} + \left(-\tan x\right)\\ \mathbf{elif}\;\varepsilon \leq 0.00165:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (/ (sin eps) (cos eps))))
   (if (<= eps -9e-6)
     (+ (* t_0 (pow 1.0 0.3333333333333333)) (- (tan x)))
     (if (<= eps 0.00165)
       (+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
       t_0))))
double code(double x, double eps) {
	double t_0 = sin(eps) / cos(eps);
	double tmp;
	if (eps <= -9e-6) {
		tmp = (t_0 * pow(1.0, 0.3333333333333333)) + -tan(x);
	} else if (eps <= 0.00165) {
		tmp = eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sin(eps) / cos(eps)
    if (eps <= (-9d-6)) then
        tmp = (t_0 * (1.0d0 ** 0.3333333333333333d0)) + -tan(x)
    else if (eps <= 0.00165d0) then
        tmp = eps + (eps * ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double t_0 = Math.sin(eps) / Math.cos(eps);
	double tmp;
	if (eps <= -9e-6) {
		tmp = (t_0 * Math.pow(1.0, 0.3333333333333333)) + -Math.tan(x);
	} else if (eps <= 0.00165) {
		tmp = eps + (eps * (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, eps):
	t_0 = math.sin(eps) / math.cos(eps)
	tmp = 0
	if eps <= -9e-6:
		tmp = (t_0 * math.pow(1.0, 0.3333333333333333)) + -math.tan(x)
	elif eps <= 0.00165:
		tmp = eps + (eps * (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0)))
	else:
		tmp = t_0
	return tmp
function code(x, eps)
	t_0 = Float64(sin(eps) / cos(eps))
	tmp = 0.0
	if (eps <= -9e-6)
		tmp = Float64(Float64(t_0 * (1.0 ^ 0.3333333333333333)) + Float64(-tan(x)));
	elseif (eps <= 0.00165)
		tmp = Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, eps)
	t_0 = sin(eps) / cos(eps);
	tmp = 0.0;
	if (eps <= -9e-6)
		tmp = (t_0 * (1.0 ^ 0.3333333333333333)) + -tan(x);
	elseif (eps <= 0.00165)
		tmp = eps + (eps * ((sin(x) ^ 2.0) / (cos(x) ^ 2.0)));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -9e-6], N[(N[(t$95$0 * N[Power[1.0, 0.3333333333333333], $MachinePrecision]), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 0.00165], N[(eps + N[(eps * N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\sin \varepsilon}{\cos \varepsilon}\\
\mathbf{if}\;\varepsilon \leq -9 \cdot 10^{-6}:\\
\;\;\;\;t_0 \cdot {1}^{0.3333333333333333} + \left(-\tan x\right)\\

\mathbf{elif}\;\varepsilon \leq 0.00165:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if eps < -9.00000000000000023e-6

    1. Initial program 52.9%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. add-cube-cbrt52.8%

        \[\leadsto \color{blue}{\left(\sqrt[3]{\tan \left(x + \varepsilon\right)} \cdot \sqrt[3]{\tan \left(x + \varepsilon\right)}\right) \cdot \sqrt[3]{\tan \left(x + \varepsilon\right)}} - \tan x \]
      2. pow352.7%

        \[\leadsto \color{blue}{{\left(\sqrt[3]{\tan \left(x + \varepsilon\right)}\right)}^{3}} - \tan x \]
      3. add-exp-log20.8%

        \[\leadsto {\color{blue}{\left(e^{\log \left(\sqrt[3]{\tan \left(x + \varepsilon\right)}\right)}\right)}}^{3} - \tan x \]
      4. pow-exp20.9%

        \[\leadsto \color{blue}{e^{\log \left(\sqrt[3]{\tan \left(x + \varepsilon\right)}\right) \cdot 3}} - \tan x \]
    3. Applied egg-rr20.9%

      \[\leadsto \color{blue}{e^{\log \left(\sqrt[3]{\tan \left(x + \varepsilon\right)}\right) \cdot 3}} - \tan x \]
    4. Taylor expanded in x around 0 55.6%

      \[\leadsto \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon} \cdot {1}^{0.3333333333333333}} - \tan x \]

    if -9.00000000000000023e-6 < eps < 0.00165

    1. Initial program 26.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Taylor expanded in eps around 0 99.2%

      \[\leadsto \color{blue}{\varepsilon \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
    3. Step-by-step derivation
      1. cancel-sign-sub-inv99.2%

        \[\leadsto \varepsilon \cdot \color{blue}{\left(1 + \left(--1\right) \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
      2. metadata-eval99.2%

        \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{1} \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) \]
      3. *-lft-identity99.2%

        \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{\frac{{\sin x}^{2}}{{\cos x}^{2}}}\right) \]
      4. distribute-lft-in99.2%

        \[\leadsto \color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
      5. *-rgt-identity99.2%

        \[\leadsto \color{blue}{\varepsilon} + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} \]
    4. Simplified99.2%

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]

    if 0.00165 < eps

    1. Initial program 52.6%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Taylor expanded in x around 0 54.8%

      \[\leadsto \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification76.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -9 \cdot 10^{-6}:\\ \;\;\;\;\frac{\sin \varepsilon}{\cos \varepsilon} \cdot {1}^{0.3333333333333333} + \left(-\tan x\right)\\ \mathbf{elif}\;\varepsilon \leq 0.00165:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin \varepsilon}{\cos \varepsilon}\\ \end{array} \]

Alternative 8: 41.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.82:\\ \;\;\;\;\sin x - \tan x\\ \mathbf{else}:\\ \;\;\;\;\tan \left(\varepsilon + x\right) - x\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (<= x -0.82) (- (sin x) (tan x)) (- (tan (+ eps x)) x)))
double code(double x, double eps) {
	double tmp;
	if (x <= -0.82) {
		tmp = sin(x) - tan(x);
	} else {
		tmp = tan((eps + x)) - x;
	}
	return tmp;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: tmp
    if (x <= (-0.82d0)) then
        tmp = sin(x) - tan(x)
    else
        tmp = tan((eps + x)) - x
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double tmp;
	if (x <= -0.82) {
		tmp = Math.sin(x) - Math.tan(x);
	} else {
		tmp = Math.tan((eps + x)) - x;
	}
	return tmp;
}
def code(x, eps):
	tmp = 0
	if x <= -0.82:
		tmp = math.sin(x) - math.tan(x)
	else:
		tmp = math.tan((eps + x)) - x
	return tmp
function code(x, eps)
	tmp = 0.0
	if (x <= -0.82)
		tmp = Float64(sin(x) - tan(x));
	else
		tmp = Float64(tan(Float64(eps + x)) - x);
	end
	return tmp
end
function tmp_2 = code(x, eps)
	tmp = 0.0;
	if (x <= -0.82)
		tmp = sin(x) - tan(x);
	else
		tmp = tan((eps + x)) - x;
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[LessEqual[x, -0.82], N[(N[Sin[x], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], N[(N[Tan[N[(eps + x), $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.82:\\
\;\;\;\;\sin x - \tan x\\

\mathbf{else}:\\
\;\;\;\;\tan \left(\varepsilon + x\right) - x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -0.819999999999999951

    1. Initial program 7.7%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Step-by-step derivation
      1. tan-quot7.4%

        \[\leadsto \color{blue}{\frac{\sin \left(x + \varepsilon\right)}{\cos \left(x + \varepsilon\right)}} - \tan x \]
      2. div-inv7.5%

        \[\leadsto \color{blue}{\sin \left(x + \varepsilon\right) \cdot \frac{1}{\cos \left(x + \varepsilon\right)}} - \tan x \]
    3. Applied egg-rr7.5%

      \[\leadsto \color{blue}{\sin \left(x + \varepsilon\right) \cdot \frac{1}{\cos \left(x + \varepsilon\right)}} - \tan x \]
    4. Taylor expanded in x around 0 8.4%

      \[\leadsto \sin \left(x + \varepsilon\right) \cdot \frac{1}{\color{blue}{\cos \varepsilon}} - \tan x \]
    5. Taylor expanded in eps around 0 10.3%

      \[\leadsto \color{blue}{\sin x} - \tan x \]

    if -0.819999999999999951 < x

    1. Initial program 51.4%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Taylor expanded in x around 0 49.7%

      \[\leadsto \tan \left(x + \varepsilon\right) - \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification39.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.82:\\ \;\;\;\;\sin x - \tan x\\ \mathbf{else}:\\ \;\;\;\;\tan \left(\varepsilon + x\right) - x\\ \end{array} \]

Alternative 9: 58.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\sin \varepsilon}{\cos \varepsilon} \end{array} \]
(FPCore (x eps) :precision binary64 (/ (sin eps) (cos eps)))
double code(double x, double eps) {
	return sin(eps) / cos(eps);
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = sin(eps) / cos(eps)
end function
public static double code(double x, double eps) {
	return Math.sin(eps) / Math.cos(eps);
}
def code(x, eps):
	return math.sin(eps) / math.cos(eps)
function code(x, eps)
	return Float64(sin(eps) / cos(eps))
end
function tmp = code(x, eps)
	tmp = sin(eps) / cos(eps);
end
code[x_, eps_] := N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin \varepsilon}{\cos \varepsilon}
\end{array}
Derivation
  1. Initial program 39.9%

    \[\tan \left(x + \varepsilon\right) - \tan x \]
  2. Taylor expanded in x around 0 56.2%

    \[\leadsto \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}} \]
  3. Final simplification56.2%

    \[\leadsto \frac{\sin \varepsilon}{\cos \varepsilon} \]

Alternative 10: 39.9% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \tan \left(\varepsilon + x\right) - x \end{array} \]
(FPCore (x eps) :precision binary64 (- (tan (+ eps x)) x))
double code(double x, double eps) {
	return tan((eps + x)) - x;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = tan((eps + x)) - x
end function
public static double code(double x, double eps) {
	return Math.tan((eps + x)) - x;
}
def code(x, eps):
	return math.tan((eps + x)) - x
function code(x, eps)
	return Float64(tan(Float64(eps + x)) - x)
end
function tmp = code(x, eps)
	tmp = tan((eps + x)) - x;
end
code[x_, eps_] := N[(N[Tan[N[(eps + x), $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}

\\
\tan \left(\varepsilon + x\right) - x
\end{array}
Derivation
  1. Initial program 39.9%

    \[\tan \left(x + \varepsilon\right) - \tan x \]
  2. Taylor expanded in x around 0 37.5%

    \[\leadsto \tan \left(x + \varepsilon\right) - \color{blue}{x} \]
  3. Final simplification37.5%

    \[\leadsto \tan \left(\varepsilon + x\right) - x \]

Alternative 11: 4.3% accurate, 205.0× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (x eps) :precision binary64 0.0)
double code(double x, double eps) {
	return 0.0;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = 0.0d0
end function
public static double code(double x, double eps) {
	return 0.0;
}
def code(x, eps):
	return 0.0
function code(x, eps)
	return 0.0
end
function tmp = code(x, eps)
	tmp = 0.0;
end
code[x_, eps_] := 0.0
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 39.9%

    \[\tan \left(x + \varepsilon\right) - \tan x \]
  2. Step-by-step derivation
    1. add-cube-cbrt39.6%

      \[\leadsto \tan \left(x + \varepsilon\right) - \color{blue}{\left(\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}\right) \cdot \sqrt[3]{\tan x}} \]
    2. pow339.6%

      \[\leadsto \tan \left(x + \varepsilon\right) - \color{blue}{{\left(\sqrt[3]{\tan x}\right)}^{3}} \]
  3. Applied egg-rr39.6%

    \[\leadsto \tan \left(x + \varepsilon\right) - \color{blue}{{\left(\sqrt[3]{\tan x}\right)}^{3}} \]
  4. Taylor expanded in eps around 0 4.4%

    \[\leadsto \color{blue}{\frac{\sin x}{\cos x} - {1}^{0.3333333333333333} \cdot \frac{\sin x}{\cos x}} \]
  5. Step-by-step derivation
    1. pow-base-14.4%

      \[\leadsto \frac{\sin x}{\cos x} - \color{blue}{1} \cdot \frac{\sin x}{\cos x} \]
    2. *-lft-identity4.4%

      \[\leadsto \frac{\sin x}{\cos x} - \color{blue}{\frac{\sin x}{\cos x}} \]
    3. +-inverses4.4%

      \[\leadsto \color{blue}{0} \]
  6. Simplified4.4%

    \[\leadsto \color{blue}{0} \]
  7. Final simplification4.4%

    \[\leadsto 0 \]

Developer target: 76.7% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)} \end{array} \]
(FPCore (x eps) :precision binary64 (/ (sin eps) (* (cos x) (cos (+ x eps)))))
double code(double x, double eps) {
	return sin(eps) / (cos(x) * cos((x + eps)));
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = sin(eps) / (cos(x) * cos((x + eps)))
end function
public static double code(double x, double eps) {
	return Math.sin(eps) / (Math.cos(x) * Math.cos((x + eps)));
}
def code(x, eps):
	return math.sin(eps) / (math.cos(x) * math.cos((x + eps)))
function code(x, eps)
	return Float64(sin(eps) / Float64(cos(x) * cos(Float64(x + eps))))
end
function tmp = code(x, eps)
	tmp = sin(eps) / (cos(x) * cos((x + eps)));
end
code[x_, eps_] := N[(N[Sin[eps], $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}
\end{array}

Reproduce

?
herbie shell --seed 2023261 
(FPCore (x eps)
  :name "2tan (problem 3.3.2)"
  :precision binary64

  :herbie-target
  (/ (sin eps) (* (cos x) (cos (+ x eps))))

  (- (tan (+ x eps)) (tan x)))