recursively enumerable recursive languagesmassey/teaching/cs301/restricted...3 we will prove: • if...

18
1 CS 301 - Lecture 23 Recursive and Recursively Enumerable Languages Fall 2008 Review Languages and Grammars Alphabets, strings, languages Regular Languages Deterministic Finite and Nondeterministic Automata Equivalence of NFA and DFA Regular Expressions Regular Grammars Properties of Regular Languages Languages that are not regular and the pumping lemma Context Free Languages Context Free Grammars Derivations: leftmost, rightmost and derivation trees Parsing and ambiguity Simplifications and Normal Forms Nondeterministic Pushdown Automata Pushdown Automata and Context Free Grammars Deterministic Pushdown Automata Pumping Lemma for context free grammars Properties of Context Free Grammars Turing Machines Definition, Accepting Languages, and Computing Functions Combining Turing Machines and Turing’s Thesis Turing Machine Variations Universal Turing Machine and Linear Bounded Automata Today: Recursive and Recursively Enumerable Languages Recursively Enumerable and Recursive Languages Definition: A language is recursively enumerable if some Turing machine accepts it

Upload: lykien

Post on 14-Mar-2018

230 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

1

CS 301 - Lecture 23 Recursive and Recursively

Enumerable Languages

Fall 2008

Review •  Languages and Grammars

–  Alphabets, strings, languages •  Regular Languages

–  Deterministic Finite and Nondeterministic Automata –  Equivalence of NFA and DFA Regular Expressions –  Regular Grammars –  Properties of Regular Languages –  Languages that are not regular and the pumping lemma

•  Context Free Languages –  Context Free Grammars –  Derivations: leftmost, rightmost and derivation trees –  Parsing and ambiguity –  Simplifications and Normal Forms –  Nondeterministic Pushdown Automata –  Pushdown Automata and Context Free Grammars –  Deterministic Pushdown Automata –  Pumping Lemma for context free grammars –  Properties of Context Free Grammars

•  Turing Machines –  Definition, Accepting Languages, and Computing Functions –  Combining Turing Machines and Turing’s Thesis –  Turing Machine Variations –  Universal Turing Machine and Linear Bounded Automata –  Today: Recursive and Recursively Enumerable Languages

Recursively Enumerable and

Recursive Languages

Definition:

A language is recursively enumerable if some Turing machine accepts it

Page 2: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

2

For string :

Let be a recursively enumerable language L

and the Turing Machine that accepts it M

Lw∈

w

if then halts in a final state M

Lw∉if then halts in a non-final state Mor loops forever

Definition: A language is recursive if some Turing machine accepts it and halts on any input string

In other words: A language is recursive if there is a membership algorithm for it

For string :

Let be a recursive language L

and the Turing Machine that accepts it M

Lw∈

w

if then halts in a final state M

Lw∉if then halts in a non-final state M

Turing acceptable languages and

Enumeration Procedures

Page 3: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

3

We will prove:

•  If a language is recursive then there is an enumeration procedure for it

•  A language is recursively enumerable if and only if there is an enumeration procedure for it

(weak result)

(strong result)

Theorem:

if a language is recursive then there is an enumeration procedure for it

L

Proof:

MM~

Enumeration Machine

Accepts LEnumerates all strings of input alphabet

If the alphabet is then can enumerate strings as follows:

},{ baM~

abaaabbabbaaaaab......

Page 4: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

4

Enumeration procedure

Repeat:

M~ generates a string

M

wchecks if Lw∈

YES: print to output wNO: ignore w

End of Proof

Example:

M~

abaaabbabbaaaaab......

)(ML

b

ab

bbaaa

......

,....},,,{ aaabbabbL =Enumeration

Output

b

ab

bbaaa

......

Theorem:

if language is recursively enumerable then there is an enumeration procedure for it

L

Proof:

MM~

Enumeration Machine

Accepts LEnumerates all strings of input alphabet

Page 5: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

5

If the alphabet is then can enumerate strings as follows:

},{ baM~

abaaabbabbaaaaab

Enumeration procedure

Repeat: M~ generates a string

M

wchecks if Lw∈

YES: print to output wNO: ignore w

NAIVE APPROACH

Problem: If machine may loop forever

Lw∉M

M~

M

1w

executes first step on

BETTER APPROACH

1w

M~ Generates second string 2w

M executes first step on 2wsecond step on 1w

Generates first string M~ Generates third string 3w

M executes first step on 3wsecond step on 2w

third step on 1w

And so on............

Page 6: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

6

1w 2w 3w 4w

1

Step in string

1 1 1

2 2 2 2

3 3 3 3

If for any string machine halts in a final state then it prints on the output

Miw

iw

End of Proof

Theorem:

If for language there is an enumeration procedure then is recursively enumerable

L

L

Proof:

wInput Tape

Enumerator for L

Compare

Machine that accepts L

Page 7: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

7

Turing machine that accepts L

Repeat:

•  Using the enumerator, generate the next string of L

For input string w

•  Compare generated string with wIf same, accept and exit loop

End of Proof

We have proven:

A language is recursively enumerable if and only if there is an enumeration procedure for it

We will prove:

1. There is a specific language which is not recursively enumerable (not accepted by any Turing Machine)

2. There is a specific language which is recursively enumerable but not recursive

Recursive

Recursively Enumerable

Non Recursively Enumerable

Page 8: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

8

Some Languages Are Not Recursively Enumerable

Proof Using Uncountable Sets

A set is uncountable if it is not countable

Definition:

Theorem:

Let be an infinite countable set

The powerset of is uncountable S2 S

SProof:

Since is countable, we can write S

},,,{ 321 …sssS =

Elements of S

Page 9: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

9

Elements of the powerset have the form:

},{ 31 ss

},,,{ 10975 ssss

……

We encode each element of the power set with a binary string of 0’s and 1’s

1s 2s 3s 4s

1 0 0 0}{ 1s

Powerset element

Encoding

0 1 1 0},{ 32 ss

1 0 1 1},,{ 431 sss

Let’s assume (for contradiction) that the powerset is countable.

Then: we can enumerate the elements of the powerset

1 0 0 0 0

1 1 0 0 0

1 1 0 1 0

1 1 0 0 1

Powerset element Encoding

1t

2t

3t

4t

Page 10: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

10

Take the powerset element whose bits are the complements in the diagonal

1 0 0 0 0

1 1 0 0 0

1 1 0 1 0

1 1 0 0 1

1t

2t

3t

4t

New element: …0011(birary complement of diagonal)

The new element must be some of the powerset

it

However, that’s impossible:

the i-th bit of must be the complement of itself

from definition of it

it

Contradiction!!!

Since we have a contradiction:

The powerset of is uncountable S2 S

Page 11: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

11

An Application: Languages

Example Alphabet : },{ baThe set of all Strings:

},,,,,,,,,{},{ *…aabaaabbbaabaababaS λ==

infinite and countable

Example Alphabet : },{ baThe set of all Strings:

},,,,,,,,,{},{ *…aabaaabbbaabaababaS λ==

infinite and countable

A language is a subset of :

},,{ aababaaL =

S

Example Alphabet : },{ baThe set of all Strings:

},,,,,,,,,{},{ *…aabaaabbbaabaababaS λ==

infinite and countable

The powerset of contains all languages: }},,,}{,{},{},{{2 …aababaabaaS λ=

1L 2L 3L 4L

uncountable

S

Languages: uncountable

Turing machines: countable

1L 2L 3L kL

1M 2M 3M

?

There are more languages than Turing Machines

Page 12: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

12

There are some languages not accepted by Turing Machines

(These languages cannot be described by algorithms)

Conclusion:

Languages Accepted by Turing Machines

Languages not accepted by Turing Machines

kL

A Language which is not

Recursively Enumerable

We want to find a language that is not Recursively Enumerable

This language is not accepted by any Turing Machine

Page 13: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

13

Consider alphabet }{a

Strings: …,,,, aaaaaaaaaa

1a 2a 3a 4a

Consider Turing Machines that accept languages over alphabet }{a

They are countable:

…,,,, 4321 MMMM

Example language accepted by

},,{)( aaaaaaaaaaaaML i =

},,{)( 642 aaaML i =

iM

Alternative representation

1a 2a 3a 4a 5a 6a 7a

)( iML

0 1 1 10 0 0

1a 2a 3a 4a

)( 1ML

0 1 10

)( 2ML

)( 3ML

01 0 1

0 1 11

)( 4ML 0 10 0

Page 14: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

14

Consider the language

)}(:{ iii MLaaL ∈=

L consists from the 1’s in the diagonal

1a 2a 3a 4a

)( 1ML

0 1 10

)( 2ML

)( 3ML

01 0 1

0 1 11

)( 4ML 0 10 0

},,{ 43…aaL =

Consider the language

)}(:{ iii MLaaL ∈=

L consists of the 0’s in the diagonal

)}(:{ iii MLaaL ∉=

L

1a 2a 3a 4a

)( 1ML

0 1 10

)( 2ML

)( 3ML

01 0 1

0 1 11

)( 4ML 0 10 0

},,{ 21…aaL =

Page 15: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

15

Theorem:

Language is not recursively enumerable LProof:

is recursively enumerable LAssume for contradiction that

There must exist some machine that accepts

kML

LML k =)(

1a 2a 3a 4a

)( 1ML

0 1 10

)( 2ML

)( 3ML

01 0 1

0 1 11

)( 4ML 0 10 0

Question: ?1MMk =

1a 2a 3a 4a

)( 1ML

0 1 10

)( 2ML

)( 3ML

01 0 1

0 1 11

)( 4ML 0 10 0

Answer: 1MMk ≠)(

)(

11

1

MLa

MLa k

Page 16: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

16

1a 2a 3a 4a

)( 1ML

0 1 10

)( 2ML

)( 3ML

01 0 1

0 1 11

)( 4ML 0 10 0

Question: ?2MMk =

1a 2a 3a 4a

)( 1ML

0 1 10

)( 2ML

)( 3ML

01 0 1

0 1 11

)( 4ML 0 10 0

Answer: 2MMk ≠)(

)(

22

2

MLa

MLa k

1a 2a 3a 4a

)( 1ML

0 1 10

)( 2ML

)( 3ML

01 0 1

0 1 11

)( 4ML 0 10 0

Question: ?3MMk =

1a 2a 3a 4a

)( 1ML

0 1 10

)( 2ML

)( 3ML

01 0 1

0 1 11

)( 4ML 0 10 0

Answer: 3MMk ≠)(

)(

33

3

MLa

MLa k

Page 17: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

17

Similarly: ik MM ≠

)(

)(

ii

ki

MLa

MLa

)(

)(

ii

ki

MLa

MLa

for any i

Because either:

or

Therefore, the machine cannot exist kM

Therefore, the language is not recursively enumerable

L

End of Proof

Observation:

There is no algorithm that describes L

(otherwise would be accepted by some Turing Machine)

L Recursive

Recursively Enumerable

Non Recursively Enumerable

L

Page 18: Recursively Enumerable Recursive Languagesmassey/Teaching/cs301/Restricted...3 We will prove: • If a language is recursive then there is an enumeration procedure for it • A language

18

What’s Next •  Read

–  Linz Chapter 1,2.1, 2.2, 2.3, (skip 2.4), 3, 4, 5, 6.1, 6.2, (skip 6.3), 7.1, 7.2, 7.3, (skip 7.4), 8, 9, 10, 11

–  JFLAP Chapter 1, 2.1, (skip 2.2), 3, 4, 5, 6, 7, (skip 8), 9, (skip 10), 11 •  Next Lecture Topics From 11.1, 11.2, 11.3, and 11.4

–  More Recursive Languages, Unrestricted Grammars, Context Sensitive Grammars, and the Chomsky Hierarchy

•  Quiz 3 in Recitation on Wednesday 11/12 –  Covers Linz 7.1, 7.2, 7.3, (skip 7.4), 8, and JFLAP 5,6,7 –  Closed book, but you may bring one sheet of 8.5 x 11 inch paper with any notes you

like. –  Quiz will take the full hour

•  Homework –  Homework Due Thursday