# Construction of regular languages and recognizability of polynomials

## 1 Introduction

Recently, P. Lecomte and I have introduced in  the concept of numeration system on a regular language. A numeration system is a triple $`(L,\mathrm{\Sigma },<)`$ where $`L`$ is an infinite regular language over a totally ordered finite alphabet $`(\mathrm{\Sigma },<)`$. The lexicographic ordering of $`L`$ gives a one-to-one correspondence $`\mathrm{r}_S`$ between the set of the natural numbers $``$ and the language $`L`$.

For each $`n`$, $`\mathrm{r}_S(n)`$ denotes the $`(n+1)^{th}`$ word of $`L`$ with respect to the lexicographic ordering and is called the $`S`$-representation of $`n`$.

For $`wL`$, we set $`\mathrm{val}_S(w)=\mathrm{r}_S^1(w)`$ and we call it the numerical value of $`w`$.

When one has a simple method to represent integers, some natural questions about “recognizability” arise. By recognizability, one means the following. Let $`S`$ be a numeration system and $`X`$ be a subset of $``$. Then $`X`$ is said to be $`S`$-recognizable if $`\mathrm{r}_S(X)`$ is recognizable by a finite automaton. Therefore we can consider two kinds of questions.

$`\mathrm{}`$ For a given numeration system $`S`$, is it possible to determine which subsets of $``$ are $`S`$-recognizable ?

$`\mathrm{}`$ For a given subset $`X`$ of $``$, is it possible to find a numeration system $`S`$ in which $`X`$ is $`S`$-recognizable ?

To give a partial but very important answer to the first question, it is shown in  that arithmetic progressions are always recognizable in any numeration system. It is also shown that if $`X`$ is recognizable for some system $`S`$ then $`X+k`$ is also $`S`$-recognizable. (These two results will be useful in some proofs of this paper.)

In , we were interested in the second question when $`X`$ is the set $`𝒫`$ of primes. It is shown that $`\mathrm{r}_S(𝒫)`$ is never recognizable for any numeration system $`S`$. In this paper, we will be mainly concerned by the second question when $`X`$ is a polynomial image of $``$.

For classical numeration systems with integer base, it is well-known that the set of the perfect squares is not $`k`$-recognizable for any $`k\{0,1\}`$ (see  for a survey about classical numeration systems). However, in  we show quite easily that the numeration system

$$S=(a^{}b^{}a^{}c^{},\{a,b,c\},a<b<c)$$

is such that the set $`\mathrm{r}_S(\{n^2:n\})`$ is regular. The choice of the language $`a^{}b^{}a^{}c^{}`$ was given by some density considerations: this language has exactly $`2n+1`$ words of length $`n`$. In view of this result, J.-P. Allouche asked the following question. Is it possible to generalize the result about the set of the perfect squares to the set $`\{n^k:n\}`$, $`k>2`$ ? Moreover, if $`P`$ is a polynomial belonging to $`[x]`$ (resp. $`[x]`$ or $`[x]`$) such that $`P()`$ then can one find a numeration system such that $`P()`$ is recognizable ?

In all these cases, we answer affirmatively. For a given polynomial $`P`$, we give an explicit method to construct a numeration system such that $`\mathrm{r}_S(P())`$ is regular. For this purpose, we show how to obtain a regular language which contains exactly $`P(n+1)P(n)`$ words of length $`n`$ for $`n`$ large enough. The construction of regular languages with specified density is a problem beyond the concern of numeration systems.

The fact that the set of primes is never recognizable and that the polynomial images of $``$ are recognizable give another interpretation of a well-known result (see \[4, Theorem 21\]): no non constant polynomial $`f(n)`$ with integral coefficients can be prime for all $`n`$, or for all sufficiently large $`n`$.

## 2 Recognizability of polynomials

Our aim will be to construct a numeration system in which $`P()`$ is recognizable when $`P[x]`$ and $`P()`$.

We will proceed in four steps. First of all, we give an explicit iterative method to obtain regular languages such that the number of words of length $`n`$ is exactly $`n^k`$ (in  it is said that such languages can be easily obtained). The languages which are given here can be interpreted as the basic constructors of our method.

In the three other steps, we increase gradually the difficulty. First we consider the case $`P[x]`$ which is quite simple since we only deal with the operation of addition. Next we consider $`P[x]`$; here the problem of substraction must be resolved. Finally, we have the most general case, $`P[x]`$ and the problem of division. In each of these last three steps, we give an instructive short example of construction.

i) Languages with density $`n^k`$

First we recall some basic definitions and operations on languages.

###### Definition 1

The density function of a language $`L\mathrm{\Sigma }^{}`$ is

$$\rho _L::n\mathrm{\#}(\mathrm{\Sigma }^nL)$$

where $`\mathrm{\#}A`$ denotes the cardinality of the set $`A`$.

###### Definition 2

If $`x`$ and $`y`$ are two words of $`\mathrm{\Sigma }^{}`$ then the shuffle of $`x`$ and $`y`$ is the language $`xy`$ defined by

$$\{x_1y_1\mathrm{}x_ny_n:x=x_1\mathrm{}x_n,y=y_1\mathrm{}y_n,x_i,y_i\mathrm{\Sigma }^{},1in,n1\}.$$

If $`L_1,L_2\mathrm{\Sigma }^{}`$ then the shuffle of the two languages is the language

$$L_1L_2=\{w\mathrm{\Sigma }^{}:wxy,\mathrm{for}\mathrm{some}xL_1,yL_2\}.$$

Recall that if $`L_1,L_2`$ are regular then $`L_1L_2`$ is also regular (see for instance \[3, Proposition 3.5\]).

###### Definition 3

Let $`L\mathrm{\Sigma }^{}`$. Then $`\mathrm{\Sigma }`$ is the minimal alphabet of $`L`$ if $`\sigma \mathrm{\Sigma }`$, $`wL:w=u\sigma v,u,v\mathrm{\Sigma }^{}`$.

We want to construct regular languages $`L_k`$ such that $`\rho _{L_k}(n)=n^k`$. The first two languages are, for example, $`L_0=a^{}`$ and $`L_1=a^+b^{}`$.

To construct a language $`L_2`$, we first need a language $`M_2`$ such that $`\rho _{M_2}(n)=n+1`$. We can take $`M_2=a^{}b^{}`$. Hence $`L_2=M_2\{c\}`$. Indeed if one considers the words of length $`n`$ belonging to $`L_2`$, they are obtained from $`n`$ distinct words of length $`n1`$ belonging to $`M_2`$ and for each of these words, $`c`$ can be positioned in $`n`$ different places. Thus one has exactly $`n^2`$ words of length $`n`$ in $`L_2`$. As an example, we have below the construction of the nine words of length $`3`$,

$$\begin{array}{ccc}a^{}b^{}& & a^{}b^{}\{c\}\\ aa& & aac,aca,caa\\ ab& & abc,acb,cab\\ bb& & bbc,bcb,cbb.\end{array}$$

Observe that the letter $`c`$ does not belong to the minimal alphabet of $`M_2`$.

To construct $`L_3`$, we simply need a language $`M_3`$ such that $`\rho _{M_3}(n)=(n+1)^2`$. This can be done using the previously defined languages $`L_0,L_1,L_2`$, each of them written on a different alphabet,

$$M_3=\underset{\rho (n)=n^2}{\underset{}{(a^{}b^{}\{c\})}}\underset{\rho (n)=2n}{\underset{}{d^+e^{}f^+g^{}}}\underset{\rho (n)=1}{\underset{}{h^{}}}.$$

Then we have $`L_3=M_3\{i\}`$.

This procedure can be repeated and thus for any $`k2`$, $`L_k`$ can be obtained as a union of previously constructed languages and one operation of shuffle with a new letter.

In the following, the notations $`M_k`$ and $`L_k`$ will refer to the previously constructed languages such that $`\rho _{M_k}(n)=(n+1)^{k1}`$ and $`\rho _{L_k}(n)=n^k`$.

###### Remark 1

Let $`u_k`$ be the size of the minimal alphabet of $`L_k`$. The construction of $`L_k`$ gives

$$\{\begin{array}{c}u_0=1,u_1=2,u_2=3,\hfill \\ u_m=\underset{k=0}{\overset{m1}{}}u_k\left(\genfrac{}{}{0pt}{}{m1}{k}\right)+1,m3.\hfill \end{array}$$

By direct inspection, one can check that $`u_3=9`$, $`u_4=26`$, $`u_5=90<5!`$ and for $`n=6,\mathrm{},10`$, $`u_n<n!`$. Let $`m11`$. Since $`\left(\genfrac{}{}{0pt}{}{m1}{i}\right)<\left(\genfrac{}{}{0pt}{}{m1}{5}\right)`$ for $`i4`$; one has easily, by recurrence on $`m`$, the following upper bound

$$u_m<\underset{k=0}{\overset{m1}{}}k!\left(\genfrac{}{}{0pt}{}{m1}{k}\right)=e\mathrm{\Gamma }(m,1)<e(m1)!$$

where $`\mathrm{\Gamma }(m,1)`$ is the incomplete gamma function defined by

$$\mathrm{\Gamma }(a,b)=_b^+\mathrm{}t^{a1}e^t𝑑t.$$

###### Remark 2

In view of an earlier version of this paper, J. Shallit suggested another construction of a language $`K`$ such that $`\rho _K(n)=n^k`$. It uses the following result (see \[1, Section 6.5\])

$$n^k=\underset{t=0}{\overset{k}{}}t!S(k,t)\left(\genfrac{}{}{0pt}{}{n}{t}\right)$$

where $`S(k,t)`$ are the Stirling numbers of the second kind. The language over {a,b} with all strings of length $`n`$ containing exactly $`t`$ letters $`b`$ is regular and has a density $`\rho (n)=\left(\genfrac{}{}{0pt}{}{n}{t}\right)`$. Therefore a union of such languages on distinct alphabets gives the language $`K`$.

This construction is perhaps simpler than the construction of $`L_k`$ but uses a greater alphabet. The size of the minimal alphabet is $`\mathrm{max}_{t=0,\mathrm{},k}t!S(k,t)`$ and a lower bound is given by $`k!`$. We won’t use it in the following.

ii) Recognizability of polynomials belonging to $`[x]`$

The main idea is that we have to find a regular language such that the positions of the first words of each length are the values taken by the polynomial.

###### Proposition 4

Let $`P[x]`$. If $`P()`$ then there exists a numeration system $`S=(L,\mathrm{\Sigma },<)`$ such that $`P()`$ is $`S`$-recognizable.

Proof. Since the translation by a constant doesn’t alter the recognizablity of a set, as recalled in the introduction (see  for details), we can assume that $`P(0)=0`$. We have to construct a regular language $`L`$ such that the number of words of length $`n`$ is exactly $`P(n+1)P(n)`$. Since $`P(n+1)P(n)`$ only contains powers of $`n`$ with non-negative integral coefficients, the construction of $`L`$ can be easily achieved by union of languages $`L_k`$ on distinct alphabets (one has a small restriction for the language $`L_0`$; we explain it in the following example to keep this proof simple). To conclude the proof, the reader must recall that if a language $`L`$ is regular then the language $`(L)`$ formed of the smallest words of each length for the lexicographic ordering is still regular . One can check that $`\mathrm{r}_S(P())=(L)`$. $`\mathrm{}`$

###### Example 1

Let $`P(x)=2x^2+3x`$. Then

$$P(x+1)P(x)=4x+5.$$

We consider the language $`L`$ which is formed by four copies of $`L_1`$ and five copies of $`L_0`$.

A very important remark is that with five copies of $`L_0`$, we obtain five words of any positive length but the only one empty word $`\epsilon `$. So to get rid of this problem we add to our language four new words of length $`1`$ (we thus add four letters to the alphabet). This remark applies for all the following constructions: if one uses $`n`$ copies of $`L_0`$ then add $`n1`$ words of length $`1`$ and treat the case $`n=1`$ separately.

One can check that for $`n1`$, the first word of length $`n`$ is the $`[P(n)+1]^{th}`$ word of $`L`$ and

$$\mathrm{r}_S(P(\{1\}))=(L\mathrm{\Sigma }).$$

Therefore $`\mathrm{r}_S(P())`$ is regular since we only add one word for $`\mathrm{r}_S(P(1))`$ to a regular language.

###### Corollary 5

Let $`k\{0,1\}`$. There exist a numeration system $`S`$ such that the set $`\{x^k:x\}`$ is $`S`$-recognizable. $`\mathrm{}`$

iii) Recognizability of polynomials belonging to $`[x]`$

This lemma gets rid of the problem of the coefficients belonging to $``$ instead of $``$.

###### Lemma 6

Let $`k`$ and $`\alpha `$ be two positive integers. There exist a regular language $``$ such that $`\rho _{}(n)=n^k\alpha n^{k1}`$ for all $`n\alpha `$.

Proof. Assume that $`k2`$. Let $`\mathrm{\Sigma }_k`$ be the minimal alphabet of $`M_k`$. Then $`L_k=M_k\{\sigma \}`$ where $`\sigma \mathrm{\Sigma }_k`$. For $`i=1,\mathrm{},n`$, $`L_k`$ has exactly $`n^{k1}`$ words of length $`n`$ with $`\sigma `$ in position $`i`$. From this observation, one can check that

$$=L_k\underset{i=0}{\overset{\alpha 1}{}}\mathrm{\Sigma }_k^{}\sigma \mathrm{\Sigma }_k^i$$

have exactly $`n^k\alpha n^{k1}`$ words of length $`n`$ for $`n\alpha `$. Notice that $`\rho _{}(n)=0`$ if $`n<\alpha `$.

If $`k=1`$ then we have to remove the $`\alpha `$ first words of each length from $`L_1`$,

$$=L_1[\underset{\begin{array}{c}firstwords\\ ofeachlength\end{array}}{\underset{}{(L_1)}}\underset{\begin{array}{c}secondwords\\ ofeachlength\end{array}}{\underset{}{(L_1(L_1))}}\mathrm{}]$$

Notice one more time that $`\rho _{}(n)=0`$ if $`n<\alpha `$. $`\mathrm{}`$

###### Proposition 7

Let $`P[x]`$. If $`P()`$ then there exists a numeration system $`S=(L,\mathrm{\Sigma },<)`$ such that $`P()`$ is $`S`$-recognizable.

Proof. We proceed as in Proposition 4 and consider the polynomial $`Q(n)=P(n+1)P(n)`$. Observe that since $`P()`$, the coefficient of the dominant power in $`P`$ is positive and thus the same remark holds for $`Q`$. By adding extra terms of the form $`x^jx^j`$, if $`\mathrm{deg}(Q)=k`$ we can assume that

$$Q(x)=x^{i_1+1}a_{i_1}x^{i_1}+\mathrm{}+x^{i_r+1}a_{i_r}x^{i_r}+\underset{l=0}{\overset{k}{}}b_lx^l$$

where $`i_1,\mathrm{},i_r\{0,\mathrm{},k1\}`$, $`a_{i_1},\mathrm{},a_{i_r}\{0\}`$ and $`b_0,\mathrm{},b_k`$. Let $`\alpha =sup_{j=1,\mathrm{},r}a_{i_j}`$. Using Lemma 6, for $`j=1,\mathrm{},r`$ we construct languages $`_j`$ such that for all $`n\alpha `$, $`\rho __j(n)=n^{i_j+1}a_{i_j}n^{i_j}`$. The reader can construct easily a language $`L`$ such $`n\alpha `$, $`\rho _L(n)=Q(n)`$ by union of languages $`_j`$ and $`L_l`$.

If we want to consider the smallest word of each length, as in Proposition 4, then the language $`L`$ must contain exactly $`P(\alpha )`$ words of length at most $`\alpha 1`$ (in this case, the first word of length $`\alpha `$ is the $`[P(\alpha )+1]^{th}`$ word of $`L`$ and its numerical value is thus $`P(\alpha )`$). This can be achieved by adding or removing a finite number of words from the regular language $`L`$ (this operation doesn’t alter the regularity of $`L`$). Thus

$$\mathrm{r}_S(\{P(n):n\alpha \})=(L)\mathrm{\Sigma }^\alpha .$$

To conclude we have to add a finite number of words for the representation of $`P(0),\mathrm{},P(\alpha 1)`$ and

$$\mathrm{r}_S(P())=((L)\mathrm{\Sigma }^\alpha )\{\mathrm{r}_S(P(0)),\mathrm{},\mathrm{r}_S(P(\alpha 1))\}.$$

$`\mathrm{}`$

###### Example 2

Let $`P(x)=x^43x^22x+5`$. Then

$`Q(n)=P(n+1)P(n)`$ $`=`$ $`4x^3+6x^22x4`$   
$`=`$ $`4x^3+5x^2+x^23x+x4.`$   
With four copies of $`L_3`$, five copies of $`L_2`$ and using Lemma 6, one can construct a regular language $`L`$ such that<sup>1</sup><sup>1</sup>1Here the expression of $`\rho _L(n)`$ is very simple since $`3`$ and $`4`$ only differ by one unit (remark that $`4n^3+6n^22n4=4n^3+6n^23nn=4`$ and $`4n^3+6n^23n=4n^3+5n^2n=3`$ or $`0`$).

$$\rho _L(n)=\{\begin{array}{cc}4n^3+6n^22n4\hfill & \mathrm{if}n4\hfill \\ 4n^3+5n^2\hfill & \mathrm{otherwise}.\hfill \end{array}$$

We have $`P(4)=205`$ and the number of words of length at most $`3`$ belonging to $`L`$ is $`214`$ thus we remove $`9`$ words of length at most $`3`$ in $`L`$. Therefore, the first word of length $`4`$ in $`L`$ is the representation of $`P(4)`$ and

$$\mathrm{r}_S(\{P(n):n4\})=(L)\mathrm{\Sigma }^4$$
(1)   
is a regular subset of $`L`$. Since $`\{P(0),\mathrm{},P(3)\}`$ is equal to $`\{1,5,53\}`$, we add the second, the $`6^{th}`$ and the $`54^{th}`$ word of $`L`$ to (1) to obtain $`\mathrm{r}_S(P())`$.

###### Example 3

We begin another example which show how to obtain a correct expression for $`\rho _L(n)`$ in a trickier situation. Let $`P(x)=x^54x^32x^2+8`$, then

$$Q(x)=5x^4+9x^3+x^33x^2+x^212x+x5.$$

To construct a language $`L`$, we use five copies of $`L_4`$, nine copies of $`L_3`$ and apply three times Lemma 6. Thus

$$\rho _L(n)=\{\begin{array}{cc}Q(n)\hfill & \mathrm{if}n12\hfill \\ 5n^4+10n^33n^2+n5\hfill & \mathrm{if}12>n5\hfill \\ 5n^4+10n^33n^2\hfill & \mathrm{if}5>n3\hfill \\ 5n^4+9n^3\hfill & \mathrm{otherwise}.\hfill \end{array}$$

iv) Recognizability of polynomials belonging to $`[x]`$

Finally, we obtain the theorem of recognizability in the general case.

###### Theorem 8

Let $`P[x]`$. If $`P()`$ then there exists a numeration system $`S=(L,\mathrm{\Sigma },<)`$ such that $`P()`$ is $`S`$-recognizable.

Proof. Let

$$P(x)=\frac{a_k}{b_k}x^k+\frac{a_{k1}}{b_{k1}}x^{k1}+\mathrm{}+\frac{a_0}{b_0}$$

with $`b_0,\mathrm{},b_k,a_k\{0\}`$ and $`a_0,\mathrm{},a_{k1}`$. Let $`s`$ be the least common multiple of $`b_0,\mathrm{},b_k`$. One has

$$P=\frac{P^{}}{s}$$

with $`P^{}[x]`$. By hypothesis $`P()`$; thus $`P^{}()s`$. As in Proposition 7, there exist a constant $`\alpha `$ and a language $`L^{}`$ such that $`n\alpha `$,

$$\rho _L^{}(n)=P^{}(n+1)P^{}(n)=s[P(n+1)P(n)].$$

We modify $`L^{}`$ (by adding or removing a finite number of words) to have

$$\underset{i=0}{\overset{\alpha 1}{}}\rho _L^{}(i)=sP(\alpha ).$$

It was proved in  that the arithmetic progression $`s`$ is recognizable for any numeration system. Let $`S^{}=(L^{},\mathrm{\Sigma },<)`$ then $`L=\mathrm{r}_S^{}(s)`$ is a regular language such that

$$\underset{i=0}{\overset{\alpha 1}{}}\rho _L(i)=P(\alpha )\mathrm{and}n\alpha ,\rho _L(n)=P(n+1)P(n).$$

We conclude as in Proposition 7. $`\mathrm{}`$

###### Example 4

Let

$`P(x)`$ $`=`$ $`{\displaystyle \frac{x^4}{3}}2x^3+{\displaystyle \frac{37}{6}}x^2{\displaystyle \frac{17}{2}}x+4`$   
$`=`$ $`{\displaystyle \frac{1}{3}}(x7)x^2(x+1)+{\displaystyle \frac{17}{2}}x(x1)+4.`$   
The reader can check easily that $`P()`$. We have $`s=6`$ and

$`P^{}(n+1)P^{}(n)`$ $`=`$ $`8n^324n^2+46n24`$   
$`=`$ $`7n^3+45n+n^324n^2+n24.`$   
Using seven copies of $`L_3`$, $`45`$ copies of $`L_1`$ and applying Lemma 6 twice, we construct a language $`L^{}`$ such that

$$\rho _L^{}(n)=\{\begin{array}{cc}6(P(n+1)P(n))\hfill & \mathrm{if}n24\hfill \\ 7n^3+45n\hfill & \mathrm{otherwise}.\hfill \end{array}$$

The number of words of length at most $`23`$ in $`L^{}`$ is $`545652`$ and $`6P(24)=517776`$. Thus we remove $`27876`$ words from $`L^{}\mathrm{\Sigma }^{23}`$. In this new language lexicographically ordered, we only take the words at position $`6i+1`$, $`i`$, to obtain the regular language $`L`$. Thus the $`[P(24)+1]^{th}`$ word of $`L`$ is the first word of length $`24`$ belonging to $`L`$ and

$$\mathrm{r}_S(\{P(n):n24\})=(L)\mathrm{\Sigma }^{24}.$$

To conclude, we have as usual to add a finite number of words for the representation of $`P(0),\mathrm{},P(23)`$.

###### Remark 3

In , we have studied the problem of changing the ordering of the alphabet and we have exhibit some subset $`X`$ of $``$ and some numeration systems $`S`$ and $`S^{}`$ which only differ by the ordering of the alphabet such that $`\mathrm{r}_S(X)`$ is regular and $`\mathrm{r}_S^{}(X)`$ not.

This kind of singularity doesn’t appear here. For a given polynomial $`P`$, we have shown how to construct a particular numeration system $`S=(L,\mathrm{\Sigma },<)`$ such that $`P()`$ is $`S`$-recognizable. By construction, one can easily check that $`P()`$ is also $`T`$-recognizable for any system $`T=(L,\mathrm{\Sigma },)`$ where $``$ is a reordering of $`\mathrm{\Sigma }`$.

## 3 Acknoledgments

The author would like to thank J.-P. Allouche and P. Lecomte for their support and fruitful conversations. We also thank J. Shallit for his valuable suggestions.