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
 A: An easier way is to note that $x^4-2x^3+x-2$ has the simple roots $x=-1$ and $x=2$, which are obvious candidates by the rational root theorem, so your polynomial is divisible by
$$(x+1)(x-2)=x^2-x-2.$$
A: Note that
$$x^4-2x^3+x-2 = x^3(x-2)+1(x-2)=(x-2)(x^3+1)=\color{red}{(x-2)(x+1)}(x^2-x+1).$$

Regarding the taking a factor out part, we use
$$ab+ac = a(b+c)$$
to factor $a$ out of the terms. In your case, it is $ab+ac+ad = a(b+c+d)$.
A: Another way: complete the square in  $\rm\color{#c00}{lead\ 2\ terms}$  yielding
$$ \underbrace{\color{#c00}{(x^2\!-\!x)^2} - (\color{#c00}{x^2}\!-\!x)-2}_{\Large \color{#c00}{x^4\ -\ 2x^3}\ +\ x\ -\ 2\!\!\!\!\!\!\!\!\!\!\!\! } = X^2\!-\!X\!-\!2 = (X\!+\!1)(X\!-\!2) = (x^2\!-\!x\!+\!1)\underbrace{(x^2\!-\!x\!-\!2)}_{\Large (x-2)(x+1)}$$
A: $$x^4-2x^3+x-2=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).$$
A: 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.
A: $$\begin{align}
x^4-2x^3+x-2&= x^4 + (\color{red}{-2x^3+x-2})\\
&= x^4 + \color{red}{P(x)}\\
&= x^4 + \color{green}{-x^3-2x^2+}(\color{green}{x^3+2x^2}+\color{red}{P(x)})\\
&= \color{blue}{(x^4 + -x^3-2x^2)}+(x^3+2x^2+\color{red}{P(x)})\\
&= (x^2-x-2)(x^2)+(x^3+2x^2+\color{red}{P(x)})\\
&= (x^2-x-2)(x^2)+(x^3+2x^2+\color{red}{-2x^3+x-2})\\
&= (x^2-x-2)(x^2)+(-x^3+2x^2+x-2)\\
&= \dots\\
\end{align}$$
Try comparing the line with blue highlighting with your original problem (e.g. $x^4-x^3-2x^2$). Now, keep going, and try to split up the rest of the polynomial, using the same method.
