<s>[INST] how to factorize $a^3 - ab^3 + a^2 + b^2 + 1$ I've got the following question in a book about maths olympiad 

factorize $a^3b - ab^3 + a^2 + b^2 + 1$

and the answer to this question is

$a^3b - ab^3 + a^2 + b^2 + 1$$= a^3b - a^2b^2 + ab + a^2b^2 - ab^3 + b^2 - ab + + a^2+ 1$ $= ab(a^2 - ab +1) + b^2 (a^2 - ab + 1) + (a^2 - ab + 1)$  $= (a^2 - ab + 1)(ab+b^2 + 1)$

I understand that $a^2b^2 + ab$ is added to the polynomials for further factorization. However, it seems like a magic to me. I didn't know how I can think of adding $a^2b^2 + ab$. Adding two terms is really hard to think of to me. If I am given this question in the future, I am quite sure that I still can't finish it.
My question is: How can I know what terms to add to the polynomails so that I can group things up and do factorization? Also, where can I find more factorization like this for me to practise?
 [/INST] Another way to guesstimate is to try $b=1$ and $a=1$:
$$a^3b - ab^3 + a^2 + b^2 + 1=a^3+a^2-a+2=(a^2-a+1)(a+2)=(a^2-a+\color{red}1)(a+1+\color{red}1)\\
a^3b - ab^3 + a^2 + b^2 + 1=-b^3+b^2+b+2=(2-b)(b^2+b+1)=(1-b+\color{red}1)(b+b^2+\color{red}1)$$
Hence:
$$a^3b - ab^3 + a^2 + b^2 + 1=(a^2-ab+1)(ab+b^2+1)$$
Note: $\color{red}1$s must be fixed. One can guess the term $ab$ from the signs.
</s>