Presentation is loading. Please wait.

Presentation is loading. Please wait.

Theorem 1 Context-free languages are closed under union, concatenation and Kleene closure. Proof Let L1= L(G1) and L2 = L(G2) be CFL’s, where G1 = (V1,

Similar presentations


Presentation on theme: "Theorem 1 Context-free languages are closed under union, concatenation and Kleene closure. Proof Let L1= L(G1) and L2 = L(G2) be CFL’s, where G1 = (V1,"— Presentation transcript:

1 Theorem 1 Context-free languages are closed under union, concatenation and Kleene closure. Proof Let L1= L(G1) and L2 = L(G2) be CFL’s, where G1 = (V1, T1, P1, S 1 ) and G2 = (V2, T2, P2, S 2 ) 6.2 Closure Properties of CFL's 1.For union, L1  L2, Construct G = (V, T, P, S), where P = P1  P2  {S  S 1, S  S 2 }, V = V1  V2  {S}

2 2.For concatenation, L1 . L2, Construct G = (V, T, P, S), where P = P1  P2  {S  S 1 S 2 }, V = V1  V2  {S} 3.For Kleene closure, L 1 *, Construct G = (V, T, P, S), where P = P 1  {S  S 1 S, S  }, V = V 1  {S}

3 Theorem 2 Context-free languages are closed under substitution. Proof Let L be a CFL, L   *, and for each a in  let L a be a CFL. Let L = L(G), G = (V, T, P, S), and for each a in  let L a = L(G a ), where G a =(V a, T a, P a, S a ). Assume that V  V a = , for all a in . And V a  V b = , for all a≠ b in . Construct G’=(V’, T’, P’, S), where V’ =  a in  V a  V, T’ =  a in  T a, P’ =  a in  P a  {A  f(  ) | A  is in P, and f(a) = S a for each a in  }

4 Example 6 L = {0 n 1 m | n ≠m } is a CFL. Let L = L(G), G = ({S, A, B}, {0, 1}, P, S), where P contains the following production rules: S  0S1 | 0A | 1B, A  0A | , B  1B | . Let L 0 = L(G 0 ), G = ({S 0 }, { (, ), [, ]}, P, S 0 ), where P contains the following production rules: S 0  S 0 S 0 | [S 0 ] | (S 0 ) | [] | () L 0 can be defined recursively as follows: 1.() and [] are in L 0. 2.If R and S are in L 0, then (R), [R], and RS are in L 0. And L 0 contains only the strings described in 1 and 2.

5 Let L 1 = L(G 1 ), G = ({S 1, C, D}, {c, d}, P, S 1 ), where P contains the following production rules: S 1  dC | cD C  dCC | cS | c D  cDD | dS | d Let L 1 consists of strings over {c, d} with the property that the number of c’s is equal to the number of d’s in the strings. If f is the substitution f(0) = L 0 and f(1) = L 1, then f(L) is generated by the grammar S  S 0 SS 1 | S 0 A | S 1 B, A  S 0 A | , B  S 1 B | . S 0  S 0 S 0 | [S 0 ] | (S 0 ) | [] | () S 1  dC | cD C  dCC | cS | c D  cDD | dS | d

6 Corollary Context-free languages are closed under homomorphism. Proof homomorphism is a special case of substitution.

7 Theorem 3 Context-free languages are closed under inverse homomorphism. Proof Let h :  Δ* be a homomorphism and L be a CFL.. Let L = L(M), PDA M = (Q, Δ, Γ, , q0, Z0, F). An idea of constructing a PDA M’ to accept h -1 (L) is as follows: What M’ does is the following: On reading an input symbol a, M’ generates the string h(a) and stores h(a) in a buffer, then simulates M on h(a). Only when the buffer is empty, M’ is allowed to read in next input. And the buffer holds only a suffix of h(a) for some input a at all time. M’ accepts an input w if the buffer is empty and M enters a final state.

8 Q’ = { [q, x] | q  Q and x is a suffix of some h(a) for a  .} Construct a PDA M’ = (Q’, , Γ,  ’, [q0,  ], Z0, F  {  }) to accept h -1 (L) as follows:  ’ is defined as follows: 1.  ’ ([q, x], , Y) contains all ([p, x], γ) if  (q, , Y) contains (p, γ). The move M’ simulates  -move of M ignoring the buffer. 2.  ’ ([q, ax], , Y) contains all ([p, x], γ) if  (q, a, Y) contains (p, γ). M’ simulates moves of M on reading a  Δ, then removes a from the front of the buffer. 3.  ’ ([q,  ], a, Y) contains all ([q, h(a)], γ) for all a   and Y  Γ. When the buffer is empty, M’ reads an input a and loads the buffer with h(a).

9 (q, h(a),  ) (p, ,  )  ([q, ,], a,  ) (q, h(a),  ) ([p,  ], ,  ). If M accepts h(w), i.e., (q0, h(w), Z0) (p, ,  ) for some p in F and  in Γ*, then ([q0,  ], w, Z0) ([p,  ], ,  ). So M’ accepts w. We have that h -1 (L(M))  L(M’)

10 If M’ accepts w = a 1 a 2 … a n. ([q0,  ], a 1 a 2 … a n, Z0) ([p1,  ], a 2 … a n,  1), ([p1, h(a 1 )], a 2 a 3 … a n,  1), ([p2,  ], a 2 a 3 … a n,  2), ([p2, h(a 2 )], a 3 … a n,  2), ([p n,  ], ,  n+1 ), where p n is a final state.

11 For all i, we have (p i, h(a i ),  i ) (p i+1, ,  i+1 ). So, for these moves altogether we have (q 0, h(a 1 a 2 …a n ), Z 0 ) (p n, ,  n+1 ). Hence, h(a 1 a 2 …a n ) is in L(M). And L(M’)  h -1 (L(M)}. End of Theorem 3.

12 Theorem 4 Context-free languages are not closed under intersection. Proof L1 = {0 n 1 n 0 m | n, m = 0, 1, 2, …} and L2 = {0 n 1 m 0 m | n, m = 0, 1, 2, …} are CFL’s. L1  L2 = {0 n 1 n 0 n | n = 0, 1, 2, …} is not CFL.

13 Corollary Context-free languages are not closed under complementation. L1  L2 = (L1 c  L2 c ) c, where c stands for complement. If CFL’s are closed under complement, then CFL’s are closed under intersection.

14 Theorem 5 The intersection of a context-free language and a regular language is context-free. Proof Let L be a CFL, and let R be a regular language. L = L(M L ) for PDA M L = (Q L, , Γ,  L, q0, Z0, F L ), and R = L(M R ) for DFA M R = (Q R, ,  R, p0, F R ). Construct a PDA M’ for L  R by simulating M L and M R in parallel. M = (Q L  Q R, , Γ, , [p0, q0], Z0, F L  F R ), where  ([p, q], a, X) contains ([p’, q’],  ) if and only if  R (p, a) = p’,  L (q, a, X) contains (q’,  ).


Download ppt "Theorem 1 Context-free languages are closed under union, concatenation and Kleene closure. Proof Let L1= L(G1) and L2 = L(G2) be CFL’s, where G1 = (V1,"

Similar presentations


Ads by Google