pushdown automata
play

Pushdown Automata A pushdown automata (PDA) is essentially: - PDF document

Pushdown Automata A pushdown automata (PDA) is essentially: Pushdown Automata An NFA with a stack A move of a PDA will depend upon Current state of the machine Current symbol being read in Current symbol popped off the


  1. Pushdown Automata  A pushdown automata (PDA) is essentially: Pushdown Automata  An NFA with a stack  A “move” of a PDA will depend upon  Current state of the machine  Current symbol being read in  Current symbol popped off the top of the stack  With each “move”, the machine can  Move into a new state  Push symbols on to the stack Pushdown Automata Pushdown Automata  The stack  The stack has its own alphabet Input tape  Included in this alphabet is a special symbol used to indicate an empty stack. 1 2 ( z ) 3  Note that the basic PDA is non- 5 4 deterministic! State machine Stack Pushdown Automata Pushdown Automata  Let’s formalize this:  About this transition function δ :  A pushdown automata (PDA) is a 7-tuple:  During a move of a PDA:  M = (Q, Σ , Γ , δ , q 0 , z , F) where  At most one character is read from the input tape  Q = finite set of states  λ transitions are okay  Σ = tape alphabet  The topmost character is popped from the stack  Γ = stack alphabet (may have symbols in common w/ Σ )  The machine will move to a new state based on:  q 0 ∈ Q = start state  The character read from the tape  z ∈ Γ = initial stack symbol  The character popped off the stack  F ⊆ Q = set of accepting states  The current state of the machine  δ = transition function  0 or more symbols from the stack alphabet are pushed onto the stack. 1

  2. Pushdown Automata Pushdown Automata  Formally:  Example:  δ : Q x ( Σ ∪ { λ }) x Γ → (finite subsets of Q x Γ * )  δ (q, a, a ) = ( p, aa)  Meaning:  Domain:  When in state q,  Q = state  Reading in an a from the tape  ( Σ ∪ { λ }) = symbol read off tape  With an a popped off the stack  Γ = symbol popped off stack  The machine will  Range  Go into state p  Q = new state  Push the string “aa” onto the stack  Γ * = symbols pushed onto the stack Pushdown Automata Pushdown Automata  Configuration of a PDA  Move of a PDA:  Gives the current “configuration” of the  We can describe a single move of a PDA: machine  (q, x, α ) a (p, y, β )  If:  (p, x, α ) where  x = ay, α = γ X, β = YX  p is the current state  And  δ (q, x, γ ) includes (p, Y) or  x is a string indicating what remains to be read on the tape  δ (q, ε , γ ) includes (p, Y) and x = y.  α is the current contents of the stack. Pushdown Automata Pushdown Automata  Moves of a PDA  Strings accepted by a PDA by Final State  Start at (q 0 , x, z )  We can write:  Start state q 0  (q, x, α ) a * (p, y, β )  X on the input tape  If  Empty stack  You can get from one configuration to the other by  End with (q, λ , β ) applying 0 or more moves.  End in an accepting state (q ∈ F)  All characters of x have been read  Some string on the stack (doesn’t matter what). 2

  3. Pushdown Automata Pushdown Automata  The language accepted by a PDA  Strings accepted by a PDA (Final State)  Let M = (Q, Σ , Γ , q 0 , z, F, δ ) be a PDA  Let M = (Q, Σ , Γ , δ , q 0 , z , F) be a PDA  The language accepted by M by final state,  x is accepted by M if  Denoted L(M) is  (q 0 , x, z ) a * (q, λ , β )  The set of all strings x that are accepted by M by final state  Where  q ∈ F  β ∈ Γ * Pushdown Automata Pushdown Automata  Let’s look at an example:  Let’s look at an example:  L = { xcx r | x ∈ { a,b } * }  L = { xcx r | x ∈ { a,b } * }  Basic idea for building a PDA  The PDA will have 4 states  Read chars off the tape until you reach the ‘c’.  State 0 (initial) : reading before the ‘c’  As you read chars push them on the stack  State 1: read the ‘c’  After reading the c, match the chars read with the chars  State 2 :read after ‘c’, comparing chars popped off the stack until all chars are read  State 3: (accepting): move only after all chars  If at any point the char read does not match the char popped, the machine “crashes” read and stack empty Pushdown Automata PDA Example  Transition for abcba  Let’s look at an example:  (q 0 , abcba, Z) a (q 0 , bcba, a) // push a  L = { xcx r | x ∈ { a,b } * }  a (q 0 , cba, ba) // push b  a (q 1 , ba, ba) // goto 1 b, b / λ b, z / b z c, z / z λ , z / z a, a / λ  a (q 2 , ba, ba) // λ trans a, z / a z c, a / a λ , a / a  a (q 2 , a, a) // pop b c, b / b λ , b / b q 0 q 1 q 2 q 3  a (q 2 , λ , z) // pop a λ , z / z b, b / bb  a (q 3 , λ , z) // Accept! a, b / ab a, a / aa b, a / ba 3

  4. PDA Example Pushdown Automata  Transition for abcb  I bet you’re wondering if JFLAP can  (q 0 , abcb, z) a (q 0 , bcb, a) // push a handle PDAs!  a (q 0 , cb, ba) // push b  Yes, it can…  a (q 1 , b, ba) // goto 1  Let’s take a look.  a (q 2 , b, ba) // ε trans  a (q 2 , λ , a) // pop b  Nowhere to go // Reject! Pushdown Automata Pushdown Automata  Let’s look at another example:  Let’s look at another example:  L = { xx r | x ∈ { a,b } * }  L = { xx r | x ∈ { a,b } * }  The PDA will have 3 states  Basic idea for building a PDA  State 0 (initial) : reading before the center of string  State 1: read after center of string, comparing chars  Much like last example, except  State 2 (accepting): after all chars read, stack should be  This time we don’t know when to start popping and empty comparing  The machine can choose to go from state 0 to  Since PDAs are non-deterministic, this is not a state 1 at any time: problem  Will result in many “wrong” set of moves  All you need is one “right” set of moves for a string to be accepted. Pushdown Automata PDA Example  Let’s look at an example:  Let’s see a bad transition set for abba  (q 0 , abba,z) a (q 0 , bba, a) // push a  L = { xx r | x ∈ { a,b } * }  a (q 0 , ba, ba) // push b  a (q 0 , a, bba) // push b b, b / λ  a (q 1 , a, bba) // λ trans b, z / b z λ , z / z a, a / λ a, z / a z  Nowhere to go // Reject! λ , a / a λ , b / b q 0 q 1 q 2 λ , z / z b, b / bb a, b / ab a, a / aa b, a / ba 4

  5. PDA Example Pushdown Automata  Let’s see a good transition set for abba  “Let’s go to the video tape”  (q 0 , abba, z) a (q 0 , bba, a) // push a  Actually JFLAP…  a (q 0 , ba, ba) // push b  a (q 1 , ba, ba) // ε trans  a (q 1 , a, a) // pop b  a (q 1 , λ , Z) // pop a  a (q 2 , λ , Z) // Accept! Pushdown Automata Pushdown Automata  Strings accepted by a PDA by Final State  Strings accepted by a PDA (Final State)  Start at (q 0 , x, z)  Let M = (Q, Σ , Γ , δ , q 0 , z, F) be a PDA  Start state q 0  x is accepted by M if  X on the input tape  (q 0 , x, z) a * (q, λ , β )  Empty stack  End with (q, λ , β )  End in an accepting state (q ∈ F)  Where  All characters of x have been read  q ∈ A  Some string on the stack (doesn’t matter what).  β ∈ Γ * Pushdown Automata Pushdown Automata  Strings accepted by a PDA by Empty Stack  Strings accepted by a PDA (Empty  Start at (q 0 , x, z) Stack)  Start state q 0  Let M = (Q, Σ , Γ , δ , q 0 , z, F) be a PDA  X on the input tape  x is accepted by M if  Empty stack  End with (q, λ , λ )  (q 0 , x, z) a * (q, λ , λ )  End in any state  All characters of x have been read  Where  Stack is empty  q ∈ Q 5

  6. Pushdown Automata Final State vs. Empty Stack  The language accepted by a PDA  The two means by which a PDA can  Let M = (Q, Σ , Γ , q 0 , z, F, δ ) be a PDA accept are equivalent wrt the class of  The language accepted by M by final state, languages accepted  Denoted L(M) is  The set of all strings x that are accepted by M by final  Given a PDA M such that L = L(M), there state exists a PDA M’ such that L = N(M’)  The language accepted by M by empty stack,  Given a PDA M such that L = N(M), there  Denoted N(M) is  The set of all strings x that are accepted by M by empty exists a PDA M’ such that L = L(M’) stack We will show that all languages accepted by a PDA by final state  will be accepted by an equivalent PDA by empty stack and visa versa Final State → Empty Stack Accept by Empty Stack  Final State → Empty Stack  Final State → Empty Stack  Given a PDA P F = (Q, Σ , Γ , δ F , q 0 , z ,F)  Basic idea and L = L (P F ) then there exists a PDA P N  Transitions of P N will mimic those of P F such that L = N (P N )  Create a new state in P N that will empty the stack.  The machine can move into this new state whenever the machine is in an accepting state  We will build such a PDA of P F Final State → Empty Stack Accept by Empty Stack  Final State → Empty Stack  Final State → Empty Stack  We must be careful though  P N = (  P F may crash when the stack is empty.  Q ∪ {p o , p},  In those cases we need to assure that P N does not  Σ , accept  Γ ∪ {X 0 }  To solve this:  Create a new empty stack symbol X 0 which is placed on  δ N the stack before P F s empty stack marker (z)  p 0 ,  z will only be popped by the new “stack emptying state  The first move of P N will be to place zX 0 on P N stack.  X 0 ) 6

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend