2tan (problem 3.3.2)

Percentage Accurate: 42.0% → 99.4%
Time: 21.3s
Alternatives: 17
Speedup: 1.8×

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 17 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: 99.4% accurate, 0.2× speedup?

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

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

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

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


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

    1. Initial program 61.1%

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}}} - \tan x \]
      5. associate-/r/99.4%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-\left(\tan x + \tan \varepsilon\right)}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}} - \tan x \]
    9. Taylor expanded in x around inf 99.5%

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

    if -1.4000000000000001e-7 < eps < 8.0000000000000002e-13

    1. Initial program 31.5%

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

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

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

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

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

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

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

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

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

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

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

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

    if 8.0000000000000002e-13 < eps

    1. Initial program 56.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.5% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\sin \varepsilon}{\cos \varepsilon}\\ \left(\frac{t_0}{1 - t_0 \cdot \frac{\sin x}{\cos x}} + \frac{\tan x \cdot \tan \varepsilon}{\frac{1}{\tan x} - \tan \varepsilon}\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (/ (sin eps) (cos eps))))
   (+
    (+
     (/ t_0 (- 1.0 (* t_0 (/ (sin x) (cos x)))))
     (/ (* (tan x) (tan eps)) (- (/ 1.0 (tan x)) (tan eps))))
    (fma -1.0 (tan x) (tan x)))))
double code(double x, double eps) {
	double t_0 = sin(eps) / cos(eps);
	return ((t_0 / (1.0 - (t_0 * (sin(x) / cos(x))))) + ((tan(x) * tan(eps)) / ((1.0 / tan(x)) - tan(eps)))) + fma(-1.0, tan(x), tan(x));
}
function code(x, eps)
	t_0 = Float64(sin(eps) / cos(eps))
	return Float64(Float64(Float64(t_0 / Float64(1.0 - Float64(t_0 * Float64(sin(x) / cos(x))))) + Float64(Float64(tan(x) * tan(eps)) / Float64(Float64(1.0 / tan(x)) - tan(eps)))) + fma(-1.0, tan(x), tan(x)))
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(t$95$0 / N[(1.0 - N[(t$95$0 * N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 / N[Tan[x], $MachinePrecision]), $MachinePrecision] - N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 * N[Tan[x], $MachinePrecision] + N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\sin \varepsilon}{\cos \varepsilon}\\
\left(\frac{t_0}{1 - t_0 \cdot \frac{\sin x}{\cos x}} + \frac{\tan x \cdot \tan \varepsilon}{\frac{1}{\tan x} - \tan \varepsilon}\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right)
\end{array}
\end{array}
Derivation
  1. Initial program 45.9%

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

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

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

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

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

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

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

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

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

    \[\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. Taylor expanded in x around inf 67.7%

    \[\leadsto \color{blue}{\left(\left(\frac{\sin \varepsilon}{\cos \varepsilon \cdot \left(1 - \frac{\sin \varepsilon \cdot \sin x}{\cos \varepsilon \cdot \cos x}\right)} + \frac{\sin x}{\cos x \cdot \left(1 - \frac{\sin \varepsilon \cdot \sin x}{\cos \varepsilon \cdot \cos x}\right)}\right) - \frac{\sin x}{\cos x}\right)} + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
  6. Step-by-step derivation
    1. associate--l+82.1%

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

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

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

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

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

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

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

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

      \[\leadsto \left(\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \log \left(e^{\frac{\tan x}{1 - \tan \varepsilon \cdot \color{blue}{\tan x}} - \tan x}\right)\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
    6. *-commutative82.2%

      \[\leadsto \left(\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \log \left(e^{\frac{\tan x}{1 - \color{blue}{\tan x \cdot \tan \varepsilon}} - \tan x}\right)\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
  9. Applied egg-rr82.2%

    \[\leadsto \left(\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \color{blue}{\log \left(e^{\frac{\tan x}{1 - \tan x \cdot \tan \varepsilon} - \tan x}\right)}\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
  10. Step-by-step derivation
    1. rem-log-exp82.2%

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

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

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

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

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

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

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

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

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

    \[\leadsto \left(\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \color{blue}{\frac{\tan x \cdot \frac{1}{\tan x} - \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot 1}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x}}}\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
  12. Step-by-step derivation
    1. rgt-mult-inverse82.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \left(\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \frac{\tan x \cdot \tan \varepsilon}{\frac{1}{\tan x} - \tan \varepsilon}\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right) \]
  15. Add Preprocessing

Alternative 3: 99.4% accurate, 0.2× speedup?

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

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

\mathbf{elif}\;\varepsilon \leq 8 \cdot 10^{-13}:\\
\;\;\;\;\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)\\

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


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

    1. Initial program 61.1%

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}}} - \tan x \]
      5. associate-/r/99.4%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-\left(\tan x + \tan \varepsilon\right)}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}} - \tan x \]
    9. Taylor expanded in x around inf 99.5%

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

    if -1.69999999999999987e-7 < eps < 8.0000000000000002e-13

    1. Initial program 31.5%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}}} - \tan x \]
    5. 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)} \]
    6. 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. sub-neg99.6%

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

        \[\leadsto \varepsilon \cdot \left(1 + \left(-\color{blue}{\left(-\frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}\right)\right) - {\varepsilon}^{2} \cdot \left(-1 \cdot \frac{\sin x}{\cos x} + -1 \cdot \frac{{\sin x}^{3}}{{\cos x}^{3}}\right) \]
      6. remove-double-neg99.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) \]
    7. 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 8.0000000000000002e-13 < eps

    1. Initial program 56.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -1.7 \cdot 10^{-7}:\\ \;\;\;\;\frac{\left(-\tan x\right) - \tan \varepsilon}{-1 + \frac{\sin \varepsilon \cdot \sin x}{\cos \varepsilon \cdot \cos x}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 8 \cdot 10^{-13}:\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-1, \tan x, \tan x\right) + \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \frac{\sin \varepsilon \cdot \tan x}{\cos \varepsilon}}, -\tan x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 99.4% accurate, 0.2× speedup?

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

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

\mathbf{elif}\;\varepsilon \leq 8 \cdot 10^{-13}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\

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


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

    1. Initial program 61.1%

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}}} - \tan x \]
      5. associate-/r/99.4%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-\left(\tan x + \tan \varepsilon\right)}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}} - \tan x \]
    9. Taylor expanded in x around inf 99.5%

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

    if -3.6e-9 < eps < 8.0000000000000002e-13

    1. Initial program 31.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \varepsilon + \color{blue}{{\tan x}^{2}} \cdot \varepsilon \]
    7. Applied egg-rr99.2%

      \[\leadsto \color{blue}{\varepsilon + {\tan x}^{2} \cdot \varepsilon} \]
    8. Step-by-step derivation
      1. +-commutative99.2%

        \[\leadsto \color{blue}{{\tan x}^{2} \cdot \varepsilon + \varepsilon} \]
      2. *-commutative99.2%

        \[\leadsto \color{blue}{\varepsilon \cdot {\tan x}^{2}} + \varepsilon \]
      3. fma-def99.2%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)} \]

    if 8.0000000000000002e-13 < eps

    1. Initial program 56.9%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \color{blue}{\frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}}}, -\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^{-9}:\\ \;\;\;\;\frac{\left(-\tan x\right) - \tan \varepsilon}{-1 + \frac{\sin \varepsilon \cdot \sin x}{\cos \varepsilon \cdot \cos x}} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 8 \cdot 10^{-13}:\\ \;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-1, \tan x, \tan x\right) + \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \frac{\sin \varepsilon \cdot \tan x}{\cos \varepsilon}}, -\tan x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 99.3% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;\varepsilon \leq 8 \cdot 10^{-13}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\

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


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

    1. Initial program 61.1%

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}}} - \tan x \]
      5. associate-/r/99.4%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-\left(\tan x + \tan \varepsilon\right)}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}} - \tan x \]
    9. Taylor expanded in x around inf 99.5%

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

    if -4.20000000000000039e-9 < eps < 8.0000000000000002e-13

    1. Initial program 31.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \varepsilon + \color{blue}{{\tan x}^{2}} \cdot \varepsilon \]
    7. Applied egg-rr99.2%

      \[\leadsto \color{blue}{\varepsilon + {\tan x}^{2} \cdot \varepsilon} \]
    8. Step-by-step derivation
      1. +-commutative99.2%

        \[\leadsto \color{blue}{{\tan x}^{2} \cdot \varepsilon + \varepsilon} \]
      2. *-commutative99.2%

        \[\leadsto \color{blue}{\varepsilon \cdot {\tan x}^{2}} + \varepsilon \]
      3. fma-def99.2%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)} \]

    if 8.0000000000000002e-13 < eps

    1. Initial program 56.9%

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

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

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

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

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

Alternative 6: 99.4% accurate, 0.3× speedup?

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

\mathbf{elif}\;\varepsilon \leq 8 \cdot 10^{-13}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\

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


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

    1. Initial program 61.1%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
    7. 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)} \]

    if -5.79999999999999982e-9 < eps < 8.0000000000000002e-13

    1. Initial program 31.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \varepsilon + \color{blue}{{\tan x}^{2}} \cdot \varepsilon \]
    7. Applied egg-rr99.2%

      \[\leadsto \color{blue}{\varepsilon + {\tan x}^{2} \cdot \varepsilon} \]
    8. Step-by-step derivation
      1. +-commutative99.2%

        \[\leadsto \color{blue}{{\tan x}^{2} \cdot \varepsilon + \varepsilon} \]
      2. *-commutative99.2%

        \[\leadsto \color{blue}{\varepsilon \cdot {\tan x}^{2}} + \varepsilon \]
      3. fma-def99.2%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)} \]

    if 8.0000000000000002e-13 < eps

    1. Initial program 56.9%

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

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

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

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

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

Alternative 7: 99.4% 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 -4.2 \cdot 10^{-9}:\\ \;\;\;\;\frac{t_0}{t_1} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 8 \cdot 10^{-13}:\\ \;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \frac{1}{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 -4.2e-9)
     (- (/ t_0 t_1) (tan x))
     (if (<= eps 8e-13)
       (fma eps (pow (tan x) 2.0) eps)
       (- (* t_0 (/ 1.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 <= -4.2e-9) {
		tmp = (t_0 / t_1) - tan(x);
	} else if (eps <= 8e-13) {
		tmp = fma(eps, pow(tan(x), 2.0), eps);
	} else {
		tmp = (t_0 * (1.0 / t_1)) - 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 <= -4.2e-9)
		tmp = Float64(Float64(t_0 / t_1) - tan(x));
	elseif (eps <= 8e-13)
		tmp = fma(eps, (tan(x) ^ 2.0), eps);
	else
		tmp = Float64(Float64(t_0 * Float64(1.0 / t_1)) - 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[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -4.2e-9], N[(N[(t$95$0 / t$95$1), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 8e-13], N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision] + eps), $MachinePrecision], N[(N[(t$95$0 * N[(1.0 / t$95$1), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\varepsilon \leq 8 \cdot 10^{-13}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\

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


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

    1. Initial program 61.1%

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

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

    if -4.20000000000000039e-9 < eps < 8.0000000000000002e-13

    1. Initial program 31.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \varepsilon + \color{blue}{{\tan x}^{2}} \cdot \varepsilon \]
    7. Applied egg-rr99.2%

      \[\leadsto \color{blue}{\varepsilon + {\tan x}^{2} \cdot \varepsilon} \]
    8. Step-by-step derivation
      1. +-commutative99.2%

        \[\leadsto \color{blue}{{\tan x}^{2} \cdot \varepsilon + \varepsilon} \]
      2. *-commutative99.2%

        \[\leadsto \color{blue}{\varepsilon \cdot {\tan x}^{2}} + \varepsilon \]
      3. fma-def99.2%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)} \]

    if 8.0000000000000002e-13 < eps

    1. Initial program 56.9%

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

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

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

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

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

Alternative 8: 99.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -3.8 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 8 \cdot 10^{-13}\right):\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= eps -3.8e-9) (not (<= eps 8e-13)))
   (- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x))
   (fma eps (pow (tan x) 2.0) eps)))
double code(double x, double eps) {
	double tmp;
	if ((eps <= -3.8e-9) || !(eps <= 8e-13)) {
		tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
	} else {
		tmp = fma(eps, pow(tan(x), 2.0), eps);
	}
	return tmp;
}
function code(x, eps)
	tmp = 0.0
	if ((eps <= -3.8e-9) || !(eps <= 8e-13))
		tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x));
	else
		tmp = fma(eps, (tan(x) ^ 2.0), eps);
	end
	return tmp
end
code[x_, eps_] := If[Or[LessEqual[eps, -3.8e-9], N[Not[LessEqual[eps, 8e-13]], $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[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision] + eps), $MachinePrecision]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -3.80000000000000011e-9 or 8.0000000000000002e-13 < eps

    1. Initial program 58.8%

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

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

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

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

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

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

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

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

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

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

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

    if -3.80000000000000011e-9 < eps < 8.0000000000000002e-13

    1. Initial program 31.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \varepsilon + \color{blue}{{\tan x}^{2}} \cdot \varepsilon \]
    7. Applied egg-rr99.2%

      \[\leadsto \color{blue}{\varepsilon + {\tan x}^{2} \cdot \varepsilon} \]
    8. Step-by-step derivation
      1. +-commutative99.2%

        \[\leadsto \color{blue}{{\tan x}^{2} \cdot \varepsilon + \varepsilon} \]
      2. *-commutative99.2%

        \[\leadsto \color{blue}{\varepsilon \cdot {\tan x}^{2}} + \varepsilon \]
      3. fma-def99.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -3.8 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 8 \cdot 10^{-13}\right):\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 76.3% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -0.025 \lor \neg \left(\varepsilon \leq 8 \cdot 10^{-13}\right):\\ \;\;\;\;\left(-\tan x\right) - \frac{\tan x + \tan \varepsilon}{-1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= eps -0.025) (not (<= eps 8e-13)))
   (- (- (tan x)) (/ (+ (tan x) (tan eps)) -1.0))
   (fma eps (pow (tan x) 2.0) eps)))
double code(double x, double eps) {
	double tmp;
	if ((eps <= -0.025) || !(eps <= 8e-13)) {
		tmp = -tan(x) - ((tan(x) + tan(eps)) / -1.0);
	} else {
		tmp = fma(eps, pow(tan(x), 2.0), eps);
	}
	return tmp;
}
function code(x, eps)
	tmp = 0.0
	if ((eps <= -0.025) || !(eps <= 8e-13))
		tmp = Float64(Float64(-tan(x)) - Float64(Float64(tan(x) + tan(eps)) / -1.0));
	else
		tmp = fma(eps, (tan(x) ^ 2.0), eps);
	end
	return tmp
end
code[x_, eps_] := If[Or[LessEqual[eps, -0.025], N[Not[LessEqual[eps, 8e-13]], $MachinePrecision]], N[((-N[Tan[x], $MachinePrecision]) - N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] / -1.0), $MachinePrecision]), $MachinePrecision], N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision] + eps), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.025 \lor \neg \left(\varepsilon \leq 8 \cdot 10^{-13}\right):\\
\;\;\;\;\left(-\tan x\right) - \frac{\tan x + \tan \varepsilon}{-1}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -0.025000000000000001 or 8.0000000000000002e-13 < eps

    1. Initial program 59.2%

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x + \tan \varepsilon}}} - \tan x \]
      5. associate-/r/99.6%

        \[\leadsto \color{blue}{\frac{1}{1 - \tan x \cdot \tan \varepsilon} \cdot \left(\tan x + \tan \varepsilon\right)} - \tan x \]
      6. distribute-lft-in99.5%

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

      \[\leadsto \color{blue}{\left(\frac{-1}{-1 + \tan x \cdot \tan \varepsilon} \cdot \tan x + \frac{-1}{-1 + \tan x \cdot \tan \varepsilon} \cdot \tan \varepsilon\right)} - \tan x \]
    7. Step-by-step derivation
      1. distribute-lft-in99.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-\left(\tan x + \tan \varepsilon\right)}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}} - \tan x \]
    9. Taylor expanded in x around 0 61.1%

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

    if -0.025000000000000001 < eps < 8.0000000000000002e-13

    1. Initial program 31.3%

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

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

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

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

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

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

        \[\leadsto \color{blue}{1 \cdot \varepsilon + \frac{{\sin x}^{2}}{{\cos x}^{2}} \cdot \varepsilon} \]
      2. *-un-lft-identity98.6%

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

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

        \[\leadsto \varepsilon + \frac{\sin x \cdot \sin x}{\color{blue}{\cos x \cdot \cos x}} \cdot \varepsilon \]
      5. frac-times98.5%

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

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

        \[\leadsto \varepsilon + \left(\tan x \cdot \color{blue}{\tan x}\right) \cdot \varepsilon \]
      8. pow298.6%

        \[\leadsto \varepsilon + \color{blue}{{\tan x}^{2}} \cdot \varepsilon \]
    7. Applied egg-rr98.6%

      \[\leadsto \color{blue}{\varepsilon + {\tan x}^{2} \cdot \varepsilon} \]
    8. Step-by-step derivation
      1. +-commutative98.6%

        \[\leadsto \color{blue}{{\tan x}^{2} \cdot \varepsilon + \varepsilon} \]
      2. *-commutative98.6%

        \[\leadsto \color{blue}{\varepsilon \cdot {\tan x}^{2}} + \varepsilon \]
      3. fma-def98.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)} \]
    9. Simplified98.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification79.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -0.025 \lor \neg \left(\varepsilon \leq 8 \cdot 10^{-13}\right):\\ \;\;\;\;\left(-\tan x\right) - \frac{\tan x + \tan \varepsilon}{-1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 76.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -0.025 \lor \neg \left(\varepsilon \leq 8 \cdot 10^{-13}\right):\\ \;\;\;\;\frac{\sin \varepsilon}{\cos \varepsilon}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= eps -0.025) (not (<= eps 8e-13)))
   (/ (sin eps) (cos eps))
   (fma eps (pow (tan x) 2.0) eps)))
double code(double x, double eps) {
	double tmp;
	if ((eps <= -0.025) || !(eps <= 8e-13)) {
		tmp = sin(eps) / cos(eps);
	} else {
		tmp = fma(eps, pow(tan(x), 2.0), eps);
	}
	return tmp;
}
function code(x, eps)
	tmp = 0.0
	if ((eps <= -0.025) || !(eps <= 8e-13))
		tmp = Float64(sin(eps) / cos(eps));
	else
		tmp = fma(eps, (tan(x) ^ 2.0), eps);
	end
	return tmp
end
code[x_, eps_] := If[Or[LessEqual[eps, -0.025], N[Not[LessEqual[eps, 8e-13]], $MachinePrecision]], N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision] + eps), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.025 \lor \neg \left(\varepsilon \leq 8 \cdot 10^{-13}\right):\\
\;\;\;\;\frac{\sin \varepsilon}{\cos \varepsilon}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -0.025000000000000001 or 8.0000000000000002e-13 < eps

    1. Initial program 59.2%

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

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

    if -0.025000000000000001 < eps < 8.0000000000000002e-13

    1. Initial program 31.3%

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

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

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

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

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

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

        \[\leadsto \color{blue}{1 \cdot \varepsilon + \frac{{\sin x}^{2}}{{\cos x}^{2}} \cdot \varepsilon} \]
      2. *-un-lft-identity98.6%

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

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

        \[\leadsto \varepsilon + \frac{\sin x \cdot \sin x}{\color{blue}{\cos x \cdot \cos x}} \cdot \varepsilon \]
      5. frac-times98.5%

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

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

        \[\leadsto \varepsilon + \left(\tan x \cdot \color{blue}{\tan x}\right) \cdot \varepsilon \]
      8. pow298.6%

        \[\leadsto \varepsilon + \color{blue}{{\tan x}^{2}} \cdot \varepsilon \]
    7. Applied egg-rr98.6%

      \[\leadsto \color{blue}{\varepsilon + {\tan x}^{2} \cdot \varepsilon} \]
    8. Step-by-step derivation
      1. +-commutative98.6%

        \[\leadsto \color{blue}{{\tan x}^{2} \cdot \varepsilon + \varepsilon} \]
      2. *-commutative98.6%

        \[\leadsto \color{blue}{\varepsilon \cdot {\tan x}^{2}} + \varepsilon \]
      3. fma-def98.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)} \]
    9. Simplified98.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification78.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -0.025 \lor \neg \left(\varepsilon \leq 8 \cdot 10^{-13}\right):\\ \;\;\;\;\frac{\sin \varepsilon}{\cos \varepsilon}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 76.1% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.025 \lor \neg \left(\varepsilon \leq 8 \cdot 10^{-13}\right):\\
\;\;\;\;\frac{\sin \varepsilon}{\cos \varepsilon}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -0.025000000000000001 or 8.0000000000000002e-13 < eps

    1. Initial program 59.2%

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

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

    if -0.025000000000000001 < eps < 8.0000000000000002e-13

    1. Initial program 31.3%

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

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

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

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

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

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

        \[\leadsto \color{blue}{1 \cdot \varepsilon + \frac{{\sin x}^{2}}{{\cos x}^{2}} \cdot \varepsilon} \]
      2. *-un-lft-identity98.6%

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

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

        \[\leadsto \varepsilon + \frac{\sin x \cdot \sin x}{\color{blue}{\cos x \cdot \cos x}} \cdot \varepsilon \]
      5. frac-times98.5%

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

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

        \[\leadsto \varepsilon + \left(\tan x \cdot \color{blue}{\tan x}\right) \cdot \varepsilon \]
      8. pow298.6%

        \[\leadsto \varepsilon + \color{blue}{{\tan x}^{2}} \cdot \varepsilon \]
    7. Applied egg-rr98.6%

      \[\leadsto \color{blue}{\varepsilon + {\tan x}^{2} \cdot \varepsilon} \]
    8. Step-by-step derivation
      1. *-rgt-identity98.6%

        \[\leadsto \color{blue}{\varepsilon \cdot 1} + {\tan x}^{2} \cdot \varepsilon \]
      2. *-commutative98.6%

        \[\leadsto \varepsilon \cdot 1 + \color{blue}{\varepsilon \cdot {\tan x}^{2}} \]
      3. distribute-lft-in98.5%

        \[\leadsto \color{blue}{\varepsilon \cdot \left(1 + {\tan x}^{2}\right)} \]
    9. Simplified98.5%

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

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

Alternative 12: 76.1% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.025 \lor \neg \left(\varepsilon \leq 8 \cdot 10^{-13}\right):\\
\;\;\;\;\frac{\sin \varepsilon}{\cos \varepsilon}\\

\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -0.025000000000000001 or 8.0000000000000002e-13 < eps

    1. Initial program 59.2%

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

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

    if -0.025000000000000001 < eps < 8.0000000000000002e-13

    1. Initial program 31.3%

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

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

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

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

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

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

        \[\leadsto \color{blue}{1 \cdot \varepsilon + \frac{{\sin x}^{2}}{{\cos x}^{2}} \cdot \varepsilon} \]
      2. *-un-lft-identity98.6%

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

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

        \[\leadsto \varepsilon + \frac{\sin x \cdot \sin x}{\color{blue}{\cos x \cdot \cos x}} \cdot \varepsilon \]
      5. frac-times98.5%

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

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

        \[\leadsto \varepsilon + \left(\tan x \cdot \color{blue}{\tan x}\right) \cdot \varepsilon \]
      8. pow298.6%

        \[\leadsto \varepsilon + \color{blue}{{\tan x}^{2}} \cdot \varepsilon \]
    7. Applied egg-rr98.6%

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

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

Alternative 13: 57.2% accurate, 1.0× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}} \]
  4. Final simplification61.5%

    \[\leadsto \frac{\sin \varepsilon}{\cos \varepsilon} \]
  5. Add Preprocessing

Alternative 14: 50.1% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2800 \lor \neg \left(\varepsilon \leq 8 \cdot 10^{-13}\right):\\
\;\;\;\;\tan \left(\varepsilon + x\right) - x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -2800 or 8.0000000000000002e-13 < eps

    1. Initial program 59.6%

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

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

    if -2800 < eps < 8.0000000000000002e-13

    1. Initial program 31.0%

      \[\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)} \]
    6. Taylor expanded in x around 0 53.9%

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot {x}^{2}} \]
    7. Step-by-step derivation
      1. *-commutative53.9%

        \[\leadsto \varepsilon + \color{blue}{{x}^{2} \cdot \varepsilon} \]
    8. Simplified53.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -2800 \lor \neg \left(\varepsilon \leq 8 \cdot 10^{-13}\right):\\ \;\;\;\;\tan \left(\varepsilon + x\right) - x\\ \mathbf{else}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot {x}^{2}\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 39.6% accurate, 2.0× speedup?

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

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

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

    \[\leadsto \tan \left(x + \varepsilon\right) - \color{blue}{x} \]
  4. Final simplification43.2%

    \[\leadsto \tan \left(\varepsilon + x\right) - x \]
  5. Add Preprocessing

Alternative 16: 14.9% accurate, 2.0× speedup?

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

\\
\varepsilon - \tan x
\end{array}
Derivation
  1. Initial program 45.9%

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

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]
    2. clear-num67.7%

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

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

    \[\leadsto \frac{1}{\color{blue}{\frac{\cos \varepsilon}{\sin \varepsilon}}} - \tan x \]
  6. Taylor expanded in eps around 0 14.9%

    \[\leadsto \color{blue}{\varepsilon} - \tan x \]
  7. Final simplification14.9%

    \[\leadsto \varepsilon - \tan x \]
  8. Add Preprocessing

Alternative 17: 3.6% accurate, 102.5× speedup?

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

\\
-x
\end{array}
Derivation
  1. Initial program 45.9%

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

    \[\leadsto \tan \left(x + \varepsilon\right) - \color{blue}{x} \]
  4. Taylor expanded in x around inf 3.7%

    \[\leadsto \color{blue}{-1 \cdot x} \]
  5. Step-by-step derivation
    1. neg-mul-13.7%

      \[\leadsto \color{blue}{-x} \]
  6. Simplified3.7%

    \[\leadsto \color{blue}{-x} \]
  7. Final simplification3.7%

    \[\leadsto -x \]
  8. Add Preprocessing

Developer target: 75.1% 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 2024017 
(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)))