Solution (source code)

= Solution

One precise version of the <Taylor theorem with Lagrange remainder> is as follows. Let $n\geq0$, let $f$ and its <derivatives> through order $n$ be continuous on the closed interval between distinct points $a$ and $x$, and suppose $f^{(n+1)}$ exists throughout its interior. Then some $\xi$ strictly between $a$ and $x$ satisfies
$$
\boxed{f(x)=\sum_{k=0}^n\frac{f^{(k)}(a)}{k!}(x-a)^k
+\frac{f^{(n+1)}(\xi)}{(n+1)!}(x-a)^{n+1}.}
$$
Here the endpoint <derivatives> are understood as restrictions of derivatives defined near the interval, or as their continuous one-sided extensions. No continuity of $f^{(n+1)}$ is required. For $x=a$ the equality is immediate with zero remainder.

To prove the formula, write the <Taylor polynomial> as $P_n(t)=\sum_{k=0}^n f^{(k)}(a)(t-a)^k/k!$ and define
$$
K=\frac{f(x)-P_n(x)}{(x-a)^{n+1}},\qquad
h(t)=f(t)-P_n(t)-K(t-a)^{n+1}.
$$
Then $h(a)=h(x)=0$, and $h^{(j)}(a)=0$ for $j=1,\ldots,n$. The <Rolle theorem> gives a zero $\xi_1$ of $h'$ strictly between $a$ and $x$. If $n\geq1$, apply the <Rolle theorem> to $h'$ between $a$ and $\xi_1$, using $h'(a)=0$, to get a zero $\xi_2$ of $h''$. Repeating produces a point $\xi_{n+1}$ strictly between $a$ and $x$ with $h^{(n+1)}(\xi_{n+1})=0$. Each application is justified by continuity on the relevant closed interval and differentiability in its interior; the same construction works when $x<a$.

Since $P_n$ has degree at most $n$,
$$
0=h^{(n+1)}(\xi_{n+1})
=f^{(n+1)}(\xi_{n+1})-(n+1)!K.
$$
Substituting this value of $K$ into its definition proves the displayed <Taylor theorem with Lagrange remainder>.