In computer science, the complexity function of a word or string (a finite or infinite sequence of symbols from some alphabet) is the function that counts the number of distinct factors (substrings of consecutive symbols) of that string. More generally, the complexity function of a formal language (a set of finite strings) counts the number of distinct words of given length.
Let u be a (possibly infinite) sequence of symbols from an alphabet. Define the functionpu(n) of a positive integer n to be the number of different factors (consecutive substrings) of length n from the string u.[1] [2] [3] [4]
For a string u of length at least n over an alphabet of size k we clearly have
1\lepu(n)\lekn ,
An aperiodic sequence is one which is not ultimately periodic. An aperiodic sequence has strictly increasing complexity function (this is the Morse–Hedlund theorem),[8] so p(n) is at least n+1.[9]
A set S of finite binary words is balanced if for each n the subset Sn of words of length n has the property that the Hamming weight of the words in Sn takes at most two distinct values. A balanced sequence is one for which the set of factors is balanced.[10] A balanced sequence has complexity function at most n+1.[11]
A Sturmian word over a binary alphabet is one with complexity function n + 1.[12] A sequence is Sturmian if and only if it is balanced and aperiodic.[13] [14] An example is the Fibonacci word.[12] [15] More generally, a Sturmian word over an alphabet of size k is one with complexity n+k−1. An Arnoux-Rauzy word over a ternary alphabet has complexity 2n + 1:[12] an example is the Tribonacci word.[16]
For recurrent words, those in which each factor appears infinitely often, the complexity function almost characterises the set of factors: if s is a recurrent word with the same complexity function as t are then s has the same set of factors as t or δt where δ denotes the letter doubling morphism a → aa.[17]
Let L be a language over an alphabet and define the function pL(n) of a positive integer n to be the number of different words of length n in L[18] The complexity function of a word is thus the complexity function of the language consisting of the factors of that word.
a(bb)*a
L\subseteq\{xykz:x,y,z\inF, k\inN\} .
A polynomial or sparse language is one for which the complexity function p(n) is bounded by a fixed power of n. A regular language which is not polynomial is exponential: there are infinitely many n for which p(n) is greater than kn for some fixed k > 1.[19]
The topological entropy of an infinite sequence u is defined by
Htop(u)=\limn
logpu(n) | |
nlogk |
.
The limit exists as the logarithm of the complexity function is subadditive.[20] [21] Every real number between 0 and 1 occurs as the topological entropy of some sequence is applicable,[22] which may be taken to be uniformly recurrent[23] or even uniquely ergodic.[24]
For x a real number and b an integer ≥ 2 then the complexity function of x in base b is the complexity function p(x,b,n) of the sequence of digits of x written in base b.If x is an irrational number then p(x,b,n) ≥ n+1; if x is rational then p(x,b,n) ≤ C for some constant C depending on x and b.[25] It is conjectured that for algebraic irrational x the complexity is bn (which would follow if all such numbers were normal) but all that is known in this case is that p grows faster than any linear function of n.[26]
The abelian complexity function pab(n) similarly counts the number of occurrences of distinct factors of given length n, where now we identify factors that differ only by a permutation of the positions. Clearly pab(n) ≤ p(n). The abelian complexity of a Sturmian sequence satisfies pab(n) = 2.[27]
. M. Lothaire . Algebraic combinatorics on words . With preface by Jean Berstel and Dominique Perrin . Reprint of the 2002 hardback . Encyclopedia of Mathematics and Its Applications . 90. Cambridge University Press . 2011 . 978-0-521-18071-9 . 1221.68183 .