Infinite word - Combinatorics

Skip to content
Back to top
View this page
Edit this page

# Infinite word

AUTHORS:

- Sebastien Labbe

- Franco Saliola

EXAMPLES:

## Creation of an infinite word

Periodic infinite words:

Sage

    sage: v = Word([0, 4, 8, 8, 3])
    sage: vv = v^Infinity
    sage: vv
    word: 0488304883048830488304883048830488304883...

Python

    >>> from sage.all import *
    >>> v = Word([Integer(0), Integer(4), Integer(8), Integer(8), Integer(3)])
    >>> vv = v**Infinity
    >>> vv
    word: 0488304883048830488304883048830488304883...

Infinite words from a function \(f:\mathbb{N}\rightarrow A\) over an alphabet \(A\):

Sage

    sage: Word(lambda n: n%3)
    word: 0120120120120120120120120120120120120120...

[Python]

    >>> from sage.all import *
    >>> Word(lambda n: n%Integer(3))
    word: 0120120120120120120120120120120120120120...

Sage

    sage: def t(n):
    ....:     return add(Integer(n).digits(base=2)) % 2
    sage: Word(t, alphabet = [0, 1])
    word: 0110100110010110100101100110100110010110...

Python

    >>> 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...

or as a one-liner:

Sage

    sage: Word(lambda n : add(Integer(n).digits(base=2)) % 2, alphabet = [0, 1])
    word: 0110100110010110100101100110100110010110...

[Python]

    >>> from sage.all import *
    >>> Word(lambda n : add(Integer(n).digits(base=Integer(2))) % Integer(2), alphabet = [Integer(0), Integer(1)])
    word: 0110100110010110100101100110100110010110...

Infinite words from iterators:

Sage

    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,...

Python

    >>> 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,...

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

    sage: mu = WordMorphism('a->ab,b->ba'); mu
    WordMorphism: a->ab, b->ba
    sage: mu.fixed_point('a')
    word: abbabaabbaababbabaababbaabbabaabbaababba...

[Python]

    >>> from sage.all import *
    >>> mu = WordMorphism('a->ab,b->ba'); mu
    WordMorphism: a->ab, b->ba
    >>> mu.fixed_point('a')
    word: abbabaabbaababbabaababbaabbabaabbaababba...

Infinite words in a specific combinatorial class:

Sage

    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...

Python

    >>> 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...

class sage.combinat.words.infinite_word.InfiniteWord_class

  Bases: `Word_class`

  length()

    Return the length of `self`.

    EXAMPLES:

    Sage

        sage: f = lambda n : n % 6
        sage: w = Word(f); w
        word: 0123450123450123450123450123450123450123...
        sage: w.length()
        +Infinity

    Python

        >>> from sage.all import *
        >>> f = lambda n : n % Integer(6)
        >>> w = Word(f); w
        word: 0123450123450123450123450123450123450123...
        >>> w.length()
        +Infinity