Top Banner
1 Module 10 • Recursive and r.e. language classes – representing solvable and half- solvable problems • Proofs of closure properties – for the set of recursive (solvable) languages – for the set of r.e. (half-solvable) languages • Generic Element proof technique
41

1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

Dec 22, 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 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

1

Module 10

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

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

• Generic Element proof technique

Page 2: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

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 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

3

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 4: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

4

REC and Set Complement

RECEVEN

All Languages

ODD• Even: set of even length strings

• Is Even solvable (recursive)?

• Give a program P that solves it.

• Complement of Even?– Odd: set of odd length strings

• Is Odd recursive (solvable)?

• Does this prove REC is closed under set complement?

• How is the program P’ that solves Odd related to the program P that solves Even?

Page 5: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

5

P’ Illustration

PInput x Yes/No

P’

No/Yes

Page 6: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

6

Code for P’

bool main(string y)

{

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

}

bool P (string y)

/* details deleted; key fact is P is guaranteed to halt on all inputs */

Page 7: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

7

Set Complement Lemma

• If L is a solvable language, then L complement is a solvable language

• 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 8: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

8

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

9

REC Closed Under Set Union

All Languages

L1

L2

L1 U L2

REC

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

• Proof– Let L1 and L2 be arbitrary

solvable languages

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

Page 10: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

10

REC Closed Under Set Union

All Languages

L1

L2

L1 U L2

REC

– Construct program P3 from P1 and P2 as follows

– P3 solves L1 U L2 • Halts on all inputs• Answers correctly

– L1 U L2 is solvable

Page 11: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

11

Yes/No

Yes/No

P3 Illustration

P1

P2

ORYes/No

P3

Page 12: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

12

Code for P3

bool main(string y) {

if (P1(y)) return yes;

else if (P2(y)) return yes;

else return no;

}bool P1(string y) /* details deleted; key fact is P1 always halts. */

bool P2(string y) /* details deleted; key fact is P2 always halts. */

Page 13: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

13

Other Closure Properties

• Unary Operations– Language Reversal– Kleene Star

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

Page 14: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

14

Closure Properties of RE *

• We now try to prove RE is closed under the same two set operations– Set Union – 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 15: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

15

RE Closed Under Set Union

• Expressing this closure property as an infinite set of facts– 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 16: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

16

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 17: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

17

Basic Proof Ideas• Name your generic objects

– For example, L or L1 or L2

• Only use facts which apply to any relevant objects– For example, there must exist a program P1 that half-

solves L1

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

often work our way in

Page 18: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

18

RE Closed Under Set UnionL1

L2

L1 U L2

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

• L1 U L2 is an r.e. language

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

• There exists a program P that half-solves L1 U L2

• Construct program P3 from P1 and P2

• Prove Program P3 half-solves L1 U L2

Page 19: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

19

• What code did we use for P3 when we worked with solvable languages?

Constructing Program P3

L1

L2

L1 U L2

bool main(string y) {

if (P1(y)) return yes;

else if (P2(y)) return yes;

else return no;}bool P1(string y) /* details deleted; key fact is P1 always halts. */

bool P2(string y) /* details deleted; key fact is P2 always halts. */

• Will this code work for half-solvable languages?

Page 20: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

20

Proving P3 Is Correct

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

– For all x in L1 U L2, must show P3

– For all x not in L1 U L2, must show P3

Page 21: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

21

P3 works correctly?

– Let x be an arbitrary string in L1 U L2

• Note, this subproof is a generic element proof

– What are the two possibilities for x?• x is in L1

• x is in L2

– What does P3 do if x is in L1?• Does it matter if x is in or not in L2?

– What does P3 do if x is in L2?• Does it matter if x is in or not in L1?

– Does P3 work correctly on such x?• If not, what strings cause P3 a problem?

bool main(string y) {

if (P1(y)) return yes;

else if (P2(y)) return yes;

else return no;

}

Page 22: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

22

P3 works correctly?

– Let x be an arbitrary string NOT in L1 U L2

• Note, this subproof is a generic element proof

– x is not in L1 AND x is not in L2

– What does P3 do on x in this case?

• What does P1 do on x?

• What does P2 do on x?

– Does P3 work correctly on such x?

bool main(string y) {

if (P1(y)) return yes;

else if (P2(y)) return yes;

else return no;

}

Page 23: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

23

Code for Correct P3

bool main(string y){if ((P1(y) || P2(y)) return yes; /* P1 and P2 run in parallel (alternating execution) */

else return no;}bool P1(string y)

/* key fact is P1 only guaranteed to halt on yes input instances */

bool P2(string y) /* key fact is P2 only guaranteed to halt on yes input instances */

Page 24: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

24

P3 works correctly?

– Let x be an arbitrary string in L1 U L2

• Note, this subproof is a generic element proof

– What are the two possibilities for x?• x is in L1

• x is in L2

– What does P3 do if x is in L1?• Does it matter if x is in or not in L2?

– What does P3 do if x is in L2?• Does it matter if x is in or not in L1?

– Does P3 work correctly on such x?• If not, what strings cause P3 a problem?

bool main(string y){ if ((P1(y) || P2(y)) return yes; else return no;}/* P1 and P2 run in parallel */

Page 25: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

25

• First-order logic formulation for statement– RE is closed under set complement

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

• L1 complement is in RE

• L2 complement is in RE

• ...

RE and Set complement L

LcRE

Page 26: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

26

RE and Set complement

• Let L be an arbitrary r.e. language

• L complement is an r.e. language

• There exists P s.t. Y(P)=L

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

• Construct program P’ from P• Prove Program P’ half-solves L complement

LLc

RE

Page 27: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

27

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?

• Does this prove that RE is not closed under set complement?

Page 28: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

28

Other closure properties

• Unary Operations– Language reversal– Kleene Closure

• Binary operations– set intersection– concatenation

• Not closed– Set difference (on practice hw)

Page 29: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

29

Pseudo Closure Property

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

• Question: What about Lc?

Page 30: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

30

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 31: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

31

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?

Page 32: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

32

Illustration

*

L

P1 halts

Lc

P2 halts

Page 33: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

33

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 34: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

34

P3 Illustration

P1

P2

Yes

Yes

P3

Input

Yes

No

Page 35: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

35

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) /* guaranteed to halt on strings in L*/

bool P2(string y) /* guaranteed to halt on strings in Lc */

Page 36: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

36

RE and REC

REC

RE

All Languages

L Lc

Page 37: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

37

RE and REC

REC

RE

All Languages

LLc

Lc

Lc

Are there any languages L in RE - REC?

Page 38: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

38

RE and REC

REC

RE

All Languages

H

So where does Hc belong?

Hc

Page 39: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

39

Closure Property Questions

• Which of the following imply L is solvable given REC is closed under set union?– L1 U L2 = L

– L1 U L = L2

– L U L2 = L1

• In all cases, L1 and L2 are known to be solvable

Page 40: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

40

Closure Property Questions

• Which of the following imply L is NOT solvable given REC is closed under set union?– L1 U L2 = L

– L1 U L = L2

– L U L2 = L1

• In all cases, L1 is solvable and L2 is NOT solvable

Page 41: 1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.

41

Summary• Definition of REC and RE

• Proofs of some closure properties for both language classes– RE more complex

• Pseudo-closure Property

• RE is not closed under set complement

• Proving a language is or is not in a language class using closure properties