class MonoideDeCompositions(Parent): def __init__(self, ensemble): Parent.__init__(self, category = FiniteMonoids()) self._ensemble = Set(ensemble) def _repr_(self): return "Monoide de compositions de %s" % self._ensemble def product(self, x, y): new_composition = [] for B in x.value: for C in y.value: BC = B.intersection(C) if BC: new_composition.append(BC) return self.create_element(new_composition) @cached_method def one(self): return self.create_element([self._ensemble]) @cached_method def semigroup_generators(self): return [self.one()] + [self.create_element(X) for X in OrderedSetPartitions(self._ensemble, 2)] def an_element(self): return self.semigroup_generators()[0] def create_element(self, x): return self(self.Element.wrapped_class(map(Set, x))) def regions(self): return [M.create_element([[i] for i in perm]) for perm in Permutations(len(self._ensemble))] class Element (ElementWrapper): wrapped_class = tuple def shape(self): return Composition([len(B) for B in self.value]) def _repr_(self): return '[%s]' % '|'.join(''.join(map(str, block)) for block in self.value)