Ta có: \(\frac{4}{x+1}+\frac{x^2+x-2}{\left(x+1\right)\left(x+2\right)}\)
\(=\frac{4}{x+1}+\frac{x^2+2x-x-2}{\left(x+1\right)\left(x+2\right)}\)
\(=\frac{4}{x+1}+\frac{x\left(x+2\right)-\left(x+2\right)}{\left(x+1\right)\left(x+2\right)}\)
\(=\frac{4}{x+1}+\frac{\left(x+2\right)\left(x-1\right)}{\left(x+2\right)\left(x+1\right)}\)
\(=\frac{4}{x+1}+\frac{x-1}{x+1}\)
\(=\frac{x+3}{x+1}\)