<s>[INST] If $\lim_{x\to 0}\frac{\cos^2x-\cos x-e^x\cos x+e^x-\frac{x^3}{2}}{x^n}$ is a non zero finite number number, find $n$ where $n\in\mathbb{N}$ 
If the following limit $$\lim_{x\to 0}\frac{\cos^2x-\cos x-e^x\cos x+e^x-\frac{x^3}{2}}{x^n}$$
  is a non zero finite number number, find $n$ where $n\in\mathbb{N}$

$$\lim_{x\to 0}\frac{\cos^2x-\cos x-e^x\cos x+e^x-\frac{x^3}{2}}{x^n}=\lim_{x\to 0}\frac{(\cos x-e^x)(\cos x-1)-\frac{x^3}{2}}{x^n}=\lim_{x\to 0}\frac{x^2(\cos x-e^x)\frac{(\cos x-1)}{x^2}-\frac{x^3}{2}}{x^n}$$
Since $\lim_{x\to 0}\frac{(\cos x-1)}{x^2}=-\frac{1}{2}$
$$\implies \lim_{x\to 0}\frac{x^2(\cos x-e^x)\frac{(\cos x-1)}{x^2}-\frac{x^3}{2}}{x^n}=\lim_{x\to 0}\frac{-\frac{x^2}{2}(\cos x-e^x)-\frac{x^3}{2}}{x^n}$$
Since $\cos x$ is $1$ when $x$ tends to zero,
$$\lim_{x\to 0}\frac{-\frac{x^2}{2}(\cos x-e^x)-\frac{x^3}{2}}{x^n}=\lim_{x\to 0}\frac{-\frac{x^2}{2}(1-e^x)-\frac{x^3}{2}}{x^n}$$
Since $\frac{1-e^x}{x}$ tends to $-1$ when $x\to 0$, 
$$\lim_{x\to 0}\frac{-\frac{x^2}{2}(1-e^x)-\frac{x^3}{2}}{x^n}=\lim_{x\to 0}\frac{\frac{x^2}{2}x-\frac{x^3}{2}}{x^n}$$
Isnt the answer $n=3$? Answer given is $n=4$
 [/INST] You can't replace $(1-\cos x)/x^2$ with $1/2$. This can only be done for a “global factor”, not for a summand in a longer expression.
Consider, for instance,
$$
\lim_{x\to0}\frac{x-\sin x}{x^n}=
\lim_{x\to0}\frac{x\left(1-\dfrac{\sin x}{x}\right)}{x^n}
$$
where you can't replace $\sin x/x$ with $1$.

Apply l’Hôpital as many times as needed, under the assumption you continue to get an indeterminate form; consider
\begin{align}
f(x)&=\cos^2x-\cos x-e^x\cos x+e^x-\frac{x^3}{2} && f(0)=0 \\
f'(x)&=-2\sin x\cos x+\sin x-e^x\cos x+e^x\sin x+e^x-\frac{3x^2}{2} && f'(0)=0 \\[4px]
f''(x)&=-2\cos2x+\cos x+2e^x\sin x+e^x-3x && f''(0)=0 \\[8px]
f'''(x)&=4\sin2x-\sin x+2e^x\sin x+2e^x\cos x+e^x-3 && f'''(0)=0 \\[8px]
f''''(x)&=8\cos2x-\cos x+4e^x\cos x+e^x && f''''(0)=12
\end{align}
So, for $0\le n<4$, the limit is $0$; if $n=4$, the limit is $1/2$.
You can also compute the Taylor expansion, but I'm not sure that in this case it's shorter.
</s>