Top Banner
CSCI 2670 Introduction to Theory of Computing September 15, 2004
22

CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Dec 17, 2015

Download

Documents

Norman Hill
Welcome message from author
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
Page 1: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

CSCI 2670Introduction to Theory of

Computing

September 15, 2004

Page 2: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Agenda

• Yesterday– Pumping lemma review

• Today– Prove the pumping lemma– Introduce context-free grammars

Page 3: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Announcement

• Quiz tomorrow– CGF parse trees & interpretation– Pumping lemma

Page 4: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Nonregular languages

• There are many nonregular languages– {0n1n | n 0}– {101,101001,1010010001,…}– {w | w has the same number of 0s and

1s}• All regular languages can be

generated by finite automata• States must be reused if the length of

a string is greater than the number of states– If states are reused, there will be

repetition

Page 5: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

The pumping lemma

Theorem: If A is a regular language, then there is a number p where, if s is any string in A of length at least p, then s may be divided into three pieces, s = xyz, satisfying the following conditions

1. for each i 0, xyiz is in A2. |y| > 0, and3. |xy| p

p is called the pumping length

Page 6: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Proof idea

• Pumping length is equal to the number of states in the DFA whose language is A– p = |Q|

• If A accepts a word w with |w| > p, then some state must be entered twice while processing w– Pigeonhole principle

Page 7: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Proof idea

1. for each i 0, xyiz is in A2. |y| > 0, and3. |xy| p

x

y

z

Page 8: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Proof

• Let A be any regular language

• Find DFA M=(Q,,,q0,F) with L(M)=A

• Let p=|Q|

• Let s=s1s2s3…sn be any string in A with |s| = n p– What if no such s is in A?

Page 9: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Proof (cont.)

• Let r1, r2, r3, …, rn+1 be the sequence of states entered while processing s– r1 = q0

– rn+1 F

– ri+1 = (ri, si)

Page 10: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Proof (cont.)

• Consider the first p+1 elements of this sequence– p+1 states must contain a repeated

state

• Let rk be the first state to be repeated and let rt be the second occurance of this state– t p+1

Page 11: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Proof (cont.)

• Let x=s1s2…sk-1, y=sksk+1…st-1, z=stst+1…sn

• There is an error in the proof on page 79 of Sipser (y is incorrectly defined)

– x takes M from r1 to rk

– y takes M from rk to rt

– z takes M from rt to rn+1, which is an accept state

• Since rk and rt are the same state, M must accept xyiz for any i=0, 1, 2, …

Page 12: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Proof (cont.)

• Have we satisfied the conditions of the theorem?

1. for each i 0, xyiz is in A

2. |y| > 0, and

3. |xy| p

• Have we satisfied the conditions of the theorem?

1. for each i 0, xyiz is in A Yes

2. |y| > 0, and Yes since t > k and y=sksk+1…st-1

3. |xy| p Yes since t p+1 and xy = s1s2…st-1

Page 13: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Regular languages -- Summary

• Let R be any language. The following are equivalent

1. R is a regular language2. R = L(M) for some finite automata

M, where M is a DFA, an NFA, or a GNFA

3. R is describe by some regular expression

4. R has a pumping length of p• If R can be shown not to have a

finite pumping length, then R is not regular

Page 14: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Context-free grammars

• The shortcoming of finite automata is that each state has very limited meaning– You have no memory of where you’ve

been – only knowledge of where you are

• Context-free grammars are a more powerful method of describing languages– Example: {0n1n | n 0} is a CFG

Page 15: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Example CFG

• Context-free grammars use substitution to maintain knowledge

S (S)S SSS ()

• All possible legal parenthesis pairings can be expressed by consecutive applications of these rules

• Is this a regular language?

Page 16: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Example

S (S) | SS | ()• (()())(())• S SS

(S)(S) (SS)(()) (()())(())

• This sequence of substitutions is called a derivation

Page 17: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Parse tree

S (S) | SS | ()S

SS

SS

()()()

S

)(

S

( )

Page 18: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Example 2

S Sb | BbB aBb | aCbC ε

• Derivation for aaabbbbbSSb

BbbaaBbbbbaaaεbbbbb

aBbbbaaaCbbbbb

Page 19: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Example 2 parse tree

S

ε

S

b

B

b

B

a b

B

a bba

C

Page 20: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Example 2

S Sb | BbB aBb | aCbC ε

Question 1: What language does this grammar accept?

Answer: {anbm | m > n > 0}Question 2: Can this CFG be simplified?Answer: yes.

Replace BaCb with Bab and remove Cε

Page 21: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Other languages described by CFG’s

• The foxtrot– http://linus.socs.uts.edu.au/~don/pubs/foxtrot.html

• A type of Tamil poetry called Venpa

• Ancient language of Sanscrit– http://en.wikipedia.org/wiki/Context-free_grammar

Page 22: CSCI 2670 Introduction to Theory of Computing September 15, 2004.

Tomorrow

• Formal definition for CFG• Designing CFG’s