arXiv:2608.24238cs.FLAug 2026

Manuscript Offprint

arXiv:2608.24238

Unary Versus Binary Two-Way Automata

Viliam Geffert, Vincent Hlaváč, Rastislav Královič

Viliam Geffert ∗^{*}

Department of Computer Science, P. J. Šafárik University, Slovakia

viliam.geffert@upjs.sk

Vincent Hlaváč

Rastislav Královič

Department of Computer Science, Comenius University, Slovakia

vincent.hlavac@fmph.uniba.sk

rastislav.kralovic@fmph.uniba.sk

If L is a unary language, then its binary coded version binL is a binary language containing all binary strings representing any 0x∈L0^x \in L. It it known that if a unary language L is regular and can be recognized by a minimal one-way deterministic finite automaton (1DFA) with n states, then its binary coded version is also regular and can be recognized by a 1DFA with at most n states, but at least 1+log⁡n1+\log n states.

Here we shall present related results for two-way automata (2DFAs). First, we shall show that each unary 2DFA A1A_1 with nn states can be converted to a 2DFA A2A_2 recognizing bin L(A1)\mathsf{L}(A_1) with at most O(n⋅log⁡n)O(n \cdot \log n) states. If A1A_1 is minimal and uses only loops of odd lengths, A2A_2 will use at most 2n+22n+2 states, but it must use at least nn states. For each n≥7n \geq 7, we shall also present a unary witness language for which a minimal 2DFA uses exactly nn states, but any minimal 2DFA recognizing its binary coded version uses at least nn states, but less than n+log⁡nn+\log n states.

Keywords: finite automata, unary regular languages, state complexity

1 Introduction

If L is a unary language, then its binary coded version binL is a binary language containing all binary strings representing any 0x∈L0^x \in L. Unary (tally) languages play an important role as languages with a very low information content and many of their properties are different from the general or binary case [1, 6, 12].

In the case of unary regular languages, we have substantial differences in state complexity of several operations. As an example, removing nondeterminism in a one-way nondeterministic finite automaton with nn states may increase the number of states up to 2n2^n [22, 18, 21, 23], while the corresponding cost for automata with unary input alphabet is only e(1+o(1))⋅n⋅ln⁡ne^{(1+o(1))\cdot\sqrt{n\cdot\ln n}} [2, 5, 20]. There are other differences, for example, if a unary language is not regular, then it is not context free [11].

Quite recently [7, 10], it was shown that if a unary language L is recognized by a one-way deterministic finite automaton (1DFA) A1A_1 with nn states, then its binary coded version can be recognized by a 1DFA A2A_2 with at most nn states and, if A1A_1 is minimal, then A2A_2 must use at least 1+⌈log⁡n⌉1 + \lceil \log n \rceil states. The gap between unary and binary versions can indeed be exponential; there are witness languages matching this gap, for each n≥1n \geq 1.

The conversion in the opposite direction does not work in general: there exist binary regular languages for which the unary versions are not regular. As an example, consider the unary language L={02k:k≥0}\mathsf{L} = \{0^{2^k} : k \geq 0\}. This language is not even context-free, which can be proved easily, by the use of

∗^{*}Supported by the Slovak Research and Development Agency under contract no. APVV-24-0103.

M. Hospodár et al. (Eds.): 17th International Conference on Automata and Formal Languages (AFL 2026) EPTCS 451, 2026, pp. 1–16, doi:10.4204/EPTCS.451.1

© V. Geffert, V. Hlaváč & R. Královič

Unary Versus Binary Two-Way Automata

the Pumping Lemma [13, Sect. 7.2]. Nevertheless, its binary coded version is regular: a number is a power of two if and only if its binary representation contains exactly one symbol “1” (we allow leading zeros), which can be tested by a 1DFA with only 3 states. However, the set of powers of two is regular only if the base used for representing numbers is itself a power of two, but not regular in any other bases. In general, a set of numbers is regular in all bases only if its unary coded version is regular, otherwise it can be regular only in bases which are powers of some fixed positive integer [3].

In spite of that it is decidable [8], for a given binary 1DFA A2A_2, whether there exists a unary 1DFA A1A_1 such that binL(A1)=L(A2)\text{bin} \mathsf{L}(A_1) = \mathsf{L}(A_2). The decision is computed in time that is polynomial in the number of states of A2A_2. If the answer is positive, the algorithm constructs A1A_1. Interestingly, such decision becomes easier if we use the convention to write number representations with the least significant bit first: the problem of whether there exists a unary 1DFA A1A_1 such that binL(A1)=L(A2)R\text{bin} \mathsf{L}(A_1) = \mathsf{L}(A_2)^R can be decided in linear time [19].

This paper presents related results for two-way deterministic finite automata (2DFAs). First, we shall show that each unary 2DFA A1A_1 with nn states can be converted to a binary 2DFA A2A_2 recognizing bin L(A1)\mathsf{L}(A_1) with at most O(n⋅log⁡n)O(n \cdot \log n) states.

Moreover, if A1A_1 does not use loops of even lengths, 2n+22n+2 states are sufficient. If, in addition, A1A_1 is minimal, then nn states are necessary. This follows from a conversion in the opposite way: if A2A_2 is a binary 2DFA with nn states recognizing a binary coded version of a unary language L\mathsf{L} with no tail and an odd period, it can be converted to a unary 2DFA A1A_1 recognizing L\mathsf{L} with at most nn states. Next, for each n≥7n \geq 7, we shall present a unary witness language Ln\mathsf{L}_n for which a minimal 2DFA uses exactly nn states such that any minimal binary 2DFA recognizing bin Ln\mathsf{L}_n must use at least nn states, but less than n+log⁡n−1n + \log n - 1 states.

References (23)