COMP20121 The Implementation and Power of Computer Languages Power - - PowerPoint PPT Presentation

comp20121 the implementation and power of computer
SMART_READER_LITE
LIVE PREVIEW

COMP20121 The Implementation and Power of Computer Languages Power - - PowerPoint PPT Presentation

COMP20121 The Implementation and Power of Computer Languages Power Part http://www.cs.man.ac.uk/ petera/2121/index.html . Peter Aczel room: CS2.52, tel: 56155 petera@cs.man.ac.uk email: School of Computer Science, University of


slide-1
SLIDE 1

COMP20121 The Implementation and Power of Computer Languages ‘Power’ Part

http://www.cs.man.ac.uk/∼petera/2121/index.html .

Peter Aczel room: CS2.52, tel: 56155 email:

petera@cs.man.ac.uk

School of Computer Science, University of Manchester

COMP20121 - Section 0 – p.1/307

slide-2
SLIDE 2

COMP20121, ‘power’ part: section 3 LECTURE EIGHT

Section 3: Turing machines (ctd)

COMP20121 - Section 3 – p.162/307

slide-3
SLIDE 3

Informal description

Here is an alternative way of describing the same machine.

COMP20121 - Section 3 – p.163/307

slide-4
SLIDE 4

Informal description

Here is an alternative way of describing the same machine.

  • Remember the first symbol of the input

string (by going to state 1 if it is an a and to state 2 if it is a b) and erase it.

COMP20121 - Section 3 – p.163/307

slide-5
SLIDE 5

Informal description

Here is an alternative way of describing the same machine.

  • Remember the first symbol of the input

string (by going to state 1 if it is an a and to state 2 if it is a b) and erase it.

  • Go to the right until you find a blank.

(This is the end of the input string.)

COMP20121 - Section 3 – p.163/307

slide-6
SLIDE 6

Informal description

  • If the symbol to the left of that blank is

the one remembered, erase it. If it is a blank, stop in an accepting state (0). Otherwise stop (in a non-accepting state).

COMP20121 - Section 3 – p.164/307

slide-7
SLIDE 7

Informal description

  • If the symbol to the left of that blank is

the one remembered, erase it. If it is a blank, stop in an accepting state (0). Otherwise stop (in a non-accepting state).

  • Go to the left until you find a blank.

(This is the start of what’s left of the input string.)

COMP20121 - Section 3 – p.164/307

slide-8
SLIDE 8

Informal description

  • If the symbol to the left of that blank is

the one remembered, erase it. If it is a blank, stop in an accepting state (0). Otherwise stop (in a non-accepting state).

  • Go to the left until you find a blank.

(This is the start of what’s left of the input string.)

  • Start over with the head pointing at the

symbol to the right of that blank.

COMP20121 - Section 3 – p.164/307

slide-9
SLIDE 9

Informal description–II

Having gone through these states we know that

COMP20121 - Section 3 – p.165/307

slide-10
SLIDE 10

Informal description–II

Having gone through these states we know that

  • If the first letter and the last letter of

the string were not equal, the machine has stopped in a non-accepting state.

COMP20121 - Section 3 – p.165/307

slide-11
SLIDE 11

Informal description–II

Having gone through these states we know that

  • If the first letter and the last letter of

the string were not equal, the machine has stopped in a non-accepting state.

  • If the first and the last letter were

equal, they have now both been erased and the head is pointing at the new first letter (the old second letter).

COMP20121 - Section 3 – p.165/307

slide-12
SLIDE 12

Informal description–II

Having gone through these states we know that

  • If the first letter and the last letter of

the string were not equal, the machine has stopped in a non-accepting state.

  • If the first and the last letter were

equal, they have now both been erased and the head is pointing at the new first letter (the old second letter). The machine will now start over.

COMP20121 - Section 3 – p.165/307

slide-13
SLIDE 13

Informal description–II

Hence the recognized language is that

COMP20121 - Section 3 – p.166/307

slide-14
SLIDE 14

Informal description–II

Hence the recognized language is that of all palindromes.

COMP20121 - Section 3 – p.166/307

slide-15
SLIDE 15

Accepting languages

Consider a Turing machine over the alphabet Σ = {a} which accepts the set of all words of even length

COMP20121 - Section 3 – p.167/307

slide-16
SLIDE 16

Accepting languages

Consider a Turing machine over the alphabet Σ = {a} which accepts the set of all words of even length, that is

{a2i | i ∈ N}.

COMP20121 - Section 3 – p.167/307

slide-17
SLIDE 17

Accepting languages

Consider a Turing machine over the alphabet Σ = {a} which accepts the set of all words of even length, that is

{a2i | i ∈ N}.

We can code this with two states, for ‘odd’ and ‘even’.

COMP20121 - Section 3 – p.167/307

slide-18
SLIDE 18

Accepting languages–II

The machine moves to the right until it finds a blank, switching between these two states, where 0 is the sole accepting state.

COMP20121 - Section 3 – p.168/307

slide-19
SLIDE 19

Accepting languages–II

The machine moves to the right until it finds a blank, switching between these two states, where 0 is the sole accepting state.

δ a

0 (1, a, R) stop 1 (0, a, R) stop

COMP20121 - Section 3 – p.168/307

slide-20
SLIDE 20

Accepting languages–II

Now consider instead the Turing machine given by

δ a

0 (1, a, R) stop 1 (0, a, R) (1,

, R)

COMP20121 - Section 3 – p.169/307

slide-21
SLIDE 21

Accepting languages–II

Now consider instead the Turing machine given by

δ a

0 (1, a, R) stop 1 (0, a, R) (1,

, R)

This machine moves to the right as well, switching between two states coding for ‘odd’ and ‘even’.

COMP20121 - Section 3 – p.169/307

slide-22
SLIDE 22

Accepting languages–II

If the machine finds a blank then

COMP20121 - Section 3 – p.170/307

slide-23
SLIDE 23

Accepting languages–II

If the machine finds a blank then

  • it will stop (in an accepting state) if the

current state is the one which is for ‘even’;

COMP20121 - Section 3 – p.170/307

slide-24
SLIDE 24

Accepting languages–II

If the machine finds a blank then

  • it will stop (in an accepting state) if the

current state is the one which is for ‘even’;

  • it will keep moving to the right forever if

the current state is the one for ‘odd’.

COMP20121 - Section 3 – p.170/307

slide-25
SLIDE 25

Accepting languages–III

The machines

δ a (1, a, R)

stop 1

(0, a, R)

stop

and

δ a (1, a, R)

stop 1

(0, a, R) (1, , R)

both with sole accepting state 0 accept the same language.

COMP20121 - Section 3 – p.171/307

slide-26
SLIDE 26

Accepting languages–III

The machines

δ a (1, a, R)

stop 1

(0, a, R)

stop

and

δ a (1, a, R)

stop 1

(0, a, R) (1, , R)

both with sole accepting state 0 accept the same language. Which one is more useful?

COMP20121 - Section 3 – p.171/307

slide-27
SLIDE 27

Recognizable versus decidable

Definition 16 A language is Turing-recognizable (or recursively enumerable) if there is a Turing machine which recognizes it.

COMP20121 - Section 3 – p.172/307

slide-28
SLIDE 28

Recognizable versus decidable

Definition 16 A language is Turing-recognizable (or recursively enumerable) if there is a Turing machine which recognizes it. A language is Turing-decidable (or recursive) if there is a Turing machine which recognizes it which halts for all inputs.

COMP20121 - Section 3 – p.172/307

slide-29
SLIDE 29

Recognizable versus decidable–II

  • Every Turing-decidable language is

Turing-recognizable, but not vice versa.

COMP20121 - Section 3 – p.173/307

slide-30
SLIDE 30

Recognizable versus decidable–II

  • Every Turing-decidable language is

Turing-recognizable, but not vice versa.

  • In order to show that a language is

Turing-decidable, we have to design a machine which halts for all inputs. Such a machine will give us a definite answer, ‘yes’

  • r ‘no’, for every word.

COMP20121 - Section 3 – p.173/307

slide-31
SLIDE 31

Recognizable versus decidable–II

  • In order to show that a language is

Turing-recognizable, we merely have to design a machine which halts for all inputs which it accepts.

COMP20121 - Section 3 – p.174/307

slide-32
SLIDE 32

Recognizable versus decidable–II

  • In order to show that a language is

Turing-recognizable, we merely have to design a machine which halts for all inputs which it accepts.

  • With a Turing-recognizable language, we

may never be certain that some given word really does not belong to the language.

COMP20121 - Section 3 – p.174/307

slide-33
SLIDE 33

C-F languages are Turing-decidable

Proposition 3.1 Every context-free language is Turing-decidable. Biggest problem: Create machine which terminates for all inputs.

COMP20121 - Section 3 – p.175/307

slide-34
SLIDE 34

C-F languages are Turing-decidable

Proposition 3.1 Every context-free language is Turing-decidable. The proof requires the following.

COMP20121 - Section 3 – p.175/307

slide-35
SLIDE 35

C-F languages are Turing-decidable

Proposition 3.1 Every context-free language is Turing-decidable. The proof requires the following.

  • Convert grammar into Chomsky

normal form (Chomsky nf).

COMP20121 - Section 3 – p.175/307

slide-36
SLIDE 36

C-F languages are Turing-decidable

Proposition 3.1 Every context-free language is Turing-decidable. The proof requires the following.

  • Convert grammar into Chomsky

normal form (Chomsky nf).

  • We haven’t covered this, so we will
  • nly describe the properties of this

normal form here.

COMP20121 - Section 3 – p.175/307

slide-37
SLIDE 37

C-F languages are Turing-decidable

Proposition 3.1 Every context-free language is Turing-decidable. The proof requires the following.

  • Convert grammar into Chomsky

normal form (Chomsky nf).

  • Then a string of length n will be

generated after at most 2n − 1 applications of a production rule.

COMP20121 - Section 3 – p.175/307

slide-38
SLIDE 38

C-F languages are Turing-decidable

The proof requires the following.

  • Convert grammar into Chomsky nf.
  • There is a TM to do this.

COMP20121 - Section 3 – p.176/307

slide-39
SLIDE 39

C-F languages are Turing-decidable

The proof requires the following.

  • Convert grammar into Chomsky nf.
  • There is a TM to do this.
  • Given an input string α of length n, let

the machine generate all words of the language which require no more than

2n − 1 applications of a production

rule.

COMP20121 - Section 3 – p.176/307

slide-40
SLIDE 40

C-F languages are Turing-decidable

The proof requires the following.

  • Convert grammar into Chomsky nf.
  • There is a TM to do this.
  • Given an input string α of length n, let

the machine generate all words of the language which require no more than

2n − 1 applications of a production

  • rule. If α is generated along the way,

accept, otherwise reject.

COMP20121 - Section 3 – p.176/307

slide-41
SLIDE 41

Turing-decidability & complementation

Since a Turing machine deciding a language has to halt for all inputs, we can also find out whether a given word does not belong to the language under consideration.

COMP20121 - Section 3 – p.177/307

slide-42
SLIDE 42

Turing-decidability & complementation

Since a Turing machine deciding a language has to halt for all inputs, we can also find out whether a given word does not belong to the language under consideration. Theorem 3.2 A language is Turing-decidable if and only if its complement is Turing-decidable.

COMP20121 - Section 3 – p.177/307

slide-43
SLIDE 43

Turing-decidability & complementation

Since a Turing machine deciding a language has to halt for all inputs, we can also find out whether a given word does not belong to the language under consideration. Theorem 3.2 A language is Turing-decidable if and only if its complement is Turing-decidable. Proving this result is an exercise.

COMP20121 - Section 3 – p.177/307

slide-44
SLIDE 44

Enumerating languages

Idea: A Turing machine can do many more things than accept or reject a given input string.

COMP20121 - Section 3 – p.178/307

slide-45
SLIDE 45

Enumerating languages

Idea: A Turing machine can do many more things than accept or reject a given input string. For example such a machine can list (or ‘enumerate’) all the words of a language.

COMP20121 - Section 3 – p.178/307

slide-46
SLIDE 46

Enumerating languages

Idea: A Turing machine can do many more things than accept or reject a given input string. For example such a machine can list (or ‘enumerate’) all the words of a language. For this it just starts producing words, starting with an empty tape.

COMP20121 - Section 3 – p.178/307

slide-47
SLIDE 47

Enumerating languages

What languages do we get this way?

COMP20121 - Section 3 – p.179/307

slide-48
SLIDE 48

Enumerating languages

What languages do we get this way? Theorem 3.3 A language is Turing-recognizable if and only if there is a Turing machine enumerating it.

COMP20121 - Section 3 – p.179/307

slide-49
SLIDE 49

Properties of languages

There are many ways of creating languages from existing ones. Some classes of languages are closed under some of these.

COMP20121 - Section 3 – p.180/307

slide-50
SLIDE 50

Properties of languages

There are many ways of creating languages from existing ones. Some classes of languages are closed under some of these.

closed under

COMP20121 - Section 3 – p.180/307

slide-51
SLIDE 51

Properties of languages

There are many ways of creating languages from existing ones. Some classes of languages are closed under some of these.

closed under compl.

COMP20121 - Section 3 – p.180/307

slide-52
SLIDE 52

Properties of languages

There are many ways of creating languages from existing ones. Some classes of languages are closed under some of these.

closed under compl. intersect.

COMP20121 - Section 3 – p.180/307

slide-53
SLIDE 53

Properties of languages

There are many ways of creating languages from existing ones. Some classes of languages are closed under some of these.

closed under compl. intersect. union

COMP20121 - Section 3 – p.180/307

slide-54
SLIDE 54

Properties of languages

There are many ways of creating languages from existing ones. Some classes of languages are closed under some of these.

closed under compl. intersect. union reversal

COMP20121 - Section 3 – p.180/307

slide-55
SLIDE 55

Properties of languages

There are many ways of creating languages from existing ones. Some classes of languages are closed under some of these.

closed under compl. intersect. union reversal concat.

COMP20121 - Section 3 – p.180/307

slide-56
SLIDE 56

Properties of languages

There are many ways of creating languages from existing ones. Some classes of languages are closed under some of these.

closed under compl. intersect. union reversal concat. regular

  • COMP20121 - Section 3 – p.180/307
slide-57
SLIDE 57

Properties of languages

There are many ways of creating languages from existing ones. Some classes of languages are closed under some of these.

closed under compl. intersect. union reversal concat. regular

  • context-free
  • COMP20121 - Section 3 – p.180/307
slide-58
SLIDE 58

Properties of languages

There are many ways of creating languages from existing ones. Some classes of languages are closed under some of these.

closed under compl. intersect. union reversal concat. regular

  • context-free
  • Turing-dec.
  • COMP20121 - Section 3 – p.180/307
slide-59
SLIDE 59

Properties of languages

There are many ways of creating languages from existing ones. Some classes of languages are closed under some of these.

closed under compl. intersect. union reversal concat. regular

  • context-free
  • Turing-dec.
  • Turing-rec.
  • COMP20121 - Section 3 – p.180/307
slide-60
SLIDE 60

Chomsky’s hierarchy

The different kinds of languages we have looked at in this course form a hierarchy.

COMP20121 - Section 3 – p.181/307

slide-61
SLIDE 61

Chomsky’s hierarchy

The different kinds of languages we have looked at in this course form a hierarchy. With (some of) these languages there are corresponding machines and grammars.

COMP20121 - Section 3 – p.181/307

slide-62
SLIDE 62

Chomsky’s hierarchy

Languages

COMP20121 - Section 3 – p.182/307

slide-63
SLIDE 63

Chomsky’s hierarchy

Languages Production rules for grammars are Γ → ∆ such that

COMP20121 - Section 3 – p.182/307

slide-64
SLIDE 64

Chomsky’s hierarchy

Languages Production rules for grammars recognizing machines are Γ → ∆ such that are

COMP20121 - Section 3 – p.182/307

slide-65
SLIDE 65

Chomsky’s hierarchy

Languages Production rules for grammars recognizing machines are Γ → ∆ such that are regular

Γ = R: any one non-terminal

finite state

∆ = xR′ or ∆ = x or ∆ = ǫ where

automata

R′ non-terminal, x terminal

COMP20121 - Section 3 – p.182/307

slide-66
SLIDE 66

Chomsky’s hierarchy

Languages Production rules for grammars recognizing machines are Γ → ∆ such that are regular

Γ = R: any one non-terminal

finite state

∆ = xR′ or ∆ = x or ∆ = ǫ where

automata

R′ non-terminal, x terminal

context-free

Γ = R any one non-terminal

non-deterministic

∆ any string

pushdown automata

COMP20121 - Section 3 – p.182/307

slide-67
SLIDE 67

Chomsky’s hierarchy

Languages Production rules for grammars recognizing machines are Γ → ∆ such that are regular

Γ = R: any one non-terminal

finite state

∆ = xR′ or ∆ = x or ∆ = ǫ where

automata

R′ non-terminal, x terminal

context-free

Γ = R any one non-terminal

non-deterministic

∆ any string

pushdown automata context-sensitive

Γ any string containing non-terminals

Turing machines

∆ any string at least as long as Γ

with bounded tape

COMP20121 - Section 3 – p.182/307

slide-68
SLIDE 68

Chomsky’s hierarchy

Languages Production rules for grammars recognizing machines are Γ → ∆ such that are regular

Γ = R: any one non-terminal

finite state

∆ = xR′ or ∆ = x or ∆ = ǫ where

automata

R′ non-terminal, x terminal

context-free

Γ = R any one non-terminal

non-deterministic

∆ any string

pushdown automata context-sensitive

Γ any string containing non-terminals

Turing machines

∆ any string at least as long as Γ

with bounded tape Turing-recognizable

Γ any string containing non-terminals

Turing machines

∆ any string

COMP20121 - Section 3 – p.182/307

slide-69
SLIDE 69

Section 3 summary

  • Turing machines are automata with random-access memory.

COMP20121 - Section 3 – p.183/307

slide-70
SLIDE 70

Section 3 summary

  • Turing machines are automata with random-access memory.
  • Turing machines are more powerful than PDAs.

COMP20121 - Section 3 – p.183/307

slide-71
SLIDE 71

Section 3 summary

  • Turing machines are automata with random-access memory.
  • Turing machines are more powerful than PDAs.
  • Languages recognized by a Turing machine are called

Turing-recognizable, and these are the same languages as those which are enumerated by a Turing machine.

COMP20121 - Section 3 – p.183/307

slide-72
SLIDE 72

Section 3 summary

  • Turing machines are automata with random-access memory.
  • Turing machines are more powerful than PDAs.
  • Languages recognized by a Turing machine are called

Turing-recognizable, and these are the same languages as those which are enumerated by a Turing machine.

  • If there is a Turing machine recognizing a language which halts for all

inputs we say the language is Turing-decidable. (Rather than just having to accept words belonging to the language, the machine must effectively reject words that do not.)

COMP20121 - Section 3 – p.183/307

slide-73
SLIDE 73

Languages over {0, 1}

{0, 1}∗

COMP20121 - Section 3 – p.184/307

slide-74
SLIDE 74

Languages over {0, 1}

regular

{0, 1}∗

DFAs decide regular expressions generate COMP20121 - Section 3 – p.184/307

slide-75
SLIDE 75

Languages over {0, 1}

context-free

{0, 1}∗ {0n1n | n ∈ N}

non-deterministic PDAs decide DFAs decide context-free grammars generate regular expressions generate regular COMP20121 - Section 3 – p.184/307

slide-76
SLIDE 76

Languages over {0, 1}

regular context-free

{0, 1}∗ {0n1n0n1n | n ∈ N} {0n1n | n ∈ N}

non-deterministic PDAs decide TMs decide DFAs decide context-free grammars generate regular expressions generate Turing-decidable COMP20121 - Section 3 – p.184/307

slide-77
SLIDE 77

Languages over {0, 1}

regular context-free

{0, 1}∗ {0n1n0n1n | n ∈ N} {0n1n | n ∈ N}

non-deterministic PDAs decide TMs decide TMs recognize DFAs decide context-free grammars generate regular expressions generate Turing-decidable Turing-recognizable TMs enumerate; unrestricted grammars generate

{(M, α) | The Turing machine M halts on input α}

COMP20121 - Section 3 – p.184/307

slide-78
SLIDE 78

Languages over {0, 1}

regular context-free

{0, 1}∗ {0n1n0n1n | n ∈ N} {0n1n | n ∈ N}

non-deterministic PDAs decide TMs decide TMs recognize DFAs decide context-free grammars generate regular expressions generate Turing-decidable Turing-recognizable

{Mn | Mn does not accept Mn}

TMs enumerate; unrestricted grammars generate

{(M, α) | The Turing machine M halts on input α}

COMP20121 - Section 3 – p.184/307