Compute number of free variables

Do not substitute terms if there are no free variables.
Optimized substitution algorithm.

Eagerly simplify substitutions and keep them in a simple array.  Use
numFreeVariables to cut off unnecessary substitutions.  Fix numFreeVariables
for Variable class (type can also have free variables).