Complexity function


In computer science, the complexity function of a string, a finite or infinite sequence of letters from some alphabet, is the function that counts the number of distinct factors from that string. More generally, the complexity function of a language, a set of finite words over an alphabet, counts the number of distinct words of given length.

Complexity function of a word

Let u be a sequence of symbols from an alphabet. Define the function
pu of a positive integer n to be the number of different factors of length n from the string u.
For a string u of length at least n over an alphabet of size k we clearly have
the bounds being achieved by the constant word and a disjunctive word, for example, the Champernowne word respectively. For infinite words u, we have pu bounded if u is ultimately periodic. Conversely, if pun for some n, then u is ultimately periodic.
An aperiodic sequence is one which is not ultimately periodic. An aperiodic sequence has strictly increasing complexity function, so p is at least n+1.
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. A balanced sequence has complexity function at most n+1.
A Sturmian word over a binary alphabet is one with complexity function n + 1. A sequence is Sturmian if and only if it is balanced and aperiodic. An example is the Fibonacci word. 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: an example is the Tribonacci word.
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 aaa.

Complexity function of a language

Let L be a language over an alphabet and define the function pL of a positive integer n to be the number of different words of length n in L The complexity function of a word is thus the complexity function of the language consisting of the factors of that word.
The complexity function of a language is less constrained than that of a word. For example, it may be bounded but not eventually constant: the complexity function of the regular language takes values 3 and 4 on odd and even n≥2 respectively. There is an analogue of the Morse–Hedlund theorem: if the complexity of L satisfies pLn for some n, then pL is bounded and there is a finite language F such that
A polynomial or sparse language is one for which the complexity function p 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 is greater than kn for some fixed k > 1.

Related concepts

The topological entropy of an infinite sequence u is defined by
The limit exists as the logarithm of the complexity function is subadditive. Every real number between 0 and 1 occurs as the topological entropy of some sequence is applicable, which may be taken to be uniformly recurrent or even uniquely ergodic.
For x a real number and b an integer ≥ 2 then the complexity function of x in base b is the complexity function p of the sequence of digits of x written in base b.
If x is an irrational number then pn+1; if x is rational then pC for some constant C depending on x and b. It is conjectured that for algebraic irrational x the complexity is bn but all that is known in this case is that p grows faster than any linear function of n.
The abelian complexity function pab 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 pabp. The abelian complexity of a Sturmian sequence satisfies pab = 2.