remove some O(n^2) algorithms in the front end
related to #2239. there were only problems for unusual expressions with
very large numbers of variables.