1 the chomsky hierarchy. 2 unrestricted grammars: rules have form string of variables and terminals...

63
1 The Chomsky Hierarchy

Post on 20-Dec-2015

219 views

Category:

Documents


1 download

TRANSCRIPT

1

The Chomsky Hierarchy

2

Unrestricted Grammars:

Rules have form vu

String of variablesand terminals

String of variablesand terminals

3

Example grammar:

dAc

cAaB

aBcS

4

A language is generated by anunrestricted grammarif and only if is recursively enumerableL

L

5

Context-Sensitive Grammars:

Rules have form vu

String of variablesand terminals

String of variablesand terminals

And: |||| vu

6

The language }{ nnn cba

is context-sensitive:

aaAaaaB

BbbB

BbccAc

bAAb

aAbcabcS

|

|

7

A language is context sensistiveif and only if is accepted by a Linear-Boundedautomaton

L

L

8

There is a language which is context-sensitivebut not recursive

9

Non-recursively enumerable

Recursively-enumerable

Recursive

Context-sensitive

Context-free

regular

10

Decidability

11

Consider problems with answer YES or NO

Examples:

• Does Machine have three states ?M

• Is string a binary number? w

• Does DFA accept any input? M

12

A problem is decidable

if some Turing machine solves the problem

13

Some decidable problems:

• Does Machine have three states ?M

• Is string a binary number? w

• Does DFA accept any input? M

14

The machine that decides the problem:

• If the answer is YES then halts in a yes state

• If the answer is NO then halts in a no state

These states may not be final states

15

Difference between

Recursive Languages andDecidable problems

The YES halting states may not be final states

For decidable problems:

16

There are some problemswhich are undecidable:

There is no Turing Machine thatsolves all instances of the problem

17

A famous undecidable problem:

The halting problem

18

The Halting Problem

Inputs: •Turing MachineM

•String w

Question: Does halt on ? M w

19

THEOREM

The halting problem is undecidable

20

THEOREM

The halting problem is undecidable

PROOF

Assume for contradiction thatthe halting problem is decidable

21

There exists Turing Machinethat solves the halting problem

H

HM

wYES or NO

YES: M accepts w

NO: M Doesn’t accept w

22

H

wwM 0q

yq

nq

Initial tapecontents

Encodingof M w

String

YES

NO

23

H Construct machine :

If returns YES then loop forever H

If returns NO then haltH

24

H

wwM 0q

yq

nq NO

aq bq

H

Loop forever

25

HConstruct machine

Input:

If M halts on input Mw

then loop forever

Else halt

:

Mw (machine )M

26

MwMM wwrepeat

MwH

H

27

Run machine H with input itself

28

HRun machine

Input:

If halts on input

then loop forever

Else halt

:

Hw ˆ (machine )H

H Hw ˆ

29

on input H Hw ˆ

If halts then loops forever

If doesn’t halt then it halts

:

H

H

NONSENSE !!!!!

30

Therefore, we have contradiction

The halting problem is undecidable

END OF PROOF

31

Another proof of the same theorem

If the halting problem was decidable thenevery recursively enumerable languagewould be recursive

32

THEOREM

The halting problem is undecidable

PROOF

Assume for contradiction thatthe halting problem is decidable

33

Turing Machine solves the halting problemH

For inputs: machine M and string w

H Returns:

M halts on input wYES: if

M doesn’t halt on inputwNO: if

34

Let be a recursively enumerable language L

Let be the Machine that acceptsM L

We will prove that is recursive L

We will describe a membership algorithm

35

Run with inputs: M wandH

HIf Returns:

M doesn’t halt on inputwNO:

Then M doesn’t accept w

36

HIf Returns:

M halts on input wYES:

Run M wwith input

M will halt, and either accept or reject w

37

Therefore L is recursive

But there are recursively enumerablelanguages which are not recursive

Contradiction!!!!

38

Therefore, the halting problemis undecidable

END OF PROOF

39

Reducibility

40

Problem is reduced to problemA B

BIf is decidable then is decidableA

means

41

Problem is reduced to problemA B

AIf is undecidable then is undecidableB

also means

42

Example:

The halting problem

is reduced to

The state-entry problem

43

The state-entry problem

Inputs: M•Turing Machine

•State q

Question:

Does M

•String w

enter state q

on input ?w

44

THEOREM

The state-entry problem is undecidable

45

THEOREM

The state-entry problem is undecidable

PROOF

Reduce the halting problem to

the state-entry problem

46

Suppose we have an algorithmfor the state-entry problem

We will construct an algorithmfor the halting problem

47

Inputs for the halting problem

•A machine M

•A string w

Algorithm for halting problem must determineif halts on inputM w

48

Modify machine :M

•Add new state q

•From any halting state add transitions to q

M q

halting statesSinglehalt state

M

49

M halts if and only if

M halts on state q

50

Algorithm for halting problem:

Inputs: M wand

1. Construct with state M q

2. Run algorithm for state-entry problem with inputs: M wq, ,

51

Generate

M M

w

M qw

State-entry

machine

Halting problem machine

YES

NO

52

Since the halting problem is undecidable,

the state-entry problem is also undecidable

END OF PROOF

53

Another example:

The halting problem

is reduced to

The blank-tape halting problem

54

The blank-tape halting problem

Input: MTuring Machine

Question:

Does M halt when started with

a blank tape?

55

THEOREM

The blank-tape halting problem is undecidable

56

THEOREM

PROOF

Reduce halting problem to

Blank-tape halting problem

The blank-tape halting problem is undecidable

57

Suppose we have an algorithmfor the blank-tape halting problem

We will construct an algorithmfor the halting problem

58

Inputs for the halting problem

•A machine M

•A string w

Algorithm for halting problem must determineif halts on inputM w

59

wMConstruct a new machine

• On blank tape writes w

• Then continues execution like M

60

M halts if and only if

wM halts when started with blank tape

61

Algorithm for halting problem:

Inputs: M wand

1. Construct wM

2. Run algorithm for blank-tape halting problem with input

, ,

wM

62

Generate

wM

M

w

blank-tape halting machine

Halting problem machine

YES

NO

wM

63

Since the halting problem is undecidable,

the blank-tape halting problem is also undecidable

END OF PROOF