<s>[INST] How do we factor out $x^2 - x -2$ in this expression? Suppose we're given that
$$x^4 - 2x^3 +x-2$$
How do we factor out $x^2 - x -2$ in this expression?

$$(x^4 -x^3- 2x^2)-(x^3-x^2-2x)+(x^2-x-2) = x^2(x^2 -x-2)-x(x^2-x-2)+(x^2-x-2) = (x^2-x-2)(x^2-x+1)$$

This satisfies with what we want to get. However, I do not seem to have understood what is done there. Could I get your assistance in order to understand it? Perhaps there's better way of factoring. 
Regards
 [/INST] If $x^2 - x -2$ is indeed a factor of $x^4 - 2x^3 + x -2$, that means I can write:
$$ x^4 - 2x^3 + x - 2 = P(x)(x^2 -x - 2)$$
In order to reproduce the $x^4$ term, that means that the leading term of $P(x)$ is $x^2$. Now
$$ x^2(x^2 -x -2) = x^4 -x^3 -2x^2 $$
which is not the same as what we started with. Let's try to salvage the situation by adding/subtracting whatever we need to both sides of this equation in order to make the RHS agree with our original polynomial. We need another $-x^3$, we need to get rid of the $-2x^2$ and we need to add $x-2$:
$$ \begin{align}
x^2(x^2-x-2) -x^3 +2x^2 + x -2 & = x^4 - x^3 -2x^2 - x^3 + 2x^2 + x -2 \\
& = x^4 -2x^3 +x -2
\end{align}$$
We continue the same way, starting with the $-x^3$ term on the LHS. We will try to write $$-x^3 + 2x^2 + x - 2 = Q(x)(x^2 - x -2)$$ We see that the leading term of $Q(x)$ must be $-x$ in order to reproduce the $-x^3$ term. 
$$ (-x)(x^2 -x -2) = -x^3 +x^2 + 2x$$
which is not the same as $-x^3 + 2x^2 + x - 2$, so we'll add/subtract whateve we need to both sides: we need an extra $x^2$, we need to take away $x$ and add $-2$:
$$ (-x)(x^2 -x -2) +x^2 - x - 2= -x^3 +x^2 + 2x +x^2 - x - 2 = -x^3 + 2x^2 + x - 2$$
We continue on with what's left in the LHS: we want to write
$$x^2 - x - 2= R(x)(x^2 - x - 2)$$
Obviously R(x) is the constant polynomial $R(x) = 1$. So gathering the pieces together we can say:
$$ \begin{align}
x^4 - 2x^3 + x - 2 &= x^2(x^2-x-2) -x^3 +2x^2 + x -2 \\
&= x^2(x^2-x-2) -x(x^2-x-2) + x^2-x-2 \\
&= x^2(x^2-x-2) -x(x^2-x-2) + 1(x^2-x-2) \\
&= (x^2 - x + 1)(x^2-x-2)
\end{align}$$
Maybe this makes it clearer where the original manipulations came from, but what I did above is pretty much long division (of polynomials) without saying so. In long division, you would arrange as in long division of numbers but instead of calculating successive digits of the (numerical) quotient, you calculate successive terms of the (polynomial) quotient. It looks like this:
$$
\require{enclose}
\begin{array}{r}
{\color{red}{x^2}} {\color{blue}{-x}} + {\color{green}1} \\
x^2 - x - 2 \enclose{longdiv}{x^4 - 2x^3 + \phantom{2x^2 +} x - 2} \\
     \underline{\color{red}{x^4 - \phantom{2}x^3 - 2x^2}\phantom{+x - 2}} \\
     \phantom{x^4 }\phantom{- 2}-x^3 + 2x^2 + x - 2 \\
     \underline{\color{blue}{-x^3 + x^2 + 2x}\phantom{- 2}} \\
     \phantom{x^4 + -x^3}{x^2 -x -2} \\
     \underline{\color{green}{x^2 -x -2 }}\\
     \underline{0}
\end{array}
$$
Hope this helps.
</s>