Top Banner
1 Lecture 9 • Recursive and r.e. language classes – representing solvable and unsolvable problems • Proofs of closure properties – for the set of recursive (solvable) languages – for the set of r.e. (half-solvable) languages • Generic element/template proof technique • Relationship between RE and REC – pseudoclosure property
49

1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

Dec 19, 2015

Download

Documents

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: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

1

Lecture 9

• Recursive and r.e. language classes– representing solvable and unsolvable problems

• Proofs of closure properties – for the set of recursive (solvable) languages– for the set of r.e. (half-solvable) languages

• Generic element/template proof technique• Relationship between RE and REC

– pseudoclosure property

Page 2: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

2

RE and REC language classes

• REC– A solvable language is commonly referred to as

a recursive language for historical reasons– REC is defined to be the set of solvable or

recursive languages

• RE– A half-solvable language is commonly referred

to as a recursively enumerable or r.e. language– RE is defined to be the set of r.e. or half-

solvable languages

Page 3: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

3

Why study closure properties of RE and REC?

• It tests how well we really understand the concepts we encounter– language classes, REC, solvability, half-solvability

• It highlights the concept of subroutines and how we can build on previous algorithms to construct new algorithms– we don’t have to build our algorithms from scratch

every time

Page 4: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

4

Example Application• Setting

– I have two programs which can solve the language recognition problems for L1 and L2

– I want a program which solves the language recognition problem for L1 intersect L2

• Question– Do I need to develop a new program from scratch

or can I use the existing programs to help?• Does this depend on which languages L1 and L2 I am

working with?

Page 5: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

5

Closure Properties of REC

• We now prove REC is closed under two set operations– Set Complement– Set Intersection

• In these proofs, we try to highlight intuition and common sense

Page 6: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

6

Quick Questions

• What does the following statement mean?– REC is closed under the set complement

operation

• How do you prove a language L is in REC?

Page 7: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

7

Set Complement Example

• Even: the set of even length strings over {0,1}• Complement of Even?

– Odd: the set of odd length strings over {0,1}

• Is Odd recursive (solvable)?• How is the program P’ which solves Odd related

to the program P which solves Even?

Page 8: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

8

Set Complement Lemma

• If L is a solvable language, then L complement is a solvable language– Rewrite this in first-order logic

• Proof– Let L be an arbitrary solvable language

• First line comes from For all L in REC

– Let P be the C++ program which solves L• P exists by definition of REC

Page 9: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

9

– Modify P to form P’ as follows• Identical except at very end

• Complement answer – Yes -> No– No -> Yes

– Program P’ solves L complement• Halts on all inputs

• Answers correctly

– Thus L complement is solvable• Definition of solvable

proof continued

Page 10: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

10

P’ Illustration

PInput x

YES

No

P’

YES

No

Page 11: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

11

Code for P’

bool main(string y)

{

if (P (y)) return no; else return yes;

}

bool P (string y) /* details unknown */

Page 12: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

12

Set Intersection Example

• Even: the set of even length strings over {0,1}• Mod-5: the set of strings of length a multiple of 5

over {0,1}• What is Even intersection Mod-5?

– Mod-10: the set of strings of length a multiple of 10 over {0,1}

• How is the program P3 (Mod-10) related to programs P1 (Even) and P2 (Mod-5)

Page 13: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

13

Set Intersection Lemma

• If L1 and L2 are solvable languages, then L1 intersection L2 is a solvable language

– Rewrite this in first-order logic

– Note we have two languages because intersection is a binary operation

• Proof– Let L1 and L2 be arbitrary solvable languages

– Let P1 and P2 be programs which solve L1 and L2, respectively

Page 14: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

14

– Construct program P3 from P1 and P2 as follows

• P3 runs both P1 and P2 on the input string

• If both say yes, P3 says yes

• Otherwise, P3 says no

– P3 solves L1 intersection L2 • Halts on all inputs

• Answers correctly

– L1 intersection L2 is a solvable language

proof continued

Page 15: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

15

P3 Illustration

P1

P2

Yes/No

Yes/No

ANDYes/No

P3

Page 16: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

16

Code for P3

bool main(string y)

{

if (P1(y) && P2(y)) return yes;

else return no;

}

bool P1(string y) /* details unknown */

bool P2(string y) /* details unknown */

Page 17: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

17

Other Closure Properties

• Unary Operations– Language Reversal– Kleene Star

• Binary Operations– Set Union– Set Difference– Symmetric Difference– Concatenation

Page 18: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

18

Closure Properties of RE

• We now try to prove RE is closed under the same two set operations– Set Intersection – Set Complement

• In these proofs– We define a more formal proof methodology– We gain more intuition about the differences

between solvable and half-solvable problems

Page 19: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

19

Quick Questions

• What does the following statement mean?– RE is closed under the set intersection

operation

• How do you prove a language L is in RE?

Page 20: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

20

RE Closed Under Set Intersection

• First-order logic formulation?– For all L1, L2 in RE, L1 intersect L2 in RE

– For all L1, L2 ((L1 in RE) and (L2 in RE) --> ((L1 intersect L2) in RE)

• What this really means– Let Li denote the ith r.e. language

• L1 intersect L1 is in RE

• L1 intersect L2 is in RE

• ...

• L2 intersect L1 is in RE

• ...

Page 21: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

21

Generic Element or Template Proofs

• Since there are an infinite number of facts to prove, we cannot prove them all individually

• Instead, we create a single proof that proves each fact simultaneously

• I like to call these proofs generic element or template proofs

Page 22: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

22

Basic Proof Ideas• Name your generic objects

– In this case, we use L1 and L2

• Only use facts which apply to any relevant objects– We will only use the fact that there must exist P1 and

P2 which half-solve L1 and L2

• Work from both ends of the proof– The first and last lines are usually obvious, and we can

often work our way in

Page 23: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

23

Set Intersection Example

• Let L1 and L2 be arbitrary r.e. languages

• L1 intersection L2 is an r.e. language

• There exist P1 and P2 s.t. Y(P1)=L1 and Y(P2)=L2

– By definition of half-solvable languages

• There exists a program P which half-solves L1 intersection L2

• Construct program P3 from P1 and P2

– Note, we can assume very little about P1 and P2

• Prove Program P3 half-solves L1 intersection L2

Page 24: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

24

Constructing P3

• What did we do in the REC setting?

• Build P3 using P1 and P2 as subroutines

• We just have to be careful now in how we use P1 and P2

Page 25: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

25

Constructing P3

• Run P1 and P2 in parallel

– One instruction of P1, then one instruction of P2, and so on

• If both halt and say yes, halt and say yes

• If both halt but both do not say yes, halt and say no– Note, if either never halts, P3 never halts

Page 26: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

26

P3 Illustration

P1

P2

Yes/No/-

Yes/No/-

ANDYes/No/-

P3

Input

Page 27: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

27

Code for P3

bool main(string y)

{

parallel-execute(P1(y), P2(y)) until both return;

if ((P1(y) && P2(y)) return yes;

else return no;

}

bool P1(string y) /* details unknown */

bool P2(string y) /* details unknown */

Page 28: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

28

Proving P3 Is Correct

• 2 steps to showing P3 half-solves L1 intersection L2

– For all x in L1 intersection L2, must show P3 • accepts x

– halts and says yes

– For all x not in L1 intersection L2, must show P3 • rejects x or• loops on x or• crashes on x

Page 29: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

29

Part 1 of Correctness Proof

• P3 accepts x in L1 intersection L2

– Let x be an arbitrary string in L1 intersection L2

• Note, this subproof is a generic element proof

– P1 accepts x

• L1 intersection L2 is a subset of L1

• P1 accepts all strings in L1

– P2 accepts x

– P3 accepts x• We reach the AND gate because of the 2 previous facts

• Since both P1 and P2 accept, AND evaluates to YES

Page 30: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

30

Part 2 of Correctness Proof• P3 does not accept x not in L1 intersection L2

– Let x be an arbitrary string not in L1 intersection L2

– By definition of intersection, this means x is not in L1 or L2

– Case 1: x is not in L1 • 2 possibilities

• P1 rejects (or crashes on) x

– One input to AND gate is No– Output cannot be yes

– P3 does not accept x

• P1 loops on x

– One input never reaches AND gate– No output

– P3 loops on x

• P3 does not accept x when x is not in L1

– Case 2: x is not in L2

• Essentially identical analysis

– P3 does not accept x not in L1 intersection L2

Page 31: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

31

RE closed under set complement?

• First-order logic formulation?– For all L in RE, L complement in RE– For all L (L in RE) --> ((L complement) in RE)

• What this really means– Let Li denote the ith r.e. language

• L1 complement is in RE

• L2 complement is in RE

• ...

Page 32: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

32

Set complement proof overview

• Let L be an arbitrary r.e. language

• L complement is an r.e. language

• There exists P s.t. Y(P)=L– By definition of r.e. languages

• There exists a program P’ which half-solves L complement

• Construct program P’ from P– Note, we can assume very little about P

• Prove Program P’ half-solves L complement

Page 33: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

33

Constructing P’• What did we do in recursive case?

– Run P and then just complement answer at end• Accept -> Reject• Reject -> Accept

• Does this work in this case?– No. Why not?

• Accept->Reject and Reject ->Accept ok• Problem is we need to turn Loop->Accept

– this requires solving the halting problem

Page 34: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

34

What can we conclude?

• Previous argument only shows that the approach used for REC does not work for RE

• This does not prove that RE is not closed under set complement

• Later, we will prove that RE is not closed under set complement

Page 35: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

35

Other closure properties

• Unary Operations– Language reversal– Kleene Closure

• Binary operations– union– concatenation

• Not closed– Set difference

Page 36: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

36

Closure Property Applications

• How can we use closure properties to prove a language LT is r.e. or recursive?

• Unary operator op (e.g. complement)– 1) Find a known r.e. or recursive language L

– 2) Show LT = L op

• Binary operator op (e.g. intersection)– 1) Find 2 known r.e or recursive languages L1 and L2

– 2) Show LT = L1 op L2

Page 37: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

37

Closure Property Applications

• How can we use closure properties to prove a language LT is not r.e. or recursive?

• Unary operator op (e.g. complement)– 1) Find a known not r.e. or non-recursive language L

– 2) Show LT op = L

• Binary operator op (e.g. intersection)– 1) Find a known r.e. or recursive language L1

– 2) Find a known not r.e. or non-recursive language L2

– 2) Show L2 = L1 op LT

Page 38: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

38

Example

• Looping Problem– Input

• Program P

• Input x for program P

– Yes/No Question• Does P loop on x?

• Looping Problem is unsolvable– Looping Problem complement = H

Page 39: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

39

Closure Property Applications

• Proving a new closure property

• Theorem: Unsolvable languages are closed under set complement– Let L be an arbitrary unsolvable language

– If Lc is solvable, then L is solvable• (Lc)c = L

• Solvable languages closed under complement

– However, we are assuming that L is unsolvable

– Therefore, we can conclude that Lc is unsolvable

– Thus, unsolvable languages are closed under complement

Page 40: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

40

Pseudo Closure Property

• Lemma: If L and Lc are half-solvable, then L is solvable.

• First-order logic?– For all L in RE, (Lc in RE) --> (L in REC)

– For all L, ((L in RE) and (Lc in RE)) --> (L in REC)

• Question: What about Lc?– Also solvable because REC closed under set

complement

Page 41: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

41

High Level Proof

– Let L be an arbitrary language where L and Lc are both half-solvable

– Let P1 and P2 be the programs which half-solve L and Lc, respectively

– Construct program P3 from P1 and P2

• Argue P3 solves L

– L is solvable

Page 42: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

42

Constructing P3

• Problem– Both P1 and P2 may loop on some input strings,

and we need P3 to halt on all input strings

• Key Observation– On all input strings, one of P1 and P2 is

guaranteed to halt. Why?• Nature of complement operation

Page 43: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

43

Illustration

*

L

P1 halts

Lc

P2 halts

Page 44: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

44

Construction and Proof

• P3’s Operation

– Run P1 and P2 in parallel on the input string x until one accepts x

• Guaranteed to occur given previous argument

• Also, only one program will accept any string x

– IF P1 is the accepting machine THEN yes ELSE no

Page 45: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

45

P3 Illustration

P1

P2

Yes

Yes

P3

Input

Yes

No

Page 46: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

46

Code for P3

bool main(string y)

{

parallel-execute(P1(y), P2(y)) until one returns yes;

if (P1(y)) return yes;

if (P2(Y)) return no;

}

bool P1(string y) /* details unknown */

bool P2(string y) /* details unknown */

Page 47: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

47

Question

• What if P2 rejects the input?

• Our description of P3 doesn’t describe what we should do in this case.– If P2 rejects the input, then the input must be in

L

– This means P1 will eventually accept the input.

– This means P3 will eventually accept the input.

Page 48: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

48

RE and REC

REC

RE

All Languages

L Lc

Page 49: 1 Lecture 9 Recursive and r.e. language classes –representing solvable and unsolvable problems Proofs of closure properties –for the set of recursive (solvable)

49

RE and REC

REC

RE

All Languages

LLc

Lc

Lc

Are there any languages L in RE - REC?