2tan (problem 3.3.2)

Percentage Accurate: 42.7% → 98.9%
Time: 15.5s
Alternatives: 7
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 7 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.7% accurate, 1.0× speedup?

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

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

Alternative 1: 98.9% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := 1 - \tan x \cdot \tan \varepsilon\\
t_1 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -3.2 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{t_0}, t_1, -\tan x\right)\\

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

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


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

    1. Initial program 47.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x} \]
    7. Step-by-step derivation
      1. clear-num99.2%

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

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

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

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

    if -3.20000000000000012e-9 < eps < 6.50000000000000043e-28

    1. Initial program 28.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 6.50000000000000043e-28 < eps

    1. Initial program 50.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 98.9% accurate, 0.4× speedup?

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

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

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


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

    1. Initial program 49.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.0000000000000001e-9 < eps < 6.50000000000000043e-28

    1. Initial program 28.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 77.4% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -8.5 \cdot 10^{-6} \lor \neg \left(\varepsilon \leq 6.5 \cdot 10^{-28}\right):\\
\;\;\;\;\tan \varepsilon\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < -8.4999999999999999e-6 or 6.50000000000000043e-28 < eps

    1. Initial program 49.4%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\tan \varepsilon} \]
    7. Simplified52.0%

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

    if -8.4999999999999999e-6 < eps < 6.50000000000000043e-28

    1. Initial program 28.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -8.5 \cdot 10^{-6} \lor \neg \left(\varepsilon \leq 6.5 \cdot 10^{-28}\right):\\ \;\;\;\;\tan \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 77.3% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -9.6 \cdot 10^{-6} \lor \neg \left(\varepsilon \leq 6.5 \cdot 10^{-28}\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 -9.6e-6) (not (<= eps 6.5e-28)))
   (tan eps)
   (* eps (+ 1.0 (pow (tan x) 2.0)))))
double code(double x, double eps) {
	double tmp;
	if ((eps <= -9.6e-6) || !(eps <= 6.5e-28)) {
		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 <= (-9.6d-6)) .or. (.not. (eps <= 6.5d-28))) 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 <= -9.6e-6) || !(eps <= 6.5e-28)) {
		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 <= -9.6e-6) or not (eps <= 6.5e-28):
		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 <= -9.6e-6) || !(eps <= 6.5e-28))
		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 <= -9.6e-6) || ~((eps <= 6.5e-28)))
		tmp = tan(eps);
	else
		tmp = eps * (1.0 + (tan(x) ^ 2.0));
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[Or[LessEqual[eps, -9.6e-6], N[Not[LessEqual[eps, 6.5e-28]], $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 -9.6 \cdot 10^{-6} \lor \neg \left(\varepsilon \leq 6.5 \cdot 10^{-28}\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 < -9.5999999999999996e-6 or 6.50000000000000043e-28 < eps

    1. Initial program 49.4%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\tan \varepsilon} \]
    7. Simplified52.0%

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

    if -9.5999999999999996e-6 < eps < 6.50000000000000043e-28

    1. Initial program 28.8%

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

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

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

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

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

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

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

        \[\leadsto \varepsilon \cdot \left(1 + \frac{\color{blue}{\sin x \cdot \sin x}}{\cos x \cdot \cos x}\right) \]
      3. frac-times99.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.5%

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

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

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

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

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

Alternative 5: 77.4% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -1.15 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 6.5 \cdot 10^{-28}\right):\\ \;\;\;\;\tan \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= eps -1.15e-5) (not (<= eps 6.5e-28)))
   (tan eps)
   (+ eps (* eps (pow (tan x) 2.0)))))
double code(double x, double eps) {
	double tmp;
	if ((eps <= -1.15e-5) || !(eps <= 6.5e-28)) {
		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.15d-5)) .or. (.not. (eps <= 6.5d-28))) 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.15e-5) || !(eps <= 6.5e-28)) {
		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.15e-5) or not (eps <= 6.5e-28):
		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.15e-5) || !(eps <= 6.5e-28))
		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.15e-5) || ~((eps <= 6.5e-28)))
		tmp = tan(eps);
	else
		tmp = eps + (eps * (tan(x) ^ 2.0));
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[Or[LessEqual[eps, -1.15e-5], N[Not[LessEqual[eps, 6.5e-28]], $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.15 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 6.5 \cdot 10^{-28}\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.15e-5 or 6.50000000000000043e-28 < eps

    1. Initial program 49.4%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\tan \varepsilon} \]
    7. Simplified52.0%

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

    if -1.15e-5 < eps < 6.50000000000000043e-28

    1. Initial program 28.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 58.5% 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 38.8%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\tan \varepsilon} \]
  7. Simplified55.4%

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

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

Alternative 7: 31.5% 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 38.8%

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

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

    \[\leadsto \color{blue}{\varepsilon} \]
  5. Final simplification33.1%

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

Developer target: 76.7% 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 2024019 
(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)))