Average Error: 36.6 → 1.1
Time: 19.0s
Precision: binary64
Cost: 33096
\[\tan \left(x + \varepsilon\right) - \tan x \]
\[\begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ t_1 := 1 - \tan x \cdot \tan \varepsilon\\ \mathbf{if}\;\varepsilon \leq -2.2035044657257864 \cdot 10^{-5}:\\ \;\;\;\;\frac{t_0}{t_1} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 1.1607855148576445 \cdot 10^{-36}:\\ \;\;\;\;\varepsilon + \frac{1}{\frac{{\cos x}^{2}}{\varepsilon \cdot {\sin x}^{2}}}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \frac{1}{t_1} - \tan x\\ \end{array} \]
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps))) (t_1 (- 1.0 (* (tan x) (tan eps)))))
   (if (<= eps -2.2035044657257864e-5)
     (- (/ t_0 t_1) (tan x))
     (if (<= eps 1.1607855148576445e-36)
       (+ eps (/ 1.0 (/ (pow (cos x) 2.0) (* eps (pow (sin x) 2.0)))))
       (- (* t_0 (/ 1.0 t_1)) (tan x))))))
double code(double x, double eps) {
	return tan((x + eps)) - 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 <= -2.2035044657257864e-5) {
		tmp = (t_0 / t_1) - tan(x);
	} else if (eps <= 1.1607855148576445e-36) {
		tmp = eps + (1.0 / (pow(cos(x), 2.0) / (eps * pow(sin(x), 2.0))));
	} else {
		tmp = (t_0 * (1.0 / t_1)) - tan(x);
	}
	return tmp;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = tan((x + eps)) - tan(x)
end function
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 <= (-2.2035044657257864d-5)) then
        tmp = (t_0 / t_1) - tan(x)
    else if (eps <= 1.1607855148576445d-36) then
        tmp = eps + (1.0d0 / ((cos(x) ** 2.0d0) / (eps * (sin(x) ** 2.0d0))))
    else
        tmp = (t_0 * (1.0d0 / t_1)) - tan(x)
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	return Math.tan((x + eps)) - Math.tan(x);
}
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 <= -2.2035044657257864e-5) {
		tmp = (t_0 / t_1) - Math.tan(x);
	} else if (eps <= 1.1607855148576445e-36) {
		tmp = eps + (1.0 / (Math.pow(Math.cos(x), 2.0) / (eps * Math.pow(Math.sin(x), 2.0))));
	} else {
		tmp = (t_0 * (1.0 / t_1)) - Math.tan(x);
	}
	return tmp;
}
def code(x, eps):
	return math.tan((x + eps)) - math.tan(x)
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 <= -2.2035044657257864e-5:
		tmp = (t_0 / t_1) - math.tan(x)
	elif eps <= 1.1607855148576445e-36:
		tmp = eps + (1.0 / (math.pow(math.cos(x), 2.0) / (eps * math.pow(math.sin(x), 2.0))))
	else:
		tmp = (t_0 * (1.0 / t_1)) - math.tan(x)
	return tmp
function code(x, eps)
	return Float64(tan(Float64(x + eps)) - tan(x))
end
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 <= -2.2035044657257864e-5)
		tmp = Float64(Float64(t_0 / t_1) - tan(x));
	elseif (eps <= 1.1607855148576445e-36)
		tmp = Float64(eps + Float64(1.0 / Float64((cos(x) ^ 2.0) / Float64(eps * (sin(x) ^ 2.0)))));
	else
		tmp = Float64(Float64(t_0 * Float64(1.0 / t_1)) - tan(x));
	end
	return tmp
end
function tmp = code(x, eps)
	tmp = tan((x + eps)) - tan(x);
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 <= -2.2035044657257864e-5)
		tmp = (t_0 / t_1) - tan(x);
	elseif (eps <= 1.1607855148576445e-36)
		tmp = eps + (1.0 / ((cos(x) ^ 2.0) / (eps * (sin(x) ^ 2.0))));
	else
		tmp = (t_0 * (1.0 / t_1)) - tan(x);
	end
	tmp_2 = tmp;
end
code[x_, eps_] := N[(N[Tan[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
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, -2.2035044657257864e-5], N[(N[(t$95$0 / t$95$1), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 1.1607855148576445e-36], N[(eps + N[(1.0 / N[(N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision] / N[(eps * N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * N[(1.0 / t$95$1), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
t_1 := 1 - \tan x \cdot \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -2.2035044657257864 \cdot 10^{-5}:\\
\;\;\;\;\frac{t_0}{t_1} - \tan x\\

\mathbf{elif}\;\varepsilon \leq 1.1607855148576445 \cdot 10^{-36}:\\
\;\;\;\;\varepsilon + \frac{1}{\frac{{\cos x}^{2}}{\varepsilon \cdot {\sin x}^{2}}}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original36.6
Target15.3
Herbie1.1
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)} \]

Derivation

  1. Split input into 3 regimes
  2. if eps < -2.20350446572578636e-5

    1. Initial program 29.1

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Applied egg-rr0.4

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

    if -2.20350446572578636e-5 < eps < 1.16078551485764454e-36

    1. Initial program 45.2

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

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

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
      Proof
      (+.f64 eps (*.f64 eps (/.f64 (pow.f64 (sin.f64 x) 2) (pow.f64 (cos.f64 x) 2)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 eps)) (*.f64 eps (/.f64 (pow.f64 (sin.f64 x) 2) (pow.f64 (cos.f64 x) 2)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 1 eps) (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 (pow.f64 (sin.f64 x) 2) (pow.f64 (cos.f64 x) 2)) eps))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-rgt-in_binary64 (*.f64 eps (+.f64 1 (/.f64 (pow.f64 (sin.f64 x) 2) (pow.f64 (cos.f64 x) 2))))): 31 points increase in error, 15 points decrease in error
      (*.f64 eps (+.f64 1 (Rewrite<= *-lft-identity_binary64 (*.f64 1 (/.f64 (pow.f64 (sin.f64 x) 2) (pow.f64 (cos.f64 x) 2)))))): 0 points increase in error, 0 points decrease in error
      (*.f64 eps (+.f64 1 (*.f64 (Rewrite<= metadata-eval (neg.f64 -1)) (/.f64 (pow.f64 (sin.f64 x) 2) (pow.f64 (cos.f64 x) 2))))): 0 points increase in error, 0 points decrease in error
      (*.f64 eps (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 1 (*.f64 -1 (/.f64 (pow.f64 (sin.f64 x) 2) (pow.f64 (cos.f64 x) 2)))))): 0 points increase in error, 0 points decrease in error
    4. Applied egg-rr0.4

      \[\leadsto \varepsilon + \varepsilon \cdot \frac{\color{blue}{0.5 - 0.5 \cdot \cos \left(2 \cdot x\right)}}{{\cos x}^{2}} \]
    5. Applied egg-rr0.5

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

    if 1.16078551485764454e-36 < eps

    1. Initial program 29.8

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Applied egg-rr29.9

      \[\leadsto \color{blue}{\sqrt[3]{{\tan \left(x + \varepsilon\right)}^{3}}} - \tan x \]
    3. Applied egg-rr3.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -2.2035044657257864 \cdot 10^{-5}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 1.1607855148576445 \cdot 10^{-36}:\\ \;\;\;\;\varepsilon + \frac{1}{\frac{{\cos x}^{2}}{\varepsilon \cdot {\sin x}^{2}}}\\ \mathbf{else}:\\ \;\;\;\;\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \end{array} \]

Alternatives

Alternative 1
Error1.1
Cost32968
\[\begin{array}{l} t_0 := \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{if}\;\varepsilon \leq -2.2035044657257864 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\varepsilon \leq 1.1607855148576445 \cdot 10^{-36}:\\ \;\;\;\;\varepsilon + \frac{1}{\frac{{\cos x}^{2}}{\varepsilon \cdot {\sin x}^{2}}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error14.6
Cost26568
\[\begin{array}{l} t_0 := \mathsf{fma}\left(\tan x + \tan \varepsilon, 1, -\tan x\right)\\ \mathbf{if}\;\varepsilon \leq -2.2035044657257864 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\varepsilon \leq 4.37400911955214 \cdot 10^{-8}:\\ \;\;\;\;\varepsilon + \frac{1}{\frac{{\cos x}^{2}}{\varepsilon \cdot {\sin x}^{2}}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error14.6
Cost26248
\[\begin{array}{l} t_0 := \mathsf{fma}\left(\tan x + \tan \varepsilon, 1, -\tan x\right)\\ \mathbf{if}\;\varepsilon \leq -2.2035044657257864 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\varepsilon \leq 4.37400911955214 \cdot 10^{-8}:\\ \;\;\;\;\varepsilon + \frac{\varepsilon \cdot \left(0.5 + \cos \left(x \cdot 2\right) \cdot -0.5\right)}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error14.7
Cost20360
\[\begin{array}{l} \mathbf{if}\;\varepsilon \leq -2.2035044657257864 \cdot 10^{-5}:\\ \;\;\;\;\frac{1}{\frac{\cos \varepsilon}{\sin \varepsilon}}\\ \mathbf{elif}\;\varepsilon \leq 4.37400911955214 \cdot 10^{-8}:\\ \;\;\;\;\varepsilon + \frac{\varepsilon \cdot \left(0.5 + \cos \left(x \cdot 2\right) \cdot -0.5\right)}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin \varepsilon}{\cos \varepsilon}\\ \end{array} \]
Alternative 5
Error14.7
Cost19976
\[\begin{array}{l} \mathbf{if}\;\varepsilon \leq -2.2035044657257864 \cdot 10^{-5}:\\ \;\;\;\;\frac{1}{\frac{\cos \varepsilon}{\sin \varepsilon}}\\ \mathbf{elif}\;\varepsilon \leq 4.37400911955214 \cdot 10^{-8}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot {\left(\frac{\sin x}{\cos x}\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin \varepsilon}{\cos \varepsilon}\\ \end{array} \]
Alternative 6
Error14.8
Cost14280
\[\begin{array}{l} t_0 := \cos \left(x \cdot 2\right)\\ \mathbf{if}\;\varepsilon \leq -2.2035044657257864 \cdot 10^{-5}:\\ \;\;\;\;\frac{1}{\frac{\cos \varepsilon}{\sin \varepsilon}}\\ \mathbf{elif}\;\varepsilon \leq 4.37400911955214 \cdot 10^{-8}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{0.5 + t_0 \cdot -0.5}{0.5 + 0.5 \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin \varepsilon}{\cos \varepsilon}\\ \end{array} \]
Alternative 7
Error26.8
Cost12992
\[\frac{\sin \varepsilon}{\cos \varepsilon} \]
Alternative 8
Error43.9
Cost7104
\[\varepsilon + \varepsilon \cdot \left(0.5 + \cos \left(x \cdot 2\right) \cdot -0.5\right) \]
Alternative 9
Error44.5
Cost64
\[\varepsilon \]

Error

Reproduce

herbie shell --seed 2022312 
(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)))