def Klazar_occurrences(pi, pattern):
Return the number of occurrences of pattern in pi.
From Mansour 2013, page 86, Example 3.24
The set partition π = 135/26/4 contains four occurrences of
the pattern 12/3, namely, 13/6, 13/4, 15/6, and 35/6. On the other hand, the
set partition π avoids the pattern 12/34.
sage: Klazar_occurrences([[1,3,5],[2,6],[4]], [[1,2],[3]])
sage: Klazar_occurrences([[1,3,5],[2,6],[4]], [[1,2],[3,4]])
pi = SetPartition(pi).standardization()
pattern = SetPartition(pattern).standardization()
for s in Subsets(range(1,1+pi.size()), pattern.size()):
if pi.restriction(s).standardization() == pattern:
return Klazar_occurrences(pi, [[1,2,3]])
parent_initializer = SetPartitions
element_repr = lambda X: str(sorted([sorted(s) for s in X])).replace("[","{").replace("]","}")
for elt in parent_initializer(level):
print('%s => %s' % (element_repr(elt), statistic(elt)))