from sage.combinat.permutation import to_standard
def occurrences(p, pattern):
Return elements in sequences of distinct blocks order isomorphic
for i, b in enumerate(p):
o.extend(occurrences_aux(q, [e], pattern))
def occurrences_aux(p, prefix, pattern):
Return all occurrences of the form `(prefix, suffix)` order
isomorphic to `pattern`, where `suffix` are elements in sequences
of distinct blocks of `p`.
if len(pattern) == len(prefix):
pattern_prefix = to_standard(pattern[:len(prefix)+1])
for i, b in enumerate(p):
new_prefix = prefix + [e]
if to_standard(new_prefix) == pattern_prefix:
yield from occurrences_aux(q, new_prefix, pattern)
return len(occurrences(p, [1,3,2]))
parent_initializer = OrderedSetPartitions
for elt in parent_initializer(level):
print('%s => %s' % (element_repr(elt), statistic(elt)))