Prove $g(x+h) = g(x) + hg'(x) + \frac{1}{2} h^2 g''(x) + o(h^2)$ from definition of limit I want to prove $g(x+h) = g(x) + hg'(x) + \frac{1}{2} h^2 g''(x) + o(h^2)$ from the definition of limit, where x is a 1D variable, $o(h)$ is a quantity that depends on scalar h negligible compared to h as h goes to zero i.e. a small quantity
Attempt:
Recall definition of limit
$$\lim_{h\to 0} |\frac{g(x+h) - g(x) - hg'(x)}{h}| = |\frac{o(h)}{h}|$$
which turns into a more familiar form
$$\lim_{h\to 0}  |\frac{g(x+h) - g(x)}{h}| = g'(x)$$
Conclusion 
$$g(x+h) - g(x) = hg'(x) + o(h)$$
Taking a derivative wrt $x$ in above expression ields
$$g'(x+h) - g'(x) = hg''(x)$$
Sub in definition of derivative for both LHS terms
$$g(x+h^2) - g(x+h) - g(x+h) + g(x) = h^2 g''(x) + ho(h)$$
Therefore
$$g(x+h^2) = g(x) + 2hg'(x) + h^2 g''(x) + o(h^2)$$
dividing a 2 across
$$\frac{g(x+h^2)}{2}  = \frac{g(x)}{2} + hg'(x) + \frac{1}{2} h^2g''(x) + o(h^2)$$
which is not quite...
$$g(x+h) = g(x) + hg'(x) + \frac{1}{2} h^2 g''(x) + o(h^2)$$
the desired result
Can someone show me how to prove this?
 A: We have
\begin{align}
L &= \lim_{h \to 0}\frac{g(x + h) - g(x) - hg'(x)}{h^{2}}\notag\\
&= \lim_{h \to 0}\frac{g'(x + h) - g'(x)}{2h}\text{ (by L'Hospital's Rule)}\notag\\
&= \frac{g''(x)}{2} \text{ (by definition of }g''(x))\notag\\
\end{align}
and hence $$\lim_{h \to 0}\dfrac{g(x + h) - g(x) - hg'(x) - \dfrac{h^{2}}{2}g''(x)}{h^{2}} = 0\tag{1}$$ i.e. $$g(x + h) = g(x) + hg'(x) + \frac{h^{2}}{2}g''(x) + o(h^{2})$$

Without the use of L'Hospital's rule the proof is a bit difficult. Idea is to consider the function $$f(h) = g(x + h) - g(x) - hg'(x) - \frac{h^{2}}{2}\{g''(x) - \epsilon\}$$ for any arbitrary $\epsilon > 0$. Clearly we have $f(0) = f'(0) = 0$ and $$f'(h) = g'(x + h) - g'(x) - h\{g''(x) - \epsilon\}$$ so that $f''(0) = \epsilon > 0$. Hence $f'(h) > 0$ in some neighborhood $(0, \delta_{1})$. Clearly this implies that $f(h) > 0$ in some neighborhood $(0, \delta_{1})$. Thus for any $\epsilon > 0$ we have found a $\delta_{1} > 0$ such that $f(h) > 0$ whenever $0 < h < \delta_{1}$. In other words we have $$\dfrac{g(x + h) - g(x) - hg'(x) - \dfrac{h^{2}}{2}g''(x)}{h^{2}} > -\epsilon\tag{2}$$ Considering the function $$p(h) = g(x + h) - g(x) - hg'(x) - \frac{h^{2}}{2}\{g''(x) + \epsilon\}$$ we can find a $\delta_{2} > 0$ such that $$\dfrac{g(x + h) - g(x) - hg'(x) - \dfrac{h^{2}}{2}g''(x)}{h^{2}}  < \epsilon\tag{3}$$ whenever $0 < h < \delta_{2}$. From $(2)$ and $(3)$ it follows that $$\lim_{h \to 0^{+}}\dfrac{g(x + h) - g(x) - hg'(x) - \dfrac{h^{2}}{2}g''(x)}{h^{2}} = 0$$ Similarly we can treat $h \to 0^{-}$ and thus establish the limit equation $(1)$.
In both the proofs above we have only used the fact that $g''(x)$ exists. Also note that $x$ is a fixed point and the variable being used for limit considerations is $h$ and it would have been more suitable to state the result replacing $x$ with a variable like $a$ or $c$. The result can be generalized for $n^{\text{th}}$ order derivative also (with similar proofs as given above).
If $f^{(n)}(a)$ exists then $$f(a + h) = f(a) + hf'(a) + \frac{h^{2}}{2!}f''(a) + \cdots + \frac{h^{n}}{n!}f^{(n)}(a) + o(h^{n})$$ as $h \to 0$.
Some people refer to the above result by the name Taylor's Theorem with Peano's form of remainder and this version of Taylor's theorem is the one which requires the least amount of conditions on the function $f$ involved.
A: Note that in the third line of your derivation, $O$ is not a function. In a more exact sense, one could argue that it depends on $x$ as well as $h$ so that your fourth line is driven invalid. To obtain your desired result, you should note that $$\mathop {\lim }\limits_{h \to 0} \left( {\frac{{g(x + h) - g(x)}}{h} - g'(x)} \right) = \mathop {\lim }\limits_{h \to 0} \left( {\frac{{g'(x + h)}}{1} - g'(x)} \right) = 0$$where we have used L'Hopital's rule in obtaining the R.H.S. and have assumed the continuity of $g'(x)$. In a similar fashion, we have $$\begin{array}{l}\mathop {\lim }\limits_{h \to 0} \left( {\frac{{\frac{{g(x + h) - g(x)}}{h} - g'(x)}}{h}} \right) = \mathop {\lim }\limits_{h \to 0} \left( {\frac{{g(x + h) - g(x) - hg'(x)}}{{{h^2}}}} \right) = \\\mathop {\lim }\limits_{h \to 0} \left( {\frac{{g'(x + h) - g'(x)}}{{2h}}} \right) = \mathop {\lim }\limits_{h \to 0} \left( {\frac{{g''(x + h)}}{2}} \right)\end{array}$$Also note that continuity of $g''(x)$ could be implied using $$g''(x + h) = g''(x) + O(h)$$Could you see the last step?
