a: \(=\left(x^2+x-2\right)\left(x^2+x\right)+1\)
\(=\left(x^2+x\right)^2-2\left(x^2+x\right)+1\)
\(=\left(x^2+x-1\right)^2\)
b: \(=x\left(x-1\right)\left(x+1\right)\left(x+2\right)+1\)
\(=\left(x^2+x\right)\left(x^2+x-2\right)+1\)
\(=\left(x^2+x-1\right)^2\)