Sunteți pe pagina 1din 53

Push Down Automata

Introduction Schematic representation of Pushdown automata and its working Formal definition of PDA > variations of Transition functions and their meaning > Move of a PDA Instantaneous Description of PDA Language acceptance of PDA > Language Acceptance from the final state > Language Acceptance from the empty stack

Graphical representaions of PDA Construction of PDA for CFL Equivalence of PDAs and CFGs Deterministic Push Down Automata

Introduction
A simple Automata can accept only Regular languages and they can cannot accept context free languages. This is because FA have limited memory and recognition of CFL requires unbounded memory. In order to have this ability for FA, extra storage mechanism is provided and is called as STACK. So, A FA with stack as storage Mechanism is called Push Automata

Formal Defination
A Non deterministic PDA(NPDA) is defined as a 7-tuple M=(Q,,,,q0,Z,F) where Q= Finite set of internal states = Input symbols called input Alphabet = stack symbols called as stack Alphabet = A transition function q0= A start state Z = A symbol on the stack indicates bottom of the stack F= A finite set of final states

PDA consists of 4 components namely, Input buffer, Stack, control Unit and output 1.Input Buffer : This holds the string to be processed. It is divided into n number of cells and each cell is capable of holding a single character. There is a reading mechanism and individual characters are read from left to right, one character at a time 2.Stack : It is an extra storage mechanism which is divided into n number cells and each cell is capable of holding a single character. The character Z is used to indicate the bottom and the reading and writing is done with usual stack operation i.e., LIFO and decided by the Transition function

Control Unit : This is used to control the Overall operation of PDA. Initially it is assumed to be in start state q0, input pointer is pointing to the first character a of the input string to be processed and Z is the symbol on top of the stack the next state and STACK operation is decided by the transition function and we say the PDA has taken a move. When this happens state is changed or it can stay in the same state and stack is operated with usual stack operation

It means that the transition function takes 3 arguments and is defined as follows : Q X ( U {}) X = Q X * i.e., It takes 3 arguments namely current state of the m/c, current input symbol and the current symbol on the top of the stack and the result of the transition function is a set pairs (Q,x) where Q is the next state and x is string that decides the stack operation and they are as follows

1. (q0,a,Z)=(p, aZ) It means in state q0 ,on i/p symbol a and when top of stack is Z, the PDA enters into state p and the i/p symbol a is pushed on to stack over Z. 2. (q0,a,bZ)=(p,) It means in state q0 ,on i/p symbol a and when top of stack is b, the PDA enters into state p and the stack top symbol b is popped from the stack and Z is now on top.

3. (q0,a,bZ)=(p,r) It means in state q0 ,on i/p symbol a and when top of stack is b, the PDA enters into state p and the stack top symbol b is replaced by r and r is now on top of the stack. 4. (q0, , )=(q0,Z) It means in state q0 ,on empty i/p symbol and when stack is empty , the PDA enters into state q0 and the symbol Z is pushed onto the stack .

5. (q0, ,Z )=(q0, ) It means in state q0 ,on empty i/p symbol and when top of stack is Z , the PDA enters into state q0 and the symbol Z is popped from the stack . 4. OUTPUT : whenever input string is exhausted and PDA stays in the final state or stack is empty the string is accepted otherwise it is rejected

Instantaneous Description (ID) of PDA While processing the string w the current and successive configurations are described by the term Instantaneous Description ID which is defined as triplet (q,w,u) where q -> current state w -> string to be processed u -> current content of stack Note: |- is used to indicate the Different IDs

Example: Let the current configuration of PDA be (q0,aw,bZ) if transition function is defined as (q0,a,b) = (p, ab) then next configuration of PDA is described as (q0,aw,bZ) |- (p, w, abZ) if transition function is defined as (q0,a,b) = (p, ) then next configuration of PDA is described as (q0,aw,bZ) |- (p, w, Z)

if transition function is defined as (q0,a,b) = (p, c) then next configuration of PDA is described as (q0,aw,bZ) |- (p, w, cZ)

Language Acceptance of a PDA: 1. Language acceptance by final state: Here PDA has to process entire string w and finally it has to stay in a state that belongs to final state. At this moment of time stack contents are irrelevant. This is defined as follows L(M)={ w * : (q0,w,z) |- (p, ,u) } where p is in F and u is *

2. Language acceptance by empty stack: Here PDA has to process entire string w and finally it has to empty the stack. This moment of time current state is irrelevant. This is defined as follows L(M)={ w * : (q0,w,z) |- (p, , ) } where p is current state which is irrelevant.

Graphical Representations of PDA


PDAs are represented by Transition diagram and is as follows : 1. The nodes corresponds to the state of the PDA 2. An arrow labeled start indicates the start state and doubly circled states are final states 3. If (q,a,x) = (p, ) is a transition function then there is an arrow labeled a,x/ from state q to state p.

Construction of PDA for CFL L={anbn | n>=0} L={anb2n | n>=0} L={w | w (a+b)* and na(w)=nb(w) } L={w | w (a+b)* and na(w)>nb(w) } L={w | w (a+b)* and na(w)<nb(w) } L={anbm c(n+m) | n>=0} L={a2nbn | n>=0}

Equivalence of CFG and PDAs We Know that the language accepted by PDA is Context free language and these languages are represented by context-freegrammar. From every context-free-grammar we can construct PDA and vice versa. Let us discuss the construction of PDA from Context-free-grammar

Construction of PDA from Context-freegrammar 1 By GNF notation of CFG 2 By Empty stack( Without GNF notation)

1.By GNF Notation of CFG:


Step1 : Convert the grammar into GNF Step2 : Let q0 be the start state and Z be the initial symbol on the stack. Without consuming any Input, push the start symbol onto the stack and change the state to q1. The transition is as follows: (q0,,Z)= (q1,SZ) Step3 : For each production of the form a) A-> a introduce the transition (q1,a,A)= (q1,) b) A-> a introduce the transition (q1,a,A)= (q1,)

Step 4 Finally, in state q1, without consuming the input, change the state to qf which is an accepting state. The transition as follows (q0,,Z)= (qf,Z) Example : S->aABC A-> aB | a B-> bA | b C-> a

Its PDA construction is as follows (q0,,Z)= (q1,SZ) S->aABC (q1,a, S)= (q1,ABC) A-> aB | a (q1,a,A)= (q1,B) (q1,a,A)= (q1,) B-> bA | b (q1,b,B)= (q1,A) (q1,b,B)= (q1,) C-> a (q1,a,C)= (q1,) (q1,,Z)= (qf, Z)

2 By Empty stack ( Without GNF notation)


Let G=(V,T,S,P) be a CFG then PDA M that accepts L(G) by empty as follows M =({q),T, VUT, , q, S) where transition function is defined as follows 1.For each variable A (q,,A) = (q,) such that A-> is Production in P
2. For each terminal a , (q, a, a) = (q,)

Deterministic Push Down Automata Definition : Let M=(Q,,,,q0,Z,F) be a PDA. It is said to be deterministic if it satisfies the following conditions 1.(q,a,A) is unquily defined for each qQ, a and A 2.(q,,A) is defined then (q,a,A) is undefined for all a

Properties of Context free Languages


Closure Properties Pumping Lemma

Closure properties of CFGs We know that the family of regular languages are closed under all the set operations namely, Union, concatenation, Kleen star, intersection and complement. Similarly, The Family of context free languages are closed under Union, concatenation, Kleen star only and not closed under Intersection. Let discuss these properties one by one

1 Theorem: If L1 and L2 are context free languages then L1UL2 is a context free language Proof: If L1 and L2 are context free languages, then each of them has a context free grammar Let G1 and G2 are the grammars for L1 and L2 respectively. Proof requires that grammars have no Non terminal common. So, subscript all of G1s non terminals with 1 and subscript all of G2s non terminal with 2

Now we combine the two grammars into one grammar that will generate the union of two languages. To do this, we add one new non terminal S and two new productions and is as follows S->S1 | S2 Here S is starting non terminal for the new UNION grammar and can replaced by either S1 ( Start Symbol of G1) or S2 ( start symbol of G2), there by generating either a string from L1 or from L2. Since the non terminals of the two original languages are different in the derivation If we replace S by S1 we use only the production of grammar G1 and if we replace S by S2 we use only the production of grammar G2 . The resulting grammar G is usually a Union of G1 and G2. Hence the argument is proved.

2 Theorem : If L1 and L2 are context free languages , then L1L2 is a context free languages Proof: Here also we subscript all of the non terminals of G1 with a 1 and all of the non terminals of G2 with a 2. Then we add a new non terminal S and one new rule to the combined grammar S->S1S2 The resulting grammar G, in the derivation generates first strings of L1 by start symbol S1 and then it generates strings of L2. The resulting strings are nothing but the concatenation of strings of L1 and L2. Hence the argument is proved

3 Theorem : If L is a context free language, then L* is also context free language. Proof: Subscript all the non terminals of the Grammar for L with a 1. Then add a new start symbol S and the new rule as follows S->S1 S | Here the rule S->S1 S is used to generate the strings of several instances and the rule S->| is used to terminate the strings generated from S1. The resulting strings are nothing the star closure of L. Hence the argument is proved.

4 Theorem: If L1 and L2 are context free languages then L1L2 is not context free language. Proof: The two context free languages are not closed under Intersection is proved by considering the examples Let L1= {an bn cm | n, m>=0} is Context Free language

Also, Let L2= {am bn cn | n, m>=0} is Context Free language Since, both are context free languages there exits a Context free grammar and is as follows G1 : S->AB G2: S->AB A->aAb | A->aA | B-> cB | B->bBc |

The strings in L1 contains the same number of as and bs, while the strings in L2 contain the same number bs and cs. The intersections of L1 and L2 contains the strings of both in L1 and L2. i.e same number of as, bs and cs Thus L1L2= {an bn cn | n >=0} Using pumping lemma the above language can proved it is not Context free language. So, the class of context free languages are not closed under Intersection.

5 Theorem: If L is a context free language then Complement of L is not context free language. Proof: From set Identity. Complement can be expressed as follows L1L2 = Complement (Complement(L1)UComplent(L2)) we know that Context free languages are not closed under Intersection. Hence context free languages are not closed Complement

Pumping Lemma for context free languages


Statement : Let L be an infinite context free language. Then there exists some positive integer m such that any w L with |w|>=m can be decomposed as w=uvxyz with |vxy|<=m and |vy|>=1 Such that uvixyiZ L for all i=1,2,3

Proof: consider the languages L-{} and assume that we have grammar G for it without unit productions and -productions Since the length of the RHS of a productions is bounded say K and number of variables are finite , the length of the derivations of any wL must be at least |w|/k. Therefore since L is infinite , there exists arbitrarily long derivation and derivation tree of arbitrary height.

Since the number of variables are finite for G there must be some variable that repeats in the derivation path and is shown in fig so the derivation is as follows S=>uAz=>uvAyz=>uvxyz where u,v,x,y and z are all strings of terminals. From the above we see that A=>vAy and A=>x we can generate all the strings uvixyiz, i=0,1,2.. of the grammar and are in L

In the derivation A=>vAy and A=>x no variable repeats and no unit production and production v and y cannot be empty strings because |vy|>=1. hence completes the argument.

Turing Machine(TM)
Introduction Schematic representation of Turing Machine and its working Formal definition of Turing Machine > Transition function Move of a TM Instantaneous Description of TM Language acceptance of TM Representation of TM Examples on TM

Turing Machines
(At last!)

Introduction

Turing Machine is modified version of PDA and it is more powerful than PDA. Instead of stack it uses the Tape to store the input symbols. Turing Machine is going to accept all types of languages ( regular (Type-3), context free (type2)and context sensitive languages(type-1)). Apart from these languages it can also accept Type-0 languages generated by unrestricted grammar. Hence it is called as generalized finite automata.

Schematic representation of Turing Machine and its working

It is generalized finite automata and has three main components, namely Tape, Read-write head and control unit

1. Tape : It is storage device of infinite length and is divided into n number cells. Each cell is capable of holding a single character. The string to be processed is stored and read from left to right. Before and after the strings the blank character are stored

2. Read-write Head It is a reading / writing mechanism that can read and write a symbol from where it is pointing. The reading/writing and movement of read-write head is controlled by control unit 3. Control unit: This component drives the working of Turing Machine. It controls reading/writing operations and movement of read-write head.

At any given instance of time TM is assumed to be in some state(Initially start state) and the read/write head is pointing to some symbol in the tape, the next state, read / write operations and movement of read/write head is decided by the transition function and is as follows:
Next state Symbol to be replaced in tape

(q,
Current state

a) = (p,

b,

R/L)
Movement of head (R-right, L-left)

I/P symbol pointed by R/W head

Formal Definition: The Turing M = (Q,,,,q0,B,F) where Q = Finite set of internal states = Finite set of input alphabets = Finite set of Tape alphabets = Transition Function ( :(Q,)Q x x (R,L) q0 = Start state belongs to Q B = A special symbol indicating Blank Character F =Set of final states and is subset of Q

Instantaneous Description (ID) of TM : While processing the string W the current and successive configuration of the TM is described by the term Instantaneous Description (ID). Here it is defined on the whole string and (not on the string that is to processed) the current state of the Machine and formally it is defined as follows

An ID of Turing machine is a string in q, where q is the current state, is string made from Tape symbols. The read/write head is pointing to the first character of the string The initial ID is denoted by q0 where q0 is the start state and the read/write is pointing to the first character of from left The final ID is denoted as qB where qF is the final state and the read/write head is pointing to the blank character denoted by B

Example : If the Initial ID of TM is Say BBBBa1a2a3a4qa5a6a7a8a9BBBB. If the Transition function (q,a5)=(p,b5,R) then Next ID is defined as follows a1a2a3a4qa5a6a7a8a9 |- a1a2a3a4b5pa6a7a8a9

If the Transition function (q,a5)=(p,c5,L) then Next ID is defined as follows a1a2a3a4qa5a6a7a8a9 |- a1a2a3pa4 c 5a6a7a8a9

Language acceptance of TM: After processing the entire string the machine has to stay in final state and read/write head should point to blank Character. Formally it is defined as follows Let M = (Q,,,,q0,B,F) be the Turing Machine. The language accepted by M is defined as L(M) = {W |q0 w |- 1p2, where w*, pF and 1,2 * }

S-ar putea să vă placă și