cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans Menu • Revisiting and Reversing the Pumping Lemma • Recognizing Non-Regular Languages • Pushdown Automata Revisiting the Pumping Lemma q 0 q z x y z If input string is longer than |Q|, some state must repeat. q i If A is a regular language, then there is some number p (the pumping length) where for any string s∈A and |s|≥ p, s may be divided into three pieces, s = xyz, such that |y|> 0, |xy|≤ p, and for any i ≥ 0, xy i z∈A. Pumping Game for Language A 1. Player 1: picks p 2. Player 2: picks s∈A and |s|≥ p 3. Player 1: picks x, y, z, |y|> 0, |xy|≤ p, s = xyz 4. Player 2: picks i ≥ 0 Player 1 wins if xy i z∈ A, Player 2 wins if xy i z∉A If Player 1 can always win: A is regular If Player 2 can always win: A is not regular q 0 q z x y z q i What if Player 2 picks an s∉A? Pump-Priming Game for Language A 1. Player 1: picks p 2. Player 2: picks s∉A and |s|≥ p 3. Player 1: picks x, y, z, |y|> 0, |xy|≤ p, s = xyz 4. Player 2: picks i ≥ 0 Player 1 wins if xy i z ∉ A, Player 2 wins if xy i z ∈A If Player 1 can always win: A is regular If Player 2 can always win: A is not regular q 0 q z x y z q i A = { w | w has more 0s than 1s } Pump-Priming Game for Language A 1. Player 1: picks p 2. Player 2: picks s∉A and |s|≥ p 3. Player 1: picks x, y, z, |y|> 0, |xy|≤ p, s = xyz 4. Player 2: picks i ≥ 0 Player 1 wins if xy i z ∉ A, Player 2 wins if xy i z ∈A If Player 1 can always win: A is regular If Player 2 can always win: A is not regular
5
Embed
Menu cs3102: Theory of Computation Class 6: …cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans Menu • Revisiting and Reversing
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
cs3102: Theory of Computation
Class 6:
Pushdown Automata
Spring 2010
University of Virginia
David Evans
Menu
• Revisiting and Reversing the Pumping Lemma
• Recognizing Non-Regular Languages
• Pushdown Automata
Revisiting the Pumping Lemma
q0
qz
x
y
z
If input string is longer than |Q|, some state must repeat.
qi
If A is a regular language, then there is some
number p (the pumping length) where for any
string s∈A and |s|≥ p, s may be divided into
three pieces, s = xyz, such that |y|> 0, |xy|≤
p, and for any i ≥ 0, xyiz∈A.
Pumping Game for Language A1. Player 1: picks p2. Player 2: picks s∈A and |s|≥ p3. Player 1: picks x, y, z, |y|> 0, |xy|≤ p, s = xyz4. Player 2: picks i ≥ 0
Player 1 wins if xyiz∈ A, Player 2 wins if xyiz∉AIf Player 1 can always win: A is regular
If Player 2 can always win: A is not regular
q0
qz
x
y
z
qi
What if Player 2 picks an s∉A?
Pump-Priming Game for Language A1. Player 1: picks p2. Player 2: picks s∉∉∉∉A and |s|≥ p3. Player 1: picks x, y, z, |y|> 0, |xy|≤ p, s = xyz4. Player 2: picks i ≥ 0
Player 1 wins if xyiz ∉∉∉∉ A, Player 2 wins if xyiz ∈∈∈∈AIf Player 1 can always win: A is regular
If Player 2 can always win: A is not regular
q0
qz
x
y
z
qi
A = { w | w has more 0s than 1s }
Pump-Priming Game for Language A1. Player 1: picks p2. Player 2: picks s∉∉∉∉A and |s|≥ p3. Player 1: picks x, y, z, |y|> 0, |xy|≤ p, s = xyz4. Player 2: picks i ≥ 0
Player 1 wins if xyiz ∉∉∉∉ A, Player 2 wins if xyiz ∈∈∈∈AIf Player 1 can always win: A is regular
If Player 2 can always win: A is not regular
A Complementary View
• Regular Languages are closed under
complement: if A is regular, then Ā is regular
Proof sketch:
DFA M = (Q, Σ, δ, q0, F) recognizes A.
DFA M = (Q, Σ, δ, q0, Q − F) recognizes Ā.
• Thus, Player 2 wins by showing either A or Ā is non-regular.
All Languages
Regular
Languages
Can be recognized by some DFA
Finite
Languages
anbn
wwR
What do we need to add to a DFA to recognize
some non-regular languages?
DFA + Counter?
A = anbn
DFA + Counter?
count = 0
A = anbn
a, count = count + 1b, count = count − 1
b, count = count − 1
Accept if count == 0.
DFA + Stack =
Deterministic Pushdown AutomatonA = anbn
DFA + Stack =
Deterministic Pushdown Automaton
a, push a b, pop a
b, pop a
Accept if stack is empty.
A = anbn
Formalizing DPDA
Note: Sipser only defines Nondeterministic PDA and calls it PDA.
DPDA Transitions
Inputs: state, alphabet symbol or ε, popped stack symbol or ε
Outputs: state, stack symbol to push or ε
It is a deterministic machine:
must always follow possible ε-input transition.
a, ε→ Aq1 q2
Deterministic Pushdown Automaton
q1 q2
a, ε→ +
b, + → ε
A = anbn
Bottom of stack marker
q0b, + → ε
ε, ε→ $
q3
ε, $ → ε
This looks like nondeterminism, but is not: must always take
possible ε-transitions a state with an (ε, h) transitions
cannot have any other (a, h) transitions; a state with a (a, ε)
transition, cannot have any other (a, h) transitions
A = { w | w has more 0s than 1s }
Computing Model for DPDA
First, we need to model the stack!
$
+
+
+
push +
$
+
+
+
+
pop +
$
+
+
+
Modeling the Stack
Modeling the Stack
This would be a normal
way to define a stack,
but not what we use!
DPDA Computation Model
δ∗ : Q× Σ∗ × Γ∗ǫ → Q× Γ∗ǫ
δ∗(q, ǫ, γ) = (q, γ)
∀q ∈ Q, ∀a ∈ Σ, x ∈ Σ∗, γ ∈ Γ∗ :
δ∗ : Q× Σ∗ × Γ∗ǫ → Q× Γ∗ǫ∀q ∈ Q, ∀a ∈ Σ, x ∈ Σ∗, γ ∈ Γ∗, h ∈ Γ :