Exemplo n.º 1
0
    def __init__(self, alphabet, rels):
        # Check the alphabet
        if not isinstance(alphabet, str):
            raise TypeError('the first argument (alphabet) must be a string')
        elif not all(alphabet.count(i) == 1 for i in alphabet):
            raise ValueError('the first argument (alphabet) must be a '
                             'duplicate-free string')

        # Corner case
        if len(alphabet) == 0 and not len(rels) == 0:
            raise ValueError('the empty semigroup must not have' +
                             ' any relations')
        # Check the relations
        if not (isinstance(rels, list)
                and all(isinstance(rel, list) for rel in rels)):
            raise TypeError('the second argument (relations) must be a ' +
                            'list of lists')
        elif not all(
                len(rel) == 2 and isinstance(rel[0], str)
                and isinstance(rel[1], str) for rel in rels):
            raise TypeError('the second argument (relations) must be a ' +
                            'list of pairs of strings')

        self._pure_letter_alphabet = True
        for i in alphabet:
            if not i in ('abcdefghijklmnopqrstuvwxyz1' +
                         'ABCDEFGHIJKLMNOPQRSTUVWXYZ'):
                self._pure_letter_alphabet = False
                break

        for i, rel in enumerate(rels):
            for j, word in enumerate(rel):
                rels[i][j] = self._parse_word(word)

        self.alphabet = alphabet
        self.relations = rels

        for rel in rels:
            for word in rel:
                self.check_word(word)

        libsemigroups.FpSemigroupNC.__init__(self, len(alphabet), rels)
        if not self.is_obviously_infinite():
            Semigroup.__init__(self,
                               *[_FPSOME(self, i) for i in self.alphabet])
Exemplo n.º 2
0
    def factorisation(self, word):
        '''
        Factorises a given word into a list of generators each represented by
        an integer starting at 0.

        Args:
            word (str): word to be factorised.

        Returns:
            list: factorisation into generators.

        Examples:
            >>> S = FpSemigroup('ab',[['a', 'aa'], ['b', 'bbb'], ['ab', 'ba']])
            >>> S.factorisation('b')
            [1]
            >>> S.factorisation('aaabb')
            [0, 1, 1]
        '''
        if self.is_obviously_infinite():
            raise ValueError('given semigroup is infinite')
        word = self._parse_word(word)
        self.check_word(word)
        Pyword = libsemigroups.PythonElementNC(_FPSOME(self, word))
        return Semigroup.factorisation(self, Pyword)
Exemplo n.º 3
0
 def nridempotents(self):
     if not self.is_finite():
         raise ValueError('given semigroup is infinite')
     return Semigroup.nridempotents(self)
Exemplo n.º 4
0
 def enumerate(self, limit):
     if not self.is_finite():
         raise ValueError('given semigroup is infinite')
     return Semigroup.enumerate(self, limit)