Cancel when terms have a common factors

Reviewers: eater

Reviewed By: eater

Differential Revision: http://phabricator.khanacademy.org/D10545