Department of Computer & Information Sciences Recursive Languages Pakistan Institute of Engineering and Applied Sciences Definition: A recursive language L is a for which there exists a TM that will halt and accept an input string in L, and Recursively Enumerable halt and reject, otherwise. and RiRecursive Languages ElExample: The of determining whether a natural number is a perfect square (represented by using the string an) is decidable.

Based on slides by Costas Busch [http://csc.lsu.edu/~busch] Umar Faiz http://www.pieas.edu.pk/umarfaiz/cis317

1 2

Recursive Languages Recursively Enumerable Languages Let L be a recursive language and M the Definition: that accepts it A language is recursively enumerable if some Turing For string : w machine accepts it

If w ∈ L then M halts in a final state Let L be a recursively enumerable language and M the Turi ng Machi ne that accept s it If w ∉ L then M halts in a non-final state For string : w If w ∈ L then M halts in a final state If w ∉ L then M halts in a non-final state and loops forever

Costas Busch - RPI 3 Costas Busch - RPI 4

Non Recursively Enumerable Context-Free Languages We will prove: Technical Note: Type-1 languages explicitly Type-0 Languages 1. There is a specific language which is not recursively exclude the null string. All other language (Recursively Enum.) enumerable (not accepted by any Turing Machine) families permit the null Recursive string as a member. Languages (The Venn diagram is in slight error because 2. There is a specific language which is recursively of this technicality.) enumerable but not recursi ve Type-1 (Context-sensitive) Languages Type-2 (Context-free) Languages Linear (Context-free) Type-3 Languages (Regular) Languages Costas Busch - RPI 5 6

1 Non Recursively Enumerable

Recursively Enumerable A Language which is not Recursively Enumerable

Recursive

7 Costas Busch - RPI 8

Non Recursively Enumerable Non Recursively Enumerable • We want to find a language that is Non Recursively Enumerable Consider alphabet {a} • This language is not accepted by any Turing Machine Strings: a, aa, aaa, aaaa, K 1 2 3 4 a a a a L Consider Turing Machines that accept languages over alphabet {a} They are countable:

M1, M 2, M3, M 4, K

Costas Busch - RPI 9 Costas Busch - RPI 10

Non Recursively Enumerable Non Recursively Enumerable

1 2 3 4 Example language accepted by Mi a a a a L L(Mi ) = {aa,aaaa,aaaaaa} 2 4 6 L(M1) 0 110 L L(Mi ) = {a ,a ,a } 1010 Alternative representation L(M2) L 1 2 3 4 5 6 7 a a a a a a a L L(M3) 0111 L L(Mi ) 0 1110 0 0 L L(M4) 010 0 L

Costas Busch - RPI 11 Costas Busch - RPI 12

2 Non Recursively Enumerable Non Recursively Enumerable

1 2 3 4 Consider the language a a a a L i i L(M1) 0 110 L L = {a : a ∈ L(Mi )} L(M2) 1 0 0 1 L

L(M3) 0111 L

L(M4) 010 0 L L consists from the 1’s in the diagonal 3 4 L = {a ,a ,K} Costas Busch - RPI 13 Costas Busch - RPI 14

Non Recursively Enumerable Non Recursively Enumerable Consider the language L 1 2 3 4 a a a a L L(M1) 0 110 L i i L = {a : a ∈ L(Mi )} L(M2) 1010 L i i L(M ) L = {a : a ∉ L(Mi )} 3 0111 L L(M4) 010 0 L L consists of the 0’s in the diagonal 1 2 L = {a ,a ,K} Costas Busch - RPI 15 Costas Busch - RPI 16

Non Recursively Enumerable Non Recursively Enumerable Theorem: Proof: – Language L is not recursively enumerable Assume for contradiction that L is recursively enumerable There must exist some machine M k that accepts L

L(M k ) = L

Costas Busch - RPI 17 Costas Busch - RPI 18

3 1 2 3 4 1 2 3 4 a a a a L a a a a L

L(M1) 0 110 L L(M1) 0 110 L

L(M2) 1 0 0 1 L L(M2) 1 0 0 1 L

L(M3) 0 1 1 1 L L(M3) 0 1 1 1 L

L(M4) 010 0 L L(M4) 010 0 L 1 a ∈ L(Mk ) Answer: M ≠ M Question: M k = M1? k 1 1 Costas Busch - RPI 19 Costas Busch - RPIa ∉ L(M1) 20

1 2 3 4 1 2 3 4 a a a a L a a a a L

L(M1) 0 110 L L(M1) 0 110 L

L(M2) 1 0 0 1 L L(M2) 1 0 0 1 L

L(M3) 0 1 1 1 L L(M3) 0 1 1 1 L

L(M4) 010 0 L L(M4) 010 0 L 2 a ∈ L(Mk ) Answer: M ≠ M Question: Mk = M2 ? k 2 2 Costas Busch - RPI 21 Costas Busch - RPIa ∉ L(M2) 22

1 2 3 4 1 2 3 4 a a a a L a a a a L

L(M1) 0 110 L L(M1) 0 110 L

L(M2) 1 0 0 1 L L(M2) 1 0 0 1 L

L(M3) 0 1 1 1 L L(M3) 0 1 1 1 L

L(M4) 010 0 L L(M4) 010 0 L 3 a ∉ L(Mk ) Answer: M ≠ M Question: Mk =M 3 ? k 3 3 Costas Busch - RPI 23 Costas Busch - RPIa ∈ L(M3) 24

4 Non Recursively Enumerable Non Recursively Enumerable Therefore, the machine M k cannot exist. Therefore, the language L is not recursively enumerable Similarly: M k ≠ Mi for any i Observation: Because either: There is no that describes L (otherwise would be accept ed by some Turi ng Machi ne) ai ∈ L(M ) ai ∉ L(M ) k or k i i a ∉ L(Mi ) a ∈ L(Mi )

Costas Busch - RPI 25 Costas Busch - RPI 26

Non Recursively Enumerable L

Recursively Enumerable A Language which is Recursively Enumerable and not Recursive

Recursive

27 Costas Busch - RPI 28

We want to find a language which We will prove that the language i i Is recursively But not L = {a : a ∈ L(Mi )} enumerable recursive Is recursively enumerable but not recursive

There is a Turing The machine Machine that accepts doesn’t halt the language on some input

Costas Busch - RPI 29 Costas Busch - RPI 30

5 1 2 3 4 a a a a L Theorem: i i L(M1) 0 110 L The language L = { a : a ∈ L ( M i )} is recursively enumerable Proof: L(M2) 1010 L We will give a Turing Machine that accepts L L(M3) 0111 L

L(M4) 010 0 L

3 4 L = {a ,a ,K} Costas Busch - RPI 31 Costas Busch - RPI 32

Turing Machine that accepts L For any input string w Observation: i Recursively enumerable Compute i , for which w = a i i L = {a : a ∈ L(Mi )} Find Turing machine Mi (using an procedure for Turing Machines) Not recursively enumerable i Simulate M on input a i i i L = {a : a ∉ L(Mi )} If M accepts, then accept w i (Thus, also not recursive) End of Proof

Costas Busch - RPI 33 Costas Busch - RPI 34

Theorem: Proof: Assume for contradiction that L is recursive i i The language L = {a : a ∈ L(Mi )}

is not recursive Then L is recursive: Tak e th e Turing Mach ine M th at accepts L M halts on any input: If M accepts then reject If M rejects then accept

Costas Busch - RPI 35 Costas Busch - RPI 36

6 Non Recursively Enumerable Therefore: L L is recursive Recursively Enumerable But we know: L

L is not recursively enumerable thus, not recursive Recursive CONTRADICTION!!!! Therefore, L is not recursive

Costas Busch - RPI 37 38

We will prove: (weak result) If a language is recursive then there is an enumeration procedure for it Turing acceptable languages and Enumeration Procedures (strong result) A language is recursively enumerable if and only if there is an enumeration procedure for it

Costas Busch - RPI 39 Costas Busch - RPI 40

Proof: Theorem: If a language L is recursive then there is an Enumeration Machine enumeration procedure for it

~ M M

Enumerates all Accepts L strings of input alphabet

Costas Busch - RPI 41 Costas Busch - RPI 42

7 ~ Enumeration procedure If the alphabet is { a , b } then M can enumerate strings as follows: a Repeat: b ~ aa M generates a string w ab M checks if w∈ L ba YES: print w to output bb aaa NO: ignore w aab ...... End of Proof

Costas Busch - RPI 43 Costas Busch - RPI 44

Example: L = {b,ab,bb,aaa,....} Theorem: ~ Enumeration If language L is recursively enumerable then M L(M ) Output there is an enumeration procedure for it a b b b aa ab ab ab ba bb bb bb aaa aaa aaa aab ...... Costas Busch - RPI 45 Costas Busch - RPI 46

~ If the alphabet is { a , b } then M can enumerate Proof: strings as follows: Enumeration Machine a b ~ M M aa ab ba bb aaa Enumerates all Accepts L aab strings of input alphabet

Costas Busch - RPI 47 Costas Busch - RPI 48

8 NAIVE APPROACH BETTER APPROACH Enumeration procedure ~ M Generates first string w ~ 1 Repeat: M generates a string w M executes first step on w1 M checks if w∈ L YES: pri n t w to out put ~ M Generates second string w2 NO: ignore w

Problem: If w∉ L M executes first step on w2 machine M may loop forever second step on w1

Costas Busch - RPI 49 Costas Busch - RPI 50

~ w M Generates third string 3 w1 w2 w3 w4 L

M executes first step on w3 1 11 1

second step on w2 Step in 22 third step on w 22 1 string 33 3 3 And so on......

L Costas Busch - RPI 51 Costas Busch - RPI 52

Theorem: If for language L there is an enumeration If for any string w i machine halts in a final state procedure then L is recursively enumerable then it prints M on the output wi

End of Proof

Costas Busch - RPI 53 Costas Busch - RPI 54

9 Proof: Input Tape Turing machine that accepts L

w For input string w

Machine that Repeat: accepts L Using the enumerator, generate the next string of L

Enumerator Compare Compare generated string with w for L If same, accept and exit loop

End of Proof

Costas Busch - RPI 55 Costas Busch - RPI 56

Context-Free Languages Technical Note: Non Recursively Enumerator) Type-1 languages explicitly We have proven: exclude the null string. Type-0 Languages All other language (Recursively Enum.) families permit the null A language is recursively enumerable if and only if Recursive string as a member. there is an enumeration procedure for it (The Venn diagram is Languages in slight error because of this technicality.) Type-1 (Context-sensitive) Languages Type-2 (Context-free) Languages Linear (Context-free) Type-3 Languages (Regular) Languages Costas Busch - RPI 57 58

10