  We develop a new, powerful method for counting elements in a multiset. As a
first application, we use this algorithm to study the number of occurrences of
patterns in a permutation. For patterns of length 3 there are two Wilf classes,
and the general behaviour of these is reasonably well-known. We slightly extend
some of the known results in that case, and exhaustively study the case of
patterns of length 4, about which there is little previous knowledge. For such
patterns, there are seven Wilf classes, and based on extensive enumerations and
careful series analysis, we have conjectured the asymptotic behaviour for all
classes.
