Sébastien Labbé
unread,Nov 16, 2012, 6:03:53 PM11/16/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sage-...@googlegroups.com
Hi,
In combinatorics on words, we often deal with infinite sequences, and there is code in Sage to deal with these things. After that, I don't know if the question you want to ask to those objects are the same as the problems considered in combinatorics on words (like, computing the factor complexity, amongst other things). But, at least, you can take a look at it to see how it works.
So, an infinite word can be defined as a function from the non negative integers to an certain alphabet :
sage: Word(lambda n: n^3 % 7)
word: 0116166011616601161660116166011616601161...
Or as an infinite iterator :
sage: Word(primes(0, infinity))
word: 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,...
Well known infinite sequence on {0,1} include the Fibonacci sequence :
sage: words.FibonacciWord()
word: 0100101001001010010100100101001001010010...
The Fibonacci word is also the infinite fixed point of the following morphism (another way of creating an infinite sequence in Sage) :
sage: m = WordMorphism('0->01,1->0')
sage: m.fixed_point('0')
word: 0100101001001010010100100101001001010010...
For any infinite word, there are some methods available, like get the i^th term or slice it :
sage: P = Word(primes(0, infinity))
sage: P[1000]
7927
sage: P[100000:100006]
word: 1299721,1299743,1299763,1299791,1299811,1299817
In this last case, it returns a finite word :
sage: type(_)
<class 'sage.combinat.words.word.FiniteWord_iter_with_caching'>
Compute the finite differences, and so on...
sage: P.finite_differences()
word: 1,2,2,4,2,4,2,4,6,2,6,4,2,4,6,6,2,6,4,2,6,4,6,8,4,2,4,2,4,14,4,6,2,10,2,6,6,4,6,6,...
Cheers,
Sébastien