Upload
chaitanya-hebbal
View
224
Download
0
Embed Size (px)
Citation preview
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 1/53
Push Down Automata
• Introduction
• Schematic representation of Pushdown automata andits 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
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 2/53
• Graphical representaions of PDA
• Construction of PDA for CFL
•
Equivalence of PDA’s and CFG’s • Deterministic Push Down Automata
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 3/53
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 withstack as storage Mechanism is called Push
Automata
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 4/53
Formal Defination
A Non deterministic PDA(NPDA) is defined as a 7-tupleM=(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
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 5/53
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 6/53
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 andthe reading and writing is done with usual stack operation
i.e., LIFO and decided by the Transition function
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 7/53
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 andZ 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 samestate and stack is operated with usual stack
operation
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 8/53
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 them/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
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 9/53
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.
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 10/53
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 ispushed onto the stack .
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 11/53
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
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 12/53
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 astriplet (q,w,u)
where q -> current state
w -> string to be processedu -> current content of stack
Note: |- is used to indicate the Different ID’s
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 13/53
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 isdescribed as (q0,aw,bZ) |- (p, w, abZ)
if transition function is defined as
δ(q0,a,b) = (p, ε) then next configuration of PDA isdescribed as (q0,aw,bZ) |- (p, w, Z)
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 14/53
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)
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 15/53
Language Acceptance of a PDA:
1. Language acceptance by final state:
Here PDA has to process entire string w andfinally 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 Г*
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 16/53
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.
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 17/53
Graphical Representations of PDA
PDA’s 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 isan arrow labeled a,x/α from state q to state p.
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 18/53
• Construction of PDA for CFL
L={anbn | n>=0}
L={a
n
b
2n
| 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}
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 19/53
Equivalence of CFG and PDA’s
We Know that the language accepted by
PDA is Context free language and these
languages are represented by context-free-
grammar. From every context-free-grammar
we can construct PDA and vice versa. Let us
discuss the construction of PDA fromContext-free-grammar
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 20/53
• Construction of PDA from Context-free-
grammar
1 By GNF notation of CFG
2 By Empty stack( Without GNF notation)
f
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 21/53
1.By GNF Notation of CFG:
Step1 : Convert the grammar into GNFStep2 : 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,ε)
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 22/53
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
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 23/53
• 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)
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 24/53
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,ε)
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 25/53
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
qЄQ, aЄ∑ and AЄГ
2.δ(q,Є,A) is defined then δ(q,a,A) is
undefined for all a Є ∑
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 26/53
Properties of Context free
Languages
•Closure Properties
•
Pumping Lemma
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 27/53
Closure properties of CFG’s
We know that the family of regularlanguages are closed under all the set
operations namely, Union, concatenation,Kleen star, intersection and complement.Similarly, The Family of context free languagesare closed under Union, concatenation, Kleenstar only and not closed under Intersection.Let discuss these properties one by one
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 28/53
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 allof G1’s non terminals with 1 and subscript all of
G2’s non terminal with 2
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 29/53
Now we combine the two grammars into one grammar thatwill generate the union of two languages. To do this, weadd one new non terminal S and two new productions andis as follows
S->S1 | S2
Here S is starting non terminal for the new UNIONgrammar and can replaced by either S1 ( Start Symbol of G1) or S2 ( start symbol of G2), there by generating either astring from L1 or from L2. Since the non terminals of thetwo original languages are different in the derivation If wereplace S by S1 we use only the production of grammar G1and 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.
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 30/53
2 Theorem : If L1 and L2 are context free languages , thenL1L2 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 ruleto the combined grammar
S->S1S2
The resulting grammar G, in the derivationgenerates first strings of L1 by start symbol S1 and thenit generates strings of L2. The resulting strings arenothing but the concatenation of strings of L1 and L2.Hence the argument is proved
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 31/53
3 Theorem : If L is a context free language, then L*is also context free language.
Proof: Subscript all the non terminals of theGrammar for L with a 1. Then add a new start
symbol S and the new rule as followsS->S1 S |Є
Here the rule S->S1 S is used to generate thestrings of several instances and the rule S->|Є isused to terminate the strings generated from S1.The resulting strings are nothing the star closureof L. Hence the argument is proved.
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 32/53
4 Theorem: If L1 and L2 are context free
languages then L1ПL2 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
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 33/53
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 |Є
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 34/53
The strings in L1 contains the same number of a’s and b’s, while the strings in L2 contain the samenumber b’s and c’s. The intersections of L1 and L2contains the strings of both in L1 and L2. i.e samenumber of a’s, b’s and c’s
Thus L1ПL2= {an bn cn | n >=0}
Using pumping lemma the above language can
proved it is not Context free language. So, theclass of context free languages are not closedunder Intersection.
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 35/53
5 Theorem: If L is a context free language thenComplement of L is not context free language.
Proof: From set Identity. Complement can be
expressed as followsL1ПL2 = Complement
(Complement(L1)UComplent(L2))
we know that Context free languages are notclosed under Intersection. Hence context freelanguages are not closed Complement
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 36/53
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……
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 37/53
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 isbounded say K and number of variables are finite
, the length of the derivations of any wЄL must be
at least |w|/k. Therefore since L is infinite , thereexists arbitrarily long derivation and derivation
tree of arbitrary height.
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 38/53
Since the number of variables are finite for G theremust be some variable that repeats in thederivation 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=>xwe can generate all the strings uvixyiz, i=0,1,2..of the grammar and are in L
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 39/53
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 theargument.
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 40/53
Turing Machine(TM)•Introduction
•Schematic representation of Turing Machineand 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
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 41/53
Turing Machines
(At last!)
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 42/53
Introduction
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 43/53
Turing Machine is modified version of PDA and itis 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 (type-2)and context sensitive languages(type-1)). Apart
from these languages it can also accept Type-0languages generated by unrestricted grammar.Hence it is called as generalized finite automata.
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 44/53
Schematic representation of Turing Machine and itsworking
It is generalized finite automata and has three maincomponents, namely Tape, Read-write head andcontrol unit
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 45/53
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 fromleft to right. Before and after the strings the
blank character are stored
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 46/53
2. Read-write Head
It is a reading / writing mechanism that canread and write a symbol from where it is
pointing. The reading/writing and movementof read-write head is controlled by control unit
3. Control unit: This component drives theworking of Turing Machine. It controlsreading/writing operations and movement of read-write head.
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 47/53
At any given instance of time TM is assumed to be in somestate(Initially start state) and the read/write head ispointing to some symbol in the tape, the next state, read /write operations and movement of read/write head isdecided by the transition function δ and is as follows:
Next Symbol to be
state replaced in tape
↓ ↓
δ(q, a) = (p, b, R/L)
↑ ↑ ↑Current I/P symbol Movement of head (R-right, L-left)
state pointed by R/W head
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 48/53
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 CharacterF =Set of final states and is subset of Q
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 49/53
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 Machineand formally it is defined as follows
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 50/53
An ID of Turing machine is a string in αqβ, whereq is the current state, αβ is string made from Tapesymbols. The read/write head is pointing to thefirst character of the string β
The initial ID is denoted by q0αβ where q0 is thestart state and the read/write is pointing to thefirst character of α from left
The final ID is denoted as αβqB where qЄF is thefinal state and the read/write head is pointing tothe blank character denoted by B
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 51/53
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
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 52/53
If the Transition function δ(q,a5)=(p,c5,L) then
Next ID is defined as follows
a1a2a3a4qa5a6a7a8a9 |- a1a2a3pa4 c 5a6a7a8a9
8/3/2019 Push Down Automata New
http://slidepdf.com/reader/full/push-down-automata-new 53/53
Language acceptance of TM:
After processing the entire string the machinehas to stay in final state and read/write head
should point to blank Character. Formally it isdefined 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 |- α1pα2, where wЄ∑*, pЄFand α1,α2 Є Г* }