580 likes | 591 Views
Theory of Computation. Transition Graph. Definition: A Transition graph (TG), is a collection of the following: Finite number of states, at least one of which is start state and some (maybe none) final states. Finite set of input letters ( Σ ) from which input strings are formed.
E N D
Transition Graph Definition: A Transition graph (TG), is a collection of the following: Finite number of states, at least one of which is start state and some (maybe none) final states. Finite set of input letters (Σ) from which input strings are formed. Finite set of transitions that show how to go from one state to another based on reading specified substrings of input letters, possibly even the null string: Λ.
Example Consider the Language L , defined over Σ = {a, b} of all strings including Λ. The language L may be accepted by the following TG The language L may also be accepted by the following TG a,b a,b + Λ -
Example Continued … TG1 TG2 a,b a,b + a,b
Example Consider the language L of strings, defined over Σ={a, b},starting with b. The language L may be expressed by RE b(a + b)* , may be accepted by the following TG –– + a,b b
Example Consider the Language L of strings, defined over Σ = {a, b}, containing double a. The language L may be expressed by the following regular expression (a+b)* (aa) (a+b)*. This language may be accepted by the following TG
Example Continued … b,a b,a aa 1- 2+
Example Consider the language L of strings, defined over Σ={a, b},having double a or double b. The language L can be expressed by RE (a+b)* (aa + bb) (a+b)*. The above language may also be expressed by the following TGs.
Example continued … x a a a,b a,b –– + b b y
OR a,b a,b aa,bb - +
Generalized Transition Graphs A generalized transition graph (GTG) is a collection of three things Finite number of states, at least one of which is start state and some (maybe none) final states. Finite set of input letters (Σ) from which input strings are formed. Directed edges connecting some pair of states labeled with regular expression.
Example Consider the language L of strings, defined over Σ={a,b}, containing double a or double b. The language L can be expressed by the following regular expression (a+b)* (aa + bb) (a+b)* The language L may be accepted by the following GTG.
Example continued … a+b a+b aa+bb - +
Example Consider the language L of strings, defined over Σ = {a, b}, beginning and ending in different letters. The language L may be expressed by RE a(a + b)*b + b(a + b)*a The language L may be accepted by the following GTG
Example Continued … + b(a+b)*a - a( a+b)* b + The language L may be accepted by the following GTG as well
Example Continued … b(a+b)*a + a( a+b)* b - +
Example Consider the language L of strings, defined over Σ={a, b},having triple a or triple b. The language L may be expressed by RE (a+b)* (aaa + bbb) (a+b)* This language may be accepted by the following GTG
Example Continued … a+b a+b aaa+bbb - + OR (a+b)*(aaa+bbb)(a+b)* - +
Kleene’s Theorem If a language is expressed by FA or TG or RE then it can also be expressed by other two as well. the theorem is proved by proving the following three parts
Kleene’s Theorem continued … Kleene’s Theorem Part I If a language is accepted by an FA then it can be accepted by a TG as well. Kleene’s Theorem Part II If a language is accepted by a TG then it can be expressed by an RE as well. Kleene’s Theorem Part III If a language is expressed by an RE then it can also be accepted by an FA.
Kleene’s Theorem continued … Proof(Kleene’s Theorem Part I) Since every FA can be considered to be a TG, therefore there is nothing to prove.
Kleene’s Theorem continued … Proof(Kleene’s Theorem Part II) To prove part II of the theorem, an algorithm consisting of different steps is explained showing how a RE can be obtained corresponding to the given TG.
Kleene’s Theorem part II continued … Step 1If a TG has more than one start state, then introduce a new start state connecting the new state to the old start states by the transitions labeled by Λ and make the old start states the non-start states.
Example b b 3+ 1- aa a a 4+ 2- bb
Example Continued ... b b 3+ 1 Λ aa a - Λ a 4+ 2 bb
Kleene’s Theorem part II continued … Step 2: If a TG has more than one final state, then introduce a new final state, connecting the old final states to the new final state by the transitions labeled by Λ.
Example b b 3+ 1 Λ aa a - a Λ 4+ 2 bb
Example continued … b b 3 1 Λ Λ aa a - + Λ a Λ 4 2 bb
Kleene’s Theorem part II continued … Step 3: If a state has more than one incoming transition edge labeled by the corresponding REs, from the same state (including the possibility of loops at a state), then replace all these transition edges with a single transition edge labeled by the sum of corresponding REs.
Example The above TG can be reduced to r3 r1 5 …. …. 4 r2 r4 r3+r4 r1+r2 5 …. …. 4
Note The step 3 can be generalized to any finite number of transitions as shown below The above TG can be reduced to … r1+r2 + +rn 5 …. …. r1 r2 …. …. 5 …. rn
Kleene’s Theorem part II continued … Step 4 (bypass and state elimination) If three states in a TG are connected in a sequence then eliminate the middle state and connect the first state with the third by a single transition (including loops) labeled by the RE, which is the concatenation of corresponding two REs in the existing sequence.
Example r3 r2 r4 5 …. 6 …. 4 To eliminate state 5 the above can be reduced to r2r3*r4 …. 6 …. 4
Example Consider the part of a TG, containing a circuit at a state, as shown below To eliminate state 3 the above TG can be reduced to 4 3 r2 r3 r1 …. 2 …. r4 r4r2*r3 r1r2*r3 …. 4 …. 2
Example Consider a part of the following TG To eliminate state 3 the above TG can be reduced to 4 3 2 r2 r9 r7 r3 r1 r5 …. …. r8 r4 r6
Example continued ... To eliminate state 4 the above TG can be reduced to 2 4 2 r1 +r3 r5*r4 r9 +r8r5*r7 r2 +r3 r5*r7 …. …. r6 +r8r5*r4 (r1 +r3 r5*r4 )+(r2 +r3 r5*r7 )(r9 +r8 r5*r7 )*(r6 +r8 r5*r4 ) …. ….
Example Consider the following TG To have single final state, the above TG can be reduced to the following aa,b 2+ aaa ab,ba - 1 bba 3+
Example continued … To eliminate states 2 and 3, the above TG can be reduced to the following aa+b 2 Λ aaa ab+ba - 1 4+ bba Λ 3 aa+b ab+ba aaa Λ+bbaΛ - 1 4+
Example continued … To eliminate state 1 the above TG can be reduced to the following Hence the required RE is (ab+ba)(aa+b)*(aaa+bba) (ab+ba)(aa+b)*(aaa+bba) - +
Kleene’s Theorem Part III Continued … If r1 and r2 are regular expressions then their sum, concatenation and closure are also regular expressions
Kleene’s Theorem Part III Continued … Method1 (Union of two FAs):Using the FAs corresponding to r1 and r2an FA can be built, corresponding to r1+r2. This method can be developed considering the following examples
Example Let r1=(a+b)*b defines L1 and the FA1 is and r2 = (a+b )*aa(a+b )* defines L2and FA2 be a b b X1– X2+ a a,b b a a y2 y1- y3+ b
Sum of two FAs Continued … Let FA3 be an FA corresponding to r1+ r2, then the initial state ofFA3 must correspond to the initial state of FA1 or the initial state of FA2. Since the language corresponding to r1+r2 is the union of corresponding languages L1 and L2, consists of the strings belonging to L1or L2 or both, therefore, a final state ofFA3 must correspond to a final state of FA1 or FA2or both.
Example continued … a,b b a a y2 y1– y3+ a b b b X1– X2+ a
Example continued … RE corresponding to the above FA may be r1+r2 = (a+b)*b + (a+b)*aa(a+b)* Z2 a a b a b a Z5 + Z1- b Z4 + a b b Z3+
Kleene’s Theorem Part III Continued … Method2 (Concatenation of two FAs): Using the FAs corresponding to r1 and r2, an FA can be built, corresponding to r1r2. This method can be developed considering the following examples
Example Let r1=(a+b)*b defines L1 and FA1 is and r2 = (a+b )*aa (a+b )* defines L2and FA2is a b b X1– X2+ a a,b b a a y2 y1- y3+ b
Concatenation of two FAs Cont… Let FA3 be an FA corresponding to r1r2, then: initial state of FA3 =initial state of FA1 final state of FA3 =final state of FA2 if final state of FA1 is entered, then initial state of FA2 will also be included.
Example continued … a,b b a a y2 y1- y3+ a b b b X1– X2+ a