Evaluate $\displaystyle \int \dfrac{x^2 + x + 1}{\left(x + 1\right)^2 \left(x + 2\right)} \; dx$
Let $I = \displaystyle \int \dfrac{x^2 + x + 1}{\left(x + 1\right)^2 \left(x + 2\right)} \; dx$ $\;\;\; \cdots \; (1)$
Let $\dfrac{x^2 + x + 1}{\left(x + 1\right)^2 \left(x + 2\right)} = \dfrac{A}{\left(x + 1\right)^2} + \dfrac{B}{x + 1} + \dfrac{C}{x + 2}$ $\;\;\; \cdots \; (2)$
$\begin{aligned}
\implies x^2 + x + 1 & = A \left(x + 2\right) + B \left(x + 1\right) \left(x + 2\right) + C \left(x + 1\right)^2 \\\\
& = A x + 2 A + B x^2 + 3 B x + 2 B + C x^2 + 2 C x + C \\\\
& = x^2 \left(B + C\right) + x \left(A + 3 B + 2 C\right) + \left(2 A + 2 B + C\right)
\end{aligned}$
Comparing the coefficient of $x^2$ term gives
$B + C = 1$ $\implies$ $B = 1 - C$ $\;\;\; \cdots \; (3a)$
Comparing the coefficient of $x$ term gives
$A + 3 B + 2 C = 1$ $\implies$ $A + 3 \left(1 - C\right) + 2 C = 1$ $\;\;\;$ [By equation $(3a)$]
$\implies$ $A - C = - 2$ $\;\;\; \cdots \; (3b)$
Comparing the constant term gives
$2 A + 2 B + C = 1$ $\implies$ $2 A + 2 \left(1 - C\right) + C = 1$ $\;\;\;$ [By equation $(3a)$]
$\implies$ $2 A - C = -1$ $\;\;\; \cdots \; (3c)$
Subtracting equations $(3a)$ and $(3b)$ gives $A = 1$
Substituting the value of A in equation $(3b)$ gives $C = A + 2 = 3$
Substituting the value of B in equation $(3a)$ gives $B = 1 - C = -2$
$\therefore$ $\;$ Substituting the values of A, B and C in equation $(2)$ gives
$\dfrac{x^2 + x + 1}{\left(x + 1\right)^2 \left(x + 2\right)} = \dfrac{1}{\left(x + 1\right)^2} - \dfrac{2}{x + 1} + \dfrac{3}{x + 2}$ $\;\;\; \cdots \; (4)$
$\therefore$ $\;$ In view of equation $(4)$, equation $(1)$ becomes
$\begin{aligned}
I & = \int \dfrac{dx}{\left(x + 1\right)^2} - 2 \int \dfrac{dx}{x + 1} + 3 \int \dfrac{dx}{x + 2} \\\\
& = \dfrac{- 1}{x + 1} - 2 \log \left|x + 1\right| + 3 \log \left|x + 2\right| + c
\end{aligned}$