COMP3630 / -无代写
时间:2025-04-02
COMP3630 / COMP6363 week 5: Introduction to Turing Machines This Lecture Covers Chapter 8 of HMU: Introduction to Turing Machines slides created by: Dirk Pattinson, based on material by Peter Hoefner and Rob van Glabbeck; with improvements by Pascal Bercher convenor & lecturer: Pascal Bercher The Australian National University Semester 1, 2025 Content of this Chapter Turing Machine Extensions of Turing Machines Restrictions of Turing Machines Extensions of PDAs – and Relationship to TMs Additional Reading: Chapter 8 of HMU. Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 2 / 34 Introduction to TMs Introduction to TMs Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 3 / 34 Introduction to TMs Turing Machine: Informal Definition Finite Control B B B B BBa bc a b b · · ·· · · ∠ A tape extending infinitely in both sides ∠ A reading head that can edit tape, move right or left ∠ A finite control ∠ A string is accepted if finite control ever reaches a final/accepting state Heads-up: There are many variations of TMs (e.g., in COMP1600, the head could also stay stationary), and we will go through a few of them. Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 4 / 34 Introduction to TMs Turing Machine: Formal Definition A Turing machine M = (Q,Σ,Γ, δ, q0,B,F ) is comprised of: ∠ Q: finite set of states ∠ Σ: finite set of input symbols ∠ Γ: finite set of tape symbols such that Σ ⊆ Γ ∠ δ: (deterministic) transition function. δ is a partial function over Q × Γ, where the first component is viewed as the present state, and the second is viewed as the tape symbol read. If δ(q,X ) is defined, then Present state Next StateTape symbol Reading head direction to move next ‹(q;X) = (q0; Y; D) The symbol replacing X ∠ B ∈ Γ \ Σ is the blank symbol. All but a finite number of tape symbols are Bs. ∠ q0: the initial state of the TM. ∠ F : the set of final/accepting states of the TM. ∠ Head always moves to the left or right. Being stationary is not an option. It can also be defined with such an option, see tutorial. Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 5 / 34 Introduction to TMs Describing TMs ∠ Turing machines can be defined by describing δ using a transition table. ∠ They can also be defined using transition diagrams (with labels appropriately altered) q q0If ‹(q;X) = (q0; Y; D) X=Y D A TM that accepts any binary string that does not contain 111 q0 1= 1 ! 1=1! 1=1! 0=0! 0= 0 ! q1 q2q3 qf B=B ! B=B ! B =B ! 0=0! This encodes a DFA (almost). Can you see why? Because we never manipulate the tape and terminate once the String is read. The only difference is that not all edges are defined, but this can be fixed with a trap state. Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 6 / 34 Introduction to TMs Instantaneous Descriptions of TMs ∠ An instantaneous description (or configuration) of a TM is a complete description of the system that enables one to determine the trajectory of the TM as it operates. ∠ The instantaneous description or configuration or ID of a TM contains 3 parts: (a) The (finite, non-trivial) portion of tape to the left of the reading head; (b) the state that the TM is presently in; and (c) the (finite, non-trivial) portion of the tape to the right of the reading head. q B B X1 X2 X3 X‘· · · · · · · · ·· · · Xi 1 i ‘ head q B B X1 X2 X3 · · · · · ·· · · X‘ B B B B z }| {i Blanks segment to the strict leftz }| { X1 · · ·Xi 1 statez}|{ q segment from the head onwardsz }| { Xi · · ·X‘ segment to the strict leftz }| { X1 · · ·X‘Bi 1 statez}|{ q head · · · q B BX1 X2 X3 · · ·· · · X‘B B z }| { head · · · i Blanks · · · statez}|{ q segment from the head onwardsz }| { BiX1 · · ·X‘ IDState, Tape contents, Reading head location Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 7 / 34 Introduction to TMs ‘Moves’ of a TM ∠ Just as in the case of a PDA, we use ⊢ M to indicate a single move of a TM M, and ∗ ⊢ M to indicate zero or a finite number of moves of a TM. Next IDPresent ID X1 · · ·Xi 1qXi · · ·X‘ X1 · · ·X‘Bi 1q qBiX1 : : : X‘ Transition ‹(q;Xi ) = (q 0; Y; R) ‹(q;Xi ) = (q 0; Y; L) X1 · · ·Xi 1Y q0Xi+1 · · ·X‘ X1 · · ·Xi 2q0Xi 1Y Xi+1 · · ·X‘ ‹(q;B) = (q0; Y; R) ‹(q;B) = (q0; Y; R) ‹(q;B) = (q0; Y; L) ‹(q;B) = (q0; Y; L) X1 · · ·X‘Bi 1Y q0 (1 < i < ‘) X1 · · ·X‘ 1q0X‘Y i = 1 X1 · · ·X‘Bi 2q0BY i > 1{ Y q0X2 · · ·X‘ i = 0 Y q0Bi 1X1 · · ·X‘ i > 0{ q0BY Bi 1X1 · · ·X‘ i > 0 q0BY X2 · · ·X‘ i = 0{ Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 8 / 34 Introduction to TMs Language accepted by a TM ∠ A string w is in the language accepted by a TM M iff q0w ∗ ⊢ M αpβ for some p ∈ F . For accepted words, note that the TM may not necessarily halt (i.e., allow for no further transitions) in such a final state; it may even move to a non-final state afterwards. If a final state is ever visited, w is accepted in the language of M. It is always possible to redesign a TM to halt for all accepted words without changing its language; just remove all transitions out of final states. ∠ Otherwise, w is rejected by M. Careful: Rejection might be defined differently in different textbooks/courses. (In fact, our textbook doesn’t even define it! It just “uses” it.) We will learn that we can’t always notice whether a word is rejected, because the TM might be stuck in a loop (and we don’t know that). In general, we cannot redesign TMs to halt on all rejected words. ∠ A language L is recursively enumerable if it is accepted by some TM. ∠ A language L is recursive if it is accepted by a TM that always halts on all inputs. Re cu rsi veRegular Co nte xt- fre e Re cu rsi ve ly En um er ab le (R E) (Context-sensitive languages sit between the CFLs and recursive languages.) Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 9 / 34 Introduction to TMs On Acceptance, Rejection, Halting, and Decidability Usually, there is no need to define outgoing transitions for final states, since as soon as we enter a final state, the input word is accepted (so why proceed?) ∠ Thus, when you pick/design a TM to accept a given language L, you can consider “reasonable” TMs that always halt on accepted words. ∠ However, if you have to judge properties of a given TM (e.g., whether it always halts, or accepts a particular word etc.), then you have to deal with any TM – reasonable or not... (Motivation: You might want to judge properties of somebody’s “program”) Let L be given and M a TM, such that L(M) = L. ∠ If M halts on all inputs in Σ∗, we call it a total TM, say that it decides L, and call L a decidable (or recursive) language. ∠ If M halts on all inputs taken from L (but does not necessarily halt for all inputs in Σ∗ \ L), then L is semi-decidable (or recursively enumerable). ∠ In both cases, M ‘accepts’ L. (That’s literally what L(M) = L means!) ∠ Note: Just because L ∈ RE does not mean L /∈ R since R ⊆ RE . Also, R ⊊ RE . Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 10 / 34 Introduction to TMs On Acceptance, Rejection, Halting, and Decidability ∠ “Accepting w”, i.e. w ∈ L(M), does not imply halting, since the machine may keep going after reaching a final state. If we design a TM, there’s no point in defining transitions out of any final state (so, it would halt). ∠ “Rejecting w”, i.e. w /∈ L(M), also does not imply halting. Either w was rejected because the TM halted after a finite number of steps having never reached a final state, or the TM loops through non-final states forever (and never reached a final state before). ∠ “Not accepting w” is the same as “rejecting w .” ∠ “Not rejecting w” is the same as “accepting w .” ∠ “Halting on w” neither implies w ∈ L(M) nor w /∈ L(M), i.e., it is not enough information to determine whether w was accepted or rejected. This is because we do not know whether we have previously traversed a final state. ∠ “Not halting on w” also neither implies w ∈ L(M) nor w /∈ L(M). Those are determined by whether the TM ever traverses a final state. However, if the TM is “reasonable”, then w /∈ L(M) (i.e., the word is rejected). Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 11 / 34 Introduction to TMs On Acceptance, Rejection, Halting, and Decidability Accepted w ∈ L(M) Rejected w /∈ L(M) Halted on w reached a final state, possibly kept going, then eventually reached a point where no further transition was possible eventually reached a point where no further transition was possible and never traversed a final state Looped forever on w reached a final state and keeps making transitions forever keeps making transitions forever, traversing non-final states only Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 12 / 34 Extensions of TMs Extensions of TMs Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 13 / 34 Extensions of TMs Multiple-Track TMs Multiple-track TM ∠ We do not provide a formal definition (but assume you could provide one). ∠ There are k tracks, each having symbols written on them. They are essentially tapes, but we call them that way since they are not independent. ∠ The machine can only read symbols from each tape corresponding to one location, i.e., all symbols in a column at any one time. ∠ Likewise, all tapes move simultaneously in the same direction. Finite Control · · ·· · · · · ·· · · · · ·· · · ... X1 X2 Xk ∠ A k-track TM with tape alphabet Γ has the same language-acceptance power as a TM with tape alphabet Γk . (E.g., each cell contains the “symbol” (X1, . . . ,Xk)) Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 14 / 34 Extensions of TMs Multi-tape TMs Multiple-tape TM ∠ We (again) don’t provide a formal definition (but assume you could provide one). ∠ There are k (independent) tapes, each having symbols written on them. ∠ The machine can read each tape independently, i.e., the symbols read from each tape need not correspond to the same location. ∠ After all tapes are read, all tape transitions must happen (now we can also stay with a head – the entire TM is for convenience anyway!). Finite Control · · ·· · · · · ·· · · · · ·· · · ... X1 X2 Xk ∠ The rest stays the same (e.g., one set of states, acceptance, etc.). Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 15 / 34 Extensions of TMs Multi-tape TMs Theorem 8.2.1 Every language that is accepted by a multi-tape TM is also recursively enumerable (i.e., accepted by some ‘standard’ TM). Proof of Theorem 8.2.1 ∠ Let L be accepted by a k-tape TM M. We’ll devise a 2k-track TM M ′ that accepts L. ∠ Every even tape of M ′ has the same alphabet as that of the k-tape TM. The 2i th track of M ′ contains exactly the same contents as the i th tape of M. ∠ Every odd track has an alphabet {B, †}, and contains a single †. The 2i − 1th track of M ′ contains † at the location where the i th head of M is located. Finite Control Finite Control · · ·· · · · · ·· · · · · ·· · ·· · · 10 11 54 1312 6 14 † 12 † † 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 1 1 1 1 1 0 1 0 1 0 1 0 11 0 1 0 1 0 1 0 1 M 0 M · · ·· · · Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 16 / 34 Extensions of TMs Multi-tape TMs Proof of Theorem 8.2.1 (1 of 3) What is the main problem we need to solve? ∠ In the Multi-tape TM M, heads move independently, whereas in the Multi-track TM M ′ they do not. So the heads can diverge: Finite Control Finite Control · · ·· · · · · ·· · · · · ·· · ·· · · 10 11 54 1312 6 14 † 12 † † 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 1 1 1 1 1 0 1 0 1 0 1 0 11 0 1 0 1 0 1 0 1 M 0 M · · ·· · · (But M ′ has just a single head position!) So, how to solve it? ∠ Make sure that in each transition of M, we visit all heads of M ′. ∠ “Store” all head positions in a state with k (number of tapes) entries. Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 17 / 34 Extensions of TMs Multi-tape TMs Proof of Theorem 8.2.1 (2 of 3) ∠ The state of M ′ has 3 components: (a) the state of M; (b) the number of †s to its head’s strict left; and (c) a k-length tuple from (Γ ∪ {?})k . ∠ At the beginning of the sweep, the head of M ′ is at the location of the leftmost † and the state of M ′ is (q, 0, [?, · · · , ?]). The head moves to the right uncovering †s and the corresponding track symbols (are stored in the third component of the state). ∠ Each move of M takes multiple moves of M ′, and is a sweep of the tape from the location of the leftmost † to that of the rightmost † and back performing the changes to tracks that M would do to its corresponding tapes. ∠ The right sweep ends when the second component is k. Finite Control Finite Control · · ·· · · · · ·· · · · · ·· · ·· · · 10 11 54 1312 6 14 † 12 † † 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 1 1 1 1 1 0 1 0 1 0 1 0 11 0 1 0 1 0 1 0 1 M 0 M · · ·· · · Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 18 / 34 Extensions of TMs Multi-tape TMs Proof of Theorem 8.2.1 (3 of 3) ∠ At this stage (once the i in (q, i , [γ1, · · · , γk ]) is k and all γj are set), M ′ knows the head symbols M will have read, and knows what actions to take. ∠ It then sweeps left making appropriate changes to the tracks (just like M does to its tape) each time a † is encountered. M ′ also moves the †s accordingly. ∠ The left sweep ends when the second component is zero. At this time, M ′ would have completed moving the †s and the track contents; they’ll now match those of M. ∠ M ′ then moves the state to (q′, 0, [?, · · · , ?]) and starts the next sweep if q′ is not a final state. ∠ Note that M ′ mimics M and hence the languages accepted are identical. Finite Control Finite Control · · ·· · · · · ·· · · · · ·· · ·· · · 10 11 54 1312 6 14 † 12 † † 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 1 1 1 1 1 0 1 0 1 0 1 0 11 0 1 0 1 0 1 0 1 M 0 M · · ·· · · Pascal Bercher week 5: Introduction to Turing Machines Semester 1, 2025 19 / 34 Extensions of TMs Multi-tape TMs ∠ The running time of a TM M with input w is the number of moves M makes before it halts. (If it does not, the running time is ∞). ∠ The time complexity TM : {0, 1, . . .} → {0, 1, . . .} ∪ {∞} of a TM M is defined as: ∠ TM(n) := maximum running time of M for an input w of length n symbols. Theorem 8.2.2 The time taken for M ′ in Theorem 8.2.1 to process n moves of k-tape M is O(n2). Outline of Proof of Theorem 8.2.2 ∠ In the ith move of M, any two heads of M can be at most 2i locations apart. ∠ Each sweep then requires 4i moves of M ′. ∠ Each track update requires Θ(k) time. ∠ So, n moves in M need O(n2) moves in M ′. ! ! ! ! · · · · · · Moves ofM0 n Lo ca tio n of ta pe he ad s n 0