So you want to know if a specific mathematical expression (like $(x-1)^2 - (x^2-2x))$ is a constant. Just check whether its derivative is zero:
sage: var('C, C2')