2tan (problem 3.3.2)

Percentage Accurate: 42.5% → 99.4%
Time: 19.9s
Alternatives: 9
Speedup: 2.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 alternatives:

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

Initial Program: 42.5% accurate, 1.0× speedup?

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

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

Alternative 1: 99.4% accurate, 0.4× speedup?

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

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

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


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

    1. Initial program 53.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.34999999999999981e-9 < eps < 3.20000000000000012e-9

    1. Initial program 33.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.1% accurate, 0.2× speedup?

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

\\
\begin{array}{l}
t_0 := \tan x \cdot \tan \varepsilon\\
\frac{t_0 + \frac{\cos x}{\cos \varepsilon} \cdot \frac{\sin \varepsilon}{\sin x}}{\frac{1 - t_0}{\tan x}}
\end{array}
\end{array}
Derivation
  1. Initial program 44.8%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\frac{\tan x}{\frac{\cos \varepsilon}{\sin \varepsilon}}}} - \tan x \]
    4. clear-num71.1%

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

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

    \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\frac{\tan x}{\frac{1}{\tan \varepsilon}}}} - \tan x \]
  8. Step-by-step derivation
    1. tan-quot70.9%

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \frac{\tan x}{\frac{1}{\tan \varepsilon}}} - \color{blue}{\frac{\sin x}{\cos x}} \]
    2. frac-sub70.9%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \frac{\sin x}{\cos x}} \]
    8. clear-num70.8%

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \color{blue}{\frac{1}{\frac{\cos x}{\sin x}}} \]
  9. Applied egg-rr70.9%

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

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

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

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

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

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

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

      \[\leadsto \frac{\tan x \cdot \tan \varepsilon + \left(\frac{\tan x + \tan \varepsilon}{\sqrt{\tan x} \cdot \color{blue}{\sqrt{\tan x}}} - 1\right)}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \frac{1}{\tan x}} \]
    8. rem-square-sqrt74.0%

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

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

      \[\leadsto \frac{\tan x \cdot \tan \varepsilon + \left(\frac{\tan x + \tan \varepsilon}{\tan x} - 1\right)}{\color{blue}{\frac{1 - \tan x \cdot \tan \varepsilon}{\frac{\tan x}{1}}}} \]
    11. rem-square-sqrt38.6%

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

      \[\leadsto \frac{\tan x \cdot \tan \varepsilon + \left(\frac{\tan x + \tan \varepsilon}{\tan x} - 1\right)}{\frac{1 - \tan x \cdot \tan \varepsilon}{\color{blue}{\sqrt{\tan x} \cdot \frac{\sqrt{\tan x}}{1}}}} \]
  11. Simplified74.0%

    \[\leadsto \color{blue}{\frac{\tan x \cdot \tan \varepsilon + \left(\frac{\tan x + \tan \varepsilon}{\tan x} - 1\right)}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x}}} \]
  12. Taylor expanded in x around inf 99.2%

    \[\leadsto \frac{\tan x \cdot \tan \varepsilon + \color{blue}{\frac{\cos x \cdot \sin \varepsilon}{\cos \varepsilon \cdot \sin x}}}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x}} \]
  13. Step-by-step derivation
    1. times-frac99.2%

      \[\leadsto \frac{\tan x \cdot \tan \varepsilon + \color{blue}{\frac{\cos x}{\cos \varepsilon} \cdot \frac{\sin \varepsilon}{\sin x}}}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x}} \]
  14. Simplified99.2%

    \[\leadsto \frac{\tan x \cdot \tan \varepsilon + \color{blue}{\frac{\cos x}{\cos \varepsilon} \cdot \frac{\sin \varepsilon}{\sin x}}}{\frac{1 - \tan x \cdot \tan \varepsilon}{\tan x}} \]
  15. Final simplification99.2%

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

Alternative 3: 99.4% accurate, 0.4× speedup?

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

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

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


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

    1. Initial program 53.3%

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

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

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

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

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

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

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

    if -3.7e-9 < eps < 2.0500000000000002e-9

    1. Initial program 33.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 99.4% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;\varepsilon \leq 3.6 \cdot 10^{-9}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\

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


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

    1. Initial program 50.8%

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

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

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

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

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

    if -4.5999999999999998e-9 < eps < 3.6e-9

    1. Initial program 33.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\varepsilon \cdot {\tan x}^{2} + \varepsilon} \]

    if 3.6e-9 < eps

    1. Initial program 56.3%

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

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

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

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

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

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

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

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

Alternative 5: 77.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -1.7 \cdot 10^{-7}:\\ \;\;\;\;\tan \varepsilon\\ \mathbf{elif}\;\varepsilon \leq 3 \cdot 10^{-9}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\tan x}{\varepsilon \cdot -0.3333333333333333 + \frac{1}{\varepsilon}}} - \tan x\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (<= eps -1.7e-7)
   (tan eps)
   (if (<= eps 3e-9)
     (+ eps (* eps (pow (tan x) 2.0)))
     (-
      (/
       (+ (tan x) (tan eps))
       (- 1.0 (/ (tan x) (+ (* eps -0.3333333333333333) (/ 1.0 eps)))))
      (tan x)))))
double code(double x, double eps) {
	double tmp;
	if (eps <= -1.7e-7) {
		tmp = tan(eps);
	} else if (eps <= 3e-9) {
		tmp = eps + (eps * pow(tan(x), 2.0));
	} else {
		tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) / ((eps * -0.3333333333333333) + (1.0 / eps))))) - 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 <= (-1.7d-7)) then
        tmp = tan(eps)
    else if (eps <= 3d-9) then
        tmp = eps + (eps * (tan(x) ** 2.0d0))
    else
        tmp = ((tan(x) + tan(eps)) / (1.0d0 - (tan(x) / ((eps * (-0.3333333333333333d0)) + (1.0d0 / eps))))) - tan(x)
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double tmp;
	if (eps <= -1.7e-7) {
		tmp = Math.tan(eps);
	} else if (eps <= 3e-9) {
		tmp = eps + (eps * Math.pow(Math.tan(x), 2.0));
	} else {
		tmp = ((Math.tan(x) + Math.tan(eps)) / (1.0 - (Math.tan(x) / ((eps * -0.3333333333333333) + (1.0 / eps))))) - Math.tan(x);
	}
	return tmp;
}
def code(x, eps):
	tmp = 0
	if eps <= -1.7e-7:
		tmp = math.tan(eps)
	elif eps <= 3e-9:
		tmp = eps + (eps * math.pow(math.tan(x), 2.0))
	else:
		tmp = ((math.tan(x) + math.tan(eps)) / (1.0 - (math.tan(x) / ((eps * -0.3333333333333333) + (1.0 / eps))))) - math.tan(x)
	return tmp
function code(x, eps)
	tmp = 0.0
	if (eps <= -1.7e-7)
		tmp = tan(eps);
	elseif (eps <= 3e-9)
		tmp = Float64(eps + Float64(eps * (tan(x) ^ 2.0)));
	else
		tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(tan(x) / Float64(Float64(eps * -0.3333333333333333) + Float64(1.0 / eps))))) - tan(x));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	tmp = 0.0;
	if (eps <= -1.7e-7)
		tmp = tan(eps);
	elseif (eps <= 3e-9)
		tmp = eps + (eps * (tan(x) ^ 2.0));
	else
		tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) / ((eps * -0.3333333333333333) + (1.0 / eps))))) - tan(x);
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[LessEqual[eps, -1.7e-7], N[Tan[eps], $MachinePrecision], If[LessEqual[eps, 3e-9], N[(eps + N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Tan[x], $MachinePrecision] / N[(N[(eps * -0.3333333333333333), $MachinePrecision] + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.7 \cdot 10^{-7}:\\
\;\;\;\;\tan \varepsilon\\

\mathbf{elif}\;\varepsilon \leq 3 \cdot 10^{-9}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\

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


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

    1. Initial program 50.8%

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

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

        \[\leadsto \color{blue}{\tan \varepsilon} \]
      2. *-un-lft-identity54.6%

        \[\leadsto \color{blue}{1 \cdot \tan \varepsilon} \]
      3. *-commutative54.6%

        \[\leadsto \color{blue}{\tan \varepsilon \cdot 1} \]
    4. Applied egg-rr54.6%

      \[\leadsto \color{blue}{\tan \varepsilon \cdot 1} \]
    5. Step-by-step derivation
      1. *-rgt-identity54.6%

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

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

    if -1.69999999999999987e-7 < eps < 2.99999999999999998e-9

    1. Initial program 33.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\varepsilon \cdot {\tan x}^{2} + \varepsilon} \]

    if 2.99999999999999998e-9 < eps

    1. Initial program 56.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -1.7 \cdot 10^{-7}:\\ \;\;\;\;\tan \varepsilon\\ \mathbf{elif}\;\varepsilon \leq 3 \cdot 10^{-9}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\tan x}{\varepsilon \cdot -0.3333333333333333 + \frac{1}{\varepsilon}}} - \tan x\\ \end{array} \]

Alternative 6: 77.7% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.7 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 1.65 \cdot 10^{-7}\right):\\
\;\;\;\;\tan \varepsilon\\

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


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

    1. Initial program 53.3%

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

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

        \[\leadsto \color{blue}{\tan \varepsilon} \]
      2. *-un-lft-identity56.2%

        \[\leadsto \color{blue}{1 \cdot \tan \varepsilon} \]
      3. *-commutative56.2%

        \[\leadsto \color{blue}{\tan \varepsilon \cdot 1} \]
    4. Applied egg-rr56.2%

      \[\leadsto \color{blue}{\tan \varepsilon \cdot 1} \]
    5. Step-by-step derivation
      1. *-rgt-identity56.2%

        \[\leadsto \color{blue}{\tan \varepsilon} \]
    6. Simplified56.2%

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

    if -1.69999999999999987e-7 < eps < 1.6500000000000001e-7

    1. Initial program 33.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -1.7 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 1.65 \cdot 10^{-7}\right):\\ \;\;\;\;\tan \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\varepsilon \cdot \left(1 + {\tan x}^{2}\right)\\ \end{array} \]

Alternative 7: 77.7% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.7 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 2.5 \cdot 10^{-7}\right):\\
\;\;\;\;\tan \varepsilon\\

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


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

    1. Initial program 53.3%

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

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

        \[\leadsto \color{blue}{\tan \varepsilon} \]
      2. *-un-lft-identity56.2%

        \[\leadsto \color{blue}{1 \cdot \tan \varepsilon} \]
      3. *-commutative56.2%

        \[\leadsto \color{blue}{\tan \varepsilon \cdot 1} \]
    4. Applied egg-rr56.2%

      \[\leadsto \color{blue}{\tan \varepsilon \cdot 1} \]
    5. Step-by-step derivation
      1. *-rgt-identity56.2%

        \[\leadsto \color{blue}{\tan \varepsilon} \]
    6. Simplified56.2%

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

    if -1.69999999999999987e-7 < eps < 2.49999999999999989e-7

    1. Initial program 33.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -1.7 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 2.5 \cdot 10^{-7}\right):\\ \;\;\;\;\tan \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\ \end{array} \]

Alternative 8: 58.3% accurate, 2.0× speedup?

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

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

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

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

      \[\leadsto \color{blue}{\tan \varepsilon} \]
    2. *-un-lft-identity57.9%

      \[\leadsto \color{blue}{1 \cdot \tan \varepsilon} \]
    3. *-commutative57.9%

      \[\leadsto \color{blue}{\tan \varepsilon \cdot 1} \]
  4. Applied egg-rr57.9%

    \[\leadsto \color{blue}{\tan \varepsilon \cdot 1} \]
  5. Step-by-step derivation
    1. *-rgt-identity57.9%

      \[\leadsto \color{blue}{\tan \varepsilon} \]
  6. Simplified57.9%

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

    \[\leadsto \tan \varepsilon \]

Alternative 9: 31.4% 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 44.8%

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

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

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

    \[\leadsto \varepsilon \]

Developer target: 76.6% accurate, 0.7× speedup?

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

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

Reproduce

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

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

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