+ All Categories
Home > Documents > CSCI 2670 Introduction to Theory of Computing

CSCI 2670 Introduction to Theory of Computing

Date post: 07-Jan-2016
Category:
Upload: idalia
View: 24 times
Download: 0 times
Share this document with a friend
Description:
CSCI 2670 Introduction to Theory of Computing. September 22, 2005. Agenda. Yesterday Pushdown automata Today Equivalence of pushdown automata and CFG’s Pumping lemma for CFG’s. Announcements. Matrix Reloaded tonight! 6:30 in Boyd 328 Free popcorn 25 cent Coke - PowerPoint PPT Presentation
34
CSCI 2670 Introduction to Theory of Computing September 22, 2005
Transcript
Page 1: CSCI 2670 Introduction to Theory of Computing

CSCI 2670Introduction to Theory of

Computing

September 22, 2005

Page 2: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Agenda

• Yesterday– Pushdown automata

• Today– Equivalence of pushdown automata

and CFG’s– Pumping lemma for CFG’s

Page 3: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Announcements

• Matrix Reloaded tonight!– 6:30 in Boyd 328

• Free popcorn• 25 cent Coke• Pizza will be ordered at cost if people

want

Page 4: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Equivalence of PDA’s and CFG’s

Theorem: A language is context free if and only if some pushdown automaton recognizes it

Proved in two lemmas – one for the “if” direction and one for the “only if” direction

We will only do the “only if” step – i.e., show that every context-free language has an associated PDA

Page 5: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

CFG’s are recognized by PDA’s

Lemma: If a language is context free, then some pushdown automaton recognizes it

Proof idea: Construct a PDA following CFG rules

Page 6: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

CFG’s are recognized by PDA’s

Format of the new PDA

qstart qloop qacceptε, ε S$ ε, $ ε

a,aε

ε,Aw

Start by pushing the start variable and stack bottom marker

Have a transition for each rule replacing the variable with its right hand side

Have a transition that allows us to read each alphabet symbol if it is at the top of the stack

Finish only if the stack is empty

Page 7: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Constructing the PDA

• You can read any symbol in when that symbol is at the top of the stack– Transitions of the form a,aε

• The rules will be pushed onto the stack – when a variable A is on top of the stack and there is a rule Aw, you pop A and push w

• You can go to the accept state only if the stack is empty

Page 8: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Idea of PDA construction for AxBz

State control

a b

At

State control

a b

xBzt

Page 9: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Actual construction for AxBz

ε,Az ε, ε B

ε, ε x

In an abuse of notation, we say (q,ε,A)=(q,xBz)

Page 10: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Constructing the PDA

• Q = {qstart, qloop, qaccept}E, where E is the set of states used for replacement rules onto the stack

(the PDA alphabet) is the set of terminals in the CFG

(the stack alphabet) is the union of the terminals and the variables and {$} (or some suitable placeholder)

Page 11: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Constructing the PDA

is comprised of several rules1. (qstart,ε,ε)=(qloop,S$)

- Start with placeholder on the stack and with the start variable

2. (qloop,a,a)=(qloop,ε) for every a- Terminals may be read off the top of the

stack

3. (qloop,ε,A)=(qloop,w) for every rule Aw- Implement replacement rules

4. (qloop,ε,$)=(qaccept,ε)- Accept when the stack is empty

Page 12: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Example

• S SS | (S) | ()

qstart qloop qacceptε, ε S$ ε, $ ε

(,(ε

),)ε

ε,SSS

ε,S(S)

ε,S()

Page 13: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Example

• Read (()())

qstart qacceptε, ε S$ ε, $ ε

(,(ε

),)ε

ε,SSS

ε,S(S)

ε,S()S$

qloop

Page 14: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Example

• Read (()())

qstart qacceptε, ε S$ ε, $ ε

(,(ε

),)ε

ε,SSS

ε,S(S)

ε,S()

qloop

(S)$

Page 15: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Example

• Read (()())

qstart qacceptε, ε S$ ε, $ ε

(,(ε

),)ε

ε,SSS

ε,S(S)

ε,S()

qloop

S)$

(

Page 16: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Example

• Read (()())

qstart qacceptε, ε S$ ε, $ ε

(,(ε

),)ε

ε,SSS

ε,S(S)

ε,S()

qloop

SS)$

(

Page 17: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Example

• Read (()())

qstart qacceptε, ε S$ ε, $ ε

(,(ε

),)ε

ε,SSS

ε,S(S)

ε,S()

qloop

()S)$

(

Page 18: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Example

• Read (()())

qstart qacceptε, ε S$ ε, $ ε

(,(ε

),)ε

ε,SSS

ε,S(S)

ε,S()

qloop

)S)$

((

Page 19: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Example

• Read (()())

qstart qacceptε, ε S$ ε, $ ε

(,(ε

),)ε

ε,SSS

ε,S(S)

ε,S()

qloop

S)$

(()

Page 20: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Example

• Read (()())

qstart qacceptε, ε S$ ε, $ ε

(,(ε

),)ε

ε,SSS

ε,S(S)

ε,S()

qloop

())$

(()

Page 21: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Example

• Read (()())

qstart qacceptε, ε S$ ε, $ ε

(,(ε

),)ε

ε,SSS

ε,S(S)

ε,S()

qloop

))$

(()(

Page 22: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Example

• Read (()())

qstart qacceptε, ε S$ ε, $ ε

(,(ε

),)ε

ε,SSS

ε,S(S)

ε,S()

qloop

)$

(()()

Page 23: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Example

• Read (()())

qstart qacceptε, ε S$ ε, $ ε

(,(ε

),)ε

ε,SSS

ε,S(S)

ε,S()

qloop

$

(()())

Page 24: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Example

• Read (()())

qstartε, ε S$ ε, $ ε

(,(ε

),)ε

ε,SSS

ε,S(S)

ε,S()

qloop

(()())

qaccept

Page 25: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

The pumping lemma for RE’s

• The pumping lemma for RE’s depends on the structure of the DFA and the fact that a state must be revisited– Only a finite number of states

x

y

z

Page 26: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

The pumping lemma for CFG’s

• What might be repeated in a CFG?– The variables

T

R

R

u v x y z

v & y will be repeated simultaneously

Page 27: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

The pumping lemma for CFG’s

TR

R

u v x y z

TR

uv y

z

R

x yv

R

Page 28: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

The pumping lemma for CFG’s

TR

R

u v x y z

TR

ux

z

Page 29: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

The pumping lemma for CFL’s

Theorem: If A is a context-free language, then there is a number p (the pumping length) where, if s is any string in A of length at least p, then s may be divided into five pieces s=uvxyz satisfying the conditions:

1. For each i 0, uvixyiz A2. |vy| > 03. |vxy| p

Page 30: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Finding the pumping length of a CFL

• Let b equal the longest right-hand side of any rule (assume b > 1)– Each node in the parse tree has at

most b children– At most bh nodes are h steps from the

start node

• Let p equal b|V|+2, where |V| is the number of variables (could be huge!)– Tree height is at least |V|+2

Page 31: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Example

• Show A is not context free, where A={an|n is prime}

Proof: Assume A is context-free and let p be the pumping length of A. Let w=an for any np. By the pumping lemma, w=uvxyz such that |vxy|p, |vy|>0, and uvixyizA for all i=0,2,1….

Page 32: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Example (cont.)

• Show A is not context free, where A={an|n is prime}

Clearly, vy=ak for some kConsider the string uvn+1xyn+1z

This string add n copies of ak to w – i.e., this is an+nk

Since the exponent is n(1+k) this in not in A, which contradicts the pumping lemma. Therefore, A is not context free.

Page 33: CSCI 2670 Introduction to Theory of Computing

September 22, 2005

Page 34: CSCI 2670 Introduction to Theory of Computing

September 22, 2005


Recommended