chapter 3- the church-turing thesis sharif university of...

48
Theory of Languages and Automata Chapter 3- The Church-Turing Thesis Sharif University of Technology

Upload: others

Post on 22-Sep-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Theory of Languages

and Automata

Chapter 3- The Church-Turing Thesis

Sharif University of Technology

Page 2: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Turing Machine

O Several models of computing devices

� Finite automata

� Pushdown automata

O Tasks that are beyond the capabilities of these O Tasks that are beyond the capabilities of these

models

� Much more powerful model

� Proposed by Alan Turing in 1936

Prof. MovagharTheory of Languages and Automata 2

Page 3: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Turing Machine (cont.)

O Similar to a finite automaton

� Unlimited memory

O Can do everything that a real computer can do

O Cannot solve certain problems

� Beyond the theoretical limits of computation

Prof. MovagharTheory of Languages and Automata 3

Page 4: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Tape

O An infinite tape

� A tape head to read and write symbols

O Initially contains the input string and blank

everywhere elseeverywhere else

O Outputs: accept and reject

� By entering accepting and rejecting states

� If it doesn’t enter an accepting or a rejecting state,

never halts

Prof. MovagharTheory of Languages and Automata 4

Page 5: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Differences with finite automata

1. A Turing machine can both write on the tape and

read from it.

2. The read-write head can move both to the left and

to the right.to the right.

3. The tape is infinite.

4. The special state for rejecting and accepting take

effect immediately.

Prof. MovagharTheory of Languages and Automata 5

Page 6: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Example

O B = {w#w| w ∊ {0,1}* }

O M11

� Accept if its input is a member of B

� Reject, otherwise

O Strategy: zigzag to the corresponding places on the

two sides of # and determine whether they match

Prof. MovagharTheory of Languages and Automata 6

Page 7: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Example (cont.)

O To keep track of which symbols have been checked

already, M1 crosses off each symbol as it is

examinedexamined

O Crossing off all the symbols: going to an accept

state

Prof. MovagharTheory of Languages and Automata 7

Page 8: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Example (cont.)

O M1 = “On input string w:

1. Zig-zag across the tape to corresponding positions in

either side of the # symbol to check whether these

positions contain the same symbol. If they do not, or positions contain the same symbol. If they do not, or

if no # is found, reject. Cross off symbols as they are

checked to keep track of which symbols correspond.

2. When all symbols to the left of the # have been

crossed off, check for any remaining symbols to the

right of the #. If any symbols remain, reject;

otherwise, accept.”

Prof. MovagharTheory of Languages and Automata 8

Page 9: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Example (cont.)

O Snapshots of Turing machine M1 computing on

input 011000#011000

Prof. MovagharTheory of Languages and Automata 9

Page 10: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Turing Machine (Formal Definition)

O A Turing machine is a 7-tuple, (Q, ∑, Γ, δ, q0, qaccept, qreject), where Q, ∑, Γ are all finite sets and

1. Q is the set of states,

2. ∑ is the input alphabet not containing the blank symbol ⨆

⨆∈ ⊆

2. ∑ is the input alphabet not containing the blank symbol ⨆,

3. Γ is the tape alphabet where ⨆∈Γ and ∑⊆Γ,

4. δ : Q × Γ→ Q × Γ × {Γ, R} is the transition function,

5. q0 ∈ Q is the start state,

6. qaccept ∈ Q is the accept state, and

7. qreject ∈ Q is the reject state, where qreject ≠ qaccept.

Prof. MovagharTheory of Languages and Automata 10

Page 11: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Computation of a Turing Machine

O Initially receives its input on the leftmost n squares

of the tape

� The rest is blank

The head starts on the leftmost square of the tapeO The head starts on the leftmost square of the tape

O The first blank on the tape: the end of the input

Prof. MovagharTheory of Languages and Automata 11

Page 12: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Computation of a Turing Machine

(cont.)

O The computation proceeds according to the rules

� Transition function

O If M tries to move its head to the left off the left-

hand end of the tape, the head stays in the same hand end of the tape, the head stays in the same

place

O The computation continues until it enters either the

accept or reject states

� If neither occurs, it goes forever

Prof. MovagharTheory of Languages and Automata 12

Page 13: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Configuration

O The current state, the current tape contents, the

current head location

� Changes occur, as the Turing machine computes

Prof. MovagharTheory of Languages and Automata 13

Page 14: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Configuration (cont.)

O The Start Configuration of M on input w is q0w.

O In an Accepting Configuration, the state of the

configuration is qaccept.

Rejecting ConfigurationO In a Rejecting Configuration, the state of the

configuration is qreject.

O A Halting Configuration is either an accepting

configuration or a rejecting configuration.

Prof. MovagharTheory of Languages and Automata 14

Page 15: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

C1 Yields C2

O Suppose that we have a, b, and c in Γ, as well as u

and v in Γ* and states qi and qj. In that case uaqibv

and uqjacv are two configurations, Say that

uaq bv yields uq acvuaqibv yields uqjacv

If in the transition function δ(qi ,b)=(qj ,c, L). That

handles the case where the Turing machine moves

leftward. For a rightward move, say that

uaqibv yields uacqjv

if δ(qi ,b)=(qj ,c, L).

Prof. MovagharTheory of Languages and Automata 15

Page 16: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Equivalent Transition Function

O The transition function could have been defined

equivalently

δ : Q’ × Γ→ Q × Γ × {Γ, R}

O Q’ is Q, without qaccept and qreject

O M accepts input w, if a sequence of configurations

C1, C2, …, Ck exists:

1. C1 is the start configuration of M on input w,

2. each Ci yields Ci+1 , and

3. Ck is an accepting configuration.

Prof. MovagharTheory of Languages and Automata 16

Page 17: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

O The collection of strings that M accepts is the

language of M, or the language recognized

The Language of a Turing Machine

language of M, or the language recognized

by M, denoted L(M).

Prof. MovagharTheory of Languages and Automata 17

Page 18: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Turing-recognizable language

O Definition: Call a language Turing-recognizable if

some Turing machine recognizes it.

O Three outcomes on an input:

� Accept

� Reject

� Loop

O Sometimes distinguishing a machine that is looping

from one that is taking a long time, is difficult.

Prof. MovagharTheory of Languages and Automata 18

Page 19: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Turing-decidable language

O Definition: Call a language Turing-decidable or

simply decidable if some Turing machine decides it.

Turing machines that halt on all inputsO Turing machines that halt on all inputs

� Never loop

� Deciders

Prof. MovagharTheory of Languages and Automata 19

Page 20: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Example 1

O

Prof. MovagharTheory of Languages and Automata 20

Page 21: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Example 1 (formal description)

O

Prof. MovagharTheory of Languages and Automata 21

Page 22: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Example 1 (state diagram)

Prof. MovagharTheory of Languages and Automata 22

Page 23: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Example 1 (sample run on input 0000)

Prof. MovagharTheory of Languages and Automata 23

Page 24: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Example 2

O

Prof. MovagharTheory of Languages and Automata 24

Page 25: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Example 2 (state diagram)

Prof. MovagharTheory of Languages and Automata 25

Page 26: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Example 3

O

Prof. MovagharTheory of Languages and Automata 26

Page 27: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Example 4

O

Prof. MovagharTheory of Languages and Automata 27

Page 28: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Multitape Turing Machine

O

Prof. MovagharTheory of Languages and Automata 28

Page 29: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Multitape Turing Machine

O

Prof. MovagharTheory of Languages and Automata 29

Page 30: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Example

O Representing three tapes with one

Prof. MovagharTheory of Languages and Automata 30

Page 31: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Simulation Procedure

O

Prof. MovagharTheory of Languages and Automata 31

Page 32: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

O At any point in a computation the machine may

proceed according to several possibilities.

O Transition function

Nondeterministic Turing Machine

δ : Q × Γ→ P(Q × Γ × {Γ, R})

O Every nondeterministic Turing machine has an

equivalent deterministic Turing machine.

Prof. MovagharTheory of Languages and Automata 32

Page 33: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Example

Prof. MovagharTheory of Languages and Automata 33

Page 34: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

1. Initially tape 1 contains the input w, and tapes 2 and 3 are empty.

2. Copy tape 1 to tape 2.

3. Use tape 2 to simulate N with input w on one branch of its nondeterministic computation. Before each step of N consult the next symbol on tape 3 to determine which

Simulation Procedure

consult the next symbol on tape 3 to determine which choice to make among those allowed by N's transition function. If no more symbols remain on tape 3 or if this nondeterministic choice is invalid, abort this branch by going to stage 4. Also go to stage 4 if a rejecting configuration is encountered. If an accepting configuration is encountered, accept the input.

4. Replace the string on tape 3 with the lexicographically next string. Simulate the next branch of N's computation by going to stage 2.

Prof. MovagharTheory of Languages and Automata 34

Page 35: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

O A language is Turing-recognizable if and only if

some nondeterministic Turing machine recognizes it.

O PROOF: Any deterministic TM is automatically a

nondeterministic TM, and so one direction of this

Theorem

nondeterministic TM, and so one direction of this

theorem follows immediately. The other direction

follows from Theorem 3.16.

Prof. MovagharTheory of Languages and Automata 35

Page 36: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

O We can modify the proof of Theorem 3.16 so that if N always halts on all branches of its computation, D will always halt. We call a nondeterministic Turing machine a decider if all branches halt on all inputs.

Theorem (cont.)

machine a decider if all branches halt on all inputs. Exercise 3.3 asks you to modify the proof in this way to obtain the following corollary to previous theorem.

O COROLLARY: A language is decidable if and only if some nondeterministic Turing machine decides it.

Prof. MovagharTheory of Languages and Automata 36

Page 37: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

O Loosely defined: a Turing Machine with an attached

printer

� Printer: an output device

O Every time the Turing Machine wants to add a string to

the list, it sends the string to the printer

Enumerators

the list, it sends the string to the printer

Prof. MovagharTheory of Languages and Automata 37

Page 38: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

O An enumerator E starts with a blank input tape.

O If it doesn’t halt, it may print an infinite list of

strings.

O The language enumerated by E: the collection of all

the strings that it eventually prints out.

Enumerators

the strings that it eventually prints out.

O A language is Turing-recognizable if and only if

some enumerator enumerates it.

Prof. MovagharTheory of Languages and Automata 38

Page 39: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

O A language is Turing-recognizable if and only if some enumerator enumerates it.

O PROOF First we show that if we have an enumerator E that enumerates a language A, a TM M recognizes A. The TM M works in the following way.

O M = "On input w:

Theorem

O M = "On input w:

1. Run E. Every time that E outputs a string, compare it with w.

2. If w ever appears in the output of E, accept."

Clearly, M accepts those strings that appear on E's list. Now we do the other direction. If TM M recognizes a language A, we can construct the following enumerator E for A. Say that S1, 82, S3,... is a list of all possible strings in r*.

O E = "Ignore the input.

1. Repeat the following for i = 1, 2, 3 ....

2. Run M for i steps on each input, s, 12, . .. , s.

3. If any computations accept, print out the corresponding sj."

Prof. MovagharTheory of Languages and Automata 39

Page 40: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

O All variants of Turing Machine models share the

essential feature of Turing Machines: unrestricted access

to unlimited memory!

Equivalence with Other Models

to unlimited memory!

Prof. MovagharTheory of Languages and Automata 40

Page 41: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

O Informally, an algorithm is a collection of simple instructions for carrying out some task.

Even though algorithms have had a long

Definition of Algorithm

O Even though algorithms have had a long history, the notion of algorithm itself was not defined precisely until the twentieth century.

O The definition came in the 1936 papers of Alonzo Church and Alan Turing

Prof. MovagharTheory of Languages and Automata 41

Page 42: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

O

HlLBERT’s Problem

Prof. MovagharTheory of Languages and Automata 42

Page 43: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

O Hilbert's tenth problem was to devise an algorithm

that tests whether a polynomial has an integral root.

He did not use the term algorithm but rather “ a

process according to which it can be determined by a

HlLBERT’s Problem(Cont.)

process according to which it can be determined by a

finite number of operations.”

O Interestingly, in the way he phrased this problem,

Hilbert explicitly asked that an algorithm be

"devised." Thus he apparently assumed that such an

algorithm must exist-someone need only find it.

Prof. MovagharTheory of Languages and Automata 43

Page 44: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

D = {p| p is a polynomial with an integral root}. Hilbert’s tenth

problem asks in essence whether the set D is decidable.

Church-Turing Thesis

problem asks in essence whether the set D is decidable.

D1 = {p| p is a polynomial over x with an integral root}.

Here is a TM M1 that recognizes D1 :

M1 = "The input is a polynomial p over the variable x.

1. Evaluate p with x set successively to the values 0, 1, -1, 2, -2,

3, 3.... If at any point the polynomial evaluates to 0, accept.“

For the multivariable case, we can present a similar TM M that

recognizes D. Here M goes through all possible settings of its

variables to integral values.

Both M1 and M are recognizers but not deciders

Prof. MovagharTheory of Languages and Automata 44

Page 45: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

Church-Turing Thesis (Cont.)

O We can convert M1 to be a decider for D1 because

we can calculate bounds within which the roots of a

single variable polynomial must lie and restrict the

search to these bounds. In fact, one can prove that search to these bounds. In fact, one can prove that

the roots of such a polynomial must lie between the

values

± k cmax / c1

where k is the number of terms in the polynomial,

cmax is coefficient with the largest absolute value,

and c1 is the coefficient of the highest order term.

Page 46: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

O The input to a Turing Machine is a string.

O If we want to provide an object, rather than a string,

it must be represented as a string.

Terminology for describing Turing Machines

O The notion for the encoding of an object O into its

representation as a string is <O>

O Break the algorithm into stages

O The first line of the algorithm describes the input to

the machine

Prof. MovagharTheory of Languages and Automata 46

Page 47: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

O A = {⟨G⟩|G is a connected undirected graph}

O The following is a high-level description of a TM M

that decides A.

O M = "On input (G), the encoding of a graph G:

Example

O M = "On input (G), the encoding of a graph G:

1. Select the first node of G and mark it.

2. Repeat the following stage until no new nodes are

marked:

3. For each node in G, mark it if it is attached by an

edge to a node that is already marked.

4. Scan all the nodes of G to determine whether they all

are marked. If they are, accept; otherwise, reject."

Prof. MovagharTheory of Languages and Automata 47

Page 48: Chapter 3- The Church-Turing Thesis Sharif University of ...ce.sharif.edu/courses/91-92/1/ce415-1/resources... · Initially tape 1 contains the input w, and tapes 2 and 3 are empty

O How <G> encodes the graph G as a string

Example (Cont.)

O A list of the nodes of G followed by a list of the

edges of G

Prof. MovagharTheory of Languages and Automata 48