2tan (problem 3.3.2)

Percentage Accurate: 62.1% → 99.6%
Time: 29.3s
Alternatives: 15
Speedup: 205.0×

Specification

?
\[\left(\left(-10000 \leq x \land x \leq 10000\right) \land 10^{-16} \cdot \left|x\right| < \varepsilon\right) \land \varepsilon < \left|x\right|\]
\[\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 15 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: 62.1% 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.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\tan x}^{2}\\ t_1 := t\_0 + 1\\ t_2 := {\sin x}^{2} \cdot \left(t\_1 \cdot {\cos x}^{-2}\right)\\ t_3 := \mathsf{fma}\left(-0.5, t\_1, 0.16666666666666666 \cdot t\_0\right)\\ t_4 := \tan x \cdot t\_1\\ \varepsilon + \varepsilon \cdot \left(\varepsilon \cdot \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{\left(0.16666666666666666 + t\_3\right) - t\_2}{\cos x}, -0.3333333333333333 \cdot t\_4\right), -0.16666666666666666\right) + \left(t\_2 - t\_3\right), t\_4\right) + {\left(\sin x \cdot \frac{1}{\cos x}\right)}^{2}\right) \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (pow (tan x) 2.0))
        (t_1 (+ t_0 1.0))
        (t_2 (* (pow (sin x) 2.0) (* t_1 (pow (cos x) -2.0))))
        (t_3 (fma -0.5 t_1 (* 0.16666666666666666 t_0)))
        (t_4 (* (tan x) t_1)))
   (+
    eps
    (*
     eps
     (+
      (*
       eps
       (fma
        eps
        (+
         (fma
          (- eps)
          (fma
           (sin x)
           (/ (- (+ 0.16666666666666666 t_3) t_2) (cos x))
           (* -0.3333333333333333 t_4))
          -0.16666666666666666)
         (- t_2 t_3))
        t_4))
      (pow (* (sin x) (/ 1.0 (cos x))) 2.0))))))
double code(double x, double eps) {
	double t_0 = pow(tan(x), 2.0);
	double t_1 = t_0 + 1.0;
	double t_2 = pow(sin(x), 2.0) * (t_1 * pow(cos(x), -2.0));
	double t_3 = fma(-0.5, t_1, (0.16666666666666666 * t_0));
	double t_4 = tan(x) * t_1;
	return eps + (eps * ((eps * fma(eps, (fma(-eps, fma(sin(x), (((0.16666666666666666 + t_3) - t_2) / cos(x)), (-0.3333333333333333 * t_4)), -0.16666666666666666) + (t_2 - t_3)), t_4)) + pow((sin(x) * (1.0 / cos(x))), 2.0)));
}
function code(x, eps)
	t_0 = tan(x) ^ 2.0
	t_1 = Float64(t_0 + 1.0)
	t_2 = Float64((sin(x) ^ 2.0) * Float64(t_1 * (cos(x) ^ -2.0)))
	t_3 = fma(-0.5, t_1, Float64(0.16666666666666666 * t_0))
	t_4 = Float64(tan(x) * t_1)
	return Float64(eps + Float64(eps * Float64(Float64(eps * fma(eps, Float64(fma(Float64(-eps), fma(sin(x), Float64(Float64(Float64(0.16666666666666666 + t_3) - t_2) / cos(x)), Float64(-0.3333333333333333 * t_4)), -0.16666666666666666) + Float64(t_2 - t_3)), t_4)) + (Float64(sin(x) * Float64(1.0 / cos(x))) ^ 2.0))))
end
code[x_, eps_] := Block[{t$95$0 = N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 + 1.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] * N[(t$95$1 * N[Power[N[Cos[x], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(-0.5 * t$95$1 + N[(0.16666666666666666 * t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[Tan[x], $MachinePrecision] * t$95$1), $MachinePrecision]}, N[(eps + N[(eps * N[(N[(eps * N[(eps * N[(N[((-eps) * N[(N[Sin[x], $MachinePrecision] * N[(N[(N[(0.16666666666666666 + t$95$3), $MachinePrecision] - t$95$2), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(-0.3333333333333333 * t$95$4), $MachinePrecision]), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] + N[(t$95$2 - t$95$3), $MachinePrecision]), $MachinePrecision] + t$95$4), $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[Sin[x], $MachinePrecision] * N[(1.0 / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\tan x}^{2}\\
t_1 := t\_0 + 1\\
t_2 := {\sin x}^{2} \cdot \left(t\_1 \cdot {\cos x}^{-2}\right)\\
t_3 := \mathsf{fma}\left(-0.5, t\_1, 0.16666666666666666 \cdot t\_0\right)\\
t_4 := \tan x \cdot t\_1\\
\varepsilon + \varepsilon \cdot \left(\varepsilon \cdot \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{\left(0.16666666666666666 + t\_3\right) - t\_2}{\cos x}, -0.3333333333333333 \cdot t\_4\right), -0.16666666666666666\right) + \left(t\_2 - t\_3\right), t\_4\right) + {\left(\sin x \cdot \frac{1}{\cos x}\right)}^{2}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 61.7%

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

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

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

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

    \[\leadsto \varepsilon + \color{blue}{\left(\varepsilon \cdot \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{\left(0.16666666666666666 + \mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right)\right) - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)}{\cos x}, -0.3333333333333333 \cdot \left(\tan x \cdot \left(1 + {\tan x}^{2}\right)\right)\right), -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right) - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)\right), \tan x \cdot \left(1 + {\tan x}^{2}\right)\right) + {\tan x}^{2}\right)} \cdot \varepsilon \]
  7. Step-by-step derivation
    1. tan-quot99.4%

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

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

    \[\leadsto \varepsilon + \left(\varepsilon \cdot \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{\left(0.16666666666666666 + \mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right)\right) - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)}{\cos x}, -0.3333333333333333 \cdot \left(\tan x \cdot \left(1 + {\tan x}^{2}\right)\right)\right), -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right) - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)\right), \tan x \cdot \left(1 + {\tan x}^{2}\right)\right) + {\color{blue}{\left(\sin x \cdot \frac{1}{\cos x}\right)}}^{2}\right) \cdot \varepsilon \]
  9. Final simplification99.4%

    \[\leadsto \varepsilon + \varepsilon \cdot \left(\varepsilon \cdot \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{\left(0.16666666666666666 + \mathsf{fma}\left(-0.5, {\tan x}^{2} + 1, 0.16666666666666666 \cdot {\tan x}^{2}\right)\right) - {\sin x}^{2} \cdot \left(\left({\tan x}^{2} + 1\right) \cdot {\cos x}^{-2}\right)}{\cos x}, -0.3333333333333333 \cdot \left(\tan x \cdot \left({\tan x}^{2} + 1\right)\right)\right), -0.16666666666666666\right) + \left({\sin x}^{2} \cdot \left(\left({\tan x}^{2} + 1\right) \cdot {\cos x}^{-2}\right) - \mathsf{fma}\left(-0.5, {\tan x}^{2} + 1, 0.16666666666666666 \cdot {\tan x}^{2}\right)\right), \tan x \cdot \left({\tan x}^{2} + 1\right)\right) + {\left(\sin x \cdot \frac{1}{\cos x}\right)}^{2}\right) \]
  10. Add Preprocessing

Alternative 2: 99.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\tan x}^{2}\\ t_1 := t\_0 + 1\\ t_2 := \mathsf{fma}\left(-0.5, t\_1, 0.16666666666666666 \cdot t\_0\right)\\ t_3 := \tan x + {\tan x}^{3}\\ t_4 := {\sin x}^{2} \cdot \left(t\_1 \cdot {\cos x}^{-2}\right)\\ \varepsilon + \varepsilon \cdot \left(t\_0 + \varepsilon \cdot \left(t\_3 + \varepsilon \cdot \left(\mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{\left(0.16666666666666666 + t\_2\right) - t\_4}{\cos x}, -0.3333333333333333 \cdot t\_3\right), -0.16666666666666666\right) + \left(t\_4 - t\_2\right)\right)\right)\right) \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (pow (tan x) 2.0))
        (t_1 (+ t_0 1.0))
        (t_2 (fma -0.5 t_1 (* 0.16666666666666666 t_0)))
        (t_3 (+ (tan x) (pow (tan x) 3.0)))
        (t_4 (* (pow (sin x) 2.0) (* t_1 (pow (cos x) -2.0)))))
   (+
    eps
    (*
     eps
     (+
      t_0
      (*
       eps
       (+
        t_3
        (*
         eps
         (+
          (fma
           (- eps)
           (fma
            (sin x)
            (/ (- (+ 0.16666666666666666 t_2) t_4) (cos x))
            (* -0.3333333333333333 t_3))
           -0.16666666666666666)
          (- t_4 t_2))))))))))
double code(double x, double eps) {
	double t_0 = pow(tan(x), 2.0);
	double t_1 = t_0 + 1.0;
	double t_2 = fma(-0.5, t_1, (0.16666666666666666 * t_0));
	double t_3 = tan(x) + pow(tan(x), 3.0);
	double t_4 = pow(sin(x), 2.0) * (t_1 * pow(cos(x), -2.0));
	return eps + (eps * (t_0 + (eps * (t_3 + (eps * (fma(-eps, fma(sin(x), (((0.16666666666666666 + t_2) - t_4) / cos(x)), (-0.3333333333333333 * t_3)), -0.16666666666666666) + (t_4 - t_2)))))));
}
function code(x, eps)
	t_0 = tan(x) ^ 2.0
	t_1 = Float64(t_0 + 1.0)
	t_2 = fma(-0.5, t_1, Float64(0.16666666666666666 * t_0))
	t_3 = Float64(tan(x) + (tan(x) ^ 3.0))
	t_4 = Float64((sin(x) ^ 2.0) * Float64(t_1 * (cos(x) ^ -2.0)))
	return Float64(eps + Float64(eps * Float64(t_0 + Float64(eps * Float64(t_3 + Float64(eps * Float64(fma(Float64(-eps), fma(sin(x), Float64(Float64(Float64(0.16666666666666666 + t_2) - t_4) / cos(x)), Float64(-0.3333333333333333 * t_3)), -0.16666666666666666) + Float64(t_4 - t_2))))))))
end
code[x_, eps_] := Block[{t$95$0 = N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 + 1.0), $MachinePrecision]}, Block[{t$95$2 = N[(-0.5 * t$95$1 + N[(0.16666666666666666 * t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Tan[x], $MachinePrecision] + N[Power[N[Tan[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] * N[(t$95$1 * N[Power[N[Cos[x], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(eps + N[(eps * N[(t$95$0 + N[(eps * N[(t$95$3 + N[(eps * N[(N[((-eps) * N[(N[Sin[x], $MachinePrecision] * N[(N[(N[(0.16666666666666666 + t$95$2), $MachinePrecision] - t$95$4), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(-0.3333333333333333 * t$95$3), $MachinePrecision]), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] + N[(t$95$4 - t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\tan x}^{2}\\
t_1 := t\_0 + 1\\
t_2 := \mathsf{fma}\left(-0.5, t\_1, 0.16666666666666666 \cdot t\_0\right)\\
t_3 := \tan x + {\tan x}^{3}\\
t_4 := {\sin x}^{2} \cdot \left(t\_1 \cdot {\cos x}^{-2}\right)\\
\varepsilon + \varepsilon \cdot \left(t\_0 + \varepsilon \cdot \left(t\_3 + \varepsilon \cdot \left(\mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{\left(0.16666666666666666 + t\_2\right) - t\_4}{\cos x}, -0.3333333333333333 \cdot t\_3\right), -0.16666666666666666\right) + \left(t\_4 - t\_2\right)\right)\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 61.7%

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

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

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

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

    \[\leadsto \varepsilon + \color{blue}{\left(\varepsilon \cdot \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{\left(0.16666666666666666 + \mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right)\right) - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)}{\cos x}, -0.3333333333333333 \cdot \left(\tan x \cdot \left(1 + {\tan x}^{2}\right)\right)\right), -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right) - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)\right), \tan x \cdot \left(1 + {\tan x}^{2}\right)\right) + {\tan x}^{2}\right)} \cdot \varepsilon \]
  7. Step-by-step derivation
    1. fma-undefine99.4%

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

    \[\leadsto \varepsilon + \left(\varepsilon \cdot \color{blue}{\left(\varepsilon \cdot \left(\mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{\left(0.16666666666666666 + \mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right)\right) - {\sin x}^{2} \cdot \left(\left(1 + {\tan x}^{2}\right) \cdot {\cos x}^{-2}\right)}{\cos x}, -0.3333333333333333 \cdot \left(\tan x + {\tan x}^{3}\right)\right), -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right) - {\sin x}^{2} \cdot \left(\left(1 + {\tan x}^{2}\right) \cdot {\cos x}^{-2}\right)\right)\right) + \left(\tan x + {\tan x}^{3}\right)\right)} + {\tan x}^{2}\right) \cdot \varepsilon \]
  9. Final simplification99.4%

    \[\leadsto \varepsilon + \varepsilon \cdot \left({\tan x}^{2} + \varepsilon \cdot \left(\left(\tan x + {\tan x}^{3}\right) + \varepsilon \cdot \left(\mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{\left(0.16666666666666666 + \mathsf{fma}\left(-0.5, {\tan x}^{2} + 1, 0.16666666666666666 \cdot {\tan x}^{2}\right)\right) - {\sin x}^{2} \cdot \left(\left({\tan x}^{2} + 1\right) \cdot {\cos x}^{-2}\right)}{\cos x}, -0.3333333333333333 \cdot \left(\tan x + {\tan x}^{3}\right)\right), -0.16666666666666666\right) + \left({\sin x}^{2} \cdot \left(\left({\tan x}^{2} + 1\right) \cdot {\cos x}^{-2}\right) - \mathsf{fma}\left(-0.5, {\tan x}^{2} + 1, 0.16666666666666666 \cdot {\tan x}^{2}\right)\right)\right)\right)\right) \]
  10. Add Preprocessing

Alternative 3: 99.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\sin x}^{2}\\ t_1 := {\tan x}^{2}\\ t_2 := {\cos x}^{-2}\\ t_3 := t\_1 + 1\\ t_4 := \tan x \cdot t\_3\\ \varepsilon + \varepsilon \cdot \left(t\_1 + \varepsilon \cdot \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{-0.3333333333333333 + t\_0 \cdot \left(t\_2 \cdot \left(-1 - t\_1\right)\right)}{\cos x}, -0.3333333333333333 \cdot t\_4\right), -0.16666666666666666\right) + \left(t\_0 \cdot \left(t\_3 \cdot t\_2\right) - \mathsf{fma}\left(-0.5, t\_3, 0.16666666666666666 \cdot t\_1\right)\right), t\_4\right)\right) \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (pow (sin x) 2.0))
        (t_1 (pow (tan x) 2.0))
        (t_2 (pow (cos x) -2.0))
        (t_3 (+ t_1 1.0))
        (t_4 (* (tan x) t_3)))
   (+
    eps
    (*
     eps
     (+
      t_1
      (*
       eps
       (fma
        eps
        (+
         (fma
          (- eps)
          (fma
           (sin x)
           (/ (+ -0.3333333333333333 (* t_0 (* t_2 (- -1.0 t_1)))) (cos x))
           (* -0.3333333333333333 t_4))
          -0.16666666666666666)
         (- (* t_0 (* t_3 t_2)) (fma -0.5 t_3 (* 0.16666666666666666 t_1))))
        t_4)))))))
double code(double x, double eps) {
	double t_0 = pow(sin(x), 2.0);
	double t_1 = pow(tan(x), 2.0);
	double t_2 = pow(cos(x), -2.0);
	double t_3 = t_1 + 1.0;
	double t_4 = tan(x) * t_3;
	return eps + (eps * (t_1 + (eps * fma(eps, (fma(-eps, fma(sin(x), ((-0.3333333333333333 + (t_0 * (t_2 * (-1.0 - t_1)))) / cos(x)), (-0.3333333333333333 * t_4)), -0.16666666666666666) + ((t_0 * (t_3 * t_2)) - fma(-0.5, t_3, (0.16666666666666666 * t_1)))), t_4))));
}
function code(x, eps)
	t_0 = sin(x) ^ 2.0
	t_1 = tan(x) ^ 2.0
	t_2 = cos(x) ^ -2.0
	t_3 = Float64(t_1 + 1.0)
	t_4 = Float64(tan(x) * t_3)
	return Float64(eps + Float64(eps * Float64(t_1 + Float64(eps * fma(eps, Float64(fma(Float64(-eps), fma(sin(x), Float64(Float64(-0.3333333333333333 + Float64(t_0 * Float64(t_2 * Float64(-1.0 - t_1)))) / cos(x)), Float64(-0.3333333333333333 * t_4)), -0.16666666666666666) + Float64(Float64(t_0 * Float64(t_3 * t_2)) - fma(-0.5, t_3, Float64(0.16666666666666666 * t_1)))), t_4)))))
end
code[x_, eps_] := Block[{t$95$0 = N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Cos[x], $MachinePrecision], -2.0], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$1 + 1.0), $MachinePrecision]}, Block[{t$95$4 = N[(N[Tan[x], $MachinePrecision] * t$95$3), $MachinePrecision]}, N[(eps + N[(eps * N[(t$95$1 + N[(eps * N[(eps * N[(N[((-eps) * N[(N[Sin[x], $MachinePrecision] * N[(N[(-0.3333333333333333 + N[(t$95$0 * N[(t$95$2 * N[(-1.0 - t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(-0.3333333333333333 * t$95$4), $MachinePrecision]), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] + N[(N[(t$95$0 * N[(t$95$3 * t$95$2), $MachinePrecision]), $MachinePrecision] - N[(-0.5 * t$95$3 + N[(0.16666666666666666 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\sin x}^{2}\\
t_1 := {\tan x}^{2}\\
t_2 := {\cos x}^{-2}\\
t_3 := t\_1 + 1\\
t_4 := \tan x \cdot t\_3\\
\varepsilon + \varepsilon \cdot \left(t\_1 + \varepsilon \cdot \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{-0.3333333333333333 + t\_0 \cdot \left(t\_2 \cdot \left(-1 - t\_1\right)\right)}{\cos x}, -0.3333333333333333 \cdot t\_4\right), -0.16666666666666666\right) + \left(t\_0 \cdot \left(t\_3 \cdot t\_2\right) - \mathsf{fma}\left(-0.5, t\_3, 0.16666666666666666 \cdot t\_1\right)\right), t\_4\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 61.7%

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

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

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

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

    \[\leadsto \varepsilon + \color{blue}{\left(\varepsilon \cdot \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{\left(0.16666666666666666 + \mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right)\right) - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)}{\cos x}, -0.3333333333333333 \cdot \left(\tan x \cdot \left(1 + {\tan x}^{2}\right)\right)\right), -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right) - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)\right), \tan x \cdot \left(1 + {\tan x}^{2}\right)\right) + {\tan x}^{2}\right)} \cdot \varepsilon \]
  7. Taylor expanded in x around 0 99.3%

    \[\leadsto \varepsilon + \left(\varepsilon \cdot \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{\color{blue}{-0.3333333333333333} - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)}{\cos x}, -0.3333333333333333 \cdot \left(\tan x \cdot \left(1 + {\tan x}^{2}\right)\right)\right), -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right) - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)\right), \tan x \cdot \left(1 + {\tan x}^{2}\right)\right) + {\tan x}^{2}\right) \cdot \varepsilon \]
  8. Final simplification99.3%

    \[\leadsto \varepsilon + \varepsilon \cdot \left({\tan x}^{2} + \varepsilon \cdot \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{-0.3333333333333333 + {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(-1 - {\tan x}^{2}\right)\right)}{\cos x}, -0.3333333333333333 \cdot \left(\tan x \cdot \left({\tan x}^{2} + 1\right)\right)\right), -0.16666666666666666\right) + \left({\sin x}^{2} \cdot \left(\left({\tan x}^{2} + 1\right) \cdot {\cos x}^{-2}\right) - \mathsf{fma}\left(-0.5, {\tan x}^{2} + 1, 0.16666666666666666 \cdot {\tan x}^{2}\right)\right), \tan x \cdot \left({\tan x}^{2} + 1\right)\right)\right) \]
  9. Add Preprocessing

Alternative 4: 99.5% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\tan x}^{2}\\ t_1 := t\_0 + 1\\ t_2 := \tan x \cdot t\_1\\ \varepsilon \cdot \left(\left(t\_0 + \varepsilon \cdot \mathsf{fma}\left(\varepsilon, {\sin x}^{2} \cdot \left(t\_1 \cdot {\cos x}^{-2}\right) + \left(\mathsf{fma}\left(-\varepsilon, -0.3333333333333333 \cdot \left(x + t\_2\right), -0.16666666666666666\right) - \mathsf{fma}\left(-0.5, t\_1, 0.16666666666666666 \cdot t\_0\right)\right), t\_2\right)\right) + 1\right) \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (pow (tan x) 2.0)) (t_1 (+ t_0 1.0)) (t_2 (* (tan x) t_1)))
   (*
    eps
    (+
     (+
      t_0
      (*
       eps
       (fma
        eps
        (+
         (* (pow (sin x) 2.0) (* t_1 (pow (cos x) -2.0)))
         (-
          (fma (- eps) (* -0.3333333333333333 (+ x t_2)) -0.16666666666666666)
          (fma -0.5 t_1 (* 0.16666666666666666 t_0))))
        t_2)))
     1.0))))
double code(double x, double eps) {
	double t_0 = pow(tan(x), 2.0);
	double t_1 = t_0 + 1.0;
	double t_2 = tan(x) * t_1;
	return eps * ((t_0 + (eps * fma(eps, ((pow(sin(x), 2.0) * (t_1 * pow(cos(x), -2.0))) + (fma(-eps, (-0.3333333333333333 * (x + t_2)), -0.16666666666666666) - fma(-0.5, t_1, (0.16666666666666666 * t_0)))), t_2))) + 1.0);
}
function code(x, eps)
	t_0 = tan(x) ^ 2.0
	t_1 = Float64(t_0 + 1.0)
	t_2 = Float64(tan(x) * t_1)
	return Float64(eps * Float64(Float64(t_0 + Float64(eps * fma(eps, Float64(Float64((sin(x) ^ 2.0) * Float64(t_1 * (cos(x) ^ -2.0))) + Float64(fma(Float64(-eps), Float64(-0.3333333333333333 * Float64(x + t_2)), -0.16666666666666666) - fma(-0.5, t_1, Float64(0.16666666666666666 * t_0)))), t_2))) + 1.0))
end
code[x_, eps_] := Block[{t$95$0 = N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 + 1.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Tan[x], $MachinePrecision] * t$95$1), $MachinePrecision]}, N[(eps * N[(N[(t$95$0 + N[(eps * N[(eps * N[(N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] * N[(t$95$1 * N[Power[N[Cos[x], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[((-eps) * N[(-0.3333333333333333 * N[(x + t$95$2), $MachinePrecision]), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] - N[(-0.5 * t$95$1 + N[(0.16666666666666666 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\tan x}^{2}\\
t_1 := t\_0 + 1\\
t_2 := \tan x \cdot t\_1\\
\varepsilon \cdot \left(\left(t\_0 + \varepsilon \cdot \mathsf{fma}\left(\varepsilon, {\sin x}^{2} \cdot \left(t\_1 \cdot {\cos x}^{-2}\right) + \left(\mathsf{fma}\left(-\varepsilon, -0.3333333333333333 \cdot \left(x + t\_2\right), -0.16666666666666666\right) - \mathsf{fma}\left(-0.5, t\_1, 0.16666666666666666 \cdot t\_0\right)\right), t\_2\right)\right) + 1\right)
\end{array}
\end{array}
Derivation
  1. Initial program 61.7%

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

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

    \[\leadsto \color{blue}{\varepsilon \cdot \left(1 + \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \sin x \cdot \frac{0.16666666666666666 + \left(\mathsf{fma}\left(-0.5, 1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}, \frac{0.16666666666666666 \cdot {\sin x}^{2}}{{\cos x}^{2}}\right) - {\sin x}^{2} \cdot \frac{1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}}{{\cos x}^{2}}\right)}{\cos x} + \left(\left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) \cdot \frac{\sin x}{\cos x}\right) \cdot -0.3333333333333333, -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, 1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}, \frac{0.16666666666666666 \cdot {\sin x}^{2}}{{\cos x}^{2}}\right) - {\sin x}^{2} \cdot \frac{1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}}{{\cos x}^{2}}\right), \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) \cdot \frac{\sin x}{\cos x}\right), \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)} \]
  5. Taylor expanded in x around 0 99.2%

    \[\leadsto \varepsilon \cdot \left(1 + \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \color{blue}{-0.3333333333333333 \cdot x} + \left(\left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) \cdot \frac{\sin x}{\cos x}\right) \cdot -0.3333333333333333, -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, 1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}, \frac{0.16666666666666666 \cdot {\sin x}^{2}}{{\cos x}^{2}}\right) - {\sin x}^{2} \cdot \frac{1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}}{{\cos x}^{2}}\right), \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) \cdot \frac{\sin x}{\cos x}\right), \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right) \]
  6. Step-by-step derivation
    1. *-commutative99.2%

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

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

    \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{\left(\varepsilon \cdot \mathsf{fma}\left(\varepsilon, \left(\mathsf{fma}\left(-\varepsilon, -0.3333333333333333 \cdot \left(x + \tan x \cdot \left(1 + {\tan x}^{2}\right)\right), -0.16666666666666666\right) - \mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right)\right) + {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right), \tan x \cdot \left(1 + {\tan x}^{2}\right)\right) + {\tan x}^{2}\right)}\right) \]
  9. Final simplification99.2%

    \[\leadsto \varepsilon \cdot \left(\left({\tan x}^{2} + \varepsilon \cdot \mathsf{fma}\left(\varepsilon, {\sin x}^{2} \cdot \left(\left({\tan x}^{2} + 1\right) \cdot {\cos x}^{-2}\right) + \left(\mathsf{fma}\left(-\varepsilon, -0.3333333333333333 \cdot \left(x + \tan x \cdot \left({\tan x}^{2} + 1\right)\right), -0.16666666666666666\right) - \mathsf{fma}\left(-0.5, {\tan x}^{2} + 1, 0.16666666666666666 \cdot {\tan x}^{2}\right)\right), \tan x \cdot \left({\tan x}^{2} + 1\right)\right)\right) + 1\right) \]
  10. Add Preprocessing

Alternative 5: 99.0% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\sin \varepsilon}{\cos \varepsilon}\\ t_1 := \frac{\sin x}{\cos x}\\ t_2 := 1 - t\_0 \cdot t\_1\\ \frac{t\_0}{t\_2} + \left(\frac{t\_1}{t\_2} - t\_1\right) \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (/ (sin eps) (cos eps)))
        (t_1 (/ (sin x) (cos x)))
        (t_2 (- 1.0 (* t_0 t_1))))
   (+ (/ t_0 t_2) (- (/ t_1 t_2) t_1))))
double code(double x, double eps) {
	double t_0 = sin(eps) / cos(eps);
	double t_1 = sin(x) / cos(x);
	double t_2 = 1.0 - (t_0 * t_1);
	return (t_0 / t_2) + ((t_1 / t_2) - t_1);
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    t_0 = sin(eps) / cos(eps)
    t_1 = sin(x) / cos(x)
    t_2 = 1.0d0 - (t_0 * t_1)
    code = (t_0 / t_2) + ((t_1 / t_2) - t_1)
end function
public static double code(double x, double eps) {
	double t_0 = Math.sin(eps) / Math.cos(eps);
	double t_1 = Math.sin(x) / Math.cos(x);
	double t_2 = 1.0 - (t_0 * t_1);
	return (t_0 / t_2) + ((t_1 / t_2) - t_1);
}
def code(x, eps):
	t_0 = math.sin(eps) / math.cos(eps)
	t_1 = math.sin(x) / math.cos(x)
	t_2 = 1.0 - (t_0 * t_1)
	return (t_0 / t_2) + ((t_1 / t_2) - t_1)
function code(x, eps)
	t_0 = Float64(sin(eps) / cos(eps))
	t_1 = Float64(sin(x) / cos(x))
	t_2 = Float64(1.0 - Float64(t_0 * t_1))
	return Float64(Float64(t_0 / t_2) + Float64(Float64(t_1 / t_2) - t_1))
end
function tmp = code(x, eps)
	t_0 = sin(eps) / cos(eps);
	t_1 = sin(x) / cos(x);
	t_2 = 1.0 - (t_0 * t_1);
	tmp = (t_0 / t_2) + ((t_1 / t_2) - t_1);
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 - N[(t$95$0 * t$95$1), $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$0 / t$95$2), $MachinePrecision] + N[(N[(t$95$1 / t$95$2), $MachinePrecision] - t$95$1), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\sin \varepsilon}{\cos \varepsilon}\\
t_1 := \frac{\sin x}{\cos x}\\
t_2 := 1 - t\_0 \cdot t\_1\\
\frac{t\_0}{t\_2} + \left(\frac{t\_1}{t\_2} - t\_1\right)
\end{array}
\end{array}
Derivation
  1. Initial program 61.7%

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x \]
  6. Simplified62.0%

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

    \[\leadsto \color{blue}{\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}} \]
  8. Step-by-step derivation
    1. associate--l+98.9%

      \[\leadsto \color{blue}{\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)} \]
    2. associate-/r*98.9%

      \[\leadsto \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) \]
    3. times-frac98.9%

      \[\leadsto \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) \]
  9. Simplified98.9%

    \[\leadsto \color{blue}{\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)} \]
  10. Add Preprocessing

Alternative 6: 99.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\tan x}^{2}\\ \varepsilon + \varepsilon \cdot \left(t\_0 + \varepsilon \cdot \mathsf{fma}\left(\varepsilon, 0.3333333333333333, \tan x \cdot \left(t\_0 + 1\right)\right)\right) \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (pow (tan x) 2.0)))
   (+
    eps
    (*
     eps
     (+ t_0 (* eps (fma eps 0.3333333333333333 (* (tan x) (+ t_0 1.0)))))))))
double code(double x, double eps) {
	double t_0 = pow(tan(x), 2.0);
	return eps + (eps * (t_0 + (eps * fma(eps, 0.3333333333333333, (tan(x) * (t_0 + 1.0))))));
}
function code(x, eps)
	t_0 = tan(x) ^ 2.0
	return Float64(eps + Float64(eps * Float64(t_0 + Float64(eps * fma(eps, 0.3333333333333333, Float64(tan(x) * Float64(t_0 + 1.0)))))))
end
code[x_, eps_] := Block[{t$95$0 = N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]}, N[(eps + N[(eps * N[(t$95$0 + N[(eps * N[(eps * 0.3333333333333333 + N[(N[Tan[x], $MachinePrecision] * N[(t$95$0 + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\tan x}^{2}\\
\varepsilon + \varepsilon \cdot \left(t\_0 + \varepsilon \cdot \mathsf{fma}\left(\varepsilon, 0.3333333333333333, \tan x \cdot \left(t\_0 + 1\right)\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 61.7%

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

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

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

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

    \[\leadsto \varepsilon + \color{blue}{\left(\varepsilon \cdot \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{\left(0.16666666666666666 + \mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right)\right) - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)}{\cos x}, -0.3333333333333333 \cdot \left(\tan x \cdot \left(1 + {\tan x}^{2}\right)\right)\right), -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right) - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)\right), \tan x \cdot \left(1 + {\tan x}^{2}\right)\right) + {\tan x}^{2}\right)} \cdot \varepsilon \]
  7. Taylor expanded in x around 0 98.9%

    \[\leadsto \varepsilon + \left(\varepsilon \cdot \mathsf{fma}\left(\varepsilon, \color{blue}{0.3333333333333333}, \tan x \cdot \left(1 + {\tan x}^{2}\right)\right) + {\tan x}^{2}\right) \cdot \varepsilon \]
  8. Final simplification98.9%

    \[\leadsto \varepsilon + \varepsilon \cdot \left({\tan x}^{2} + \varepsilon \cdot \mathsf{fma}\left(\varepsilon, 0.3333333333333333, \tan x \cdot \left({\tan x}^{2} + 1\right)\right)\right) \]
  9. Add Preprocessing

Alternative 7: 99.1% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \varepsilon + \varepsilon \cdot \left({\tan x}^{2} + \varepsilon \cdot \left(\varepsilon \cdot 0.3333333333333333 + x \cdot \left(0.6666666666666666 \cdot {\varepsilon}^{2} + 1\right)\right)\right) \end{array} \]
(FPCore (x eps)
 :precision binary64
 (+
  eps
  (*
   eps
   (+
    (pow (tan x) 2.0)
    (*
     eps
     (+
      (* eps 0.3333333333333333)
      (* x (+ (* 0.6666666666666666 (pow eps 2.0)) 1.0))))))))
double code(double x, double eps) {
	return eps + (eps * (pow(tan(x), 2.0) + (eps * ((eps * 0.3333333333333333) + (x * ((0.6666666666666666 * pow(eps, 2.0)) + 1.0))))));
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = eps + (eps * ((tan(x) ** 2.0d0) + (eps * ((eps * 0.3333333333333333d0) + (x * ((0.6666666666666666d0 * (eps ** 2.0d0)) + 1.0d0))))))
end function
public static double code(double x, double eps) {
	return eps + (eps * (Math.pow(Math.tan(x), 2.0) + (eps * ((eps * 0.3333333333333333) + (x * ((0.6666666666666666 * Math.pow(eps, 2.0)) + 1.0))))));
}
def code(x, eps):
	return eps + (eps * (math.pow(math.tan(x), 2.0) + (eps * ((eps * 0.3333333333333333) + (x * ((0.6666666666666666 * math.pow(eps, 2.0)) + 1.0))))))
function code(x, eps)
	return Float64(eps + Float64(eps * Float64((tan(x) ^ 2.0) + Float64(eps * Float64(Float64(eps * 0.3333333333333333) + Float64(x * Float64(Float64(0.6666666666666666 * (eps ^ 2.0)) + 1.0)))))))
end
function tmp = code(x, eps)
	tmp = eps + (eps * ((tan(x) ^ 2.0) + (eps * ((eps * 0.3333333333333333) + (x * ((0.6666666666666666 * (eps ^ 2.0)) + 1.0))))));
end
code[x_, eps_] := N[(eps + N[(eps * N[(N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision] + N[(eps * N[(N[(eps * 0.3333333333333333), $MachinePrecision] + N[(x * N[(N[(0.6666666666666666 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\varepsilon + \varepsilon \cdot \left({\tan x}^{2} + \varepsilon \cdot \left(\varepsilon \cdot 0.3333333333333333 + x \cdot \left(0.6666666666666666 \cdot {\varepsilon}^{2} + 1\right)\right)\right)
\end{array}
Derivation
  1. Initial program 61.7%

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

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

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

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

    \[\leadsto \varepsilon + \color{blue}{\left(\varepsilon \cdot \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{\left(0.16666666666666666 + \mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right)\right) - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)}{\cos x}, -0.3333333333333333 \cdot \left(\tan x \cdot \left(1 + {\tan x}^{2}\right)\right)\right), -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right) - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)\right), \tan x \cdot \left(1 + {\tan x}^{2}\right)\right) + {\tan x}^{2}\right)} \cdot \varepsilon \]
  7. Taylor expanded in x around 0 98.2%

    \[\leadsto \varepsilon + \left(\varepsilon \cdot \color{blue}{\left(0.3333333333333333 \cdot \varepsilon + x \cdot \left(1 + 0.6666666666666666 \cdot {\varepsilon}^{2}\right)\right)} + {\tan x}^{2}\right) \cdot \varepsilon \]
  8. Final simplification98.2%

    \[\leadsto \varepsilon + \varepsilon \cdot \left({\tan x}^{2} + \varepsilon \cdot \left(\varepsilon \cdot 0.3333333333333333 + x \cdot \left(0.6666666666666666 \cdot {\varepsilon}^{2} + 1\right)\right)\right) \]
  9. Add Preprocessing

Alternative 8: 99.1% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq 6 \cdot 10^{-13}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \left(x \cdot \left(\varepsilon + x \cdot \left(x \cdot \left(x \cdot 0.6666666666666666 + \varepsilon \cdot 1.3333333333333333\right) + 1\right)\right)\right)\\

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


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

    1. Initial program 61.4%

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

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

      \[\leadsto \color{blue}{\varepsilon \cdot \left(1 + \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \sin x \cdot \frac{0.16666666666666666 + \left(\mathsf{fma}\left(-0.5, 1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}, \frac{0.16666666666666666 \cdot {\sin x}^{2}}{{\cos x}^{2}}\right) - {\sin x}^{2} \cdot \frac{1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}}{{\cos x}^{2}}\right)}{\cos x} + \left(\left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) \cdot \frac{\sin x}{\cos x}\right) \cdot -0.3333333333333333, -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, 1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}, \frac{0.16666666666666666 \cdot {\sin x}^{2}}{{\cos x}^{2}}\right) - {\sin x}^{2} \cdot \frac{1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}}{{\cos x}^{2}}\right), \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) \cdot \frac{\sin x}{\cos x}\right), \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)} \]
    5. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\varepsilon + \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{0.16666666666666666 + \left(\mathsf{fma}\left(-0.5, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right), \left(0.16666666666666666 \cdot {\sin x}^{2}\right) \cdot {\cos x}^{-2}\right) - {\sin x}^{2} \cdot \left(\mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot {\cos x}^{-2}\right)\right)}{\cos x}, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot \left(\tan x \cdot -0.3333333333333333\right)\right), -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right), \left(0.16666666666666666 \cdot {\sin x}^{2}\right) \cdot {\cos x}^{-2}\right) - {\sin x}^{2} \cdot \left(\mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot {\cos x}^{-2}\right)\right), \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot \tan x\right), {\sin x}^{2} \cdot {\cos x}^{-2}\right) \cdot \varepsilon} \]
    6. Taylor expanded in eps around 0 100.0%

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

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

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

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

      \[\leadsto \varepsilon + \color{blue}{\left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(\left(0.6666666666666666 \cdot x + 0.8333333333333334 \cdot \varepsilon\right) - -0.5 \cdot \varepsilon\right)\right)\right)\right)} \cdot \varepsilon \]
    10. Step-by-step derivation
      1. associate--l+100.0%

        \[\leadsto \varepsilon + \left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \color{blue}{\left(0.6666666666666666 \cdot x + \left(0.8333333333333334 \cdot \varepsilon - -0.5 \cdot \varepsilon\right)\right)}\right)\right)\right) \cdot \varepsilon \]
      2. *-commutative100.0%

        \[\leadsto \varepsilon + \left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(\color{blue}{x \cdot 0.6666666666666666} + \left(0.8333333333333334 \cdot \varepsilon - -0.5 \cdot \varepsilon\right)\right)\right)\right)\right) \cdot \varepsilon \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \varepsilon + \left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(x \cdot 0.6666666666666666 + \color{blue}{\varepsilon \cdot \left(0.8333333333333334 - -0.5\right)}\right)\right)\right)\right) \cdot \varepsilon \]
      4. metadata-eval100.0%

        \[\leadsto \varepsilon + \left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(x \cdot 0.6666666666666666 + \varepsilon \cdot \color{blue}{1.3333333333333333}\right)\right)\right)\right) \cdot \varepsilon \]
    11. Simplified100.0%

      \[\leadsto \varepsilon + \color{blue}{\left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(x \cdot 0.6666666666666666 + \varepsilon \cdot 1.3333333333333333\right)\right)\right)\right)} \cdot \varepsilon \]

    if 5.99999999999999968e-13 < eps

    1. Initial program 70.6%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{\tan \left(x + \varepsilon\right) + \tan x}{{\tan \left(x + \varepsilon\right)}^{2} - {\tan x}^{2}}}} \]
    5. Step-by-step derivation
      1. *-un-lft-identity71.6%

        \[\leadsto \frac{1}{\color{blue}{1 \cdot \frac{\tan \left(x + \varepsilon\right) + \tan x}{{\tan \left(x + \varepsilon\right)}^{2} - {\tan x}^{2}}}} \]
      2. clear-num71.7%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq 6 \cdot 10^{-13}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \left(x \cdot \left(\varepsilon + x \cdot \left(x \cdot \left(x \cdot 0.6666666666666666 + \varepsilon \cdot 1.3333333333333333\right) + 1\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{\tan \left(\varepsilon + x\right) - \tan x}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 99.0% accurate, 1.0× speedup?

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

\\
\varepsilon + \varepsilon \cdot \left({\tan x}^{2} + \varepsilon \cdot \left(\varepsilon \cdot 0.3333333333333333\right)\right)
\end{array}
Derivation
  1. Initial program 61.7%

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

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

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

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

    \[\leadsto \varepsilon + \color{blue}{\left(\varepsilon \cdot \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{\left(0.16666666666666666 + \mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right)\right) - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)}{\cos x}, -0.3333333333333333 \cdot \left(\tan x \cdot \left(1 + {\tan x}^{2}\right)\right)\right), -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, 1 + {\tan x}^{2}, 0.16666666666666666 \cdot {\tan x}^{2}\right) - {\sin x}^{2} \cdot \left({\cos x}^{-2} \cdot \left(1 + {\tan x}^{2}\right)\right)\right), \tan x \cdot \left(1 + {\tan x}^{2}\right)\right) + {\tan x}^{2}\right)} \cdot \varepsilon \]
  7. Taylor expanded in x around 0 98.1%

    \[\leadsto \varepsilon + \left(\varepsilon \cdot \color{blue}{\left(0.3333333333333333 \cdot \varepsilon\right)} + {\tan x}^{2}\right) \cdot \varepsilon \]
  8. Step-by-step derivation
    1. *-commutative98.1%

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

    \[\leadsto \varepsilon + \left(\varepsilon \cdot \color{blue}{\left(\varepsilon \cdot 0.3333333333333333\right)} + {\tan x}^{2}\right) \cdot \varepsilon \]
  10. Final simplification98.1%

    \[\leadsto \varepsilon + \varepsilon \cdot \left({\tan x}^{2} + \varepsilon \cdot \left(\varepsilon \cdot 0.3333333333333333\right)\right) \]
  11. Add Preprocessing

Alternative 10: 99.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq 2 \cdot 10^{-13}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \left(x \cdot \left(\varepsilon + x \cdot \left(x \cdot \left(x \cdot 0.6666666666666666 + \varepsilon \cdot 1.3333333333333333\right) + 1\right)\right)\right)\\

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


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

    1. Initial program 61.4%

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

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

      \[\leadsto \color{blue}{\varepsilon \cdot \left(1 + \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \sin x \cdot \frac{0.16666666666666666 + \left(\mathsf{fma}\left(-0.5, 1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}, \frac{0.16666666666666666 \cdot {\sin x}^{2}}{{\cos x}^{2}}\right) - {\sin x}^{2} \cdot \frac{1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}}{{\cos x}^{2}}\right)}{\cos x} + \left(\left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) \cdot \frac{\sin x}{\cos x}\right) \cdot -0.3333333333333333, -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, 1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}, \frac{0.16666666666666666 \cdot {\sin x}^{2}}{{\cos x}^{2}}\right) - {\sin x}^{2} \cdot \frac{1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}}{{\cos x}^{2}}\right), \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) \cdot \frac{\sin x}{\cos x}\right), \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)} \]
    5. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\varepsilon + \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{0.16666666666666666 + \left(\mathsf{fma}\left(-0.5, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right), \left(0.16666666666666666 \cdot {\sin x}^{2}\right) \cdot {\cos x}^{-2}\right) - {\sin x}^{2} \cdot \left(\mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot {\cos x}^{-2}\right)\right)}{\cos x}, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot \left(\tan x \cdot -0.3333333333333333\right)\right), -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right), \left(0.16666666666666666 \cdot {\sin x}^{2}\right) \cdot {\cos x}^{-2}\right) - {\sin x}^{2} \cdot \left(\mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot {\cos x}^{-2}\right)\right), \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot \tan x\right), {\sin x}^{2} \cdot {\cos x}^{-2}\right) \cdot \varepsilon} \]
    6. Taylor expanded in eps around 0 100.0%

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

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

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

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

      \[\leadsto \varepsilon + \color{blue}{\left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(\left(0.6666666666666666 \cdot x + 0.8333333333333334 \cdot \varepsilon\right) - -0.5 \cdot \varepsilon\right)\right)\right)\right)} \cdot \varepsilon \]
    10. Step-by-step derivation
      1. associate--l+100.0%

        \[\leadsto \varepsilon + \left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \color{blue}{\left(0.6666666666666666 \cdot x + \left(0.8333333333333334 \cdot \varepsilon - -0.5 \cdot \varepsilon\right)\right)}\right)\right)\right) \cdot \varepsilon \]
      2. *-commutative100.0%

        \[\leadsto \varepsilon + \left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(\color{blue}{x \cdot 0.6666666666666666} + \left(0.8333333333333334 \cdot \varepsilon - -0.5 \cdot \varepsilon\right)\right)\right)\right)\right) \cdot \varepsilon \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \varepsilon + \left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(x \cdot 0.6666666666666666 + \color{blue}{\varepsilon \cdot \left(0.8333333333333334 - -0.5\right)}\right)\right)\right)\right) \cdot \varepsilon \]
      4. metadata-eval100.0%

        \[\leadsto \varepsilon + \left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(x \cdot 0.6666666666666666 + \varepsilon \cdot \color{blue}{1.3333333333333333}\right)\right)\right)\right) \cdot \varepsilon \]
    11. Simplified100.0%

      \[\leadsto \varepsilon + \color{blue}{\left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(x \cdot 0.6666666666666666 + \varepsilon \cdot 1.3333333333333333\right)\right)\right)\right)} \cdot \varepsilon \]

    if 2.0000000000000001e-13 < eps

    1. Initial program 70.6%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification98.9%

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

Alternative 11: 98.5% accurate, 9.8× speedup?

\[\begin{array}{l} \\ \varepsilon + \varepsilon \cdot \left(x \cdot \left(\varepsilon + x \cdot \left(x \cdot \left(x \cdot 0.6666666666666666 + \varepsilon \cdot 1.3333333333333333\right) + 1\right)\right)\right) \end{array} \]
(FPCore (x eps)
 :precision binary64
 (+
  eps
  (*
   eps
   (*
    x
    (+
     eps
     (*
      x
      (+
       (* x (+ (* x 0.6666666666666666) (* eps 1.3333333333333333)))
       1.0)))))))
double code(double x, double eps) {
	return eps + (eps * (x * (eps + (x * ((x * ((x * 0.6666666666666666) + (eps * 1.3333333333333333))) + 1.0)))));
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = eps + (eps * (x * (eps + (x * ((x * ((x * 0.6666666666666666d0) + (eps * 1.3333333333333333d0))) + 1.0d0)))))
end function
public static double code(double x, double eps) {
	return eps + (eps * (x * (eps + (x * ((x * ((x * 0.6666666666666666) + (eps * 1.3333333333333333))) + 1.0)))));
}
def code(x, eps):
	return eps + (eps * (x * (eps + (x * ((x * ((x * 0.6666666666666666) + (eps * 1.3333333333333333))) + 1.0)))))
function code(x, eps)
	return Float64(eps + Float64(eps * Float64(x * Float64(eps + Float64(x * Float64(Float64(x * Float64(Float64(x * 0.6666666666666666) + Float64(eps * 1.3333333333333333))) + 1.0))))))
end
function tmp = code(x, eps)
	tmp = eps + (eps * (x * (eps + (x * ((x * ((x * 0.6666666666666666) + (eps * 1.3333333333333333))) + 1.0)))));
end
code[x_, eps_] := N[(eps + N[(eps * N[(x * N[(eps + N[(x * N[(N[(x * N[(N[(x * 0.6666666666666666), $MachinePrecision] + N[(eps * 1.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\varepsilon + \varepsilon \cdot \left(x \cdot \left(\varepsilon + x \cdot \left(x \cdot \left(x \cdot 0.6666666666666666 + \varepsilon \cdot 1.3333333333333333\right) + 1\right)\right)\right)
\end{array}
Derivation
  1. Initial program 61.7%

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

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

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

    \[\leadsto \color{blue}{\varepsilon + \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{0.16666666666666666 + \left(\mathsf{fma}\left(-0.5, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right), \left(0.16666666666666666 \cdot {\sin x}^{2}\right) \cdot {\cos x}^{-2}\right) - {\sin x}^{2} \cdot \left(\mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot {\cos x}^{-2}\right)\right)}{\cos x}, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot \left(\tan x \cdot -0.3333333333333333\right)\right), -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right), \left(0.16666666666666666 \cdot {\sin x}^{2}\right) \cdot {\cos x}^{-2}\right) - {\sin x}^{2} \cdot \left(\mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot {\cos x}^{-2}\right)\right), \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot \tan x\right), {\sin x}^{2} \cdot {\cos x}^{-2}\right) \cdot \varepsilon} \]
  6. Taylor expanded in eps around 0 98.8%

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

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

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

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

    \[\leadsto \varepsilon + \color{blue}{\left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(\left(0.6666666666666666 \cdot x + 0.8333333333333334 \cdot \varepsilon\right) - -0.5 \cdot \varepsilon\right)\right)\right)\right)} \cdot \varepsilon \]
  10. Step-by-step derivation
    1. associate--l+97.2%

      \[\leadsto \varepsilon + \left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \color{blue}{\left(0.6666666666666666 \cdot x + \left(0.8333333333333334 \cdot \varepsilon - -0.5 \cdot \varepsilon\right)\right)}\right)\right)\right) \cdot \varepsilon \]
    2. *-commutative97.2%

      \[\leadsto \varepsilon + \left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(\color{blue}{x \cdot 0.6666666666666666} + \left(0.8333333333333334 \cdot \varepsilon - -0.5 \cdot \varepsilon\right)\right)\right)\right)\right) \cdot \varepsilon \]
    3. distribute-rgt-out--97.2%

      \[\leadsto \varepsilon + \left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(x \cdot 0.6666666666666666 + \color{blue}{\varepsilon \cdot \left(0.8333333333333334 - -0.5\right)}\right)\right)\right)\right) \cdot \varepsilon \]
    4. metadata-eval97.2%

      \[\leadsto \varepsilon + \left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(x \cdot 0.6666666666666666 + \varepsilon \cdot \color{blue}{1.3333333333333333}\right)\right)\right)\right) \cdot \varepsilon \]
  11. Simplified97.2%

    \[\leadsto \varepsilon + \color{blue}{\left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(x \cdot 0.6666666666666666 + \varepsilon \cdot 1.3333333333333333\right)\right)\right)\right)} \cdot \varepsilon \]
  12. Final simplification97.2%

    \[\leadsto \varepsilon + \varepsilon \cdot \left(x \cdot \left(\varepsilon + x \cdot \left(x \cdot \left(x \cdot 0.6666666666666666 + \varepsilon \cdot 1.3333333333333333\right) + 1\right)\right)\right) \]
  13. Add Preprocessing

Alternative 12: 98.3% accurate, 12.1× speedup?

\[\begin{array}{l} \\ \varepsilon + \varepsilon \cdot \left(x \cdot \left(\varepsilon + x \cdot \left(x \cdot \left(\varepsilon \cdot 1.3333333333333333\right) + 1\right)\right)\right) \end{array} \]
(FPCore (x eps)
 :precision binary64
 (+ eps (* eps (* x (+ eps (* x (+ (* x (* eps 1.3333333333333333)) 1.0)))))))
double code(double x, double eps) {
	return eps + (eps * (x * (eps + (x * ((x * (eps * 1.3333333333333333)) + 1.0)))));
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = eps + (eps * (x * (eps + (x * ((x * (eps * 1.3333333333333333d0)) + 1.0d0)))))
end function
public static double code(double x, double eps) {
	return eps + (eps * (x * (eps + (x * ((x * (eps * 1.3333333333333333)) + 1.0)))));
}
def code(x, eps):
	return eps + (eps * (x * (eps + (x * ((x * (eps * 1.3333333333333333)) + 1.0)))))
function code(x, eps)
	return Float64(eps + Float64(eps * Float64(x * Float64(eps + Float64(x * Float64(Float64(x * Float64(eps * 1.3333333333333333)) + 1.0))))))
end
function tmp = code(x, eps)
	tmp = eps + (eps * (x * (eps + (x * ((x * (eps * 1.3333333333333333)) + 1.0)))));
end
code[x_, eps_] := N[(eps + N[(eps * N[(x * N[(eps + N[(x * N[(N[(x * N[(eps * 1.3333333333333333), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\varepsilon + \varepsilon \cdot \left(x \cdot \left(\varepsilon + x \cdot \left(x \cdot \left(\varepsilon \cdot 1.3333333333333333\right) + 1\right)\right)\right)
\end{array}
Derivation
  1. Initial program 61.7%

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

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

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

    \[\leadsto \color{blue}{\varepsilon + \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{0.16666666666666666 + \left(\mathsf{fma}\left(-0.5, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right), \left(0.16666666666666666 \cdot {\sin x}^{2}\right) \cdot {\cos x}^{-2}\right) - {\sin x}^{2} \cdot \left(\mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot {\cos x}^{-2}\right)\right)}{\cos x}, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot \left(\tan x \cdot -0.3333333333333333\right)\right), -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right), \left(0.16666666666666666 \cdot {\sin x}^{2}\right) \cdot {\cos x}^{-2}\right) - {\sin x}^{2} \cdot \left(\mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot {\cos x}^{-2}\right)\right), \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot \tan x\right), {\sin x}^{2} \cdot {\cos x}^{-2}\right) \cdot \varepsilon} \]
  6. Taylor expanded in eps around 0 98.8%

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

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

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

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

    \[\leadsto \varepsilon + \color{blue}{\left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(0.8333333333333334 \cdot \varepsilon - -0.5 \cdot \varepsilon\right)\right)\right)\right)} \cdot \varepsilon \]
  10. Step-by-step derivation
    1. distribute-rgt-out--97.2%

      \[\leadsto \varepsilon + \left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \color{blue}{\left(\varepsilon \cdot \left(0.8333333333333334 - -0.5\right)\right)}\right)\right)\right) \cdot \varepsilon \]
    2. metadata-eval97.2%

      \[\leadsto \varepsilon + \left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(\varepsilon \cdot \color{blue}{1.3333333333333333}\right)\right)\right)\right) \cdot \varepsilon \]
  11. Simplified97.2%

    \[\leadsto \varepsilon + \color{blue}{\left(x \cdot \left(\varepsilon + x \cdot \left(1 + x \cdot \left(\varepsilon \cdot 1.3333333333333333\right)\right)\right)\right)} \cdot \varepsilon \]
  12. Final simplification97.2%

    \[\leadsto \varepsilon + \varepsilon \cdot \left(x \cdot \left(\varepsilon + x \cdot \left(x \cdot \left(\varepsilon \cdot 1.3333333333333333\right) + 1\right)\right)\right) \]
  13. Add Preprocessing

Alternative 13: 98.3% accurate, 22.8× speedup?

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

\\
\varepsilon + \varepsilon \cdot \left(x \cdot \left(\varepsilon + x\right)\right)
\end{array}
Derivation
  1. Initial program 61.7%

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

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

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

    \[\leadsto \color{blue}{\varepsilon + \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{0.16666666666666666 + \left(\mathsf{fma}\left(-0.5, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right), \left(0.16666666666666666 \cdot {\sin x}^{2}\right) \cdot {\cos x}^{-2}\right) - {\sin x}^{2} \cdot \left(\mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot {\cos x}^{-2}\right)\right)}{\cos x}, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot \left(\tan x \cdot -0.3333333333333333\right)\right), -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right), \left(0.16666666666666666 \cdot {\sin x}^{2}\right) \cdot {\cos x}^{-2}\right) - {\sin x}^{2} \cdot \left(\mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot {\cos x}^{-2}\right)\right), \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot \tan x\right), {\sin x}^{2} \cdot {\cos x}^{-2}\right) \cdot \varepsilon} \]
  6. Taylor expanded in eps around 0 98.8%

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

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

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

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

    \[\leadsto \varepsilon + \color{blue}{\left(x \cdot \left(\varepsilon + x\right)\right)} \cdot \varepsilon \]
  10. Final simplification97.2%

    \[\leadsto \varepsilon + \varepsilon \cdot \left(x \cdot \left(\varepsilon + x\right)\right) \]
  11. Add Preprocessing

Alternative 14: 97.9% accurate, 29.3× speedup?

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

\\
\varepsilon + \varepsilon \cdot \left(\varepsilon \cdot x\right)
\end{array}
Derivation
  1. Initial program 61.7%

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

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

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

    \[\leadsto \color{blue}{\varepsilon + \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(-\varepsilon, \mathsf{fma}\left(\sin x, \frac{0.16666666666666666 + \left(\mathsf{fma}\left(-0.5, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right), \left(0.16666666666666666 \cdot {\sin x}^{2}\right) \cdot {\cos x}^{-2}\right) - {\sin x}^{2} \cdot \left(\mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot {\cos x}^{-2}\right)\right)}{\cos x}, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot \left(\tan x \cdot -0.3333333333333333\right)\right), -0.16666666666666666\right) - \left(\mathsf{fma}\left(-0.5, \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right), \left(0.16666666666666666 \cdot {\sin x}^{2}\right) \cdot {\cos x}^{-2}\right) - {\sin x}^{2} \cdot \left(\mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot {\cos x}^{-2}\right)\right), \mathsf{fma}\left({\sin x}^{2}, {\cos x}^{-2}, 1\right) \cdot \tan x\right), {\sin x}^{2} \cdot {\cos x}^{-2}\right) \cdot \varepsilon} \]
  6. Taylor expanded in eps around 0 98.8%

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

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

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

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

    \[\leadsto \varepsilon + \color{blue}{\left(\varepsilon \cdot x\right)} \cdot \varepsilon \]
  10. Final simplification96.9%

    \[\leadsto \varepsilon + \varepsilon \cdot \left(\varepsilon \cdot x\right) \]
  11. Add Preprocessing

Alternative 15: 97.9% accurate, 205.0× speedup?

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

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

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

    \[\leadsto \tan \color{blue}{\varepsilon} - \tan x \]
  4. Taylor expanded in eps around 0 8.1%

    \[\leadsto \color{blue}{\varepsilon} - \tan x \]
  5. Taylor expanded in eps around inf 96.9%

    \[\leadsto \color{blue}{\varepsilon} \]
  6. Add Preprocessing

Developer Target 1: 99.9% 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}

Developer Target 2: 62.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x \end{array} \]
(FPCore (x eps)
 :precision binary64
 (- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x)))
double code(double x, double eps) {
	return ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = ((tan(x) + tan(eps)) / (1.0d0 - (tan(x) * tan(eps)))) - tan(x)
end function
public static double code(double x, double eps) {
	return ((Math.tan(x) + Math.tan(eps)) / (1.0 - (Math.tan(x) * Math.tan(eps)))) - Math.tan(x);
}
def code(x, eps):
	return ((math.tan(x) + math.tan(eps)) / (1.0 - (math.tan(x) * math.tan(eps)))) - math.tan(x)
function code(x, eps)
	return Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x))
end
function tmp = code(x, eps)
	tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
end
code[x_, eps_] := 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]
\begin{array}{l}

\\
\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x
\end{array}

Developer Target 3: 99.0% accurate, 1.0× speedup?

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

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

Reproduce

?
herbie shell --seed 2024170 
(FPCore (x eps)
  :name "2tan (problem 3.3.2)"
  :precision binary64
  :pre (and (and (and (<= -10000.0 x) (<= x 10000.0)) (< (* 1e-16 (fabs x)) eps)) (< eps (fabs x)))

  :alt
  (! :herbie-platform default (/ (sin eps) (* (cos x) (cos (+ x eps)))))

  :alt
  (! :herbie-platform default (- (/ (+ (tan x) (tan eps)) (- 1 (* (tan x) (tan eps)))) (tan x)))

  :alt
  (! :herbie-platform default (+ eps (* eps (tan x) (tan x))))

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