There are many parts of number theory I don't know of, and today's story is about one I learnt very recently, at the intersection of number theory and computer science. It is about the natural numbers that we can recognize using a finite automaton.
Finite automata and automatic functions
Finite automata
Finite automata are very elementary computers. These machines can receive instructions of finitely many sorts, and can be in finitely many states; moreover, their behaviour is prescribed: when, in a given state, they receive one instruction, they just move to another state. Mathematically, one can say that there is a finite set of instructions, a finite set of states, and a mapping . One state is labeled as the initial state; wen reading a list of instructions , the machine goes through the states , , , etc. until it reaches and outputs its the final state . All in all, the automaton defines a function from the set of lists in to the set . Such functions are called automatic.
In practice, some states could be labeled as admissible, in which case the machine unlocks the door, and the set of lists such that is admissible is then called the language of the automaton.
The basic question of automata theory is to describe the (so-called “regular”) languages recognizable by some automaton, more generally the automatic functions. It appears that they are of a very restricted nature: due to the elementary nature of finite automata, they are much more restricted than the kind of languages that would be recognizable by a program in the programming language of your choice. The reason is that they have a fixed memory while “theoretical” computers, as modelled by Turing machines for example, have a potentially infinite memory, that is, as large as the computation may require.
Numbers
Number theory enters when you decide that the set of instructions are digits 0, 1, 2,…, 9 and the lists in represent a number. You then wish to understand what numbers can be recognizable, or what functions are automatic, for a finite set . This is what happens, for example, in the very elementary finite automata that stand at almost all Paris doors as electronic locks. They recognize exactly one 4-digit number (and any 4-digit number) puts them back in the initial state.
When it comes about digits, they can be the usual ones, 0, 1, 2,… , 9, writing number in base 10, but any other basis can be considered, and any set of digits that allows to write all numbers can be used. For example, one can consider writing numbers in base 3, with digits 0, 1, 2, 3, 4.
Let us thus fix some basis . The first theorem is that the set of automatic functions does not depend on the set of digits which is considered. The reason is that one can build another kind of machine (called a transducer) that works like a finite automaton except that it output something at each step. Here, we can have a transducer that outputs the digits in some representation given the digits in another one. There could be carries to take care of, but when the basis is the same, their impact is controlled, and it can be controlled by finitely many of them. It is important for this argument that the basis stays the same, and we will see that in a more striking way later on. For this reason, we will not specify the set of digits in the sequel.
Examples
Here are some examples of recognizable sets of numbers.
- The empty set works. It suffices to have no terminal state.
- Singletons work. For example, to recognize “314”, one needs one initial state “”, three states labeled “3”, “31” and “314”, and a junk state “J”. The machine moves from “” to “3” if it receives “3”, and to “J” otherwise; from “3” to “31” if it receives “1”, etc.
- The union and the intersection of two recognizable sets are recognizable. Just make an automaton whose sets are pair of states of the two automata that recognize the given states, and simulate the moves of each of them. Similarly, the complement of a recognizable set is recognizable.
- By the previous examples, finite sets and complements of finite sets are recognizable.
- Here is a number theoretically more interesting example : arithmetic progressions are recognizable. To produce an automaton that, say, recognize all integers congruent to 1 modulo 4, it suffices to have a machine with 4 states that computes the euclidean reminder step by step.
- Another number theoretically interesting example: powers of . Indeed their writing in base consists of one digit “1” followed by a series of “0”.
- A number theoretically annoying property of recognizable sets: since a finite automaton has finitely many states, the “pumping lemma” shows that for any large enough recognizable number, one can replicate at will some inner part of the writing and get another number. I suppose one can deduce from this property that the set of prime numbers cannot be recognizable. (This is exercise 5.8.12 in the book Automatic sequences, by J-P. Allouche and J. Shallit.)
- Numbers recognizable in base are also recognizable in base (or some other power) and conversely: it suffices to emulate the base -writing of a number using base -digits, or conversely.
Building from characteristic functions of admissible languages, the preceding results can be turned to examples of automatic functions. In particular, we obtain that functions which are ultimately periodic are automatic.
Cobham's theorem
Statement
Number theory can also enter a topic from two sides at a time, and here is the point of this blog post. Can one compare the sets of recognizable numbers from different bases? By the following theorem, they are genuinely distinct.
Theorem (Cobham, 1969). — Let be a finite set and let be a function which is automatic in two bases and .
If and are not powers of the same integer, then
is ultimately periodic.
Since ultimately periodic functions are automatic in any basis,
this theorem is definitely optimal.
The original proof of Cobham's theorem is said to be difficult, and this theorem has obtained various other simpler proofs, often partially flawed. I wish to describe here the recent proof by Thijmen Krebs (publisher version, arXiv:1801.06704) which calls itself “more reasonable”.
The assumption that and are not powers of the same integer will appear in different, equivalent, form in the proof: they do not have common powers.
Local periods
To prove that is ultimately periodic, Krebs proves that is periodic on large overlapping intervals.
Lemma 1. — Let be a function and let and be intervals of integers. We assume that has period on and period on . If , then has period on the interval .
The proof is elementary. Consider such that . If both and belong to , then . Let us assume otherwise. If belongs to , but not , then ; since has at least elements, must belongs to . The other cases are similar and show that both belong to . Using that is large, we pick up elements in such that . Then , the first and last equality using the -periodicity on , and the middle one the -periodicity on .
A diophantine approximation lemma
Lemma 2. — Let and be two real numbers such that . For every , there exist nonzero natural numbers and such that .
The result is obvious if and have a common power, so we may assume that this is not the case. Then various proofs are possible. For example, one may consider the additive subgroup of generated by and ; by assumption, it is dense hence there exists a small linear combination ; taking exponentials, is close to~, as claimed.
Krebs gives a “pigeonhole-like” proof which is nice. For every integer , consider the unique integer such that . There must be two integers and such that and such that and differ at most from , and this implies the result.
Some functional equations
Let be a function which is automatic in some basis , computed by an automaton with set of states . For every , let be the set of integers such that . Note that these sets form a partition of .
The following lemma is a variant of the pumping lemma in the theory of automata; it is by it that automatic functions acquire their specific properties.
Lemma 3. — For every integers and any integer such that , one has .
Indeed, when the automaton reads the integer , it first reads , and goes to state ; similarly, when it reads , it first reads and reaches the state too. In both cases it then reads and ends up in the same final state.
Construction of local periods
We now consider a function which is automatic in two bases and which do not have common powers. We thus have two finite automata and , with sets of states and . For each state , we have a set of integers as above; these sets form a partition of . Let be the set of states such that is infinite. For , we define similarly, as well as .
Let . Since the , for , form a finite partition of and is infinite, there exists a state and two distinct integers and . Let be an integer strictly greater than all , for .
Applying lemma 3 for , we obtain integer such that . For , we ; since and have no common power, this is a nonzero integer, and we choose the sign so that it is strictly positive.
For each integer , we define an interval of integers by .
Lemma 4. — For every state and any integer , the function has period on .
To that aim, we consider and prove that . First of all, we have the inequality because . Consequently, is written with at most digits in base . Applying lemma 3, we have , because and . Applying lemma 3 again, this is equal to , hence to . Applying lemma 3 a third time, this is equal to . This concludes the proof.
Conclusion
Since the sets , for are finite, the set for cover all integers larger than some integer, say .
For , there exists such that and we have shown that is periodic with period on an interval . By abuse of notation, write .
Let be the union of the intervals , for . One has ; for , the intersection is hence has at least points, thus at least . Using lemma 1, has period on , for all .
This concludes the proof that is ultimately periodic