In this section, we consider specific series whose terms depend on a real number \(x\). If such a series \(\sum a_n(x)\) converges for all values of \(x\) within an interval \((a,b) \subset {\mathbb{R}}\), we can think of this series as representing a function \(f: (a,b) \to {\mathbb{R}}\), where \(f(x)\) is defined to be the sum of \(\sum a_n(x)\). Examples of such series are power series and Fourier series. We are investigating in this course the former.
Series of the form \(P(x) = \sum_{n=0}^\infty b_n x^n\) are called power series. (Geometric series, arithmetico-geometric series containing the variable \(x\) are examples of power series.) We refer to \(b_0, b_1, b_2, \dots\) as the coefficients of the power series \(P(x)\).
As with geometric series in particular, we generally expect such a series to converge for some range of values of \(x\) near 0.
When the series converges, the partial sums \(P_K(x)=\sum_{n=0}^{K-1} b_n x^n\) will be increasingly good approximations of \(P(x)\). This provides a useful approach to calculating and studying functions that can be written as power series. For example, we saw for the geometric series \(\sum_{n=0}^\infty x^n = \frac{1}{1-x}\), so e.g. \(1 + x + x^2\) can be used as an approximation of \(\frac{1}{1-x}\).
Convergence of power series
To find the range of \(x\) for which a power series \(P(x) = \sum b_n x^n\) converges absolutely, we use the ratio test: \[\rho = \lim_{n \to \infty} \left| \frac{b_{n+1} x^{n+1} }{b_n x^n} \right| = |x| \lim_{n \to \infty} \left| \frac{b_{n+1} }{b_n} \right|,\] so if \(\lim_{n \to \infty} \left| \frac{b_{n+1} }{b_n} \right| = 0\), the sum converges absolutely for all \(x \in {\mathbb{R}}\), while if \(\lim_{n \to \infty} \left| \frac{b_{n+1} }{b_n} \right| = c >0\), it converges absolutely for \(|x| < \frac{1}{c}\), and diverges for \(|x| > \frac{1}{c}\). Nota bene: convergence at the endpoints \(|x| = \frac{1}{c}\) needs to be considered separately. We call the region where the series converges the interval of convergence. Be also aware that the ratio test is not always successful for the determination of the interval of convergence, for example, if \(\lim_{n \to \infty} \vert \frac{b_{n+1}}{b_n} \vert\) does not exist.
Examples:
Geometric series \(P(x) = \sum_{n=0}^\infty x^n = \frac{1}{1-x}\). Here \(b_n=1\), so \(\frac{b_{n+1}}{b_n} = 1\), and the series converges for \(|x| < 1\), as we said previously.
\(P(x) = e^x = \sum_{n=0}^\infty \frac{1}{n!} x^n\). Here \(b_n = \frac{1}{n!}\), so \(\lim_{n \to \infty} \left| \frac{b_{n+1} }{b_n} \right| = \lim_{n \to \infty} \frac{n!}{(n+1)!} = \lim_{n \to \infty} \frac{1}{n+1} = 0\), so \(P(x)\) converges for all \(x\).
For the geometric series, we see that the function \(\frac{1}{1-x}\) diverges at one end of the interval of convergence. For real series, this connection is not universal, but it is if we generalise to a complex argument, to consider the complex power series \[P(z) = \sum_{n=0}^\infty b_n z^n.\] If \(\lim_{n \to \infty} \left| \frac{b_{n+1} }{b_n} \right| = c >0\), this converges absolutely for \(|z| < 1/c\), that is, within a circle in the complex plane. We call \(1/c\) the radius of convergence. We have the following general fact, which holds always:
FACT: Any real- or complex-valued power series \(P(z) = \sum b_n z^n\) has a radius of convergence, that is, a value \(r \in [0,\infty]\), such that \(P(z)\) converges absolutely for all \(|z| < r\) and diverges for all \(|z| > r\). The convergence/divergence behaviour of \(P(z)\) in the circle \(|z|=r\) is not clear and needs to be investigated separately. Note, however, that the radius of convergence \(r\) cannot be always derived via the ratio test, there are power series for which the ratio test is inconclusive.
In the setting of complex-valued power series representing a function \(P(z)\) within a circle of radius \(r\), where \(r\) is the radius of convergence, it is another general fact that \(P(z)\) may be extended continuously beyond the domain \(|z|<r\), but there will always be at least one point on the circle of radius \(r\), at which this extension is not well defined, that is, has a singularity. In the case of the function \(f(z) = \frac{1}{1-z} = \sum z^n\), this singularity is at a real value and lies at the point \(z=1 \in {\mathbb{C}}\).
Example: If we take the geometric series and if we set \(z = -w^2\), we get \[P(w) = \sum_{n=0}^\infty (-w^2)^n = \sum_{n=0}^\infty (-1)^n w^{2n} = \frac{1}{1+w^2}.\] This complex-valued series converges for \(|w| <1\), since it is a geometric series in \(-w^2\) and converges therefore for \(|w|^2 = |-w^2| <1\), and it has singularities at \(w = \pm i\) on the circle \(|w|=1\).
Integrating and differentiating power series: The derivative or integral of a power series \(P(x)\) with respect to \(x\) will have the same radius of convergence. (Unlike for general series, where we don’t always know how differentiation and integration affect convergence.)
This can be confirmed in the case of a power series, for which the ratio test is successful: Then the series \(P(x) = \sum_{n=0}^\infty b_n x^n\) is (absolutely) convergent for \(|x| < 1/c\), where \(c = \lim_{n \to \infty} \left| \frac{b_{n+1} }{b_n} \right|\). The derivative \(P'(x) = \sum_{n=1}^\infty n b_n x^{n-1}\) is then convergent for \(|x| < 1/c'\) with \[c' = \lim_{n \to \infty} \left| \frac{(n+1) b_{n+1} }{n b_n} \right|.\] Note that \[c' = \lim_{n \to \infty} \frac{(n+1)}{n } \lim_{n \to \infty} \left| \frac{b_{n+1} }{ b_n} \right| = \lim_{n \to \infty} \left| \frac{b_{n+1} }{ b_n} \right| = c,\] which is the same condition as for \(P(x)\), and \(P'(x)\) has therefore the same radius of convergence. Similarly, the integral \[\int P(x) dx = \left( \sum_{n=0}^\infty \frac{1}{n+1} b_n x^{n+1} \right) + c\] is (absolutely) convergent for \(|x| < c''\), where \[c'' = \lim_{n \to \infty} \left| \frac{(n+1) b_{n+1} }{(n+2) b_n} \right|,\] but \[c'' = \lim_{n \to \infty} \frac{n+1}{n+2 } \lim_{n \to \infty} \left| \frac{b_{n+1} }{ b_n} \right| = \lim_{n \to \infty} \left| \frac{b_{n+1} }{ b_n} \right| = c,\] which is again the same condition as for \(P(x)\), and hence it has also the same radius of convergence.
Let us now discuss a slight generalisation of power series, which we will encounter often. Up to now, all our power series were of the form \(P(x) = \sum b_n x^n\). They can be also written as \[P(x) = \sum_{n=0}^\infty b_n (x-0)^n,\] and it is important to consider also more general power series of the form \[P(x) = \sum_{n=0}^\infty b_n (x-a)^n,\] where \(a \in {\mathbb{R}}\) is a fixed real value. Similarly, one can employ the ratio test to find the radius of convergence \(r = 1/c\) with \[c = \lim_{n \to \infty} \vert \frac{b_{n+1}}{b_n} \vert,\] if the limit exists. However, the interval of convergence will be shifted to be the region \((a-r,a+r)\) plus, potentially, one or both of the end-points of this interval.
Finally, we sometimes use manipulations of power series to obtain new power series. For example: Let \(P(x) = \sum_{n=0}^\infty b_n x^n\) be a power series and let \(x = 1+y^2\). Then \[P(1+y^2) = \sum_{n=0}^\infty b_n (1+y^2)^n\] is again a power series in \(y\), namely, \[\begin{gathered} P(1+y^2) = b_0 + b_1 (1+y^2) + b_2 (1+y^2)^2 + b_3 (1+y^2)^3 + \cdots \\ = b_0 + b_1 + b_1 y^2 + b_2 + 2 b_2 y^2 + b_2 y^4 + b_3 + 3 b_3 y^2 + 3 b_3 y^4 + b_3 y^6 + \cdots \\ = (b_0 + b_1 + b_2 + b_3 + \cdots) + (b_1 + 2b_2 + 3b_3 + \cdots) y^2 + (b_2 + 3 b_3 + \cdots) y^4 + (b_3 + \cdots) y^6 \\ =: c_0 + c_2 y^2 + c_4 y^4 + c_6 y^6 \cdots \end{gathered}\] with new coefficients \(c_0,c_2,c_4,c_6,\dots\), which are (infinite) expressions in the original coefficients \(b_0,b_1,b_2,b_3,\dots\).
We have seen a couple of functions that are equal to a power series. Now we want to show that this is generic; any appropriately differentiable function \(f(x)\) has a power series representation, called a Taylor series. We build this up by progressively refined polynomial approximations of \(f(x)\) near a point \(x=a\). The Taylor series is useful because in the interval of convergence, the polynomial partial sums will provide a useful approximation to \(f(x)\), which are usually much easier to work with than the actual function \(f(x)\) itself.
How can we obtain such an approximation? For a function \(y=f(x)\), we can plot its graph in the \((x-y)\)-plane. We want to approximate the graph by something simple. The simplest graph is a line. We can then approximate the graph of \(f\) at a point \(a\) by taking the tangent at \(a\). The slope of this tangent line is of course the derivative \(f'(x)\), and the equation for the line is \[y=f(a) + f'(a)(x-a).\] This is a first approximation of \(f\) and it is called the first Taylor polynomial \(p_{1}(x)\).
Why is it a “good” approximation? Well, the error is \[f(x)-p_{1}(x)=f(x)-f(a)-f'(a)(x-a)=(x-a)\underbrace{\left(\frac{f(x)-f(a)}{x-a}-f'(a)\right)}_{\to0\text{ as }x\to a}.\] So, as we approach the point \(x=a\), the error goes to \(0\).
We now want to find better approximations, so-called “higher” Taylor polynomials \(p_{2}(x),p_{3}(x),\dots\) such that for each \(n\) \[\frac{f(x)-p_{n}(x)}{(x-a)^{n}}\longrightarrow0\text{ as }x\longrightarrow a.\] We write \(f(x) = f(a) + \int_a^x f'(y) dy\), and use a first-order approximation for \(f'(y)\), \[f'(y) \approx f'(a) + (y-a) f''(a)\] Integrating this gives \[\begin{gathered} f(x) = f(a) + \int_a^x f'(y) dy \approx f(a) + \int_a^x [f'(a) + (y-a) f''(a)] dy \\ = f(a) + (x-a) f'(a) + \frac{1}{2} (x-a)^2 f''(a).\end{gathered}\] This gives the second-order Taylor polynomial \[p_2(x) = f(a) + (x-a) f'(a) + \frac{1}{2} (x-a)^2 f''(a).\] This is a better approximation in that it also matches the second derivative of \(f(x)\) at \(a\).
The Taylor polynomials are approximations to \(f(x)\), which are good near the base point \(a\). Note the dependence on \(a\), which is crucial; we will often consider expansions around 0 for simplicity, but not always!
We can continue to improve the approximation in the same way: in general the Taylor polynomial of degree \(N\) for \(f(x)\) about \(x=a\) is \[p_{N,a}(x) = f(a) + (x-a) f'(a) + \frac{1}{2} (x-a)^2 f''(a) + \frac{1}{3!} (x-a)^3 f'''(a) + \ldots + \frac{1}{N!} (x-a)^N f^{(N)}(x).\] we also write \[p_{N,a}(x) = \sum_{n=0}^N \frac{(x-a)^n}{n!} f^{(n)} (a),\] where we use the convention \(0! = 1\). This is constructed to match the first \(n\) derivatives of \(f(x)\) at \(x=a\). (Note that we use the notation \(f^{(n)}(x)\) for the \(n\)-th derivative of \(f(x)\).)
Examples:
For \(f(x) = e^x\), \(f' = f'' = \ldots = e^x\), so we obtain \[p_{n,0}(x) = 1 +x + \frac{1}{2} x^2 + \frac{1}{3!}x^3 + \ldots + \frac{1}{n!} x^n.\]
For \(f(x) = \sin x\), \(f' = \cos x\), \(f'' = - \sin x\), \(f''' = - \cos x\), so we obtain \[p_{3,0}(x) = \sin(0) + \cos(0) x - \frac{1}{2} \sin(0) x^2 - \frac{1}{3!} \cos(0) x^3 = x - \frac{1}{3!} x^3\] \(\sin(x)\) is an odd function, which is why we only get odd powers in the Taylor polynomial.
For \(f(x) = \ln x\), \(f' = \frac{1}{x}\), \(f'' = - \frac{1}{x^2}\), \(f''' = \frac{2}{x^3}\), \(f^{(4)} = - \frac{6}{x^4}\), etc. Let’s calculate \(p_{4,1}(x)\): \(f(1) = 0\), \(f'(1) = 1\), \(f''(1) = -1\), \(f'''(1) = 2\), \(f^{(4)}(1) = -6\), so we obtain \[\begin{gathered} p_{4,1}(x) = f(1) + (x-1) f'(1) + \frac{1}{2} (x-1)^2 f''(1) + \frac{1}{3!} (x-1)^3 f'''(1) \\ + \frac{1}{4!} (x-1)^4 f^{(4)}(1) = (x-1) - \frac{1}{2} (x-1)^2 + \frac{1}{3} (x-1)^3 - \frac{1}{4} (x-1)^4. \end{gathered}\] Note that we couldn’t define a polynomial approximation to \(\ln x\) at \(x=0\), as it is not differentiable there.
A special case is where \(f(x)\) is a polynomial: suppose \(f(x)=x^{2}+2x+1\) and \(a=0\). Then \[\begin{aligned} f(a)=1\\ f'(a)=2 & & p_{1}(x)=1+2x\\ f''(a)=2 & & p_{2}(x)=1+2x+\frac{2x^{2}}{2}=f(x)\\ f^{(3)}(a)=0 & & p_{3}(x)=p_{2}(x)\\ \cdots=0 & & \vdots\\ \cdots=0 & & p_{N}(x)=p_{2}(x).\end{aligned}\] In general, the \(N\)-th Taylor polynomial of a polynomial function \(f(x)\) of degree \(n\) will eventually (for \(N\ge n\)) be the polynomial \(f(x)\) itself.
The Taylor series is the power series \(P_a(x) = \lim_{n \to \infty} p_{n,a}(x)\). This is defined if \(f(x)\) is infinitely differentiable at \(x=a\). In most cases, but not always, agrees \(P_a(x)\) with \(f(x)\) within the interval of convergence of the power series. When this is the case, we say that \(f(x)\) is an analytic function near \(a\). In this course, we will be only concerned with analytic functions, that is, all our Taylor series will match the original functions within their interval of convergence.
For an analytic function \(f(x)\), we can therefore write \[f(x) = \sum_{n=0}^\infty \frac{1}{n!} (x-a)^n f^{(n)}(a),\] which holds for all \(x\) in the interval of convergence. A Taylor series about \(a=0\) is also called a McLaurin series.
Examples:
\(e^x = \sum_{n=0}^\infty \frac{x^n}{n!}\).
\(\sin(x) = \sum_{n=0}^\infty \frac{(-1)^n}{(2n+1)!} x^{2n+1}\).
Note that these power series converge absolutely for all \(x\in\mathbb R\). By contrast, the Taylor series for \(\ln(1+x)\) does not converge everywhere: \[\ln(1+x)=\sum_{n=1}^{\infty}\frac{(-1)^{n+1}}{n}x^{n}.\] For convergence, the ratio test yields \[\left|\frac{\frac{(-1)^{n+2}}{(n+1)}x^{n+1}}{\frac{(-1)^{n+1}}{n}x^{n}}\right|=|x|\cdot\frac{n}{(n+1)}\longrightarrow|x|,\] so this power series converges (absolutely) for \(|x|<1\). For \(|x|>1\) it diverges and its polynomial partial sums are therefore no longer a good approximation for \(|x| > 1\).
The key result in this subsection is a bound on the error in the approximation \(f(x) \approx p_{N,a}(x)\). This error bound is obtained by a careful analysis of a so-called remainder term. The precise statement reads as follows:
Taylor’s theorem: If \(f(x)\) is differentiable \(N+1\) times in a neighbourhood of \(a\), \(x\) is a point in this neighbourhood, and \(f^{(N+1)}\) is continuous between \(a\) and \(x\), then \[f(x) = p_{N,a}(x) + R_{N+1,a}(x),\] where \(p_{N,a}(x)\) is the \(N\)th Taylor polynomial for \(f(x)\) around \(a\), and \(R_{N+1,a}(x)\) is the \(N\)th remainder term \[R_{N+1,a}(x) = \frac{f^{(N+1)}(\xi)}{(N+1)!} (x-a)^{N+1}\] for some value \(\xi\) in the interval between \(a\) and \(x\).
We will not prove this result, but we will use it to compute error bounds. Before doing so, let us provide a few remarks:
This expression for \(R_{n+1,a}(x)\) is also known as the Lagrange form of the remainder.
It is reasonable that the remainder term \(R_{n+1,a}(x)\) involves \(f^{(n+1)}\); if it happened that the function \(f(x)\) was actually a polynomial of degree \(n\), \(p_n(x)\) would be precisely equal to \(f(x)\), and \(f^{(n+1)}\) and hence also the remainder term would vanish.
Since the remainder term involves \((x-a)^{n+1}\), it is smaller for \(x\) near \(a\), and typically smaller for larger \(n\), as long as \(|x-a|<1\).
We cannot explicitly calculate the remainder term, as it involves some point \(\xi \in (a,x)\), and the theorem doesn’t tell us which point we need to use (The point \(\xi\) will depend on \(f\), \(n\), \(a\), and \(x\).) But we may be able to bound it: If \(|f^{n+1}(\xi)| \le M\) for all \(\xi \in (a,x)\), then \[R_{n+1,a}(x) \le \frac{M}{(n+1)!} (x-a)^{n+1} .\] The point of Taylor’s theorem is to use such bounds to bound the error in a given polynomial approximation to a function, and thus to find an approximation of a desired accuracy.
Example: Find a Taylor polynomial approximation to \(\cos(0.5)\) accurate to \(\pm0.01\).
We take \(f(x) = \cos x\), so \(f' = \sin x\), \(f'' = -\cos x\), \(f''' = -\sin x\), \(f^{(4)} = \cos x\) etc. Consider an expansion around \(x=0\), since we can evaluate the derivatives there: \(f(0) = 1\), \(f'(0) = 0\), \(f''(0) = -1\), \(f'''(0) = 0\), etc. The simplest approximation is \(p_1(x) = f(0) + x f'(0)= 1\); this is probably not going to meet our accuracy target though. Indeed, \(R_2(x) = \frac{1}{2} f''(\xi) x^2\), so \(R_2(0.5) = -\frac{1}{8} \cos \xi\). All we can say about \(\cos \xi\) is that it takes values in \([-1,1]\), so we know that \(|R_2(0.5)| \le 1/8\), but we wanted a smaller error. The next Taylor polynomials are \(p_2(x) = p_3(x) = 1- \frac{1}{2} x^2\). This leads to an error \[R_{4}(0.5) = \frac{f^{(4)}(\xi)}{4!} (0.5)^4 = 0.0026 \cos \xi\] for some \(\xi \in (0,0.5)\), so \(|R_4(0.5)| \le 0.0026\), and \(p_3\) is a good enough approximation: \[\cos(0.5) \approx p_3(0.5) = 1 - \frac{1}{2} (0.5)^2 = 0.875,\] up to an error which is at most \(0.0026\).
Example: For \(f(x) = e^{\cos x}\), find \(p_2(x)\) about \(x=\frac{\pi}{2}\), and bound the error in this estimate.
Using the chain rule, we find \[\begin{aligned} f'(x) &= - \sin x e^{\cos x}, \quad f'(\frac{\pi}{2}) = -1, \\ f''(x) &= (-\cos x + \sin^2 x) e^{\cos x}, \quad f''(\frac{\pi}{2}) = 1, \\ f'''(x) &= (\sin x + 3 \sin x \cos x - \sin^3 x) e^{\cos x}, \end{aligned}\] so \[p_{2,\frac{\pi}{2}}(x) = 1 - (x-\frac{\pi}{2}) + \frac{1}{2} (x-\frac{\pi}{2})^2,\] with remainder term \[R_3(x) = e^{\cos \xi} (\sin \xi + 3 \sin \xi \cos \xi - \sin^3 \xi) \frac{(x- \frac{\pi}{2})^3}{3!},\] for some \(\xi \in (\frac{\pi}{2},x)\).
To bound the error, we use \(|\cos \xi| < 1\), so \(e^{\cos \xi} <e\); for the term in \(\sin \xi + 3 \sin \xi \cos \xi - \sin^3 \xi\), we can obtain different bounds depending on how much simplification we do. We can simply say each of the trigonometric functions is \(\le 1\) in absolute value, so \[|\sin \xi + 3 \sin \xi \cos \xi - \sin^3 \xi| \le | \sin \xi | + 3 | \sin \xi \cos \xi | + |\sin \xi|^3 \le 5.\] Alternatively, we could simplify \[\sin \xi + 3 \sin \xi \cos \xi - \sin^3 \xi = \sin \xi \cos^2 \xi + 3 \sin \xi \cos \xi,\] which leads to the bound \(\le 4\) in absolute value, or further simplify \[\sin \xi \cos^2 \xi + 3 \sin \xi \cos \xi = \frac{1}{2} \sin 2\xi (\cos \xi + 3),\] so end up with the bound \[\left| \frac{1}{2} \sin 2\xi (\cos \xi + 3) \right| \le \frac{1}{2} |\sin 2\xi| \cdot (|\cos \xi| + 3) \le 2\] Therefore \[|R_3(x)| = |e^{\cos \xi}| \cdot \left|\frac{1}{2} \sin 2\xi (\cos \xi + 3)\right| \cdot \frac{|x- \frac{\pi}{2}|^3}{3!} < \frac{e}{3} \left|x- \frac{\pi}{2}\right|^3.\]
We can use Taylor series to evaluate limits \[\lim_{x\to a} \frac{f(x)}{g(x)}\] where \(f(x)\), \(g(x)\) are regular at \(a\). We write the functions in their Taylor series about \(a\), \[f(x) = \sum_{n=0}^\infty a_n(x-a)^n, \quad g(x) = \sum_{n=0}^\infty b_n (x-a)^n.\] Suppose the first non-zero coefficients are \(a_N\), \(b_M\), so \(f(x) = a_N (x-a)^N + \cdots\), \(g(x) = b_M (x-a)^M + \cdots\). Then \[\lim_{x\to a} \frac{f(x)}{g(x)} = \lim_{x\to a} \frac{(x-a)^N}{(x-a)^M}\cdot\frac{a_N + a_{N-1} \frac{1}{x-a}+ \cdots }{b_M + b_{M-1} \frac{1}{x-a}+ \cdots} = \lim_{x\to a} \frac{a_N}{b_M} (x-a)^{N-M},\] so if \(N > M\), \(\lim_{x\to a} \frac{f(x)}{g(x)} =0\), if \(N < M\), \(\lim_{x\to a} \frac{f(x)}{g(x)}\) does not exist, and if \(N=M\), \[\lim_{x\to a} \frac{f(x)}{g(x)} = \frac{a_N}{b_N} = \frac{f^{(N)}(a)}{g^{(N)}(a)} .\] The non-trivial limits are simply the ratio of the first non-zero coefficients in the Taylor series. This is clearly related to evaluating the limits via l’Hôpital’s rule; this provides another perspective on the use of l’Hôpital’s rule, and may be useful where we already know the Taylor series or can obtain it without explicitly evaluating the derivatives.
Examples:
Consider \(\lim_{x\to 0}\frac{\frac{x^2}{1-x}+2\cos{x}-2}{2x^3+3x^7}\). We know \(\frac{1}{1-x} = \sum_{n=0}^\infty x^n = 1 + x+ x^2 + \cdots\) and \[\cos x = \sum_{n even} \frac{(-1)^{n/2}}{n!} x^n = 1- \frac{1}{2} x^2 + \frac{1}{4!} x^4 + \ldots .\] Henceforth we use the following notation, with was introduced by the German mathematician Edmund Landau (1877-1938) :̃ We write \(o(x^n)\) to denote any function which vanishes faster than \(x^n\) as \(x\to 0\), so we can write \(\frac{1}{1-x} = 1 + x+ x^2 + o(x^2)\). Clearly \(x^m o(x^n)\) is an \(o(x^{n+m})\) function. Then \[\begin{gathered} \lim_{x\to 0}\frac{\frac{x^2}{1-x}+2\cos{x}-2}{2x^3+3x^7} \\ = \lim_{x\to 0}\frac{x^2 (1 + x+ x^2 + o(x^2) ) + 2 (1- \frac{1}{2} x^2 + \frac{1}{4!} x^4 + o(x^4) ) -2}{2x^3+3x^7} \\ = \lim_{x\to 0}\frac{ x^3 + \frac{11}{12} x^4 + o(x^4)}{2x^3+3x^7} = \frac{1}{2}. \end{gathered}\]
In more complicated cases, we can use the function of functions trick: consider \[f(x)=\exp\left(\frac{\sin x}{1-3x}\right)\] and calculate \[L := \lim_{x\to0}\frac{f(x)-(x+1)}{x\cos x-\ln(1+x)}.\]
First consider \(f(x)\) for \(x\) near \(0\) (\(|x|<1\)). From previous calculations, we can write \[\sin x=x-\frac{x^{3}}{3!}+o(x^{3}),\qquad\text{and}\qquad\frac{1}{1-3x}=1+3x+9x^{2}+27x^{3}+o(x^{3}),\] Thus \[\begin{aligned} \frac{\sin x}{1-3x} & =\left(x-\frac{x^{3}}{3!}+o(x^{3})\right)(1+3x+9x^{2}+27x^{3}+o(x^{3}))\\ & =x-\frac{x^{3}}{3!}+o(x^{3})+3x^{2}+9x^{3}+o(x^{3})\\ & =x+3x^{2}+\frac{53}{6}x^{3}+o(x^{3}).\end{aligned}\] We also know that \(e^{x}=1+x+\frac{x^{2}}{2}+\cdots\) and plugging in the above, we get \[\begin{aligned} f(x) & =1+x+3x^{2}+\frac{53}{6}x^{3}+o(x^{3})+\left(x+3x^{2}+\frac{53}{6}x^{3}+o(x^{3})\right)^{2}/2\\ & \quad+\left(x+3x^{2}+\frac{53}{6}x^{3}+o(x^{3})\right)^{3}/6+o(x^{3})\\ & =1+x+3x^{2}+\frac{53}{6}x^{3}+o(x^{3})+x^{2}/2+(2x\cdot3x^{2})/2+x^{3}/6+o(x^{3})\\ & =1+x+\frac{7}{2}x^{2}+12x^{3}+o(x^{3}).\end{aligned}\] To calculate the final limit, we also need to Taylor expand \(\cos x\) \(\ln(1+x)\) up to order \(3\): \[\cos x=1-\frac{x^{2}}{2}+o(x^{3}),\qquad\text{and}\qquad\ln(1+x)=x-\frac{x^{2}}{2}+\frac{x^{3}}{3}+o(x^{3}),\] so \(x\cos x-\ln(1+x)=\frac{x^{2}}{2}-\frac{5}{6}x^{3}+o(x^{3})\). Thus, \[L=\lim_{x\to 0}\frac{\frac{7}{2}x^{2}+12x^{3}+o(x^{3})}{\frac{x^{2}}{2}-\frac{5}{6}x^{3}+o(x^{3})}=\frac{\frac{7}{2}+12x+o(x)}{\frac{1}{2}-\frac{5}{6}x+o(x)}=\frac{7/2}{1/2}=7.\]