Evaluate a formula using substitution