AUTHORS:
EXAMPLES:
Periodic infinite words:
sage: v = Word([0, 4, 8, 8, 3])
sage: vv = v^Infinity
sage: vv
word: 0488304883048830488304883048830488304883...
Infinite words from a function over an alphabet :
sage: Word(lambda n: n%3)
word: 0120120120120120120120120120120120120120...
sage: def t(n):
... return add(Integer(n).digits(base=2)) % 2
sage: Word(t, alphabet = [0, 1])
word: 0110100110010110100101100110100110010110...
or as a one-liner:
sage: Word(lambda n : add(Integer(n).digits(base=2)) % 2, alphabet = [0, 1])
word: 0110100110010110100101100110100110010110...
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,...
Infinite words from morphism
For example, let and be the morphism defined by :
sage: mu = WordMorphism('a->ab,b->ba'); print mu
WordMorphism: a->ab, b->ba
sage: mu.fixed_point('a')
word: abbabaabbaababbabaababbaabbabaabbaababba...
Infinite words in a specific combinatorial class:
sage: W = Words("ab"); W
Words over Ordered Alphabet ['a', 'b']
sage: f = lambda n : 'a' if n % 2 == 1 else 'b'
sage: W(f)
word: babababababababababababababababababababa...
Bases: sage.combinat.words.abstract_word.Word_class
Returns the length of self.
EXAMPLES:
sage: f = lambda n : n % 6
sage: w = Word(f); w
word: 0123450123450123450123450123450123450123...
sage: w.length()
+Infinity