2tan (problem 3.3.2)

Percentage Accurate: 42.0% → 98.5%
Time: 18.9s
Alternatives: 13
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 13 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.0% 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.5% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\cos x}^{2}\\ t_1 := \tan x + \tan \varepsilon\\ t_2 := {\sin x}^{2}\\ t_3 := \frac{t_2}{t_0}\\ t_4 := t_3 + 1\\ t_5 := t_3 \cdot -0.3333333333333333\\ t_6 := \sin x \cdot t_4\\ t_7 := \frac{t_2 \cdot t_4}{t_0}\\ \mathbf{if}\;\varepsilon \leq -0.00023:\\ \;\;\;\;t_1 \cdot \frac{1}{1 - \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 4.4 \cdot 10^{-12}:\\ \;\;\;\;\left(\left(\left(0.3333333333333333 + \left(t_7 - t_5\right)\right) \cdot {\varepsilon}^{3} + \frac{t_6 \cdot {\varepsilon}^{2}}{\cos x}\right) + \varepsilon \cdot t_4\right) - {\varepsilon}^{4} \cdot \left(\frac{\sin x \cdot \left(\left(t_5 - t_7\right) - 0.3333333333333333\right)}{\cos x} + -0.3333333333333333 \cdot \frac{t_6}{\cos x}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t_1, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \tan x \cdot \tan \varepsilon}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right)\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (pow (cos x) 2.0))
        (t_1 (+ (tan x) (tan eps)))
        (t_2 (pow (sin x) 2.0))
        (t_3 (/ t_2 t_0))
        (t_4 (+ t_3 1.0))
        (t_5 (* t_3 -0.3333333333333333))
        (t_6 (* (sin x) t_4))
        (t_7 (/ (* t_2 t_4) t_0)))
   (if (<= eps -0.00023)
     (- (* t_1 (/ 1.0 (- 1.0 (/ (* (tan x) (sin eps)) (cos eps))))) (tan x))
     (if (<= eps 4.4e-12)
       (-
        (+
         (+
          (* (+ 0.3333333333333333 (- t_7 t_5)) (pow eps 3.0))
          (/ (* t_6 (pow eps 2.0)) (cos x)))
         (* eps t_4))
        (*
         (pow eps 4.0)
         (+
          (/ (* (sin x) (- (- t_5 t_7) 0.3333333333333333)) (cos x))
          (* -0.3333333333333333 (/ t_6 (cos x))))))
       (+
        (fma
         t_1
         (expm1 (log1p (/ -1.0 (+ -1.0 (* (tan x) (tan eps))))))
         (- (tan x)))
        (fma -1.0 (tan x) (tan x)))))))
double code(double x, double eps) {
	double t_0 = pow(cos(x), 2.0);
	double t_1 = tan(x) + tan(eps);
	double t_2 = pow(sin(x), 2.0);
	double t_3 = t_2 / t_0;
	double t_4 = t_3 + 1.0;
	double t_5 = t_3 * -0.3333333333333333;
	double t_6 = sin(x) * t_4;
	double t_7 = (t_2 * t_4) / t_0;
	double tmp;
	if (eps <= -0.00023) {
		tmp = (t_1 * (1.0 / (1.0 - ((tan(x) * sin(eps)) / cos(eps))))) - tan(x);
	} else if (eps <= 4.4e-12) {
		tmp = ((((0.3333333333333333 + (t_7 - t_5)) * pow(eps, 3.0)) + ((t_6 * pow(eps, 2.0)) / cos(x))) + (eps * t_4)) - (pow(eps, 4.0) * (((sin(x) * ((t_5 - t_7) - 0.3333333333333333)) / cos(x)) + (-0.3333333333333333 * (t_6 / cos(x)))));
	} else {
		tmp = fma(t_1, expm1(log1p((-1.0 / (-1.0 + (tan(x) * tan(eps)))))), -tan(x)) + fma(-1.0, tan(x), tan(x));
	}
	return tmp;
}
function code(x, eps)
	t_0 = cos(x) ^ 2.0
	t_1 = Float64(tan(x) + tan(eps))
	t_2 = sin(x) ^ 2.0
	t_3 = Float64(t_2 / t_0)
	t_4 = Float64(t_3 + 1.0)
	t_5 = Float64(t_3 * -0.3333333333333333)
	t_6 = Float64(sin(x) * t_4)
	t_7 = Float64(Float64(t_2 * t_4) / t_0)
	tmp = 0.0
	if (eps <= -0.00023)
		tmp = Float64(Float64(t_1 * Float64(1.0 / Float64(1.0 - Float64(Float64(tan(x) * sin(eps)) / cos(eps))))) - tan(x));
	elseif (eps <= 4.4e-12)
		tmp = Float64(Float64(Float64(Float64(Float64(0.3333333333333333 + Float64(t_7 - t_5)) * (eps ^ 3.0)) + Float64(Float64(t_6 * (eps ^ 2.0)) / cos(x))) + Float64(eps * t_4)) - Float64((eps ^ 4.0) * Float64(Float64(Float64(sin(x) * Float64(Float64(t_5 - t_7) - 0.3333333333333333)) / cos(x)) + Float64(-0.3333333333333333 * Float64(t_6 / cos(x))))));
	else
		tmp = Float64(fma(t_1, expm1(log1p(Float64(-1.0 / Float64(-1.0 + Float64(tan(x) * tan(eps)))))), Float64(-tan(x))) + fma(-1.0, tan(x), tan(x)));
	end
	return tmp
end
code[x_, eps_] := Block[{t$95$0 = N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 / t$95$0), $MachinePrecision]}, Block[{t$95$4 = N[(t$95$3 + 1.0), $MachinePrecision]}, Block[{t$95$5 = N[(t$95$3 * -0.3333333333333333), $MachinePrecision]}, Block[{t$95$6 = N[(N[Sin[x], $MachinePrecision] * t$95$4), $MachinePrecision]}, Block[{t$95$7 = N[(N[(t$95$2 * t$95$4), $MachinePrecision] / t$95$0), $MachinePrecision]}, If[LessEqual[eps, -0.00023], N[(N[(t$95$1 * N[(1.0 / N[(1.0 - N[(N[(N[Tan[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 4.4e-12], N[(N[(N[(N[(N[(0.3333333333333333 + N[(t$95$7 - t$95$5), $MachinePrecision]), $MachinePrecision] * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(t$95$6 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(eps * t$95$4), $MachinePrecision]), $MachinePrecision] - N[(N[Power[eps, 4.0], $MachinePrecision] * N[(N[(N[(N[Sin[x], $MachinePrecision] * N[(N[(t$95$5 - t$95$7), $MachinePrecision] - 0.3333333333333333), $MachinePrecision]), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(-0.3333333333333333 * N[(t$95$6 / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 * N[(Exp[N[Log[1 + N[(-1.0 / N[(-1.0 + N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision] + N[(-1.0 * N[Tan[x], $MachinePrecision] + N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\cos x}^{2}\\
t_1 := \tan x + \tan \varepsilon\\
t_2 := {\sin x}^{2}\\
t_3 := \frac{t_2}{t_0}\\
t_4 := t_3 + 1\\
t_5 := t_3 \cdot -0.3333333333333333\\
t_6 := \sin x \cdot t_4\\
t_7 := \frac{t_2 \cdot t_4}{t_0}\\
\mathbf{if}\;\varepsilon \leq -0.00023:\\
\;\;\;\;t_1 \cdot \frac{1}{1 - \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} - \tan x\\

\mathbf{elif}\;\varepsilon \leq 4.4 \cdot 10^{-12}:\\
\;\;\;\;\left(\left(\left(0.3333333333333333 + \left(t_7 - t_5\right)\right) \cdot {\varepsilon}^{3} + \frac{t_6 \cdot {\varepsilon}^{2}}{\cos x}\right) + \varepsilon \cdot t_4\right) - {\varepsilon}^{4} \cdot \left(\frac{\sin x \cdot \left(\left(t_5 - t_7\right) - 0.3333333333333333\right)}{\cos x} + -0.3333333333333333 \cdot \frac{t_6}{\cos x}\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_1, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \tan x \cdot \tan \varepsilon}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right)\\


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

    1. Initial program 54.7%

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

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

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

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

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

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

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

    if -2.3000000000000001e-4 < eps < 4.39999999999999983e-12

    1. Initial program 26.4%

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

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

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

      \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
    5. Step-by-step derivation
      1. add-cube-cbrt26.0%

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

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

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

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

    if 4.39999999999999983e-12 < eps

    1. Initial program 56.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -1 \cdot \tan x\right) + \mathsf{fma}\left(-1, \tan x, 1 \cdot \tan x\right)} \]
      6. *-un-lft-identity99.5%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right) + \mathsf{fma}\left(\color{blue}{-1}, \tan x, 1 \cdot \tan x\right) \]
      8. *-un-lft-identity99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \color{blue}{\tan x}\right) \]
    4. 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) + \mathsf{fma}\left(-1, \tan x, \tan x\right)} \]
    5. Step-by-step derivation
      1. expm1-log1p-u99.5%

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\color{blue}{-1}}{-\left(1 - \tan x \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      4. sub-neg99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-\color{blue}{\left(1 + \left(-\tan x \cdot \tan \varepsilon\right)\right)}}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      5. distribute-neg-in99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{\color{blue}{\left(-1\right) + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      6. metadata-eval99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{\color{blue}{-1} + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      7. distribute-lft-neg-in99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      8. add-sqr-sqrt52.3%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\left(\sqrt{-\tan x} \cdot \sqrt{-\tan x}\right)} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      9. sqrt-unprod84.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      10. sqr-neg84.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      11. sqrt-unprod32.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\left(\sqrt{\tan x} \cdot \sqrt{\tan x}\right)} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      12. add-sqr-sqrt59.1%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\tan x} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      13. distribute-lft-neg-in59.1%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      14. add-sqr-sqrt27.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -0.00023:\\ \;\;\;\;\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 4.4 \cdot 10^{-12}:\\ \;\;\;\;\left(\left(\left(0.3333333333333333 + \left(\frac{{\sin x}^{2} \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)}{{\cos x}^{2}} - \frac{{\sin x}^{2}}{{\cos x}^{2}} \cdot -0.3333333333333333\right)\right) \cdot {\varepsilon}^{3} + \frac{\left(\sin x \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)\right) \cdot {\varepsilon}^{2}}{\cos x}\right) + \varepsilon \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)\right) - {\varepsilon}^{4} \cdot \left(\frac{\sin x \cdot \left(\left(\frac{{\sin x}^{2}}{{\cos x}^{2}} \cdot -0.3333333333333333 - \frac{{\sin x}^{2} \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)}{{\cos x}^{2}}\right) - 0.3333333333333333\right)}{\cos x} + -0.3333333333333333 \cdot \frac{\sin x \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)}{\cos x}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \tan x \cdot \tan \varepsilon}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 98.5% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ t_1 := \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \mathbf{if}\;\varepsilon \leq -3.6 \cdot 10^{-5}:\\ \;\;\;\;t_0 \cdot \frac{1}{1 - \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 4.4 \cdot 10^{-12}:\\ \;\;\;\;{\varepsilon}^{2} \cdot \left(\frac{\sin x}{\cos x} + \frac{{\sin x}^{3}}{{\cos x}^{3}}\right) + \left({\varepsilon}^{3} \cdot \left(0.3333333333333333 + \left(t_1 - \left(t_1 \cdot -0.3333333333333333 - \frac{{\sin x}^{4}}{{\cos x}^{4}}\right)\right)\right) + \varepsilon \cdot \left(t_1 + 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t_0, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \tan x \cdot \tan \varepsilon}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right)\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps)))
        (t_1 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
   (if (<= eps -3.6e-5)
     (- (* t_0 (/ 1.0 (- 1.0 (/ (* (tan x) (sin eps)) (cos eps))))) (tan x))
     (if (<= eps 4.4e-12)
       (+
        (*
         (pow eps 2.0)
         (+ (/ (sin x) (cos x)) (/ (pow (sin x) 3.0) (pow (cos x) 3.0))))
        (+
         (*
          (pow eps 3.0)
          (+
           0.3333333333333333
           (-
            t_1
            (-
             (* t_1 -0.3333333333333333)
             (/ (pow (sin x) 4.0) (pow (cos x) 4.0))))))
         (* eps (+ t_1 1.0))))
       (+
        (fma
         t_0
         (expm1 (log1p (/ -1.0 (+ -1.0 (* (tan x) (tan eps))))))
         (- (tan x)))
        (fma -1.0 (tan x) (tan x)))))))
double code(double x, double eps) {
	double t_0 = tan(x) + tan(eps);
	double t_1 = pow(sin(x), 2.0) / pow(cos(x), 2.0);
	double tmp;
	if (eps <= -3.6e-5) {
		tmp = (t_0 * (1.0 / (1.0 - ((tan(x) * sin(eps)) / cos(eps))))) - tan(x);
	} else if (eps <= 4.4e-12) {
		tmp = (pow(eps, 2.0) * ((sin(x) / cos(x)) + (pow(sin(x), 3.0) / pow(cos(x), 3.0)))) + ((pow(eps, 3.0) * (0.3333333333333333 + (t_1 - ((t_1 * -0.3333333333333333) - (pow(sin(x), 4.0) / pow(cos(x), 4.0)))))) + (eps * (t_1 + 1.0)));
	} else {
		tmp = fma(t_0, expm1(log1p((-1.0 / (-1.0 + (tan(x) * tan(eps)))))), -tan(x)) + fma(-1.0, tan(x), tan(x));
	}
	return tmp;
}
function code(x, eps)
	t_0 = Float64(tan(x) + tan(eps))
	t_1 = Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))
	tmp = 0.0
	if (eps <= -3.6e-5)
		tmp = Float64(Float64(t_0 * Float64(1.0 / Float64(1.0 - Float64(Float64(tan(x) * sin(eps)) / cos(eps))))) - tan(x));
	elseif (eps <= 4.4e-12)
		tmp = Float64(Float64((eps ^ 2.0) * Float64(Float64(sin(x) / cos(x)) + Float64((sin(x) ^ 3.0) / (cos(x) ^ 3.0)))) + Float64(Float64((eps ^ 3.0) * Float64(0.3333333333333333 + Float64(t_1 - Float64(Float64(t_1 * -0.3333333333333333) - Float64((sin(x) ^ 4.0) / (cos(x) ^ 4.0)))))) + Float64(eps * Float64(t_1 + 1.0))));
	else
		tmp = Float64(fma(t_0, expm1(log1p(Float64(-1.0 / Float64(-1.0 + Float64(tan(x) * tan(eps)))))), Float64(-tan(x))) + fma(-1.0, tan(x), tan(x)));
	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[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -3.6e-5], N[(N[(t$95$0 * N[(1.0 / N[(1.0 - N[(N[(N[Tan[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 4.4e-12], N[(N[(N[Power[eps, 2.0], $MachinePrecision] * N[(N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[Sin[x], $MachinePrecision], 3.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[eps, 3.0], $MachinePrecision] * N[(0.3333333333333333 + N[(t$95$1 - N[(N[(t$95$1 * -0.3333333333333333), $MachinePrecision] - N[(N[Power[N[Sin[x], $MachinePrecision], 4.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(eps * N[(t$95$1 + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * N[(Exp[N[Log[1 + N[(-1.0 / N[(-1.0 + N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision] + N[(-1.0 * N[Tan[x], $MachinePrecision] + N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\varepsilon \leq 4.4 \cdot 10^{-12}:\\
\;\;\;\;{\varepsilon}^{2} \cdot \left(\frac{\sin x}{\cos x} + \frac{{\sin x}^{3}}{{\cos x}^{3}}\right) + \left({\varepsilon}^{3} \cdot \left(0.3333333333333333 + \left(t_1 - \left(t_1 \cdot -0.3333333333333333 - \frac{{\sin x}^{4}}{{\cos x}^{4}}\right)\right)\right) + \varepsilon \cdot \left(t_1 + 1\right)\right)\\

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


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

    1. Initial program 54.7%

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

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

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

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

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

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

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

    if -3.60000000000000009e-5 < eps < 4.39999999999999983e-12

    1. Initial program 26.4%

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

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

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

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

      \[\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) + \left(\varepsilon \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) + {\varepsilon}^{3} \cdot \left(0.3333333333333333 - \left(-1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} + \left(-1 \cdot \frac{{\sin x}^{4}}{{\cos x}^{4}} + -0.3333333333333333 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)\right)\right)} \]

    if 4.39999999999999983e-12 < eps

    1. Initial program 56.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -1 \cdot \tan x\right) + \mathsf{fma}\left(-1, \tan x, 1 \cdot \tan x\right)} \]
      6. *-un-lft-identity99.5%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right) + \mathsf{fma}\left(\color{blue}{-1}, \tan x, 1 \cdot \tan x\right) \]
      8. *-un-lft-identity99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \color{blue}{\tan x}\right) \]
    4. 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) + \mathsf{fma}\left(-1, \tan x, \tan x\right)} \]
    5. Step-by-step derivation
      1. expm1-log1p-u99.5%

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\color{blue}{-1}}{-\left(1 - \tan x \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      4. sub-neg99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-\color{blue}{\left(1 + \left(-\tan x \cdot \tan \varepsilon\right)\right)}}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      5. distribute-neg-in99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{\color{blue}{\left(-1\right) + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      6. metadata-eval99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{\color{blue}{-1} + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      7. distribute-lft-neg-in99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      8. add-sqr-sqrt52.3%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\left(\sqrt{-\tan x} \cdot \sqrt{-\tan x}\right)} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      9. sqrt-unprod84.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      10. sqr-neg84.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      11. sqrt-unprod32.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\left(\sqrt{\tan x} \cdot \sqrt{\tan x}\right)} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      12. add-sqr-sqrt59.1%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\tan x} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      13. distribute-lft-neg-in59.1%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      14. add-sqr-sqrt27.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -3.6 \cdot 10^{-5}:\\ \;\;\;\;\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 4.4 \cdot 10^{-12}:\\ \;\;\;\;{\varepsilon}^{2} \cdot \left(\frac{\sin x}{\cos x} + \frac{{\sin x}^{3}}{{\cos x}^{3}}\right) + \left({\varepsilon}^{3} \cdot \left(0.3333333333333333 + \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} - \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} \cdot -0.3333333333333333 - \frac{{\sin x}^{4}}{{\cos x}^{4}}\right)\right)\right) + \varepsilon \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \tan x \cdot \tan \varepsilon}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 98.5% accurate, 0.2× speedup?

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

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

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

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


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

    1. Initial program 53.4%

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

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

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

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

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

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

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

    if -3.2000000000000001e-7 < eps < 4.39999999999999983e-12

    1. Initial program 26.8%

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

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

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

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

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

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

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

      \[\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)} \]
    8. Step-by-step derivation
      1. +-commutative99.6%

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

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

        \[\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)} \]
      4. cancel-sign-sub-inv99.6%

        \[\leadsto \varepsilon \cdot \color{blue}{\left(1 + \left(--1\right) \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) \]
      5. metadata-eval99.6%

        \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{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) \]
      6. *-lft-identity99.6%

        \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{\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) \]
    9. Simplified99.6%

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

    if 4.39999999999999983e-12 < eps

    1. Initial program 56.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -1 \cdot \tan x\right) + \mathsf{fma}\left(-1, \tan x, 1 \cdot \tan x\right)} \]
      6. *-un-lft-identity99.5%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right) + \mathsf{fma}\left(\color{blue}{-1}, \tan x, 1 \cdot \tan x\right) \]
      8. *-un-lft-identity99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \color{blue}{\tan x}\right) \]
    4. 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) + \mathsf{fma}\left(-1, \tan x, \tan x\right)} \]
    5. Step-by-step derivation
      1. expm1-log1p-u99.5%

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\color{blue}{-1}}{-\left(1 - \tan x \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      4. sub-neg99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-\color{blue}{\left(1 + \left(-\tan x \cdot \tan \varepsilon\right)\right)}}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      5. distribute-neg-in99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{\color{blue}{\left(-1\right) + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      6. metadata-eval99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{\color{blue}{-1} + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      7. distribute-lft-neg-in99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      8. add-sqr-sqrt52.3%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\left(\sqrt{-\tan x} \cdot \sqrt{-\tan x}\right)} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      9. sqrt-unprod84.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      10. sqr-neg84.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      11. sqrt-unprod32.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\left(\sqrt{\tan x} \cdot \sqrt{\tan x}\right)} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      12. add-sqr-sqrt59.1%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\tan x} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      13. distribute-lft-neg-in59.1%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      14. add-sqr-sqrt27.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -3.2 \cdot 10^{-7}:\\ \;\;\;\;\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 4.4 \cdot 10^{-12}:\\ \;\;\;\;{\varepsilon}^{2} \cdot \left(\frac{\sin x}{\cos x} + \frac{{\sin x}^{3}}{{\cos x}^{3}}\right) + \varepsilon \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \tan x \cdot \tan \varepsilon}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 98.4% accurate, 0.2× speedup?

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

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

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

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


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

    1. Initial program 53.4%

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

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

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

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

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

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

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

    if -7.4e-9 < eps < 4.39999999999999983e-12

    1. Initial program 26.8%

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

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

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

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

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

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

    if 4.39999999999999983e-12 < eps

    1. Initial program 56.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -1 \cdot \tan x\right) + \mathsf{fma}\left(-1, \tan x, 1 \cdot \tan x\right)} \]
      6. *-un-lft-identity99.5%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right) + \mathsf{fma}\left(\color{blue}{-1}, \tan x, 1 \cdot \tan x\right) \]
      8. *-un-lft-identity99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \color{blue}{\tan x}\right) \]
    4. 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) + \mathsf{fma}\left(-1, \tan x, \tan x\right)} \]
    5. Step-by-step derivation
      1. expm1-log1p-u99.5%

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\color{blue}{-1}}{-\left(1 - \tan x \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      4. sub-neg99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-\color{blue}{\left(1 + \left(-\tan x \cdot \tan \varepsilon\right)\right)}}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      5. distribute-neg-in99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{\color{blue}{\left(-1\right) + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      6. metadata-eval99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{\color{blue}{-1} + \left(-\left(-\tan x \cdot \tan \varepsilon\right)\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      7. distribute-lft-neg-in99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      8. add-sqr-sqrt52.3%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\left(\sqrt{-\tan x} \cdot \sqrt{-\tan x}\right)} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      9. sqrt-unprod84.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\sqrt{\left(-\tan x\right) \cdot \left(-\tan x\right)}} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      10. sqr-neg84.4%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\sqrt{\color{blue}{\tan x \cdot \tan x}} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      11. sqrt-unprod32.0%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\left(\sqrt{\tan x} \cdot \sqrt{\tan x}\right)} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      12. add-sqr-sqrt59.1%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \left(-\color{blue}{\tan x} \cdot \tan \varepsilon\right)}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      13. distribute-lft-neg-in59.1%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \color{blue}{\left(-\tan x\right) \cdot \tan \varepsilon}}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
      14. add-sqr-sqrt27.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -7.4 \cdot 10^{-9}:\\ \;\;\;\;\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 4.4 \cdot 10^{-12}:\\ \;\;\;\;\varepsilon \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{-1 + \tan x \cdot \tan \varepsilon}\right)\right), -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 99.3% accurate, 0.2× speedup?

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

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

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

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


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

    1. Initial program 53.4%

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

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

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

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

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

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

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

    if -7.4e-9 < eps < 4.39999999999999983e-12

    1. Initial program 26.8%

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

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

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

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

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

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

    if 4.39999999999999983e-12 < eps

    1. Initial program 56.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -1 \cdot \tan x\right) + \mathsf{fma}\left(-1, \tan x, 1 \cdot \tan x\right)} \]
      6. *-un-lft-identity99.5%

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right) + \mathsf{fma}\left(\color{blue}{-1}, \tan x, 1 \cdot \tan x\right) \]
      8. *-un-lft-identity99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right) + \mathsf{fma}\left(-1, \tan x, \color{blue}{\tan x}\right) \]
    4. 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) + \mathsf{fma}\left(-1, \tan x, \tan x\right)} \]
    5. Step-by-step derivation
      1. *-commutative99.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -7.4 \cdot 10^{-9}:\\ \;\;\;\;\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 4.4 \cdot 10^{-12}:\\ \;\;\;\;\varepsilon \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-1, \tan x, \tan x\right) + \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}}, -\tan x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 99.3% accurate, 0.3× speedup?

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

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

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

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


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

    1. Initial program 53.4%

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

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

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

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

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

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

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

    if -7.4e-9 < eps < 4.39999999999999983e-12

    1. Initial program 26.8%

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

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

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

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

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

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

    if 4.39999999999999983e-12 < eps

    1. Initial program 56.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{1 - \color{blue}{\frac{\tan x}{\frac{\cos \varepsilon}{\sin \varepsilon}}}}, \tan x + \tan \varepsilon, -\tan x\right) \]
      4. div-inv99.4%

        \[\leadsto \mathsf{fma}\left(\frac{1}{1 - \color{blue}{\tan x \cdot \frac{1}{\frac{\cos \varepsilon}{\sin \varepsilon}}}}, \tan x + \tan \varepsilon, -\tan x\right) \]
      5. clear-num99.5%

        \[\leadsto \mathsf{fma}\left(\frac{1}{1 - \tan x \cdot \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}}}, \tan x + \tan \varepsilon, -\tan x\right) \]
      6. tan-quot99.5%

        \[\leadsto \mathsf{fma}\left(\frac{1}{1 - \tan x \cdot \color{blue}{\tan \varepsilon}}, \tan x + \tan \varepsilon, -\tan x\right) \]
      7. log1p-expm1-u98.4%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -7.4 \cdot 10^{-9}:\\ \;\;\;\;\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 4.4 \cdot 10^{-12}:\\ \;\;\;\;\varepsilon \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{1 - \tan x \cdot \tan \varepsilon}, \tan x + \tan \varepsilon, -\tan x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 99.3% accurate, 0.3× speedup?

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

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

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

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


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

    1. Initial program 53.4%

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

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

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

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

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

      \[\leadsto \left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\tan x \cdot \tan \varepsilon\right)\right)}} - \tan x \]
    7. Step-by-step derivation
      1. log1p-expm1-u98.8%

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

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

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

        \[\leadsto \left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan \varepsilon \cdot \color{blue}{\frac{1}{\frac{\cos x}{\sin x}}}} - \tan x \]
      5. un-div-inv98.9%

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

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

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

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

    if -7.4e-9 < eps < 4.39999999999999983e-12

    1. Initial program 26.8%

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

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

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

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

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

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

    if 4.39999999999999983e-12 < eps

    1. Initial program 56.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{1 - \color{blue}{\frac{\tan x}{\frac{\cos \varepsilon}{\sin \varepsilon}}}}, \tan x + \tan \varepsilon, -\tan x\right) \]
      4. div-inv99.4%

        \[\leadsto \mathsf{fma}\left(\frac{1}{1 - \color{blue}{\tan x \cdot \frac{1}{\frac{\cos \varepsilon}{\sin \varepsilon}}}}, \tan x + \tan \varepsilon, -\tan x\right) \]
      5. clear-num99.5%

        \[\leadsto \mathsf{fma}\left(\frac{1}{1 - \tan x \cdot \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}}}, \tan x + \tan \varepsilon, -\tan x\right) \]
      6. tan-quot99.5%

        \[\leadsto \mathsf{fma}\left(\frac{1}{1 - \tan x \cdot \color{blue}{\tan \varepsilon}}, \tan x + \tan \varepsilon, -\tan x\right) \]
      7. log1p-expm1-u98.4%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -7.4 \cdot 10^{-9}:\\ \;\;\;\;\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \frac{\tan \varepsilon}{\frac{1}{\tan x}}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 4.4 \cdot 10^{-12}:\\ \;\;\;\;\varepsilon \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{1 - \tan x \cdot \tan \varepsilon}, \tan x + \tan \varepsilon, -\tan x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 99.3% accurate, 0.4× speedup?

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

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

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

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


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

    1. Initial program 53.4%

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

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

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

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

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

      \[\leadsto \left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\tan x \cdot \tan \varepsilon\right)\right)}} - \tan x \]
    7. Step-by-step derivation
      1. log1p-expm1-u98.8%

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

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

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

        \[\leadsto \left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan \varepsilon \cdot \color{blue}{\frac{1}{\frac{\cos x}{\sin x}}}} - \tan x \]
      5. un-div-inv98.9%

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

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

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

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

    if -7.4e-9 < eps < 4.39999999999999983e-12

    1. Initial program 26.8%

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

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

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

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

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

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

    if 4.39999999999999983e-12 < eps

    1. Initial program 56.0%

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\color{blue}{1 \cdot \tan x}\right) + \mathsf{fma}\left(-\tan x, 1, \tan x \cdot 1\right) \]
      6. *-un-lft-identity99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\color{blue}{\tan x}\right) + \mathsf{fma}\left(-\tan x, 1, \tan x \cdot 1\right) \]
      7. *-commutative99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right) + \mathsf{fma}\left(-\tan x, 1, \color{blue}{1 \cdot \tan x}\right) \]
      8. *-un-lft-identity99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right) + \mathsf{fma}\left(-\tan x, 1, \color{blue}{\tan x}\right) \]
    4. 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) + \mathsf{fma}\left(-\tan x, 1, \tan x\right)} \]
    5. Step-by-step derivation
      1. +-commutative99.5%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -7.4 \cdot 10^{-9}:\\ \;\;\;\;\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \frac{\tan \varepsilon}{\frac{1}{\tan x}}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 4.4 \cdot 10^{-12}:\\ \;\;\;\;\varepsilon \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 99.3% accurate, 0.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -7.4e-9 or 4.39999999999999983e-12 < eps

    1. Initial program 54.5%

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\color{blue}{1 \cdot \tan x}\right) + \mathsf{fma}\left(-\tan x, 1, \tan x \cdot 1\right) \]
      6. *-un-lft-identity99.1%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\color{blue}{\tan x}\right) + \mathsf{fma}\left(-\tan x, 1, \tan x \cdot 1\right) \]
      7. *-commutative99.1%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right) + \mathsf{fma}\left(-\tan x, 1, \color{blue}{1 \cdot \tan x}\right) \]
      8. *-un-lft-identity99.1%

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

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

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

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

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

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

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

    if -7.4e-9 < eps < 4.39999999999999983e-12

    1. Initial program 26.8%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -7.4 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 4.4 \cdot 10^{-12}\right):\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\varepsilon \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)\\ \end{array} \]
  5. Add Preprocessing

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

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

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


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

    1. Initial program 53.4%

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

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

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

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

    if -7.4e-9 < eps < 4.39999999999999983e-12

    1. Initial program 26.8%

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

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

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

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

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

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

    if 4.39999999999999983e-12 < eps

    1. Initial program 56.0%

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\color{blue}{1 \cdot \tan x}\right) + \mathsf{fma}\left(-\tan x, 1, \tan x \cdot 1\right) \]
      6. *-un-lft-identity99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\color{blue}{\tan x}\right) + \mathsf{fma}\left(-\tan x, 1, \tan x \cdot 1\right) \]
      7. *-commutative99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right) + \mathsf{fma}\left(-\tan x, 1, \color{blue}{1 \cdot \tan x}\right) \]
      8. *-un-lft-identity99.5%

        \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right) + \mathsf{fma}\left(-\tan x, 1, \color{blue}{\tan x}\right) \]
    4. 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) + \mathsf{fma}\left(-\tan x, 1, \tan x\right)} \]
    5. Step-by-step derivation
      1. +-commutative99.5%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -7.4 \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.4 \cdot 10^{-12}:\\ \;\;\;\;\varepsilon \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 77.3% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0022 \lor \neg \left(\varepsilon \leq 4.4 \cdot 10^{-12}\right):\\
\;\;\;\;\tan \varepsilon\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -0.00220000000000000013 or 4.39999999999999983e-12 < eps

    1. Initial program 55.6%

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

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

        \[\leadsto \color{blue}{\tan \varepsilon} \]
    5. Applied egg-rr58.7%

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

    if -0.00220000000000000013 < eps < 4.39999999999999983e-12

    1. Initial program 26.2%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -0.0022 \lor \neg \left(\varepsilon \leq 4.4 \cdot 10^{-12}\right):\\ \;\;\;\;\tan \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\varepsilon \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 57.9% 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 41.6%

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

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

      \[\leadsto \color{blue}{\tan \varepsilon} \]
  5. Applied egg-rr58.7%

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

    \[\leadsto \tan \varepsilon \]
  7. Add Preprocessing

Alternative 13: 30.6% 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 41.6%

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

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

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

    \[\leadsto \varepsilon \]
  6. Add Preprocessing

Developer target: 76.2% 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 2024013 
(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)))