lecture 18uofh - cosc 3340 - dr. verma 1 cosc 3340: introduction to theory of computation university...

23
Lecture 18 UofH - COSC 3340 - Dr. Ve rma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Upload: gabriel-anthony

Post on 01-Jan-2016

232 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma1

COSC 3340: Introduction to Theory of Computation

University of Houston

Dr. Verma

Lecture 18

Page 2: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma2

Combining Turing Machines

A Turing Machine can be a component of another Turing Machine (“subroutine”)

We will develop a graphical notation to build larger machines for more complex tasks easily. The scheme is hierarchical.

Combination is possible since all TM’s are designed to be “non-hanging” – so the first machine can save something on the leftend of the tape.

Reference: “Elements of the Theory of Computation’’ by

H.R. Lewis and C.H. Papadimitriou.

Page 3: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma3

Combining Turing Machines

Assumptions, for convenience: – From now on, Turing machines can either write a symbol or

move head but not both in the same move.

– All TMs have only one alphabet , containing the blank symbol

– All machines start in this position: #w#

There are two types of basic machines:– Symbol-writing– Head-moving

Page 4: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma4

Basic Machines: Symbol-Writing

There are || symbol-writing machines, one for each symbol in . Each TM simply writes a specified symbol in the currently scanned tape square and halts.

Formally, the TM which writes a is

Wa = (K, , , s), where K = {q} for some arbitrarily chosen state qs = q and(q, b) = (h, a) for each b

Notation: Wa

Page 5: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma5

Basic Machines: Head-Moving

The head-moving machines simply move the head one square to the left or right, and then halt.

Formally, the TM’s are

VL = ({q}, , L, q), where

L(q, a) = (h, L) for each a VR = ({q}, , R, q), where

R(q, a) = (h, R) for each a

let q be some state

let q be some state

Notation: L and R

Page 6: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma6

Rules for Combining Machines

Machines may be connected just like a Finite Automaton.

If two machine are connected, then the first machine has to halt before the other machine starts.

Page 7: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma7

Rules for Combining Machines

M1 M2

M1 M2

M3

a

b

If M1 and M2 are any TM Start in the initial state of M1; operate as M1 would operate until M1 would

halt; then initiate M2 and operate as M2 would operate

After M1 halts either M2 or M3 would start depending on the

symbol.

Page 8: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma8

Abbreviations

L/R – A TM that moves the head one cell to the left/right

R□ - A TM that moves to the Right seeking □ L□ - A TM that moves to the Left seeking □ R□ - A TM that moves to the Right seeking a

nonblank spot L□ - A TM that moves to the Left seeking

nonblank spot

Page 9: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma9

Example: R□

R

a

b

R□State Symbol Next state action

q0 □ (q1, □, R)

q0 a (q1, a, R)

q0 b (q1, b, R)

q1 □ halt

q1 a (q1, a, R)

q1 b (q1, b, R)

M = ({q0, q1 }, {a, b}, {a, b, □}, , q0, {})

L□ is very similar to R□

Alphabet () = {a, b}

Page 10: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma10

JFLAP SIMULATION

Page 11: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma11

JFLAP SIMULATION

Page 12: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma12

JFLAP SIMULATION

Page 13: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma13

JFLAP SIMULATION

Page 14: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma14

JFLAP SIMULATION

Page 15: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma15

Example: Machine 1

>L□

R□

R □(R□)2 (L□)2 □

Page 16: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma16

Example: Machine 1 (contd.)

□abc□□abc□□□bc□□□bc□□□□bc□a□□bc□a□abc□a

□abc□a□a□c□a□a□c□a□□a□c□ab□a□c□ab□abc□ab

□abc□a□ab□□a□ab□□ab□□a□c□abc□ab□□abc□abc□abc□abc□abc□abc□abc□

Let C be the TM, we say C transforms □w□ into □w□w□ (Copying Machine)

Page 17: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma17

Example: Machine 2

>L□

L□

R LR

Page 18: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma18

Example: Machine 2 (contd.)

□ab□□ab□□ab□□ab□aab□aab□

aab□aab□abb□abb□ab□

Let SL be the TM, we say SL transforms □w□ into w□

(Shift-Left Machine)

Page 19: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma19

Example: Machine 3

>aL□L

Ra

□ aRa□CaLa□

LI

aRa□ IR�L□ □

LI

□R�

R

□La□

a

□I

a

I

Page 20: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma20

Example: Machine 3 (contd.)

f(n, m) = n m is computed by the TM

(Multiplication Machine)

□II□II□□II□IIa□II□IIa□II□IIa□I□□IIa□I□□IIa□a□□IIa□a□□IIa□a□□II□□a□□II□II□

□a□□II□IIa□a□□II□IIa□□□□II□IIa□□□□II□IIaa□□□II□IIaa□□□II□IIaa□□□II□II□a□□□II□II□a□□□IIIII□a□□□IIIII□

a□□□IIIII□a□□□IIII□□a□□□IIII□□a□□IIIII□□a□□IIIII□□

.

.

.□IIII□□□□□

f(2,2) = ?

Page 21: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma21

Turing Machine Models

Variants of TM model – Two-way infinite tape– Multiple tapes– Multiple heads on each tape– Multi-dimensional tapes, and– Combinations of the above.

Page 22: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma22

Are the variants more powerful than the basic model?

Ans: No

All "reasonable" extensions including those listed before lead to the same classes of languages or functions. Proved by showing that the basic model can simulate the extensions.

Page 23: Lecture 18UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18

Lecture 18 UofH - COSC 3340 - Dr. Verma23

Techniques for Simulations

The basic TM has– expanded set of states– expanded alphabet

Note: one step in extended model is usually simulated by many steps in the basic model.