2tan (problem 3.3.2)

Percentage Accurate: 42.3% → 98.6%
Time: 16.8s
Alternatives: 14
Speedup: 2.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 14 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: 98.6% accurate, 0.2× speedup?

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

\\
\begin{array}{l}
t_0 := \tan x \cdot \tan \varepsilon\\
t_1 := 1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\\
t_2 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -2.6 \cdot 10^{-7}:\\
\;\;\;\;t_2 \cdot \frac{1}{1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}} - \tan x\\

\mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, t_1, \frac{t_1 \cdot \left(\sin x \cdot \left(\varepsilon \cdot \varepsilon\right)\right)}{\cos x}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{t_2 \cdot \cos x + \sin x \cdot \left(t_0 + -1\right)}{\cos x \cdot \left(1 - t_0\right)}\\


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

    1. Initial program 56.8%

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

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

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

      \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
    4. Step-by-step derivation
      1. *-commutative99.6%

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

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

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

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

    if -2.59999999999999999e-7 < eps < 3.2e-29

    1. Initial program 27.7%

      \[\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) + \frac{{\varepsilon}^{2} \cdot \left(\sin x \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)}{\cos x}} \]
    3. Step-by-step derivation
      1. fma-def99.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\varepsilon, 1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}, \frac{{\varepsilon}^{2} \cdot \left(\sin x \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)}{\cos x}\right)} \]
      2. cancel-sign-sub-inv99.7%

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

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

        \[\leadsto \mathsf{fma}\left(\varepsilon, 1 + \color{blue}{\frac{{\sin x}^{2}}{{\cos x}^{2}}}, \frac{{\varepsilon}^{2} \cdot \left(\sin x \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)}{\cos x}\right) \]
    4. Simplified99.7%

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

    if 3.2e-29 < eps

    1. Initial program 61.2%

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

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

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

        \[\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}} \]
    3. Applied egg-rr99.5%

      \[\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}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.6%

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

Alternative 2: 98.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ t_1 := 1 - \tan x \cdot \tan \varepsilon\\ \mathbf{if}\;\varepsilon \leq -3.1 \cdot 10^{-7}:\\ \;\;\;\;t_0 \cdot \frac{1}{1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\ \;\;\;\;\left(\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) + \left(\varepsilon \cdot \varepsilon\right) \cdot \left(\frac{{\sin x}^{3}}{{\cos x}^{3}} + \frac{\sin x}{\cos x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0 \cdot \cos x - \sin x \cdot t_1}{\cos x \cdot t_1}\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps))) (t_1 (- 1.0 (* (tan x) (tan eps)))))
   (if (<= eps -3.1e-7)
     (- (* t_0 (/ 1.0 (- 1.0 (/ (* (tan eps) (sin x)) (cos x))))) (tan x))
     (if (<= eps 3.2e-29)
       (+
        (+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
        (*
         (* eps eps)
         (+ (/ (pow (sin x) 3.0) (pow (cos x) 3.0)) (/ (sin x) (cos x)))))
       (/ (- (* t_0 (cos x)) (* (sin x) t_1)) (* (cos x) t_1))))))
double code(double x, double eps) {
	double t_0 = tan(x) + tan(eps);
	double t_1 = 1.0 - (tan(x) * tan(eps));
	double tmp;
	if (eps <= -3.1e-7) {
		tmp = (t_0 * (1.0 / (1.0 - ((tan(eps) * sin(x)) / cos(x))))) - tan(x);
	} else if (eps <= 3.2e-29) {
		tmp = (eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)))) + ((eps * eps) * ((pow(sin(x), 3.0) / pow(cos(x), 3.0)) + (sin(x) / cos(x))));
	} else {
		tmp = ((t_0 * cos(x)) - (sin(x) * t_1)) / (cos(x) * t_1);
	}
	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 = 1.0d0 - (tan(x) * tan(eps))
    if (eps <= (-3.1d-7)) then
        tmp = (t_0 * (1.0d0 / (1.0d0 - ((tan(eps) * sin(x)) / cos(x))))) - tan(x)
    else if (eps <= 3.2d-29) then
        tmp = (eps + (eps * ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))) + ((eps * eps) * (((sin(x) ** 3.0d0) / (cos(x) ** 3.0d0)) + (sin(x) / cos(x))))
    else
        tmp = ((t_0 * cos(x)) - (sin(x) * t_1)) / (cos(x) * t_1)
    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 = 1.0 - (Math.tan(x) * Math.tan(eps));
	double tmp;
	if (eps <= -3.1e-7) {
		tmp = (t_0 * (1.0 / (1.0 - ((Math.tan(eps) * Math.sin(x)) / Math.cos(x))))) - Math.tan(x);
	} else if (eps <= 3.2e-29) {
		tmp = (eps + (eps * (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)))) + ((eps * eps) * ((Math.pow(Math.sin(x), 3.0) / Math.pow(Math.cos(x), 3.0)) + (Math.sin(x) / Math.cos(x))));
	} else {
		tmp = ((t_0 * Math.cos(x)) - (Math.sin(x) * t_1)) / (Math.cos(x) * t_1);
	}
	return tmp;
}
def code(x, eps):
	t_0 = math.tan(x) + math.tan(eps)
	t_1 = 1.0 - (math.tan(x) * math.tan(eps))
	tmp = 0
	if eps <= -3.1e-7:
		tmp = (t_0 * (1.0 / (1.0 - ((math.tan(eps) * math.sin(x)) / math.cos(x))))) - math.tan(x)
	elif eps <= 3.2e-29:
		tmp = (eps + (eps * (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0)))) + ((eps * eps) * ((math.pow(math.sin(x), 3.0) / math.pow(math.cos(x), 3.0)) + (math.sin(x) / math.cos(x))))
	else:
		tmp = ((t_0 * math.cos(x)) - (math.sin(x) * t_1)) / (math.cos(x) * t_1)
	return tmp
function code(x, eps)
	t_0 = Float64(tan(x) + tan(eps))
	t_1 = Float64(1.0 - Float64(tan(x) * tan(eps)))
	tmp = 0.0
	if (eps <= -3.1e-7)
		tmp = Float64(Float64(t_0 * Float64(1.0 / Float64(1.0 - Float64(Float64(tan(eps) * sin(x)) / cos(x))))) - tan(x));
	elseif (eps <= 3.2e-29)
		tmp = Float64(Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))) + Float64(Float64(eps * eps) * Float64(Float64((sin(x) ^ 3.0) / (cos(x) ^ 3.0)) + Float64(sin(x) / cos(x)))));
	else
		tmp = Float64(Float64(Float64(t_0 * cos(x)) - Float64(sin(x) * t_1)) / Float64(cos(x) * t_1));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	t_0 = tan(x) + tan(eps);
	t_1 = 1.0 - (tan(x) * tan(eps));
	tmp = 0.0;
	if (eps <= -3.1e-7)
		tmp = (t_0 * (1.0 / (1.0 - ((tan(eps) * sin(x)) / cos(x))))) - tan(x);
	elseif (eps <= 3.2e-29)
		tmp = (eps + (eps * ((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))) + ((eps * eps) * (((sin(x) ^ 3.0) / (cos(x) ^ 3.0)) + (sin(x) / cos(x))));
	else
		tmp = ((t_0 * cos(x)) - (sin(x) * t_1)) / (cos(x) * t_1);
	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[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -3.1e-7], N[(N[(t$95$0 * N[(1.0 / N[(1.0 - N[(N[(N[Tan[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 3.2e-29], N[(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[(eps * eps), $MachinePrecision] * N[(N[(N[Power[N[Sin[x], $MachinePrecision], 3.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t$95$0 * N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
t_1 := 1 - \tan x \cdot \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -3.1 \cdot 10^{-7}:\\
\;\;\;\;t_0 \cdot \frac{1}{1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}} - \tan x\\

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

\mathbf{else}:\\
\;\;\;\;\frac{t_0 \cdot \cos x - \sin x \cdot t_1}{\cos x \cdot t_1}\\


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

    1. Initial program 56.8%

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

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

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

      \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
    4. Step-by-step derivation
      1. *-commutative99.6%

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

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

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

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

    if -3.1e-7 < eps < 3.2e-29

    1. Initial program 27.7%

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

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

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

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

      \[\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-neg28.1%

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

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

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

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

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

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

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

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

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

    if 3.2e-29 < eps

    1. Initial program 61.2%

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

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

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

        \[\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}} \]
    3. Applied egg-rr99.5%

      \[\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}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -3.1 \cdot 10^{-7}:\\ \;\;\;\;\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\ \;\;\;\;\left(\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) + \left(\varepsilon \cdot \varepsilon\right) \cdot \left(\frac{{\sin x}^{3}}{{\cos x}^{3}} + \frac{\sin x}{\cos x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \sin x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}\\ \end{array} \]

Alternative 3: 98.6% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x \cdot \tan \varepsilon\\ t_1 := \tan x + \tan \varepsilon\\ \mathbf{if}\;\varepsilon \leq -1.6 \cdot 10^{-9}:\\ \;\;\;\;t_1 \cdot \frac{1}{1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1 \cdot \cos x + \sin x \cdot \left(t_0 + -1\right)}{\cos x \cdot \left(1 - t_0\right)}\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (* (tan x) (tan eps))) (t_1 (+ (tan x) (tan eps))))
   (if (<= eps -1.6e-9)
     (- (* t_1 (/ 1.0 (- 1.0 (/ (* (tan eps) (sin x)) (cos x))))) (tan x))
     (if (<= eps 3.2e-29)
       (+ eps (* eps (/ (- 0.5 (/ (cos (+ x x)) 2.0)) (pow (cos x) 2.0))))
       (/
        (+ (* t_1 (cos x)) (* (sin x) (+ t_0 -1.0)))
        (* (cos x) (- 1.0 t_0)))))))
double code(double x, double eps) {
	double t_0 = tan(x) * tan(eps);
	double t_1 = tan(x) + tan(eps);
	double tmp;
	if (eps <= -1.6e-9) {
		tmp = (t_1 * (1.0 / (1.0 - ((tan(eps) * sin(x)) / cos(x))))) - tan(x);
	} else if (eps <= 3.2e-29) {
		tmp = eps + (eps * ((0.5 - (cos((x + x)) / 2.0)) / pow(cos(x), 2.0)));
	} else {
		tmp = ((t_1 * cos(x)) + (sin(x) * (t_0 + -1.0))) / (cos(x) * (1.0 - 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) :: t_1
    real(8) :: tmp
    t_0 = tan(x) * tan(eps)
    t_1 = tan(x) + tan(eps)
    if (eps <= (-1.6d-9)) then
        tmp = (t_1 * (1.0d0 / (1.0d0 - ((tan(eps) * sin(x)) / cos(x))))) - tan(x)
    else if (eps <= 3.2d-29) then
        tmp = eps + (eps * ((0.5d0 - (cos((x + x)) / 2.0d0)) / (cos(x) ** 2.0d0)))
    else
        tmp = ((t_1 * cos(x)) + (sin(x) * (t_0 + (-1.0d0)))) / (cos(x) * (1.0d0 - t_0))
    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 <= -1.6e-9) {
		tmp = (t_1 * (1.0 / (1.0 - ((Math.tan(eps) * Math.sin(x)) / Math.cos(x))))) - Math.tan(x);
	} else if (eps <= 3.2e-29) {
		tmp = eps + (eps * ((0.5 - (Math.cos((x + x)) / 2.0)) / Math.pow(Math.cos(x), 2.0)));
	} else {
		tmp = ((t_1 * Math.cos(x)) + (Math.sin(x) * (t_0 + -1.0))) / (Math.cos(x) * (1.0 - t_0));
	}
	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 <= -1.6e-9:
		tmp = (t_1 * (1.0 / (1.0 - ((math.tan(eps) * math.sin(x)) / math.cos(x))))) - math.tan(x)
	elif eps <= 3.2e-29:
		tmp = eps + (eps * ((0.5 - (math.cos((x + x)) / 2.0)) / math.pow(math.cos(x), 2.0)))
	else:
		tmp = ((t_1 * math.cos(x)) + (math.sin(x) * (t_0 + -1.0))) / (math.cos(x) * (1.0 - t_0))
	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 <= -1.6e-9)
		tmp = Float64(Float64(t_1 * Float64(1.0 / Float64(1.0 - Float64(Float64(tan(eps) * sin(x)) / cos(x))))) - tan(x));
	elseif (eps <= 3.2e-29)
		tmp = Float64(eps + Float64(eps * Float64(Float64(0.5 - Float64(cos(Float64(x + x)) / 2.0)) / (cos(x) ^ 2.0))));
	else
		tmp = Float64(Float64(Float64(t_1 * cos(x)) + Float64(sin(x) * Float64(t_0 + -1.0))) / Float64(cos(x) * Float64(1.0 - t_0)));
	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 <= -1.6e-9)
		tmp = (t_1 * (1.0 / (1.0 - ((tan(eps) * sin(x)) / cos(x))))) - tan(x);
	elseif (eps <= 3.2e-29)
		tmp = eps + (eps * ((0.5 - (cos((x + x)) / 2.0)) / (cos(x) ^ 2.0)));
	else
		tmp = ((t_1 * cos(x)) + (sin(x) * (t_0 + -1.0))) / (cos(x) * (1.0 - t_0));
	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, -1.6e-9], N[(N[(t$95$1 * N[(1.0 / N[(1.0 - N[(N[(N[Tan[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 3.2e-29], N[(eps + N[(eps * N[(N[(0.5 - N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t$95$1 * N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[(1.0 - t$95$0), $MachinePrecision]), $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 -1.6 \cdot 10^{-9}:\\
\;\;\;\;t_1 \cdot \frac{1}{1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}} - \tan x\\

\mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\

\mathbf{else}:\\
\;\;\;\;\frac{t_1 \cdot \cos x + \sin x \cdot \left(t_0 + -1\right)}{\cos x \cdot \left(1 - t_0\right)}\\


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

    1. Initial program 56.8%

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

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

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

      \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
    4. Step-by-step derivation
      1. *-commutative99.6%

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

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

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

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

    if -1.60000000000000006e-9 < eps < 3.2e-29

    1. Initial program 27.7%

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

      \[\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-inv97.5%

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

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

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

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

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

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
    5. Step-by-step derivation
      1. unpow299.5%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\sin x \cdot \sin x}}{{\cos x}^{2}} \]
      2. sin-mult99.6%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\frac{\cos \left(x - x\right) - \cos \left(x + x\right)}{2}}}{{\cos x}^{2}} \]
    6. Applied egg-rr99.6%

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

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

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

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

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

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

    if 3.2e-29 < eps

    1. Initial program 61.2%

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

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

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

        \[\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}} \]
    3. Applied egg-rr99.5%

      \[\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}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.6%

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

Alternative 4: 98.7% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -5.2 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 3.2 \cdot 10^{-29}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}} - \tan x\\

\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -5.2000000000000002e-9 or 3.2e-29 < eps

    1. Initial program 58.8%

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

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

        \[\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.4%

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

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

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

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
    6. Step-by-step derivation
      1. *-commutative99.4%

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

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

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

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

    if -5.2000000000000002e-9 < eps < 3.2e-29

    1. Initial program 27.7%

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

      \[\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-inv97.5%

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

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

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

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

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

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
    5. Step-by-step derivation
      1. unpow299.5%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\sin x \cdot \sin x}}{{\cos x}^{2}} \]
      2. sin-mult99.6%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\frac{\cos \left(x - x\right) - \cos \left(x + x\right)}{2}}}{{\cos x}^{2}} \]
    6. Applied egg-rr99.6%

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

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

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

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

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

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

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

Alternative 5: 98.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ t_1 := 1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}\\ \mathbf{if}\;\varepsilon \leq -2.7 \cdot 10^{-9}:\\ \;\;\;\;t_0 \cdot \frac{1}{t_1} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{t_1} - \tan x\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps)))
        (t_1 (- 1.0 (/ (* (tan eps) (sin x)) (cos x)))))
   (if (<= eps -2.7e-9)
     (- (* t_0 (/ 1.0 t_1)) (tan x))
     (if (<= eps 3.2e-29)
       (+ eps (* eps (/ (- 0.5 (/ (cos (+ x x)) 2.0)) (pow (cos x) 2.0))))
       (- (/ t_0 t_1) (tan x))))))
double code(double x, double eps) {
	double t_0 = tan(x) + tan(eps);
	double t_1 = 1.0 - ((tan(eps) * sin(x)) / cos(x));
	double tmp;
	if (eps <= -2.7e-9) {
		tmp = (t_0 * (1.0 / t_1)) - tan(x);
	} else if (eps <= 3.2e-29) {
		tmp = eps + (eps * ((0.5 - (cos((x + x)) / 2.0)) / pow(cos(x), 2.0)));
	} else {
		tmp = (t_0 / t_1) - 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 = 1.0d0 - ((tan(eps) * sin(x)) / cos(x))
    if (eps <= (-2.7d-9)) then
        tmp = (t_0 * (1.0d0 / t_1)) - tan(x)
    else if (eps <= 3.2d-29) then
        tmp = eps + (eps * ((0.5d0 - (cos((x + x)) / 2.0d0)) / (cos(x) ** 2.0d0)))
    else
        tmp = (t_0 / t_1) - 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 = 1.0 - ((Math.tan(eps) * Math.sin(x)) / Math.cos(x));
	double tmp;
	if (eps <= -2.7e-9) {
		tmp = (t_0 * (1.0 / t_1)) - Math.tan(x);
	} else if (eps <= 3.2e-29) {
		tmp = eps + (eps * ((0.5 - (Math.cos((x + x)) / 2.0)) / Math.pow(Math.cos(x), 2.0)));
	} else {
		tmp = (t_0 / t_1) - Math.tan(x);
	}
	return tmp;
}
def code(x, eps):
	t_0 = math.tan(x) + math.tan(eps)
	t_1 = 1.0 - ((math.tan(eps) * math.sin(x)) / math.cos(x))
	tmp = 0
	if eps <= -2.7e-9:
		tmp = (t_0 * (1.0 / t_1)) - math.tan(x)
	elif eps <= 3.2e-29:
		tmp = eps + (eps * ((0.5 - (math.cos((x + x)) / 2.0)) / math.pow(math.cos(x), 2.0)))
	else:
		tmp = (t_0 / t_1) - math.tan(x)
	return tmp
function code(x, eps)
	t_0 = Float64(tan(x) + tan(eps))
	t_1 = Float64(1.0 - Float64(Float64(tan(eps) * sin(x)) / cos(x)))
	tmp = 0.0
	if (eps <= -2.7e-9)
		tmp = Float64(Float64(t_0 * Float64(1.0 / t_1)) - tan(x));
	elseif (eps <= 3.2e-29)
		tmp = Float64(eps + Float64(eps * Float64(Float64(0.5 - Float64(cos(Float64(x + x)) / 2.0)) / (cos(x) ^ 2.0))));
	else
		tmp = Float64(Float64(t_0 / t_1) - tan(x));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	t_0 = tan(x) + tan(eps);
	t_1 = 1.0 - ((tan(eps) * sin(x)) / cos(x));
	tmp = 0.0;
	if (eps <= -2.7e-9)
		tmp = (t_0 * (1.0 / t_1)) - tan(x);
	elseif (eps <= 3.2e-29)
		tmp = eps + (eps * ((0.5 - (cos((x + x)) / 2.0)) / (cos(x) ^ 2.0)));
	else
		tmp = (t_0 / t_1) - 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[(1.0 - N[(N[(N[Tan[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -2.7e-9], N[(N[(t$95$0 * N[(1.0 / t$95$1), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 3.2e-29], N[(eps + N[(eps * N[(N[(0.5 - N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / t$95$1), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
t_1 := 1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}\\
\mathbf{if}\;\varepsilon \leq -2.7 \cdot 10^{-9}:\\
\;\;\;\;t_0 \cdot \frac{1}{t_1} - \tan x\\

\mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\

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


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

    1. Initial program 56.8%

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

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

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

      \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
    4. Step-by-step derivation
      1. *-commutative99.6%

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

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

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

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

    if -2.7000000000000002e-9 < eps < 3.2e-29

    1. Initial program 27.7%

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

      \[\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-inv97.5%

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

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

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

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

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

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
    5. Step-by-step derivation
      1. unpow299.5%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\sin x \cdot \sin x}}{{\cos x}^{2}} \]
      2. sin-mult99.6%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\frac{\cos \left(x - x\right) - \cos \left(x + x\right)}{2}}}{{\cos x}^{2}} \]
    6. Applied egg-rr99.6%

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

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

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

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

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

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

    if 3.2e-29 < eps

    1. Initial program 61.2%

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

        \[\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.5%

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

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

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
    6. Step-by-step derivation
      1. *-commutative99.3%

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

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

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

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

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

Alternative 6: 98.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ t_1 := 1 - \tan x \cdot \tan \varepsilon\\ \mathbf{if}\;\varepsilon \leq -3.3 \cdot 10^{-9}:\\ \;\;\;\;t_0 \cdot \frac{1}{t_1} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 4.7 \cdot 10^{-26}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{t_1}{t_0}} - \tan x\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps))) (t_1 (- 1.0 (* (tan x) (tan eps)))))
   (if (<= eps -3.3e-9)
     (- (* t_0 (/ 1.0 t_1)) (tan x))
     (if (<= eps 4.7e-26)
       (+ eps (* eps (/ (- 0.5 (/ (cos (+ x x)) 2.0)) (pow (cos x) 2.0))))
       (- (/ 1.0 (/ t_1 t_0)) (tan x))))))
double code(double x, double eps) {
	double t_0 = tan(x) + tan(eps);
	double t_1 = 1.0 - (tan(x) * tan(eps));
	double tmp;
	if (eps <= -3.3e-9) {
		tmp = (t_0 * (1.0 / t_1)) - tan(x);
	} else if (eps <= 4.7e-26) {
		tmp = eps + (eps * ((0.5 - (cos((x + x)) / 2.0)) / pow(cos(x), 2.0)));
	} else {
		tmp = (1.0 / (t_1 / 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 = 1.0d0 - (tan(x) * tan(eps))
    if (eps <= (-3.3d-9)) then
        tmp = (t_0 * (1.0d0 / t_1)) - tan(x)
    else if (eps <= 4.7d-26) then
        tmp = eps + (eps * ((0.5d0 - (cos((x + x)) / 2.0d0)) / (cos(x) ** 2.0d0)))
    else
        tmp = (1.0d0 / (t_1 / 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 = 1.0 - (Math.tan(x) * Math.tan(eps));
	double tmp;
	if (eps <= -3.3e-9) {
		tmp = (t_0 * (1.0 / t_1)) - Math.tan(x);
	} else if (eps <= 4.7e-26) {
		tmp = eps + (eps * ((0.5 - (Math.cos((x + x)) / 2.0)) / Math.pow(Math.cos(x), 2.0)));
	} else {
		tmp = (1.0 / (t_1 / t_0)) - Math.tan(x);
	}
	return tmp;
}
def code(x, eps):
	t_0 = math.tan(x) + math.tan(eps)
	t_1 = 1.0 - (math.tan(x) * math.tan(eps))
	tmp = 0
	if eps <= -3.3e-9:
		tmp = (t_0 * (1.0 / t_1)) - math.tan(x)
	elif eps <= 4.7e-26:
		tmp = eps + (eps * ((0.5 - (math.cos((x + x)) / 2.0)) / math.pow(math.cos(x), 2.0)))
	else:
		tmp = (1.0 / (t_1 / t_0)) - math.tan(x)
	return tmp
function code(x, eps)
	t_0 = Float64(tan(x) + tan(eps))
	t_1 = Float64(1.0 - Float64(tan(x) * tan(eps)))
	tmp = 0.0
	if (eps <= -3.3e-9)
		tmp = Float64(Float64(t_0 * Float64(1.0 / t_1)) - tan(x));
	elseif (eps <= 4.7e-26)
		tmp = Float64(eps + Float64(eps * Float64(Float64(0.5 - Float64(cos(Float64(x + x)) / 2.0)) / (cos(x) ^ 2.0))));
	else
		tmp = Float64(Float64(1.0 / Float64(t_1 / t_0)) - tan(x));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	t_0 = tan(x) + tan(eps);
	t_1 = 1.0 - (tan(x) * tan(eps));
	tmp = 0.0;
	if (eps <= -3.3e-9)
		tmp = (t_0 * (1.0 / t_1)) - tan(x);
	elseif (eps <= 4.7e-26)
		tmp = eps + (eps * ((0.5 - (cos((x + x)) / 2.0)) / (cos(x) ^ 2.0)));
	else
		tmp = (1.0 / (t_1 / 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[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -3.3e-9], N[(N[(t$95$0 * N[(1.0 / t$95$1), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 4.7e-26], N[(eps + N[(eps * N[(N[(0.5 - N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(t$95$1 / t$95$0), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\varepsilon \leq 4.7 \cdot 10^{-26}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\

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


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

    1. Initial program 56.8%

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

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

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

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

    if -3.30000000000000018e-9 < eps < 4.69999999999999989e-26

    1. Initial program 28.9%

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

      \[\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-inv97.5%

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

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

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}}}\right)}^{3} \]
      5. *-rgt-identity97.6%

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

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
    5. Step-by-step derivation
      1. unpow299.5%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\sin x \cdot \sin x}}{{\cos x}^{2}} \]
      2. sin-mult99.6%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\frac{\cos \left(x - x\right) - \cos \left(x + x\right)}{2}}}{{\cos x}^{2}} \]
    6. Applied egg-rr99.6%

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

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

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

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

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

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

    if 4.69999999999999989e-26 < eps

    1. Initial program 59.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. clear-num99.4%

        \[\leadsto \color{blue}{\frac{1}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}}} - \tan x \]
    3. Applied egg-rr99.4%

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

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

Alternative 7: 98.8% 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 -2.8 \cdot 10^{-9}:\\ \;\;\;\;\frac{t_1}{1 + \left(1 - \left(1 + t_0\right)\right)} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 4.7 \cdot 10^{-26}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1 - t_0}{t_1}} - \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 -2.8e-9)
     (- (/ t_1 (+ 1.0 (- 1.0 (+ 1.0 t_0)))) (tan x))
     (if (<= eps 4.7e-26)
       (+ eps (* eps (/ (- 0.5 (/ (cos (+ x x)) 2.0)) (pow (cos x) 2.0))))
       (- (/ 1.0 (/ (- 1.0 t_0) t_1)) (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 <= -2.8e-9) {
		tmp = (t_1 / (1.0 + (1.0 - (1.0 + t_0)))) - tan(x);
	} else if (eps <= 4.7e-26) {
		tmp = eps + (eps * ((0.5 - (cos((x + x)) / 2.0)) / pow(cos(x), 2.0)));
	} else {
		tmp = (1.0 / ((1.0 - t_0) / t_1)) - 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 <= (-2.8d-9)) then
        tmp = (t_1 / (1.0d0 + (1.0d0 - (1.0d0 + t_0)))) - tan(x)
    else if (eps <= 4.7d-26) then
        tmp = eps + (eps * ((0.5d0 - (cos((x + x)) / 2.0d0)) / (cos(x) ** 2.0d0)))
    else
        tmp = (1.0d0 / ((1.0d0 - t_0) / t_1)) - 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 <= -2.8e-9) {
		tmp = (t_1 / (1.0 + (1.0 - (1.0 + t_0)))) - Math.tan(x);
	} else if (eps <= 4.7e-26) {
		tmp = eps + (eps * ((0.5 - (Math.cos((x + x)) / 2.0)) / Math.pow(Math.cos(x), 2.0)));
	} else {
		tmp = (1.0 / ((1.0 - t_0) / t_1)) - 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 <= -2.8e-9:
		tmp = (t_1 / (1.0 + (1.0 - (1.0 + t_0)))) - math.tan(x)
	elif eps <= 4.7e-26:
		tmp = eps + (eps * ((0.5 - (math.cos((x + x)) / 2.0)) / math.pow(math.cos(x), 2.0)))
	else:
		tmp = (1.0 / ((1.0 - t_0) / t_1)) - 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 <= -2.8e-9)
		tmp = Float64(Float64(t_1 / Float64(1.0 + Float64(1.0 - Float64(1.0 + t_0)))) - tan(x));
	elseif (eps <= 4.7e-26)
		tmp = Float64(eps + Float64(eps * Float64(Float64(0.5 - Float64(cos(Float64(x + x)) / 2.0)) / (cos(x) ^ 2.0))));
	else
		tmp = Float64(Float64(1.0 / Float64(Float64(1.0 - t_0) / t_1)) - 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 <= -2.8e-9)
		tmp = (t_1 / (1.0 + (1.0 - (1.0 + t_0)))) - tan(x);
	elseif (eps <= 4.7e-26)
		tmp = eps + (eps * ((0.5 - (cos((x + x)) / 2.0)) / (cos(x) ^ 2.0)));
	else
		tmp = (1.0 / ((1.0 - t_0) / t_1)) - 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, -2.8e-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, 4.7e-26], N[(eps + N[(eps * N[(N[(0.5 - N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(N[(1.0 - t$95$0), $MachinePrecision] / t$95$1), $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 -2.8 \cdot 10^{-9}:\\
\;\;\;\;\frac{t_1}{1 + \left(1 - \left(1 + t_0\right)\right)} - \tan x\\

\mathbf{elif}\;\varepsilon \leq 4.7 \cdot 10^{-26}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\

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


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

    1. Initial program 56.8%

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

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

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

        \[\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.5%

      \[\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.6%

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

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

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

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

        \[\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-udef84.3%

        \[\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-udef84.3%

        \[\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.6%

        \[\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.6%

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

    if -2.79999999999999984e-9 < eps < 4.69999999999999989e-26

    1. Initial program 28.9%

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

      \[\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-inv97.5%

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

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

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}}}\right)}^{3} \]
      5. *-rgt-identity97.6%

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

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
    5. Step-by-step derivation
      1. unpow299.5%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\sin x \cdot \sin x}}{{\cos x}^{2}} \]
      2. sin-mult99.6%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\frac{\cos \left(x - x\right) - \cos \left(x + x\right)}{2}}}{{\cos x}^{2}} \]
    6. Applied egg-rr99.6%

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

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

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

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

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

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

    if 4.69999999999999989e-26 < eps

    1. Initial program 59.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. clear-num99.4%

        \[\leadsto \color{blue}{\frac{1}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}}} - \tan x \]
    3. Applied egg-rr99.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -2.8 \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 4.7 \cdot 10^{-26}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}} - \tan x\\ \end{array} \]

Alternative 8: 98.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -5 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 3.2 \cdot 10^{-29}\right):\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= eps -5e-9) (not (<= eps 3.2e-29)))
   (- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x))
   (+ eps (* eps (/ (- 0.5 (/ (cos (+ x x)) 2.0)) (pow (cos x) 2.0))))))
double code(double x, double eps) {
	double tmp;
	if ((eps <= -5e-9) || !(eps <= 3.2e-29)) {
		tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
	} else {
		tmp = eps + (eps * ((0.5 - (cos((x + 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 <= (-5d-9)) .or. (.not. (eps <= 3.2d-29))) then
        tmp = ((tan(x) + tan(eps)) / (1.0d0 - (tan(x) * tan(eps)))) - tan(x)
    else
        tmp = eps + (eps * ((0.5d0 - (cos((x + 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 <= -5e-9) || !(eps <= 3.2e-29)) {
		tmp = ((Math.tan(x) + Math.tan(eps)) / (1.0 - (Math.tan(x) * Math.tan(eps)))) - Math.tan(x);
	} else {
		tmp = eps + (eps * ((0.5 - (Math.cos((x + x)) / 2.0)) / Math.pow(Math.cos(x), 2.0)));
	}
	return tmp;
}
def code(x, eps):
	tmp = 0
	if (eps <= -5e-9) or not (eps <= 3.2e-29):
		tmp = ((math.tan(x) + math.tan(eps)) / (1.0 - (math.tan(x) * math.tan(eps)))) - math.tan(x)
	else:
		tmp = eps + (eps * ((0.5 - (math.cos((x + x)) / 2.0)) / math.pow(math.cos(x), 2.0)))
	return tmp
function code(x, eps)
	tmp = 0.0
	if ((eps <= -5e-9) || !(eps <= 3.2e-29))
		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(Float64(0.5 - Float64(cos(Float64(x + x)) / 2.0)) / (cos(x) ^ 2.0))));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	tmp = 0.0;
	if ((eps <= -5e-9) || ~((eps <= 3.2e-29)))
		tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
	else
		tmp = eps + (eps * ((0.5 - (cos((x + x)) / 2.0)) / (cos(x) ^ 2.0)));
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[Or[LessEqual[eps, -5e-9], N[Not[LessEqual[eps, 3.2e-29]], $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[(0.5 - N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -5.0000000000000001e-9 or 3.2e-29 < eps

    1. Initial program 58.8%

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

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

        \[\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.4%

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

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

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

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

    if -5.0000000000000001e-9 < eps < 3.2e-29

    1. Initial program 27.7%

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

      \[\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-inv97.5%

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

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

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

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

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

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
    5. Step-by-step derivation
      1. unpow299.5%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\sin x \cdot \sin x}}{{\cos x}^{2}} \]
      2. sin-mult99.6%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\frac{\cos \left(x - x\right) - \cos \left(x + x\right)}{2}}}{{\cos x}^{2}} \]
    6. Applied egg-rr99.6%

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

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

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

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

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

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

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

Alternative 9: 98.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ t_1 := 1 - \tan x \cdot \tan \varepsilon\\ \mathbf{if}\;\varepsilon \leq -5 \cdot 10^{-9}:\\ \;\;\;\;t_0 \cdot \frac{1}{t_1} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{t_1} - \tan x\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps))) (t_1 (- 1.0 (* (tan x) (tan eps)))))
   (if (<= eps -5e-9)
     (- (* t_0 (/ 1.0 t_1)) (tan x))
     (if (<= eps 3.2e-29)
       (+ eps (* eps (/ (- 0.5 (/ (cos (+ x x)) 2.0)) (pow (cos x) 2.0))))
       (- (/ t_0 t_1) (tan x))))))
double code(double x, double eps) {
	double t_0 = tan(x) + tan(eps);
	double t_1 = 1.0 - (tan(x) * tan(eps));
	double tmp;
	if (eps <= -5e-9) {
		tmp = (t_0 * (1.0 / t_1)) - tan(x);
	} else if (eps <= 3.2e-29) {
		tmp = eps + (eps * ((0.5 - (cos((x + x)) / 2.0)) / pow(cos(x), 2.0)));
	} else {
		tmp = (t_0 / t_1) - 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 = 1.0d0 - (tan(x) * tan(eps))
    if (eps <= (-5d-9)) then
        tmp = (t_0 * (1.0d0 / t_1)) - tan(x)
    else if (eps <= 3.2d-29) then
        tmp = eps + (eps * ((0.5d0 - (cos((x + x)) / 2.0d0)) / (cos(x) ** 2.0d0)))
    else
        tmp = (t_0 / t_1) - 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 = 1.0 - (Math.tan(x) * Math.tan(eps));
	double tmp;
	if (eps <= -5e-9) {
		tmp = (t_0 * (1.0 / t_1)) - Math.tan(x);
	} else if (eps <= 3.2e-29) {
		tmp = eps + (eps * ((0.5 - (Math.cos((x + x)) / 2.0)) / Math.pow(Math.cos(x), 2.0)));
	} else {
		tmp = (t_0 / t_1) - Math.tan(x);
	}
	return tmp;
}
def code(x, eps):
	t_0 = math.tan(x) + math.tan(eps)
	t_1 = 1.0 - (math.tan(x) * math.tan(eps))
	tmp = 0
	if eps <= -5e-9:
		tmp = (t_0 * (1.0 / t_1)) - math.tan(x)
	elif eps <= 3.2e-29:
		tmp = eps + (eps * ((0.5 - (math.cos((x + x)) / 2.0)) / math.pow(math.cos(x), 2.0)))
	else:
		tmp = (t_0 / t_1) - math.tan(x)
	return tmp
function code(x, eps)
	t_0 = Float64(tan(x) + tan(eps))
	t_1 = Float64(1.0 - Float64(tan(x) * tan(eps)))
	tmp = 0.0
	if (eps <= -5e-9)
		tmp = Float64(Float64(t_0 * Float64(1.0 / t_1)) - tan(x));
	elseif (eps <= 3.2e-29)
		tmp = Float64(eps + Float64(eps * Float64(Float64(0.5 - Float64(cos(Float64(x + x)) / 2.0)) / (cos(x) ^ 2.0))));
	else
		tmp = Float64(Float64(t_0 / t_1) - tan(x));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	t_0 = tan(x) + tan(eps);
	t_1 = 1.0 - (tan(x) * tan(eps));
	tmp = 0.0;
	if (eps <= -5e-9)
		tmp = (t_0 * (1.0 / t_1)) - tan(x);
	elseif (eps <= 3.2e-29)
		tmp = eps + (eps * ((0.5 - (cos((x + x)) / 2.0)) / (cos(x) ^ 2.0)));
	else
		tmp = (t_0 / t_1) - 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[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -5e-9], N[(N[(t$95$0 * N[(1.0 / t$95$1), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 3.2e-29], N[(eps + N[(eps * N[(N[(0.5 - N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / t$95$1), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\

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


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

    1. Initial program 56.8%

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

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

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

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

    if -5.0000000000000001e-9 < eps < 3.2e-29

    1. Initial program 27.7%

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

      \[\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-inv97.5%

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

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

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

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

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

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
    5. Step-by-step derivation
      1. unpow299.5%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\sin x \cdot \sin x}}{{\cos x}^{2}} \]
      2. sin-mult99.6%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\frac{\cos \left(x - x\right) - \cos \left(x + x\right)}{2}}}{{\cos x}^{2}} \]
    6. Applied egg-rr99.6%

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

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

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

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

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

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

    if 3.2e-29 < eps

    1. Initial program 61.2%

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

        \[\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.5%

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

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

      \[\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 -5 \cdot 10^{-9}:\\ \;\;\;\;\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \end{array} \]

Alternative 10: 76.8% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00068:\\
\;\;\;\;\tan \varepsilon\\

\mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\

\mathbf{else}:\\
\;\;\;\;\tan \varepsilon\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -6.8e-4 or 3.2e-29 < eps

    1. Initial program 59.2%

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

      \[\leadsto \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}} \]
    3. Step-by-step derivation
      1. tan-quot62.3%

        \[\leadsto \color{blue}{\tan \varepsilon} \]
      2. expm1-log1p-u49.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan \varepsilon\right)\right)} \]
      3. expm1-udef46.4%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\tan \varepsilon\right)} - 1} \]
    4. Applied egg-rr46.4%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\tan \varepsilon\right)} - 1} \]
    5. Step-by-step derivation
      1. expm1-def49.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan \varepsilon\right)\right)} \]
      2. expm1-log1p62.3%

        \[\leadsto \color{blue}{\tan \varepsilon} \]
    6. Simplified62.3%

      \[\leadsto \color{blue}{\tan \varepsilon} \]

    if -6.8e-4 < eps < 3.2e-29

    1. Initial program 27.5%

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

      \[\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-inv97.0%

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

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

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}}}\right)}^{3} \]
      5. *-rgt-identity97.0%

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

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
    5. Step-by-step derivation
      1. unpow299.0%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\sin x \cdot \sin x}}{{\cos x}^{2}} \]
      2. sin-mult99.0%

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\frac{\cos \left(x - x\right) - \cos \left(x + x\right)}{2}}}{{\cos x}^{2}} \]
    6. Applied egg-rr99.0%

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

        \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{\frac{\cos \left(x - x\right)}{2} - \frac{\cos \left(x + x\right)}{2}}}{{\cos x}^{2}} \]
      2. +-inverses99.0%

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

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

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

      \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{0.5 - \frac{\cos \left(x + x\right)}{2}}}{{\cos x}^{2}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -0.00068:\\ \;\;\;\;\tan \varepsilon\\ \mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 - \frac{\cos \left(x + x\right)}{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\tan \varepsilon\\ \end{array} \]

Alternative 11: 76.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -0.00068:\\ \;\;\;\;\tan \varepsilon\\ \mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \sqrt{{\tan x}^{4}}\\ \mathbf{else}:\\ \;\;\;\;\tan \varepsilon\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (<= eps -0.00068)
   (tan eps)
   (if (<= eps 3.2e-29) (+ eps (* eps (sqrt (pow (tan x) 4.0)))) (tan eps))))
double code(double x, double eps) {
	double tmp;
	if (eps <= -0.00068) {
		tmp = tan(eps);
	} else if (eps <= 3.2e-29) {
		tmp = eps + (eps * sqrt(pow(tan(x), 4.0)));
	} else {
		tmp = tan(eps);
	}
	return tmp;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: tmp
    if (eps <= (-0.00068d0)) then
        tmp = tan(eps)
    else if (eps <= 3.2d-29) then
        tmp = eps + (eps * sqrt((tan(x) ** 4.0d0)))
    else
        tmp = tan(eps)
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double tmp;
	if (eps <= -0.00068) {
		tmp = Math.tan(eps);
	} else if (eps <= 3.2e-29) {
		tmp = eps + (eps * Math.sqrt(Math.pow(Math.tan(x), 4.0)));
	} else {
		tmp = Math.tan(eps);
	}
	return tmp;
}
def code(x, eps):
	tmp = 0
	if eps <= -0.00068:
		tmp = math.tan(eps)
	elif eps <= 3.2e-29:
		tmp = eps + (eps * math.sqrt(math.pow(math.tan(x), 4.0)))
	else:
		tmp = math.tan(eps)
	return tmp
function code(x, eps)
	tmp = 0.0
	if (eps <= -0.00068)
		tmp = tan(eps);
	elseif (eps <= 3.2e-29)
		tmp = Float64(eps + Float64(eps * sqrt((tan(x) ^ 4.0))));
	else
		tmp = tan(eps);
	end
	return tmp
end
function tmp_2 = code(x, eps)
	tmp = 0.0;
	if (eps <= -0.00068)
		tmp = tan(eps);
	elseif (eps <= 3.2e-29)
		tmp = eps + (eps * sqrt((tan(x) ^ 4.0)));
	else
		tmp = tan(eps);
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[LessEqual[eps, -0.00068], N[Tan[eps], $MachinePrecision], If[LessEqual[eps, 3.2e-29], N[(eps + N[(eps * N[Sqrt[N[Power[N[Tan[x], $MachinePrecision], 4.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Tan[eps], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00068:\\
\;\;\;\;\tan \varepsilon\\

\mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \sqrt{{\tan x}^{4}}\\

\mathbf{else}:\\
\;\;\;\;\tan \varepsilon\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -6.8e-4 or 3.2e-29 < eps

    1. Initial program 59.2%

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

      \[\leadsto \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}} \]
    3. Step-by-step derivation
      1. tan-quot62.3%

        \[\leadsto \color{blue}{\tan \varepsilon} \]
      2. expm1-log1p-u49.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan \varepsilon\right)\right)} \]
      3. expm1-udef46.4%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\tan \varepsilon\right)} - 1} \]
    4. Applied egg-rr46.4%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\tan \varepsilon\right)} - 1} \]
    5. Step-by-step derivation
      1. expm1-def49.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan \varepsilon\right)\right)} \]
      2. expm1-log1p62.3%

        \[\leadsto \color{blue}{\tan \varepsilon} \]
    6. Simplified62.3%

      \[\leadsto \color{blue}{\tan \varepsilon} \]

    if -6.8e-4 < eps < 3.2e-29

    1. Initial program 27.5%

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

      \[\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-inv97.0%

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

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

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}}}\right)}^{3} \]
      5. *-rgt-identity97.0%

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

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt98.8%

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

        \[\leadsto \varepsilon + \varepsilon \cdot \color{blue}{\sqrt{\frac{{\sin x}^{2}}{{\cos x}^{2}} \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}}} \]
      3. pow299.0%

        \[\leadsto \varepsilon + \varepsilon \cdot \sqrt{\color{blue}{{\left(\frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}^{2}}} \]
      4. unpow299.0%

        \[\leadsto \varepsilon + \varepsilon \cdot \sqrt{{\left(\frac{\color{blue}{\sin x \cdot \sin x}}{{\cos x}^{2}}\right)}^{2}} \]
      5. unpow299.0%

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

        \[\leadsto \varepsilon + \varepsilon \cdot \sqrt{{\color{blue}{\left(\frac{\sin x}{\cos x} \cdot \frac{\sin x}{\cos x}\right)}}^{2}} \]
      7. tan-quot98.9%

        \[\leadsto \varepsilon + \varepsilon \cdot \sqrt{{\left(\color{blue}{\tan x} \cdot \frac{\sin x}{\cos x}\right)}^{2}} \]
      8. tan-quot99.0%

        \[\leadsto \varepsilon + \varepsilon \cdot \sqrt{{\left(\tan x \cdot \color{blue}{\tan x}\right)}^{2}} \]
      9. pow299.0%

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

      \[\leadsto \varepsilon + \varepsilon \cdot \color{blue}{\sqrt{{\left({\tan x}^{2}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. unpow299.0%

        \[\leadsto \varepsilon + \varepsilon \cdot \sqrt{\color{blue}{{\tan x}^{2} \cdot {\tan x}^{2}}} \]
      2. pow-sqr99.0%

        \[\leadsto \varepsilon + \varepsilon \cdot \sqrt{\color{blue}{{\tan x}^{\left(2 \cdot 2\right)}}} \]
      3. metadata-eval99.0%

        \[\leadsto \varepsilon + \varepsilon \cdot \sqrt{{\tan x}^{\color{blue}{4}}} \]
    8. Simplified99.0%

      \[\leadsto \varepsilon + \varepsilon \cdot \color{blue}{\sqrt{{\tan x}^{4}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -0.00068:\\ \;\;\;\;\tan \varepsilon\\ \mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \sqrt{{\tan x}^{4}}\\ \mathbf{else}:\\ \;\;\;\;\tan \varepsilon\\ \end{array} \]

Alternative 12: 76.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00068:\\
\;\;\;\;\tan \varepsilon\\

\mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\
\;\;\;\;\varepsilon \cdot \left(1 + {\tan x}^{2}\right)\\

\mathbf{else}:\\
\;\;\;\;\tan \varepsilon\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -6.8e-4 or 3.2e-29 < eps

    1. Initial program 59.2%

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

      \[\leadsto \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}} \]
    3. Step-by-step derivation
      1. tan-quot62.3%

        \[\leadsto \color{blue}{\tan \varepsilon} \]
      2. expm1-log1p-u49.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan \varepsilon\right)\right)} \]
      3. expm1-udef46.4%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\tan \varepsilon\right)} - 1} \]
    4. Applied egg-rr46.4%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\tan \varepsilon\right)} - 1} \]
    5. Step-by-step derivation
      1. expm1-def49.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan \varepsilon\right)\right)} \]
      2. expm1-log1p62.3%

        \[\leadsto \color{blue}{\tan \varepsilon} \]
    6. Simplified62.3%

      \[\leadsto \color{blue}{\tan \varepsilon} \]

    if -6.8e-4 < eps < 3.2e-29

    1. Initial program 27.5%

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

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

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

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

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

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

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

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}}}\right)}^{3} \]
      5. *-rgt-identity97.0%

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\varepsilon} + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}}\right)}^{3} \]
    6. Simplified97.0%

      \[\leadsto {\left(\sqrt[3]{\color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}}}\right)}^{3} \]
    7. Step-by-step derivation
      1. rem-cube-cbrt99.0%

        \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
      2. *-commutative99.0%

        \[\leadsto \varepsilon + \color{blue}{\frac{{\sin x}^{2}}{{\cos x}^{2}} \cdot \varepsilon} \]
      3. distribute-rgt1-in99.0%

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

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

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

        \[\leadsto \left(\color{blue}{\frac{\sin x}{\cos x} \cdot \frac{\sin x}{\cos x}} + 1\right) \cdot \varepsilon \]
      7. tan-quot99.0%

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

        \[\leadsto \left(\tan x \cdot \color{blue}{\tan x} + 1\right) \cdot \varepsilon \]
      9. pow299.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -0.00068:\\ \;\;\;\;\tan \varepsilon\\ \mathbf{elif}\;\varepsilon \leq 3.2 \cdot 10^{-29}:\\ \;\;\;\;\varepsilon \cdot \left(1 + {\tan x}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\tan \varepsilon\\ \end{array} \]

Alternative 13: 57.7% accurate, 2.0× speedup?

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

\\
\tan \varepsilon
\end{array}
Derivation
  1. Initial program 43.6%

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

    \[\leadsto \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}} \]
  3. Step-by-step derivation
    1. tan-quot59.7%

      \[\leadsto \color{blue}{\tan \varepsilon} \]
    2. expm1-log1p-u53.4%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan \varepsilon\right)\right)} \]
    3. expm1-udef26.6%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\tan \varepsilon\right)} - 1} \]
  4. Applied egg-rr26.6%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\tan \varepsilon\right)} - 1} \]
  5. Step-by-step derivation
    1. expm1-def53.4%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan \varepsilon\right)\right)} \]
    2. expm1-log1p59.7%

      \[\leadsto \color{blue}{\tan \varepsilon} \]
  6. Simplified59.7%

    \[\leadsto \color{blue}{\tan \varepsilon} \]
  7. Final simplification59.7%

    \[\leadsto \tan \varepsilon \]

Alternative 14: 30.7% accurate, 205.0× speedup?

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

\\
\varepsilon
\end{array}
Derivation
  1. Initial program 43.6%

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

    \[\leadsto \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}} \]
  3. Taylor expanded in eps around 0 31.4%

    \[\leadsto \color{blue}{\varepsilon} \]
  4. Final simplification31.4%

    \[\leadsto \varepsilon \]

Developer target: 76.4% 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 2023297 
(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)))