Automata and Reduced Words in the Free Group
Thomas Ang, Giovanni Pighizzini, Narad Rampersad, Jeffrey Shallit
aa r X i v : . [ c s . F L ] O c t Automata and Reduced Words in the FreeGroup
Thomas Ang , Giovanni Pighizzini , Narad Rampersad , and Jeffrey Shallit David R. Cheriton School of Computer ScienceUniversity of Waterloo Waterloo, ON, Canada N2L 3G1 { tang,shallit } @uwaterloo.ca Dipartimento di Informatica e ComunicazioneUniversit`a degli Studi di Milano, via Comelico 39, 20135 Milano, Italy [email protected] Department of Mathematics and StatisticsUniversity of Winnipeg, Winnipeg, MB, Canada R3B 2E9 [email protected]
Abstract.
We consider some questions about formal languages thatarise when inverses of letters, words and languages are defined. The re-duced representation of a language over the free monoid is its uniqueequivalent representation in the free group. We show that the class of reg-ular languages is closed under taking the reduced representation, whilethe class of context-free languages is not. We also give an upper boundon the state complexity of the reduced representation of a regular lan-guage, and prove upper and lower bounds on the length of the shortestreducible string in a regular language. Finally we show that the set ofall words which are equivalent to the words in a regular language canbe nonregular, and that regular languages are not closed under taking ageneralized form of the reduced representation.
A word in a free group can be represented in many different ways. For example, aaa − and aa − baa − b − a are two different ways to write the word a . Among allthe different representations, however, there is one containing no occurrences ofa letter next to its own inverse. We call such a word reduced . In this paperwe consider some basic questions about formal languages and their reducedrepresentations. In previous work on automatic groups, these notions of inversesymbols and reduced words have been studied, but only with regards to automatathat are assumed to generate groups [1].First we define some standard notation. A deterministic finite automaton(DFA) is denoted by a quintuple ( Q, Σ, δ, q , F ) where Q is the finite set ofstates, Σ is the finite input alphabet, δ : Q × Σ → Q is the transition function, q ∈ Q is the initial state, and F ⊆ Q is the set of accepting states. We generalize δ to the usual extended transition function with domain Q × Σ ∗ . We use similarnotations to represent a nondeterministic finite automaton with ǫ -transitions ( ǫ -NFA), except the transition function is δ : Q × ( Σ ∪ { ǫ } ) → Q . In an ǫ -NFA its possible to have ǫ -transitions, which are transitions that can be taken withoutreading input symbols. For a DFA or ǫ -NFA M , L ( M ) is the language acceptedby M . For any x ∈ Σ ∗ , | x | denotes the length of x , and | x | a for some a ∈ Σ denotes the number of occurrences of a in x . We let | Σ | denote the alphabet size.We use the terms prefix and factor in the following way. If there exist x, z ∈ Σ ∗ and w = xyz , we say that y is a factor of w . If x = ǫ , we also say that y is aprefix of w . If y is a factor or prefix of w and y = w , then y is a proper factor ora proper prefix of w , respectively.In addition to this standard notation, we also define some notation specificto our problem. For a letter a , we denote its inverse by a − , and we let theempty word, ǫ , be the identity. We consider only alphabets of the form Σ = Γ ∪ Γ − , where Γ = { , , . . . } and Γ − = { − , − , . . . } . For a word w ∈ Σ ∗ = a a · · · a n , we denote its inverse by w − = a − n · · · a − a − , and for a language L ⊆ Σ ∗ , we let L − = { w − : w ∈ L } . Note that taking the inverse of a word isequivalent to reversing it and then applying a homomorphism that maps eachletter to its inverse. Now, we introduce a reduction operation on words, consistingof removing factors of the form aa − , with a ∈ Σ . More formally, let us definethe relation ⊢ ⊆ Σ ∗ × Σ ∗ such that, for all w, w ′ ∈ Σ ∗ , w ⊢ w ′ if and only ifthere exists x, y ∈ Σ ∗ and a ∈ Σ satisfying w = xaa − y and w ′ = xy . As usual, ⊢ ∗ denotes the reflexive and transitive closure of ⊢ . Lemma 1.
For each w ∈ Σ ∗ there exists exactly one word r ( w ) ∈ Σ ∗ such that w ⊢ ∗ r ( w ) and r ( w ) does not contain any factor of the form aa − , with a ∈ Σ .Proof. First, we prove that if w ⊢ w ′ and w ⊢ w ′′ then there exists u ∈ Σ ∗ suchthat w ′ ⊢ ∗ u and w ′′ ⊢ ∗ u , i.e., in the terminology of rewriting systems, Σ ∗ withthe relation ⊢ is a local confluent system.To this aim, suppose that w = x ′ aa − y ′ = x ′′ bb − y ′′ , w ′ = x ′ y ′ , w ′′ = x ′′ y ′′ ,for some x ′ , x ′′ , y ′ , y ′′ ∈ Σ ∗ , a, b ∈ Σ ∗ , and, without loss of generality, that | x ′ | ≤ | x ′′ | . If | x ′ | = | x ′′ | then w ′ = w ′′ , hence, we can take u = w ′ . Otherwise, if | x ′ aa − | ≤ | x ′′ | then w = x ′ aa − zbb − y ′′ , for some z ∈ Σ ∗ and the desired wordis u = x ′ zy ′′ . In the only remaining case, x ′ a = x ′′ , which implies that b = a − and w = x ′ aa − ay ′′ . Hence w ′ = w ′′ = x ′ ay ′′ , so we just take u = w ′ .Since w ⊢ w ′ implies that | w ′ | = | w | −
2, no infinite reduction sequencesare possible. By Newman’s lemma [5], this implies that the system is confluent,namely, for each w ∈ Σ ∗ there exists exactly one word r ( w ) such that w ⊢ ∗ r ( w )and, for each x ∈ Σ ∗ , r ( w ) ⊢ ∗ x implies x = r ( w ), i.e., r ( w ) does not contain anyfactor aa − . ⊓⊔ We define the reduced representation of a word w ∈ Σ ∗ as the word r ( w ) givenin Lemma 1, i.e, the word which is obtained from w by repeatedly replacing with ǫ all factors of the form aa − , for any letter a ∈ Σ , until no such factor exists.If r ( w ) = ǫ we say that w is reducible . We can extend this to languages so thatfor L ⊆ Σ ∗ , we let r ( L ) = { r ( w ) : w ∈ L } .Given a language L , the ⊢ -closure of L is the set of the words which can beobtained by “reducing” words of L , i.e., the set { x ∈ Σ ∗ : ∃ w ∈ L s.t. w ⊢ ∗ x } .Notice that r ( L ) coincides with the intersection of the ⊢ -closure of L and r ( Σ ∗ ).2ection 2 examines the reduced representations of regular and context-freelanguages. Section 3 provides some bounds on the state complexity of reducedrepresentations. In Section 4 we look at bounds on the length of the shortest wordin a regular language that reduces to ǫ . Section 5 demonstrates counterexamplesfor some other natural questions. When considering the reduced representations of languages, it is natural to won-der if common classes of languages are closed under this operation. In this sectionwe show that if a language L is regular then r ( L ) is regular, but if L is context-free then r ( L ) does not need to be context-free. Lemma 2.
For Σ = Γ ∪ Γ − , where Γ = { , . . . , k } and Γ − = { − , . . . , k − } ,there exists a DFA M k of k + 2 states that accepts r ( Σ ∗ ) .Proof. We notice that a word w is reduced if and only if it does not containthe factor aa − , for each a ∈ Σ . This condition can be verified by defining anautomaton M k that remembers in its finite control the last input letter. To thisaim, the automaton has a state q a for each a ∈ Σ . If in the state q a the symbol a − is received, then the automaton reaches a dead state q − .Formally, M k is the DFA ( Q, Σ, δ, q , F ) defined as follows (see Figure 1 foran example): Q = { q , q − } ∪ { q i : i ∈ Γ ∪ Γ − } , F = Q \ { q − } , and δ ( q a , c ) = ( q c , if a = c − and q a = q − ; q − , otherwise . ⊓⊔ Lemma 3.
Given an ǫ -NFA M = ( Q, Σ, δ, q , F ) with n states, an automaton M ′ accepting the ⊢ -closure of L ( M ) can be built in time O ( n ) .Proof. The idea behind the proof is to present an algorithm that given M com-putes M ′ by adding to M ǫ -transitions corresponding to paths on reduciblewords. The algorithm is similar to a well known algorithm for minimizing DFAs[3, p. 70]. It uses a directed graph G = ( Q, E ) to remember ǫ -transitions. Foreach pair of states s, t , the algorithm also keep a set l ( s, t ) of pairs of states, withthe following meaning: if ( p, q ) ∈ l ( s, t ) and the algorithm discovers that there isa path from s to t on a reducible word (and hence it adds the edge ( s, t ) to G ),then there exists a path from p to q on a reducible word (thus, the algorithmcan also add the edge ( p, q )). E ← transitive closure of { ( p, q ) | q ∈ δ ( p, ǫ ) } for s, t ∈ Q do l ( s, t ) ← ∅ for p, q, s, t ∈ Q doif ∃ a ∈ Σ s.t. s ∈ δ ( p, a ) and q ∈ δ ( t, a − ) thenif ( s, t ) ∈ E then E ← update ( E, ( p, q )) else l ( s, t ) ← l ( s, t ) ∪ { ( p, q ) } q q − q − − − − − − − q − q − − − Fig. 1. M , a DFA that accepts r ( Σ ∗ ) for | Σ | = 4.The subroutine update returns the smallest set E ′ having the following proper-ties: – E ∪ { ( p, q ) } ⊆ E ′ ; – if ( p ′ , q ′ ) ∈ E ′ then each element belonging to l ( p ′ , q ′ ) is in E ′ ; – the graph ( Q, E ′ ) is transitive.At the end of the execution, the automaton M ′ is obtained by adding to M an ǫ -transition from a state p to a state q for each edge ( p, q ) in the resultinggraph G .Now, we show that the language accepted by M ′ is the ⊢ -closure of L ( M ).To this aim, we observe that for all p, q, s, t ∈ Q , such that s ∈ δ ( p, a ) and q ∈ δ ( t, a − ) are transitions of M for some a ∈ Σ , if M ′ contains an ǫ -transitionfrom s to t then it must contain also an ǫ -transition from p to q . In fact, when thealgorithm examines these 4 states in the loop, if ( s, t ) is in E then the algorithmcalls update to add ( p, q ) to E . Otherwise, the algorithm adds ( p, q ) to l ( s, t ).Since M ′ finally contains the ǫ -transition from s to t , then there is a step ofthe algorithm, after the insertion of ( p, q ) in l ( s, t ), adding the pair ( s, t ) to E .The only part of the algorithm able to perform this operation is the subroutine update . But when the subroutine adds the pair ( s, t ) to E then it must add allthe pairs in l ( s, t ). Hence, M ′ must also contain an ǫ -transition from p to q . As Notice that the pair ( s, t ) can be added to E by the subroutine update either becauseit is the second argument in the call of the subroutine, or because it belongs to alist l ( p ′ , q ′ ), where ( p ′ , q ′ ) is added to E in the same call, or because there is a path w ∈ L ( M ′ ) and w ⊢ w ′ then w ′ ∈ L ( M ′ ), i.e., L ( M ′ ) is closedunder ⊢ . Since the algorithm does not remove the original transitions from M , L ( M ) ⊆ L ( M ′ ) and, hence, the ⊢ -closure of L ( M ) is included in L ( M ′ ).On the other hand, it can be easily shown that for each ǫ -transition of M ′ from a state p to a state q there exists a reducible word z such that q ∈ δ ( p, z )in M . Using this argument, from each word w ∈ L ( M ′ ) we can find a word x ∈ L ( M ) such that x ⊢ ∗ w . This permit us to conclude that L ( M ′ ) accepts the ⊢ -closure of L ( M ).Now we show that the algorithm works in O ( n ) time. A naive analysis givesa running time growing at least as n . In fact, the second for-loop iterates overall state 4-tuples. Inside the loop the most expensive step is the subroutine update . This subroutine starts by adding an edge ( p, q ) to E . For each newedge ( p ′ , q ′ ) added to E the subroutine has to add all the edges in l ( p ′ , q ′ ),while keeping the graph transitive. This seems to be an expensive part of thecomputation. However, we can observe that each set l ( p ′ , q ′ ) contains less than n elements. Furthermore, a set l ( p ′ , q ′ ) is examined only once during the executionof the algorithm, namely when ( p ′ , q ′ ) is added to E . Hence, the total time spentwhile examining the sets l in all the calls of the subroutine update is O ( n ).Furthermore, no more that n edges can be inserted into G , and each insertioncan be done in O ( n ) amortized time while maintaining the transitive closure[4,6]. Summing up, we get that the overall time of the algorithm is O ( n ). ⊓⊔ By combining the results in the previous lemmata, we are now able to showthe following:
Proposition 1.
Given an ǫ -NFA M = ( Q, Σ, δ, q , F ) with n states, an ǫ -NFA M r such that L ( M r ) = r ( L ( M )) can be built in O ( n ) time.Proof. The language r ( L ( M )) is the intersection of the ⊢ -closure of L ( M ) and r ( Σ ∗ ). According to Lemma 3, from M we build an automaton M ′ acceptingthe ⊢ -closure of L ( M ). Hence, using standard constructions, from M ′ and theautomaton obtained in Lemma 2 (whose size is fixed, if the input alphabet isfixed), we get the automaton M r accepting r ( M ) = L ( M ′ ) ∩ r ( Σ ∗ ).The most expensive part is the construction of M ′ , which uses O ( n ) time. ⊓⊔ Corollary 1.
For any L ⊆ Σ ∗ , if L is regular then r ( L ) is regular. Now we turn our attention to context-free languages and prove that theanalogue of Corollary 1 does not hold. For this we use the notion of a quotientof two languages.
Definition 1.
Given L , L ⊆ Σ ∗ , the quotient of L by L is L /L = { w : ∃ x ∈ L such that wx ∈ L } from s to t consisting of some arcs already in E and at least one arc added duringthe same call of update . Lemma 4.
For any two languages L , L ⊆ Γ ∗ , the language L = r ( L L − ) ∩ Γ ∗ equals the quotient L /L .Proof. We notice that r ( wxx − ) = w , for each w, x ∈ Γ ∗ . Hence, given w ∈ Γ ∗ ,it holds that w ∈ L = r ( L L − ) ∩ Γ ∗ if and only if there exists x ∈ L suchthat wx ∈ L . Therefore L = L /L . ⊓⊔ Corollary 2.
The class of context-free languages is not closed under r () .Proof. By contradiction, suppose that the class of context-free languages isclosed unded r (). Since this class is closed under the operations of reversal,morphism, concatenation and intersection with a regular language, for any twocontext-free languages L and L over Γ , the language L = r ( L L − ) ∩ Γ ∗ isalso context-free. However, from Lemma 4, L = L /L , implying that the classof context-free languages would be closed under quotient, a contradiction. ⊓⊔ Here we look at some bounds on the state complexity of the reduced represen-tation of a regular language.
Proposition 2.
For any ǫ -NFA, M = ( Q, Γ ∪ Γ − , δ, q , F ) with n states, Γ = { , , . . . , k } and Γ − = { − , − , . . . , k − } for some positive integer k , thereexists a DFA of at most n (2 k + 2) states that accepts r ( L ( M )) .Proof. The upper bound follows from the algorithm used to prove Proposition 1.The first part of the construction (i.e., the construction of the automaton M ′ accepting the ⊢ -closure of the language accepted by M ) does not increase thenumber of states. The resulting automaton M ′ can be converted into a DFAwith 2 n states. Finally, to get an automaton accepting r ( L ( M )) we apply theusual cross-product construction to this automaton and to the DFA with 2 k + 2states accepting r ( Σ ∗ ) obtained in Lemma 2. The intersection results in a DFAof no more than 2 n (2 k + 2) states. ⊓⊔ Since each DFA is a fortiori an ǫ -NFA, the previous proposition gives anupper bound for the state complexity of the reduced representation. Another interesting question is: given a DFA M of n states such that ǫ ∈ r ( L ( M )), what is the shortest w ∈ L ( M ) such that r ( w ) = ǫ ? We provideupper and lower bounds, and we examine the special case of small alphabets.First we provide an upper bound. 6 roposition 3. For any NFA M = ( Q, Σ, δ, q , F ) with n states such that thereexists w ∈ L ( M ) with r ( w ) = ǫ , there exists w ′ ∈ L ( M ) such that | w ′ | ≤ n − n and r ( w ′ ) = ǫ .Proof. Suppose M accepts w ∈ Σ + such that r ( w ) = ǫ . Then w can be de-composed in at least one of two ways. Either there exist u, v ∈ Σ + such that w = uv, r ( u ) = ǫ and r ( v ) = ǫ (Case 1), or there exist u ∈ Σ ∗ , a ∈ Σ suchthat w = aua − and r ( u ) = ǫ (Case 2). Any factor w ′ of w such that r ( w ′ ) = ǫ can also be decomposed in at least one of these two ways, so we can recursivelydecompose w and the resulting factors until we have decomposed w into singlesymbols. So, we can specify a certain type of parse tree such that M accepts w ∈ Σ ∗ with r ( w ) = ǫ if and only if we can build this type of parse tree for w .Define our parse tree for a given w as follows. Every internal node correspondsto a factor w ′ of w such that r ( w ′ ) = ǫ , and the root of the whole tree correspondsto w . The leaves store individual symbols. When read from left to right, thesymbols in the leaves of any subtree form the word that corresponds to the rootof the subtree. Each internal node is of one of two types:1. The node has two children, both of which are internal nodes that serve asroots of subtrees (corresponds to Case 1).2. The node has three children, where the left and the right children are singlesymbols that are inverses of each other, and the child in the middle is emptyor it is an internal node that is the root of another subtree (corresponds toCase 2).An example is shown in Figure 2. Now, we fix an accepting computation of M on input w . We label each internal node t with a pair of states p, q ∈ Q suchthat if w ′ is the factor of w that corresponds to the subtree rooted at t , and w = xw ′ y , then p ∈ δ ( q , x ) and q ∈ δ ( p, w ′ ) are the states reached after readingthe input prefixes x and xw ′ , respectively, during the accepting computationunder consideration. (This also implies that q f ∈ δ ( q, y ), with q f ∈ F , and( q , q f ) is the label associated with the root of the tree.)7 B a − C a a − D ab b − b − E bb − b W Fig. 2.
An example parse tree for the word w = a − bb − aa − b − b − bba , withoutthe state pair labels.If the parse tree of w has two nodes t and u with the same state-pair labelsuch that u is a descendent of t , then there exists a word shorter than w whichis accepted and reduces to the empty word. This is because we can replace thesubtree rooted at t with the subtree rooted at u . Furthermore, if an internal node t is labeled with a pair ( q, q ), for some q ∈ Q , then the factor w ′ correspondingto the subtree rooted at t can be removed from w , obtaining a shorter reducibleword. Hence, by a pigeonhole argument, we conclude that the height of thesubtree corresponding to the shortest reducible word w is at most n − n . We nowobserve that the number of leaves of a parse tree of height k defined accordingto our rules is at most 2 k . (Such a tree is given by the complete binary tree ofheight k , which has no nodes with three children. The avoidance of nodes withthree children is important because such nodes fail to maximize the numberof internal nodes in the tree, which in turn results in less than the maximumnumber of leaves.) This permits us to conclude that | w | ≤ n − n . ⊓⊔ Now we show that there is a lower bound that is exponential in the alphabetsize and in the number of the states.
Proposition 4.
For all integers n ≥ there exists a DFA, M n , with n + 1 states over the alphabet Σ = Γ ∪ Γ − , where Γ = { , , . . . , n − } and Γ − = { − , − , . . . , ( n − − } , with the property that if w ∈ L ( M n ) and r ( w ) = ǫ ,then | w | ≥ n − .Proof. The proof is constructive. Let M n be the DFA ( Q, Σ, δ, q , F ), illustratedin Figure 3, where Q = { q − , q , q , . . . , q n − } , F = { q } , and δ ( q a , c ) = q , if c = 1 and a = 0; q a +1 , if c = a − and 1 ≤ a ≤ n − q , if either c = a and 1 ≤ a ≤ n − , or c = 1 − and a = n − . q − . q q − q − q − − ( n − − q n − n − q n − ( n − − Fig. 3. M n : an n + 1 state DFA with the property that for all w ∈ L ( M n ) suchthat r ( w ) = ǫ , | w | ≥ n − . The dead state is not shown.Now we show that M n has the desired property. Assume there exists w ∈ L ( M n ) such that r ( w ) = ǫ . Then | w | a = | w | a − for all a ∈ Σ . Since all words in L ( M n ) must contain the symbol 1 (due to the single incoming transition to theonly accepting state), it follows that w must also contain 1 − . Furthermore, theonly possible transition from q not leading to the dead state uses the symbol1 − . Hence w must begin with the prefix 11 − . Since δ ( q , − ) = q and theonly two transitions that leave q are on 2 and 2 − , w must contain both of 2and 2 − . Now assume that w contains the symbol i − with 1 < i < n −
2. Thenthe state q i +1 must be reached while reading w , thus implying that the symbols( i + 1) and ( i + 1) − also appear in w . Therefore, by induction, w must containat least one occurrence of each a ∈ Σ .Now we claim that w must contain at least 2 n − − a occurrences of the symbol a , for 1 ≤ a ≤ n −
2, and hence at least 2 n − − a occurrences of the symbol a − .We prove the claim by induction on n − − a . The basis, a = n −
2, follows fromthe previous argument. Now, suppose the claim true for k = n − − a . We proveit for k + 1 = n − − ( a − w contains at least2 k occurrences of the symbol a and at least 2 k occurences of a − . Observingthe structure of the automaton, we conclude that to have such a number ofoccurrences of the two letters a and a − , the state q k must be visited at least9 k +1 times. On the other hand, the only transition entering q k is from the state q k − on the letter ( a − − . Hence, w must contain at least 2 k +1 = 2 n − − ( a − occurrences of ( a − − and, according to the initial discussion, at least 2 k +1 =2 n − − ( a − occurrences of a −
1. This proves the claim.By computing the sum over all alphabet symbols, we get that | w | ≥ n − − n − − must always be followed by the symbol1 − , w must actually contain one additional occurrence of each of 1 and 1 − .Thus | w | ≥ n − . ⊓⊔ It turns out that the shortest word that reduces to ǫ accepted by the DFA M n in the proof of Proposition 4 is related to the well-known ruler sequence,( ν ( n )) n ≥ , where ν ( n ) denotes the exponent of the highest power of 2 divid-ing n . This sequence has many interesting characterizations including being thelexicographically least infinite squarefree word over Z . For integers k >
0, let r k = ( ν ( n ) ≤ n< k ) be the prefix of length 2 k − r = 0102010.Let w n be the shortest word accepted by M n that reduces to ǫ . Let w ′ n be theprefix of w of length | w | −
2. This is well defined for n ≥
3. Also let w n = w ′ n = ǫ for n = 2. Then for any integer n ≥
3, we have w n = w ′ n − ( n − w ′ n − ( n − − −
1. It can be easily verified that this word is accepted by M n . Now definethe homomorphism h such that h ( a ) = a for a ∈ Γ , and h ( a ) = ǫ for a ∈ Γ − .Then h ( w n ) = r n − Proposition 5.
For each integer n ≥ there exists a DFA, M n with n + 1 states over the alphabet Σ = Γ ∪ Γ − , where Γ = { , } and Γ − = { − , − } ,with the property that the only word w ∈ L ( M n ) such that r ( w ) = ǫ has length | w | = 3 · n − .Proof. The proof is constructive. Let M n be the DFA ( Q, Σ, δ, q n , F ) where Q = { q − , q , q , p } ∪ { p i , q i , r i : 2 ≤ i ≤ n } , F = { p n } , and δ ( q a , c ) = q a − , if 1 ≤ a ≤ n, and either c = 1 and a ≡ , or c = 2 and a ≡ .δ ( p a , c ) = p a +1 , if 1 ≤ a ≤ n − , and either c = 1 and a ≡ , or c = 2 and a ≡ ,r a +1 , if 1 ≤ a ≤ n − , and either c = 1 − and a ≡ , or c = 2 − and a ≡ .δ ( r a , c ) = q a − , if 2 ≤ a ≤ n, and either c = 1 − and a ≡ , or c = 2 − and a ≡ .δ ( q , a − ) = p q − . The case n = 4 is illustratedin Figure 4. ✛✚✘✙ p ✛✚✘✙ p ✛✚✘✙ p ✛✚✘✙ p ✛✚✘✙ q ✛✚✘✙ q ✛✚✘✙ q ✛✚✘✙ q ✛✚✘✙ r ✛✚✘✙ r ✛✚✘✙ r ✛✚✘✙ q ✲ ✗✖ ✔✕ ✛ ✛ ✛ ✲ ✲ ✲ ✻ − ✻ − ✻ − ✻ − ✻ − ✻ − ❅❅❅❅❅❅❅❘ (cid:0)(cid:0)(cid:0)(cid:0)(cid:0)(cid:0)(cid:0)✠ − Fig. 4. M : a 3 · · −
4. (The dead state is not represented.)In order to prove the statement, for each integer m ≥
0, let us consider theset C m of pairs of states, others than the dead state, which are connected by areducible word of length m , i.e. C m = { ( s ′ , s ′′ ) ∈ Q ′ × Q ′ : ∃ w ∈ Σ ∗ s.t. | w | = m, r ( w ) = ǫ, and δ ( s ′ , w ) = s ′′ } , where Q ′ = Q \ { q − } . We notice that C m = ∅ , for m odd. Furthermore C = { ( s, s ) : s ∈ Q ′ } and, for m > C m = C ′ m ∪ C ′′ m , where: C ′ m = { ( s ′ , s ′′ ) : ∃ ( r ′ , r ′′ ) ∈ C m − , a ∈ Σ s.t. δ ( s ′ , a ) = r ′ and δ ( r ′′ , a − ) = s ′′ } , (1) C ′′ m = { ( s ′ , s ′′ ) : ∃ m ′ , m ′′ > , ( s ′ , r ′ ) ∈ C m ′ , ( r ′′ , s ′′ ) ∈ C m ′′ s.t. m ′ + m ′′ = m and r ′ = r ′′ } . (2)We claim that, for each m ≥ C m = { ( q k , p k ) } , if ∃ k , 1 ≤ k ≤ n , s.t. m = 3 · k − { ( q k , r k ) , ( r k , p k ) } , if ∃ k , 2 ≤ k ≤ n , s.t. m = 3 · k − − ∅ , otherwise. (3)11e prove (3) by induction on m .As already noticed, C = ∅ . By inspecting the transition function of M n , wecan observe that C = { ( q , p ) } . Notice that 2 = 3 · −
4. This proves thebasis.For the inductive step, we now consider m > m .First, we show that we can simplify the formula (2) for C ′′ m . In fact, usingthe inductive hypothesis, for 0 < m ′ , m ′′ < m , the only possible ( s ′ , r ′ ) ∈ C m ′ and ( r ′′ , s ′′ ) ∈ C m ′′ satisfying r ′ = r ′′ are the pairs ( q j , r j ) , ( r j , p j ) ∈ C · j − − ,obtained by taking m ′ = m ′′ = 3 · j − −
2, for suitable values of j . This, togetherwith the condition m ′ + m ′′ = m , restricts the set C ′′ m to: C ′′ m = { ( s ′ , s ′′ ) | ∃ r ∈ Q : ( s ′ , r ) ∈ C m/ and ( r, s ′′ ) ∈ C m/ } . (4)Now we consider three subcases: Case 1: m = 3 · k −
4, with k ≥ m − · j − · j −
2, for any j . Hence, by the inductive hypothesis, C m − = ∅ .By (1), this implies C ′ m = ∅ , and then C m = C ′′ m .We now compute C ′′ m using (4) and the set C m/ obtained according to theinductive hypothesis. We observe that m/ · k − −
2. Hence, for k ≤ n , C m/ = { ( q k , r k ) , ( r k , p k ) } and, thus, C m = C ′′ m = { ( q k , p k ) } . On the other hand,if k > n then C m/ = ∅ , which implies C m = C ′′ m = ∅ . Case 2: m = 3 · k − −
2, with k ≥ m/ · j − · j − C ′′ m must be empty. Thus, C m = C ′ m .We compute C ′ m as in (1), using the set C m − obtained according to theinduction hypothesis. We notice that m − · k − −
4. If k > n + 1 then C m − = ∅ , thus implying C m = C ′ m = ∅ . Otherwise, C m − = { ( q k − , p k − ) } .In order to obtain all the elements of C ′ m , we have to examine the transitionsentering q k − or leaving p k − . For k = n + 1 there are no such transitionsand, hence, C m = C ′ m = ∅ . For k ≤ n all the transitions entering q k − orleaving p k − involve the same symbol a ∈ { , } or its inverse: there are exactlytwo transitions entering q k − ( δ ( q k , a ) = δ ( r k , a − ) = q k − ) and exactly twotransitions leaving p k − ( δ ( p k − , a ) = p k and δ ( p k − , a − ) = r k ). Hence, by theappropriate combinations of these transitions with the only pair ( q k − , p k − ) in C m − , we get that C m = C ′ m = { ( q k , r k ) , ( r k , p k ) } . Case 3: Remaining values of m .If m = 3 · k − with k ≥
2, then C m − = { ( q k , r k ) , ( r k , p k ) } . All the transitionsentering or leaving r k use the same symbol a − , with a ∈ { , } , while all thetransitions entering q k or leaving p k use the other symbol b ∈ { , } , b = a , or b − . Hence, from (1), C ′ m = ∅ .For all the other values of m , the form of m − · j − · j −
2. This implies that C m − = ∅ and, then, C ′ m must be empty. Hence, weconclude that C m = C ′′ m . 12uppose C ′′ m = ∅ . From (4) and the inductive hypothesis, it follows that m/ · j − − j , thus implying m = 3 · j −
4. This is a contradiction,because the values of m we are considering are not of this form. Hence, C m = C ′′ m must be empty.This completes the proof of (3).Recall that the initial state of M n is q n , while the only final state is p n .Hence, the length of the shortest reducible word accepted by M n is the smallestinteger m such that ( q n , p n ) ∈ C m . According to (3), we conclude that such alength is 3 · n − M n whose length is different than 3 · n −
4. With some small refinements in theargument used to prove (3), we can show that M n accepts exactly one reducibleword. In particular, for k ≥ w k = − , if k = 1;1 w k − − − w k − , if k > k odd;2 w k − − − w k − , otherwise.By an inductive argument it can be proved that w k is the only reducible wordsuch that δ ( q k , w k ) = p k and | w k | = 3 · k − ⊓⊔ We now examine the special case where Σ = { , − } , and give a cubic upperbound and quadratic lower bound. The next proposition gives the upper bound,which holds even in the nondeterministic case. Proposition 6.
Let M = ( Q, { , − } , δ, q , F ) be an NFA with n states suchthat ǫ ∈ r ( L ( M )) . Then M accepts a reducible word of length at most n (2 n + 1) .Proof. We prove the result by contradiction. Assume the shortest w ∈ L ( M )such that r ( w ) = ǫ has | w | > n (2 n + 1). Define a function b on words by b ( z ) = | z | − | z | − for z ∈ Σ ∗ . Roughly speaking, the function b measures the“balance” between the number of occurrences of the symbol 1 and those of thesymbol 1 − in a word.Suppose that no factor w ′ of w has | b ( w ′ ) | > n . Then the function b cantake on at most 2 n + 1 distinct values. Since | w | > n (2 n + 1), there must bea value C such that b takes the value C for more than n different prefixes of w . That is, there is some ℓ ≥ n such that w = xy y · · · y ℓ z where the y i arenonempty and b ( x ) = b ( xy ) = b ( xy y ) = · · · = b ( xy y · · · y ℓ ) . Consider a sequence of ℓ + 1 states p , p , . . . , p ℓ ∈ Q , and a state q f ∈ F , suchthat during an accepting computation M makes the following transitions: p ∈ δ ( q , x ) , p ∈ δ ( p , y ) , . . . , p ℓ ∈ δ ( p ℓ − , y ℓ ) , q f ∈ δ ( p ℓ , z )Since ℓ ≥ n , a state must repeat in the above sequence, say p i = p j with i < j . Then u = xy · · · y i y j +1 · · · y ℓ z is shorter than w (since we have omitted13 i +1 · · · y j ) and it is accepted by M . Furthermore, observing that b ( y i +1 · · · y j ) =0, we conclude that r ( u ) = ǫ . Since | u | < | w | , this is a contradiction to our choiceof w . Hence, w must contain a factor w ′ of w such that | b ( w ′ ) | > n .Let y be the shortest factor of w such that b ( y ) = 0 and | b ( y ′ ) | > n forsome prefix y ′ of y . We can write w = xyz , for suitable words x, z . Let D be themaximum value of | b ( y ′ ) | over all prefixes y ′ of y . We suppose that D >
0. (Theargument can be easily adapted to the case
D < i = 0 , , , . . . , D , let R ( i ) be the shortest prefix of y with b ( R ( i )) = i . Similarly, let S ( i ) be the longestprefix of y with b ( S ( i )) = i . Again, consider an accepting computation of M oninput w . For each pair [ R ( i ) , S ( i )], let [ P ( i ) , Q ( i )] be the pair of states such that M is in state P ( i ) after reading xR ( i ) and M is in state Q ( i ) after reading xS ( i ).Since D > n , some pair of states repeats in the sequence { [ P ( i ) , Q ( i )] } . That is,there exists j < k such that [ P ( j ) , Q ( j )] = [ P ( k ) , Q ( k )]. We may therefore omitthe portion of the computation that occurs between the end of R ( j ) and theend of R ( k ) as well as that which occurs between the end of S ( k ) and the endof S ( j ) to obtain a computation accepting a shorter word u such that r ( u ) = ǫ .Again we have a contradiction, and our result follows. ⊓⊔ The following proposition gives a quadratic lower bound.
Proposition 7.
For each integer n ≥ there exists a DFA M n with n +1 states,over the alphabet Σ = { , − } , such that the only reducible word w ∈ L ( M n ) ,has length ( n + 1)( n − / if n is odd, and n / if n is even.Proof. The proof is constructive. Let M n be the DFA ( Q, Σ, δ, q , F ), illustratedin Figure 5, where Q = { q − } ∪ { q i : 0 ≤ i < n } , F = { q ⌊ n ⌋ } , and δ ( q a , c ) = q a +1 , if either c = 1 and 0 ≤ a < ⌊ n ⌋ , or c = 1 − and ⌊ n ⌋ ≤ a ≤ n − q a mod 2 , if c = 1 − and a = n − . Any other transitions lead to the dead state, q − .Observe that if n is odd, then each word w accepted by M n has the form w = (1 n − − n +12 ) α n − , for an α ≥
0. Computing the “balance” function b introduced in the proof of Proposition 6, we get b ( w ) = ( n − − α ), which is0 if and only if α = n − . Finally, by computing the length of w for such an α ,we obtain ( n + 1)( n − / n even, we can prove that the only reducible wordaccepted by M n has length n / ⊓⊔ − − − − − − q q n − q n − q n q q q n − Fig. 5.
Top: M n where n is odd. Bottom: M n where n is even. Here we look at counterexamples that solve two natural questions. The firstquestion is whether the set of all equivalent words to those in a regular languagemust be regular. The second question is whether any of our results hold for amore generalized form of the reduced representation. We now define the set ofequivalent words.
Definition 2.
For w ∈ Σ ∗ , the set of equivalent words is eq( w ) = { w ′ : r ( w ) = r ( w ′ ) } For L ⊆ Σ ∗ , the set of equivalent words is eq( L ) = { eq( w ) : w ∈ L } Proposition 8.
There exists L ⊆ Σ ∗ such that L is regular but eq( L ) is not.Proof. Consider the following example. Let Σ = { , − } and let L = { ǫ } .Then eq( L ) is the language of balanced parentheses, which is well known to benonregular. ⊓⊔ Proposition 9.
Let L be a regular language over an alphabet Σ . The language eq( L ) is context-free.Proof. Let M be a DFA accepting L . We first construct the ǫ -NFA M r of Propo-sition 1 that accepts r ( L ). We then reverse the transitions of M r to obtain an ǫ -NFA A that accepts the reversal of r ( L ). We now construct a PDA B thataccepts eq( L ). The operation of B is as follows. On input w , the PDA B readseach symbol of w and compares it with the symbol on top of the stack. If thesymbol being read is a and the symbol on top of the stack is the inverse of a , the15achine B pops the top symbol of the stack. Otherwise, the machine B pushes a on top of the stack. After the input w is consumed, the stack contains a word z that is equivalent to w . Moreover, since z does not contain any factor of theform aa − , the word z must equal r ( w ) by Lemma 1. Finally, on ǫ -transitions,the PDA B pops each symbol of z off the stack and simulates the computationof A on each popped symbol. The net effect is to simulate A on z R (the reversalof z ). If z R is accepted by A , the PDA B accepts w . Since z R is accepted by A if and only if z ∈ r ( L ), the PDA B accepts w if and only if r ( w ) ∈ r ( L ).However, we have r ( w ) ∈ r ( L ) if and only if w ∈ eq( L ), so B accepts eq( L ), asrequired. ⊓⊔ A set of equivalent words as described above can be thought of as an equiv-alence class under an equivalence relation described by a very particular set ofequations: for all a ∈ Σ, aa − = ǫ . Our generalization is to allow for an arbitraryset of equations, which we will refer to as the “defining set of equations”. Thena generalized reduced representation of a word is an equivalent word such thatthere are no shorter equivalent words. It is no longer necessary that reducedrepresentation be unique, so we denote the set of generalized reduced represen-tations of a word w as r g ( w ). For example, if Σ = { a, b, c, d } we may have thedefining set of equations { ab = cd, bc = a } . Then eq( abd ) = { abd, cdd, bcbd } and r g ( aabd ) = { abd, cdd } . It is natural to wonder whether an analogous result toCorollary 1 holds under this generalized form of reduced representations. Proposition 10.
There exists L ⊆ Σ ∗ such that L is regular but r g ( L ) is noteven context-free.Proof. Consider the following example. Let Σ = { a, b, c } , let the defining set ofequations be { ab = ba, ac = ca, bc = cb } and let L = ( abc ) ∗ . Then r g ( L ) is thelanguage { x : | x | a = | x | b = | x | c } , which is known to be noncontext-free, andhence also nonregular. ⊓⊔ References
1. Epstein, D.B.A., Cannon, J.W., Holt, D.F., Levy, S.V.F., Paterson, M.S.,Thurston, W.P.: Word Processing in Groups. Jones and Bartlett Publishers (1992)2. Ginsburg, S., Spanier, E.H.: Quotients of context-free languages. J. Assoc. Comput.Mach. (1963) 487–4923. Hopcroft, J.E., Ullman, J.D.: Introduction to Automata Theory, Languages, andComputation. Addison-Wesley (1979)4. Italiano, G.F.: Amortized efficiency of a path retrieval data structure. Theor.Comput. Sci. (1986) 273–2815. Newman, M.H.A.: On theories with a combinatorial definition of “equivalence”.Annals of Mathematics (1942) 223–2436. Poutr´e, J.A., van Leeuwen, J.: Maintenance of transitive closures and transitivereductions of graphs. In Gottler, H., Schneider, H.J., eds.: Proceedings of theinternational Workshop on Graph-theoretic Concepts in Computer Science . Lect.Notes Comput. Sci., Vol. 314. Springer-Verlag (1998) 106–120(1942) 223–2436. Poutr´e, J.A., van Leeuwen, J.: Maintenance of transitive closures and transitivereductions of graphs. In Gottler, H., Schneider, H.J., eds.: Proceedings of theinternational Workshop on Graph-theoretic Concepts in Computer Science . Lect.Notes Comput. Sci., Vol. 314. Springer-Verlag (1998) 106–120