2DFA - This is page 119 Printer: Opaque this Lecture 17...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: This is page 119 Printer: Opaque this Lecture 17 Two-Way Finite Automata Two-way finite automata are similar to the machines we have been study- ing, except that they can read the input string in either direction. We think of them as having a read head, which can move left or right over the input string. Like ordinary finite automata, they have a finite set Q of states and can be either deterministic (2DFA) or nondeterministic (2NFA). Although these automata appear much more powerful than one—way finite automata, in reality they are equivalent in the sense that they only accept regular sets. We will prove this result using the Myhill—Nerode theorem. We think of the symbols of the input string as occupying cells of a finite tape, one symbol per cell. The input string is enclosed in left and right endmarkers l- and -l, which are not elements of the input alphabet E. The read head may not move outside of the endmarkers. mam—m Informally, the machine starts in its start state .9 with its read head pointing to the left endmarker. At any point in time, the machine is in some state q with its read head scanning some tape cell containing an input symbol a,- or one of the endmarkers. Based on its current state and the symbol occupying 120 Lecture 17 Example 17.1 the tape cell it is currently scanning, it moves its read head either left or right one cell and enters a new state. It accepts by entering a special accept state t and rejects by entering a special reject state r. The machine’s action on a particular state and symbol is determined by a transition function 6 that is part of the specification of the machine. Here is an informal description of a 2DFA accepting the set A {:L' E {a, b}* | #a(x) is a multiple of 3 and #b(m) is even}. The machine starts in its start state scanning the left endmarker. It scans left to right over the input, counting the number of a’s mod 3 and ignoring the b’s. When it reaches the right endmarker -I, if the number of (1.75 it has seen is not a multiple of 3, it enters its reject state, thereby rejecting the input—the input string a: is not in the set A, since the first condition is not satisfied. Otherwise it scans right to left over the input, counting the number of b’s mod 2 and ignoring the a’s. When it reaches the left endmarker I- again, if the number of b’s it has seen is odd, it enters its reject state; otherwise, it enters its accept state. El Unlike ordinary finite automata, a 2DFA needs only a single accept state and a single reject state. We can think of it as halting immediately when it enters one of these two states, although formally it keeps running but remains in the accept or reject state. The machine need not read the entire input before accepting or rejecting. Indeed, it need not ever accept or reject at all, but may loop infinitely without ever entering its accept or reject state. Formal Definition of 2DFA Formally, a 2DFA is an octuple M (Q, 2’ |—’ -|’ 6, 8’ t7 r), where 0 Q is a finite set (the states), o 2 is a finite set (the input alphabet), o I- is the left endmarker, I- ¢ 2, o -| is the right endmarker, -| ¢ 2, o 6 : Q x (2 U {|-, -i}) —> (Q x {L,R}) is the transition function (L,R stand for left and right, respectively), o s E Q is the start state, 0 t E Q is the accept state, and Two—Way Finite Automata 121 Example 17.2 o r E Q is the reject state, 1' aé t, such that for all states (1, 5(q, l‘) (u, R) for some u E Q, 5((1, ‘0 = (v,L) for some 1) E Q, (17'1) and for all symbols b E E U {|-}, 6t,b=t,R, 6r,b=r,R, 6((t, 4)) = ((t, Li, 6E1", 4)) =((1", 13)). (17-2) Intuitively, the function 6 takes a state and a symbol as arguments and returns a new state and a direction to move the head. If 6(p, b) = (q, d), then whenever the machine is in state p and scanning a tape cell containing symbol b, it moves its head one cell in the direction (1 and enters state q. The restrictions (17.1) prevent the machine from ever moving outside the input area. The restrictions (17.2) say that once the machine enters its accept or reject state, it stays in that state and moves its head all the way to the right of the tape. The octuple is not a legal 2DFA if its transition function 6 does not satisfy these conditions. Here is a formal description of the 2DFA described informally in Example 17.1 above. Q: 2: {quqla q2ap07p17ta’r}a {(1, b}. The start, accept, and reject states are qo, t, and 7”, respectively. The tran- sition function 6 is given by the following table: l- a, b -| (10 ((10, R) (‘11, R) ((10, R) (P0, L) (11 — ((12, R) ((11, R) (7‘, L) q2 - ((10, R) ((12, R) (7”, L) p0 (ta (p07 (P1: _ p1 (Irv (P17 (p07 _ t (ta R) (ta R) (t: R) (75,11) 7‘ (7‘, R) (7‘, R) (7", R) (7‘, L) The entries marked — will never occur in any computation, so it doesn’t matter what we put here. The machine is in states qo, ql, or (12 on the first pass over the input from left to right; it is in state q,- if the number of a’s it has seen so far is 2' mod 3. The machine is in state p0 or p1 on the second pass over the input from right to left, the index indicating the parity of the number of b’s it has seen so far. El 122 Lecture 17 Configurations and Acceptance Fix an input at E 2*, say :L' = a1a2 - nan. Let a0 = I- and an+1 = -I. Then agalag-nananH = I-x-l. A configuration of the machine on input a; is a pair (q, such that q E Q and 0 g 2' g n + 1. Informally, the pair (q, gives a current state and current position of the read head. The start configuration is (s, 0), meaning that the machine is in its start state 3 and scanning the left endmarker. A binary relation —;> , the next configuration relation, is defined on con— figurations as follows: 600, at) = (q, L) =~ (m) f (m — 1), am) = (M) a (pa) i» (q,z'+ 1). The relation %> describes one step of the machine on input ac. We define the relations %> inductively, n 2 0: - (pa) % (m); and - if (w) %> (m) and (m) %> (u, k), then (pa) (u, k). 1 The relation %> is just the n—fold composition of 7. The relations %> are functions; that is, for any configuration (p, i), there is exactly one configuration (q, j) such that (p, %> (q, j). Now define def n (p,i)%(q,j) <=> 3n20 (p,i)7(q,j)- Note that the definitions of these relations depend on the input m. The machine is said to accept the input at if (s, 0) %> (t, for some i. In other words, the machine enters its accept state at some point. The machine is said to reject the input a: if (s, 0) f (r, for some 2'. In other words, the machine enters its reject state at some point. It cannot both accept and reject input at by our assumption that t 7é r and by properties (17.2). The machine is said to halt on input in if it either accepts a: or rejects m. Note that this is a purely mathematical definition—the machine doesn’t really grind to a halt! It is possible that the machine neither accepts nor rejects cc, in which case it is said to loop on x. The set L(M) is defined to be the set of strings accepted by M. Two—Way Finite Automata 123 Example 17.3 The 2DFA described in Example 17.2 goes through the following sequence of configurations on input aababbb, leading to acceptance: (quO): (qul): (111,2), 012,3): (42,4), (110,5): ((105), (110,7): (110,8), (1,0,7), (191,6)? (p075)! (p174)! (p113): (p012): (100,1), (1,0,0), (t:1)' It goes through the following sequence of configurations on input aababa, leading to rejection: ((1010)? (goal), (q172)5 (q2:3)1 (q2:4)1 (q075)1 (goats), (q1a7), (T’6)' It goes through the following sequence of configurations on input aababb, leading to rejection: (quO): 010,1): (41,2), (912,3): (912,4), (110,5), (90,6), (40,7), (170,6), (131,5): (100,4): (P03), (171,2): (111:1), (101:0), Oral)- B This is page 124 Printer: Opaque this Lecture 18 2DFAs and Regular Sets In this lecture we show that 2DFAs are no more powerful than ordinary DFAs. Here is the idea. Consider a long input string broken up in an ar— bitrary place into two substrings acz. How much information about a: can the machine carry across the boundary from x into 2? Since the machine is two-way, it can cross the boundary between a; and z several times. Each time it crosses the boundary moving from right to left, that is, from 2 into :13, it does so in some state q. When it crosses the boundary again moving from left to right (if ever), it comes out of a: in some state, say 17. Now if it ever goes into a: in the future in state q again, it will emerge again in state p, because its future action is completely determined by its current configuration (state and head position). Moreover, the state p depends only on q and x. We will write Tz (q) = p to denote this relationship. We can keep track of all such information by means of a finite table Tm=(QU{°}) —’ (QUfil), where Q is the set of states of the 2DFA M, and o and J. are two other objects not in Q whose purpose is described below. On input :32, the machine M starts in its start state scanning the left end- marker. As it computes, it moves its read head. The head may eventually cross the boundary moving left to right from av into 2. The first time it does so (if ever), it is in some state, which we will call Tz(o) (this is the purpose of o). The machine may never emerge from cc; in this case we 2DFAs and Regular Sets 125 write Tm(o) = J. (this is the purpose of l). The state Tm(o) gives some information about :13, but only a finite amount of information, since there are only finitely many possibilities for Tz(o). Note also that Tm(o) depends only on m and not on 2.: if the input were xw instead of $2, the first time the machine passed the boundary from a: into 11), it would also be in state Tm(o), because its action up to that point is determined only by as; it hasn’t seen anything to the right of the boundary yet. If Tm(o) = J_, M must be in an infinite loop inside ac and will never accept or reject, by our assumption about moving all the way to the right endmarker whenever it accepts or rejects. Suppose that the machine does emerge from :6 into z. It may wander around in z for a while, then later may move back into :3 from right to left in state q. If this happens, then it will either o eventually emerge from 20 again in some state p, in which case we define Tm(q) = p; or 0 never emerge, in which case we define T$(q) = J_. Again, note that T$(q) depends only on m and q and not on 2. If the machine entered a: from the right on input am in state q, then it would emerge again in state Tm(q) (or never emerge, if Tm(q) = J_), because M is deterministic, and its behavior while inside an is completely determined by x and the state it entered a: in. If we write down Tm(q) for every state q along with Tm(o), this gives all the information about a: one could ever hope to carry across the boundary from a: to 2. One can imagine an agent sitting to the right of the boundary between a: and z, trying to obtain information about x. All it is allowed to do is observe the state Tz(o) the first time the machine emerges from .7: (if ever) and later send probes into .7: in various states q to see What state Tm(q) the machine comes out in (if at all). If y is another string such that Ty = Tm, then a: and y will be indistinguishable from the agent’s point of v1ew. Now note that there are only finitely many possible tables T: (Q u {o}) —> (Q U {i}), namely (k + 1)k+1, where k is the size of Q. Thus there is only a finite amount of information about :1: that can be passed across the boundary to the right of .73, and it is all encoded in the table Tm. Note also that if T9, = Ty and M accepts xz, then M accepts yz. This is because the sequence of states the machine is in as it passes the boundary between at and z (or between 11 and z) in either direction is completely determined by the table T3 = Ty and 2. To accept $2, the machine must at some point be scanning the right endmarker in its accept state t. Since 126 Lecture 18 the sequence of states along the boundary is the same and the action when the machine is scanning z is the same, this also must happen on input yz. Now we can use the Myhill—Nerode theorem to show that L(M) is regular. We have just argued that Ta, = Ty : \7’z (M accepts xz <=> M accepts yz) :> Vz(xzeL(M)<=>yzeL(M)) <=> xEL(M)y, where E L( M) is the relation first defined in Eq. (16.1) of Lecture 16. Thus if two strings have the same table, then they are equivalent under E L( M). Since there are only finitely many tables, the relation EL(M) has only finitely many equivalence classes, at most one for each table; therefore, E L( M) is of finite index. By the Myhill—Nerode theorem, L(M) is a regular set. Constructing a DFA The argument above may be a bit unsatisfying, since it does not explicitly construct a DFA equivalent to a given 2DFA M. We can easily do so, however. Intuitively, we can build a DFA whose states correspond to the tables. Formally, define def mEy T$=Ty. That is, call two strings in 2* equivalent if they have the same table. There are only finitely many equivalence classes, at most one for each table; thus E is of finite index. We can also show the following: (i) The table Tm is uniquely determined by T3 and a; that is, if Ta, = Ty, then Tm = Tya. This says that E is a right congruence. (ii) Whether or not w is accepted by M is completely determined by T3; that is, if Tx 2 Ty, then either both as and y are accepted by M or neither is. This says that E refines L(M These observations together say that E is a Myhill—Nerode relation for L(M). Using the construction E I—> ME described in Lecture 15, we can obtain a DFA for L(M) explicitly. To show (i), we show how to construct Tm from TE and a. . p0ap1a-H :pkaq0,q1:‘” qu E Q suCh = and =pi+1a 0 S S k _ 1a and 6(pkaa) = (qkaR)a then Tza(p0) = (11:- 2DFAs and Regular Sets 127 . p01p17' -' apkaq01q1an- aqk—l E Q suCh = and Tz(qi) =pi+1, 0 S i S k — 1, and pk =1», i < k, then Tara(p0) = i. is J_. . pr0ap1a- ' - :pkaquQIa ' ' - aqk E QSUCh that 6(piaa) : (qiaL)a 0 k, : pi+1a 0 S S k _ 1a and : J—a then Tma(p0) || |/\ o If TZ(0) = J_, then Tm(o) = J_. o If T$(o) = p, then Tm(o) = T$a(p). For (ii), suppose T3 = Ty and consider the sequence of states M is in as it crosses the boundary in either direction between the input string and the right endmarker -|. This sequence is the same on input :1: as it is on input y, since it is completely determined by the table. Both strings a: and y are accepted iff this sequence contains the accept state t. We have shown that the relation E is a Myhill—Nerode relation for L(M), where M is an arbitrary 2DFA. The construction E n—> ME of Lecture 15 gives a DFA equivalent to M. Recall that in that construction, the states of the DFA correspond in a one-to—one fashion with the E-classes; and here, each E—class [3:] corresponds to a table Tm : (Q U {0}) —> (Q U {J_}). If we wanted to, we could build a DFA M’ directly from the tables: Q’ ‘5 {row-Damon}, 8’ déf Tea 6’(Tz,a) déf Tm, F’ déf {TzleL(M)}. The transition function 6’ is well defined because of property (i), and Tx 6 F’ iff :1: E L(M) by property (ii). As usual, one can prove by induction on |y| that 3mm?!) = Tam? then a: 6 L(M’) <=> 3’(s’,x) 6 F’ <=> 3’(T€,x) e F’ <=> Ta, 6 F’ <=> a: e L(M) Thus L(M’) = Another proof, due to Vardi [113], is given in Miscellaneous Exercise 61. 128 Lecture 18 Historical Notes Two-way finite automata were first studied by Rabin and Scott [96] and Shepherdson [105]. Vardi [113] gave a shorter proof of equivalence to DFAs (Miscellaneous Exercise 61). ...
View Full Document

Page1 / 10

2DFA - This is page 119 Printer: Opaque this Lecture 17...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online