Analyzing limits problem Calculus (tell me where I'm wrong). I came accross: $$\lim_{x \to\ 0}\frac{x\cos x - \log (1 + x)}{x^{2}}$$
I tried the following please tell me where I 'm wrong:
$$\lim_{x \to\ 0}\frac{x\cos x - \log (1 + x)}{x^{2}} $$
$$\text{(Dividing by }x)$$ 
$$=\displaystyle\lim_{x \to\ 0}\dfrac{ \cos x - \dfrac{\log (1 + x)}{x}}{x} $$
$$=\lim_{x \to\ 0}\frac{\cos x - 1}{x} $$
$$=\lim_{x \to\ 0}\frac{-2\sin^{2} \dfrac{x}{2}}{x} $$
$$=\lim_{x \to\ 0}\frac{-2x\sin^{2}\dfrac{x}{2}}{(\dfrac{x}{2})^{2}\times 4} $$
$$\lim_{x \to\ 0}\dfrac{-x}{2}=0$$
But Answer given is $\dfrac{1}{2}$
Please Help.
 A: $\frac{\log(1+x)}{x}\neq 1$ it's undefined. And you can not directly take limit for only one part inside .
A: With l'Hospital:
$$\lim_{x\to0}\frac{x\cos x-\log(1+x)}{x^2}\stackrel{\text{l'H}}=\lim_{x\to0}\frac{\cos x-x\sin x-\frac1{1+x}}{2x}\stackrel{\text{l'H}}=$$
$$=\lim_{x\to0}\frac{-2\sin x-x\cos x+\frac1{(1+x)^2}}2=\frac{-0-0+1}2=\frac12$$
With Taylor series:
$$\frac{x\cos x-\log(1+x)}{x^2}=\frac1{x^2}\left(x-\frac{x^3}2+\ldots -x+\frac{x^2}2-\frac{x^3}3\ldots\right)=\frac12-\frac56 x+\ldots\xrightarrow[x\to0]{}\frac12$$
A: The mistake is simple and somewhat common for beginners. The fact is that when you are evaluating the limit of a complex expression (i.e. consisting of many sub-expressions which are somewhat simple individually) then in general it is not possible to replace a sub-expression by its limit in a step during overall evaluation of limit.
Thus when you replace the sub-expression $(\log(1 + x))/x$ with its limit $1$ as $x \to 0$ you have done something wrong. This is not permitted by any of rules of limits.
However there are two situations when it is permitted to replace a sub-expression by its limit. Let $C$ be a complicated expression whose limit as $x \to a$ needs to be evaluated. And let $S$ be one of the simple sub-expressions in $C$ whose limit as $x \to a$ is already known to be $L$.
1) You can replace sub-expression $S$ by its limit $L$ if the whole expression $C$ can be written as $C = R \pm S$ where $R$ is (rest of the) expression obtained when you literally remove $S$ from $C$. I call this situation as $S$ occurs in additive manner in the overall expression $C$.
2) You can replace sub-expression $S$ by its limit $L$ if $L \neq 0$ and if the whole expression $C$ can be written as $C = R \times S$ or $C = R/S$ where $R$ is (rest of the) expression obtained when you literally remove $S$ from $C$. I call this situation as $S$ occurs in multiplicative manner in the overall expression $C$. Also note that in this case $L$ must be non-zero. If $L = 0$ then you are out of luck.
These rules are almost always used (perhaps without knowing that such rules exist) during evaluation of a limit in step by step fashion. The best part about these two rules is that the replacement of $S$ by its limit $L$ is done without knowing anything about the rest of expression $R$. The replacements are valid irrespective of the fact that $R$ has a limit or not.
In the current question $$C = \dfrac{\cos x - \dfrac{\log(1 + x)}{x}}{x}, S = \frac{\log(1 + x)}{x}, L = 1$$ and when we remove $S$ from $C$ literally we get $$R = \frac{\cos x}{x}$$ Clearly we don't have $C = R \pm S$ or $C = R/S$ or $C = R\times S$ and hence it is not possible to replace $S$ by its limit $L = 1$.
At the same time if we write $C$ as $$C = \frac{\log(1 + x)}{x}\cdot\dfrac{\dfrac{x\cos x}{\log(1 + x)} - 1}{x}$$ then we can replace the first factor by $L = 1$ and $$R = \dfrac{\dfrac{x\cos x}{\log(1 + x)} - 1}{x}$$ and it is sufficient to calculate limit of $R$ and multiply it by $L$ to get the answer. However such a split does not help us because the expression $R$ does not seem to be any simpler compared to original $C$.

Note: The rules which I have mentioned above for replacing sub-expressions by their limits are something which I have explicitly written in my blogs and many answers on MSE. I have myself not found them in any textbooks but at the same time I have seen many solved examples in various textbooks which make use of these rules implicitly. They are easy to prove and I found it worthwhile to mention them explicitly for benefit of readers so that at least they can avoid the replacements which are not valid. A more formal version of these rules along with proofs is discussed in this question. 
A: we have $$cos(x)-1=\cos(x/2)^2-\sin(x/2)^2-1=-2\sin(x/2)^2-1$$
