Infinite word¶
AUTHORS:
Sebastien Labbe
Franco Saliola
EXAMPLES:
Creation of an infinite word¶
Periodic infinite words:
sage: v = Word([0, 4, 8, 8, 3])
sage: vv = v^Infinity
sage: vv
word: 0488304883048830488304883048830488304883...
>>> from sage.all import *
>>> v = Word([Integer(0), Integer(4), Integer(8), Integer(8), Integer(3)])
>>> vv = v**Infinity
>>> vv
word: 0488304883048830488304883048830488304883...
v = Word([0, 4, 8, 8, 3]) vv = v^Infinity vv
Infinite words from a function \(f:\mathbb{N}\rightarrow A\) over an alphabet \(A\):
sage: Word(lambda n: n%3)
word: 0120120120120120120120120120120120120120...
>>> from sage.all import *
>>> Word(lambda n: n%Integer(3))
word: 0120120120120120120120120120120120120120...
Word(lambda n: n%3)
sage: def t(n):
....: return add(Integer(n).digits(base=2)) % 2
sage: Word(t, alphabet = [0, 1])
word: 0110100110010110100101100110100110010110...
>>> from sage.all import *
>>> def t(n):
... return add(Integer(n).digits(base=Integer(2))) % Integer(2)
>>> Word(t, alphabet = [Integer(0), Integer(1)])
word: 0110100110010110100101100110100110010110...
def t(n): return add(Integer(n).digits(base=2)) % 2 Word(t, alphabet = [0, 1])
>>> from sage.all import *
>>> def t(n):
... return add(Integer(n).digits(base=Integer(2))) % Integer(2)
>>> Word(t, alphabet = [Integer(0), Integer(1)])
word: 0110100110010110100101100110100110010110...
def t(n): return add(Integer(n).digits(base=2)) % 2 Word(t, alphabet = [0, 1])
or as a one-liner:
sage: Word(lambda n : add(Integer(n).digits(base=2)) % 2, alphabet = [0, 1])
word: 0110100110010110100101100110100110010110...
>>> from sage.all import *
>>> Word(lambda n : add(Integer(n).digits(base=Integer(2))) % Integer(2), alphabet = [Integer(0), Integer(1)])
word: 0110100110010110100101100110100110010110...
Word(lambda n : add(Integer(n).digits(base=2)) % 2, alphabet = [0, 1])
Infinite words from iterators:
sage: from itertools import count,repeat
sage: Word( repeat(4) )
word: 4444444444444444444444444444444444444444...
sage: Word( count() )
word: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,...
>>> from sage.all import *
>>> from itertools import count,repeat
>>> Word( repeat(Integer(4)) )
word: 4444444444444444444444444444444444444444...
>>> Word( count() )
word: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,...
from itertools import count,repeat Word( repeat(4) ) Word( count() )
Infinite words from morphism
For example, let \(A=\{a,b\}\) and \(\mu : A^* \rightarrow A^*\) be the morphism defined by \(a\mapsto ab, b\mapsto ba\):
sage: mu = WordMorphism('a->ab,b->ba'); mu
WordMorphism: a->ab, b->ba
sage: mu.fixed_point('a')
word: abbabaabbaababbabaababbaabbabaabbaababba...
>>> from sage.all import *
>>> mu = WordMorphism('a->ab,b->ba'); mu
WordMorphism: a->ab, b->ba
>>> mu.fixed_point('a')
word: abbabaabbaababbabaababbaabbabaabbaababba...
mu = WordMorphism('a->ab,b->ba'); mu mu.fixed_point('a')
Infinite words in a specific combinatorial class:
sage: W = InfiniteWords("ab"); W
Infinite words over {'a', 'b'}
sage: f = lambda n : 'a' if n % 2 == 1 else 'b'
sage: W(f)
word: babababababababababababababababababababa...
>>> from sage.all import *
>>> W = InfiniteWords("ab"); W
Infinite words over {'a', 'b'}
>>> f = lambda n : 'a' if n % Integer(2) == Integer(1) else 'b'
>>> W(f)
word: babababababababababababababababababababa...
W = InfiniteWords("ab"); W f = lambda n : 'a' if n % 2 == 1 else 'b' W(f)
- class sage.combinat.words.infinite_word.InfiniteWord_class[source]¶
Bases:
Word_class
- length()[source]¶
Return the length of
self
.EXAMPLES:
sage: f = lambda n : n % 6 sage: w = Word(f); w word: 0123450123450123450123450123450123450123... sage: w.length() +Infinity
>>> from sage.all import * >>> f = lambda n : n % Integer(6) >>> w = Word(f); w word: 0123450123450123450123450123450123450123... >>> w.length() +Infinity
f = lambda n : n % 6 w = Word(f); w w.length()