Turing Machines Wen-Guey Tzeng Computer Science Department - - PowerPoint PPT Presentation
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
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
TM Model
3 2017 Spring
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 – : QQ{L,R}, the transition function – : blank symbol – q0Q: the initial state – FQ: the set of final states
- Note: this TM is deterministic.
4 2017 Spring
Transition function
5
- (q0, a)=(q1, d, R)
2017 Spring
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
Transition graph
7
– (q0, a)=(q0, b, R) – (q0, b)=(q0, b, R) – (q0, )=(q1, , L)
2017 Spring
TM runs forever
8
- Check TM on input aab
2017 Spring
Instantaneous description
- x1qx2 = a1a2…ak-1 q akak+1…an
- Also, called “configuration”
9 2017 Spring
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
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
A computation
- A computation is a sequence of configurations
that leads to a halt state.
- q0aa ├ bq1b ├ bbq1├ bq1b (halt)
12 2017 Spring
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
TM as
- Language acceptors
- Transducers
14 2017 Spring
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), qfF, 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
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
Example:
- Design a TM to accept L={anbn : n1}
- 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
- 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
- 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
- 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
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
TM as transducers
- To compute a function f(w)=w’, where w, w’
are strings
– q0w├* qf w’ (halt)
- A function f:DR is TM-computable
if there is a TM M=(Q, , , , q0, , F) such that q0w├* qf f(w) (halt) for all wD
- We will show in the following that TM can
compute complicated functions
22 2017 Spring
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
- 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
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
26
Run q011
2017 Spring
Examples: (comparer)
- Design a TM to compute
q0w(x)0w(y)├* qY w(x)0w(y) if xy q0w(x)0w(y)├* qN w(x)0w(y) if x<y
27 2017 Spring
Combining TM for complicated tasks
- Design a TM to compute
f(x,y)=x+y if xy, and f(x,y)=0 if x<y
28 2017 Spring
- qC,0w(x)0w(y)
├* qA,0 w(x)0w(y) if xy ├* 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
Example: (if-then-else)
- if a then qj else qk
– (qi, a)=(qj0, a, R), for qiQ – (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
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
32 2017 Spring
Macroinstructionssubprogram
- A calls B
33 2017 Spring
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
- 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
Algorithms
- An algorithm for a functin f:DR
is a TM such that
q0d├* qff(d) for all dD
36 2017 Spring