    # On the binomial equivalence classes of finite words

Two finite words u and v are k-binomially equivalent if, for each word x of length at most k, x appears the same number of times as a subsequence (i.e., as a scattered subword) of both u and v. This notion generalizes abelian equivalence. In this paper, we study the equivalence classes induced by the k-binomial equivalence with a special focus on the cardinalities of the classes. We provide an algorithm generating the 2-binomial equivalence class of a word. For k ≥ 2 and alphabet of 3 or more symbols, the language made of lexicographically least elements of every k-binomial equivalence class and the language of singletons, i.e., the words whose k-binomial equivalence class is restricted to a single element, are shown to be non context-free. As a consequence of our discussions, we also prove that the submonoid generated by the generators of the free nil-2 group on m generators is isomorphic to the quotient of the free monoid { 1, ... , m}^* by the 2-binomial equivalence.

## Authors

##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1. Introduction

Let be a totally ordered alphabet of the form . We make use of the same notation for the induced lexicographic order on .

Let be an equivalence relation on . The equivalence class of the word is denoted by . We will be particularly interested in two types of subsets of with respect to . We let

 LL(∼,Σ)={w∈Σ∗∣∀u∈[w]∼:w≤u}

denote the language of lexicographically least elements of every equivalence class for . So there is a one-to-one correspondence between and . We let

 Sing(∼,Σ)={w∈Σ∗∣#[w]∼=1}

denote the language made of the so-called -singletons, i.e., the elements whose equivalence class is restricted to a single element. Clearly, we have . In the extensively studied context of Parikh matrices (see Section 2), two words are -equivalent if they have the same Parikh matrix. In that setting, singletons are usually called -unambiguous words and have attracted the attention of researchers, see, for instance,  and the references therein.

Let be an integer. Let be the -abelian equivalence relation introduced by Karhumäki . Two words are -abelian equivalent if they have the same number of factors of length at most . If , the words are abelian equivalent. We denote by the

Parikh vector

of the finite word , defined as

 Ψ(u)=(|u|1,…,|u|m),

where is the number of occurrences of the letter in . Two words and are abelian equivalent if and only if .

The -abelian equivalence relation has recently received a lot of attention, see, for instance, [9, 10]. In particular, the number of -abelian singletons of length is studied in . Based on an operation of -switching, the following result is given in .

###### Theorem 1.

Let . Let be a -letter alphabet. For the -abelian equivalence, the two languages and are regular.

As discussed in Section 2, the set of -unambiguous words over a -letter alphabet is also known to be regular. Motivated by this type of results, we will consider another equivalence relation, namely the -binomial equivalence introduced in , and study the corresponding sets and .

###### Definition 2.

We let the binomial coefficient denote the number of times appears as a (not necessarily contiguous) subsequence of . Let be an integer. Two words and are -binomially equivalent, denoted , if for all words of length at most .

We will show that -abelian and -binomial equivalences have incomparable properties for the corresponding languages and . These two equivalence are both a refinement of the classical abelian equivalence and it is interesting to see how they differ. As mentioned by Whiteland in his Ph.D. thesis: “part of the challenges in this case follow from the property that a modification in just one position of a word can have global effects of the distribution of subwords, and thus the structure of the equivalence classes.” .

This paper is organized as follows. The special case of -binomial equivalence over a -letter alphabet is presented in Section 2: the corresponding languages are known to be regular. In Section 3, we discuss an algorithm generating the -binomial equivalence class of any word over an arbitrary alphabet. Then we prove that the submonoid generated by the generators of the free nil- group on generators is isomorphic to . Section 4 is about the growth rate of . As a consequence of Sections 3 and 4, the growth function for the submonoid generated by the generators of the free nil- group on generators is in . In the last section, contrasting with Theorem 1, we show that and are rather complicated languages when and : they are not context-free.

## 2. 2-binomial equivalence over a 2-letter alphabet

Let be a -letter alphabet. Recall that the Parikh matrix associated with a word is the matrix given by

 P(w)=⎛⎜⎝1|w|1(w12)01|w|2001⎞⎟⎠.

For , can be deduced from . Indeed, we have and if ,

 (1) (waa)+(wab)+(wba)+(wbb)=(|w|a+|w|b2).

It is thus clear that if and only if . We can therefore make use of the following theorem of Fossé and Richomme . If two words and over an arbitrary alphabet can be factorized as and with , we write . The reflexive and transitive closure of this relation is denoted by .

###### Theorem 3.

Let be two words over . The following assertions are equivalent:

• the words and have the same Parikh matrix;

• the words and are -binomially equivalent;

• .

Consequently, the language avoiding two separate occurrences of and (or, and ) is regular. A regular expression for this language is given by

 1∗2∗+2∗1∗+1∗21∗+2∗12∗+1∗212∗+2∗121∗.

A NFA accepting was given in .

###### Remark 4.

From , we know that

 #LL(∼2,{1,2})=#({1,2}n/∼2)=n3+5n+66.

Note that this is exactly the sequence A000125 of cake numbers, i.e., the maximal number of pieces resulting from planar cuts through a cube.

###### Proposition 5.

The language is regular.

###### Proof.

As a consequence of Theorem 3, if a word belongs to , it cannot be of the form because otherwise, the word belongs to the same class and is lexicographically less. Consequently,

 LL(∼2,{1,2})⊆{1,2}∗∖{1,2}∗21{1,2}∗12{1,2}∗.

The reader can check that the language in the r.h.s. has exactly words of length . We conclude with the previous remark that the two languages are thus equal. ∎

## 3. 2-binomial equivalence over a m-letter alphabet

Theorem 3 does not hold for ternary or larger alphabets. Indeed, the two words and are -binomially equivalent but both words belong to which means that . It is therefore meaningful to study over larger alphabets and to describe the -binomial equivalence classes.

The first few terms of are given by

 1,3,9,27,78,216,568,1410,….

This sequence also appears in the Sloane’s encyclopedia as entry A140348 which is the growth function for the submonoid generated by the generators of the free nil- group on three generators. In this section, we make explicit the connection between these two notions (see Theorem 11).

Recall that the commutator of two elements belonging to a multiplicative group is . Hence, the following relations hold

 xy=yx[x,y]∀x,y∈G.

A nil- group is a group for which the commutators belong to the center , i.e.,

 (2) [x,y]z=z[x,y]∀x,y,z∈G.

Let . The free nil- group on generators has thus a presentation

 N2(Σ)=⟨Σ∣[x,y]z=z[x,y] (x,y,z∈Σ)⟩.

As an example, making use of these relations, let us show that two elements of the free group on are equivalent in :

 12321=(12[2,1])[1,2]321=21[1,2]321=213(21[1,2])=21312.

Let be the alphabet of the inverse letters, that we suppose disjoint from . By abuse of notation, for all , is the letter . Since is the quotient of the free monoid under the congruence relations generated by and (2), we will consider the natural projection denoted by

 π:(Σ∪Σ−1)∗→N2(Σ).

In Section 3.1, we provide an algorithmic description of any -binomial class. We make use of this description in Section 3.2 to show that the monoid is isomorphic to the submonoid, generated by , of the nil- group .

### 3.1. A nice tree

Let be a word over and the lexicographically least element in its abelian equivalence class, i.e.,

 ℓ=1|w|12|w|2⋯m|w|m.

Consider the following algorithm that, given , produces the word only by exchanging adjacent symbols. We let denote the longest common prefix of two finite words and . We define a sequence of words starting with .

,

while

thus and with and

consider the leftmost occurring in , i.e,

and only contains letters less than .

for to

###### Remark 6.

It can easily be shown that, at the beginning of each iteration of the while loop, the word is the least lexicographic word of its abelian class. It follows that and only contains letters less than .

In the for loop, the two letters and are exchanged. Observe that . After the for loop, the two letters and are exchanged (and again ). We record the sequence and number of exchanges of the form for all with that are performed when executing the algorithm.

Using (1), the next lemma is obvious.

###### Lemma 7.

Two abelian equivalent words are -binomially equivalent if and only if for all with . Let be a word in . In the set of tuples of size

 {((w12),…,(w1m),(w23),…,(w)2m,…,(w(m−1)m))∣w∈[ℓ]∼1},

the greatest element, for the lexicographic ordering, is achieved for .

We consider the coefficients with . Note that, in the algorithm, if is obtained from by an exchange of the form , all these coefficients remain unchanged except for

 (3) (ℓj+1ab)=(ℓjab)−1.
###### Corollary 8.

When applying the algorithm producing the word from the word , the total number of exchanges , with , is given by

 (ℓab)−(wab)=(wba).

Consequently two words are -binomially equivalent if and only if they are abelian equivalent and the total number of exchanges of each type , , when applying the algorithm to these two words, is the same. An equivalence class is thus completely determined by a word and the numbers of different exchanges. We obtain an algorithm generating all words of .

###### Definition 9.

Let us build a (directed) tree whose vertices are words, the root is . There exists an edge from to if and only if is obtained by an exchange of the type , , from . The edge is labeled with the applied exchange.

To generate the -equivalence class of , it suffices to take all the nodes that are at level such that the path from to the node is composed of edges labeled by , for all letters . Note that a polynomial time algorithm checking whether or not two words are -binomially equivalent has been obtained in  and is of independent interest.

###### Example.

Let us consider the word on the alphabet . Its -equivalence class is . It can be read from the tree in Figure 1. Some comments need to be done about this figure. The edges labeled by (resp., , ) are represented in black (resp., red, green). In every node, the vertical line separates the longest common prefix (denoted by in the algorithm) between the word in the node and the word from we are going to reach. If the current node can be written while the word can be written , the underlined letter corresponds to the leftmost occurring in (see the algorithm). Finally, when building the tree, if a path has a number of black (resp. red, green) edges greater than (resp., , ), it is useless to continue computing children of this node, since they won’t lead to an element of .

### 3.2. Isomorphism with a nil-2 submonoid

Since we are dealing with the extended alphabet , let us first introduce a convenient variation of binomial coefficients of words taking into account inverse letters.

###### Definition 10.

Let be an integer. For all words over the alphabet and , let us define

 [uv]=∑(e1,…,et)∈{−1,1}t(t∏i=1ei)(uve11⋯vett),

where is the usual binomial coefficient over the alphabet . Let and denote

 Φ(w)=([w1],…,[wm],[w12],…,[wm(m−1)])⊺∈Zm2

where the last components are obtained from all the words made of two different letters in , ordered by lexicographical order.

Notice that, if and are words over , then

 [uv]=(uv)

and so, and are -binomially equivalent if and only if .

###### Example.

Let and . Applying the previous definition, for all , we have

 [wa]=(wa)−(wa−1).

Similarly, for all , we have

 (4) [wab]=(wab)−(wa−1b)−(wab−1)+(wa−1b−1).

Therefore, computing classical binomial coefficients, we obtain

 Φ(w)= (0,2,0,2,0,−2,1,0,−1)⊺.

We are now ready to prove the main result of this section.

###### Theorem 11.

Let . The monoid is isomorphic to the submonoid, generated by , of the nil- group .

###### Proof.

Let us first show that for any two words and over such that , the relation holds. Indeed, using (4) one can easily check that, for all and , we have

 [stab]=[sab]+[tab]+[sa][tb].

Now, one can show that, for all and ,

 Φ(uv)=Φ(uxx−1v) and Φ(u[x,y]zv)=Φ(uz[x,y]v).

For instance, let with ,

 [uxx−1vab] =[uab]+[xx−1vab]+[ua][xx−1vb] =[uab]+[xx−1ab]=0+[vab]+[xx−1a]=0[vb]+[ua].⎛⎜ ⎜ ⎜ ⎜⎝[xx−1b]=0+[vb]⎞⎟ ⎟ ⎟ ⎟⎠ =[uvab].

This implies that a map can be defined on the free nil- group (otherwise stated, the diagram depicted in Figure 2 is commutative) by

 ∀r∈N2(Σ),ΦN(r)=Φ(w) for any w % such that π(w)=r.

In particular, if and are words over such that , then we may conclude that meaning that they are -binomially equivalent. Otherwise stated, for every , is a subset of an equivalence class for .

To conclude the proof, we have to show that all the elements of an equivalence class for are mapped by on the same element of . Let be such that . Using the algorithm described in Section 3.1, there exists a path in the associated tree from the root to and another one to . By definition of the commutator, if is written with , then . Moreover, since the commutators are central in .

Therefore, following backwards the path from to the root of the tree and recalling that each edge corresponds to an exchange of letters, we obtain

 π(u)=π(1|u|12|u|2⋯m|u|m[2,1](u21)⋯[m,1](um1)⋯[m,m−1](um(m−1)))

and, similarly, following backwards the path from to the root,

 π(v)=π(1|v|12|v|2⋯m|v|m[2,1](v21)⋯[m,1](vm1)⋯[m,m−1](vm(m−1))).

But since , we get . ∎

## 4. Growth order

We first show that the growth of is bounded by a polynomial in . This generalizes a result from  for a binary alphabet. Note that a similar result was obtained in 

. Next, we obtain better estimates for

.

###### Proposition 12.

Let and . We have

 #(Σn/∼k)∈O(nk2mk)

when tends to infinity.

###### Proof.

For every such that and , we have

 0≤(uv)≤(|u||v|)≤n|v|≤nk.

Therefore, for every such that , we have

 #{(uv):|u|=n}≤nk+1.

By definition, the -equivalence class of is uniquely determined by the values of for all such that . There are

 k∑i=1mi≤kmk

such coefficients and thus,

 #(Σn/∼k)≤(nk+1)kmk.

We have obtained an upper bound which is far from being optimal but it ensures that the growth is polynomial. However, for , it is possible to obtain the polynomial degree of the growth. We make use of Landau notation: if there exist constants such that, for all large enough, .

###### Proposition 13.

Let be an alphabet of size . We have

 #(Σn/∼2)∈Θ(nm2−1)

when tends to infinity.

###### Proof.

Let be the function such that for any ,

 f(x)=#({u∈Σ∗:Ψ(u)=x}/∼2).

In other words, counts the number of -binomial equivalence classes whose Parikh vector is . Let be the -norm (i.e., for all vectors , ). Clearly for all ,

 (5) #(Σn/∼2)=∑x∈Nm,||x||1=nf(x).

For any , , and , and . Any word has its equivalence class uniquely determined by the values of for all and for all . Moreover, for all and , . We deduce that for all ,

 f(x)≤∏1≤a

From equation (5), we get that

 #(Σn/∼2) ≤∑x∈Nm,||x||1=n||x||m(m−1)1 #(Σn/∼2) ≤nm(m−1)#{x∈Nm:||x||1=n} #(Σn/∼2) ≤nm(m−1)(n+1)m−1≤(n+1)m2−1.

We conclude that when . It remains to get a convenient lower bound.

For any , , and , let

 La,b,i,j={u∈{a,b}∗:|u|a=i,|u|b=j}.

Considering all possible letter exchanges as in (3) from to , the binomial coefficient decreases by at every step from to , we thus have

 (6) {(uab):u∈La,b,i,j}={0,1,…,ij}

which is a set of cardinality . For any , let us consider the following language

 L(x)=(m∏a=1m∏b=a+1La,b,⌊xam−1⌋,⌊xbm−1⌋)1∏a=maxa%(m−1),

where the products must be understood as languages concatenations, the indices of the last product are taken in decreasing order, and is the remainder of the Euclidean division of by .

For instance for ,

 L(x)={u1,2u1,3u2,3r3r2r1:∀a,b∈Σ,ua,b∈La,b,⌊xa2⌋,⌊xb2⌋,ra=axa%2}.

Roughly speaking, for every and , we will show that mostly depends on and takes a quadratic number of values (when choosing accordingly). Furthermore, the role of

words is limited to padding. Indeed, observe that for all

, .

Let and . Then, by definition, there exist words with, for all , , such that

 u=(m∏a=1m∏b=a+1ua,b)1∏a=maxa%(m−1).

Let and be two integers such that and let us compute the binomial coefficient associated with . A subword either occurs in a single factor of the above product (the first two terms below), or and appear in two different factors:

 (uij) =m∑a=1m∑b=a+1(ua,bij)+1∑a=m(axa%(m−1)ij) +∑a(a,b)∣∣ua′,b′∣∣j+∑b∈Σ∣∣bxb%(m−1)∣∣j⎞⎟ ⎟ ⎟⎠ +m∑a=1a−1∑b=1∣∣axa%(m−1)∣∣i∣∣bxb%(m−1)∣∣j.

Observe that by definition of , the second and last terms vanish. Hence,

 (uij) =(ui,jij)+∑a(a,b)a′=j or b′=j⌊xjm−1⌋⎞⎟ ⎟ ⎟ ⎟ ⎟ ⎟⎠+xj%(m−1)⎞⎟ ⎟ ⎟ ⎟ ⎟ ⎟⎠:=hi,j(x)

The second term of the latter expression is uniquely a function of (there is no dependency on ) while, from (6),

 {(ui,jij):ui,j∈Li,j,⌊xim−1⌋,⌊xjm−1⌋}={0,1,…,⌊xim−1⌋⌊xjm−1⌋+1}.

Thus for a fixed , considering all , can take different values. Moreover, for all such that

 ai,j∈{hi,j(x),…,hi,j(x)+⌊xim−1⌋⌊xjm−1⌋}∀i

there exists such that for all . We deduce that, for all ,

 f(x)≥∏a

By equation (5), we finally get the lower bound:

 #(Σn/∼2) ≥∑x∈Nm||x||1=n∏a