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?
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.