Pushdown Automata Semantics of a PDA

CS 373:

Gul Agha Mahesh Viswanathan

University of Illinois, Urbana-Champaign

Fall 2010

Agha-Viswanathan CS373 So far we considered automata with finite memory or machines with infinite memory Today: automata with access to an infinite stack — infinite memory but restricted access The stack can contain an unlimited number of characters. But can read/erase only the top of the stack: pop can add to only the top of the stack: push On longer inputs, automaton may have more items in the stack

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Restricted Infinite Memory: The Stack

Agha-Viswanathan CS373 Today: automata with access to an infinite stack — infinite memory but restricted access The stack can contain an unlimited number of characters. But can read/erase only the top of the stack: pop can add to only the top of the stack: push On longer inputs, automaton may have more items in the stack

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Restricted Infinite Memory: The Stack

So far we considered automata with finite memory or machines with infinite memory

Agha-Viswanathan CS373 The stack can contain an unlimited number of characters. But can read/erase only the top of the stack: pop can add to only the top of the stack: push On longer inputs, automaton may have more items in the stack

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Restricted Infinite Memory: The Stack

So far we considered automata with finite memory or machines with infinite memory Today: automata with access to an infinite stack — infinite memory but restricted access

Agha-Viswanathan CS373 But can read/erase only the top of the stack: pop can add to only the top of the stack: push On longer inputs, automaton may have more items in the stack

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Restricted Infinite Memory: The Stack

So far we considered automata with finite memory or machines with infinite memory Today: automata with access to an infinite stack — infinite memory but restricted access The stack can contain an unlimited number of characters.

Agha-Viswanathan CS373 can add to only the top of the stack: push On longer inputs, automaton may have more items in the stack

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Restricted Infinite Memory: The Stack

So far we considered automata with finite memory or machines with infinite memory Today: automata with access to an infinite stack — infinite memory but restricted access The stack can contain an unlimited number of characters. But can read/erase only the top of the stack: pop

Agha-Viswanathan CS373 On longer inputs, automaton may have more items in the stack

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Restricted Infinite Memory: The Stack

So far we considered automata with finite memory or machines with infinite memory Today: automata with access to an infinite stack — infinite memory but restricted access The stack can contain an unlimited number of characters. But can read/erase only the top of the stack: pop can add to only the top of the stack: push

Agha-Viswanathan CS373 Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Restricted Infinite Memory: The Stack

So far we considered automata with finite memory or machines with infinite memory Today: automata with access to an infinite stack — infinite memory but restricted access The stack can contain an unlimited number of characters. But can read/erase only the top of the stack: pop can add to only the top of the stack: push On longer inputs, automaton may have more items in the stack

Agha-Viswanathan CS373 On reading a 0, push it onto the stack After the 0s, on reading each 1, pop a 0 (If a 0 comes after a 1, reject) If attempt to pop an empty stack, reject If stack not empty at the end, reject Else accept

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Keeping Count Using the Stack

An automaton can use the stack to recognize {0n1n}

Agha-Viswanathan CS373 After the 0s, on reading each 1, pop a 0 (If a 0 comes after a 1, reject) If attempt to pop an empty stack, reject If stack not empty at the end, reject Else accept

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Keeping Count Using the Stack

An automaton can use the stack to recognize {0n1n} On reading a 0, push it onto the stack

Agha-Viswanathan CS373 (If a 0 comes after a 1, reject) If attempt to pop an empty stack, reject If stack not empty at the end, reject Else accept

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Keeping Count Using the Stack

An automaton can use the stack to recognize {0n1n} On reading a 0, push it onto the stack After the 0s, on reading each 1, pop a 0

Agha-Viswanathan CS373 If attempt to pop an empty stack, reject If stack not empty at the end, reject Else accept

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Keeping Count Using the Stack

An automaton can use the stack to recognize {0n1n} On reading a 0, push it onto the stack After the 0s, on reading each 1, pop a 0 (If a 0 comes after a 1, reject)

Agha-Viswanathan CS373 If stack not empty at the end, reject Else accept

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Keeping Count Using the Stack

An automaton can use the stack to recognize {0n1n} On reading a 0, push it onto the stack After the 0s, on reading each 1, pop a 0 (If a 0 comes after a 1, reject) If attempt to pop an empty stack, reject

Agha-Viswanathan CS373 Else accept

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Keeping Count Using the Stack

An automaton can use the stack to recognize {0n1n} On reading a 0, push it onto the stack After the 0s, on reading each 1, pop a 0 (If a 0 comes after a 1, reject) If attempt to pop an empty stack, reject If stack not empty at the end, reject

Agha-Viswanathan CS373 Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Keeping Count Using the Stack

An automaton can use the stack to recognize {0n1n} On reading a 0, push it onto the stack After the 0s, on reading each 1, pop a 0 (If a 0 comes after a 1, reject) If attempt to pop an empty stack, reject If stack not empty at the end, reject Else accept

Agha-Viswanathan CS373 On seeing a ( push it on the stack On seeing a ) pop a ( from the stack If attempt to pop an empty stack, reject If stack not empty at the end, reject Else accept

e.g. (())() is balanced, but ())() and (() are not

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis Using the Stack

An automaton can use the stack to recognize balanced parenthesis

Agha-Viswanathan CS373 On seeing a ( push it on the stack On seeing a ) pop a ( from the stack If attempt to pop an empty stack, reject If stack not empty at the end, reject Else accept

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis Using the Stack

An automaton can use the stack to recognize balanced parenthesis e.g. (())() is balanced, but ())() and (() are not

Agha-Viswanathan CS373 On seeing a ) pop a ( from the stack If attempt to pop an empty stack, reject If stack not empty at the end, reject Else accept

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis Using the Stack

An automaton can use the stack to recognize balanced parenthesis e.g. (())() is balanced, but ())() and (() are not On seeing a ( push it on the stack

Agha-Viswanathan CS373 If attempt to pop an empty stack, reject If stack not empty at the end, reject Else accept

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis Using the Stack

An automaton can use the stack to recognize balanced parenthesis e.g. (())() is balanced, but ())() and (() are not On seeing a ( push it on the stack On seeing a ) pop a ( from the stack

Agha-Viswanathan CS373 If stack not empty at the end, reject Else accept

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis Using the Stack

An automaton can use the stack to recognize balanced parenthesis e.g. (())() is balanced, but ())() and (() are not On seeing a ( push it on the stack On seeing a ) pop a ( from the stack If attempt to pop an empty stack, reject

Agha-Viswanathan CS373 Else accept

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis Using the Stack

An automaton can use the stack to recognize balanced parenthesis e.g. (())() is balanced, but ())() and (() are not On seeing a ( push it on the stack On seeing a ) pop a ( from the stack If attempt to pop an empty stack, reject If stack not empty at the end, reject

Agha-Viswanathan CS373 Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis Using the Stack

An automaton can use the stack to recognize balanced parenthesis e.g. (())() is balanced, but ())() and (() are not On seeing a ( push it on the stack On seeing a ) pop a ( from the stack If attempt to pop an empty stack, reject If stack not empty at the end, reject Else accept

Agha-Viswanathan CS373 Like an NFA with -transitions, but with a stack Stack depth unlimited: not a finite-state machine Non-deterministic: accepts if any thread of execution accepts

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Pushdown Automata (PDA)

input a b b a a b finite-state control x y x stack $

A Pushdown Automaton

Agha-Viswanathan CS373 Stack depth unlimited: not a finite-state machine Non-deterministic: accepts if any thread of execution accepts

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Pushdown Automata (PDA)

input a b b a a b finite-state control x y x stack $

A Pushdown Automaton

Like an NFA with -transitions, but with a stack

Agha-Viswanathan CS373 Non-deterministic: accepts if any thread of execution accepts

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Pushdown Automata (PDA)

input a b b a a b finite-state control x y x stack $

A Pushdown Automaton

Like an NFA with -transitions, but with a stack Stack depth unlimited: not a finite-state machine

Agha-Viswanathan CS373 Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Pushdown Automata (PDA)

input a b b a a b finite-state control x y x stack $

A Pushdown Automaton

Like an NFA with -transitions, but with a stack Stack depth unlimited: not a finite-state machine Non-deterministic: accepts if any thread of execution accepts

Agha-Viswanathan CS373 At every step: Consume next input symbol (or none) and pop the top symbol on stack (or none) Based on current state, consumed input symbol and popped stack symbol, do (non-deterministically): 1 push a symbol onto stack (or push none) 2 change to a new state

a, x → y

q1 q2

If at q1, with next input symbol a and top of stack x, then can consume a, pop x, push y onto stack and move to q2 (any of a, x, y may be )

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Pushdown Automata (PDA)

Has a non-deterministic finite-state control

Agha-Viswanathan CS373 Consume next input symbol (or none) and pop the top symbol on stack (or none) Based on current state, consumed input symbol and popped stack symbol, do (non-deterministically): 1 push a symbol onto stack (or push none) 2 change to a new state

a, x → y

q1 q2

If at q1, with next input symbol a and top of stack x, then can consume a, pop x, push y onto stack and move to q2 (any of a, x, y may be )

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Pushdown Automata (PDA)

Has a non-deterministic finite-state control At every step:

Agha-Viswanathan CS373 and pop the top symbol on stack (or none) Based on current state, consumed input symbol and popped stack symbol, do (non-deterministically): 1 push a symbol onto stack (or push none) 2 change to a new state

a, x → y

q1 q2

If at q1, with next input symbol a and top of stack x, then can consume a, pop x, push y onto stack and move to q2 (any of a, x, y may be )

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Pushdown Automata (PDA)

Has a non-deterministic finite-state control At every step: Consume next input symbol (or none)

Agha-Viswanathan CS373 Based on current state, consumed input symbol and popped stack symbol, do (non-deterministically): 1 push a symbol onto stack (or push none) 2 change to a new state

a, x → y

q1 q2

If at q1, with next input symbol a and top of stack x, then can consume a, pop x, push y onto stack and move to q2 (any of a, x, y may be )

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Pushdown Automata (PDA)

Has a non-deterministic finite-state control At every step: Consume next input symbol (or none) and pop the top symbol on stack (or none)

Agha-Viswanathan CS373 1 push a symbol onto stack (or push none) 2 change to a new state

a, x → y

q1 q2

If at q1, with next input symbol a and top of stack x, then can consume a, pop x, push y onto stack and move to q2 (any of a, x, y may be )

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Pushdown Automata (PDA)

Has a non-deterministic finite-state control At every step: Consume next input symbol (or none) and pop the top symbol on stack (or none) Based on current state, consumed input symbol and popped stack symbol, do (non-deterministically):

Agha-Viswanathan CS373 2 change to a new state

a, x → y

q1 q2

If at q1, with next input symbol a and top of stack x, then can consume a, pop x, push y onto stack and move to q2 (any of a, x, y may be )

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Pushdown Automata (PDA)

Has a non-deterministic finite-state control At every step: Consume next input symbol (or none) and pop the top symbol on stack (or none) Based on current state, consumed input symbol and popped stack symbol, do (non-deterministically): 1 push a symbol onto stack (or push none)

Agha-Viswanathan CS373 a, x → y

q1 q2

If at q1, with next input symbol a and top of stack x, then can consume a, pop x, push y onto stack and move to q2 (any of a, x, y may be )

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Pushdown Automata (PDA)

Has a non-deterministic finite-state control At every step: Consume next input symbol (or none) and pop the top symbol on stack (or none) Based on current state, consumed input symbol and popped stack symbol, do (non-deterministically): 1 push a symbol onto stack (or push none) 2 change to a new state

Agha-Viswanathan CS373 (any of a, x, y may be )

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Pushdown Automata (PDA)

Has a non-deterministic finite-state control At every step: Consume next input symbol (or none) and pop the top symbol on stack (or none) Based on current state, consumed input symbol and popped stack symbol, do (non-deterministically): 1 push a symbol onto stack (or push none) 2 change to a new state

a, x → y

q1 q2

If at q1, with next input symbol a and top of stack x, then can consume a, pop x, push y onto stack and move to q2

Agha-Viswanathan CS373 Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Pushdown Automata (PDA)

Has a non-deterministic finite-state control At every step: Consume next input symbol (or none) and pop the top symbol on stack (or none) Based on current state, consumed input symbol and popped stack symbol, do (non-deterministically): 1 push a symbol onto stack (or push none) 2 change to a new state

a, x → y

q1 q2

If at q1, with next input symbol a and top of stack x, then can consume a, pop x, push y onto stack and move to q2 (any of a, x, y may be )

Agha-Viswanathan CS373 Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Pushdown Automata (PDA): Formal Definition

A PDA P = (Q, Σ, Γ, δ, q0, F ) where Q = Finite set of states Σ = Finite input alphabet Γ = Finite stack alphabet

q0 = Start state F ⊆ Q = Accepting/final states δ : Q × (Σ ∪ {}) × (Γ ∪ {}) → P(Q × (Γ ∪ {}))

Agha-Viswanathan CS373 First push a “bottom-of-the-stack” symbol $ and move to q On seeing a ( push it onto the stack On seeing a ) pop if a ( is in the stack

Pop $ and move to final state qF

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis: PDA construction

(,  → (

,  → $ , $ →  q0 q qF

), (→ 

Agha-Viswanathan CS373 On seeing a ( push it onto the stack On seeing a ) pop if a ( is in the stack

Pop $ and move to final state qF

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis: PDA construction

(,  → (

,  → $ , $ →  q0 q qF

), (→ 

First push a “bottom-of-the-stack” symbol $ and move to q

Agha-Viswanathan CS373 On seeing a ) pop if a ( is in the stack

Pop $ and move to final state qF

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis: PDA construction

(,  → (

,  → $ , $ →  q0 q qF

), (→ 

First push a “bottom-of-the-stack” symbol $ and move to q On seeing a ( push it onto the stack

Agha-Viswanathan CS373 Pop $ and move to final state qF

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis: PDA construction

(,  → (

,  → $ , $ →  q0 q qF

), (→ 

First push a “bottom-of-the-stack” symbol $ and move to q On seeing a ( push it onto the stack On seeing a ) pop if a ( is in the stack

Agha-Viswanathan CS373 Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis: PDA construction

(,  → (

,  → $ , $ →  q0 q qF

), (→ 

First push a “bottom-of-the-stack” symbol $ and move to q On seeing a ( push it onto the stack On seeing a ) pop if a ( is in the stack

Pop $ and move to final state qF

Agha-Viswanathan CS373 ) ) ( ) ) q ( ( $ ) ( ) ) ( ) ) ) ) q q q ( $ ( $ $ ) )

q ! $ $

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis: PDA execution input ( ( ) ) ( ) ) q $ stack

Agha-Viswanathan CS373 ) ( ) ) ( ) ) ) ) q q q ( $ ( $ $ ) )

q ! $ $

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis: PDA execution input ( ( ) ) ( ) ) ) ) ( ) ) q q $ stack ( ( $

Agha-Viswanathan CS373 ( ) ) ) ) q q $ ( $ ) )

q ! $ $

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis: PDA execution input ( ( ) ) ( ) ) ) ) ( ) ) q q $ stack ( ( $ ) ( ) ) q ( $

Agha-Viswanathan CS373 ) ) q ( $ ) )

q ! $ $

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis: PDA execution input ( ( ) ) ( ) ) ) ) ( ) ) q q $ stack ( ( $ ) ( ) ) ( ) ) q q ( $ $

Agha-Viswanathan CS373 ) )

q ! $ $

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis: PDA execution input ( ( ) ) ( ) ) ) ) ( ) ) q q $ stack ( ( $ ) ( ) ) ( ) ) ) ) q q q ( $ ( $ $

Agha-Viswanathan CS373 )

! $

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis: PDA execution input ( ( ) ) ( ) ) ) ) ( ) ) q q $ stack ( ( $ ) ( ) ) ( ) ) ) ) q q q ( $ ( $ $ ) q $ Agha-Viswanathan CS373 Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Matching Parenthesis: PDA execution input ( ( ) ) ( ) ) ) ) ( ) ) q q $ stack ( ( $ ) ( ) ) ( ) ) ) ) q q q ( $ ( $ $ ) )

q ! $ $ Agha-Viswanathan CS373 First push a “bottom-of-the-stack” symbol $ and move to a pushing state Push input symbols onto the stack Non-deterministically move to a popping state (with or without consuming a single input symbol) If next input symbol is same as top of stack, pop If $ on top of stack move to accept state

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata : PDA construction

a,  → a a, a → 

,  →  ,  → $ , $ →  q0 q↓ q↑ qF a,  → 

Agha-Viswanathan CS373 Push input symbols onto the stack Non-deterministically move to a popping state (with or without consuming a single input symbol) If next input symbol is same as top of stack, pop If $ on top of stack move to accept state

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Palindrome: PDA construction

a,  → a a, a → 

,  →  ,  → $ , $ →  q0 q↓ q↑ qF a,  → 

First push a “bottom-of-the-stack” symbol $ and move to a pushing state

Agha-Viswanathan CS373 Non-deterministically move to a popping state (with or without consuming a single input symbol) If next input symbol is same as top of stack, pop If $ on top of stack move to accept state

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Palindrome: PDA construction

a,  → a a, a → 

,  →  ,  → $ , $ →  q0 q↓ q↑ qF a,  → 

First push a “bottom-of-the-stack” symbol $ and move to a pushing state Push input symbols onto the stack

Agha-Viswanathan CS373 If next input symbol is same as top of stack, pop If $ on top of stack move to accept state

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Palindrome: PDA construction

a,  → a a, a → 

,  →  ,  → $ , $ →  q0 q↓ q↑ qF a,  → 

First push a “bottom-of-the-stack” symbol $ and move to a pushing state Push input symbols onto the stack Non-deterministically move to a popping state (with or without consuming a single input symbol)

Agha-Viswanathan CS373 If $ on top of stack move to accept state

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Palindrome: PDA construction

a,  → a a, a → 

,  →  ,  → $ , $ →  q0 q↓ q↑ qF a,  → 

First push a “bottom-of-the-stack” symbol $ and move to a pushing state Push input symbols onto the stack Non-deterministically move to a popping state (with or without consuming a single input symbol) If next input symbol is same as top of stack, pop

Agha-Viswanathan CS373 Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Palindrome: PDA construction

a,  → a a, a → 

,  →  ,  → $ , $ →  q0 q↓ q↑ qF a,  → 

First push a “bottom-of-the-stack” symbol $ and move to a pushing state Push input symbols onto the stack Non-deterministically move to a popping state (with or without consuming a single input symbol) If next input symbol is same as top of stack, pop If $ on top of stack move to accept state

Agha-Viswanathan CS373 a d a m d a m

q↓ q↓ m a $ m $ a m m

q↑ q↑ q↑ a m $ m $ $

qF

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Palindrome: PDA execution m a d a m

q↓ $

Agha-Viswanathan CS373 d a m

q↓ a m $ a m m

q↑ q↑ q↑ a m $ m $ $

qF

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Palindrome: PDA execution m a d a m a d a m

q↓ q↓ $ m $

Agha-Viswanathan CS373 a m m

q↑ q↑ q↑ a m $ m $ $

qF

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Palindrome: PDA execution m a d a m a d a m d a m

q↓ q↓ q↓ $ m a $ m $

Agha-Viswanathan CS373 m

q↑ q↑ m $ $

qF

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Palindrome: PDA execution m a d a m a d a m d a m

q↓ q↓ q↓ $ m a $ m $ a m

q↑ a m $

Agha-Viswanathan CS373 q↑ $

qF

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Palindrome: PDA execution m a d a m a d a m d a m

q↓ q↓ q↓ $ m a $ m $ a m m

q↑ q↑ a m m $ $

Agha-Viswanathan CS373 qF

Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Palindrome: PDA execution m a d a m a d a m d a m

q↓ q↓ q↓ $ m a $ m $ a m m

q↑ q↑ q↑ a m $ m $ $

Agha-Viswanathan CS373 Computing Using a Stack Pushdown Automata Definition Semantics of a PDA Examples of Pushdown Automata Palindrome: PDA execution m a d a m a d a m d a m

q↓ q↓ q↓ $ m a $ m $ a m m

q↑ q↑ q↑ a m $ m $ $

qF

Agha-Viswanathan CS373 In the case of an NFA (or DFA), it is the state In the case of a TM, it is the state, head position, and tape contents In the case of a PDA, it is the state + stack contents

Definition

An instantaneous description of a PDA P = (Q, Σ, Γ, δ, q0, F ) is a pair hq, σi, where q ∈ Q and σ ∈ Γ∗

Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Instantaneous Description

In order to describe a machine’s execution, we need to capture a “snapshot” of the machine that completely determines future behavior

Agha-Viswanathan CS373 In the case of a TM, it is the state, head position, and tape contents In the case of a PDA, it is the state + stack contents

Definition

An instantaneous description of a PDA P = (Q, Σ, Γ, δ, q0, F ) is a pair hq, σi, where q ∈ Q and σ ∈ Γ∗

Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Instantaneous Description

In order to describe a machine’s execution, we need to capture a “snapshot” of the machine that completely determines future behavior In the case of an NFA (or DFA), it is the state

Agha-Viswanathan CS373 In the case of a PDA, it is the state + stack contents

Definition

An instantaneous description of a PDA P = (Q, Σ, Γ, δ, q0, F ) is a pair hq, σi, where q ∈ Q and σ ∈ Γ∗

Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Instantaneous Description

In order to describe a machine’s execution, we need to capture a “snapshot” of the machine that completely determines future behavior In the case of an NFA (or DFA), it is the state In the case of a TM, it is the state, head position, and tape contents

Agha-Viswanathan CS373 Definition

An instantaneous description of a PDA P = (Q, Σ, Γ, δ, q0, F ) is a pair hq, σi, where q ∈ Q and σ ∈ Γ∗

Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Instantaneous Description

In order to describe a machine’s execution, we need to capture a “snapshot” of the machine that completely determines future behavior In the case of an NFA (or DFA), it is the state In the case of a TM, it is the state, head position, and tape contents In the case of a PDA, it is the state + stack contents

Agha-Viswanathan CS373 Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Instantaneous Description

In order to describe a machine’s execution, we need to capture a “snapshot” of the machine that completely determines future behavior In the case of an NFA (or DFA), it is the state In the case of a TM, it is the state, head position, and tape contents In the case of a PDA, it is the state + stack contents

Definition

An instantaneous description of a PDA P = (Q, Σ, Γ, δ, q0, F ) is a pair hq, σi, where q ∈ Q and σ ∈ Γ∗

Agha-Viswanathan CS373 r0 = q1, and s0 = σ1,

rk = q2, and sk = σ2,

for every i,(ri+1, b) ∈ δ(ri , xi+1, a) such that si = as and ∗ si+1 = bs, where a, b ∈ Γ ∪ {} and s ∈ Γ

Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Computation

Definition ∗ For a PDA P = (Q, Σ, Γ, δ, q0, F ), string w ∈ Σ , and instantaneous descriptions hq1, σ1i and hq2, σ2i, we say w hq1, σ1i −→P hq2, σ2i iff there is a sequence of instanteous descriptions hr0, s0i, hr1, s1i,... hrk , sk i and a sequence x1, x2,... xk , where for each i, xi ∈ Σ ∪ {}, such that

w = x1x2 ··· xk ,

Agha-Viswanathan CS373 rk = q2, and sk = σ2,

for every i,(ri+1, b) ∈ δ(ri , xi+1, a) such that si = as and ∗ si+1 = bs, where a, b ∈ Γ ∪ {} and s ∈ Γ

Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Computation

Definition ∗ For a PDA P = (Q, Σ, Γ, δ, q0, F ), string w ∈ Σ , and instantaneous descriptions hq1, σ1i and hq2, σ2i, we say w hq1, σ1i −→P hq2, σ2i iff there is a sequence of instanteous descriptions hr0, s0i, hr1, s1i,... hrk , sk i and a sequence x1, x2,... xk , where for each i, xi ∈ Σ ∪ {}, such that

w = x1x2 ··· xk ,

r0 = q1, and s0 = σ1,

Agha-Viswanathan CS373 for every i,(ri+1, b) ∈ δ(ri , xi+1, a) such that si = as and ∗ si+1 = bs, where a, b ∈ Γ ∪ {} and s ∈ Γ

Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Computation

Definition ∗ For a PDA P = (Q, Σ, Γ, δ, q0, F ), string w ∈ Σ , and instantaneous descriptions hq1, σ1i and hq2, σ2i, we say w hq1, σ1i −→P hq2, σ2i iff there is a sequence of instanteous descriptions hr0, s0i, hr1, s1i,... hrk , sk i and a sequence x1, x2,... xk , where for each i, xi ∈ Σ ∪ {}, such that

w = x1x2 ··· xk ,

r0 = q1, and s0 = σ1,

rk = q2, and sk = σ2,

Agha-Viswanathan CS373 Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Computation

Definition ∗ For a PDA P = (Q, Σ, Γ, δ, q0, F ), string w ∈ Σ , and instantaneous descriptions hq1, σ1i and hq2, σ2i, we say w hq1, σ1i −→P hq2, σ2i iff there is a sequence of instanteous descriptions hr0, s0i, hr1, s1i,... hrk , sk i and a sequence x1, x2,... xk , where for each i, xi ∈ Σ ∪ {}, such that

w = x1x2 ··· xk ,

r0 = q1, and s0 = σ1,

rk = q2, and sk = σ2,

for every i,(ri+1, b) ∈ δ(ri , xi+1, a) such that si = as and ∗ si+1 = bs, where a, b ∈ Γ ∪ {} and s ∈ Γ

Agha-Viswanathan CS373 x1= x2=( x3=( x4=) x5=( hq0, i −→ hq, $i −→ hq, ($i −→ hq, (($i −→ hq, ($i −→ hq, (($i

Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Example of Computation

Example (,  → (

,  → $ , $ →  q0 q qF

), (→ 

(()( hq0, i −→ hq, (($i because

Agha-Viswanathan CS373 Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Example of Computation

Example (,  → (

,  → $ , $ →  q0 q qF

), (→ 

(()( hq0, i −→ hq, (($i because

x1= x2=( x3=( x4=) x5=( hq0, i −→ hq, $i −→ hq, ($i −→ hq, (($i −→ hq, ($i −→ hq, (($i

Agha-Viswanathan CS373 for some ∗ w q ∈ F and σ ∈ Γ , hq0, i −→P hq, σi

Definition The language recognized/accepted by a PDA ∗ P = (Q, Σ, Γ, δ, q0, F ) is L(P) = {w ∈ Σ | P accepts w}. A language L is said to be accepted/recognized by P if L = L(P).

Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Acceptance/Recognition

Definition ∗ A PDA P = (Q, Σ, Γ, δ, q0, F ) accepts a string w ∈ Σ iff

Agha-Viswanathan CS373 Definition The language recognized/accepted by a PDA ∗ P = (Q, Σ, Γ, δ, q0, F ) is L(P) = {w ∈ Σ | P accepts w}. A language L is said to be accepted/recognized by P if L = L(P).

Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Acceptance/Recognition

Definition ∗ A PDA P = (Q, Σ, Γ, δ, q0, F ) accepts a string w ∈ Σ iff for some ∗ w q ∈ F and σ ∈ Γ , hq0, i −→P hq, σi

Agha-Viswanathan CS373 A language L is said to be accepted/recognized by P if L = L(P).

Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Acceptance/Recognition

Definition ∗ A PDA P = (Q, Σ, Γ, δ, q0, F ) accepts a string w ∈ Σ iff for some ∗ w q ∈ F and σ ∈ Γ , hq0, i −→P hq, σi

Definition The language recognized/accepted by a PDA ∗ P = (Q, Σ, Γ, δ, q0, F ) is L(P) = {w ∈ Σ | P accepts w}.

Agha-Viswanathan CS373 Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Acceptance/Recognition

Definition ∗ A PDA P = (Q, Σ, Γ, δ, q0, F ) accepts a string w ∈ Σ iff for some ∗ w q ∈ F and σ ∈ Γ , hq0, i −→P hq, σi

Definition The language recognized/accepted by a PDA ∗ P = (Q, Σ, Γ, δ, q0, F ) is L(P) = {w ∈ Σ | P accepts w}. A language L is said to be accepted/recognized by P if L = L(P).

Agha-Viswanathan CS373 Theorem For every CFG G, there is a PDA P such that L(G) = L(P). In addition, for every PDA P, there is a CFG G such that L(P) = L(G). Thus, L is context-free iff there is a PDA P such that L = L(P).

Proof. Skipped. 

Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Expressive Power of CFGs and PDAs

CFGs and PDAs have equivalent expressive powers. More formally, ...

Agha-Viswanathan CS373 Thus, L is context-free iff there is a PDA P such that L = L(P).

Proof. Skipped. 

Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Expressive Power of CFGs and PDAs

CFGs and PDAs have equivalent expressive powers. More formally, ...

Theorem For every CFG G, there is a PDA P such that L(G) = L(P). In addition, for every PDA P, there is a CFG G such that L(P) = L(G).

Agha-Viswanathan CS373 Proof. Skipped. 

Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Expressive Power of CFGs and PDAs

CFGs and PDAs have equivalent expressive powers. More formally, ...

Theorem For every CFG G, there is a PDA P such that L(G) = L(P). In addition, for every PDA P, there is a CFG G such that L(P) = L(G). Thus, L is context-free iff there is a PDA P such that L = L(P).

Agha-Viswanathan CS373 Computation Pushdown Automata Language Recognized Semantics of a PDA Expressive Power Expressive Power of CFGs and PDAs

CFGs and PDAs have equivalent expressive powers. More formally, ...

Theorem For every CFG G, there is a PDA P such that L(G) = L(P). In addition, for every PDA P, there is a CFG G such that L(P) = L(G). Thus, L is context-free iff there is a PDA P such that L = L(P).

Proof. Skipped. 

Agha-Viswanathan CS373