COSC 3340 Introduction to Theory of Computation University

  • Slides: 19
Download presentation
COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 24

COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 24 1 Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Definition of Nondeterministic TM l A Nondeterministic Turing Machine M = (K, , ,

Definition of Nondeterministic TM l A Nondeterministic Turing Machine M = (K, , , s) – – l Configurations and the relation |─M and |─M* are defined in the natural way but now |─M need not be single-valued: – l One configuration may yield several others in one step. NTMs will only be constructed as language acceptors – 2 K, , and s are as for standard Turing machine (K X ) X ((K {h}) X ( {L, R})) Only one accepting computation required for input to be accepted. Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Example: L = {w {a, b}*: w contains an occurrence of the substring abaab

Example: L = {w {a, b}*: w contains an occurrence of the substring abaab a, b L # b L b, # a L a, # b L a a b, # # 3 Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Example: L = {w {a, b}*: w contains an occurrence of the substring abaab}

Example: L = {w {a, b}*: w contains an occurrence of the substring abaab} l l l 4 The machine receives input in the form #w#, where w {a, b}*. It first scans from the right to left and nondeterministically guesses a point in w to start checking for the specified pattern. It checks to see that the next five symbols are, from right to left, b, a, a, b, a. If this pattern is detected, the machine halts and therefore accepts the input string. If a violation of this pattern is found, the machine goes into an infinite loop. Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Example: L = {In: n is composite} # RIR l # # Given input

Example: L = {In: n is composite} # RIR l # # Given input #In# – – – Nondeterministically choose two numbers p, q > 1 and transform the input into #In #Ip #Iq #. See TM for writing Ip above. Use the multiplication machine to transform the result of Step 1 into #In #Ip*q #. Check to see that In = Ip*q; l 5 IR this is easy, since only the lengths of these strings need to be compared. Halt if the lengths are equal; otherwise continue computing forever in some trivial fashion. Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Simulation Idea for NTM l l DTM will explore the computation graph in BFS

Simulation Idea for NTM l l DTM will explore the computation graph in BFS (breadth-first order ) fashion. Enumerate all possible computation starting from all 1 -step computations, then 2 -step computations, … Initial configurations NTM 1 2 b NTM are designed as language acceptors only . . . 1 2 6 . . . b 1 b 2 . . . halt & accept Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Simulation Idea for NTM 0 0 1 0 □ □ … input tape x

Simulation Idea for NTM 0 0 1 0 □ □ … input tape x x # 0 1 x □ … simulation tape 1 2 3 3 2 3 1 2 D 1 1 3 □ address tape 7 Deterministic TM D simulating nondeterministic TM N Lecture 24 Uof. H - COSC 3340 - Dr. Verma …

Simulation Idea for NTM N l l l Initially tape 1 contains the input

Simulation Idea for NTM N l l l Initially tape 1 contains the input w, and tapes 2 and 3 are empty. Copy tape 1 onto tape 2. Use tape 2 to simulate N with input w on one branch of its nondeterministic computation. – – – l 8 Consult tape 3 to determine which choice to make. If no more symbol remain on tape 3 or if choice invalid, abort and go to next step. Go to next step if a reject configuration is encountered Replace the string on tape 3 with the lexicographically next string. Simulate the next branch of N’s computation by going to stage 2. Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Church-Turing Thesis l The thesis states that: – l l It is NOT a

Church-Turing Thesis l The thesis states that: – l l It is NOT a theorem, since it cannot be proved. (Algorithm is an informal concept). Recall, algorithm -- a sequence of precise steps, each of which can be executed in a finite amount of time with finite resources. – 9 The Turing Machine is the formal equivalent of the informal concept of algorithm. Precise means no intelligence or judgment required, can be executed literally. Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Evidence for the Thesis l l l All reasonable formal models so far have

Evidence for the Thesis l l l All reasonable formal models so far have turned out to be equivalent to TM. Reasonable -- means no infinite resources or power. Examples of other formal models: – – 10 Post Correspondence systems Random Access Machine model Unrestricted grammars. Partial Recursive Functions, etc. Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Universal Turing Machine We shall assume that there are fixed countably infinite sets K

Universal Turing Machine We shall assume that there are fixed countably infinite sets K = {q 1, q 2, q 3, …} and = {a 1, a 2, a 3, …} such that for every TM, the state set is a finite subset of K and the tape alphabet is a finite subset of . 11 Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Universal Turing Machine (contd. ) l qi h L ( ) Ii+1 I I

Universal Turing Machine (contd. ) l qi h L ( ) Ii+1 I I R ai II Ii+2 – l l l 12 Let c be another symbol We encode TM over the two-symbol alphabet {c, I}. Let M = (K, , , s) be a TM where now K K and . Thus K = {qi 1, qi 2, …, qik} and = {aj 1, aj 2, …, ajk} where i 1 < i 2 < … < ik and j 1 < j 2 < … < jk s = qim for some m, 1 m k Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Universal Turing Machine (contd. ) l l Next we define kl strings Spr the

Universal Turing Machine (contd. ) l l Next we define kl strings Spr the transition function where 1 p k and 1 r l Let (qip, ajr) = (q’, b), where – – l Let Spr = cw 1 cw 2 cw 3 cw 4 c, where – – 13 q’ K {h} b {L, R} w 1 = (qip) w 2 = (ajr) w 3 = (q’) w 4 = (b) Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Universal Turing Machine (contd. ) l l A Universal TM uses the encoding (M)

Universal Turing Machine (contd. ) l l A Universal TM uses the encoding (M) of other machines as programs to direct its operation. Therefore, U takes two arguments (M) – description of machine M – (w) – encoding of input string w and performs whatever M does on w. – 14 Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Universal Turing Machine (contd. ) l l 15 If M halts on input w,

Universal Turing Machine (contd. ) l l 15 If M halts on input w, then U halts on an input consisting of the encoding of M followed by the encoding of w. If U halts on an input consisting of the encoding of M followed by the encoding of w, then M halts on input w Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Universal TM as a 3 -tape TM Let U’ = 3 -tape TM U’

Universal TM as a 3 -tape TM Let U’ = 3 -tape TM U’ uses it three tapes as follows: The first tape contains the encoding of the tape of M The second tape contains the encoding of M itself The third tape contains the encoding of the state of M at the current point in the simulated computation. 16 Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Universal TM as a 3 -tape TM U’ U’ is started with some string

Universal TM as a 3 -tape TM U’ U’ is started with some string # (M) (w) on its first tape and the other two tapes are blank. – – 17 First U’ moves (M) onto the second tape and shift (w) down to the left end of the first tape, preceding it by #c (#) and following it by (#)c. Thus at this point the first tape contains # (#w#). From (M), U’ extracts the encoding of the initial state of M, which it copies onto the third tape. Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Universal TM as a 3 -tape TM U’ (contd. ) – U’ sets about

Universal TM as a 3 -tape TM U’ (contd. ) – U’ sets about simulating the steps of the computation of M l – 18 U’ keeps the head on the second and third tapes at the left Since M starts off scanning the last blank of #w#, U’ should begin its simulation by moving its head on the first tape to the last c on the tape. Lecture 24 Uof. H - COSC 3340 - Dr. Verma

Universal TM as a 3 -tape TM U’ (contd. ) – Now U’ finds

Universal TM as a 3 -tape TM U’ (contd. ) – Now U’ finds on its second tape the block of the form cc. Iic. Ijc. Ikc. Ilcc such that l Ii l – Finally, U’ puts Ik on the third tape and checks whether the third tape now contains (h). l l 19 is the sting of I’s ending at the current head position on the third tape Ij is that on the first tape, and changes the first tape appropriately. If it does not, then U’ simulates another computation step by M If it does, then U’ itself halts. Lecture 24 Uof. H - COSC 3340 - Dr. Verma