Download presentation

Presentation is loading. Please wait.

Published byAsia Chatt Modified over 2 years ago

1
Zvi Kohavi and Niraj K. Jha 1 Finite-state Recognizers

2
2 Deterministic Recognizers Treat FSM as a recognizer that classifies input strings into two classes: strings it accepts and strings it rejects Finite-state recognizer: Equivalent to a string of input symbols that enter the machine at successive times Finite-state control: Moore FSM States in which output symbol is 1 (0): accepting (rejecting) states A string is accepted by an FSM: if and only if the state the FSM enters after having read the rightmost symbol is an accepting state Set of strings recognized by an FSM: all input strings that take the FSM from its starting state to an accepting state

3
3 Transition Graph Example: a machine that accepts a string if and only if the string begins and ends with a 1, and every 0 in the string is preceded and followed by at least a single 1 Transition graph: consists of a set of vertices and various directed arcs connecting them At least one of the vertices is specified as a starting vertex Arcs are labeled with symbols from the input alphabet A vertex may have one or more I i -successors or none It accepts a string if the string is described by at least one path emanating from a starting vertex and terminating at an accepting vertex It may be deterministic or non-deterministic

4
4 Example Example: 1110 and accepted by the transition graph below, but 100 rejected Equivalent transition graphs: two or more graphs that recognize the same set of strings Each graph below accepts a string: if and only if each 1 is preceded by at least two 0’s

5
5 Graphs Containing -Transitions -transitions: when no input symbol is used to make the transition Example: Graph that recognizes a set of strings that start with an even number of 1’s, followed by an even number of 0’s, and end with substring 101

6
6 Converting Nondeterministic into Deterministic Graphs Example: Transition graph and its transition table Successor table and deterministic graph:

7
7Theorem Theorem: Let S be a set of strings that can be recognized by a nondeterministic transition graph G n. Then S can also be recognized by an equivalent deterministic graph G d. Moreover, if G n has p vertices, G d will have at most 2 p vertices

8
8 Regular Expressions Example: Sets of strings and the corresponding expression Graph (a) recognizes set {101}: expression denoted as 101 Graph (b) recognizes set {01,10}: expression = Graph (c) recognizes {0111,1011}: expression = –Concatenation of and 11 Graph (d) recognizes set {,1,11,111,1111,…}: expression = 1*

9
9 Regular Expressions (Contd.) Example: 01(01)* = … R* = + R + R 2 + R 3 + … Example: Set of strings on {0,1} beginning with a 0 and followed only by 1’s: 01* Example: Set of strings on {0,1} containing exactly two 1’s: 0*10*10* Example: Set of all strings on {0,1}: (0+1)* = … Example: Set of strings on {0,1} that begin with substring 11: 11(0+1)* Example: Transition graphs and the sets of strings they recognize

10
10 Definition and Basic Properties Let A = {a 1,a 2,…,a p } be a finite alphabet: then the class of regular expressions over alphabet A is defined recursively as follows: Any symbol, a 1, a 2, …, a p alone is a regular expression: as are null string and empty set If P and Q are regular expressions: then so is their concatenation PQ and their union P+Q –If P is a regular expression: then so is its closure P* No other expressions are regular: unless they can be generated in a finite number of applications of the above rules Recognizers for and :

11
11 Identities + R = R R = R = R = R = R * = Set of strings that can be described by a regular expression: regular set Not every set of strings is regular Set over {0,1}, which consists of k 0’s (for all k), followed by a 1, followed in turn by k 0’s, is not regular: … + 0 k 10 k + … –Requires an infinite number of applications of the union operation However, certain infinite sums are regular –Set consisting of alternating 0’s and 1’s, starting and ending with a 1: 1(01)*

12
12 Manipulating Regular Expressions A regular set may be described by more than one regular expression Such expressions are called equivalent Example: Alternating 0’s and 1’s, starting and ending with 1 1(01)* or (10)*1 Let P, Q, and R be regular expressions: then R + R = R PQ + PR = P(Q+R); PQ + RQ = (P + R)Q R*R* = R* RR* = R*R (R*)* = R* + RR* = R* (PQ)*P = P(QP)* (P + Q)* = (P*Q*)* = (P* + Q*)* = P*(QP*)* = (P*Q)*P* + (P + Q)*Q = (P*Q)*

13
13 Examples Example: Prove that the set of strings in which every 0 is immediately followed by at least two 1’s can be described by both R 1 and R 2, where R 1 = + 1*(011)*(1*(011)*)* R 2 = ( )* Proof: R 1 = + 1*(011)*(1*(011)*)* = (1*(011)*)* = ( )* = R 2 Example: Prove the identity (1 + 00*1) + (1 + 00*1)(0 +10*1)*(0 + 10*1) = 0*1(0 + 10*1)* Proof: LHS = (1 + 00*1)[ + (0 + 10*1)*(0 + 10*1)] = [( + 00*)1][ + (0 + 10*1)*(0 + 10*1)] = 0*1(0 + 10*1)*

14
14 Transition Graphs Recognizing Regular Sets Theorem: Every regular expression R can be recognized by a transition graph Proof:

15
15 Example Example: Construct a transition graph recognizing R = (0 + 1(01)*)*

16
16 Example (Contd.) Example: Prove that (P + Q)* = P*(QP*)*

17
17 Informal Techniques Example: Construct a graph that recognizes P = (01 + (11 + 0)1*0)*11 Graph for Q = (11 + 0)1*0 Graph for P

18
18 Example Example: Construct a graph that recognizes R = (1(00)*1 + 01*0)*

19
19 Regular Sets Corresponding to Transition Graphs The set of strings that can be recognized by a transition graph (hence, an FSM) is a regular set Theorem: Let Q, P, and R be regular expressions on a finite alphabet. Then, if P does not contain : Equation R = Q + RP has a unique solution given by R = QP* Equation R = Q + PR has a unique solution given by R = P*Q

20
20 Systems of Equations Example: Derive the set of strings derived by the following transition graph A = + A0 + B1 (1) B = A0 + B1 + C0 (2) C = B0 (3) Substituting (3) into (2): B = A0 + B1 + B00 = A0 + B(1 + 00) (4) From the theorem: B = A0(1 + 00)* (5) Substituting (5) into (1): A = + A0 + A0(1 + 00)*1 = + A(0 + 0(1 + 00)*1) (6) From the theorem: A = (0 + 0(1 + 00)*1)* = (0 + 0(1 + 00)*1)* (7) Hence, solution C from (7), (5) and (3): C = (0 + 0(1 + 00)*1)*0(1 + 00)*0

21
21 Theorem Theorem: The set of strings that take an FSM M from an arbitrary state S i to another state S j is a regular set Combining the two theorems: –An FSM recognizes a set of strings if and only if it is a regular set Applications: the correspondence between regular sets and FSMs enables us to determine whether certain sets are regular Example: Let R denote a regular set on alphabet A that can be recognized by machine M 1 Complement R’: set containing all the strings on A that are not contained in R R’ describes a regular set: since it can be recognized by a machine M 2, which is obtained from M 1 by complementing the output values associated with the states of M 1

22
22 Examples Example: Let P&Q represent the intersection of sets P and Q Prove P&Q is regular Since P’ and Q’ are regular: –P’ + Q’ is regular –Hence, (P’ + Q’)’ is regular –Since P&Q = (P’ + Q’)’: P&Q is regular Regular expressions containing complementation, intersection, union, concatenation, closure: extended regular expressions Example: Consider the set of strings on {0,1} s.t. no string in the set contains three consecutive 0’s Set can be described by: [(0 + 1)*000(0 + 1)*]’ More complicated expression if complementation not used: ( )*( )

23
23 Example Example: Let M be an FSM whose input/output alphabet is {0,1}. Assume the machine has a designated starting state. Let z 1 z 2 …z n denote the output sequence produced by M in response to input sequence x 1 x 2 …x n. Define a set S M, which consists of all the strings w s.t. w = z 1 x 1 z 2 x 2 …z n x n for any x 1 x 2 …x n in (0 + 1)*. Prove that S M is regular. Given the state diagram of M: replace each directed arc with two directed arcs and a new state, as shown in the figure Retain the original starting state: designate all the original states as accepting states The resulting nondeterministic graph recognizes S M : thus S M is regular

24
24 Example (Contd.) Example (contd.): Derive S N for machine N shown below

25
25 Two-way Recognizers Two-way recognizer (or two-way machine): consists of a finite-state control coupled through a head to a tape Initially: the finite-state control is in its designated starting state, with its head scanning the leftmost square of the tape The machine then proceeds to read the symbols of the tape: one at a time In each cycle of computation: the machine examines the symbol currently scanned by the head, shifts the head one square to the right or left, and then enters a new (not necessarily distinct) state If the machine eventually moves off the tape on the right end entering an accepting state: the tape is accepted by the machine A machine can reject a tape: either by moving off its right end while entering a rejecting state or by looping within the tape Null string can be represented either by: the absence of an input tape or by a completely blank tape A machine accepts if and only if: its starting state is an accepting state

26
26 Example Example: A two-way machine recognizing set 100*

27
27 Convenience of Using Two-way Machines Two-way machines are as powerful as one-way machines w.r.t the class of tapes they can recognize However, for some computations: it is convenient to use two-way machines since they may require fewer states Example: Consider the two-way machine shown in the table, which accepts a tape if and only if it contains at least three 1’s and at least two 0’s The minimal one-way machine that is equivalent to the two-way machine has 12 states: since it must examine the tapes for the appropriate number of 0’s and 1’s simultaneously

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google