Write $\dfrac{4x+1}{x^2 - x - 2}$ using partial fractions.
$$ \frac{4x+1}{x^2 - x - 2} = \frac{4x+1}{(x+1)(x+2)} = \frac{A}{x+1} + \frac{B}{x-2} = \frac{A(x-2)+B(x+1)}{(x+1)(x-2)}$$
$$4x+1 = A(x-2)+B(x+1)$$
$$x=2 \Rightarrow 4 \cdot2 + 1 = A(0) + B(3) \Rightarrow B = 3$$
$$x = -1 \Rightarrow 4(-1) +1 = A(-3)+ B(0) \Rightarrow A = 1$$
Thus,
$$\frac{4x+1}{x^2-x-2} = \frac{1}{x+1} + \frac{3}{x-2}\textrm{.}$$
The substitution of $x$ ($x = 2, -1$) is a common method to find out the coefficient of the partial fractions. However, the equation on the third line is obtained by multiplying $(x+1)(x-2)$, which is assumed to be nonzero. Here we have a contradiction. Furthermore, the original function is not defined at $x=-1,2$.
How can we substitute these value for $x$? So is this method valid and rigorous? How to modify it so that it is rigorous?