Turing Machines Wen-Guey Tzeng Computer Science Department - - PowerPoint PPT Presentation

turing machines
SMART_READER_LITE
LIVE PREVIEW

Turing Machines Wen-Guey Tzeng Computer Science Department - - PowerPoint PPT Presentation

Turing Machines Wen-Guey Tzeng Computer Science Department National Chiao Tung University Alan Turing One of the first to conceive a machine that can run computation mechanically without human intervention. We call algorithmic


slide-1
SLIDE 1

Turing Machines

Wen-Guey Tzeng Computer Science Department National Chiao Tung University

slide-2
SLIDE 2

Alan Turing

  • One of the first to conceive a machine

that can run computation mechanically without human

  • intervention. We call “algorithmic

computation” now.

  • The first to conceive a universal

machine – that can run programs

  • Break German Enigma Machine

(encryption) in WWII

  • Turing Award: the most prestigious

award in CS

  • Bio movie: The Imitation Game, 2015

2

1912-1954

2017 Spring

slide-3
SLIDE 3

TM Model

3 2017 Spring

slide-4
SLIDE 4
slide-5
SLIDE 5

Definition

  • A Turing machine (TM) M is defined by

M=(Q, , , , q0, ฀, F)

– Q: the set of internal states – : the input alphabet – : the tape alphabet – : QQ{L,R}, the transition function – ฀: blank symbol – q0Q: the initial state – FQ: the set of final states

  • Note: this TM is deterministic.

4 2017 Spring

slide-6
SLIDE 6

Transition function 

5

  • (q0, a)=(q1, d, R)

2017 Spring

slide-7
SLIDE 7

6

Example:

  • M=({q0, q1}, {a,b}, {a, b, ฀}, , q0, ฀, {q1})

– (q0, a)=(q0, b, R) – (q0, b)=(q0, b, R) – (q0, ฀ )=(q1, ฀, L)

2017 Spring

slide-8
SLIDE 8

Transition graph

7

– (q0, a)=(q0, b, R) – (q0, b)=(q0, b, R) – (q0, ฀ )=(q1, ฀, L)

2017 Spring

slide-9
SLIDE 9

TM runs forever

8

  • Check TM on input aab

2017 Spring

slide-10
SLIDE 10

Instantaneous description

  • x1qx2 = a1a2…ak-1 q akak+1…an
  • Also, called “configuration”

9 2017 Spring

slide-11
SLIDE 11

10

Example:

  • M=({q0, q1}, {a,b}, {a, b, ฀}, , q0, ฀, {q1})

– (q0, a)=(q0, b, R) – (q0, b)=(q0, b, R) – (q0, ฀ )=(q1, ฀, L)

  • ID: q0aa, bq0a, bbq0฀, bq1b
  • Move:

– q0aa ├ bq0a ├ bbq0฀├ bq1b (halt)

2017 Spring

slide-12
SLIDE 12

TM halts

11

  • A TM on input w “halts” if q0w reaches a

configuration that  is not defined.

– A TM on an input w may not halt. (Run forever)

  • Halting configuration: x1qx2 (halt)

– Halting does not imply acceptance

  • Accepting configuration: x1qfx2 (halt)

– Must halt and enter a final state qf – Acceptance implies halting

  • Infinite loop (non-stop): x1qx2 ├* 

2017 Spring

slide-13
SLIDE 13

A computation

  • A computation is a sequence of configurations

that leads to a halt state.

  • q0aa ├ bq1b ├ bbq1฀├ bq1b (halt)

12 2017 Spring

slide-14
SLIDE 14

Standard TM

  • It is deterministic.
  • There is only one tape.
  • The tape is unbounded in both directions.
  • All other cells are filled with blanks.
  • No output devices.
  • The input is on the tape in the beginning.
  • The left string on the tape can be viewed as
  • utput.

13 2017 Spring

slide-15
SLIDE 15

TM as

  • Language acceptors
  • Transducers

14 2017 Spring

slide-16
SLIDE 16

TM as language acceptors

  • A string w is accepted by M if

– M on input w enters a final state and halts. – Note: no need to read the entire input

  • The language accepted by M

L(M)={w+: q0w├* x1qfx2 (halt), qfF, x1, x2* }

– x1qfx2 (halt) is a halt configuration.

  • A language accepted by some TM is called a

“recursively enumerable (r.e.) ” set.

15 2017 Spring

slide-17
SLIDE 17

Example:

  • Design a TM to accept the strings of form 00*
  • The transition function

– (q0, 0)=(q1, 0, R) – (q1, 0)=(q1, 0, R) – (q1, ฀)=(q2, ฀, R)

  • F={q2}

16 2017 Spring

slide-18
SLIDE 18

Example:

  • Design a TM to accept L={anbn : n1}
  • Idea:

– Loop

  • Mark leftmost ‘a’ as ‘x’ in the tape
  • Move all the way right to mark ‘b’ as ‘y’

– After marking all a’s, move all the way right to find ฀

17 2017 Spring

slide-19
SLIDE 19
  • Example, w=aabb
  • Mark leftmost ‘a’ as ‘x’ in the tape

– (q0, a)=(q1, x, R)

  • Move all the way right to mark ‘b’ as ‘y’

– (q1, a)=(q1, a, R) – (q1, y)=(q1, y, R) – (q1, b)=(q2, y, L)

18

. . . ฀ a a b b ฀ . . .

2017 Spring

slide-20
SLIDE 20
  • Move back to find leftmost ‘a’

– (q2, y)=(q2, y, L) – (q2, a)=(q2, a, L) – (q2, x)=(q0, x, R)

  • Repeat until all a’s are marked as x’s

19

. . . ฀ x a y b ฀ . . .

2017 Spring

slide-21
SLIDE 21
  • After marking all a’s as x’s, move all the way

right to find ฀

– (q0, y)=(q3, y, R) – (q3, y)=(q3, y, R) – (q3, ฀)=(q4, ฀, R)

– If ‘b’ is encountered during the action of moving right, TM halts on a non-final state.

20

. . . ฀ x x y y ฀ . . .

2017 Spring

slide-22
SLIDE 22

Example:

  • Design a TM to accept L={w{a,b}+ : na(w)=nb(w)}
  • Idea:

– Loop

  • Pose at the beginning of the string
  • Mark leftmost ‘a’ as ‘x’ in the tape
  • Move all the way right to find the first b and mark it as

– After marking all symbols as X, enter the final state

21 2017 Spring

slide-23
SLIDE 23
slide-24
SLIDE 24
slide-25
SLIDE 25

TM as transducers

  • To compute a function f(w)=w’, where w, w’

are strings

– q0w├* qf w’ (halt)

  • A function f:DR is TM-computable

if there is a TM M=(Q, , , , q0, ฀, F) such that q0w├* qf f(w) (halt) for all wD

  • We will show in the following that TM can

compute complicated functions

22 2017 Spring

slide-26
SLIDE 26

Example: (integer adder)

  • Given two positive integer x and y, compute

x+y

– x and y are unary-represented

  • Eg. X=3, w(x)=111

– Input: w(x) 0 w(y) – Output: w(x+y) 0 – That is, q0 w(x)0w(y)├qf w(x+y)0

23 2017 Spring

slide-27
SLIDE 27
  • The transition function
  • (q0, 1)=(q0, 1, R)
  • (q0, 0)=(q1, 1, R)
  • (q1, 1)=(q1, 1, R)
  • (q1, ฀)=(q2, ฀, L)
  • (q2, 1)=(q3, 0, L)
  • (q3, 1)=(q3, 1, L)
  • (q3, ฀ )=(q4, ฀, R)
  • Run q0111011

24 2017 Spring

slide-28
SLIDE 28

Example: (string copier)

  • Design a TM to compute q0w├* qf ww, w=1+
  • Steps
  • 1. Replace every 1 by x
  • 2. Find the rightmost x and replace it with 1
  • 3. Travel to the right end and create 1 (in replace
  • f ฀)
  • 4. Repeat 2 and 3 until there are no x’s

25 2017 Spring

slide-29
SLIDE 29

26

Run q011

2017 Spring

slide-30
SLIDE 30

Examples: (comparer)

  • Design a TM to compute

q0w(x)0w(y)├* qY w(x)0w(y) if xy q0w(x)0w(y)├* qN w(x)0w(y) if x<y

27 2017 Spring

slide-31
SLIDE 31

Combining TM for complicated tasks

  • Design a TM to compute

f(x,y)=x+y if xy, and f(x,y)=0 if x<y

28 2017 Spring

slide-32
SLIDE 32
  • qC,0w(x)0w(y)

├* qA,0 w(x)0w(y) if xy ├* qE,0 w(x)0w(y) if x<y

  • qA,0w(x)0w(y) ├* qA,f w(x+y)0
  • qE,0w(x)0w(y) ├* qE,f 0

29 2017 Spring

slide-33
SLIDE 33

Example: (if-then-else)

  • if a then qj else qk

– (qi, a)=(qj0, a, R), for qiQ – (qj0, c)=(qj, c, L), for all c – (qi, b)=(qk0, b, R) for b-{a} – (qk0, c)=(qk, c, L), for all c

30 2017 Spring

slide-34
SLIDE 34

Example: (integer multiplier)

  • Design a TM for q0w(x)0w(y)├* qf w(xy)
  • Steps

– Loop until x contains no more 1’s

  • Find a 1 in x and replace it with another a
  • Replace leftmost 0 by 0y

– Replace all a’s with 1’s

31 2017 Spring

slide-35
SLIDE 35

32 2017 Spring

slide-36
SLIDE 36

Macroinstructionssubprogram

  • A calls B

33 2017 Spring

slide-37
SLIDE 37

Turing’s Thesis

  • Mechanical computation

– Computation without human intervention

  • Turing Thesis: any computation that can be

carried out by mechanical means can be carried out by some Turing machine.

  • Also called “Church-Turing Thesis”

34 2017 Spring

slide-38
SLIDE 38
  • Reasoning:

– Anything that can be done by an existing digital computer can be done by a TM – No one has yet been able to suggest a problem, solvable by algorithms, but cannot be solved by some TM – Other models are proposed. But, they are no more powerful than TM’s.

  • Even quantum computers are no more powerful than

TM’s in terms of the power language acceptance

35 2017 Spring

slide-39
SLIDE 39

Algorithms

  • An algorithm for a functin f:DR

is a TM such that

q0d├* qff(d) for all dD

36 2017 Spring

slide-40
SLIDE 40