1 lecture 14 language class lfsa –study limits of what can be done with fsa’s –closure...

30
1 Lecture 14 • Language class LFSA – Study limits of what can be done with FSA’s – Closure Properties – Comparing to other language classes

Post on 19-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

1

Lecture 14

• Language class LFSA– Study limits of what can be done with FSA’s– Closure Properties– Comparing to other language classes

Page 2: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

2

LFSA Unit Overview

• Study limits of LFSA– Understand what languages are in LFSA

• Develop techniques for showing L in LFSA

– Understand what languages are not in LFSA• Develop techniques for showing L not in LFSA

• Prove Closure Properties of LFSA

• Identify relationship of LFSA to other language classes

Page 3: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

3

Closure Properties of LFSA

Remember ideas from REC

Page 4: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

4

LFSA closed under set complement

• If L is in LFSA, then Lc is in LFSA• Proof

– Let L be an arbitrary language in LFSA

– Let M be the FSA such that L(M) = L• M exists by definition of L in LFSA

– Construct FSA M’ from M

– Argue L(M’) = Lc

– There exists an FSA M such that L(M’) = Lc

– Lc is in LFSA

Page 5: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

5

Visualization

LFSA LFSA

L Lc

M M’

FSA’s FSA’s

•Let L be an arbitrary language in LFSA•Let M be the FSA such that L(M) = L

•M exists by definition of L in LFSA

•Construct FSA M’ from M•Argue L(M’) = Lc

•Lc is in LFSA

Page 6: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

6

Construct FSA M’ from M

• What did when we proved that REC is closed under set complement?

• Construct program P’ from program P– P’ is basically the same program as program P

– The only difference comes at the end

– If P is about to return no, P’ returns yes instead

– If P is about to return yes, P’ returns no instead

• Can we translate this to FSA setting?

Page 7: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

7

Construct FSA M’ from M

• M = (Q, , q0, A, )

• M’ = (Q’, ’, q’, A’, ’)– M’ should say yes when M says no– M’ should say no when M says yes– How?

• Q’ = Q• ’ = • q’ = q0’

• ’ = • A’ = Q-A

Page 8: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

8

Example

1

2

3

a

a

a

b

b

b

FSA M

1

2

3

a

a

a

b

b

b

FSA M’

Q’ = Q’ = q’ = q0’’ = A’ = Q-A

Page 9: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

9

Construction is an algorithm

• Set Complement Construction– Algorithm Specification

• Input: FSA M

• Output: FSA M’ such that L(M’) = L(M)c

– Comments• This algorithm can be in any computational model.

– It does not have to be (and typically is not) an FSA

• These set closure constructions are useful. – More on this later

Construction Algorithm

FSA M

FSA M’

Page 10: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

10

Construction is an algorithm

• Your algorithm must give a complete specification of M’ in terms of M– Example:

• Let input FSA M = (Q, , q0, A, )

• Output FSA M’ = (Q’, ’, q’, A’, ’) where – Q’ = Q– ’ = – q’ = q0’

– ’ = – A’ = Q-A

• When describing such constructions, I will often only focus on the critical component, in this case A’ = Q-A, but you must specify all components of M’ in terms of M.

Construction Algorithm

FSA M

FSA M’

Page 11: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

11

LFSA closed under Set Intersection Operation

(also set union, set difference, and symmetric difference)

Page 12: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

12

LFSA closed under set intersection operation

• Let L1 and L2 be arbitrary languages in LFSA

• Let M1 and M2 be FSA’s s.t. L(M1) = L1, L(M2) = L2

– M1 and M2 exist by definition of L1 and L2 in LFSA

• Construct FSA M3 from FSA’s M1 and M2

• Argue L(M3) = L1 intersect L2

• There exists FSA M3 s.t. L(M3) = L1 intersect L2

• L1 intersect L2 is in LFSA

Page 13: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

13

Visualization

•Let L1 and L2 be arbitrary languages in LFSA•Let M1 and M2 be FSA’s s.t. L(M1) = L1, L(M2) = L2

•M1 and M2 exist by definition of L1 and L2 in LFSA

•Construct FSA M3 from FSA’s M1 and M2

•Argue L(M3) = L1 intersect L2

•There exists FSA M3 s.t. L(M3) = L1 intersect L2

•L1 intersect L2 is in LFSA

L1 intersect L2

L1

L2

LFSA

M3

M1

M2

FSA’s

Page 14: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

14

Algorithm Specification

• Input– Two FSA’s M1 and M2

• Output– FSA M3 such that L(M3) = L(M1) intersection L(M2)

FSA M1

FSA M2

FSA M3Alg

Page 15: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

15

Use Old Ideas

• Key concept: Try ideas from previous closure property proofs

• Example– How did the algorithm for proving recursive languages

are closed under set intersection work?• Run both input programs on the input string

• Say yes only if both say yes

– Try to create an FSA M3 that simultaneously runs M1 and M2 on the input string

FSA M1

FSA M2

FSA M3Alg

Page 16: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

16

1

Run M1 and M2 Simultaneously

0 20

0

0

0

1

1

1

1

M1

A B0

1 0,1

M2

,A 0,A 1,A 2,A

,B 0,B 1,B 2,B

M3

What happens when M1 and M2 run on input string 11010?

FSA M1

FSA M2

FSA M3Alg

Page 17: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

17

Construction

• Input – FSA M1 = (Q1, , q1, , A1)

– FSA M2 = (Q2, , q2, , A2)

• Output– FSA M3 = (Q3, , q3, , A3)

– What is Q3?

• Q3 = Q1 X Q2 where X is cartesian product

• In this case, Q3 = {(,A), (,B), (0,A), (0,B), (1,A), (1,B), (2,A), (2,B)}

– What is 3?

• 3 = 1 = 2

• In this case, 3 = {0,1}

1 0 20

000

1

11

1

M1

A B0

1 0,1

M2

Page 18: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

18

Construction

• Input – FSA M1 = (Q1, , q1, , A1)

– FSA M2 = (Q2, , q2, , A2)

• Output– FSA M3 = (Q3, , q3, , A3)

– What is q3?

• q3 = (q1, q2)

• In this case, q3 = (,A)

– What is A3?

• A3 = {(p, q) | p in A1 and q in A2}

• In this case, A3 = {(0,B)}

1 0 20

000

1

11

1

M1

A B0

1 0,1

M2

Page 19: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

19

Construction

• Input – FSA M1 = (Q1, , q1, , A1)

– FSA M2 = (Q2, , q2, , A2)

• Output– FSA M3 = (Q3, , q3, , A3)

– What is 3?

• For all p in Q1, q in Q2, a in , 3((p,q),a) = (1(p,a),2(q,a))

• In this case,– 3((0,A),0) = (1(0,0),2(A,0))

– = (0,B)

– 3((0,A),1) = (1(0,1),2(A,1))

– = (1,A)

1 0 20

000

1

11

1

M1

A B0

1 0,1

M2

Page 20: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

20

Example Summary

1 0 200

01

1

1

M1

A B0

1 0,1

M2

,A 0,A 1,A 2,A

,B 0,B 1,B 2,B

M3

0 1

0

1

0

1

0

1

0

1

0

1 0

1

Page 21: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

21

Observation

• Input – FSA M1 = (Q1, , q1, , A1)

– FSA M2 = (Q2, , q2, , A2)

• Output– FSA M3 = (Q3, , q3, , A3)

– What is A3?

• A3 = {(p, q) | p in A1 and q in A2}

• What if operation were different?– Set union, set difference, symmetric difference

Page 22: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

22

Observation continued

• Input – FSA M1 = (Q1, , q1, , A1)

– FSA M2 = (Q2, , q2, , A2)

• Output– FSA M3 = (Q3, , q3, , A3)

– What is A3?

• Set intersection: A3 = {(p, q) | p in A1 and q in A2}

• Set union: A3 = {(p, q) | p in A1 or q in A2}

• Set difference: A3 = {(p, q) | p in A1 and q not in A2}

• Symmetric difference: A3 = {(p, q) | (p in A1 and q not in A2) or (p not in A1 and q in A2) }

Page 23: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

23

Observation conclusion

• LFSA is closed under– set intersection

– set union

– set difference

– symmetric difference

• The constructions used to prove these closure properties are essentially identical

Page 24: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

24

Comments• You should be able to execute this algorithm

– Convert two FSA’s into a third FSA with the correct properties.

• You should understand the idea behind this algorithm– The third FSA essentially runs both input FSA’s simultaneously on

any input string

– How we set A3 depending on the specific set operation

• You should understand the importance of this algorithm– Design tool

• Suppose you need to build an FSA to accept some language L3

• You observe L3 = L1 intersection L2

• You already have or can easily build FSA’s to accept L1 and L2

• Use this algorithm on those FSA’s to constrct an FSA to accept L3

• You should be able to construct new algorithms for new closure property proofs

Page 25: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

25

Comparing language classes

Showing LFSA is a subset of REC

Page 26: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

26

LFSA subset REC

• Proof– Let L be an arbitrary language in LFSA– Let M be an FSA such that L(M) = L

• M exists by definition of L in LFSA

– Construct program P from FSA M– Argue P decides L– There exists a program P which decides L– L is recursive

Page 27: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

27

Visualization

LFSAREC

FSA’s C++ Programs

L L

M P

•Let L be an arbitrary language in LFSA•Let M be an FSA such that L(M) = L

•M exists by definition of L in LFSA•Construct C++ program P from FSA M•Argue P decides L•There exists a program P which decides L•L is recursive

Page 28: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

28

Comparison

L1 intersect L2

L1

L2

LFSA

M3

M1

M2

FSA’s

LNFAREC

NFA’s C++ Programs

L L

M P

Page 29: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

29

Construction

• The construction is again an algorithm A– Input to A: FSA M– Output of A: C++ program P such that P decides

L(M)– Informal description of algorithm

• Implement FSA M as C++ program using switch statements, etc.

Construction Algorithm

FSA M

Program P

Page 30: 1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes

30

Comparing computational models

• The previous slides show one method for comparing the relative power of two different computational models– Computational model CM1 is at least as general or

powerful as computational model CM2 if

• Any program P2 from computational model CM2 can be converted into an equivalent program P1 in computational model CM1.

– Question: How can we show two computational models are equivalent?