A Hierarchy of Formal Languages and Automata

Wen-Guey Tzeng Department National Chiao Tung University Recursively enumerable language

• A language L is recursively enumerable if there exists a M such that L(M)=L. – For a string w in L, M(w) halts and enters a final state. – For a string w, not in L, M(w) • Either, halt and enter a non-final state • Or, run forever (non-halt)

2016 Spring 2 • Why is it called ”recursively enumerable” ? – “recursive” = “computational” = “algorithmical” • We can list (enumerate) all strings in a r.e. language. – Later !

2016 Spring 3 Recursive language

• A language L is recursive if there exists a Turing machine M such that – L(M)=L – For every string w in *, M(w) always halts.

All languages

2016 Spring 4 Theorem: If L is recursive, we can enumerate all strings in L. • Assume that M accepts L and halts on every input.

• Let * be w1=, w2=0, w3=1, w4=00, w5=01, … in the alphabetical order. • for enumerating strings in L: 1. i=0; 2. i=i+1;

3. Run M(wi) and wait till halt. 4. If M(wi) enters a final state 5. then list wi 6. Goto 2.

2016 Spring 5 M(w) w1 =  w2 = 0 w3 = 1 w1 = 00 . . . wk . . .

1st move

2nd Halt & move non-final

3rd Halt & X move final

4th Halt & X X move non-final . . X X X .

rth Halt & X X X move final . Halt & Halt & . X X X X . final non-final

2016 Spring 6 Theorem: If L is recursive, so is 퐿ത

• Assume that M=(Q, , , , , q0, F) accepts L and halts on all inputs. – If wL, M halts and enters pF – If wL, M halts and enter qF

• Let M’=(Q, , , , , q0, F’), where F’=Q-F. – If w퐿ത, M halts and enters p  F’ – If wL, M halts and enter q  F’ – Thus, L(M’)=퐿ത. • Since M’ halts on all inputs, 퐿ത is recursive.

2016 Spring 7 Theorem: If L is r.e., all strings in L can be enumerated. • Assume that M accepts L.

• Let * be w1=, w2=0, w3=1, w4=00, w5=01, … in the alphabetical order. • Wrong statement

3. Run M(wi) and wait till halt.

2016 Spring 8 • Algorithm for enumerating L 1. i=0; 2. i=i+1; 3. For j=1 to i;

4. Run M(wj) for the (i-j+1)-th step. 5. If M(wj) halts and enters a final state 6. then list wj 7. Goto 2.

2016 Spring 9 M(w) w1 =  w2 = 0 w3 = 1 w1 = 00 . . . wk . . .

1st move

2nd Halt & Halt & move final non-final 3rd move X X

4th Halt & X X move non-final . . X X X .

rth Halt & X X X move final . . X forever X X forever X .

2016 Spring 10 • Why does the algorithm work?

– If wk is in L and accepted by M in r steps, it will be listed when j=k and i=r+j-1, within finite steps. • Thus, every w  L will be listed within finite steps and every w  L won’t be listed.

2016 Spring 11 Questions ?

All languages  L2

 L1

• Does language L1 exist? – R.E., but not recursive

• Does language L2 exist? – Not recursively enumerable

2016 Spring 12 A non-r.e. language

• Let ={a}.

• Let M1, M2, … be a list of all TM over . i i • Let L = {a : a  L(Mi)}.

a aa aaa . . . ak . . .

M1 o x 0 . . . o . . .

M2 o o x . . . o . . .

M3 x x x . . . x . . .       

Mk o x o . . . x . . .        L o o x . . . x . . .

2016 Spring 13 i i Theorem: L = {a : a  L(Mi)} is r.e. • Algorithm A: Input: ak; ; 1. List the k-th TM Mk k 2. Run Mk(a ) and wait for the result If Mk(ak) halts on a final state then A enters an accepting configuration If Mk(ak) halts on a non-final state then A enters a non-accepting configuration

2016 Spring 14 – What is A’s running result on input ak? • when akL

• when akL

2016 Spring 15 i i • Let 퐿 = {a : a  L(Mi)}

a aa aaa . . . ak . . .

M1 o x 0 . . . o . . .

M2 o o x . . . o . . .

M3 x x x . . . x . . .       

Mk o x o . . . x . . .        퐿 o o x . . . x . . . 퐿 x x o . . . o . . .

2016 Spring 16 • Theorem: 퐿 = S is not r.e.

– Assume that S is r.e. and accepted by TM Mk such that L(Mk)=S for some k. – Contradiction: k k • If a  S, then, by definition of S, a  L(Mk)=S. k k • If a  S, then, by definition of S, a  L(Mk)=S.

– Thus, Mk does not exist and S is not r.e.

2016 Spring 17 • Theorem: L is r.e., but not recursive. – L is r.e. (why?) – If L is recursive, so is 퐿. – But, 퐿 is not recursive. Thus, L is not recursive.

All languages  L2

 L1

2016 Spring 18 2016 Spring 19