# Chuỗi Taylor - Một cách dễ nhớ


<!-- The Taylor expansion is one of the most beautiful ideas in mathematics. The intuition is simple: most functions are smooth over ranges we’re interested in. And polynomials are also smooth. So for every smooth function, we should be able to write down a polynomial that approximates it pretty well. -->

**Khai triển Taylor** (Taylor expansion) xây dựng một đa thức có các đạo hàm tại điểm $c$ khớp với các đạo hàm tương ứng của hàm $f$. Nếu $f$ có đủ số đạo hàm gần $c$, đa thức Taylor bậc hữu hạn cho một xấp xỉ địa phương với sai số được mô tả bởi số dư Taylor.

<!-- And in fact, if our polynomial contains enough terms it will exactly equal the original function. Since polynomials are easier to work with than almost any other kind of function, this usually turns hard problems into easy ones. -->

Khi lấy vô hạn số hạng, ta thu được **chuỗi Taylor**, không còn là một đa thức. Chuỗi này chỉ bằng hàm ban đầu tại những điểm mà chuỗi hội tụ đến chính $f$. Điều kiện $f\in C^\infty$ chưa đủ để bảo đảm điều đó; những hàm thỏa tính chất này được gọi là hàm giải tích. Dù không dùng chuỗi vô hạn, đa thức Taylor bậc hữu hạn vẫn hữu ích vì đa thức thường dễ tính toán hơn hàm ban đầu.

<!-- The Taylor formula is the key. It gives us an equation for the polynomial expansion for every smooth function f. However, while the intuition behind it is simple, the actual formula is not. It can be pretty daunting for beginners, and even experts have a hard time remembering if they haven’t seen it for a while. -->

Công thức Taylor chỉ ra cách tìm các hệ số từ đạo hàm của $f$ tại $c$. Phần dưới đây giải thích cách suy ra công thức ấy, đồng thời tách rõ đa thức Taylor hữu hạn khỏi câu hỏi hội tụ của chuỗi Taylor vô hạn.

<!-- In this post, I’ll explain a quick and easy trick I use to re-derive the Taylor formula from scratch whenever I have trouble remembering it. -->

Trong bài viết này, tôi sẽ chia sẻ một mẹo nhỏ giúp tôi tự suy diễn lại công thức Taylor từ đầu mỗi khi cần (tức là tôi cũng chẳng nhớ nổi).

<!-- ## Starting from Scratch -->
## Bắt đầu từ hai bàn tay trắng

<!-- The idea behind the Taylor expansion is that we can re-write every smooth function as an infinite sum of polynomial terms. The first step is therefore to write down a general nth-degree polynomial. Here it is: -->

Ta bắt đầu bằng một chuỗi lũy thừa ứng viên, kí hiệu $Tf$, và yêu cầu các đạo hàm của nó tại $c$ khớp với các đạo hàm của $f$. Ký hiệu

$$f(x) \sim Tf(x) \qquad\qquad(1)$$

ở đây chỉ biểu thị sự tương ứng về các hệ số Taylor; chưa khẳng định hai vế bằng nhau tại mọi $x$.

Do đó, bước đầu tiên, ta viết ra một đa thức bậc $n$ tổng quát như sau:

$$Tf(x) = \textcolor{#FF1394}{a_0}+\textcolor{#FF1394}{a_1}(x-c)+\textcolor{#FF1394}{a_2}(x-c)^2+\textcolor{#FF1394}{a_3}(x-c)^3+\dots\qquad\qquad(2)$$

<!-- Where a0, a1, … are coefficients on each polynomial term, and c is a constant that represents where along the x-axis we want to start our approximation (if we don’t care where we start, just let c = 0, which is technically known as a Maclaurin rather than a Taylor). This series — known as a “power series” — can be written in closed form as the following: -->

Trong đó $\textcolor{#FF1394}{a_0}, \textcolor{#FF1394}{a_1}, \textcolor{#FF1394}{a_2}, \dots$ là các hệ số (coefficients) của từng hạn tử đa thức, và $c$ là hằng số (constant) ứng với một vị trí nào đó trên trục $x$ mà ta cần xấp xỉ (trường hợp $c = 0$, khai triển Taylor lúc này còn được gọi là **khai triển Maclaurin**). Dĩ nhiên $c$ phải nằm trong khoảng $(a,b)$. Vế phải của (1) còn được gọi là **chuỗi lũy thừa** (power series). Ta có thể viết gọn lại thành:

$$Tf(x)=\sum_{j=0}^\infty \textcolor{#FF1394}{a_j}(x-c)^j\qquad\qquad(3)$$

<!-- The goal here is to find a clever way to find the coefficients a0, a1, … in that equation, given some function f and an initial value of c. Here is the logic for doing that. Polynomials are smooth, so that guarantees they’re differentiable. That is, we can calculate the first, second, third and so on derivatives of them. -->

Đến đây, thứ mà ta thấy rắc rối nhất, cũng hay quên nhất chính là các hệ số $\textcolor{#FF1394}{a_0}, \textcolor{#FF1394}{a_1}, \textcolor{#FF1394}{a_2}, \dots$ trong phương trình (equation) (2) đó. Vậy nên, mục tiêu lúc này là tìm ra một công thức khéo léo nào đó để suy ra các hệ số trên thật dễ dàng khi cần. 

Giả sử $f$ có các đạo hàm cần thiết tại $c$. Ta chọn các hệ số của $Tf$ sao cho $Tf^{(n)}(c)=f^{(n)}(c)$ với mọi bậc đang xét. Nếu làm việc với một chuỗi lũy thừa hội tụ trong lân cận $c$, ta được phép lấy đạo hàm từng số hạng ở bên trong bán kính hội tụ.

<!-- So starting with our polynomial above, let’s take the first few derivatives of it, like this: -->

Lấy đạo hàm vế phải của (1), ta được:

$$
\begin{align*}
Tf'(x) &= \textcolor{#FF1394}{a_1}+2\textcolor{#FF1394}{a_2}(x-c)+3\textcolor{#FF1394}{a_3}(x-c)^2+4\textcolor{#FF1394}{a_4}(x-c)^3+\dots\\
Tf''(x) &= 2\textcolor{#FF1394}{a_2}+6\textcolor{#FF1394}{a_3}(x-c)+12\textcolor{#FF1394}{a_4}(x-c)^2+20\textcolor{#FF1394}{a_5}(x-c)^3+\dots\\
Tf'''(x) &= 6\textcolor{#FF1394}{a_3}+24\textcolor{#FF1394}{a_4}(x-c)+60\textcolor{#FF1394}{a_5}(x-c)^2+120\textcolor{#FF1394}{a_6}(x-c)^3+\dots\\
\vdots
\end{align*}
$$

<!-- Clearly we’re seeing a pattern already. We’ll use that in a minute. Now that we have n derivatives of f, let’s evaluate them for some number that will cause most of their terms to drop away. This is the key step. If we’re clever, we’ll notice that if we evaluate them at x = c, most of their terms will go to zero. That will leave behind only the coefficients a1, a2, … multiplied by some constant. So here’s that step: -->

Nếu tinh ý, ta sẽ nhận ra rằng khi tính tại $x = c$ (bao gồm cả $Tf(x)$), hầu hết các hạng tử sẽ về 0, chỉ để lại các hệ số $\textcolor{#FF1394}{a_0}, \textcolor{#FF1394}{a_1}, \textcolor{#FF1394}{a_2}, \dots$ nhân với một hằng số. Tức là:

$$
\begin{align*}
Tf(c) &= \textcolor{#FF1394}{a_0}\\
Tf'(c) &= \textcolor{#FF1394}{a_1}\\
Tf''(c) &= 2\textcolor{#FF1394}{a_2}\\
Tf'''(c) &= 6\textcolor{#FF1394}{a_3}\\
\vdots
\end{align*}
$$

Các hằng số đó bằng giai thừa của bậc đạo hàm. Tức là

$$
\begin{align*}
Tf(c) &= 1*\textcolor{#FF1394}{a_0} &= 0! &* \textcolor{#FF1394}{a_0}\\
Tf'(c) &= 1*\textcolor{#FF1394}{a_1} &= 1! &* \textcolor{#FF1394}{a_1}\\
Tf''(c) &= 2*\textcolor{#FF1394}{a_2} &= 2! &* \textcolor{#FF1394}{a_2}\\
Tf'''(c) &= 6*\textcolor{#FF1394}{a_3} &= 3! &* \textcolor{#FF1394}{a_3}\\
\vdots
\end{align*}
$$

Tổng quát hoá lên, ta được:

$$Tf^{(n)}(c) = n! * \textcolor{#FF1394}{a_n}.$$

Theo điều kiện khớp đạo hàm đã đặt ra, $Tf^{(n)}(c)=f^{(n)}(c)$, vậy nên

$$f^{(n)}(c) = n! * \textcolor{#FF1394}{a_n}.$$

<!-- Now we have a set of simple equations we can solve for a1, a2, … Simply divide both sides by n!. That gives us the following: -->

Giờ đây, ta có một hệ phương trình đơn giản có thể giải cho các hệ số $\textcolor{#FF1394}{a_0}, \textcolor{#FF1394}{a_1}, \textcolor{#FF1394}{a_2}, \dots$. Chỉ cần chia cả hai vế cho $n!.$ Điều này dẫn đến kết quả sau:

$$
\begin{align*}
\textcolor{#FF1394}{a_0} &= \frac{f(c)}{0!}\\
\textcolor{#FF1394}{a_1} &= \frac{f'(c)}{1!}\\
\textcolor{#FF1394}{a_2} &= \frac{f''(c)}{2!}\\
\textcolor{#FF1394}{a_3} &= \frac{f'''(c)}{3!}\\
\vdots
\end{align*}
$$

<!-- The pattern here is beautiful. The nth coefficient is just the nth derivative of the original function, evaluated at c, divided by n factorial. Now we have our n coefficients. The next step is to plug them back into our beginning expression for a general nth-degree polynomial, like this: -->

Quy luật ở đây khá đẹp. Hệ số bậc $n$ chỉ đơn giản là đạo hàm bậc $n$ của hàm ban đầu, tính tại $c$, rồi chia cho $n!.$ Giờ chúng ta đã có các hệ số cần thiết. Bước tiếp theo là thay chúng vào biểu thức tổng quát (2) như sau:

$$
\begin{aligned}
Tf(x) &= \textcolor{#FF1394}{a_0} + \textcolor{#FF1394}{a_1}(x-c) + \textcolor{#FF1394}{a_2}(x-c)^2 + \textcolor{#FF1394}{a_3}(x-c)^3 + \dots\\
&= \textcolor{#FF1394}{\frac{f(c)}{0!}}+\textcolor{#FF1394}{\frac{f'(c)}{1!}}(x-c)+\textcolor{#FF1394}{\frac{f''(c)}{2!}}(x-c)^2+\textcolor{#FF1394}{\frac{f'''(c)}{3!}}(x-c)^3+\dots
\end{aligned}
$$

<!-- This equation is what we’re looking for. It gives a polynomial expansion for every smooth function f. We just need to calculate the first n derivatives of f, evaluate them at c, divide each one by n!, and sum up these terms. The result will be a good approximation to our original function. The more terms we add on, the more accurate the polynomial approximation will be. -->

Đây là các hệ số của đa thức hoặc chuỗi Taylor. Với đa thức bậc $n$, chất lượng xấp xỉ được kiểm soát bởi số dư Taylor dưới các giả thiết thích hợp. Việc tăng bậc không bảo đảm xấp xỉ tốt hơn tại mọi điểm; điều đó còn phụ thuộc vào hàm, điểm khai triển và miền đang xét.

<!-- ## The Result: the Taylor Formula -->

## Kết quả: Công thức Taylor

<!-- The final step is to write this infinite series in closed form. This is the last step in the trick for remembering the formula. Writing the above as a summation, we get our final result: -->

Bước cuối cùng là viết **chuỗi Taylor gắn với $f$ tại $c$** dưới dạng tổng:

$$
Tf(x) = \sum_{j=0}^\infty \textcolor{#FF1394}{\frac{f^{(j)}(c)}{j!}}(x-c)^j
$$

Chỉ khi số dư tiến về $0$ tại $x$ đang xét — chẳng hạn khi $f$ giải tích trong một lân cận phù hợp của $c$ — ta mới có thể thay $Tf(x)$ bằng $f(x)$ trong công thức trên.

<!-- The lesson here is simple: don’t waste your time learning formulas. Learn methods. If you can remember the basic logic of where the Taylor expansion comes from, you can quickly and easily re-derive the formula from scratch. -->

Bài học chính là hiểu điều kiện khớp đạo hàm tạo ra các hệ số $f^{(j)}(c)/j!$. Cách suy luận này giúp nhớ công thức, còn việc chuỗi có hội tụ đến $f$ hay không là một câu hỏi riêng cần được kiểm tra.

## Tham khảo

- [An Easy Way to Remember the Taylor Series Expansion](https://medium.com/@andrew.chamberlain/an-easy-way-to-remember-the-taylor-series-expansion-a7c3f9101063)

