Add function to restrict the number of elements in generation of formula