How to factor x-d+(x-d)^2