arXiv:1701.03768v1 [cs.FL] 13 Jan 2017

ROBERT FERENS AND MAREK SZYKULA Abstract. We study descriptive complexity properties of the class of regular biﬁx-free languages, which is the intersection of preﬁx-free and suﬃx-free regular languages. We show that there exist a single ternary universal (stream of) biﬁx-free languages that meet all the bounds for the state complexity basic operations (Boolean operations, product, star, and reversal). This is in contrast with suﬃx-free languages, where it is known that there does not exist such a stream. Then we present a stream of biﬁx-free languages that is most complex in terms of all basic operations, syntactic complexity, and the number of atoms and their complexities, which requires a superexponential alphabet. We also complete the previous results by characterizing state complexity of product, star, and reversal, and establishing tight upper bounds for atom complexities of biﬁx-free languages. We show that to meet the bound for reversal we require at least 3 letters and to meet the bound for atom complexities n + 1 letters are suﬃcient and necessary. For the cases of product, star, and reversal we show that there are no gaps (magic numbers) in the interval of possible state complexities of the languages resulted from an operation; in particular, the state complexity of the product Lm Ln is always m + n − 2, while of the star is either n − 1 or n − 2. Keywords: atom complexity, biﬁx-free, Boolean operations, magic number, most complex, preﬁx-free, product, quotient complexity, regular language, reversal, state complexity, suﬃx-free, syntactic complexity, transition semigroup

1. Introduction A language is prefix-free or suffix-free if no word in the language is a proper prefix or suffix, respectively, of another word from the language. If a language is prefix-free and suffix-free then it is bifix-free. Languages with these properties have been studied extensively. They form important classes of codes, whose applications can be found in such fields as cryptography, data compression, information transmission, and error correction methods. In particular, prefix and suffix codes are prefix-free and suffix-free languages, respectively, while bifix-free languages can serve as both kinds of codes. For a survey about codes see [1, 19]. Moreover, they are special cases of convex languages (see e.g. [12] for the related algorithmic problems). Here we are interested how the descriptive complexity properties of prefix-free and suffix-free languages are shared in their common subclass. There are three natural measures of complexity of a regular language that are related to the Myhill (Myhill-Nerode) congruence on words. The usual state complexity or quotient complexity is the number of states in a minimal DFA recognizing the language. Therefore, state complexity measures how much memory we need to store the language in the form of a DFA, or how much time we need to perform an operation that depends on the size of the DFA. Therefore, we are interested in finding upper bounds for complexities of the resulting languages obtained as a result of some operation (e.g. union, intersection, product, or reversal). Syntactic complexity measures the number of transformations in the transition semigroup or, equivalently, the number of classes Institute of Computer Science,, University of Wroclaw, Wroclaw, Poland E-mail addresses: [email protected] , [email protected] 1

2

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

of words that act differently on the states [11, 22]; this provides a natural bound on the time and space complexity of algorithms working on the transition semigroup (for example, a simple algorithm checking whether a language is star-free just enumerates all transformations and verifies whether no one of them contains a non-trivial cycle [20]). The third measure is called the complexity of atoms [10], which is the number and state complexities of the languages of words that distinguish exactly the same subset of states (quotients). Most complex languages and universal witnesses were proposed by Brzozowski in [3]. The point here is that, it is more suitable to have a single witness that is most complex in the given subclass of regular languages, instead of having separate witnesses meeting the upper bound for each particular measure and operation. Besides theoretical aspects, this concept has also a practical motivation: To test efficiency of various algorithms or systems operating on automata (e.g. computational package GAP [15]), it is natural to use worst-case examples, that is, languages with maximal complexities. Therefore, it is preferred to have just one universal most complex example than a set of separate example for every particular case. Of course, it is also better to use a smallest possible alphabet. It may be surprising that such a single witness exists for most of the natural subclasses of regular languages: the class of all regular languages [3], right-, left-, and two-sided ideals [4], and prefixconvex languages [7]. However, there does not exist a single witness for the class of suffix-free languages [9], where two different witnesses must be used. In this paper we continue the previous studies concerning the class of bifix-free languages [5, 24]. In [5] the tight bound on the state complexity of basic operations on bifix-free languages were established; however, the witnesses were different for particular cases. The syntactic complexity complexity of bifix-free languages was first studied in [6], where a lower bound was established, and then the formula was shown to be an upper bound in [24]. Our main contributions are as follows: (1) We show a single ternary witness of bifix-free languages that meets the upper bounds for all basic operations. This is in contrast with the class of suffix-free languages, where such most complex languages do not exist. (2) We show that there exist most complex languages in terms of state complexity of all basic operations, syntactic complexity, and number of atoms and their complexities. It uses a superexponential alphabet, which cannot be reduced. (3) We prove a tight upper bound on the number of atoms and the quotient complexities of atoms of bifix-free languages. (4) We provide a complete characterization of state complexity for product and star, and show the exact ranges for the possible state complexities for product, star, and reversal of bifixfree languages. (5) We prove that at least a ternary alphabet must be used to meet the bound for reversal, and at an (n + 1)-ary alphabet must be used to meet the bounds for atom complexities. 2. Preliminaries 2.1. Regular languages and complexities. Let Σ be a non-empty finite alphabet. In this paper we deal with regular languages L ⊆ Σ∗ . For a word w ∈ L, the (left) quotient of L is the set {u | wu ∈ L}, which is also denoted by L.w. Left quotients are related to the Myhill-Nerode congruence on words, where two words u, v ∈ Σ∗ are equivalent if for every x ∈ Σ∗ , we have ux ∈ L if and only if vx ∈ L. Thus the number of quotients is the number of equivalence classes in this relation. The number of quotients of L is the quotient complexity κ(L) of this language [2]. A language is regular if it has a finite number of quotients.

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

3

Let L, K ⊆ Σ∗ be regular languages over the same alphabet Σ. By Boolean operations on these languages we mean union L∪K, intersection L∩K, difference L\K, and symmetric difference L⊕K. The reverse language LR of L is the language {ak . . . a1 | a1 . . . ak ∈ L, a1 , . . . , ak ∈ Σ}. By the basic operations on regular languages we mean the Boolean operations, the product (concatenation), the star, and the reversal operation. By the complexity of an operation we mean the maximum possible quotient complexity of the resulted language, given as a function of the quotient complexities of the operands. The syntactic complexity σ(L) of L is the number of equivalence classes of the Myhill equivalence relation on Σ+ , where two words u, v ∈ Σ+ are equivalent if for any words x, y ∈ Σ∗ , we have xuy ∈ L if and only if xvy ∈ L. The third measure of complexity of a regular language L is the number and quotient complexities of atoms [10]. Atoms arise from the left congruence of words refined by Myhill equivalence relation: two words u, v ∈ Σ∗ are equivalent if for any word x ∈ Σ∗ , we have xu ∈ L if and only if xv ∈ L [16]. Thus u and v are equivalent if they belong exactly to the same left quotients of L. An equivalence class of this relation is an atom [10] of L. It is known that (see [10]) an atom is a non-empty intersection of quotients and their complements, and the quotients of a language are unions of its atoms. Therefore, we can write AS for an atom, where S is the set of quotients of L; then AS is the intersection of the quotients of L from S together with the complements of the quotients of L outside S. 2.2. Finite automata and transformations. A deterministic finite automaton (DFA) is a tuple D = (Q, Σ, δ, q0 , F ), where Q is a finite non-empty set of states, Σ is a finite non-empty alphabet, δ : Q × Σ → Q is the transition function, q0 ∈ Q is the initial state, and F ⊆ Q is the set of final states. We extend δ to a function δ : Q × Σ∗ → Q as usual: for q ∈ Q, w ∈ Σ∗ , and a ∈ Σ, we have δ(q, ε) = q and δ(q, wa) = δ(δ(q, w), a), where ε denotes the empty word. A state q ∈ Q is reachable if there exists a word w ∈ Σ∗ such that δ(q0 , w) = q. Two states p, q ∈ Q are distinguishable if there exists a word w ∈ Σ∗ such that either δ(p, w) ∈ F and δ(q, w) ∈ / F or δ(p, w) ∈ / F and δ(q, w) ∈ F . A DFA is minimal if there is no DFA with a smaller number of states that recognizes the same language. It is well known that this is equivalent to that every state is reachable and every pair of distinct states is distinguishable. Given a regular language L, all its minimal DFAs are isomorphic, and their number of states is equal to the number of left quotients κ(L) (see e.g. [2]). Hence, the quotient complexity κ(L) is also called the state complexity of L. If a DFA is minimal then every state q corresponds to a quotient of the language, which is the set words w such that δ(q, w) ∈ F . We denote this quotient by Kq . We also write AS , where S is a subset of states, for \ \ Kq , AS = Kq ∩ q∈S

q∈S

which is an atom if AS is non-empty. A state q is empty if Kq = ∅. Throughout the paper, by Dn we denote a DFA with n states, and without loss of generality we always assume that its set of states Q = {0, . . . , n − 1} and that the initial state is 0. In any DFA Dn , every letter a ∈ Σ induces a transformation δa on the set Q of n states. By Tn we denote the set of all nn transformations of Q; then Tn is a monoid under composition. For two transformations t1 , t2 of Q, we denote its composition as t1 t2 . The transformation induced by a word w ∈ Σ∗ is denoted by δw . The image of q ∈ Q under a transformation δw is denoted by qδw , and the image of a subset S ⊆ Q is Sδw = {qδw | q ∈ S}. The preimage of a subset

4

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

−1 −1 S ⊂ Q under a transformation δw is Sδw = {q ∈ Q | qδw ∈ S}. Note that if w = a1 . . . ak , then −1 −1 −1 δa1 ...ak = δak . . . δa1 . The identity transformation is denoted by 1, which is also the same as δε , and we have q1 = q for all q ∈ Q. The transition semigroup T (n) of Dn is the semigroup of all transformations generated by the transformations induced by Σ. Since the transition semigroup of a minimal DFA of a language L is isomorphic to the syntactic semigroup of L [22], syntactic complexity σ(L) is equal to the cardinality |T (n)| of the transition semigroup T (n). Since a transformation t of Q can be viewed as a directed graph with regular out-degree equal 1 and possibly with loops, we transfer well known graph terminology to transformations: The indegree of a state q ∈ Q is the cardinality |{p ∈ Q | pt = q}|. A cycle in t is a sequence of states q1 , . . . , qk for k ≥ 2 such that qi t = qi+1 for i = 1, . . . , k − 1, and qk t = q1 . A fixed point in t is a state q such that qt = q; we therefore do not call fixed points cycles. A transformation that maps a subset S to a state q and fixes all the other states is denoted by (S → q). If S is a singleton {p} then we write shortly (p → q). A transformation that has a cycle q1 , . . . , qk and fixes all the other states is denoted by (q1 , . . . , qk ). A nondeterministic finite automaton (NFA) is a tuple N = (Q, Σ, δ, I, F ), where Q, Σ, and F are defined as in a DFA, I is the set of initial states, and δ : Q × Σ ∪ {ε} → 2Q is the transition function.

2.3. Most complex languages. A stream is a sequence (Lk , Lk+1 , . . . ) of regular languages in some class, where n is the state complexity of Ln . A dialect L′n of a language Ln is a language that differs only slightly from Ln . There are various types of dialects, depending what changes are allowed. A permutational dialect (or permutationally equivalent dialect ) is a language in which letters may be permuted or deleted. Let π : Σ → Σ be a partial permutation. If Ln (a1 , . . . , ak ) is a language over the alphabet Σ = {a1 , . . . , ak ), then we write Ln (π(a1 ), . . . , π(ak )) for a language in which a letter ai is replaced by π(ai ). In the case a letter ai is removed, so not defined by π(ai ), we write π(ai ) = . For example, if L = {a, ab, abc}, then L(b, a, ) = {b, ba}. A stream is most complex in its class if all their languages and all pairs of languages together with their dialects meet all the bounds for the state complexities of basic operations, the syntactic complexity, the number and the complexities of atoms. Note that binary operations were defined for languages with the same alphabets. Therefore, if the alphabet is not constant in the stream, to meet the bounds for binary Boolean operations, for every pair of languages we must use their dialects that restrict the alphabet to be the same. Sometimes we restrict only to some of these measures. In some cases, this allows to provide an essentially simpler stream over a smaller alphabet when we are interested only in those measures. In particular, if a syntactic complexity requires a large alphabet and for basic operations it is enough to use a constant number of letters, it is desirable to provide a separate stream which is most complex just for basic operations. Dialects are necessary for most complex streams of languages, since otherwise they would not be able to meet upper bounds in most classes. In particular, since Ln ∪ Ln = Ln , the state complexity of union would be at most n in this case. Other kinds of dialects are possible (e.g. [7]), though permutational dialects are the most restricted. 2.4. Bifix-free languages. A language L is prefix-free if there are no words u, v ∈ Σ+ such that uv ∈ L and u ∈ L. A language L is suffix-free if there are no words u, v ∈ Σ+ such that uv ∈ L and v ∈ L. A language is bifix-free if it is both prefix-free and suffix-free.

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

5

The following properties of minimal DFAs recognizing prefix-free, suffix-free, and bifix-free languages, adapted to our terminology, are well known (see e.g. [5, 6, 13, 24]): Lemma 1. Let Dn (Q, Σ, δ, 0, F ) be a minimal DFA recognizing a non-empty language L. Then L is bifix-free if and only if: 1 There is an empty state, which is n − 1 by convention, that is, n − 1 is not final and (n − 1)δa = n − 1 for all a ∈ Σ. 2 There exists exactly one final state, which is n − 2 by convention, and its quotient is {ε}; thus (n − 2)δa = n − 1 for all a ∈ Σ. 3 For u ∈ Σ+ and q ∈ Q \ {0}, if qδu 6= n − 1, then 0δu 6= qδu . The conditions (1) and (2) are sufficient and necessary for a prefix-free languages, and the conditions (1) and (3) are sufficient and necessary for a suffix-free language. It follows that a minimal DFA recognizing a non-empty bifix-free language must have at least n ≥ 3 states. Since states 0, n − 2, and n − 1 are special in the case DFAs of bifix-free languages, we denote the remaining “middle” states by QM = {1, . . . , n − 3}. Condition 3 implies that suffix-free and so bifix-free are non-returning (see [14]), that is, there is no non-empty word w ∈ Σ+ such that L.w = L. Note that in the case of unary languages, there is exactly one bifix-free language for every state complexity n ≥ 3, which is {an−2 }. The classes of unary prefix-free, unary suffix-free, and unary bifix-free languages coincide and we refer to it as to unary free languages. The state complexity of basic operations on bifix-free languages was studied in [5], where different witness languages were shown for particular operations. The syntactic complexity of bifix-free languages was shown to be (n − 1)n−3 + (n − 2)n−3 + (n − 3)2n−3 for n ≥ 6 [24]. Moreover, the transition semigroup of a minimal DFA Dn of a witness ≥6 language meeting the bound must be Wbf (n), which is a transition semigroup containing three types of transformations and can be defined as follows: Definition 2 (The largest bifix-free semigroup). ≥6 Wbf (n) =

{t ∈ T (n) |

(type 1) (type 2)

{0, n − 2, n − 1}t = {n − 1} and QM t ⊂ QM ∪ {n − 2, n − 1}, or 0t = n − 2 and {n − 2, n − 1}t = {n − 1} and QM t ⊂ QM ∪ {n − 1}, or

(type 3)

0t ∈ QM and {n − 2, n − 1}t = {n − 1} and QM t ⊆ {n − 2, n − 1} }.

Following [24], we say that an unordered pair {p, q} of distinct states from QM is colliding in T (n) if there is a transformation t ∈ T (n) such that 0t = p and rt = q for some r ∈ QM . A pair of states is focused by a transformation u ∈ T (n) if u maps both states of the pair to a single ≥6 state r ∈ QM ∪ {n − 2}. It is known that ([24]) in semigroup Wbf (n) there are no colliding pairs and every possible pair of states is focused by some transformation, and it is the unique maximal transition semigroup of a minimal DFA of a bifix-free language with this property. 3. Complexity of bifix-free languages In this section we summarize and complete known results concerning state complexity of bifix-free regular languages. We start from the obvious upper bound for the maximal complexity of quotients.

6

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

Proposition 3. Let L be a bifix-free language with state complexity n. Each (left) quotients of L have state complexity at most n − 1, except L, {ε}, and ∅, which always have state complexities n, 2, and 1, respectively. Proof. Since bifix-free languages are non-returning, their non-initial quotients have at most state complexity n − 1. 3.1. Boolean operations. In [5] it was shown that mn − (m + n) (for m, n ≥ 4) is a tight upper bound for the state complexity of union and symmetric difference of bifix-free languages, and that to meet this bound a ternary alphabet is required. It was also shown there that mn − 3(m + n − 4) and mn − (2m + 3n − 9) (for m, n ≥ 4) are tight upper bounds for intersection and difference, respectively, and that a binary alphabet is sufficient to meet these bounds. Since the tight bound is smaller for unary free languages, the size of the alphabet cannot be reduced. It may be interesting to observe that the alphabet must be essentially larger to meet the bounds in the case when m = 3. Remark 4. For n ≥ 3, to meet the bound mn − (m + n) for union or symmetric difference with minimal DFAs D3′ and Dn at least n − 2 letters are required. Proof. For each q ∈ {1, . . . , n − 2} state (1′ , q) must be reachable in the product automaton. In D3′ state 0′ is the only state that can be mapped to 1′ by the transformation of some letter a. This means that at least n − 2 different letters are required. 3.2. Product. The tight bound for the product is m + n − 2, which is met by unary free languages. We show that there is no other possibly for the product of bifix-free languages, that is, Lm Ln has always state complexity m + n − 2. Theorem 5. For m ≥ 3, n ≥ 3, for every bifix-free languages L′m and Ln , the product L′m Ln meets the bound m + n − 2. ′ Proof. Let Dm = (Q′ , Σ, δ ′ , 0′ , {(n − 2)′ }) and Dn = (Q, Σ, δ, 0, {n − 2}) be minimal DFAs for L′m and Ln , respectively. We use the well known construction for an NFA N recognizing the product of two regular languages. Then Q′ ∪ Q is the set of states, 0′ is initial and n − 2 is a final state. We have δ N being the transition function such that δ N (p, a) = {q} whenever δ ′ (p, a) = q for p, q ∈ Q′ , or δ(p, a) = q for p, q ∈ Q. Also, we have the ε-transition δ N ((m − 2)′ , ε) = {0}. We determinize N to DP ; since every reachable subset has exactly one state from Q′ , we can assume that the set of states is Q′ × 2Q , so DP = (Q′ × 2Q , Σ, δ P , {0′ }, Q′ × {{n − 2}}). Since m + n − 2 is an upper bound for product, it is enough to show that at least m + n − 2 states are reachable and pairwise distinguishable in DP . We show that the states ((n − 2)′ , {0}), (p, ∅) for each p ∈ {0′ , . . . , (m − 3)′ }, and ((m − 1)′ , {q}) for each q ∈ {1, . . . , n − 1} are reachable and distinguishable. Let R be the set of these states. From this place in the context of reachablitity and distinguishability we will consider only the states from R. ′ is minimal, every state (p, ∅) ∈ R (where p ∈ {0′ , . . . , (m − 3)′ }) Since Lm′ is prefix-free and Dm ′ ′ is reached from (0 , ∅) by a word reaching state p in Dm . Furthermore, state ((m − 2)′ , {0}) is ′ ′ reached by a word w from non-empty language Lm . Every state ((m − 1)′ , {q}) ∈ R (where q ∈ {1, . . . , n − 1}) may be reached from state ((m − 2)′ , {0}) by a word w such that 0δw = q, and hence by w′ w in D. It remains to show distinguishability. Consider two distinct states (r, {q1 }) and (r, {q2 }) from R; then r ∈ {(m − 2)′ , (m − 1)′ } and q1 , q2 ∈ Q. These states are distinguishable by a word distinguishing q1 and q2 in Dn .

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

7

P Consider two states (p, ∅) and (r, {q}) from R. There exists a word w such that (p, ∅)δw = ′ P ′ ′ ((m − 2) , {0}). We have (r, {q})δw = (rδw , {qδw }) = ((m − 1) , {qδw }). Because 0 is reachable only by the empty word in Dn since Ln is suffix-free, we have qδw 6= 0. Then ((m − 2)′ , {0}) and ((m − 1)′ , {qδw }) are distinguishable by our earlier considerations. Finally, consider two states (p1 , ∅) and (p2 , ∅) from R. There exists a word w which distinguishes ′ ′ p1 and p2 in Dm . Let w be a shortest such word. Then, without loss of generality, p1 δw = (m − 2)′ ′ ′ ′ ′ and p2 δw 6= (m− 2) . Since Dm is prefix-free, for every proper prefix v of w we have p1 δv 6= (m− 2)′ , P P and since w is shortest, we have p2 δv′ 6= (m − 2)′ . Then (p1 , ∅)δw = ((m − 2)′ , {0}) and (p2 , ∅)δw = ′ ′ ′ ′ ′ ′ (p2 δw , ∅). If p2 δw ∈ {1 , . . . , (m − 3) } then ((m − 2) , {0}) and (p2 δw , ∅) are distinguishable by our ′ earlier considerations. Otherwise p2 δw must be (m − 1)′ , and since ((m − 1)′ , ∅) is equivalent to ′ ((m − 1) , n − 1)), it is also distinguishable from ((m − 2)′ , {0}).

3.3. Star. The tight bound for star is n−1, which is met by binary bifix-free languages [5]. Here we provide a complete characterization for the state complexity of L∗n and show that there are exactly two possibilities for its state complexity: n − 1 and n − 2. This may be compared with prefix-free languages, where there are exactly three possibilities for the state complexity L∗n : n, n − 1, and n − 2 [18]. Theorem 6. Let n ≥ 3 and let Dn = (Q, Σ, δ, {n − 2}, 0) be a minimal DFA of a bifix-free language Ln . If the transformation of some a ∈ Σ maps some state from {0, . . . , n − 3} to n − 1, then L∗n has state complexity n − 1. Otherwise it has state complexity n − 2. Proof. Let N = (Q, Σ, δN , {0}, {0}) be the NFA obtained from Dn by the standard construction for L∗n : We have δ N (p, a) = {q} whenever δ(p, a) = q, and there is the ε-transition δ N (n − 2, ε) = {0}. Let DS = (2Q , Σ, δ S , {0}, {0} ∪ 2Q\{0}) be the DFA obtained by the powerset construction from N . Since in Dn only n− 2 is final and the transformation of every letter maps it to empty state n− 1, we know that only the subsets of the forms {q}, {q, n − 1}, {0, n − 2}, and {0, n − 2, n − 1}, where q ∈ Q, are reachable in DS . Since n − 1 is empty, subsets {q} and {q, n − 1} with q ∈ {0, . . . , n − 2} are equivalent, and since subsets with 0 are final, {0}, {0, n − 2}, and {0, n − 2, n − 1} are equivalent. First observe that every subset {q} with q ∈ {0, . . . , n − 3} is reachable in DS by a word reaching q in Dn . Also, if n − 1 is reachable from some state q ∈ {0, . . . , n − 3} in Dn by the transformation of some letter, then {n − 1} can be reached in DS from {q} by the transformation of this letter. S Otherwise, in DS , for all words w and all subsets S containing q ∈ {0, . . . , n − 3} we know that Sδw also contains a state from {0, . . . , n − 3}; thus subset {n − 1} cannot be reached. Let p, q ∈ {0, . . . , n − 3, n − 1} be two distinct states; we will show that {p} and {q} are distinguishable in DS . They are distinguishable in Dn , which means that there exists a word w 6= ε such that exactly one of the states pδw and qδw is final state n − 2. Let w be a shortest such word, and without loss of generality assume that pδw = n − 2. For any non-empty proper prefix v of w, we have pδv 6= n − 2 because Ln is prefix-free, qδv 6= 0 because Ln is suffix-free, and qδv 6= n − 2 S S because w is shortest. Hence, in DS , {p}δw = {0, n − 2} and {q}δw = {r} with r ∈ {1, . . . , n − 3}. Thus w distinguishes both subsets. 3.4. Reversal. For the state complexity of a reverse bifix-free language, it was shown in [5, Theorem 6] that for n ≥ 3 the tight upper bound is 2n−3 + 2, and that a ternary alphabet is sufficient. We show that the alphabet size cannot be reduced, and characterize the transition semigroup of the DFAs of witness languages.

8

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

Theorem 7. For n ≥ 6, to meet the bound 2n−3 + 2 for reversal, a witness language must have at least three letters. Moreover, for n ≥ 5 the transition semigroup T (n) of a minimal DFA ≥6 Dn (Q, Σ, δ, 0, {n − 2}) accepting a witness language must be a subsemigroup of Wbf (n). Proof. We use the standard reversal construction: let N be the NFA obtained from DFA Dn by reversing all edges, making n − 2 an initial state, and making 0 a final state. Then N = (Q, Σ, δ N , {n − 2}, {0}), and δ N (q, a) = δ −1 (q, a) = qδa−1 . We use the powerset construction to determinize N to DR . Remind that QM = {1, . . . , n − 3}. Let R(n) be the transition semigroup of DR . By the reversal construction, R(n) consists of all transformations t−1 for t ∈ T (n). As it was shown in the proof of [5, Theorem 6], to achieve the upper bound, in particular, each subset of QM must be reachable in DR . ≥6 First we show that the transition semigroup T (n) of Dn is a subsemigroup of Wbf (n). Every pair {p, q} ⊆ QM , where p 6= q, must be reachable in DR . This means that there exists a transformation t−1 ∈ R(n) such that {n − 2}t−1 = {p, q}. We have pt = n − 2 and qt = n − 2, so p and q are ≥6 focused by t ∈ T (n). Then we know that every pair of states in QM is focused, and since Wbf (n) ≥6 is the unique maximal transition semigroup with this property ([24]), we have T (n) ⊆ Wbf (n). Now we show that a binary alphabet, say Σ = {a, b}, is not enough to reach the upper bound. Let ≥6 a ∈ Σ be a letter such that 0δa = q ∈ QM . Since T (n) ⊆ Wbf (n), we have QM δa ⊆ {n − 2, n − 1}. −1 Moreover, for all p ∈ QM we have {p}δa ⊆ {0}. Also, the set {n − 2}δb−1 is empty, because if it contains some state p ∈ QM , then at most two of the 2n−4 subsets of QM containing p might be reachable, since pδb = {n−2} and pδa ∈ {n−2, n−1}; then not all subsets of QM are reachable since n ≥ 6. Because {n−2, n−1}δa = {n−2, n−1}δb = {n−1}, any subset containing n−2 is reachable in DR only by the empty word, and any subset containing n − 1 is unreachable. Hence, a non-empty subset S of QM must be reachable in DR by a word of the form abi , that is, S = {n − 2}δb−1 i a . Let −1 C be the states from QM that are fixed points or belong to a cycle in δb . Observe that δb does not change the cardinality in C, that is, for any subset T ⊆ Q we have |T ∩ C| = |T δb−1 ∩ C|. Thus, if C is non-empty, only subsets with the same cardinality in C are reachable. If C is empty, then Sδb−1 n−3 ∩ QM = ∅, thus at most n − 2 subsets of QM are reachable; since n ≥ 6, not all subsets of QM are reachable. It is known that in the case of the class of all regular languages the resulted language of the reversal operation can have any state complexity in range of integers [log2 n, 2n ] [17, 23], thus there are no gaps (magic numbers) in the interval of possible state complexities. The next theorem states that the situation is similar for the case of bifix-free languages. Theorem 8. If Ln is a bifix-free language with state complexity n ≥ 3, then the state complexity n−3 of LR ]. Moreover, all values in this range are attainable by LR n is in [3 + log2 (n − 2), 2 + 2 n for some bifix-free language Ln , whose a minimal DFA has transition semigroup that is a subsemigroup ≥6 of Wbf (n). R R Proof. Note that if Ln is a bifix-free language, then so LR n is. Also we know that (Ln ) = Ln . R Suppose for a contradiction that there is some Ln whose Ln has state complexity α < 3 + R R log2 (n − 2). We have LR n with state complexity α whose reverse (Ln ) = Ln has state complexity α−3 R R n. However, since n > 2 + 2, this means that (Ln ) exceeds the upper bound for reversal. Now it is enough to show that every value from [n, 2 + 2n−3 ] is attainable, because to reach R R R α ∈ [3 + log2 (n − 2), n − 1] for some LR n , we can use Lα = Ln whose reverse (Ln ) = Ln has state α−3 complexity n ∈ [α + 1, 2 + 2 ].

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

9

Let α ∈ [n, 2 + 2n−3 ]. We construct the DFA Dn (Q, Σ, δ, 0, {n − 2}) as follows: For each q ∈ {1, . . . , n − 3}, we put the letter aq : (0 → q)({1, . . . , n − 2 → n − 1). We choose α − 2 subsets of {1, . . . , n − 3} in such a way that we always have ∅ and all singletons {q}, while the other α − 3 − (n − 3) subsets are chosen arbitrarily. Since α ≤ 2 + 2n−3 , n ≥ 3, and the number of the subsets is 2n−3 , we can always make that choice. For each of the chosen subset, we put the letter bS : (S → n − 2)(Q \ S → n − 1). Observe that Dn is minimal: every state q ∈ {1, . . . , n − 3} is reachable by aq , and n − 2 and n − 1 are reachable using some bS . State 0 is distinguished since aq maps all the other states to empty state n − 1. Two distinct states p, q ∈ {1, . . . , n − 3} are distinguished by b{p} , since its action maps p to n − 2 and q to n − 1. Also, the transformations of aq and bS are of type 3 and ≥6 type 1 from Definition 2, and so the transition semigroup of Dn is a subsemigroup of Wbf (n). Q −1 Q\{0} R Let DR (2 , Σ, δ , {n − 2}, {0} ∪ 2 ) be the automaton recognizing Ln obtained by reversing the edges of Dn and determinization. We show that there are exactly α reachable subsets in DR . allows to reach the subset S from {n − 2}. Then for any non-empty S, δa−1 The transformation δb−1 q S for some q ∈ S allows to reach {0} from S. Thus we have reachable {0}, {n − 2}, and α − 2 chosen subsets S. No subset containing n − 1 can be reached, and {n − 2} is the only reachable subset , and these transformations containing n − 2. Since {0} is reachable only by the transformations δa−1 q of map Q \ {q} to ∅, no other subset containing 0 can be reached. Since the transformations δa−1 q the letters aq do not map any state to a state in {1, . . . , n − 3}, to reach S ⊆ {1, . . . , n − 3} we must use the transformations of the letters of type bS . But this is possible only from {n − 2} for the chosen α − 2 subsets. Finally, observe that every two distinct subsets S, S ′ ⊆ {1, . . . , n − 3} are distinguished by a−1 q such that q ∈ S ⊕ S ′ . Subset {0} is the final subset, and {n − 2} is distinguished as it is the only subset for which b{q} does not result in ∅. 3.5. Atom complexities. Here we prove a tight upper bound on the number and the state complexities of atoms of a bifix-free language. T T Remind that for S ⊆ Q an atom AS = q∈S Kq ∩ q∈Q\S Kq is a non-empty set. Then for any w ∈ Σ∗ we have \ \ AS .w = {u | wu ∈ AS } = Kq .w. Kq .w ∩ q∈S

q∈S

A quotient of a quotient of L is also a quotient of L, and therefore AS .w has the following form: \ \ AS .w = Kq , Kq ∩ q∈X

q∈Y

where |X| ≤ |S|, |Y | ≤ n − |S|, and X, Y ⊆ Q are disjoint. Using the approach from Iv´an [16] we define the DFA DS = (QS , Σ, δ, (S, Q \ S), FS ) such that: • QS = {(X, Y ) | X, Y ⊆ Q, X ∩ Y = ∅} ∪ {⊥}. • For all a ∈ Σ, (X, Y )a = (Xa, Y a) if Xta ∩ Y ta = ∅, and (X, Y )a = ⊥ otherwise; also ⊥ta = ⊥. • FS = {(X, Y ) | X ⊆ {n − 2}, Y ⊆ Q \ {n − 2}}. Then DFA DS recognizes AS , and so if DS recognizes a non-empty language, then AS is an atom. Every quotient of an atom is represented by a pair (X, Y ). Theorem 9. Suppose that Ln is a bifix-free language recognized by a minimal DFA Dn (Q, Σ, δ, 0, {n− 2}). Then there are at most 2n−3 + 2 atoms of Ln and the quotient complexity of κ(AS ) of atom

10

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

AS satisfies: ≤ 2n−2 + 1 = n κ(AS ) =2 P|S| Pn−3−|S| ≤ 3 + x=1 y=0

n−3 x

n−3−x y

if if if if

S = ∅; S = {0}; S = {n − 2}; ∅ 6= S ⊆ {1, . . . , n − 3}.

Proof. We follow similarly to the proof from [9] for the class of suffix-free languages. If n − 1 ∈ S then AS would be empty, because the quotient of n − 1 is the empty language, and so will not form an atom. Suppose that 0 ∈ S. Since Ln is suffix-free, we have K0 ∩ Kq = ∅ for q 6= 0, so if {0, q} ⊆ S then AS would be empty. Thus S = {0}, A0 = K0 , and the quotient of 0 has complexity n, since Dn is minimal. Suppose that n − 2 ∈ S. Since Kn−2 = {ε} and this is the quotient containing the empty word, we have Kn−2 ∩ Kq = ∅ for q 6= n − 2, so if {n − 2, q} ⊆ S then AS would be empty. Thus S = {n − 2}, and the quotient of n − 2 has complexity 2. It follows that there are at most 2n−3 +2 atoms: A{0} , A{n−2} , and AS for any S ⊆ {1, . . . , n−3}. T T Suppose that S = ∅. Then A∅ = q∈Q Kq . For any w ∈ Σ+ we have A∅ .w = q∈Y Kq , for some Y ⊆ Q \ {0}. We can assume that n − 1 ∈ Y since Kn−1 = Σ∗ . Thus there are at most 2n−2 choices of Y , which together with the initial quotient A∅ yields the quotient complexity 2n−2 + 1. Suppose that ∅ T 6= S ⊆ {1, .T . . , n − 3}. Consider the non-empty quotient AS .w for some w ∈ Σ+ be represented as q∈X Kq ∩ q∈Y Kq . So X has at least one and at most |S| states from Q \ {0}, Y ⊆ Q \ {0} and always contains n − 1. If n − 2 ∈ X then if this quotient is non-empty then it must be {ε}, and if n − 2 ∈ Y then the quotient may be represented by (X, Y \ {n − 2}). If 0δw ∈ {n − 2, n − 1} then Y \ {n − 2, n − 1} contains from 0 to at most n − 3 − |S| states from Q \ ({0, n − 2, n − 1} ∪ X). Suppose that 0δw = q ∈ QM . Since the language is suffix-free, the path i i in δw starting at 0 must end in n − 1, as otherwise 0δw = qδw 6= n − 1 for some i, which contradicts Lemma 1(Condition 3). But then there exists a state p ∈ QM such that pδw ∈ {n − 2, n − 1}. If p ∈ S, then n − 1 ∈ X, and so (X, Y ) represents the empty quotient. If p ∈ Q \ S, then again Y \ {n − 2, n − 1} contains at most n − 3 − |S| states. So for every choice of X we have 0 ≤ |Y \{n−2, n−1}| ≤ n−3−|S| from Q\({0, n−2, n−1}∪X), which together with the initial quotient, {ε} quotient, and the empty quotient yields the formula in the theorem. Theorem 10. For n ≥ 6, let Ln be the language recognized by the DFA D(Q, Σ, δ, 0, {n− 2}), where Σ = {a, b, c, d, e1 . . . , en−3 }, and δ is defined as follows: δa : (0 → 1)((Q \ {0}) → n − 1), δb : ({0, n − 2} → n − 1)(1, 2), δc : ({0, n − 2} → n − 1)(1, . . . , n − 3), δd : ({0, n − 2} → n − 1)(2 → 1), δeq : ({0, n − 2} → n − 1)(q → n − 2) for q ∈ QM . Then D is minimal, Ln is bifix-free and it meets the upper bounds for the number and complexities of atoms from Theorem 9. Proof. It is easy to observe that D is minimal, it recognizes a bifix-free language Ln , and its ≥6 transition semigroup is a subsemigroup of Wbf (n). We show that the atom complexities κ(AS ) meet the bounds, which also implies that there are 2n−3 + 2 atoms.

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

11

Observe that in the transition semigroup of D we have all transformations of type 1 from Definition 2: the transformations of b, c, and d generate all transformations on QM ([21]) with ({0, n − 2} → n − 1), using e2q we can map any state q to n − 1, and finally by using eq we can map any state q to n − 2. First, by the properties of prefix-free and suffix-free languages (see Lemma 1), we have the two special atoms A{n−2} = {ε} and A{0} = Ln , which obviously meet the bounds 2 and n. Now consider S ⊆ {1, . . . , n − 3} and the automaton DS recognizing AS . For S = ∅ we know that the initial state of DS is (∅, Q). Since we have all transformations of type 1, we can reach (∅, Y ) for all Y ⊆ Q \ {0} which contains n − 1. Therefore, 2n−2 states and the initial state are reachable. All states (∅, Y1 ) and (∅, Y2 ) for Y1 , Y2 ⊆ Q \ {0} which contain n − 1 are distinguishable as follows. If q ∈ Y1 and q ∈ / Y2 , then we can use (q → n − 2)((Q \ {q}) → n − 1) of type 1, which accepts from (∅, Y2 ) but does not accept from (∅, Y1 ). Also (∅, Q) is distinguished from the other states by δa δe1 . Now consider ∅ 6= S ⊆ {1, . . . , n − 3}. We show that all states (X, Y ) such that X ⊆ QM , n − 1 ∈ Y ⊆ (QM \ X) ∪ {n − 1}, |X| ≤ |S|, |Y | ≤ n − 2 − |S|, together with the initial state (S, Q \ S), the empty state ⊥, and a final state ({n − 2}, {n − 1}), are reachable and pairwise distinguishable. This yields the number of states in the formula. ≥6 We can map S to X and Q \ S to Y by a transformation of type 1 from Wbf (n). Therefore, all states (X, Y ) are reachable. Also by a transformation of type 1 we can map S to n − 2, and Q \ S to n − 1, so ({n − 2}, {n − 1}) is reachable. Then the empty state is reachable from ({n − 2}, {n − 1}) by any transformation. State ({n − 2}, {n − 1}) is the only final state which we consider. A state (X, Y ) is non-empty since we can map X to n − 2 and Y to n − 1 by a transformation of type 1. Consider two states (X1 , Y1 ) 6= (X2 , Y2 ). Without loss of generality, if q ∈ X1 and q ∈ / X2 , then the transformation (X1 → n − 2)((Q \ X1 ) → n − 1) of type 1 distinguishes both pairs. Otherwise, if q ∈ Y1 and q∈ / Y2 , then the transformation (0 → n − 1)(q → x)(n − 2 → n − 1) of type 1, where x is some state from X1 , yields the empty state from (X1 , Y1 ), but the non-empty state (X2 , Y2 \ {0, n − 2}) from (X2 , Y2 ). Theorem 11. For n ≥ 7, to meet the upper bounds for the atom complexities from Theorem 9 by the language of a minimal DFA Dn (Q, Σ, δ, 0, {n − 2}), the size of the alphabet Σ must be at least ≥6 n + 1. Moreover, the transition semigroup of Dn must be a subsemigroup of Wbf (n). ≥6 Proof. First we show that the transition semigroup of Dn is a subsemigroup of Wbf (n). Consider the atom AS for S = QM , and the DFA DS . In particular the state ({1}, {n−1}) must be reachable. So there is a transformation mapping QM to 1, which means that all colliding pairs are focused. ≥6 Since Wbf (n) is the unique maximal transition semigroup with this property ([24]), the transition semigroup of Dn must be a subsemigroup of it. Now we show that to meet the bounds we require at least n letters. Since D is minimal, there must be a letter of type 3, which maps 0 to a state from QM ; let it be named a. Consider the atom A∅ . Then all states (∅, Y ) for n − 1 ∈ Y ⊆ Q \ {0} must be reachable. In particular, for every q the state (∅, (QM \ {q}) ∪ {n − 2, n − 1}) is reachable. Let it be reachable by some word w, and consider the transformation t of the last letter in this word. Since the transition ≥6 semigroup is a subsemigroup of Wbf (n), t must be of type 1, so it maps 0 to n − 1, q to n − 2, and permutes the other states from QM . Therefore, we must have n − 3 different such transformations for every q ∈ QM ; let their letters be named eq .

12

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

Consider the atom AS for S = QM . Since a state (S \ {q}, {n − 1}) for any q ∈ QM must be reachable, in the transition semigroup there must be a transformation that focuses a pair of states from QM and does not map any state from QM to n − 2 nor to n − 1. If this transformation is induced by some word, then there must be a letter in this word with the same property. So it must be different from a and from δeq ; let it be named d. Finally, we show that there must be at least two other letters inducing transformations of type 1 acts on QM as permutations. Note that these transformations cannot be generated from δa , δd , and the transformations δeq . Consider the atom AS for S = {1, 2}. Then, in particular, all n−3 states (X, Y ) with |X| = 2 2 and Y = (QM \ X) ∪ {n − 1} must be reachable in DS , which means that there is a letter inducing permutation on QM . Let it be named c. If there are no more letters than a, c, d, and eq , then all states (X, Y ) with |X| = 2 and Y = (QM \ X) ∪ {n − 1} must be reachable from the initial ({1, 2}, Q \ {1, 2}) just by ci , since the transformations of the other letters are not permutations on QM . We can decompose δc restricted to QM into disjoint cycles. Suppose that there are two or more cycles, on C1 , C2 ⊆ QM , respectively. Then, however, only states (X, Y ) with the same number |X ∩ C1 | = |{1, 2} ∩ C1 | can be reached by ci , as δc preserves this number. Therefore, δc must be a cycle on QM . Then, however, at most n − 3 states (X, Y ) can be reached, which is less than n−3 2 for n ≥ 7. Thus, there must be another letter (inducing a permutation on QM ), say b. Summarizing, we have the letters a, b, c, d, and n−3 letters eq inducing different transformations. 4. Most complex bifix-free languages 4.1. A ternary most complex stream for basic operations. First we show a most complex stream of bifix-free languages for basic operations which uses only a ternary alphabet. This alphabet is a smallest possible, because for union, symmetric difference, and reversal we require at least three letters to meet the bounds. Definition 12 (Most complex stream for operations). For n ≥ 7, we define the DFA Dn = (Q, Σ, δ, 0, {n − 2}), where Q = {0, . . . , n − 1}, Σ = {a, b, c}, h = ⌊(n − 1)/2⌋ and δ is defined as follows: • δa : (0 → 1)({1, . . . , n − 3} → n − 2)({n − 2, n − 1} → n − 1), • δb : ({0, n − 2, n − 1} → n − 1)(1, . . . , n − 3), • δc : ({0, n − 2, n − 1} → n − 1)(1 → h)(h → n − 2)(n − 3, . . . , h + 1, h − 1, . . . , 2). The DFA Dn is illustrated in Fig. 1. Theorem 13. The DFA Dn from Definition 12 is minimal, recognizes a bifix-free language Ln (a, b, c), ≥6 has most complex quotients, and its transition semigroup is a subsemigroup of Wbf (n). The stream (Ln (a, b, c) | n ≥ 9) with some permutationally equivalent dialects meets all the bounds for basic operations as follows: • Lm (a, b, c) and Ln (a, c, b) meets the bound mn−(m+n) for union and symmetric difference, the bound mn−3(m+n−4) for intersection and the bound mn−(2m+3n−9) for difference. • Lm (a, b, c) and Lm (a, b, c) meets the bound m + n − 2 for product. • Lm (a, b, c) meets the bound n − 1 for star. • Lm (a, b, c) meets the bound 2n−3 + 2 for reversal.

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

...

c

b

2

13

c

b

h−1

a a a

0

a

b

b

c

a

1

n−2

h

a, c

c b

b

c

a a a n−3

b

c

h+1

b

...

c

Figure 1. Automaton Dn from Definition 12. Empty state n − 1 and the transitions going n − 1 are omitted.

Proof. Minimality: First we need to show that Dn is minimal. For every state Table 1 depicts a word by which that state is reached, and a word that is accepted from this state and is not accepted from any other state, thus shows that all states are reachable and distinguishable. Table 1. Reaching and distinguishing words for stream from Definition 12 State 0 q ∈ QM n−2 n−1 Most complex quotients:

Reachable by

Distinguishing accepted word

ε

ac2

abq−1 a2 a3

bn−2−q c2 ε no word exists

14

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

Since from every state q ∈ {1, . . . , n − 3} we can reach any ostate from Q \ {0}, their quotients have state complexity n − 1, and so the language of Dn meets the bound from Proposition 3. ≥6 Subsemigroup of Wbf (n): Consider a non-empty word w and its induced transformation δw from the transition semigroup ≥6 T (n) of Dn . We will show that δw ∈ Wbf (n). If 0δw = n − 1 then δw is of type 1, since there are no transitions going to state 0. If 0δw = n − 2 then w starts with a and has length at least 2, so qδw = n − 1 for all q ∈ QM , and so δw is of type 2. If 0δw ∈ QM then also w starts with a, so qδw ∈ {n − 2, n − 1} for all q ∈ QM , and so δw is of type 3. Recognizing a bifix-free language: It is enough to observe that Dn satisfies the three sufficient and necessary conditions from Lemma 1. Conditions 1 and 2 are trivially satisfied by states n − 1 and n − 2. For condition 3 note ≥6 that all words inducing a transformation in Wbf (n) and so in T (n) satisfy it. Product and star: From Theorem 5 we know that Lm (a, b, c)Ln (a, b, c) meets the bound for product. Since transformation δb maps state 0 to state n − 1, by Theorem 6 we know that L∗n (a, b, c) meets the bound n − 1 for star. Reversal: Consider the standard construction of the NFA N obtained by reversing the edges in Dn and its determinization to DR , which recognizes LR n (a, b, c). Hence, every word w in DR induces a −1 transformation acting on 2Q as δw . First we show that subsets (states of DR ) {n−2}, {0}, and each of the subsets of QM is reachable in DR . Subset {n− 2} is reachable as it is the initial state of DR , and we have {n− 2}δa−1 = QM and QM δa−1 = {0}. We show by reverse induction on cardinality that every subset of QM is reachable. Suppose that any subset of QM of size k is reachable. Consider a subset S ⊂ QM of size k − 1 < n − 3. Since S is a proper subset of QM , it is reachable from a subset S ′ of size k such that h ∈ / S ′ by the rotation (δb−1 )i for some i ∈ {0, . . . , n − 4}. Let ′′ ′ −1 S = {1} ∪ S δc . We have {1}δc = ∅. Also, since δc−1 acts like like a cycle on QM \ {1, h}, h ∈ / S ′, ′ ′ and 1δc = h, we know that S δc has size |S |, does not contain 1, and contains h if and only if S ′ contains 1. Then also (S ′ δc )δc−1 = S ′ . Hence, S ′′ has size |S| + 1 = k, and the induction step holds. It remains to show that all the listed subsets are pairwise distinguishable. Only {n − 2} accepts a2 , and only {0} is final. Consider any two different subsets S, T ⊆ QM . Without loss of generality let q ∈ S \ T . Then DR from S accepts the word bq−1 a whereas from T it does not. Reachability for Boolean operations: ′ (Q′ , Σ′ , δ ′ , 0′ , {(m − 2)′ }), where Q′ = {0′ , . . . , (m − 1)′ }, be Dm of Lm (a, b, c) with the Let Dm states renamed, and let En (Q, Σ, δ ′′ , 0, {n − 2}) be the DFA of the dialect Ln (a, b, c) obtained from Dn by swapping the transitions of letters b and c. Let DP (Q′ × Q, Σ, δ P , (0′ , 0), F P ) be the direct ′ product automaton of Dm and En . The set of final states F P depends on the particular operation and does not matter for reachability. Therefore, we have (p′ , q)δaP = (p′ δa′ , qδa′′ ) = (p′ δa′ , qδa ), (p′ , q)δbP = (p′ δb′ , qδc′′ ) = (p′ δb′ , qδb ), and (p′ , q)δcP = (p′ δc′ , qδb′′ ) = (p′ δc′ , qδc ). We will show that all mn − (m + n) + 2 states in DP are reachable, namely the initial state (0′ , 0) and all (p′ , q) for p′ ∈ Q′ \ {0′ }, q ∈ Q \ {0}. Consider a pair (p′ , q) with p′ ∈ Q′M and q ∈ QM . Let Q′C = Q′M \{1′ , h′ } and QC = QM \{1, h}. First we show that any state of the form (2′ , q) with q ∈ QM is reachable. Then we show as a consequence of the previous fact that any state from the set Q′C × QM ∪ Q′M × QC is reachable. In the third step we show that the states in {1′ , h′ } × {1, h} are also reachable.

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

15

State (2′ , h) can be reached from (0′ , 0) by the word ab. Consider the following two transforma′ tions that fix state 2′ in Dm : cb2 and bc. Note that states (2′ , h−2), (2′ , h−3), . . . , (2′ , 3), (2′ , 2), (2′ , n− ′ 3) are reachable from (2 , h) by the words (cb2 )i for i = 1, . . . , h − 2. Moreover, for n ≥ 9, since P h ≥ 4, we have (2′ , 2)δbc = (2′ , 1). Next, from (2′ , 1) states (2′ , n − 4), (2′ , n − 5), . . . , (2′ , h + ′ ′ 2), (2 , h + 1), (2 , h − 1) are reachable by the words (cb2 )i for i = 1, . . . , n − 3 − h. So we have shown that all states from {2′ } × QM are reachable. In Dn , transformation δb restricted to QM and transformation δc restricted to QC are cycles, and so we can map any state from QM to any other state from QM by δbi for some i, and similarly for QC with δci . Now we show that states (p′ , q) ∈ Q′M × QC are reachable in DP . Let i be such that 2′ δb′ i = p′ and let r ∈ QM be such that rδci = q. Then we have (2′ , r)δbPi = (2′ δb′ i , rδci ) = (p′ , q), thus (p′ , q) is reachable. By the symmetric argument, states (p′ , q) ∈ Q′C × QM are also reachable. Table 2 shows how to reach the four special states in {1′ , h′ } × {1, h}. Table 2. Reachability of states in {1′ , h′ } × {1, h} State ′

(1 , 1) . (1′ , h) (h′ , 1) (h′ , h′ )

Reachable from By word (0′ , 0) ((m − 3)′ , 1) (1′ , n − 3) (1′ , 1)

a b c (bc)2

Finally we show that the states (p′ , q) where p′ ∈ {(m − 2)′ , (m − 1)′ } or q ∈ {n − 2, n − 1} are reachable. State ((m − 2)′ , n − 2) is reachable from (0′ , 0) by a2 , state ((m − 2)′ , n − 1) by ab2 a, state ((m − 1)′ , n − 2) by ac2 a, and state ((m − 1)′ , n − 1) by a3 . Now, using symmetry, without loss of generality, we can assume that p′ ∈ {(m − 2)′ , (m − 1)′ } and q ∈ QM . If p′ = (m − 2)′ , then ((m − 2)′ , q) is reachable by c from (h′ , q − 1) or from (h′ , n − 3) if q = 1. If p′ = (m − 1)′ , then similarly ((m − 1)′ , q) is reachable by c from ((m − 2)′ , q − 1), or from ((m − 2)′ , n − 3) if q = 1. Union: The union is recognized by the product automaton DP with F P = ({(m − 2)′ } × Q) ∪ (Q′m × {n − 2}). States ((m − 2)′ , n − 2), ((m − 2)′ , n − 1), and ((m − 1)′ , n − 2) have the same quotients, and therefore are not distinguishable. We will show that all the remaining reachable states together with one of the above are pairwise distinguishable. These will be mn − (m + n) states. Consider two distinct states (p′1 , q1 ) and (p′2 , q2 ). Since union is symmetric, without loss of generality we can assume that p′1 6= p′2 . If p′1 ∈ Q′M , then we can use the distinguishing word bm−2−p1 c2 from Table 1. It is accepted ′ from state (p′1 , q1 ), but is not accepted from state p′2 in Dm (a, b, c), nor from state q1 nor q2 in En of Ln (a, c, b), because c is the last letter in this word and δb = δc′′ in En does not map any state to n − 2. If p′2 ∈ Q′M we can use the symmetric argument. It remains to consider the case when p′1 , p′2 ∈ {(m − 2)′ , (m − 1)′ }. Without loss of generality let assume that p′1 = (m−2)′ and p′2 = (m−1)′ . If q2 6= n−2, then ((m−2)′ , q1 ) is final but ((m−1)′ , q2 ) is not. If q2 = n − 2, then q1 ∈ QM since otherwise the pairs are not distinguishable. So we may use a, because ((m − 2)′ , q1 )δaP = ((m − 1)′ , n − 2) is final, but ((m − 1)′ , n − 2)δaP = ((m − 1)′ , n − 1) is empty.

16

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

Finally, state (0′ , 0) is distinguished from every other considered states since it the only state from which a2 is accepted. Symmetric difference: The symmetric difference is recognized by the product automaton DP with F P = ({(m − 2)′ } × (Q \ {n − 2}) ∪ ((Q′m \ {(m − 2)′ }) × {n − 2}). State ((m−2)′ , n−1) is equivalent to ((m−1)′ , n−2), and also state ((m−2)′ , n−2) is equivalent to ((m − 1)′ , n − 1). We show that two different reachable states (p′1 , q1 ) and (p′2 , q2 ) that are not one of these equivalent pairs are pairwise distinguishable. Without loss of generality we can assume that p′1 6= p′2 . If p′1 ∈ Q′M or p′2 ∈ Q′M , then we can use the same distinguishing word and argumentation as we do for the union operation, since that word En is not accepted from q2 nor from q1 . So suppose that p′1 , p′2 ∈ {(m − 2)′ , (m − 1)′ }. Without loss of generality let p′1 = (m − 2)′ and ′ p2 = (m − 1)′ (since p′1 6= p′2 as we assumed before). If either q1 6= n − 2 and q2 6= n − 2 or q1 = n − 2 and q2 = n − 2, then ((m − 2)′ , q1 ) and ((m − 1)′ , q2 ) differ, since exactly one of them is final. If q1 = n − 2 and q2 ∈ QM , then state (p′1 , q1 ) = ((m − 2)′ , n − 2) is empty but state (p′2 , q2 ) = ((m − 1)′ , q2 ) is not empty. The last cast is q2 = n − 2 and q1 ∈ QM . Then only ((m − 2)′ , q1 ) can accept a non-empty word (the same as that accepted by q1 in Dn ). Intersection: The intersection is recognized by the product automaton DP with F P = {(m − 2)′ , n − 2)}. We are going to show that (m − 3)(n − 3) + 3 of reachable states are pairwise distinguishable. First we have the three special equivalence classes of states: empty states (e.g. ((m − 1)′ , n − 1)), final state ((m − 2)′ , n − 2), and the initial state (0′ , 0), which is the unique state from which word a2 is accepted. The remaining states have form (p′ , q), where p′ ∈ Q′M and q ∈ QM . All of them are non-empty (a is accepted) and not final. So it is enough to show that two different states from these, (p′1 , q1 ) and (p′2 , q2 ), have different quotients. Without loss of generality we can assume that p′1 6= p′2 . If q1 ∈ QM \ {1, h}, then we can first use a word bi such that p′2 δb′ i = h′ . Then p′1 δb′ i 6= h′ , since b acts as a cycle on QM and p′1 6= p′2 . Moreover q1 δci ∈ QM \ {1, h}. Now we apply c, whose action maps h′ to (m − 2)′ . On the other hand we have p′1 δb′ i δc′ ∈ QM and q1 δci δb ∈ QM . So finally by applying a we get that (p′1 , q1 )δbPi δcP δaP = ((m − 2)′ , n − 2) is final, but (p′2 , q2 )δbPi δcP δaP = ((m − 1)′ , r) for some r ∈ Q \ {0}, which is an empty state. If q1 ∈ {1, h} and q2 ∈ QM \ {1, h}, then we can the previous argument by symmetry. So suppose that q1 , q2 ∈ {1, h}. If p′1 6= h′ then we can apply c, which maps q1 and q2 in En to states of QM \ {1, h}, since n ≥ 7 and so 2 < h < n − 3. We have (p′1 , q1 )δcP = (p′1 δc′ , q1 δb ) ∈ Q′M × (QM \ {1, h}) and (p′2 , q2 )δcP = (p′2 δc′ , q2 δb ) ∈ (Q′M ∪ {(m − 2)′ }) × (QM \ {1, h}). If p′2 δc′ 6= (m − 2)′ , then we have already shown distinguishability of this pair in the previous paragraph. If p′2 δc′ = (m − 2)′ , then letter a distinguishes the pair. Finally, if p′1 = h′ then p′2 6= h′ and we can use the symmetrical argument. Difference: The difference is recognized by the product automaton DP with F P = ({(m − 2)′ } × Q) \ {((m − 2)′ , n − 2)}. We will show that mn−2m−3n+9 of reachable states are pairwise distinguishable. First we have the three special equivalence classes of states: empty states (e.g. ((m−1)′ , n−1) or ((m−2)′ , n−2)), final states (e.g. ((m−2)′ , n−1) or ((m−2)′ , 1)), and initial state (0′ , 0). Initial state is distinguished

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

17

from all reachable states since it is the only one from which word ac2 is accepted. In the second group we have m − 3 different states of the form (p′ , n − 1), where p′1 ∈ Q′M , which are pairwise ′ distinguished in the same way as in Dm , and are not empty nor final. The last group consists of ′ ′ ′ states of the form (p , q), where p ∈ QM and q ∈ QM . They are not final and they are non-empty, because a word bi c, for some i, is accepted from them. They are distinguished from states (p′1 , n−1) from the second group, since word a is not accepted from them, but it is accepted from (p′1 , n − 1). Consider two distinct states (p′1 , q1 ) and (p′2 , q2 ) from the third group. We will show that they are distinguishable. If p′1 6= p′2 , then let take the distinguishing word bn−2−p1 c2 for p′1 from Table 1. It is accepted from (p′1 , q1 ), since a word ending with c cannot be accepted from q1 in En . Also, as a distinguishing word, it is not accepted from p′2 in Dn′ and so not from (p′2 , q2 ) in the product automaton. In the opposite case p′1 = p′2 , so q1 6= q2 . First suppose that p′1 = p′2 ∈ Q′M \ {1′ , h′ }. Let i be such that q1 δbi = h; then q2 δbi 6= h. We have (p′1 , q1 )δcPi ba = (p′1 δc′ i ba , q1 δbi ca ) = ((m − 2)′ , n − 1)), which is a final state. On the other hand (p′2 , q2 )δcPi ba = (p′2 δc′ i ba , q2 δbi ca ) = ((m − 2)′ , n − 2), which is an empty state. Now suppose that p′1 = p′2 ∈ {1′ , h′ }. If q1 , q2 ∈ Q′M \ {h}, then by applying b we result in the previous case, since m ≥ 7. Otherwise one of q1 and q2 , say q1 without loss of P generality, is equal h. Then we use ba and obtain (p′1 , q1 )δba = ((m − 2)′ , hδca ) = ((m − 2)′ , n − 1), P ′ ′ ′ which is final, and (p2 , q2 )δba = ((m − 2) , q2 δca ) = ((m − 2) , n − 2), which is empty. 4.2. Most complex stream. Here we define a most complex stream for all three measures of complexity. To meet the bound for syntactic complexity an alphabet of size at least (n − 3) + ((n − 2)n−3 − 1) + (n − 3)(2n−3 − 1) = (n − 2)n−3 + (n − 3)2n−3 − 1 is required, and so a witness stream cannot have a smaller number of letters. Our stream contains the DFAs from [24, Definition 4], ≥6 which have the transition semigroup Wbf (n). Definition 14 (Most complex stream, [24, Definition 4]). For n ≥ 6, we define the language Wn which is recognized by the DFA Wn with Q = {0, . . . , n − 1} and Σ containing the following letters: (1) bi , for 1 ≤ i ≤ n − 3, inducing the transformations (0 → n − 1)(i → n − 2)(n − 2 → n − 1), (2) ci , for every transformation of type (2) from Definition 2 that is different from (0 → n − 2)(QM → n − 1)(n − 2 → n − 1), (3) di , for every transformation of type (3) from Definition 2 that is different from (0 → q)(QM → n − 1)(n − 2 → n − 1) for some state q ∈ QM . Theorem 15. The stream (Wn | n ≥ 9) is most complex in the class of bifix-free languages: (1) The quotients of Wn have maximal state complexity (Proposition 3); (2) Wm and Wn′ meet the bounds for union, intersection, difference, symmetric difference, where Wn′ is a permutationally equivalent dialect of Wn ; (3) Wm and Wn meet the bound for product; (4) Wn meets the bounds for reversal and star; (5) Wn meets the bound for the syntactic complexity; (6) Wn meets the bounds for the number of atoms and the quotient complexities of atoms (see Theorem 9). Moreover, the size of its alphabet is a smallest possible. Proof. 1) As in the proof of Theorem 13. 2) Note that in the DFAs from Definition 12: • letter a acts as some letter di1 in Wn ;

18

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

• the action of letter b is induced by the word ci2 ci3 , where ci2 induces (0 → n − 2)(1, . . . , n − 3)(n − 2 → n − 1), and ci3 induces (0 → n − 2)(n − 2 → n − 1); • the action of letter c is induced by the word ci4 b1 , where ci4 induces (0 → n − 2)(1, h)(n − 3, . . . , h+1, h−1, . . . , 2)(n−2 → n−1), and b1 induces (0 → n−1)(1 → n−2)(n−2 → n−1). Let Wn′ be a permutationally equivalent dialect of Wn in which the letters ci2 and ci3 are swapped with ci4 and b1 . Then by Theorem 13 Wm and Wn′ meets the bounds for Boolean operations. 3) Meeting the bound for product follows directly from Theorem 5. 4) For reversal observe that every non-empty subset S ⊆ QM is reachable from {n − 2} by the letter di inducing the transformation (0 → q)(S → n − 2)(n − 2 → n − 1). Then {0} is reached from {1} by the letter dj inducing the transformation (0 → 1)(QM → n − 2)(n − 2 → n − 1), and the empty subset from {0} by any transformation. Two distinct subsets S1 , S2 ⊆ QM are distinguished by the letter dk inducing the transformation (0 → q)(S → n − 2)(n − 2), where, without loss of generality, q is such that q ∈ S1 and q ∈ / S2 . Meeting the bound for star follows from Theorem 6. ≥6 5) Since the transition semigroup of Wn is Wbf (n), Wn meets the bound for the syntactic complexity. Also, the size of the alphabet to meet this bound cannot be reduced ([24]). ≥6 6) Since the transition semigroup of the DFA from Theorem 10 is a subsemigroup of Wbf (n), we have all their transformations in the transition semigroup of Wn ; hence Wn also meets the bounds for atom complexities. 5. Conclusions Table 3. A summary of complexity of bifix-free languages for n ≥ 6 with the minimal sizes of the alphabet required to meet the bounds. Measure

Tight upper bound Minimal alphabet

Union Lm ∪ Ln

mn − (m + n)

3

Symmetric difference Lm ⊕ Ln

mn − (m + n)

3

mn − 3(m + n − 4)

2

mn − (2m + 3n − 9)

2

m+n−2

1

n−1

2

Intersection Lm ∩ Ln Difference Lm \ Ln Product Lm Ln Star

L∗n

Reversal

LR n

2 n−3

Syntactic complexity of Ln Atom complexities κ(AS )

(n − 1)

n−3

+2

n−3

+ (n − 2)

(n − 3)2

+

n−3

The bounds from Theorem 9

3 n−3

(n − 2) (n − 3)2

n−3

+

−1

n+1

We completed the previous results concerning complexity of bifix-free languages. The bounds for each considered measure are summarized in Table 3. Our particular contribution is exhibition of a single ternary stream that meets all the bounds on basic operations. Then we showed a most complex stream that meets all the upper bounds of all three complexity measures.

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

19

Table 4. The minimal sizes of the alphabet in a universal most complex stream for some of the studied subclasses of regular languages. Class

Minimal alphabet of a most complex stream(s)

Regular languages [3]

3

Right ideals [4]

4

Left ideals [4]

5

Two-sided ideals [4]

6

Prefix-free [7]

n+2

Prefix-closed [7]

4

k-proper prefix-convex [7]

7 ≤ 3 and 5

Suffix-free [9] n−3

(n − 2)

Bifix-free (Theorem 15)

+ (n − 3)2n−3 − 1 n(n − 1)/2

Non-returning [8]

It is worth noting how the properties of prefix-free and suffix-free languages are shared in the class of bifix-free languages. It is known that there does not exist such a stream in the class of suffixfree languages, even considering only basic operations. Hence, although the classes of bifix-free and suffix-free languages share many properties, such as a similar structure of the largest semigroups, the existence of most complex languages distinguishes them. This is because the bounds for star and product are much smaller for bifix-free languages and are very easily met. Additionally, a most complex stream of bifix-free languages requires a superexponential alphabet, which is much larger than in most complex streams of the other studied subclasses; see Table 4. References [1] J. Berstel, D. Perrin, and C. Reutenauer. Codes and Automata. Cambridge University Press, 2009. [2] J. A. Brzozowski. Quotient complexity of regular languages. J. Autom. Lang. Comb., 15(1/2):71–89, 2010. [3] J. A. Brzozowski. In search of the most complex regular languages. Int. J. Found. Comput. Sc., 24(6):691–708, 2013. [4] J. A. Brzozowski, S. Davies, and B. Y. V. Liu. Most complex regular ideals. http://arxiv.org/abs/1511.00157, 2015. [5] J. A. Brzozowski, G. Jir´ askov´ a, B. Li, and J. Smith. Quotient Complexity of Biﬁx-, Factor-, and Subword-free Regular Languages. Acta Cybernetica, 21(4):507–527, 2014. [6] J. A. Brzozowski, B. Li, and Y. Ye. Syntactic complexity of preﬁx-, suﬃx-, biﬁx-, and factor-free regular languages. Theoret. Comput. Sci., 449:37–53, 2012. [7] J. A. Brzozowski and C. Sinnamon. Complexity of Preﬁx-Convex Regular Languages, 2016. http://http:// arxiv.org/abs/1605.06697. [8] J. A. Brzozowski and C. Sinnamon. Most Complex Non-Returning Regular Languages, 2016. unpublished. [9] J. A. Brzozowski and M. Szykula. Complexity of Suﬃx-Free Regular Languages. In A. Kosowski and I. Walukiewicz, editors, FCT 2015, volume 9210 of LNCS, pages 146–159. Springer, 2015. [10] J. A. Brzozowski and H. Tamm. Theory of a ´tomata. Theoret. Comput. Sci., 539:13–27, 2014. [11] J. A. Brzozowski and Y. Ye. Syntactic complexity of ideal and closed languages. In Giancarlo Mauri and Alberto Leporati, editors, DLT, volume 6795 of LNCS, pages 117–128. Springer, 2011. [12] Janusz Brzozowski, Jeﬀrey Shallit, and Zhi Xu. Decision problems for convex languages. Information and Computation, 209:353–367, 2011.

20

COMPLEXITY OF REGULAR BIFIX-FREE LANGUAGES

[13] R. Cmorik and G. Jir´ askov´ a. Basic operations on binary suﬃx-free languages. In Z. Kot´ asek and et al., editors, MEMICS, pages 94–102, 2012. [14] H.-S. Eom, Y.-S. Han, and G. Jir´ askov´ a. State complexity of basic operations on non-returning regular languages. Fundamenta Informaticae, 144(2):161–182, 2016. [15] The GAP Group. GAP – Groups, Algorithms, and Programming, 2016. [16] Szabolcs Iv´ an. Complexity of atoms, combinatorially. Information Processing Letters, 116(5):356–360, 2016. [17] G. Jir´ askov´ a. On the State Complexity of Complements, Stars, and Reversals of Regular Languages, pages 431–442. Springer, 2008. ˇ [18] G. Jir´ askov´ a, M. Palmovsk´ y, and J. Sebej. Kleene Closure on Regular and Prefix-Free Languages, pages 226–237. Springer, 2014. [19] H. J¨ urgensen and S. Konstantinidis. Codes, pages 511–607. Springer, 1997. [20] R. McNaughton and S. A. Papert. Counter-Free Automata (M.I.T. Research Monograph No. 65). The MIT Press, 1971. [21] S. Piccard. Sur les bases du group sym´ etrique et du groupe alternant. Commentarii Mathematici Helvetici, 11(1):1–8, 1938. [22] J.-E. Pin. Syntactic semigroups. In Handbook of Formal Languages, vol. 1: Word, Language, Grammar, pages 679–746. Springer, New York, NY, USA, 1997. ˇ [23] J. Sebej. Reversal on Regular Languages and Descriptional Complexity, pages 265–276. Springer, 2013. [24] M. Szykula and J. Wittnebel. Syntactic complexity of biﬁx-free languages. http://arxiv.org/abs/1604.06936, 2016.