Factoring expressions with variables