This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
2. A deterministic finite automaton (DFA) is a quintuple A = (Q , Σ , δ, q0 , F ) where Q is a finite set of states, Σ is an alphabet, δ : Q × Σ → Q is the transition function, q0 ∈ Q is the distinguished start state and F ⊆ Q is the set of final states. We extend δ to a function acting on Q × Σ ∗ in the usual way: δ(q, ε) = q for all q ∈ Q , and δ(q, w a) = δ(δ(q, w), a) for any q ∈ Q , w ∈ Σ ∗ and a ∈ Σ . A DFA A = (Q , Σ , δ, q0 , F ) is said to be complete if δ is defined for all pairs (q, a) ∈ Q × Σ . In this paper, we assume that all DFAs are complete. A string w is accepted by A if δ(q0 , w) ∈ F . The language L(A) is the set of all strings accepted by A: L(A) = {w ∈ Σ ∗ : δ(q0 , w) ∈ F }. A language L is regular if there exists a DFA A such that L(A) = L. A nondeterministic finite automaton (NFA) is a quintuple A = (Q , Σ , δ, q0 , F ) where Q , Σ , q0 and F are as in the deterministic case, but the transition function is δ : Q × Σ → 2Q . The extension of δ to Q × Σ ∗ is accomplished by δ(q, ε) = q and δ(q, wa) = ∪q0 ∈δ(q,w) δ(q0 , a). For an NFA A, L(A) = {w ∈ Σ ∗ : δ(q0 , w) ∩ F 6= ∅}. It is known that NFAs accept exactly the regular languages. The (deterministic) state complexity of a regular language L, denoted sc(L), is the minimum number of states in any DFA which accepts L. Similarly, the nondeterministic state complexity of L is the minimum number of states in any NFA which accepts L, and is denoted by nsc(L). Given a DFA A = (Q , Σ , δ, q0 , F ), a state q ∈ Q is said to be reachable if there exists a string w ∈ Σ ∗ such that δ(q0 , w) = q. Given two states q1 , q2 ∈ Q , we say that they are equivalent if δ(q1 , w) ∈ F if and only if δ(q2 , w) ∈ F for all w ∈ Σ ∗ . If a pair of states is not equivalent, we say that they are inequivalent. 3. State complexity of L k In this section, we consider the state complexity of Lk , while treating the value k as a constant. We show an upper bound which is based on reachability of states, while an explicit lower bound with respect to an alphabet of size six is also given. n The upper and lower bounds differ by a multiplicative factor of 2k(k−1) n− = Θ (1). k 3.1. Upper bound Let L be a regular language with sc(L) = n, and assume that the minimal DFA for L has f final states. Note that the construction of Yu et al. [16, Thm. 2.3] for concatenation gives the following upper bound on Lk for an arbitrary k > 2: n2(k−1)n −
f (2nk − 1) 2(2n − 1)
f
− . 2
We now describe the construction of a DFA for Lk , which we use throughout what follows. Let A = (Q , Σ , δ, 0, F ) be an arbitrary DFA. Assume without loss of generality that Q = {0, 1, . . . , n − 1}. For a subset P ⊆ Q and for w ∈ Σ ∗ , we use the notation δ(P , w) = {δ(p, w) | p ∈ P }. The DFA for L(A)k is defined as Ak = (Qk , Σ , δk , Sk , Fk ) with the set of states Qk = Q × (2Q )k−1 , of which the initial state is Sk = (0, ∅, . . . , ∅) if 0 ∈ / F and Sk = (0, {0}, . . . , {0}) if 0 ∈ F , while the set of final states Fk consists of all states (i, P1 , P2 , . . . , Pk−1 ) ∈ Qk such that Pk−1 ∩ F 6= ∅. The transition function δk : Qk × Σ → Qk is defined as δk ((i, P1 , P2 , . . . , Pk−1 ), a) = (i0 , P10 , P20 , . . . , Pk0 −1 ) where: (1) (2) (3)
i0 = δ(i, a). if i0 ∈ F , then P10 = {0} ∪ δ(P1 , a). Otherwise, P10 = δ(P1 , a). for all 1 6 j 6 k − 2, if Pj0 ∩ F 6= ∅, then Pj0+1 = {0} ∪ δ(Pj+1 , a). Otherwise, Pj0+1 = δ(Pj+1 , a).
According to this definition, it is easy to see that if δk (Sk , w) = (i, P1 , . . . , Pk−1 ), then δ(0, w) = i and further ` ∈ Pj if and only if there exists a factorization w = u0 u1 . . . uj−1 v with u0 , u1 , . . . , uj−1 ∈ L(A) and with δ(0, v) = `. It follows that L(Ak ) = L(A)k .
M. Domaratzki, A. Okhotin / Theoretical Computer Science 410 (2009) 2377–2392
2379
Fig. 1. Representing states from Qk as diagrams.
Fig. 2. Transition table of Ak,n and its action on (Ak,n )k . States with no arrow originating from them are unchanged by the letter.
The above construction of Ak will be used throughout this paper. States from Qk will be represented by diagrams as in Fig. 1. Each row represents one of the k components of Qk , with the jth row representing the jth component. Accordingly, the top row is an element of Q , and all other rows represent subsets of Q . A solid dot will represent that a particular state is an element of the component: the left-most column represents state 0, the next left-most state 1, etc. Since |Qk | = n2(k−1)n , the following upper bound on the state complexity of the kth power can be inferred: Lemma 1. Let k > 2 and let L be a regular language with sc(L) = n. Then the state complexity of Lk is at most n2(k−1)n . 3.2. Lower bound In order to establish a close lower bound on the state complexity of the kth power, it is sufficient to present a sequence of automata Ak,n (2 6 k < n) over the alphabet Σ = {a, b, c , d, e, f }, with every Ak,n using n states, so that L(Ak,n )k requires Ω (n2(k−1)n ) states. Let each Ak,n have a set of states Q = {0, 1, . . . , n − 1}, of which 0 is the initial state, n − 1 is the sole final state, and where the transitions are defined as follows: j + 1 if 1 6 j 6 n − k − 1, if j = n − k, δ(j, a) = 1 j otherwise, ( 1 if j = 0, δ(j, c ) = 0 if j = 1, j otherwise, ( n − 1 if j = 0, δ(j, e) = j − 1 if n − k + 2 6 j 6 n − 1, j otherwise,
(
j+1 δ(j, b) = n − k + 1
(
j
δ(j, d) = δ(j, f ) =
1 j
if n − k + 1 6 j 6 n − 2, if j = n − 1, otherwise,
if j = n − k + 1, otherwise,
n−1 n−2
if j = 1, otherwise.
We now construct a DFA (Ak,n )k for the language L(Ak,n )k as described in Section 3.1. Its set of states is Qk = Q × (2Q )k−1 , and its initial state is (0, ∅, . . . , ∅). Fig. 2 shows the effect of the letters from Σ on states from Qk . In particular, the letter a rotates the elements in the range {1, . . . , n − k} forward, and leaves the remaining states unchanged. The letter b rotates those states in the range {n − k + 1, . . . , n − 1} forward, also leaving the rest of the states unchanged. An occurrence of the letter c swaps the states 0 and 1, leaving all others unchanged, while d collapses the state n − k + 1 onto state 0, leaving all other elements unchanged. The letter e maps the state 0 onto the state n − 1, as well as shifts those states in the range {n − k + 1, . . . , n − 1} back by one. Finally, the letter f collapses all states except 1 onto n − 2, and maps 1 to n − 1. We recall that, according to the construction of (Ak,n )k , n − 1 ∈ Pi implies 0 ∈ Pi+1 for all 1 6 i < k − 1. In the diagrams, this means that a state at the end of one row implies the existence of a state at the beginning of the next row (if such a row is present). We now show the reachability and inequivalence of a large subset of states, which will establish the lower bound. Lemmas 2 and 3 will establish that the states are reachable, and Lemma 4 shows that all such states are inequivalent. Lemma 2. Every state of the form (n − k + 1, P1 , . . . , Pk−1 ), where Pi \ {1, . . . , n − k} = {0, n − k + i + 1} for all 1 6 i < k − 1 and Pk−1 \ {1, . . . , n − k} = {0}, is reachable from the initial state. There are 2(k−1)(n−k) such states, and their general form is presented in the diagram in Fig. 3(b). In these diagrams, white areas without a dot indicate regions that are empty: no states are present in these regions. Grey areas in the diagram represent regions which may or may not be filled: any state in Pi in a grey region may or may not be present.
2380
M. Domaratzki, A. Okhotin / Theoretical Computer Science 410 (2009) 2377–2392
Fig. 3. Outline of the reachability proof for Lk .
Fig. 4. Adding j to Pi using the string an−k−j+1 bk−1−i ccbi aj−1 .
Proof. All states of this form will be reached by induction on the total number of elements in P1 , . . . , Pk−1 . Pk−1 Basis: i=1 |Pi | = 2(k − 2) + 1, that is, Pi = {0, n − k + i + 1} for all i < k − 1 and Pk−1 = {0}, see Fig. 3(a). Then the state is (n − k + 1, {0, n − k + 2}, {0, n − k + 3}, . . . , {0, n − 1}, {0}), and it is reachable from the initial state (0, ∅, . . . , ∅) by ek−1 bk−1 . Induction step: Let (n − k + 1, P1 , P2 , . . . , Pk−1 ) be an arbitrary state with Pi \ {1, . . . , n − k} = {0, n − k + i + 1} for 1 6 i < k − 1 and with Pk−1 \ {1, . . . , n − k} = {0}. Let 1 6 i 6 k − 1 and 1 6 j 6 n − k be any numbers with j ∈ / Pi . The goal is to reach the state (j0 , P1 , . . . , Pi−1 , Pi ∪ {j}, Pi+1 , . . . , Pk−1 ) from (j0 , P1 , P2 , . . . , Pk−1 ), which is sufficient to establish the induction step. In order to add j to Pi , we apply the string an−k−j+1 bk−1−i ccbi aj−1 , as shown in Fig. 4. The prefix an−k−j+1 rotates the empty square to column 1, the next substring bk−1−i rotates the element n − k + i − 2 ∈ Pi−1 to column n − 1, then cc swaps columns 0 and 1 twice, effectively filling the empty square, and the suffix bi aj−1 rotates the columns back to their original order. It remains to move the solid dot in the top row to any column among 1, . . . , n − k. Lemma 3. Every state of the form (j0 , P1 , . . . , Pk−1 ), where 1 6 j0 6 n − k, Pi \ {1, . . . , n − k} = {0, n − k + i + 1} for all 1 6 i < k − 1 and Pk−1 \ {1, . . . , n − k} = {0}, is reachable from the initial state. There are (n − k)2(k−1)(n−k) such states, illustrated in the diagram in Fig. 3(c), in which the arrow represents the range of j0 . Proof. Let (j0 , P1 , . . . , Pk−1 ) be an arbitrary state which satisfies the conditions of the lemma. We claim that there exists a reachable state (n − k + 1, P10 , . . . , Pk0 −1 ) such that, after reading daj0 −1 , we arrive at the state (j0 , P1 , . . . , Pk−1 ). This will establish the lemma. Define Pi0 as follows. Take Pi0 \ {1, . . . , n − k} = {0, n − k + i + 1} for all 1 6 i < k − 1 and Pk0 −1 \ {1, . . . , n − k} = {0}. Next, Pi0 ∩ {1, . . . , n − k} = {` − j0 + 1 : ` ∈ Pi } where subtraction and addition are taken modulo n − k in the range {1, . . . , n − k}. Then the state (n − k + 1, P10 , . . . , Pk0 −1 ) is reachable by Lemma 2, and the subsequent computation upon reading daj0 −1 is presented in Fig. 5. By d, the automaton goes from this state to (1, P10 , . . . , Pk0 −1 ). Next, after the application of aj0 −1 , each Pi0 is properly rotated (in the range {1, . . . , n − k}) to Pi , that is, the automaton proceeds to (j0 , P1 , . . . , Pk−1 ). Lemma 4. All states of the above form are pairwise inequivalent. Proof. We first require the following three claims:
M. Domaratzki, A. Okhotin / Theoretical Computer Science 410 (2009) 2377–2392
2381
Fig. 5. Moving j to position j0 using the string daj0 −1 .
Claim 1. Let (j, P1 , . . . , Pk−1 ) be an arbitrary state and 1 6 i 6 k − 1. After reading the string (cf )k−i , the automaton (Ak,n )k is in a final state if and only if 0 ∈ Pi . Proof. The proof is by induction on i, starting with i = k − 1. For i = k − 1, first suppose that 0 ∈ Pk−1 . Then after reading c, the automaton is in the state (j0 , P10 , . . . , Pk0 −1 ) with 1 ∈ Pk0 −1 . After reading f , the automaton is in the state (j00 , P100 , . . . , Pk00−1 ) with n − 1 ∈ Pk00−1 . This is a final state, as required. Now, suppose that 0 ∈ / Pk−1 . After reading c, we are in the state (j0 , P10 , . . . , Pk0 −1 ) with 1 ∈ / Pk0 −1 . After reading f , the automaton is in the state (j00 , P100 , . . . , Pk00−1 ) where n − 1 ∈ / Pk00−1 , as f maps all states but 1 to the state n − 2. Thus, as n−1∈ / Pk00−1 , the state is not final. Assume that the statement holds for all i with ` < i 6 k − 1. We now establish it for i = ` < k − 1. Assume first that 0 0 ∈ / P` . Again, after reading cf , we are in a state (j0 , P10 , . . . , Pk0 −1 ) where n − 1 ∈ / P`0 . Thus, cf does not add 0 to P`+ 1 . On 0 the other hand, the application of cf ensures that P`+1 ⊆ {n − 2, n − 1}, since f maps all states into that pair, and 0 is not 0 0 k−`−1 added to P`+ / P`+ from (j0 , P10 , . . . , Pk0 −1 ) we are not in a 1 after reading cf . Thus, 0 ∈ 1 . By induction, after reading (cf ) final state. Now assume that 0 ∈ P` . After reading cf , we can verify that we are in a state (j0 , P10 , . . . , Pk0 −1 ) where n − 1 ∈ P` , and thus 0 ∈ P`+1 . Now, by induction, after reading (cf )k−`−1 we arrive at a final state. Claim 2. For all j (0 6 j 6 n − 1), the string an−k−j+1 f (cf )k−1 is accepted from (j0 , P1 , . . . , Pk−1 ) if and only if j = j0 . Proof. To establish this claim, first note that if j = j0 , then an−k−j+1 moves to a state (1, P10 , . . . , Pk0 −1 ), which is then mapped to (n − 1, P100 , . . . , Pk00−1 ) by f . Thus, after reading an−k−j+1 f , we have 0 ∈ P100 . By Claim 1, after reading (cf )k−1 , we arrive at a final state. On the other hand, if j 6= j0 , then an−k−j+1 maps j0 to a state which is mapped to n − 2 after reading f . Thus, after reading n−k−j+1 a f , the DFA is in a state (n − 2, P10 , P20 , . . . , Pk0 −1 ) with 0 ∈ / P10 : we have just read f , which maps all elements to either n − 1 or n − 2, and the first component is not n − 1, which would add 0 to P10 . Again, using Claim 1, we can establish that upon reading (cf )k−1 , such a state (n − 2, P10 , . . . , Pk0 −1 ) proceeds to a non-final state. Claim 3. For all i, j, with 1 6 i 6 k − 1 and 0 6 j 6 n − 1, the string an−k−j+1 f (cf )k−1−i is accepted from a state (j0 , P1 , . . . , Pk−1 ) if and only if j ∈ Pi . Proof. If j ∈ Pi , then reading an−k−j+1 , the automaton moves to a state (j00 , P10 , . . . , Pk0 −1 ) where 1 ∈ Pi0 , which is subsequently mapped to a state (j000 , P100 , . . . , Pk00−1 ) where n − 1 ∈ Pi00 by f . Thus, if i < k − 1, then 0 ∈ Pi00+1 . By Claim 1, after reading (cf )k−i−1 , (j000 , P000 , . . . , Pk00−1 ) proceeds to a final state. Otherwise, if i = k − 1, then (cf )k−i−1 = ε , and since n − 1 ∈ Pk00−1 , the state (j000 , P100 , . . . , Pk00−1 ) is final. If j ∈ / Pi , then after reading an−k−j+1 the automaton moves to a state (j00 , P10 , . . . , Pk0 −1 ) with 1 ∈ / Pi0 , and the subsequent 00 00 00 00 / Pi . If i = k − 1, the string ends here and it is not accepted, which transition by f moves it to (j0 , P1 , . . . , Pk−1 ) with n − 1 ∈ settles the case. Otherwise, if i < k − 1, consider that we have just read an f , which maps every element to either n − 1 or / Pi00+1 . Again, by Claim 1, after reading (cf )k−i−1 , we arrive at a non-final n − 2; then, as n − 1 ∈ / Pi00 , we must have that 0 ∈ state. With these three claims, we can easily establish that if (j0 , P1 , P2 , . . . , Pk−1 ) 6= (j00 , P10 , P20 , . . . , Pk0 −1 ), then there exists a string w ∈ a∗ f (cf )∗ such that exactly one of the states leads to a final state on reading w . This proves Lemma 4. Theorem 1. For every n-state regular language L, with n > 1 the language Lk requires at most n2(k−1)n states. Furthermore for every k > 2, n > k + 1 and alphabet Σ with |Σ | > 6, there exists an n-state regular language L ⊆ Σ ∗ such that Lk requires at least (n − k)2(k−1)(n−k) states. Proof. By Lemmas 1, 3 and 4.
Corollary 1. For every constant k > 2, the state complexity of Lk is Θ (n2(k−1)n ). 4. State complexity of L 3 The state complexity of L2 is known precisely from Rampersad [12], who determined it as n2n − 2n−1 for n > 3. For the next power, the cube, Corollary 1 asserts that the state complexity of L3 is Θ (n4n ), and Theorem 1 states in particular that it lies between (n − 3)4(n−3) and n4n for each n > 4. We now obtain a precise expression for this function.
2382
M. Domaratzki, A. Okhotin / Theoretical Computer Science 410 (2009) 2377–2392
Fig. 6. Unreachable states in Lemma 5.
4.1. Upper bound Let A = (Q , Σ , δ, 0, F ) be an arbitrary DFA. Assume without loss of generality that Q = {0, 1, . . . , n − 1}. Recall from Section 3.1 the construction for Ak for k = 3. In particular, A3 = (Q3 , Σ , δ3 , S3 , F3 ) with the set of states Q3 = Q × 2Q × 2Q , in which the initial state is S3 = (0, ∅, ∅) if 0 ∈ / F and S3 = (0, {0}, {0}) if 0 ∈ F , while F3 consists of all states (i, P , R) ∈ Q3 with R ∩ F 6= ∅. The transition function δ3 : Q3 × Σ → Q3 is defined as follows: δ3 ((i, P , R), a) = (i0 , P 0 , R0 ) where: (1) (2) (3)
i0 = δ(i, a). if i0 ∈ F , then P 0 = {0} ∪ δ(P , a). Otherwise, P 0 = δ(P , a). if P 0 ∩ F 6= ∅, then R0 = {0} ∪ δ(R, a). Otherwise, R0 = δ(R, a).
We now give a description of unreachable states in A3 . We will again use diagrams as in the case of Lk in Section 3 to represent states; in this case, as we are considering the cube, the diagrams will have three rows. Lemma 5. The following states in Q3 are unreachable: (a) (i, P , R) such that i ∈ F and 0 ∈ / P. (b) (i, P , R) such that P ∩ F 6= ∅ and 0 ∈ / R. (c) (i, ∅, R) where R 6= ∅. Additionally, when there is only one final state and this final state is not initial (assume without loss of generality that it is state n − 1), the following states are also unreachable: (d) (i, {i}, Q ) where 0 6 i < n − 1. (e) (i, {i}, Q \ {i}) where 0 6 i < n − 1. (f) (0, Q , {0}). The six cases listed in this lemma are illustrated by the diagrams in Fig. 6. Proof. Cases (a) and (b) follow immediately from the definition of δ3 : if a final state appears in a component, 0 must be added to the next component. Case (c) also follows from the definition of δ3 : elements of R can only be added when elements of P are already present, and once some states appear in P, they will never completely disappear, since the DFA is complete. We now turn to case (d). Let i 6= n − 1 and assume that δ3 ((i0 , P 0 , R0 ), a) = (i, {i}, Q ) for some state (i0 , P 0 , R0 ) and some letter a. Since i is not a final state, the third component of (i, {i}, Q ) must be obtained as δ(R0 , a) = Q , which may only happen if R0 = Q . Then δ(Q , a) = Q , that is, a is a permutation, so every state has a unique inverse image, and we must have that P 0 = {i0 }. Thus, the preceding state (i0 , P 0 , R0 ) is (i0 , {i0 }, Q ), which is of the same form. Therefore, the states of the form (i, {i}, Q ) are reachable only from the states of the same form, and hence unreachable from the start state. Case (e) is similar to case (d). Assume that δ3 ((i0 , P 0 , R0 ), a) = (i, {i}, Q \ {i}) for some state (i0 , P 0 , R0 ) and some letter a, where i 6= n − 1. Since i is not final, the third component of (i, {i}, Q \ {i}) is obtained as δ(R0 , a) = Q \ {i}. On the other hand, δ(i0 , a) = i, so in fact δ(Q , a) = Q and a is a permutation. Therefore, P 0 = {i0 } and R0 = Q \ {i0 }, that is, the state (i, {i}, Q \ {i}) is again reachable only from a state (i0 , {i0 }, Q \ {i0 }) of the same form. This group of states is therefore also not reachable from the initial state. Finally, for case (f), consider the state (0, Q , {0}). Let (j, P , R) ∈ Q3 and a ∈ Σ be such that δ3 ((j, P , R), a) = (0, Q , {0}). As 0 ∈ / F , we have that Q = δ(P , a). Thus, it must be that P = Q . But now, j is the unique state such that δ(j, a) = 0 and R = {j}. Thus, δ3 ((j, Q , {j}), a) = (0, Q , {0}). If j 6= 0, then the state (j, Q , {j}) is already unreachable by case (b). Thus, the only other possibly reachable state leading to (0, Q , {0}) is itself, and the state is unreachable. Note that Lemma 5 does not consider the case of the initial state being the unique final state. This case is in fact trivial in terms of state complexity, which will be discussed in the proof of Lemma 6 below.
M. Domaratzki, A. Okhotin / Theoretical Computer Science 410 (2009) 2377–2392
2383
Lemma 6. Let L be a regular language with sc(L) = n > 3. Then the state complexity of L3 is at most 6n − 3 8
4n − (n − 1)2n − n.
(1)
This upper bound is reachable only if the minimal DFA A for L has a unique final state that is not initial, and only if all states in the corresponding automaton A3 are reachable except those in Lemma 5. Proof. Let A be a DFA with n states and f final states. We first note that if A has only one final state, we may assume without loss of generality that it is not the initial state. Indeed, if the lone final state is also the initial state, then L(A) = L(A)∗ . Thus L(A)k = L(A)∗ for all k > 1, and the state complexity is unaffected by taking powers (and the upper bound given by (1) obviously holds). Therefore, in what follows, in the cases where A has only one final state we assume that it is not the initial state. Consider first the case of more than one final state. Then the conditions (a), (b) and (c) from Lemma 5 are applicable. The total number of states is n4n . We can also count the number of unreachable states: (a) f 22n−1 states of the form (i, P , R) such that i ∈ F and 0 ∈ / P. (b) If 0 ∈ / F , there are n(2f − 1)22n−f −1 states of the form (i, P , R) such that P ∩ F 6= ∅ and 0 ∈ / R. Of them, f (2f − 1)22n−f −2 states also satisfy i ∈ F and 0 ∈ / P, and hence have already been excluded by (a). In total, there are n(2f − 1)22n−f −1 − f (2f − 1)22n−f −2 new unreachable states. On the other hand, if 0 ∈ F , there are n(2f − 1)22n−f −1 − f (2f −1 − 1)22n−f −1 states of the form (i, P , R) such that P ∩ F 6= ∅ and 0 ∈ / R not already excluded by (a). (c) (n − f )(2n − 1) states of the form (i, ∅, R) not already excluded by (a). The refined total of reachable states in the case that 0 ∈ / F is: n4n − f 22n−1 − (2f − 1)22n−f −2 (2n − f ) − (n − f )(2n − 1).
(2)
In the case where 0 ∈ F , it is n4n − f 22n−1 − ((2n − f )2f −1 − (n − f ))22n−f −1 − (n − f )(2n − 1).
(3)
For one final state, cases (d), (e) and (f) of Lemma 5 yield an additional 2(n − 1) + 1 = 2n − 1 states which are unreachable. Thus, the total for one final state (which is not the initial state by assumption) is, using (2), n4n − 22n−1 − 22n−3 (2n − 1) − (n − 1)(2n − 1) − 2n + 1.
(4)
− (n − 1)2n − n. Now, consider the case of f > 2: we can easily verify that f (2f −1 − 1)22n−f −1 < f (2f − 1)22n−f −2 , and hence the expression
Simplifying the above, we get the expression
6n−3 n 4 8
in (3) is larger than (2). Thus, in order to show that (4) is the true upper bound, we must show that it is larger than (3). That is, we must show that the inequality n4n − f 22n−1 − ((2n − f )2f −1 − (n − f ))22n−f −1 − (n − f )(2n − 1)
3 and 2 6 f 6 n − 1. Rewriting the left-hand side of the inequality, we get n4n − f 22n−1 − (2n − f )2f −1 − (n − f ) 22n−f −1 − (n − f )(2n − 1)
n f n−f n−f = 4n + (n − f ) − + f +1 − n 2 4 2 2 1 n−2 n n n 5n − 6 64 − + + (n − 2) = 4 + (n − 2). 2
2
8
8
In the above inequality, we use the facts that n > 3 and 2 6 f 6 n − 1. Now, note that subtracting the final quantity 4n ( 5n8−6 ) + (n − 2) from the right-hand side of the original inequality gives
n+3 8
4n − (n − 1)2n − 2n + 2.
It is now easy to verify that this quantity is strictly above zero for all n > 3.
2384
M. Domaratzki, A. Okhotin / Theoretical Computer Science 410 (2009) 2377–2392
Fig. 7. Witness automata An for cube.
4.2. Lower bound We now turn to showing that the upper bound in Lemma 6 is attainable over a four-letter alphabet. Consider a sequence of DFAs {An }n>3 defined over the alphabet Σ = {a, b, c , d}, where each automaton An has the set of states Q = {0, . . . , n − 1}, of which 0 is the initial state and n − 1 is the only final state, while the transition function is defined as follows: i+1 1 n−1
if 0 6 i 6 n − 3, if i = n − 2, if i = n − 1,
n−1 i 0
if i = 0, if 1 6 i 6 n − 1, if i = n − 1,
( δ(i, a) =
( δ(i, c ) =
0
(
δ(i, b) = i + 1 1
δ(i, d) =
i 0
if i = 0, if 1 6 i 6 n − 2, if i = n − 1,
if 0 6 i 6 n − 2, if i = n − 1.
The form of these automata is illustrated in Fig. 7. Note that the transition tables for a, b and c are permutations of the set of states, and therefore, for every σ ∈ {a, b, c }, one can consider its inverse σ −1 : Q → Q . Denote by σ −1 (j) for j ∈ Q , the unique state k such that δ(k, σ ) = j. One can consider sequences of negative symbols; for any ` > 0 denote by σ −` (j) the unique state k with δ(k, σ ` ) = j. This notation is naturally extended to sets of states: for any set P ⊆ {0, . . . , n − 1}, for any letter σ ∈ {a, b, c } and for any ` > 0, we use the notation σ −` (P ) to denote the uniquely defined set P 0 ⊆ {0, . . . , n − 1} such that δ(P 0 , σ ` ) = P. We use the construction for (An )3 given in Section 3.1. We also again use diagrams as in the case of Lk in Section 3 to represent states. We now establish three lemmas to show reachability of all states in (An )3 : first those states whose third component is empty, then those of the form (i, P , R) where i ∈ / P, and finally those with i ∈ P. Lemma 7. Every state of the form (i, P , ∅), where (I) i ∈ / P; (II) n − 1 ∈ / P; (III) if i = n − 1, then 0 ∈ P, is reachable by a string from {a, b}∗ . In other words, Lemma 7 claims that all states (i, P , R) with i ∈ / P and R = ∅ that are not deemed unreachable by Lemma 5 are in fact reachable. Proof. Induction on |P |. Basis: P = ∅. A state (i, ∅, ∅) with 0 6 i < n − 1 is reachable via ai from the start state (0, ∅, ∅). Induction step. The proof is organized into several cases, some of which are split into subcases. Each case is illustrated Fig. 8. Case 1: i = n − 1. Consider a state S = (n − 1, P , ∅) with 0 ∈ P and n − 1 ∈ / P. Case 1(a): If 1 ∈ / P, then S is reachable from (n − 2, b−1 (P \ {0}), ∅) by b, while the latter state is reachable according to the induction hypothesis, as |b−1 (P \ {0})| < |P |. Case 1(b): If 1 ∈ P, then S is reachable by a from (n − 1, a−1 (P \ {0}), ∅), which is in turn reachable by the induction hypothesis. Case 2: i = 1. Consider any state S = (1, P , ∅) with 1, n − 1 ∈ / P. Case 2(a): If 0 ∈ P, then S is reachable from (n − 1, {0} ∪ b−1 (P \ {0}), ∅) by b, where the latter state was shown to be reachable in the previous case. Case 2(b): If 0 ∈ / P, consider the greatest number ` with ` ∈ P. The state (1, {0} ∪ (P \ {`}), ∅) is reachable as in Case 2(a), and from this state the automaton goes to S by bn−1−` a` . Case 3: i 6= n − 1. Finally, any state S = (i, P , ∅) with 0 6 i 6 n − 2 and n − 1 ∈ / P is reachable from the state (1, a−(i−1) (P ), ∅) by ai−1 . States of the latter form have been shown to be reachable in Case 2.
M. Domaratzki, A. Okhotin / Theoretical Computer Science 410 (2009) 2377–2392
2385
Fig. 8. Reachability of states (i, P , ∅) in Lemma 7.
The above Lemma 7 will now be extended to reach all states (i, P , R) with i ∈ / P that are not unreachable due to Lemma 5. Lemma 8. Every state of the form (i, P , R), where (I) (II) (III) (IV)
i∈ / P; |P | > 1; if i = n − 1, then 0 ∈ P; if n − 1 ∈ P, then 0 ∈ R,
is reachable. Proof. Induction on |R|. The basis, R = ∅, is given by Lemma 7. For the induction step, we have three major cases, each of which is broken into several subcases. These cases are illustrated in Fig. 9. Case 1: n − 1 ∈ P. Case 1(a): 1 ∈ / P, i 6= 1. Then the state (b−1 (i), b−1 (P ), b−1 (R \ {0})) is reachable by the induction hypothesis, and from it the state (i, P , R) is reachable by b. Case 1(b): 1 ∈ / P, i = 1, 0 ∈ / P. Then (1, P , R) is reachable from (1, c −1 (P ), c −1 (R \ {0})) by c, where the latter state is reachable by the induction hypothesis. Case 1(c): 1 ∈ / P, i = 1, 0 ∈ P. Then the state (n − 1, b−1 (P ), b−1 (R \ {0})) is reachable by the induction hypothesis, and from this state the automaton goes by b to (1, P , R). Case 1(d): 1 ∈ P. Let j be the greatest number, such that 1, . . . , j ∈ P. Then either i > j or i = 0, and in each case (i, P , R) is reachable from (b−j (i), b−j (P ), b−j (R)) by bj . The latter state has n − 1 ∈ b−j (P ) and 1 ∈ / b−j (P ), and hence it has been proved to be reachable in Cases 1(a)–1(c). Case 2: n − 1 ∈ / P, n − 1 ∈ R. Case 2(a): 0 ∈ P. This state is reachable by c from (c −1 (i), c −1 (P ), c −1 (R)), which has n − 1 ∈ c −1 (P ) and is therefore reachable as in Case 1. Case 2(b): 0 ∈ / P. Let j be the least number in P. Then this state is reachable by aj from (a−j (i), a−j (P ), a−j (R)), which is reachable as in Case 2(a). Case 3: n − 1 ∈ / P, n − 1 ∈ / R. Case 3(a): 0 ∈ P, 0 ∈ R. This case is further split into three subcases depending on the cardinality of P and R: (3(a1 )) First assume |P | > 2 and let j be the least element of P \{0}. Then (i, P , R) is reached by bj from (b−j (i), b−j (P ), b−j (R)), which is in turn reachable as in Case 1, since n − 1 ∈ b−j (P ). 2 (3(a )) Similarly, if |R| > 2, then setting j as the least element of R \ {0} one can reach (i, P , R) by bj from (b−j (i), b−j (P ), b−j (R)), which has n − 1 ∈ b−j (R) and hence is reachable as in Case 1 or Case 2. (3(a3 )) The remaining possibility is |P | = |R| = 1, that is, P = {0} and R = {0}. Consider the state (1, {n − 1}, {0}), which was shown to be reachable in Case 1(b). From this state, the automaton goes to (1, {0}, {0}) by d and then to (i, {0}, {0}) by bi−1 .
2386
M. Domaratzki, A. Okhotin / Theoretical Computer Science 410 (2009) 2377–2392
Fig. 9. Reachability of (i, P , R) with i ∈ / P: cases in the proof of Lemma 8.
Case 3(b): 0 6 i 6 n − 2, P ∩ R 6= ∅. Let j ∈ P ∩ Q be the least such number. Then this state is reachable by aj from (a (i), a−j (P ), a−j (R)), which is reachable as in Case 3(a). Case 3(c): 0 6 i 6 n − 2, P ∩ R = ∅. Since P , R 6= ∅, there exists at least one pair (j, k) with j ∈ P and j + k (mod n − 1) ∈ R. −j
M. Domaratzki, A. Okhotin / Theoretical Computer Science 410 (2009) 2377–2392
2387
Fig. 10. Reachability of (i, P , R) with i ∈ P: cases in the proof of Lemma 9.
(V) if P = {i}, then R 6= Q and R 6= Q \ {i}. (VI) if i = 0 and P = Q , then R 6= {0} is reachable. Note that the last two conditions of Lemma 9 exactly match the last three cases of Lemma 5. Proof. The proof again involves examining several cases, though this time there is no induction. These cases are illustrated in Fig. 10. The first case is based upon Lemma 8, the other cases depend on the first case and on each other. All cases except the last one, Case 4, deal with i 6= n − 1: Case 1 assumes n − 1 ∈ / P and n − 1 ∈ / R, Case 2 uses n − 1 ∈ P and Case 3 handles the last possibility: n − 1 ∈ / P and n − 1 ∈ R. Case 1: i 6= n − 1, n − 1 ∈ / P and n − 1 ∈ / R (that is, the column n − 1 in a diagram is empty). Any such state is reachable by dai from (n − 1, a−i (P ), a−i (R)), which has 0 ∈ a−i (P ), n − 1 ∈ / a−i (P ) and n − 1 ∈ / a−i (R), and is therefore reachable by Lemma 8. Case 2: i 6= n − 1 and n − 1 ∈ P (and therefore 0 ∈ R). Case 2(a): 0 ∈ / P, and therefore i 6= 0. This state is reachable from i, c −1 (P ), c −1 (R \ {0}) by c, which is reachable as in Case 1. Case 2(b): 0 ∈ P and i 6= 0. Consider the state 0, b−i (P ) \ {n − 1}, c −1 (b−i (R)) \ {n − 1} , which has empty column n − 1 and is therefore reachable as in Case 1. From this state, the automaton goes to (n − 1, b−i (P ), b−i (R)) by c, which has 0 ∈ b−i (P ) and 0 ∈ b−i (R). Therefore, by bi the automaton further proceeds to (i, P , R). Case 2(c): 0 ∈ P and i = 0. This case will be proved at the end of the proof. Case 3: i 6= n − 1, n − 1 ∈ / P and n − 1 ∈ R. Case 3(a): |P | > 2. Let j ∈ P \ {i} and consider the state (a−j (i), c −1 (a−j (P )), c −1 (a−j (R))), which is reachable as in Case 2(a). From this state, the automaton goes to (a−j (i), a−j (P ), a−j (R)) by c and then to (i, P , R) by aj . Case 3(b): |P | = 1. Then this is a state of the form (i, {i}, R). By Condition (V) in the statement of the lemma, R 6= Q and R 6= Q \ {i}. Therefore, there exists j ∈ / R with j 6= i. If i < j, then (i, {i}, R) is reachable by bj−i ai from (0, 0, b−(j−i) (a−i (R)));
2388
M. Domaratzki, A. Okhotin / Theoretical Computer Science 410 (2009) 2377–2392
the latter state has n − 1 ∈ / b−(j−i) (a−i (R)), and so it is reachable as in Case 1. The same construction is applicable for any j 6= i, if one starts from (0, 0, b−(n−1−i+j) (a−i (R))) and uses bn−1−i+j ai . Case 4: i = n − 1 (and therefore 0 ∈ P and 0 ∈ R). This state is reachable by c from (0, c −1 (P ) \ {n − 1}, c −1 (R) \ {n − 1}), which is in turn reachable as in Case 1. This completes the case study. Now it remains to prove the last case 2(c), in which i = 0, 0 ∈ P and n − 1 ∈ P (and therefore 0 ∈ R). It follows from Condition (VI) in the statement of the lemma that there exists j > 0 with j ∈ / P or j ∈ R: indeed, if there were no such j, then P = Q and R = {0}, which would contradict Condition (VI). The proof splits into two subcases depending on j and its membership in P and in R: (2(c1 )) j ∈ P (and therefore j ∈ R by the definition of j). This state is reachable by cbj from (n − 1, c −1 (b−j (P )), c −1 (b−j (R))), which is in turn reachable as in Case 4. (2(c2 )) j ∈ / P. Consider the state (0, b−j (P ), b−j (R)\{0}), which is reachable as in Case 1 or 3(a). From this state, the automaton goes by bn−1 to state (0, b−j (P ), b−j (R)), because b−j (P ) contains the element n − 1 − j, which will eventually pass through position n − 1 and hence put 0 in R. Next, the automaton goes to (0, P , R) by bj . This remaining case concludes the proof. Thus, by the previous three lemmas, all the states which are not proven to be unreachable by Lemma 5 are, in fact, reachable. We now prove that distinct states are inequivalent. Lemma 10. All states in Q3 are pairwise inequivalent. Proof. Let (i, P , R) 6= (i0 , P 0 , R0 ). To show the inequivalence of these states, it is sufficient to construct a string that is accepted from one of these states but not from the other. If R 6= R0 , then we can assume without loss of generality that there exists a state j ∈ R \ R0 . If j > 1, then the string bn−1−j is accepted from (i, P , R) but not from (i0 , P 0 , R0 ). If j = 0, then abn−2 is accepted from (i, P , R) but not from (i0 , P 0 , R0 ). If P 6= P 0 , then assume without loss of generality that there is a state j ∈ P \ P 0 . If j 6 n − 2, then an−2−j dacabn−2 is accepted from (i, P , R) but not from (i0 , P 0 , R0 ). If j = n − 1, then bn−2 dacabn−2 is accepted from (i, P , R) but not from (i0 , P 0 , R0 ). Suppose i 6= i0 . If i 6 n − 2, then an−2−i dacan−2 dacabn−2 is accepted from (i, P , R) but not from (i0 , P 0 , R0 ). If i = n − 1, then bn−2 dacan−2 dacabn−2 is accepted from (i, P , R) but not from (i0 , P 0 , R0 ). Theorem 2. The state complexity of L3 is at most alphabet of at least 4 letters.
6n−3 n 4 8
− (n − 1)2n − n for all n > 3. This upper bound is reached on every
4.3. From cube to square We now give an interesting result which states that any witness for the worst case state complexity of L3 is also a witness for L2 as well. Proposition 1. Let L be a regular language with sc(L) = n > 3 and sc(L3 ) =
6n−3 n 4 8
− (n − 1)2n − n. Then sc(L2 ) = n2n − 2n−1 .
Proof. As sc(L) > 3, we note that L 6= ∅. Let A = (Q , Σ , δ, 0, F ) be a DFA for L and assume without loss of generality that Q = {0, . . . , n − 1}. Then A2 = (Q2 , Σ , δ2 , S2 , F2 ) is a DFA for L2 where Q2 = Q × 2Q \ {(i, P ) : i ∈ F , 0 ∈ / P }, S2 = (0, ∅) if 0 ∈ / F and S2 = (0, {0}) otherwise, F2 = {(i, P ) : P ∩ F 6= ∅} and δ2 is defined as: δ2 ((i, P ), a) = (i0 , P 0 ) where (1) i0 = δ(i, a). (2) if i0 ∈ F , then P 0 = {0} ∪ δ(P , a). Otherwise, P 0 = δ(P , a). Assume that sc(L2 ) < n2n − 2n−1 . Then when we use the construction of Yu et al. [16], we obtain either a state which is unreachable, or a pair of equivalent states. Consider reachability first. Let (i, P ) ∈ Q2 be arbitrary. Consider the state S ∈ Q3 defined by S = (i, P , ∅) if P ∩ F = ∅ and S = (i, P , {0, i0 }) for some arbitrary state i0 ∈ Q \ {0} otherwise (note that since n > 3, we can assume that i0 6= 0). The construction for L2 of Yu et al. excludes those states such that i ∈ F and 0 ∈ / P, so we note that condition (a) of Lemma 5 does not hold for S. Further, by the definition of S, conditions (b)–(e) trivially hold. Condition (f) also holds since the third component of S has size zero or two by definition. Thus, S does not satisfy the conditions of Lemma 5, so must be reachable. But then (i, P ) must also be reachable in A2 by the same input. We now turn to equivalence. In what follows, for any (i1 , P1 ), (i2 , P2 ) ∈ Q2 , we denote by (i1 , P1 ) ∼2 (i2 , P2 ) the fact that for all x ∈ Σ ∗ , if δ2 ((i1 , P1 ), x) = (i01 , P10 ) and δ2 ((i2 , P2 ), x) = (i02 , P20 ), then P10 ∩ F 6= ∅ if and only if P20 ∩ F 6= ∅. That is, ∼2 is the equivalence of states for A2 . We require the following claim: Claim 4. Let i1 , i2 ∈ Q , P1 , P2 ⊆ Q with (i1 , P1 ) ∼2 (i2 , P2 ). Let Y ⊆ Q be arbitrary. For all x ∈ Σ ∗ , there exists R ⊆ Q such that
δ3 ((i1 , P1 , Y ), x) = (i01 , P10 , R) and δ3 ((i2 , P2 , Y ), x) = (i02 , P20 , R).
M. Domaratzki, A. Okhotin / Theoretical Computer Science 410 (2009) 2377–2392
2389
Proof. The proof is by induction on |x|. For |x| = 0, then x = ε and we have that
δ3 ((i1 , P1 , Y ), ε) = (i1 , P1 , Y ) and δ3 ((i2 , P2 , Y ), ε) = (i2 , P2 , Y ). Assume that the result holds for all x ∈ Σ ∗ with |x| < k. Let x ∈ Σ ∗ be an arbitrary string of length k, and write x = x0 a where |x0 | = k − 1 and a ∈ Σ . Thus, note that
δ3 ((i1 , P1 , Y ), x0 ) = (i01 , P10 , R) and δ3 ((i2 , P2 , Y ), x0 ) = (i02 , P20 , R) for some R ⊆ Q . Let
δ3 ((i01 , P10 , R), a) = (i001 , P100 , R1 ) and δ3 ((i02 , P20 , R), a) = (i002 , P200 , R2 ) for some i001 , i002 ∈ Q and P100 , P200 , R1 , R2 ⊆ Q . We have two cases: (i) P100 ∩ F = ∅. By equivalence in A2 , the same is true of P200 . Thus, by the definition of δ3 , we have that R1 = δ(R, a) and R2 = δ(R, a) as well. Thus, R1 = R2 . (ii) P100 ∩ F 6= ∅. In this case, R1 = R2 = δ(R, a) ∪ {0}. Thus, the claim holds. We now show that all pairs of reachable states in Q2 are inequivalent. Assume not. Then there exists (i1 , P1 ), (i2 , P2 ) ∈ Q2 such that (i1 , P1 ) ∼2 (i2 , P2 ). There are three cases: (i) P1 ∩ F = ∅ (note that P2 ∩ F = ∅ as well by equivalence of states, in particular, with x = ε ). In this case, as we assume that sc(L3 ) achieves the bound in Lemma 6, and as the states (i1 , P1 , ∅) and (i2 , P2 , ∅) are not unreachable by Lemma 5, we must have that both (i1 , P1 , ∅) and (i2 , P2 , ∅) are reachable. In particular, note that conditions (d) and (e) are not satisfied since the final component is empty and n > 3. Further, (i1 , P1 , ∅) and (i2 , P2 , ∅) are equivalent in A3 by Claim 4: every state reachable from them on x has the same third component. (ii) P1 ∩ F 6= ∅, but (i1 , P1 ) 6= (0, Q ) and (i2 , P2 ) 6= (0, Q ). In this case, the states (i1 , P1 , {0}) and (i2 , P2 , {0}) are reachable. Further, as in Case (i), they are equivalent. (iii) (i1 , P1 ) = (0, Q ) (a similar case handles (i2 , P2 ) = (0, Q )). In this case, (i1 , P1 , {0, i}) and (i2 , P2 , {0, i}) are reachable states in A3 for any choice of 0 < i ∈ / F . They are equivalent by the same argument used in Case (i). Thus, in all cases, we have constructed a pair of states in Q3 which are reachable and equivalent. This is a contradiction, since each pair of states in Q3 are inequivalent, by assumption. We note that the reverse implication in Proposition 1 does not hold: for example, the witness languages given by Rampersad for the worst case complexity of L2 are over a two-letter alphabet. But by the calculations in Section 6, we will see that no language over a two-letter alphabet may give the worst case complexity for L3 for small values of n. 5. Nondeterministic state complexity We now turn to nondeterministic state complexity. Nondeterministic state complexity for basic operations has been examined by Holzer and Kutrib [6] and Ellul [3]. We give tight bounds on the nondeterministic state complexity for Lk for any k > 2. We adopt the fooling set method for proving the lower bounds on nondeterministic state complexity in the form of Birget [1, p. 188]. A fooling set for an NFA M = (Q , Σ , δ, q0 , F ) is a set S ⊆ Σ ∗ × Σ ∗ such that (a) xy ∈ L(M ) for all (x, y) ∈ S and (b) for all (x1 , y1 ), (x2 , y2 ) ∈ S with (x1 , y1 ) 6= (x2 , y2 ), either x1 y2 ∈ / L(M ) or x2 y1 ∈ / L(M ). If S is a fooling set for M, then nsc(L) > |S |. Theorem 3. For all regular languages L with nsc(L) = n and all k > 2, nsc(Lk ) 6 kn. Furthermore, for all n > 2 and k > 2, the bound is reached by a language over a binary alphabet. Proof. The upper bound is given by the construction of Holzer and Kutrib [6] or Ellul [3] for concatenation, which states that if nsc(L1 ) = n and nsc(L2 ) = m then nsc(L1 L2 ) 6 n + m. For the lower bound, consider the language Ln = an−1 (ban−1 )∗ , which is recognized by an n-state NFA given in Fig. 11(a). The language (Ln )k = (an−1 (ban−1 )∗ )k is recognized by the NFA in Fig. 11(b). The following facts will be useful: Claim 5. The only string in (Ln )k ∩ a∗ is ak(n−1) . Claim 6. The following equality holds: (Ln )k ∩ a∗ ba∗ = {aj(n−1) ba(k−j+1)(n−1) : 1 6 j 6 k}. In particular, each string in the intersection has length (k + 1)(n − 1) + 1.
2390
M. Domaratzki, A. Okhotin / Theoretical Computer Science 410 (2009) 2377–2392
Fig. 11. NFAs for Ln and for (Ln )k . Table 1 Worst case complexity of Lk . n
L2
L3
L4
L5
L6
L7
L8
2 3 4 5 6 7
5 20 56 144 352 832
7 101 620 3323 16570 79097
9 410 6738 76736 782092
11 1 331 65854 1713946
13 3729 564566
15 8833
17 18176
Our fooling set is Sn,k = {(ε, an−1 bak(n−1) )} ∪ Sn,k,1 ∪ Sn,k,2 , where Sn,k,1 = {(a(n−1)j+i , an−i−1 ba(n−1)(k−j) ) : 1 6 i 6 n − 1, 0 6 j 6 k − 1} Sn,k,2 = {(a(n−1)j b, a(k−j+1)(n−1) : 2 6 j 6 k}. The total size of the fooling set is nk, as Sn,k,1 has size k(n − 1) and Sn,k,2 has size k − 1. Further, by Claim 6, all of the elements (x, y) ∈ Sn,k satisfy xy ∈ (Ln )k . It remains to show that for all (x1 , y1 ), (x2 , y2 ) ∈ Sn,k with (x1 , y1 ) 6= (x2 , y2 ), either x1 y2 ∈ / (Ln )k or x2 y1 ∈ / (Ln )k . We say such pairs are inequivalent in what follows. First note that none of an−i−1 ba(n−1)(k−j) with 1 6 i 6 n − 1 and 0 6 j 6 k − 1 or a(k−j+1)(n−1) are in (Ln )k . Thus, the element (ε, an−1 bak(n−1) ) is inequivalent with all elements of Sn,k,1 ∪ Sn,k,2 . 0 0 0 0 Next, we consider two pairs from Sn,k,1 . Take the pairs (a(n−1)j+i , an−i−1 ba(n−1)(k−j) ) and (a(n−1)j +i , an−i −1 ba(n−1)(k−j ) ) for 0 0 some i, i0 , j, j0 with 1 6 i, i0 6 n − 1 and 0 6 j, j0 6 k − 1. Assume (i, j) 6= (i0 , j0 ). Consider the string a(n−1)j+i an−i −1 ba(n−1)(k−j ) . Its length is (n − 1)j + i + n − i0 + (n − 1)(k − j0 ) = (j − j0 )(n − 1) + (i − i0 ) + (n − 1)(k + 1) + 1. Suppose j 6= j0 ; then |(j − j0 )(n − 1)| > n − 1, and since |i − i0 | < n − 1, we have (j − j0 )(n − 1) + (i − i0 ) 6= 0, that is, the length of the string is different from (n − 1)(k + 1) + 1. If j = j0 and i 6= i0 , then (j − j0 )(n − 1) + (i − i0 ) = i − i0 6= 0, and again the string is not of length (n − 1)(k + 1) + 1. In each case the string is not in (Ln )k by Claim 6. 0 0 Now consider two pairs from Sn,k,2 . If we take (a(n−1)j b, a(k−j+1)(n−1) ) and (a(n−1)j b, a(k−j +1)(n−1) ), for some 2 6 j < j0 6 k, (n−1)j (k−j0 +1)(n−1) then we can consider the string w = a ba . Note that this string has length (n − 1)(k − (j0 − j) + 1) + 1 < k (n − 1)(k + 1) + 1. Therefore, w is not in (Ln ) by Claim 6. Finally, it remains to consider pairs from Sn,k,1 × Sn,k,2 . Consider p1 = (a(n−1)j+i , an−i−1 ba(n−1)(k−j) ) and p2 = 0 (n−1)j0 (a b, a(k−j +1)(n−1) ) for some 1 6 i 6 n − 1, 0 6 j 6 k − 1 and 2 6 j0 6 k. There are two cases: (a) if i 6= n − 1, then consider a(n−1)j+i a(k−j +1)(n−1) , obtained from concatenating the first component of p1 and the second component of p2 . As i 6= n − 1, the length of the above string is not divisible by n − 1 and thus is certainly not in (Ln )k ∩ a∗ by Claim 5. 0 (b) if i = n − 1, then consider a(n−1)j ban−i−1 ba(n−1)(k−j) , which is the first component of p2 concatenated with the second component of p1 . Simplifying, we note that this string has an occurrence of bb, which is impossible as n > 2. 0
This completes the proof. 6. Calculations We present some numerical calculations of the worst case state complexity of Lk for k from 2 to 8 and for small values of n. In each case, this state complexity can be computed by considering automata over an nn -letter alphabet, in which the transitions by different letters represent all possible functions from Q → Q . For the final states, we follow the computational technique described by Domaratzki et al. [2], which requires only considering O(n) different assignments of final states. The computed results are given in Table 1. For instance, the worst case complexity of L4 for all DFAs of size 6 (782092) is taken with respect to an alphabet of size 66 = 46656. In particular, the column for L2 starting from n = 3 is known from Rampersad [12], who obtained a closed-form expression n2n − 2n−1 ; note that for n = 2 the upper bound is five states, which is slightly less than the general bound. The case of L3 is presented in more detail in Table 2, which demonstrates the worst case state complexity of L3 over alphabets of size 2, 3, 4 and of size nn (where n is the number of states) for automata of size n between 1 and 5. The final
M. Domaratzki, A. Okhotin / Theoretical Computer Science 410 (2009) 2377–2392
2391
Table 2 Worst case state complexity of L3 .
1 2 3 4 5 6 7
2
3
4
nn
Upper bound
1 7 64 410 2277
1 7 96 608
1 7 101 620
1 7 101 620 3323 16570 79097
101 620 3323 16570 79097
column gives the upper bound from Theorem 2. Note that the table demonstrates that this upper bound cannot be reached for small values of n on alphabets of size three or fewer. Let us mention how these calculations helped us in obtaining the theoretical results in this paper. One of our computations considered all minimal 4-state DFAs over a 4-letter alphabet, pairwise nonisomorphic with respect to permutations of states and letters. There are 364644290 such automata; for each of them, the minimal DFA for its cube was computed, which took in total less than 6 days of machine time. In total 52 DFAs giving the top result (620 states) were found, and one of them was exactly the DFA A4 defined in Section 4.2. We obtained the general form of the automata An that witness the state complexity of the cube by generalizing this single example. 7. Conclusions and open problems We have continued the investigation of the state complexity of power, previously investigated by Rampersad [12]. We have given an upper bound for the state complexity of L3 over alphabets of size two or more, and shown that it is optimal for alphabets of size four by giving a matching lower bound. By calculation, the bound is not attainable for alphabets of size two or three, at least for small DFA sizes. For the case of general Lk , we have established an asymptotically tight bound. In particular, we have shown that if L is a regular language with state complexity n and k > 2, then the state complexity of Lk is Θ (n2(k−1)n ). The upper and lower n bounds on the state complexity of Lk differ by a factor of 2k(k−1) n− ; we leave it as a topic for future research to improve the k bounds for k > 4. Very recently, Ésik et al. [4] have determined the state complexity of concatenations of three and four regular languages: L1 · L2 · L3 and L1 · L2 · L3 · L4 . Unlike the cases of L3 and L4 studied in this paper, the languages being concatenated in these expressions need not be the same. Hence, the restrictions of Lemma 5(d)–(f) are not applicable in this case, and the set of reachable states has basically the same structure as in the case of concatenation of two languages. Accordingly, the worst case state complexity of concatenation of multiple languages is slightly higher than that in the case of powers of a single language. We have also considered the nondeterministic state complexity of Lk for alphabets of size two or more, and have shown a tight bound of kn. We leave open the problem of the nondeterministic state complexity of Lk over a unary alphabet, as the nondeterministic state complexity of concatenation over a unary alphabet is not currently known exactly [6]. Acknowledgements The first author’s research was conducted at the Department of Mathematics, University of Turku, during a research visit supported by the Academy of Finland under grant 118540. The first author’s research was supported in part by the Natural Sciences and Engineering Research Council of Canada. The second author’s work was supported by the Academy of Finland under grant 118540. References [1] J.-C. Birget, Intersection and union of regular languages and state complexity, Information Processing Letters 43 (1992) 185–190. [2] M. Domaratzki, D. Kisman, J. Shallit, On the number of distinct languages accepted by finite automata with n states, Journal of Automata, Languages and Combinatorics 7 (2002) 469–486. [3] K. Ellul, Descriptional complexity measures of regular languages, Master’s Thesis, University of Waterloo, Canada, 2002. [4] Z. Ésik, Y. Gao, G. Liu, S. Yu, Estimation of state complexity of combined operations, in: C. Cămpeanu, G. Pighizzini (Eds.), 10th International Workshop on Descriptional Complexity of Formal Systems, DCFS 2008, Charlottetown, PEI, Canada, July 16–18, 2008, pp. 168–181. [5] Y. Gao, K. Salomaa, S. Yu, The state complexity of two combined operations: Star of catenation and star of reversal, Fundamenta Informaticae 83 (2008) 75–89. [6] M. Holzer, M. Kutrib, Nondeterministic descriptional complexity of regular languages, International Journal of Foundations of Computer Science 14 (2003) 1087–1102. [7] J. Jirásek, G. Jirásková, A. Szabari, State complexity of concatenation and complementation, International Journal of Foundations of Computer Science 16 (3) (2005) 511–529. [8] G. Jirásková, A. Okhotin, On the state complexity of star of union and star of intersection, Turku Centre for Computer Science Technical Report 825, Turku, Finland, August 2007.
2392
M. Domaratzki, A. Okhotin / Theoretical Computer Science 410 (2009) 2377–2392
[9] G. Liu, C. Martín-Vide, A. Salomaa, S. Yu, State complexity of basic operations combined with reversal, Information and Computation 206 (2008) 1178–1186. [10] A.N. Maslov, Estimates of the number of states of finite automata, Soviet Mathematics Doklady 11 (1970) 1373–1375. [11] G. Pighizzini, J. Shallit, Unary language operations, state complexity and Jacobsthal’s function, International Journal of Foundations of Computer Science 13 (1) (2002) 145–159. [12] N. Rampersad, The state complexity of L2 and Lk , Information Processing Letters 98 (2006) 231–234. [13] G. Rozenberg, A. Salomaa (Eds.), Handbook of Formal Languages, Springer, 1997. [14] A. Salomaa, K. Salomaa, S. Yu, State complexity of combined operations, Theoretical Computer Science 383 (2–3) (2007) 140–152. [15] K. Salomaa, S. Yu, On the state complexity of combined operations and their estimation, International Journal of Foundations of Computer Science 18 (2007) 683–698. [16] S. Yu, Q. Zhuang, K. Salomaa, The state complexity of some basic operations on regular languages, Theoretical Computer Science 125 (1994) 315–328.
Theoretical Computer Science 410 (2009) 2393–2400
Contents lists available at ScienceDirect
Theoretical Computer Science journal homepage: www.elsevier.com/locate/tcs
Twin-roots of words and their properties Lila Kari, Kalpana Mahalingam 1 , Shinnosuke Seki ∗ Department of Computer Science, The University of Western Ontario, London, Ontario, Canada, N6A 5B7
article
info
Keywords: f -symmetric words Twin-roots Morphic and antimorphic involutions Primitive roots
a b s t r a c t In this paper we generalize the notion of an ι-symmetric word, from an antimorphic involution, to an arbitrary involution ι as follows: a nonempty word w is said to be ι-symmetric if w = αβ = ι(βα) for some words α, β . We propose the notion of ιtwin-roots (x, y) of an ι-symmetric word w . We prove the existence and uniqueness of the ι-twin-roots of an ι-symmetric word, and show that the left factor α and right factor β of any factorization of w as w = αβ = ι(βα), can be expressed in terms of the ι-twin-roots of w . In addition, we show that for any involution ι, the catenation of the ι-twin-roots of w equals the primitive root of w . We also provide several characterizations of the ι-twin-rots of a word, for ι being a morphic or antimorphic involution. Crown Copyright © 2009 Published by Elsevier B.V. All rights reserved.
1. Introduction Periodicity, primitivity, overlaps, and repetitions of factors play an important role in combinatorics of words, and have been the subject of extensive studies, [8,12]. Recently, a new interpretation of these notions has emerged, motivated by information encoding in DNA computing. DNA computing is based on the idea that data can be encoded as biomolecules, [1], e.g., DNA strands, and molecular biology tools can be used to transform this data to perform, e.g., arithmetic and logic operations. DNA (deoxyribonucleic acid) is a linear chain made up of four different types of nucleotides, each consisting of a base (Adenine, Cytosine, Guanine, or Thymine) and a sugar-phosphate unit. The sugar-phosphate units are linked together by covalent bonds to form the backbone of the DNA single strand. Since nucleotides may differ only by their bases, a DNA strand can be viewed as simply a word over the four-letter alphabet {A, C, G, T}. A DNA single strand has an orientation, with one end known as the 5’ end, and the other as the 3’ end, based on their chemical properties. By convention, a word over the DNA alphabet represents the corresponding DNA single strand in the 5’ to 3’ orientation, i.e., the word GGTTTTT stands for the DNA single strand 5’-GGTTTTT-3’. A crucial feature of DNA single strands is their Watson–Crick complementarity: A is complementary to T, G is complementary to C, and two complementary DNA single strands with opposite orientation will bind to each other by hydrogen bonds between their individual bases to form a stable DNA double strand with the backbones at the outside and the bound pairs of bases lying at the inside. Thus, in the context of DNA computing, a word u encodes the same information as its complement θ (u), where θ denotes the Watson–Crick complementarity function, or its mathematical formalization as an arbitrary antimorphic involution. This special feature of DNA-encoded information led to new interpretations of the concepts of repetitions and periodicity in words, wherein u and θ (u) were considered to encode the same information. For example, [4] proposed the notion of θ primitive words for an antimorphic involution θ : a nonempty word w is θ -primitive iff it cannot be written in the form w = u1 u2 . . . un where ui ∈ {u, θ (u)}, n ≥ 2. Initial results concerning this special class of primitive words are promising and include, e.g., an extension, [4], of the Fine-and-Wilf’s theorem [5].
∗
Corresponding author. Tel.: +1 519 661 2111; fax: +1 519 661 3515. E-mail addresses: [email protected] (L. Kari), [email protected], [email protected] (K. Mahalingam), [email protected] (S. Seki).
1 Current address: Department of Mathematics, Indian Institute of Technology, Madras 600042, India. 0304-3975/$ – see front matter Crown Copyright © 2009 Published by Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2009.02.032
2394
L. Kari et al. / Theoretical Computer Science 410 (2009) 2393–2400
To return to our motivation, the proof of the extended Fine-and-Wilf’s theorem [4], as well as that of an extension of the Lyndon–Schützenberger equation ui = v j w k in [10], to cases involving both words and their Watson–Crick complements, pointed out the importance of investigating overlaps between the square u2 of a word u, and its complement θ (u), i.e., overlaps of the form u2 = vθ (u)w for some words v, w . This is an analogue of the classical situation wherein u2 overlaps with u, i.e., u2 = v uw , which happens iff v = pi and w = pj for some i, j ≥ 1, where p is the primitive root of u. A natural question is thus whether there is any kind of ‘root’ which characterizes overlaps between u2 and θ (u) in the same way in which the primitive root characterizes the overlaps between u2 and u. For an arbitrary involution ι, this paper proposes as a candidate the notion of ι-twin-roots of a word. Unlike the primitive root, the ι-twin-roots are defined only for ι-symmetric words. A word u is ι-symmetric if u = αβ = ι(βα) for some words α, β and the connection with the overlap problem is the following: If ι is an involution and u is an ι-symmetric word, then u2 overlaps with ι(u), i.e., u2 = αι(u)β . The implication becomes equivalence if ι is a morphic or antimorphic involution. In this paper, we prove that an ι-symmetric word u has unique ι-twin-roots (x, y) such that xy is the primitive root of u (i.e., u = (xy)n for some n ≥ 1). In addition, if u = αβ = ι(βα), then α = (xy)i x, β = y(xy)n−i−1 for some i ≥ 1 (Proposition 4). Moreover, we provide several characterizations of ι-twin-roots for the case when ι is morphic or antimorphic. The paper is organized as follows. After basic notations, definitions and examples in Section 2, in Section 3 we investigate relationships between the primitive root and twin-roots of a word. We namely show that for an involution ι, the primitive root of an ι-symmetric word equals the catenation of its ι-twin-roots. Furthermore, for a morphic or antimorphic involution δ , we provide several characteristics of δ -twin-roots of words. In Section 4, we place the set of δ -symmetric words in the Chomsky hierarchy of languages. As an application of these results, in Section 5 we investigate the µ-commutativity between languages, XY = µ(Y )X , for a morphic involution µ. 2. Preliminaries Let Σ be a finite alphabet. A word over Σ is a finite sequence of symbols in Σ . The empty word is denoted by λ. By Σ ∗ , we denote the set of all words over Σ , and Σ + = Σ ∗ \ {λ}. For a word w ∈ Σ ∗ , the set of its prefixes, infixes, and suffixes are defined as follows: Pref(w) = {u ∈ Σ + | ∃v ∈ Σ ∗ , uv = w}, Inf(w) = {u ∈ Σ + | ∃v, v 0 ∈ Σ ∗ , v uv 0 = w}, and Suff(w) = {u ∈ Σ + | ∃v ∈ Σ ∗ , v u = w}. For other notions in the formal language theory, we refer the reader to [11,12]. A word u ∈ Σ + is said to be primitive if u = v i implies i = 1. By Q we denote the set of all primitive words. For any nonempty word u ∈ Σ + , there is a unique primitive √ word p ∈ Q , which is called the primitive root of u, such that u = pn for some n ≥ 1. The primitive root of u is denoted by u. An involution is a mapping f such that f 2 is the identity. A morphism (resp. antimorphism) f over an alphabet Σ is a mapping such that f (uv) = f (u)f (v) (f (uv) = f (v)f (u)) for all words u, v ∈ Σ ∗ . We denote by f , ι, µ, θ , and δ , an arbitrary mapping, an involution, a morphic involution, an antimorphic involution and a d-morphic involution (an involution that is either morphic or antimorphic), respectively. Note that an involution is not always length-preserving but a d-morphic involution is. A palindrome is a word which is equal to its mirror image. The concept of palindromes was generalized to θ -palindromes, [7,9], where θ is an arbitrary antimorphic involution: a word w is called a θ -palindrome if w = θ (w). This definition can be generalized as follows: For an arbitrary mapping f on Σ ∗ , a word w ∈ Σ ∗ is called a f -palindrome if w = f (w). We denote by Pf the set of all f -palindromes over Σ ∗ . The name f -palindrome serves as a reminder of the fact that, in the particular case when f is the mirror-image function, i.e., the identity function on Σ extended to an antimorphism of Σ ∗ , an f -palindrome is an ordinary palindrome. An additional reason for this choice of term was the fact that, in biology, the term ‘‘palindrome’’ is routinely used to describe DNA strings u with the property that θ (u) = u, where θ is the Watson– Crick complementarity function. In the case when f is an arbitrary function on Σ ∗ , what we here call an f -palindrome is simply a fixed point for the function f . Lemma 1. Let u ∈ Σ + and δ be a d-morphic involution. Then u ∈ Pδ if and only if
√
n
√
√
u ∈ Pδ .
√
n
√
n
Proof. Note that δ( u ) = δ( u)n for a d-morphic involution δ . If u ∈ Pδ , then we have u = δ( u ). This means that √ n √ √ √ u = δ( u)n . Since δ is length-preserving, u = δ( u). The opposite direction can be proved in a similar way. The θ -symmetric property of a word was introduced in [9] for antimorphic involutions θ . In [9], a word is said to be θ -symmetric if it can be written as a product of two θ -palindromes. We extend this notion to the f -symmetric property, where f is an arbitrary mapping. For a mapping f , a nonempty word w ∈ Σ + is f -symmetric if w = αβ = f (βα) for some α ∈ Σ + and β ∈ Σ ∗ . Our definition is a generalization of the definition in [9]. Indeed, when f is an antimorphic involution, w = αβ = f (βα) = f (α)f (β) implies α, β ∈ Pf . For an f -symmetric word w , we call a pair (α, β) such that w = αβ = f (βα) an f-symmetric factorization of w . Given an f -symmetric factorization (α, β) of a word, α is called its left factor and β is called its right factor. We denote by Sf the set of all f -symmetric words over Σ ∗ . We have the following observation on the inclusion relation between Pf and Sf . Proposition 2. For a mapping f on Σ ∗ , Pf ⊆ Sf .
L. Kari et al. / Theoretical Computer Science 410 (2009) 2393–2400
2395
3. Twin-roots and primitive roots Given an involution ι, in this section we define the notion of ι-twin-roots of an ι-symmetric word u with respect to ι. We prove that any ι-symmetric word u has unique ι-twin roots. We show that the right and left factors of any ι-symmetric factorization of u as u = αβ = ι(βα) can all be expressed in terms of the twin-roots of u with respect to ι. Moreover, we show that the catenation of the twin-roots of an ι-symmetric word u with respect to ι equals the primitive root of u. We also provide several other properties of twin-roots, for the particular case of d-morphic involutions. We begin by recalling a theorem from [6] on language equation of the type Xu = v X , whose corollary will be used for finding the ‘‘twin-roots’’ of an ι-symmetric word. Corollary 3 ([6]). Let u, v, w ∈ Σ + . If uw = wv , then there uniquely exist two words x, y ∈ Σ ∗ with xy ∈ Q such that u = (xy)i , v = (yx)i , and w = (xy)j x for some i ≥ 1 and j ≥ 0. Proposition 4. Let ι be an involution on Σ ∗ and u be an ι-symmetric word. Then there uniquely exist two words x, y ∈ Σ ∗ such that u = (xy)i for some i ≥ 1 with xy ∈ Q , and if u = αβ = ι(βα) for some α, β ∈ Σ ∗ , then there exists k ≥ 0 such that α = (xy)i−k−1 x and β = y(xy)k . Proof. Given that u is ι-symmetric and (α, β) is an ι-symmetric factorization of u. It is easy to see that β u = ι(u)β holds. Then from Corollary 3, there exist two words x, y ∈ Σ ∗ such that xy ∈ Q , u = (xy)i , ι(u) = (yx)i , and β = y(xy)k for some k ≥ 0. Since u = αβ = (xy)i , we have α = (xy)i−k−1 x. Now we have to prove that such (x, y) does not depend on the choice of (α, β). Suppose there were an ι-symmetric factorization (α 0 , β 0 ) of u for which x0 y0 ∈ Q , u = (x0 y0 )i , ι(u) = (y0 x0 )i , α 0 = (x0 y0 )i−j−1 x0 , and β 0 = y0 (x0 y0 )j for some 0 ≤ j < i and x0 , y0 ∈ Σ ∗ such that (x, y) 6= (x0 , y0 ). Then we have xy = x0 y0 and yx = y0 x0 , which contradicts the primitivity of xy. The preceding result shows that, if u is ι-symmetric, then its left factor and right factor can be written in terms of a unique pair√(x, y). We call (x, y) the twin-roots of u with respect to ι, or shortly ι-twin-roots of u. We denote the ι-twin-roots of u by ι u. Note that x 6= y and we can assume that x cannot be empty whereas y can. Proposition 4 has the following two consequences. Corollary 5. Let ι be an involution√ on Σ ∗ and u be an ι-symmetric word. Then the number of ι-symmetric factorizations of u is n for some n ≥ 1 if and only if u = ( u)n . Corollary 6. Let ι be an involution on Σ ∗ and u be an ι-symmetric word such that
√ι
u = (x, y). Then the primitive root of u is xy.
Corollary 6 is the first result that relates the notion of the primitive root of an ι-symmetric word to ι-twin-roots. For the particular case of a d-morphic involution δ , the primitive root and the δ -twin-roots are related more strongly. Firstly, we make a connection between the two elements of δ -twin-roots. Lemma 7. Let δ be a d-morphic involution on Σ ∗ , and u be a δ -symmetric word with δ -twin-roots (x, y). Then xy = δ(yx). Proof. Let u = (xy)i = αβ = δ(βα) for some i ≥ 1 and α, β ∈ Σ ∗ . Due to Proposition 4, α = (xy)k x and β = y(xy)i−k−1 for some 0 ≤ k < i. Substituting these into (xy)i = δ(βα) results in (xy)i = δ((yx)i ). Since δ is either morphic or antimorphic, we have xy = δ(yx).
√ √ √ v if and only if δ u = δ v . √ √ √ √ √ √ δ Proof. (If) For δ u = , Corollary 6 implies √u = √v = xy. (Only if) Let δ u = (x, y) and δ v = (x0 , y0 ). √ v = (x, y)√ 0 0 0 0 Corollary 6 implies u = xy and v = x y . Let p = u = v and we have p = xy = x y√. From Lemma 7, both (x, y) and (x0 , y0 ) are δ -symmetric factorizations of p. If (x, y) 6= (x0 , y0 ), due to Corollary 5, p = ( p)n for some n ≥ 2, a Proposition 8. Let δ be a d-morphic involution on Σ ∗ , and u, v be δ -symmetric words. Then
√
u=
contradiction. Proposition 9. Let δ be a d-morphic involution on Σ ∗ , and u be a δ -symmetric word such that
√ δ
u = (x, y).
(1) If δ is antimorphic, then both x and y are δ -palindromes, (2) If δ is morphic, then either (i) x is a δ -palindrome and y = λ, or (ii) x is not a δ -palindrome and y = δ(x). Proof. Due to Lemma 7, we have xy = δ(yx). If δ is antimorphic, then this means that xy = δ(x)δ(y), and hence x = δ(x) and y = δ(y). If δ is morphic, then xy = δ(y)δ(x). If y = λ, then we have x = δ(x). Otherwise, we have three cases depending on the lengths of x and y. If they have the same length, then y = δ(x). The primitivity of xy forces x not to be a δ -palindrome. If |x| < |y|, then y = y1 y2 for some y1 , y2 ∈ Σ + such that δ(y) = xy1 and y2 = δ(x). Then xy = xδ(x)δ(y1 ) = δ(y1 )xδ(x), which is a contradiction with xy ∈ Q . The case when |y| < |x| can be proved by symmetry. Next we consider the δ -twin-roots of a δ -palindrome; indeed δ -palindromes are δ -symmetric (Proposition 2), and hence have δ -twin-roots. The δ -twin-roots of δ -palindromes have the following property. Lemma 10. Let δ be a d-morphic involution and u be a δ -symmetric word such that Then u is a δ -palindrome if and only if x is a δ -palindrome and y = λ.
√ δ
u = (x, y) for some x ∈ Σ + and y ∈ Σ ∗ .
2396
L. Kari et al. / Theoretical Computer Science 410 (2009) 2393–2400
Proof. (If) Since y = λ, u = xi for some i ≥ 1. Then δ(u) = δ(xi ) = δ(x)i = xi , and hence u ∈ Pδ . (Only if) First we√consider the case when δ is antimorphic. From Proposition 9, x, y ∈ Pδ . Suppose y 6= λ. Since u ∈ Pδ , Lemma 1 implies u ∈ Pδ , and hence xy = δ(xy) = δ(y)δ(x) = yx. This means that nonempty words x and y commute, a contradiction with xy ∈ Q . Next we consider the case of δ being morphic. Since u is a δ -palindrome, any letter a from u has the palindrome property, i.e., δ(a) = a. Then all prefixes property so that x = δ(x). Proposition 9 implies either y = λ or √of u satisfy the palindrome √ y = δ(x), but the latter, with u = xy, leads to u = x2 , a contradiction. Note that the notion of ι-symmetry and ι-twin-roots of a word are dependent on the involution ι under consideration. Thus, for example, a word u may be ι1 -symmetric and not ι2 -symmetric, and its twin-roots might be different depending on the involution considered. The following two examples show that there exist words u and morphic involutions µ1 and µ2 such that the µ1 -twin-roots of u are different from µ2 -twin-roots of u, and the same situation can be found for the antimorphic case. Example 11. Let u = ATTAATTA, µ1 be the identity on Σ extended to a morphism, and µ2 be the morphic involution such that µ2 (A) = T and µ2 (T) = A. Then u is both µ1 -symmetric and µ2 -symmetric. Indeed, u = ATTA · ATTA √ = µ1 )µ ( AT ) . The µ -symmetric property of u implies that µ1 (ATTA)µ1 (ATTA), and u = AT · TAATTA = µ2 (TAATTA u = 2 1 √ √ (ATTA, λ), and the µ2 -symmetric property of u implies µ2 u = (AT, TA). We can easily check that u = ATTA · λ = AT · TA. Example 12. Let u = TAAATTTAAATT, mi be the identity on Σ extended to an antimorphism, namely the well-known mirror-image mapping, and θ be the antimorphic involution such that θ (A) = T and θ (T) = A. We can split u into two palindromes TAAAT and TTAAATT so that u is mi-symmetric. By product of two θ -palindromes √the same token, u is a √ TAAATTTA and AATT, and hence θ -symmetric. We have that mi u = (TAAAT, T) and θ u = (TA, AATT). Note that √ u = TAAAT · T = TA · AATT holds. The last example shows that it is possible to find a word u, and morphic and antimorphic involutions µ and θ , such that the µ-twin-roots of u and the θ -twin-roots of u are distinct. Example 13. Let u = AACGTTGC. µ and θ be morphic and antimorphic involutions, respectively, which map A to T, C to G, and vice √ versa. Then u = µ(TTGC √ )µ(AACG) = θ (AACGTT)θ (GC√) so that u is both µ-symmetric and θ -symmetric. We have that µ u = (AACG, TTGC) and θ u = (AACGTT, GC). Moreover u = AACG · TTGC = AACGTT · GC. 4. The set of symmetric words in the Chomsky hierarchy In this section we consider the classification of the language Sµ of the µ-symmetric words with respect to a morphic involution µ, and Sθ of the θ -symmetric words with respect to an antimorphic involution θ , in the Chomsky hierarchy, [2,11]. For a morphic involution µ, we show that Pµ , the set of all µ-palindromes, is regular (Proposition 14). Unless empty, the set Sµ \ Pµ of all µ-symmetric but non-µ-palindromic words, is not context-free (Proposition 16) but is context-sensitive (Proposition 19). As a corollary of these results we show that, unless empty, the set Sµ of all µ-symmetric words is contextsensitive (Corollary 20), but not context-free (Corollary 17). In contrast, for an antimorphic involution θ , the set of all θ symmetric words turns out to be context-free (Proposition 21). Proposition 14. Let µ be a morphic involution on Σ ∗ . Then Pµ is regular. Proof. For Σp = {a ∈ Σ | a = µ(a)}, Pµ = Σp∗ , which is regular. Next we consider Sµ \ Pµ . If c = µ(c ) holds for all letters c ∈ Σ , then Σ ∗ = Pµ , that is, Sµ \ Pµ is empty. Therefore, we assume the existence of a character c ∈ Σ satisfying c 6= µ(c ). Under this assumption, we show that Sµ \ Pµ is not context-free but context-sensitive. Lemma 15. Let µ be a morphic involution on Σ ∗ . If there is c ∈ Σ such that c 6= µ(c ), then Sµ \ Pµ is infinite. Proof. This is clear from the fact that (c µ(c ))k ∈ Sµ \ Pµ for all k ≥ 1. Proposition 16. Let µ be a morphic involution on Σ ∗ . If Σ contains a character c ∈ Σ satisfying c 6= µ(c ), then Sµ \ Pµ is not context-free. Proof. Lemma 15 implies that Sµ \ Pµ is not finite. Suppose Sµ \ Pµ were context-free. Then there is an integer n given to us by the pumping lemma. Let us choose z = an µ(a)n an µ(a)n for some a ∈ Σ satisfying a 6= µ(a). We may write z = uvw xy subject to the usual constraints (1) |vw x| ≤ n, (2) v x 6= λ, and (3) for all i ≥ 0, zi = uv i w xi y ∈ Sµ \ Pµ . Note that for any w ∈ Sµ \ Pµ and any a ∈ Σ satisfying a 6= µ(a), the number of occurrences of a in w should be equal to that of µ(a) in w . Therefore, if v x contained different numbers of a’s and µ(a)’s, z0 = uw y would not be a member of Sµ \ Pµ . Suppose vw x straddles the first block of a’s and the first block of µ(a)’s of z, and v x consists of k a’s and k µ(a)’s for some k > 0. Note that 2k < n because |v x| ≤ |vwx| ≤ n. Then z0 = an−k µ(a)n−k an µ(a)n , and z0 ∈ Sµ \ Pµ means that there exist γ 6∈ Pµ and an integer m ≥ 1 such that z0 = (γ µ(γ ))m . Thus, µ(γ ) ∈ Σ ∗ µ(a), i.e., γ ∈ Σ ∗ a. This implies that the last block of µ(a) of z0 is a suffix of the last µ(γ ) of z0 , and hence |γ | = |µ(γ )| ≥ n. As a result, an−k µ(a)k ∈ Pref(γ ), i.e., µ(a)n−k ak ∈ Pref(µ(γ )). Since a 6= µ(a), we have µ(γ ) = µ(a)n−k ak βµ(a)n for some β ∈ Σ ∗ .
L. Kari et al. / Theoretical Computer Science 410 (2009) 2393–2400
2397
This implies |µ(γ )| ≥ 2n. On the other hand, |z0 | = 4n − 2k, and hence |µ(γ )| ≤ 2n − k. Now we reached the contradiction. Even if we suppose that vw x straddles the second block of a’s and the second block of µ(a)’s of z, we would reach the same contradiction. Finally, suppose that vw x were a substring of the first block of µ(a)’s and the second block of a’s of z. Then z0 = an µ(a)n−k an−k µ(a)n = (γ µ(γ ))m for some m ≥ 1. As proved above, µ(a)n ∈ Suff(µ(γ )), and this is equivalent to an ∈ Suff(γ ). Since z0 contains the n consecutive a’s only as the prefix an , we have γ = an , i.e., µ(γ ) = µ(a)n . However, the prefix an is followed by at most n−k occurrences of µ(a) and k ≥ 1. This is a contradiction. Consequently, Sµ \ Pµ is not context-free. The proof of Proposition 16 suggests that for an alphabet Σ containing a character c satisfying c 6= µ(c ), Sµ is not context-free either. Corollary 17. Let µ be a morphic involution on Σ ∗ . If Σ contains a character c ∈ Σ satisfying c 6= µ(c ), then Sµ is not contextfree. Next we prove that Sµ \ Pµ is context-sensitive. We will construct a type-0 grammar and prove that the grammar is indeed a context-sensitive grammar. For this purpose, the workspace theorem is employed, which requires a few terminologies: Let G = (N , T , S , P ) be a grammar and consider a derivation D according to G like D : S = w0 ⇒ w1 ⇒ · · · ⇒ wn = w . The workspace of w by D is defined as WSG (w, D) = max{|wi | | 0 ≤ i ≤ n}. The workspace of w is defined as WSG (w) = min{WSG (w, D) | D is a derivation of w}. Theorem 18 (Workspace Theorem [11]). Let G be a type-0 grammar. If there is a nonnegative integer k such that WSG (w) ≤ k|w| for all nonempty words w ∈ L(G), then L(G) is context-sensitive. Proposition 19. Let µ be a morphic involution on Σ ∗ . If Σ contains a character c ∈ Σ satisfying c 6= µ(c ), then Sµ \ Pµ is context-sensitive. Proof. We provide a type-0 grammar which generates a language equivalent to Sµ \ Pµ . Let G = (N , Σ , P , S ), where S ← − ← − − → − → N = {S , Zˆ , Z , Xˆ i , Xˆ m , Y , L , #} ∪ a∈Σ { Xa , Ca }, the set of nonterminal symbols, and P is the set of production rules given below. First off, this grammar creates αµ(α) for α ∈ Σ ∗ that contains a character c ∈ Σ satisfying c 6= µ(c ). The 1–7th rules of the following list of P achieve this task. Secondly, 5th and 10–18th rules copy αµ(α) at arbitrary times so that the resulting word is (αµ(α))i for some i ≥ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19.
S S − → Xa c − → Xa Y ← − c L ← − Xˆi L ← − Xˆi L ← − Xˆ m L ← − Xˆ m L ← − Zˆ a L − → Ca c − → Ca Y − → Ca # ← − Y L ← − Zˆ Y L ← − Zˆ Y L ← − cZ ← − #Z #
→ → → → → → → → → → → → → → → → → → →
− →
#Zˆ aXˆi Xa Y # − → #Zˆ bXˆ m Xb Y # − → c Xa ← − L µ(a)Y ← − Lc − → aXˆi Xa − → bXˆ m Xb − → aXˆ m Xa ← − L − → aZˆ Ca − → c Ca − → Y Ca ← − L a# ← − L Y, ← −← − Z LY
λ ← −
Z c #Zˆ ,
∀a ∈ Σ , ∀b ∈ Σ such that b 6= µ(b), ∀ a, c ∈ Σ , ∀a ∈ Σ , ∀c ∈ Σ , ∀a ∈ Σ , ∀b ∈ Σ such that b 6= µ(b), ∀a ∈ Σ , ∀a ∈ Σ , ∀ a, c ∈ Σ , ∀a ∈ Σ , ∀a ∈ Σ ,
∀c ∈ Σ ,
λ.
This grammar works in the following manner. After the 1st or 6th rule generates a terminal symbol a ∈ Σ , the 3rd and ← − 4th rules deliver information of the symbol to Y and generate µ(a) just before Y , and by the 5th rule, the header L go back to Xˆ i . This process is repeated until a character b ∈ Σ satisfying b 6= µ(b) is generated, which is followed by changing Xˆ i to Xˆ m and generating µ(b) just before Y . Now the grammar may continue the a-θ (a) generating process or shift to a copy ← − ← − phase (9th rule Xˆ m L → L ). From now on, whenever the a-µ(a) process ends, the grammar can do this choice. Just after ← − ← − ← − using the 9th rule Xˆ m L → L , the sentential form of this derivation is Zˆ α L µ(α)Y for some α ∈ Σ + which contains at least one character b ∈ Σ satisfying b 6= µ(b). The 5th and 10–18th rules copy αµ(α) at the end of sentential form. ← − Just after coping αµ(α), the sentential form αµ(α)Zˆ Y L (αµ(α))m appears so that if the 15th rule is applied, then another
2398
L. Kari et al. / Theoretical Computer Science 410 (2009) 2393–2400
αµ(α) is copied; otherwise the derivation terminates. Therefore, a word w derived by this grammar G can be represented as (αµ(α))n for some n ≥ 1, and hence w ∈ Sµ . In addition, G generates only non-θ -palindromic word so that w ∈ Sµ \ Pµ . √ Thus, L(G) ⊆ Sµ \ Pµ . Conversely, if w ∈ Sµ \ Pµ , then it has the µ-twin-roots µ w = (x, y) and w = (xy)n for some n ≥ 1. Since y = µ(x), w can be generated by G. Therefore, Sµ \ Pµ ⊆ L(G). Consequently, L(G) = Sµ \ Pµ . Furthermore, this grammar satisfies the workspace theorem (Theorem 18). Any sentential form to derive a word cannot be longer than |w| + c for some constant c ≥ 0. Therefore, L(G) is context-sensitive. Corollary 20. Let µ be a morphic involution on Σ ∗ . If Σ contains a character c ∈ Σ satisfying c 6= µ(c ), then Sµ is contextsensitive. Finally we show that the set of all θ -symmetric words for an antimorphic involution θ is context-free. Proposition 21. For an antimorphic involution θ , Sθ is context-free. Proof. It is known that Pθ is context-free and the family of context-free languages is closed under catenation. Since Sθ = Pθ · Pθ , Sθ is context-free. 5. On the pseudo-commutativity of languages We conclude this paper with an application of the results obtained in Section 3 to the µ-commutativity of languages for a morphic involution µ. For two languages X , Y ⊆ Σ ∗ , X is said to µ-commute with Y if XY = µ(Y )X holds. Example 22. Let Σ = {a, b} and µ be a morphic involution such that µ(a) = b and µ(b) = a. For X = {ab(baab)i | i ≥ 0} and Y = {(baab)j | j ≥ 1}, XY = µ(Y )X holds. In this section we investigate languages X which µ-commute with a set Y of µ-symmetric words. When analyzing such pseudo-commutativity equations, the first step is to investigate equations wherein the set of the shortest words in X µcommutes with the set of the shortest words of Y . (In [3], the author used this strategy to find a solution to the classical commutativity of formal power series, result known as Cohn’s theorem.) For n ≥ 0, by Xn we denote the set of all words in X of length n, i.e., Xn = {w ∈ X | |w| = n}. Let m and n be the lengths of the shortest words in X and Y , respectively. Then XY = µ(Y )X implies Xm Yn = µ(Yn )Xm . The main contribution of this section is to use results from Section 3 to prove that X cannot contain any word shorter than the shortest left factor of all µ-twin-roots of words in Yn (Proposition 28). Its proof requires several results, e.g., Lemmata 25–27. Lemma 23 ([12]). Let u, v ∈ Σ + and X ⊆ Σ ∗ . If X is not empty and Xu = v X holds, then |Xn | ≤ 1 for all n ∈ N0 . Lemma 24. Let u, v ∈ Σ + and X ⊆ Σ ∗ . If X is not empty and uX = µ(X )v holds, then |Xn | ≤ 1 for all n ∈ N0 . Let X ⊆ Σ ∗ , Y ⊆ Sµ \ Pµ such that XY = µ(Y )X , and n be the length of the shortest words in Y . For n ≥ 1, let √ Yn,` = {y ∈ Yn | µ y = (x, µ(x)), |x| = `}. Informally speaking, Yn,` is a set of words in Y of length n having the µ-twinroots whose left factor is of length `. Lemma 25. Let Y ⊆ Sµ \ Pµ , y1 , y2 ∈ Yn,` for some n, ` ≥ 1, and u, w ∈ Σ ∗ . If uy1 = µ(y2 )w and |u|, |w| ≤ `, then u = w .
√
Proof. Since |y1 | = |y2 | = n, we have |u| = |w|. Let y1 = (x1 µ(x1 ))n/2` and y2 = (x2 µ(x2 ))n/2` , where µ y1 = (x1 , µ(x1 )) √ and µ y2 = (x2 , µ(x2 )) for some x1 , x2 ∈ Σ + . Now we have u(x1 µ(x1 ))n/2` = µ(x2 µ(x2 ))n/2` w . This equation, with |u| ≤ `, implies that ux1 µ(x1 ) = µ(x2 µ(x2 ))w . Then we have µ(x2 ) = uα for some α ∈ Σ ∗ , and ux1 µ(x1 ) = uαµ(u)µ(α)w . This means x1 = αµ(u) and µ(x1 ) = µ(α)w , which conclude u = w . Lemma 26. Let X ⊆ Σ ∗ , and Y ⊆ Sµ \ Pµ such that XY = µ(Y )X . For integers m, n ≥ 1 such that Xm Yn = µ(Yn )Xm and m ≤ min{` | Yn,` 6= ∅}, we have Xm Yn,` = µ(Yn,` )Xm for all ` ≥ 1.
√
Proof. Let y1 ∈ Yn such that y1 = (x1 µ(x1 ))i for some i ≥ 1, where µ y1 = (x1 , µ(x1 )). Since Xm Yn = µ(Yn )Xm holds, there √ exist u, v ∈ Xm and y2 ∈ Yn satisfying uy1 = µ(y2 )v . When y2 = (x2 µ(x2 ))j for some j ≥ 1, where µ y2 = (x2 , µ(x2 )), we will show that i = j. Suppose i 6= j. We only have to consider the case where i and j are relatively prime. The symmetry makes it possible to assume i < j, and we consider three cases: (1) i = 1 and j is even; (2) i = 1 and j is odd; and (3) i, j ≥ 2. Firstly, we consider the case (1), where we have ux1 µ(x1 ) = (µ(x2 )x2 )j v . Since |u| ≤ |x1 |, |x2 |, we can let ux1 = (µ(x2 )x2 )j/2 α and αµ(x1 ) = (µ(x2 )x2 )j/2 v for some α ∈ Σ ∗ . Note that |α| = |u| = |v| because |x1 µ(x1 )| = |(µ(x2 )x2 )j |. Since |u| ≤ |x2 |, let µ(x2 ) = uβ for some β ∈ Σ ∗ . Then the former of preceding equations implies x1 = β x2 (µ(x2 )x2 )j/2−1 α . Substituting these into the latter equation gives αµ(β)µ(x2 )(x2 µ(x2 ))j/2−1 µ(α) = uβ x2 (µ(x2 )x2 )j/2−1 v . This provides us with x2 = µ(x2 ), which contradicts x2 6∈ Pµ . Case (2) is that i = 1 and j is odd. In a similar way as the preceding case, let ux1 = (µ(x2 )x2 )(j−1)/2 µ(x2 )α and αµ(x1 ) = x2 (µ(x2 )x2 )(j−1)/2 v for some α ∈ Σ ∗ . Since |u| ≤ |x2 |, the first equation implies that µ(x2 ) = uβ for some β ∈ Σ ∗ . Then substituting this into the second equation results in α = µ(u). By the same token, we have α = µ(v), and hence u = v . Therefore, ux1 µ(x1 ) = (µ(x2 )x2 )j u = uβµ(u)µ(β)(uβµ(u)µ(β))j−1 u = u(βµ(u)µ(β)u)j . Thus, x1 µ(x1 ) = (βµ(u)µ(β)u)j , which contradicts the primitivity of x1 µ(x1 ) because the assumption that j is odd and i < j implies j ≥ 3.
L. Kari et al. / Theoretical Computer Science 410 (2009) 2393–2400
2399
Fig. 1. It is not always the case that |α1 | < |α2 | < · · · < |αj |. However, we can say that for any k1 , k2 , if k1 6= k2 , then |αk1 | 6= |αk2 |.
What remains now is the case (3) where i, j ≥ 2 are relatively prime. Since n = i · |x1 µ(x1 )| = j · |x2 µ(x2 )|, the relative primeness between i and j means that |x1 µ(x1 )| = j` and |x2 µ(x2 )| = i` for some ` ≥ 1. For all 1 ≤ k ≤ j, u(x1 µ(x1 ))ik αk = µ(x2 µ(x2 ))k for some 0 ≤ ik ≤ i and αk ∈ Pref(x1 µ(x1 )). We claim that for some `0 satisfying 0 ≤ `0 < `, there exists a 1-to-1 correspondence between {|α1 |, . . . , |αj |} and {0 + `0 , ` + `0 , 2` + `0 , . . . , (j − 1)` + `0 }. Indeed, u(x1 µ(x1 ))ik αk = µ(x2 µ(x2 ))k implies |u| + ik j` + |αk | = k|x2 µ(x2 )|. Then, |αk | = k|x2 µ(x2 )| − ik j` − |u| = (ik − ik j)` − |u|. Thus, |αk | = −|u| (mod `). We can easily check that if there exist 1 ≤ k1 , k2 ≤ j satisfying ik1 − ik1 j = ik2 − ik2 j, then k=j
k1 = k2 (mod j) because i and j are relatively prime. As a result, ∪k=1 {ik − ik j (mod j)} = {0, 1, . . . , j − 1}. By letting `0 = −|u| (mod `), the existence of the 1-to-1 correspondence has been proved. Since `0 < ` and i` = |x2 µ(x2 )|, let µ(x2 µ(x2 )) = βwα for some β, w, α ∈ Σ ∗ such that |β| = ` − `0 , |w| = (i − 1)`, and |α| = `0 . Then u(x1 µ(x1 ))ik αk = µ(x2 µ(x2 ))k implies that for all k, α ∈ Suff(αk ). Recall that for all k, αk ∈ Pref(x1 µ(x1 )). Then, with the 1-to-1 correspondence, we can say that α appears on x1 µ(x1 ) at even intervals. Let x1 µ(x1 ) = αβ1 αβ2 · · · αβj (see Fig. 1), where |β1 | = · · · = |βj | = |β|. We get (x1 µ(x1 ))ik+1 −ik αk+1 = αk µ(x2 µ(x2 )) = αk βwα for any 1 ≤ k ≤ j − 1 by substituting µ(x2 µ(x2 ))k = u(x1 µ(x1 ))ik αk into µ(x2 µ(x2 ))k+1 = u(x1 µ(x1 ))ik+1 αk+1 . Note that ik+1 ≥ ik ; otherwise, we would have (x1 µ(x1 ))ik −ik+1 αk µ(x2 µ(x2 )) = αk+1 , which is a contradiction with the fact that |x1 µ(x1 )| ≥ |αk+1 |. Since |αk β| ≤ |x1 µ(x1 )|, αk β ∈ Pref(x1 µ(x1 )). Even if ik+1 − ik = 0, αk β ∈ Pref(αk+1 ) ⊆ Pref(x1 µ(x1 )). Thus, there exists an 0 0 integer 1 ≤ j0 ≤ j such that β1 = · · · = βj0 −1 = βj0 +1 = · · · = βj = β , that is, x1 µ(x1 ) = (αβ)j −1 αβj0 (αβ)j−j . If 0
j0 < j, then there exist k1 , k2 such that αk1 = (αβ)j −1 αβj0 α and αk2 = α(βα)k for some k ≥ 1. Clearly, |αk1 |, |αk2 | ≥ `. By the original definitions of αk1 and αk2 , they must share the suffix of length `. Hence, βj0 = β . If j0 = j, then we claim that for all 1 ≤ k < j and some w ∈ Σ ≤2` , αk w ∈ Pref(x1 µ(x1 )) implies w ∈ Pref(µ(x2 µ(x2 ))). Indeed, as above we have (x1 µ(x1 ))ik+1 −ik αk+1 = αk µ(x2 µ(x2 )). If ik+1 − ik ≥ 1, then this means that αk w ∈ Pref(αk µ(x2 µ(x2 ))), and hence w ∈ Pref(µ(x2 µ(x2 ))); otherwise, αk+1 = αk µ(x2 µ(x2 )). Since αk+1 ∈ Pref(x1 µ(x1 )) and x2 µ(x2 ) ≥ 2`, αk w ∈ Pref(αk+1 ), and hence w ∈ Pref(µ(x2 µ(x2 ))). Let αk1 = (αβ)j−3 α and αk2 = (αβ)j−2 α . Then αk1 βαβα ∈ Pref(x1 µ(x1 )) implies βαβα ∈ Pref(µ(x2 µ(x2 ))). By the same token, αk2 βαβj = x1 µ(x1 ) implies βαβj ∈ Pref(µ(x2 µ(x2 ))). Thus, βj = β . Consequently, x1 µ(x1 ) = (αβ)j . Since j ≥ 3, this contradicts the primitivity of x1 µ(x1 ). Lemma 27. Let X ⊆ Σ ∗ , and Y ⊆ Sµ \ Pµ such that XY = µ(Y )X . If there exist m, n ≥ 1 such that Xm Yn = µ(Yn )Xm , and m ≤ min{` | Yn,` 6= ∅}, then |Yn,` | ≤ 1 holds for all ` ≥ 1. Proof. Lemma 26 implies that Xm Yn,` = µ(Yn,` )Xm for all ` ≥ 1. Let us consider this equation for some ` such that Yn,` 6= ∅. Then for y1 ∈ Yn,` , there must exist u, w ∈ Xm and y2 ∈ Yn,` satisfying uy1 = µ(y2 )w . Lemma 25 enables us to say u = w because m ≤ `. Thus, Xm Yn,` = µ(Yn,` )Xm is equivalent to ∀u ∈ Xm , uYn,` = µ(Yn,` )u. For the latter equation, Lemma 24 and the assumption |Yn,` | ≥ 1 make it possible to conclude |Yn,` | = 1. Having proved the required lemmata, now we will prove the main results. Proposition 28. Let X ⊆ Σ ∗ , and Y ⊆ Sµ \ Pµ such that XY = µ(Y )X . Let n be the length of the shortest words in Y . Then X does not contain any nonempty word which is strictly shorter than the shortest left factor of µ-twin-roots of an element of Yn . Proof. If there were such an element of X , the shortest words of X are shorter than any left factor of µ-twin-roots of words in Y . Let u be one of the shortest nonempty words in X , and let |u| = m for some m ≥ 1. Then XY = µ(Y )X implies Xm Yn = µ(Yn )Xm . Moreover, Lemma 26 implies that Xm Yn = µ(Yn )Xm if and only if Xm Yn,` = µ(Yn,` )Xm for all ` ≥ 1. Then, Lemma 27 implies |Yn,` | ≤ 1 for all ` ≥ 1. Let us consider the minimum ` satisfying |Yn,` | = 1. Such an ` certainly √ exists because Yn 6= ∅. Let Yn,` = {y}, where y = (xµ(x))i for some i ≥ 1 and µ y = (x, µ(x)). Then, uy = µ(y)u means u(xµ(x))i = µ((xµ(x))i )u. Moreover, the condition |u| < |x| results in uxµ(x) = µ(x)xu. Letting µ(x) = uα for some α ∈ Σ + , we have uxµ(x) = uαµ(u)µ(α)u, which means xµ(x) = α · µ(u)µ(α)u = µ(u)µ(α)u · α . Since α, u ∈ Σ + , this is a contradiction with the primitivity of xµ(x). Corollary 29. Let X ⊆ Σ ∗ , and Y ∈ Sµ \ Pµ such that XY = µ(Y )X , and m, n be the lengths of the shortest words in X and in Y , respectively. If m = min{` | Yn,` 6= ∅}, then both Xm and Yn are singletons. Proof. It is obvious that Xm Yn = µ(Yn )Xm holds. Lemma 26 implies that Xm Yn,` = µ(Yn,` )Xm for all ` ≥ 1. Moreover Lemma 27 implies that for all `, |Yn,` | ≤ 1. If there exists `0 > m such that |Yn,`0 | = 1, then Xm Yn,`0 = µ(Yn,`0 )Xm must hold. This contradicts Proposition 28, where Xm and Yn,`0 correspond to X and Y in the proposition, respectively. Now we know that Yn is singleton. Then Lemma 23 means that Xm is singleton.
2400
L. Kari et al. / Theoretical Computer Science 410 (2009) 2393–2400
Proposition 30. Let X ⊆ Σ ∗ and Y ⊆ Sµ \ Pµ such that XY = µ(Y )X . Let m and n be the lengths of the shortest words in X and Y , respectively. If m = min{` | Yn,` 6= ∅}, then a language which commutes with Y cannot contain any nonempty word which is strictly shorter than any primitive root of a word in Yn .
√
i µ Proof. Corollary 29 implies that Y √n is a singleton. Let Yn = {w}, and let w = (xµ(x)) for some i ≥ 1, where w = (x, µ(x)). Then from Corollary 6, we have √ w = xµ(x). Let Z be a language which commutes with Y . Suppose the shortest word in Z , say v , is strictly shorter than w . Let |v| = `0 . Then n = Yn Z`0 , i.e., Z`0 w = w Z`0 . Lemma 23 results √ in |Z`0 | = 1. Let √ Z`0 Y√ Z`0 = {v}. Now we have vw = wv . This implies that v = w , which contradicts the fact that |v| < | w| and v 6= λ.
6. Conclusion This paper generalizes the notion of f -symmetric words to an arbitrary mapping f . For an involution ι, we propose the notion of the ι-twin-roots of an ι-symmetric word, show their uniqueness, and the fact that the catenation of the ι-twinroots of a word equals its primitive root. Moreover, for a morphic or antimorphic involution δ , we prove several additional properties of twin-roots. We use these results to make steps toward solving pseudo-commutativity equations on languages. Acknowledgements This research was supported by The Natural Sciences and Engineering Council of Canada Discovery Grant and Canada Research Chair Award to L.K. References [1] L. Adleman, Molecular computation of solutions to combinatorial problems, Science 266 (1994) 1021–1024. [2] N. Chomsky, M.P. Schützenberger, The algebraic theory of context-free languages, in: P. Bradford, D. Hirschberg (Eds.), Computer Programming and Formal Languages, North Holland, Amsterdam, 1963, pp. 118–161. [3] P.M. Cohn, Factorization in noncommuting power series rings, Proceedings of the Cambridge Philosophical Society 58 (1962) 452–464. [4] E. Czeizler, L. Kari, S. Seki, On a special class of primitive words, in: Proc. Mathematical Foundations of Computer Science (MFCS 2008), in: LNCS, vol. 5162, Springer, Torun, Poland, 2008, pp. 265–277. [5] N.J. Fine, H.S. Wilf, Uniqueness theorem for periodic functions, Proceedings of American Mathematical Society 16 (1965) 109–114. [6] C.C. Huang, S.S. Yu, Solutions to the language equation LB = AL, Soochow Journal of Mathematics 29 (2) (2003) 201–213. [7] L. Kari, K. Mahalingam, Watson–Crick conjugate and commutative words, in: M. Garzon, H. Yan (Eds.), DNA 13, in: LNCS, vol. 4848, 2008, pp. 273–283. [8] M. Lothaire, Combinatorics on Words, Cambridge University Press, 1983. [9] A.D. Luca, A.D. Luca, Pseudopalindrome closure operators in free monoids, Theoretical Computer Science 362 (2006) 282–300. [10] R. Lyndon, M. Schützenberger, The equation aM = bN c P in a free group, Michigan Mathematical Journal 9 (1962) 289–298. [11] G. Rozenberg, A. Salomaa (Eds.), Handbook of Formal Languages, Springer-Verlag, Berlin, Heidelberg, 1997. [12] S.S. Yu, Languages and Codes, in: Lecture Notes, Department of Computer Science, National Chung-Hsing University, Taichung, Taiwan, 402, 2005.
Theoretical Computer Science 410 (2009) 2401–2409
Contents lists available at ScienceDirect
Theoretical Computer Science journal homepage: www.elsevier.com/locate/tcs
Decimations of languages and state complexity Dalia Krieger a , Avery Miller a,1 , Narad Rampersad a,2 , Bala Ravikumar b , Jeffrey Shallit a,∗ a
School of Computer Science, University of Waterloo, Waterloo, Ontario N2L 3G1, Canada
b
Computer Science Department, 141 Darwin Hall, Sonoma State University, 1801 East Cotati Avenue, Rohnert Park, CA 94928, USA
article
info
In Honor of Sheng Yu’s 60th Birthday Keywords: Deterministic finite automaton State complexity Decimation Context-free language Slender language
a b s t r a c t Let the words of a language L be arranged in increasing radix order: L = {w0 , w1 , w2 , . . .}. We consider transformations that extract terms from L in an arithmetic progression. For example, two such transformations are even(L) = {w0 , w2 , w4 . . .} and odd(L) = {w1 , w3 , w5 , . . .}. Lecomte and Rigo observed that if L is regular, then so are even(L), odd(L), and analogous transformations of L. We find good upper and lower bounds on the state complexity of this transformation. We also give an example of a context-free language L such that even(L) is not context-free. © 2009 Elsevier B.V. All rights reserved.
1. Introduction Let k ≥ 1 and let Σ = {a0 , a1 , . . . , ak−1 } be a finite alphabet. We put an ordering on the symbols of Σ by defining a0 < a1 < · · · < ak−1 . This ordering can be extended to the radix order3 on Σ ∗ by defining w < x if
• |w| < |x|, or • |w| = |x|, where w = a0 a1 · · · an−1 , x = b0 b1 · · · bn−1 , and there exists an index r, 0 ≤ r < n such that ai = bi for 0 ≤ i < r and ar < br . (For words of the same length, the radix order coincides with the lexicographic order.) Thus, given a language L = Σ ∗ , we can consider the elements of L in radix order, say L = {w0 , w1 , w2 , . . .}, where w0 < w1 < · · · . Let I ⊆ N be an index set. Given an infinite language L, we let its extraction by I, L[I ], denote the elements of L in radix order corresponding to the indices of I, where an index 0 denotes the first element of L. For example, if L = {0, 1}∗ = {, 0, 1, 00, 01, 10, 11, . . .} and I = {2, 3, 5, 7, 11, 13, . . .}, the prime numbers, then L[I ] = {1, 00, 10, 000, 100, 110, . . .}. In this paper we give a new proof of a result of Lecomte and Rigo [9], which characterizes those index sets that preserve regularity. Next, we determine upper and lower bounds on the state complexity of the transformation that maps a language
∗
Corresponding author. E-mail addresses: [email protected] (D. Krieger), [email protected] (A. Miller), [email protected] (N. Rampersad), [email protected] (B. Ravikumar), [email protected] (J. Shallit). 1 Present address: Department of Computer Science, Sandford Fleming Building, University of Toronto, 10 King’s College Road, Toronto, Ontario M5S 3G4, Canada. 2 Present address: Department of Mathematics, University of Winnipeg, Winnipeg, Manitoba R3B 2E9, Canada. 3 Sometimes erroneously called the lexicographic order in the literature. 0304-3975/$ – see front matter © 2009 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2009.02.024
2402
D. Krieger et al. / Theoretical Computer Science 410 (2009) 2401–2409
to its ‘‘decimation’’ (extraction by an ultimately periodic index set). Finally, answering an open question of Ravikumar, we show that if a language is context-free, its decimation need not be context-free. We note that our operation is not the same as the related one previously considered by Birget [4], Shallit [15] and Berstel and Boasson [2], which extracts the lexicographically least word of each length from a language. Nor is our operation the same as that introduced in Berstel, Boasson, Carton, Petazzoni, and Pin [3], which filters each word in a language by extracting the letters in the word that occur in positions specified by an index set. (Our operation simply removes words from a language, but does not change the actual words themselves.) 2. Regularity-preserving index sets Let I ⊆ N be an index set. We say that I is ultimately periodic if there exist integers r ≥ 0, m ≥ 1 such that for all i ∈ I with i ≥ r we have i ∈ I =⇒i + m ∈ I. For a language L, we define the (m, r )-decimation decm,r (L) to be L[I ], where I = {im + r : i ≥ 0}. Two particular decimations of interest are even(L) = dec2,0 (L) and odd(L) = dec2,1 (L). We now introduce some notation. Let us assume that our alphabet is Σ = {a0 , a1 , . . . , ak−1 } with a0 < a1 < · · · < ak−1 , and for a word w ∈ Σ ∗ , let F (w) be the set of words that are less than w in the radix order, that is, F (w) = {x ∈ Σ ∗ : x < w}. Lemma 1. We have F (w aj ) = {} ∪ F (w)Σ ∪ {w}{a0 , . . . , aj−1 }, and this union is disjoint. Proof. Suppose x < w aj . Then either |x| = 0, which corresponds to the term {}, or |x| ≥ 1. In this latter case, we can write x = ya for some symbol a ∈ Σ . Then either y < w , which corresponds to the term F (w)Σ , or y = w , which corresponds to the last term of the union. We now show how to count the number of words accepted by a deterministic finite automaton (DFA) which are, in radix order, less than a given word. Lemma 2. Let A = (Q , Σ , δ, q0 , F ) be a DFA with n states. For any finite language L, define M (L) to be the matrix such that the entry in row i and column j is the number of words x ∈ L with δ(qi , x) = qj . For 0 ≤ l < k, define Ml to be the n × n matrix where the entry in row i and column j is 1 if δ(qi , al ) = qj , and 0 otherwise. Then M (F (w aj )) = M ({}) + M (F (w))(M0 + M1 + · · · + Mk−1 ) + M ({w})(M0 + · · · + Mj−1 ). Proof. By standard results in path algebra and Lemma 1. We now state and prove a theorem that is essentially due to Lecomte and Rigo [9]. (Their proof is somewhat different, and does not explicitly provide the bound on state complexity that is the main focus of this article.) Theorem 3. Let I ⊆ N be an index set. Then L[I ] is regular for all regular languages L if and only if I is either finite or ultimately periodic. Proof. Suppose L[I ] is regular for all regular languages L. Then, in particular, L[I ] is regular for L = a∗ . But L[I ] = {ai : i ∈ I }. Then, by a well-known characterization of unary regular languages [11], I is either finite or ultimately periodic. For the converse, assume that L is regular. If I is finite, then L[I ] is trivially regular. Hence assume that I is ultimately periodic. We can then decompose I as the finite union of arithmetic progressions (mod m). Since the class of regular languages is closed under finite union and finite modification, it suffices to show that L[I ] is regular for all I of the form {jm + r : j ≥ 0} where m ≥ 1, 0 ≤ r < m. Since L is regular, it is accepted by a deterministic finite automaton A = (Q , Σ , δ, q0 , F ), where, as usual, Q is a finite nonempty set of states, δ is the transition function, q0 is the start state, and F is the set of final states. We show how to construct a new DFA A0 that accepts L[I ] where I = {jm + r : j ≥ 0}. Let Q = {q0 , q1 , . . . , qn−1 }. The states of A0 are pairs of the form hv, qi, where v is a vector with entries in Z/(m) and q is a state of Q . The intent is that if we reach the state hv, qi by a path labeled x, then the ith entry of v counts the number (modulo m) of words y < x that take M from state q0 to qi and, further, that δ(q0 , x) = q. More formally, let A0 = (Q 0 , Σ , δ 0 , q00 , F 0 ), where the components are defined as follows. For 0 ≤ l < k, define Ml to be the n × n matrix where the entry in row P i and column j is 1 if δ(qi , al ) = qj , and 0 otherwise. Let ej be the vector with a 1 in position j and 0’s elsewhere. Let M = 0≤l 1. Write t = rab for a, b ∈ Σ , r ∈ Σ ∗ . Let p0 = δ 0 (p, ra) and q0 = δ 0 (q, ra). Then p0 6= q0 by definition of t and r. However, δ 0 (p0 , b) = δ 0 (q0 , b), so from Case 1 we have p0 = q0 . But then, since n is odd, the parities of p0 and q0 differ. On the other hand, p0 = δ 0 (δ 0 (p, r ), a) and q0 = δ 0 (δ 0 (q, r ), a). From Lemma 9, we conclude that p0 and q0 are of the same parity. This is a contradiction, and so this case cannot occur. Corollary 11. In the transition diagram of A0 , every state p has exactly two incoming arrows, both labeled with the same letter a, arising from states of different parity, q and q. If p is of odd parity, then a = 0, and if p is of even parity, then a = 1. Proof. This follows from the proof of Lemma 10, where |s| = 1. We say that a state q ∈ Q 0 is reachable if there exists a string x ∈ {0, 1}∗ such that δ 0 (q00 , x) = q. Lemma 12. Every state of A0 is reachable.
D. Krieger et al. / Theoretical Computer Science 410 (2009) 2401–2409
2405
Proof. Here is the outline of the proof. We define two partial functions: INCR : {0, 1}∗ × {0, 1, . . . , n − 1} × {0, 1, . . . , n − 1} → {0, 1}∗ SHIFT : {0, 1}∗ × {0, 1, . . . , n − 1} → {0, 1}∗ . INCR(t , k, l) produces a string t 0 such that if δ 0 (q00 , t ) = hw, qj i and w has odd parity, then δ 0 (q00 , tt 0 ) = hw + ek + el , ql i. In other words, the effect of reading t 0 after t has been read is to increment the kth and lth bits in the first component of the state, and change the second component to ql . SHIFT(t , l) produces a string t 0 such that if δ 0 (q00 , t ) = hw, qj i and w has odd parity, then δ 0 (q00 , tt 0 ) = hw, ql i. In other words, the effect of reading t 0 after t has been read is to change the second component of the state to ql . We will show below how to define these two functions. For the moment, however, assume that these functions exist; we show how to apply them successively to form a path to any state hv, qi i. The general idea is to apply INCR to add 1-bits to the first component of the state, and then fix up the second component by applying SHIFT. We start with t = 0; this takes us from q00 to the state h[1, 0, 0, . . . , 0], q0 i. Case 1: hv, qi i has odd parity. Find the minimum index l such that vl = 1. If l = 0, then no action is necessary. If l 6= 0, use INCR(t , 0, l) to get to the state hel , ql i. At this point the first 1-bit is set correctly. Since v has odd parity, there is an even number, say 2j, of remaining 1-bits. We now apply INCR j times to increment the remaining 1-bits in pairs. Because we change an even number of bits each time, each new state reached after an application of INCR will be of odd parity. Finally, fix up the second component by applying SHIFT. Case 2: p = hv, qi i has even parity. By Corollary 11 there is a unique state q = hu, qi−1 i of odd parity such that δ 0 (q, 1) = p. Use Case 1 to get to q, and then append 1 to get to p. It now remains to see how to construct the functions INCR and SHIFT. First, we show that from any reachable state with odd parity, we eventually return to that state after reading some number of 0’s. Lemma 13. Given a state of odd parity p, and any word s ∈ {0, 1}∗ such that δ 0 (q00 , s) = p, there exists t = 0l , l ≥ 1, such that δ 0 (q00 , st ) = p. Proof. Using Lemma 9, we know that the parity of each of the states δ 0 (q00 , s0i ), i ≥ 0, is odd. Since there are only a finite number of states, we must have r := δ 0 (q00 , s0i ) = δ 0 (q00 , s0j ) for some 0 ≤ i < j. Further, choose i to be minimal and j to be minimal for this i. Suppose, to get a contradiction, that i ≥ 1. Define r 0 := δ 0 (q00 , s0i−1 ) and r 00 := δ 0 (q00 , s0j−1 ). Then r 0 6= r 00 , for otherwise i, j would not be minimal. Then r 0 and r 00 are distinct states of odd parity from which we reach r on input 0, contradicting Corollary 11. Hence i = 0, and we can take l = j. Now let p be a reachable state of odd parity. Let l(p) be the least positive integer l such that δ 0 (p, 0l ) = p. Lemma 14. If p = hv, qi i is a reachable state of odd parity, then l(p) ≥ 3 unless v = [0, 0, 0, . . . , 1], in which case l(p) = 1. Proof. If v = [0, 0, 0, . . . , 1], then from Lemma 8 we get δ 0 (hv, qi i, 0) = hv, qi i, so l(p) = 1. For the converse, suppose l(p) = 1. Then if v = [v0 , v1 , . . . , vn−1 ], we get by Lemma 8 that
[v0 , v1 , . . . , vn−1 ] = [v0 + vn−1 + 1, v0 + v1 , v1 + v2 , . . . , vn−2 + vn−1 ]. Solving this system gives v = [0, 0, . . . , 1]. If l(p) = 2, then by Lemma 8 we get [v0 , v1 , . . . , vn−1 ] = [v0 + vn−2 , v1 + vn−1 + 1, v0 + v2 , v1 + v3 , . . . , vn−3 + vn−1 ]. Solving this system gives v = [0, 0, . . . , 1]; but then l(p) = 1, a contradiction. We now define τ (p) := max(3, l(p)); hence if p is a reachable state of odd parity, then τ (p) ≥ 3 and δ 0 (p, 0τ (p) ) = p. Lemma 15. Let p = hv, qi i be a reachable state of odd parity. Then (a) δ 0 (p, 0τ (p)−3 010) = hv + ei + ei+1 , qi+1 i; (b) δ 0 (p, 0τ (p)−3 110) = hv + ei + ei+1 , qi+2 i. Proof. Since p is reachable, there exists a string s such that δ 0 (q00 , s) = p = hv, qi i. Now δ 0 (q00 , s) = δ 0 (q00 , s0τ (p) ). From the construction of A0 we know that if v = [v0 , v1 , . . . , vn−1 ] then vi counts, modulo 2, the number n of words w such that w is lexicographically less than s0τ (p) and |w|1 ≡ i (mod n). Now consider the words from s0τ (p) to s0τ (p)−3 110. In increasing lexicographic order, they are s0τ (p)−3 000 s0τ (p)−3 001 s0τ (p)−3 010 s0τ (p)−3 011 s0τ (p)−3 100 s0τ (p)−3 101 s0τ (p)−3 110.
2406
D. Krieger et al. / Theoretical Computer Science 410 (2009) 2401–2409
Now |s|1 = |s0τ (p)−3 000|1 ≡ i (mod n). Thus
δ 0 (q00 , s0τ (p)−3 001) = hv + ei , qi+1 i. Similarly, |s0τ (p)−3 001| ≡ i + 1 (mod n). Thus
δ 0 (q00 , s0τ (p)−3 010) = hv + ei + ei+1 , qi+1 i. Thus (a) is proved. With a similar computation, we find
δ 0 (q00 , s0τ (p)−3 110) = hv + ei + ei+1 , qi+2 i. This proves (b). Corollary 16. Let p = hv, qi i be any reachable state of odd parity in A0 . For all k ≥ 1, there exists a word yk ∈ {0, 1}∗ such that δ 0 (p, yk ) = hv + ei + ei+k , qi+k i. Proof. Using Lemma 15(a), we have δ 0 (p, 0τ (p)−3 010) = hv + ei + ei+1 , qi+1 i. If k = 1, we are done. Otherwise, use induction. Suppose we have found a string xk such that δ 0 (p, xk ) = p0 := hv + ei + ei+k−1 , qi+k−1 i. Then by Lemma 15(a) we have 0 0 δ 0 (p0 , 0τ (p )−3 010) = hv + ei + ei+k , qi+k i. Thus we can take yk = xk 0τ (p )−3 010. Now let us show that the function SHIFT exists. Lemma 17. Let p = hv, qi i be any reachable state of odd parity in A0 . Then for all j ≥ 0 there exists a word wj ∈ {0, 1}∗ such that δ 0 (p, wj ) = hv, qj i. Proof. If i = j we can take wj = . Otherwise, use Corollary 16 with k = n − 2 to get to the state hv + ei + ei+n−2 , qi+n−2 i. Now use Lemma 15 (b) to get to state hv + ei + ei+n−1 , qi i. Now use Corollary 16 with k = n − 1 to get to the state hv, qi−1 i. If j ≡ i − 1 (mod n), we are done. Otherwise, repeat the sequence of steps above until j is reached. Thus the SHIFT function exists. We now turn to INCR. Lemma 18. Let p = hv, qi i be any reachable state of odd parity in A0 . Then there exists a word xj,l ∈ {0, 1}∗ such that δ 0 (p, xj,l ) = hv + ej + el , ql i. Proof. First, use SHIFT to get to the state hv, qj i. From there, use Corollary 16 with k = l − j to get to state hv + ej + el , ql i. This shows that INCR exists. We have now completed the proof of Lemma 12.
Now that we know that every state of A0 is reachable, it remains to show that the number of pairwise distinguishable states is (n + 1)2n−1 . To do so, we determine when two states are equivalent. We say that a state p is equivalent to q if, for all x ∈ Σ ∗ , we have δ 0 (p, x) ∈ F 0 iff δ 0 (q, x) ∈ F 0 . The first step is the following lemma. Lemma 19. Let p0 , r0 ∈ Q 0 . Suppose there exists a word s ∈ Σ ∗ such that δ 0 (p0 , s) = p1 and δ 0 (r0 , s) = r1 where p1 6= r1 and p1 , r1 ∈ F 0 . Then there exists a word t = 0k , k ≥ 1, such that exactly one of {δ 0 (p1 , t ), δ 0 (r1 , t )} is in F 0 . Proof. Since p1 , r1 ∈ F 0 , we can write p1 = h[u0 , u1 , . . . , un−1 ], q0 i r1 = h[v0 , v1 , . . . , vn−1 ], q0 i, where u0 = v0 = 1. Let i be the greatest index such that ui 6= vi ; since by hypothesis p1 6= r1 , such an index must exist, and since u0 = v0 = 1, we have 1 ≤ i ≤ n − 1. By the definition of i we have ui = vi and uj = vj for j > i. Define p2 := δ 0 (p1 , 0) and r2 := δ 0 (r1 , 0). Suppose i = n − 1. Then from Lemma 8 we have p2 = h[u0 + un−1 + 1, u0 + u1 , u1 + u2 , . . . , un−2 + un−1 ], q0 i r2 = h[v0 + vn−1 + 1, v0 + v1 , v1 + v2 , . . . , vn−2 + vn−1 ], q0 i. Consider the first entries of the vectors in p2 and r2 . Since un−1 = vn−1 , we get that v0 + vn−1 + 1 = v0 + un−1 + 1. Since u0 = v0 = 1, this differs from u0 + un−1 + 1. Thus at most one of p2 , r2 is in F 0 , and the conclusion follows with t = 0, k = 1. Otherwise i < n − 1. Write p2 = h[x0 , . . . , xn−1 ], q0 i r2 = h[y0 , . . . , yn−1 ], q0 i.
D. Krieger et al. / Theoretical Computer Science 410 (2009) 2401–2409
2407
We have ui = vi and ui+1 = vi+1 . Also, 1 ≤ i ≤ n − 2, so 2 ≤ i + 1 ≤ n − 1. Now by Lemma 8 we get xi+1 = ui + ui+1 and yi+1 = vi + vi+1
= ui + ui + 1 , so it follows that xi+1 = yi+1 . Thus the largest index j where xj 6= yj is ≥ i + 1. We now repeat this process until j = n − 1, at which point we can finish with the argument above. Next we show that we can always get to at least one final state from any state. Lemma 20. At least one final state of A0 is reachable from any state of A0 . Proof. Let p = hv, qi i be a state of A0 . From Lemma 12 we know that there is a string y such that δ 0 (q00 , y) = p. Now let s1 = 1n−1−i 01 and s2 = 1n−1−i 10. Clearly ys2 directly follows ys1 in lexicographic order, and both ys1 , ys2 ∈ L. So at least one of these two strings must be in odd(L). We now consider when two distinct states p = hv, qi i and q = hw, qj i are equivalent. Lemma 21. A state p = hv, qi i is equivalent to q = hw, qj i iff p = q and i = j 6= 0. Proof. By Lemma 20 we know that there is a word s such that δ 0 (p, s) = f1 ∈ F 0 . If δ 0 (q, s) 6∈ F 0 , then p and q are inequivalent. Thus assume that δ 0 (q, s) = f2 ∈ F 0 . If f2 6= f1 , then we use Lemma 19 to see that f1 and f2 are not equivalent. Thus p and q are not equivalent. It follows that f1 = f2 . Hence i = j. Thus δ 0 (p, s) = δ 0 (q, s). By Lemma 10, we know that p = q. If i = 0, then p and q are inequivalent, since the string distinguishes them (v0 = w0 , so exactly one of these is 1). If i 6= 0, then we claim p and q are equivalent. To do so, we consider δ 0 (p, t ) and δ 0 (q, t ) for all strings t. If |t | = 0, then neither δ 0 (p, t ) = p nor δ 0 (q, t ) = q is in F 0 , since in order to be in F 0 a state’s second component must be q0 . If |t | = 1, then from Lemma 8 and the fact that p = q, we see that δ 0 (q, t ) = δ 0 (p, t ). From this we see immediately that δ 0 (q, u) = δ 0 (p, u) for all |u| ≥ 2. Thus the result follows. Lemma 22. The number of pairwise distinguishable states is n · 2n − (n − 1)2n−1 = (n + 1)2n−1 . Proof. There are n · 2n states in A0n . These are all reachable by Lemma 12. Of this number, a state is equivalent to at most one other state, and this occurs iff the state is of the form hv, qi i with i 6= 0. Thus we need to subtract (n − 1)2n−1 to account for the equivalent states, leaving (n + 1)2n−1 pairwise inequivalent states. We have now completed the proof of Theorem 7. 5. Decimations of context-free languages Suppose L is a context-free language. In some cases, decimations of L are still context-free. For example, if PAL = {x ∈ {a, b}∗ : x = xR }, the palindrome language, then even(L) = {} ∪ {xbxR : x ∈ {a, b}∗ } ∪ {xbbxR : x ∈ {a, b}∗ }, which is clearly context-free. If L = {an bn : n ≥ 0}, then it is easy to see that any decimation of L is context-free. This raises the following natural question: if L is a context-free language (CFL), need its decimation be context-free? In this section we give two examples where this is not the case. For the first example, let B be the balanced parentheses language on the symbols {a, b}, i.e., B = {, ab, aabb, abab, aaabbb, aababb, aabbab, abaabb, ababab, aaaabbbb, . . .}. This is a well-known CFL, generated by the context-free grammar S → aS bS | . We will show that even(B) = {, aabb, aaabbb, aabbab, ababab, . . .} is not a CFL. First, we state some useful lemmas. Lemma 23. The number of words of length 2n in B is the Catalan number Cn =
2n n
/(n + 1).
Proof. Very well known; for example, see [10, pp. 116–117]. Now let ν2 (n) denote the exponent of the highest power of 2 dividing n, and let s2 (n) denote the number of 1’s in the binary expansion of n. Lemma 24. For n ≥ 0 we have ν2 (n!) = n − s2 (n). Proof. A well-known result due to Legendre; for example, see [1, Corollary 3.2.2].
2408
D. Krieger et al. / Theoretical Computer Science 410 (2009) 2401–2409
Lemma 25. For n ≥ 0, Cn is odd if and only if n = 2i − 1 for some integer i ≥ 0. Proof. We have
ν2 (Cn ) = ν2
2n n
!
n+1
= ν2 ((2n)!) − 2ν2 (n!) − ν2 (n + 1) = (2n − s2 (2n)) − 2(n − s2 (n)) − ν2 (n + 1) = s2 (n) − ν2 (n + 1). Thus Cn is odd if and only if s2 (n) = ν2 (n + 1), if and only if n = 2i − 1 for some i ≥ 0. Lemma 26. For n ≥ 0 define Dn :=
P
22i − 1 ≤ n < 22i+1 − 1.
1≤i≤n
Cn . (Thus D0 = 0.) Then Dn is even if and only if there exists i ≥ 0 such that
Proof. Follows immediately from Lemma 25.
We are now ready to prove Theorem 27. The language even(B) is not a context-free language. Proof. P First, we observe that (ab)n is the lexicographically greatest word of length 2n in B. It follows that (ab)n is the Dn = ( 1≤i≤n Ci )th word in B in the radix order. (Recall that we start indexing at 0.) Suppose even(B) is context-free, and define the morphism h : {c}∗ → {a, b}∗ by h(c) = ab. By a well-known theorem [6, Theorem 6.3], h−1 (even(B)) is a context-free language. But h−1 (even(B)) = {cn : Dn is even}. From Lemma 26, we have h−1 (even(B)) = {cn : ∃i ≥ 0 such that 22i − 1 ≤ n < 22i+1 − 1}. Since h−1 (even(B)) is a unary CFL, by a well-known theorem it is actually regular. But the lengths of strings in a unary regular language form an ultimately periodic set, a contradiction. Hence even(B) is not context-free. Corollary 28. odd(B) is not context-free. Proof. This follows from the fact that h−1 (odd(B)) = c∗ − h−1 (even(B)). Recall that a language is a deterministic context-free language (DCFL) if it is accepted by a pushdown automaton that has at most one choice for a move from every configuration. Corollary 29. The class of DCFL’s is not closed under decimation. Proof. B is a DCFL, and even(B) is not a CFL. For our second example, consider the language D = {x ∈ {a, b}∗ : |x|a = |x|b }
= {, ab, ba, aabb, abab, abba, baab, baba, bbaa, aaabbb, . . .}. We will show Theorem 30. even(D) is not context-free. Proof. The proof is similar to that for the language B. We assume that even(D) is context-free and get a contradiction. n First, note that there are n/2 strings of length n in D if n is even, and 0 if n is odd. In particular, the number of strings of length n in D is even for n > 0. Since D contains the empty string, a nonempty string w is in even(D) if and only if it is of odd index, lexicographically speaking, among the strings of length n in D. Since, by assumption, even(D) is context-free, so is D0 = even(D) ∩ aba∗ b∗ = {abab, abaaabbb . . .}. 2n
We claim that aban bn is, lexicographically speaking, of index n−1 among all strings in D of length 2n + 2. To see this, observe that a string of length 2n + 2 is lexicographically less than aban bn if and only if it begins with aa. 2n 2n Thus aban bn ∈ even(D) if and only if n−1 is odd. Now n−1 is odd if and only if n = 2k − 1 for some k ≥ 1. Thus k k D0 = {aba2 −1 b2 −1 : k ≥ 1}, which is clearly not context-free.
D. Krieger et al. / Theoretical Computer Science 410 (2009) 2401–2409
2409
6. Decimation and slender languages Next we consider extractions and decimations of slender context-free languages. A language L is slender if there exists a constant c such that for every n ≥ 0, the number of words of length n in L is ≤ c. Charlier, Rigo, and Steiner [5] showed that if L is regular and slender, then extraction by an index set I gives a regular language if and only if I is the finite union of arithmetic progressions. We will show that the class of slender context-free languages is closed under the operation decm,r . We first review some properties of slender context-free languages. Ilie [7,8], confirming a conjecture of Păun and Salomaa [12], proved that a context-free language is slender if and only if it is a finite disjoint union of languages of the form {uv n wxn y : n ≥ 0}, and further, such a decomposition is effectively computable. Ilie [8, Corollary 13] also proved that the class of slender context-free languages is effectively closed under intersection and set difference. Theorem 31. The class of slender context-free languages is effectively closed under the operation decm,r . Proof. Let L be a slender context-free Sc language and let c be an upper bound on the number of words of any given length in L. We write L as a finite union L = i=1 Li , where, for i = 1, . . . , c, Li is the set consisting of the lexicographically ith words of each length in L. We first show that each Li is context-free. Let min(L) denote the set of the lexicographically least words of each length in L. Berstel and Boasson [2] showed that for any context-free language L, min(L) is context-free, and further, this closure is effective. In our case, the language L is slender by assumption, and the language L1 = min(L) is slender by definition. Since the class of slender context-free languages is closed under set difference, we see that the language L0 = L \ L1 is also a slender context-free language. We next define L2 := min(L0 ). Continuing this process, we see that each Li is a slender context-free language, as required, and further, this decomposition is effectively computable. For i = 1, . . . , c, let Ai be a PDA accepting Li . We show how to accept decm,r (L) by modifying each Ai appropriately. Recall Sk that we may write L as a finite disjoint union L = j=1 Pj , where each Pj is a language of the form {uv n w xn y : n ≥ 0}. Let us denote the length set {|uw y| + n|v x| : n ≥ 0} of Pj by len(Pj ). Let Nw denote the number of words in L of length < |w|. We modify Ai by adding a modulo m counter. If w = w1 · · · wn is the input to Ai , and Ai has processed the prefix w1 · · · wt −1 , t ≤ n, then the counter will store Nw1 ···wt −1 (mod m). On reading wt , Ai increments the counter by Sc1 for each language Pj such that t − 1 ∈ len(Pj ). The PDA Ai accepts w if and only if Nw + i ≡ r (mod m). It follows that i=1 L(Ai ) = decm,r (L), as required. 7. Additional remarks We point out some additional results of Rigo that are relevant. In [14, Theorem 13], he proved that if P is a polynomial that is non-negative at the natural numbers, then there exists a regular language such that extraction by the index set {P (n) : n ≥ 0} is regular. In [13, Proposition 17], he sketches the proof that extraction of an infinite regular language by the index set I = {2, 3, 5, 7, . . .} of primes is always non-regular. 8. Open problems (1) Numerical evidence suggests that if Tn = ( + (0 + 1)∗ 0)(1n )∗ (which can be accepted with an n-state DFA), then even(Tn ) requires (n + 2)2n−2 − 1 states. Prove this and generalize to larger alphabets. (2) Given a CFL L, is it decidable whether or not even(L) is a CFL? Acknowledgments We thank the referees for a careful reading of the paper. References [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15]
J.-P. Allouche, J. Shallit, Automatic Sequences: Theory, Applications, Generalizations, Cambridge University Press, 2003. J. Berstel, L. Boasson, The set of minimal words in a context-free language is context-free, J. Comput. System Sci. 55 (1997) 477–488. J. Berstel, L. Boasson, O. Carton, B. Petazzoni, J.-E. Pin, Operations preserving regular languages, Theoret. Comput. Sci. 354 (2006) 405–420. J.-C. Birget, Partial orders on words, minimal elements of regular languages, and state complexity, Theoret. Comput. Sci. 119 (1993) 267–291. E. Charlier, M. Rigo, W. Steiner, Abstract numeration systems on bounded languages and multiplication by a constant, INTEGERS 8 (2008) #A35. J.E. Hopcroft, J.D. Ullman, Introduction to Automata Theory, Languages, and Computation, Addison-Wesley, 1979. L. Ilie, On a conjecture about slender context-free languages, Theoret. Comput. Sci. 132 (1994) 427–434. L. Ilie, On lengths of words in context-free languages, Theoret. Comput. Sci. 242 (2000) 327–359. P.B.A. Lecomte, M. Rigo, Numeration systems on a regular language, Theory Comput. Syst. 34 (2001) 27–44. J.H. van Lint, R.M. Wilson, A Course in Combinatorics, Cambridge University Press, 1992. G. Pighizzini, J. Shallit, Unary language operations, state complexity and Jacobsthal’s function, Internat. J. Found. Comput. Sci. 13 (2002) 145–159. G. Păun, A. Salomaa, Thin and slender languages, Discrete Appl. Math. 61 (1995) 257–270. M. Rigo, Generalization of automatic sequences for numeration systems on a regular language, Theoret. Comput. Sci. 244 (2000) 271–281. M. Rigo, Construction of regular languages and recognizability of polynomials, Discrete Math. 254 (2002) 485–496. J. Shallit, Numeration systems, linear recurrences, and regular sets, Inform. Comput. 113 (1994) 331–347.
Theoretical Computer Science 410 (2009) 2410–2423
Contents lists available at ScienceDirect
Theoretical Computer Science journal homepage: www.elsevier.com/locate/tcs
On two open problems of 2-interval patterns Shuai Cheng Li, Ming Li ∗ David R. Cheriton School of Computer Science, University of Waterloo, Waterloo ON N2L 3G1, Canada
article Keywords: 2-interval pattern Contact map NP-hard Bioinformatics
info
a b s t r a c t The 2-interval pattern problem, introduced in [Stéphane Vialette, On the computational complexity of 2-interval pattern matching problems Theoret. Comput. Sci. 312 (2–3) (2004) 223–249], models general problems with biological structures such as protein contact maps and macroscopic describers of secondary structures of ribonucleic acids. Given a set of 2-intervals D and a model R, the problem is to find a maximum cardinality subset D 0 of D such that any two 2-intervals in D 0 satisfy R, where R is a subset of relations on disjoint 2intervals: precedence (