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?
 A: The part they don't show in olympiad solutions is the fifteen minutes of pure trial and error, testing different terms to add and subtract to see if anything works. They all demonstrate it as if it's something one ought to see right away.
Maybe, with lots of experience, one can spot it right away, or at least know which ones are more likely to work, but I don't think there is a general rule one can apply to find the relevant term.
A: Since this is a degree-$4$ polynomial, it's natural to try writing it as a product of two degree-$2$ polynomials, so the $-ab^3$ term needs to come from a $-ab/k$ multiplied with a $kb^2$, and we may as well take $k=1$. Applying the same logic to the $a^3b$ term (my earlier comment implies $a^3$ is meant to read $a^3b$, or we'd never get this factorization), we try $(ca^2-ab+d)(b^2+ab/c+1/d)$. The $a^2$ coefficient forces $c=d$; the $b^2$ coefficient forces $c=1$, determining the entire factorisation.
A: In reality, there is no actual method to always determine what terms to add. The best thing to do is to just try different combinations and memorize certain patterns that come up more often.
For more factorization like this, best to look through olympiad papers and olympiad lecture notes.
A: 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.
