Docsity

Lecture 10: NDPDAs, CFGs, and PDAs - Exam Preparation - Prof. David Evans, Study notes of Discrete Mathematics

Toggle sidebar
bg1
1
David Evans
http://www.cs.virginia.edu/evans
cs302: Theory of Computation
University of Virginia
Computer Science
Lecture 10:
Lecture 10:
Context
Context-
-Free
Free
Languages
Languages
Contextually
Contextually
2
Lecture 10: NDPDAs/CFGs/PDAs
Exam 1
• In class, next Thursday, Feb 28
• Covers:
Lectures 1-10
Sipser Ch 0-2
Problem Sets 1-3 + Comments
Exam 1
Note: unlike nearly all other sets we draw i n this class, all of these
sets are finite, and the size represents the relative si ze.
3
Lecture 10: NDPDAs/CFGs/PDAs
Exam 1 Notesheet
• For Exam 1, you may not use
anything other than
– Your own brain and body
– A single page (one side) of notes that
you create
• You can work with others to create
your notes page
4
Lecture 10: NDPDAs/CFGs/PDAs
Menu
• Are DPDAs
equivalent
to NDPDAs?
• Properties of
CFLs
• Equivalence
of CFGs and
NDPDAs
5
Lecture 10: NDPDAs/CFGs/PDAs
Language Classes
Regular Languages
Context-Free Languages
Violates Pumping
Lemma For RLs
Violates
Pumping Lemma
For CFLs
Described by DFA, NFA,
RegExp, RegGram
Described by CFG,
NDPDA
0
n
1
n
0
n
1
n
2
n
0
n
w
wwRww
Where are DPDAs?
6
Lecture 10: NDPDAs/CFGs/PDAs
Proving Set Equivalence
A= B⇔A ⊆ Band B⊇A
Sets Aand Bare equivalent if Ais a
subset of Band Bis a subset of A.
pf3
pf4
pf5

Partial preview of the text

Download Lecture 10: NDPDAs, CFGs, and PDAs - Exam Preparation - Prof. David Evans and more Study notes Discrete Mathematics in PDF only on Docsity!

David Evans http://www.cs.virginia.edu/evans

cs302: Theory of Computation University of Virginia Computer Science

Lecture 10: Lecture 10:

Context Context--FreeFree

Languages Languages

ContextuallyContextually

Lecture 10: NDPDAs/CFGs/PDAs 2

Exam 1

• In class, next Thursday, Feb 28

• Covers:

Lectures 1- Sipser Ch 0-

Problem Sets 1-3 + Comments

Exam 1

Note: unlike nearly all other sets we draw in this class, all of these sets are finite, and the size represents the relative size.

Lecture 10: NDPDAs/CFGs/PDAs 3

Exam 1 Notesheet

• For Exam 1, you may not use

anything other than

– Your own brain and body

– A single page (one side) of notes that

you create

• You can work with others to create

your notes page

Lecture 10: NDPDAs/CFGs/PDAs 4

Menu

• Are DPDAs

equivalent

to NDPDAs?

• Properties of

CFLs

• Equivalence

of CFGs and

NDPDAs

Lecture 10: NDPDAs/CFGs/PDAs 5

Language Classes

Regular Languages

Context-Free Languages

Violates Pumping Lemma For RLs

Violates Pumping Lemma

For CFLs

Described by DFA, NFA, RegExp, RegGram Described by CFG, NDPDA

0 n 1 n^

0 n 1 n 2 n

0 n

w

wwR^ ww

Where are DPDAs?

Lecture 10: NDPDAs/CFGs/PDAs 6

Proving Set Equivalence

A = B ⇔ A ⊆ B and B ⊇ A

Sets A and B are equivalent if A is a

subset of B and B is a subset of A.

Lecture 10: NDPDAs/CFGs/PDAs 7

Proving Formalism Equivalence

LR(M) = the set of languages that can be

recognized by some M

= { l | l ∈ P(Σ*) and there is some m ∈ M

such that L(m) = l }

A = B ⇔ LR(A) ⊆ LR(B) and LR(B) ⊇ LR(A)

Lecture 10: NDPDAs/CFGs/PDAs 8

Proving Formalism

Non-Equivalence

LR(M) = the set of languages that can be

recognized by some M

= { l | l ∈ P(Σ*) and there is some m ∈ M

such that L(m) = l }

A ≠ B ⇔ There is an l ∈ P(Σ*) that is in

LR(A) but not in LR(B)

or there is an l in LR(B) but not in LR(A)

Lecture 10: NDPDAs/CFGs/PDAs 9

Regular Languages

Context-Free Languages

Violates Pumping Described by DFA, NFA, Lemma For RLs RegExp, RegGram Described by CFG, NDPDA

0 n 1 n^

0 n 1 n 2 n

0 n

w

wwR ww

Sensible option 1: LR(NDPDA) ⊃⊃⊃⊃ LR(DPDA) ⊃⊃⊃⊃ LR(NFA) = LR(DFA)

Sensible option 2: LR(NDPDA) = LR(DPDA) ⊃⊃⊃⊃ LR(NFA) = LR(DFA)

To eliminate =, we need to find some language L that can be recognized by an NDPDA and prove it cannot be recognized by a DPDA

Lecture 10: NDPDAs/CFGs/PDAs 10

LR(NDPDA) ⊃ LR(DPDA)

A = { 0i 1 j^ | i ≥ 0, j = i or j = 2i }

A ∈ LR(NDPDA)

ε, ε→$

0 , ε→ +

ε, (^) ε→ ε

1 , +→ε ε, $ → ε

ε,

ε

ε^

1 , +→ε

1 , ε→ε

ε, $ → ε

Lecture 10: NDPDAs/CFGs/PDAs 11

LR(NDPDA) ⊃ LR(DPDA)

A = { 0i 1 j^ | i ≥ 0, j = i or j = 2i }

A ∉∉∉∉ LR(DPDA)

Proof by contradiction. Suppose there is a DPDA P that recognizes A. It must be in accept states only after processing 0 i 1 i^ and 0 i 12 i

0 ,^ α→ … β^1 , α→β

2 i transitions, consuming 0 i 1 i

,^ α→

β 1 , α→ β

i transitions, consuming 1 i

Lecture 10: NDPDAs/CFGs/PDAs 12

LR(NDPDA) ⊃ LR(DPDA)

A = { 0i 1 j^ | i ≥ 0, j = i or j = 2i }

A ∉∉∉∉ LR(DPDA)

Proof by contradiction. Suppose there is a DPDA P that recognizes A. It must be in accept states only after processing 0 i 1 i^ and 0 i 12 i

0 ,^ α→ …

β 1 , α→β

2 i transitions, consuming 0 i 1 i

, α→

β (^1) , α→ β

i transitions, consuming 2 i

2

2

L(P’) = { 0i 1 i 2 i^ | i ≥ 0}

Lecture 10: NDPDAs/CFGs/PDAs 19

Closure Properties of CFLs

If A and B are context free languages then:

AR^ is a context-free language TRUE

A*^ is a context-free language TRUE

A is a context-free language (complement)?

A ∪ B is a context-free language?

A ∩ B is a context-free language?

Lecture 10: NDPDAs/CFGs/PDAs 20

CFLs Closed Under Union

Given two CFLs A and B is A ∪ B a CFL?

Proof-by-construction: There is a CFG GAUB that recognizes A ∪ B. Since A and B are CFLs, there are CFGs GA = (VA, ΣA, RA, SA) and GB = (VB, ΣB, RB, SB) that generate A and B.

GAUB = (VA ∪ VB, ΣA ∪ ΣB, RAUB, S 0 ) RAUB = RA ∪ RB ∪ { S 0 → SA } ∪ { S 0 → SB }

Assumes VA and VB are disjoint (easy to arrange this by changing variable names.)

Lecture 10: NDPDAs/CFGs/PDAs 21

Closure Properties of CFLs

If A and B are context free languages then:

AR^ is a context-free language TRUE

A*^ is a context-free language TRUE

A is a context-free language (complement)?

A ∪ B is a context-free language TRUE

A ∩ B is a context-free language?

Lecture 10: NDPDAs/CFGs/PDAs 22

CFLs Closed Under

Complement?

• Try to find a counter-example

{ 0 i 1 i |^ i ≥ 0 } is a CFL.

Is its complement?

Yes. We can make a DPDA

that recognizes it: swap

accepting states of DPDA

that recognizes 0 i 1 i.

Not a counterexample…but not a proof either.

Lecture 10: NDPDAs/CFGs/PDAs 23

Complementing Non-CFLs

{ww | w ∈ Σ* } is not a CFL.

Is its complement?

Yes. This CFG recognizes is:

S → 0 S 0 | 1 S 1 | 0 X 1 | 1 X 0

X → 0 X 0 | 1 X 1 | 0 X 1 | 1 X 0 | 0 | 1 | ε

So, we have found a pair: P, P where one is a CFL and the other is not. Thus, CFLs are not closed under complement.

Opps! As Danni pointed out in class, this is badly broken. We will fix it next class…

Lecture 10: NDPDAs/CFGs/PDAs 24

Closure Properties of CFLs

If A and B are context free languages then:

AR^ is a context-free language TRUE

A*^ is a context-free language TRUE

A is not necessarily a context-free

language (complement)

A ∪ B is a context-free language TRUE

A ∩ B is a context-free language? Left for you to solve

(possibly on Exam 1)

Lecture 10: NDPDAs/CFGs/PDAs 25

Charge

• Thursday and Tuesday: some

interesting applications of CFGs