def _int_list_to_substitutions(self, words): A = self._start._alphabet W = FiniteWords(A) s = {} for i, w in enumerate(words): s[A.unrank(i)] = [A.unrank(j) for j in w] return WordMorphism(s, domain=W, codomain=W)
def __init__(self, alphabet=None): r""" INPUT: - ``alphabet`` -- the underlying alphabet TESTS:: sage: loads(dumps(LyndonWords())) is LyndonWords() True """ from sage.categories.sets_cat import Sets self._words = FiniteWords() Parent.__init__(self, category=Sets().Infinite(), facade=(self._words))
def __init__(self, e): """ TESTS:: sage: LW21 = LyndonWords([2,1]); LW21 Lyndon words with evaluation [2, 1] sage: LW21 == loads(dumps(LW21)) True """ self._e = e self._words = FiniteWords(len(e)) from sage.categories.enumerated_sets import EnumeratedSets Parent.__init__(self, category=EnumeratedSets().Finite(), facade=(self._words, ))
def iter_pisot_irreductible(d=3, arg=None): r""" Return an iterator over Pisot irreductible substitutions INPUT: - ``d`` -- size of alphabet, [0,1,...,d-1] - "arg" -- (optional, default: None) It can be one of the following : * "None" -- then the method iterates through all morphisms. * tuple (a, b) of two integers - It specifies the range "range(a, b)" of values to consider for the sum of the length EXAMPLES:: sage: from slabbe.word_morphisms import iter_pisot_irreductible sage: it = iter_pisot_irreductible(3) sage: for _ in range(4): next(it) WordMorphism: 0->01, 1->2, 2->0 WordMorphism: 0->02, 1->0, 2->1 WordMorphism: 0->10, 1->2, 2->0 WordMorphism: 0->12, 1->0, 2->1 Pour linstant, avec le tuple, il y a un bogue:: sage: it = iter_pisot_irreductible(3, (5,10)) sage: for _ in range(4): next(it) WordMorphism: 0->0000001, 1->2, 2->0 WordMorphism: 0->0000002, 1->0, 2->1 WordMorphism: 0->0000010, 1->2, 2->0 WordMorphism: 0->0000012, 1->0, 2->1 """ from slabbe.matrices import is_pisot W = FiniteWords(range(d)) for m in W.iter_morphisms(arg): incidence_matrix = m.incidence_matrix() if not incidence_matrix.det() == 1: continue if not m.is_primitive(): # mathematiquement non necessaire continue if not is_pisot(incidence_matrix): continue yield m
def standard_unbracketing(sblw): """ Return flattened ``sblw`` if it is a standard bracketing of a Lyndon word, otherwise raise an error. EXAMPLES:: sage: from sage.combinat.words.lyndon_word import standard_unbracketing sage: standard_unbracketing([1, [2, 3]]) word: 123 sage: standard_unbracketing([[1, 2], 3]) Traceback (most recent call last): ... ValueError: not a standard bracketing of a Lyndon word TESTS:: sage: standard_unbracketing(1) # Letters don't use brackets. word: 1 sage: standard_unbracketing([1]) Traceback (most recent call last): ... ValueError: not a standard bracketing of a Lyndon word """ # Nested helper function that not only returns (flattened) w, but also its # right factor in the standard Lyndon factorization. def standard_unbracketing_rec(w): if not isinstance(w, list): return [w], [] if len(w) != 2: raise ValueError("not a standard bracketing of a Lyndon word") x, t = standard_unbracketing_rec(w[0]) y, _ = standard_unbracketing_rec(w[1]) # If x = st is a standard Lyndon factorization, and y is a Lyndon word # such that y <= t, then xy is standard (but not necessarily Lyndon). if x < y and (len(t) == 0 or y <= t): x += y return x, y else: raise ValueError("not a standard bracketing of a Lyndon word") lw, _ = standard_unbracketing_rec(sblw) return FiniteWords(list(set(lw)))(lw, datatype='list', check=False)
def __init__(self, n, k): """ Initialize ``self``. TESTS:: sage: LW23 = LyndonWords(2,3); LW23 Lyndon words from an alphabet of size 2 of length 3 sage: LW23== loads(dumps(LW23)) True """ self._n = n self._k = k self._words = FiniteWords(self._n) from sage.categories.enumerated_sets import EnumeratedSets Parent.__init__(self, category=EnumeratedSets().Finite(), facade=(self._words, ))