Download presentation
Presentation is loading. Please wait.
Published byLiliana Grant Modified over 8 years ago
1
CS 3240 – Chapter 9
2
Turing Machines From Alan Turing, 1936 Turns out to be the LAST machine The only machine you'll ever need The Church-Turing Thesis All algorithms have a Turing Machine equivalent ▪ Some TMs are not algorithms, however 6/13/20162CS 3240 - Chapter 9
3
We have shown that a n b n c n is not context free By the Pumping Lemma What if we add an extra stack to a PDA? 6/13/20163CS 3240 - Chapter 9
4
input, pop1/pop2, push1/push2 6/13/20164CS 3240 - Chapter 9
5
a n is accepted by an FA a n b n is accepted by a PDA a n b n c n is accepted by a 2PDA What about a n b n c n d n ? 6/13/20165CS 3240 - Chapter 9
6
6/13/20166CS 3240 - Chapter 9
7
An FA is a machine with no auxiliary memory A PDA is like an FA but with unlimited, restricted memory LIFO access A Turing Machine is like an FA but with unlimited, unrestricted memory We can move to any memory cell We can both read and write there 6/13/20167CS 3240 - Chapter 9
8
LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar Recursively Enumerable Turing MachineUnrestricted Phrase- Structure Grammar 8CS 3240 - Introduction
9
6/13/20169CS 3240 - Chapter 9
10
6/13/201610CS 3240 - Chapter 9
11
Control Unit (Deterministic) states (1 start state; 1 or more or halt states) transitions: input,output,move (L or R) I/O Tape (2-way, infinite) pre-populated with (finite) input output left on tape after processing special blank symbol ☐ ▪ not part of input alphabet ▪ used as a separator and/or a boundary 6/13/201611CS 3240 - Chapter 9
12
Contents left on tape is ignored Typically has only one accepting state with no out-edges Any string that causes the TM to halt in an accepting state is in the TM’s language otherwise it is not in the language (an explicit reject state may also be used) 6/13/201612CS 3240 - Chapter 9
13
Pseudocode: Replace the first a with an X Move right to first b, replace with Y Move to right first c, replace with Z Move left to right-most X Repeat the above for steps until no more a’s When no more a’s, skip over all Y’s and Z’s fail if anything other than a Y or Z is encountered Halt and accept or reject 6/13/201613CS 3240 - Chapter 9
14
aabbcc Xabbcc XaYbcc XaYbZc XXYbZc XXYYZc XXYYZZ XXYYZZ ☐ XXYYZZ ☐☐ (accept) 6/13/201614CS 3240 - Chapter 9
15
6/13/201615CS 3240 - Chapter 9 Trace aabbcc
16
(q 0 )aabbcc X(q 1 )abbcc Xa(q 1 )bbcc XaY(q 2 )bcc XaYb(q 2 )cc XaY(q 3 )bZc Xa(q 3 )YbZc X(q 3 )aYbZc (q 3 )XaYbZc X(q 0 )aYbZc XX(q 1 )YbZc XXY(q 1 )bZc XXYY(q 2 )Zc XXYYZ(q 2 )c XXYY(q 3 )ZZ XXY(q 3 )YZZ XX(q 3 )YYZZ X(q 3 )XYYZZ XX(q 0 )YYZZ XXY(q 4 )YZZ XXYY(q 4 )ZZ XXYYZ(q 4 )Z XXYYZZ(q 4 ) ☐ XXYYZZ ☐ (q 5 ) ☐ (accept) 6/13/201616CS 3240 - Chapter 9
17
A sequence of configurations in a TM leading to a halt state i.e., it doesn’t crash If the TM is an acceptor, it explicitly accepts If the TM represents some function, f, it leaves f(x) on the tape, for each valid input x 6/13/2016CS 3240 - Chapter 917
18
6/13/2016CS 3240 - Chapter 918
19
What would be a reasonable strategy? 6/13/2016CS 3240 - Chapter 919
20
6/13/2016CS 3240 - Chapter 920
21
Suppose f: D → R is a function from domain D to range R If there is a TM that transforms every d in D to f(d) That is, it reads d from the tape, does its work, halts, and leaves f(d) on the tape… Then f is Turing-computable This is the formal definition of an algorithm 6/13/201621CS 3240 - Chapter 9
22
Must first decide how to encode numbers on a TM tape Then we must separate the numbers, so we can distinguish between them Plan: represent the numbers in unary notation then move the 1’s from one number to the other! ▪ i.e., just remove the separator, moving the 1’s together ▪ we’ll use zero as a separator ▪ see next slide… 6/13/201622CS 3240 - Chapter 9
23
11101111 11111111 11111111_ 1111111_ 6/13/201623CS 3240 - Chapter 9
24
6/13/201624CS 3240 - Chapter 9
25
Using unary notation, as usual 6/13/2016CS 3240 - Chapter 925
26
6/13/201626CS 3240 - Chapter 9
27
6/13/201627CS 3240 - Chapter 9 Trace ababb
28
TMs typically have one start and one or two halt states (but can have many): one if the TM is a function two if the TM is an acceptor You can “call” a TM as a routine by setting up appropriate “linkage” return to the desired state in the calling machine make sure the tape workspace is in an acceptable configuration for your instructions 6/13/201628CS 3240 - Chapter 9
29
Tape configuration: start: [x]0[y]0 finish: [x]0[y]0[xy] First, modify copy to accommodate a 0-delimiters: 0[y]0… → 0[y]0…[y] and finish by positioning at left of y Then, mark a 1 in x with a, copy y to end, and repeat; then restore x’s a’s to 1’s 6/13/201629CS 3240 - Chapter 9
30
6/13/201630CS 3240 - Chapter 9
31
6/13/2016CS 3240 - Chapter 931
32
See Example 9.11 for an explanation of Comparer. See xplusyTM.py 6/13/201632CS 3240 - Chapter 9
33
T = (Q, ∑, Γ, δ, q 0, H) Q = set of states ∑ = input alphabet Γ = tape alphabet includes ∑ and blank symbol ( ☐ ) q 0 = start state H = one or more halt states no out-arrows each typically represents a different meaning ▪ e.g., final vs. non-final 6/13/2016CS 3240 - Chapter 933
34
6/13/2016CS 3240 - Chapter 934 δ(q 0,1) = (q 0,1,R) δ(q 0,0) = (q 1,1,R) δ(q 1,1) = (q 1,1,R) δ(q 1, ☐ ) = (q 2, ☐,L) δ(q 2,1) = (q h, ☐,R)
35
δ ☐ 01 q0q0 (q 1,1,R)(q 0,1,R) q1q1 (q 2, ☐,L) (q 1,1,R) q2q2 (q h, ☐,R) 6/13/2016CS 3240 - Chapter 935 δ(q 0,1) = (q 0,1,R) δ(q 0,0) = (q 1,1,R) δ(q 1,1) = (q 1,1,R) δ(q 1, ☐ ) = (q 2, ☐,L) δ(q 2,1) = (q h, ☐,R)
36
q 0,1,q 0,1,R q 0,0,q 1,1,R q 1,1,q 1,1,R q 1,_,q 2,_,L q 2,1,q h,_,R (_ = ☐ ; Use in Program 4) 6/13/2016CS 3240 - Chapter 936
37
Input: A TM ▪ start state ▪ halt states ▪ quintuple format: state1,input,state2,output,direction An input string (initial tape contents) Output: A trace of the actions of the machine ▪ with the current state positioned at the read-write head Final state and tape contents 6/13/2016CS 3240 - Chapter 937
38
TMs can make multiple passes over the data in multiple directions And can process an arbitrary amount of auxiliary data in addition to the original input They can give more meaningful output vs. just yes/no Interesting fact: TMs came first! 6/13/2016CS 3240 - Chapter 938
39
TMs suffer from a vulnerability that FAs and PDAs do not: They are not guaranteed to halt They may hang (loop forever)! Depends on the nature of the computation More on this later 6/13/2016CS 3240 - Chapter 939
40
“Any computation that can be carried out by mechanical means can be performed by some TM” Anything that can be done on any digital computer can be done by a TM it’s the “lowest-level” programming language No one has yet found a solvable problem for which a TM cannot be written No alternative computation model invented is more powerful then a TM 6/13/201640CS 3240 - Chapter 9
41
The Turing Machine is the model for most programming as we know it Imperative Programming Defines a machine architecture Characterized by reading and writing memory Instructions and data share the same memory There are other models of computation Lambda Calculus (Functional paradigm; CS 4450) Post Systems, Markov Systems, Structured Prog… 6/13/2016CS 3240 - Chapter 941
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.