Turing Machines

Turing Machines

You Are Here! The Church-Turing Thesis Reg = Regular Languages 0*1*! Turing Machines and • Deterministic Finite Automaton Effective Computation • Nondeterministic Finite Automaton (01)*! • Regular Expression 0*1*+(01)* • Right-Linear Grammar ! CFL = Context-Free Language 0n1n Wednesday, November 8, 2011 • Context-Free Grammar wwR Reading: Sipser 3; Kozen 28 • Nondeterministic Pushdown Automaton Dec = Recursive (Turing-Decidable) Language 0n1n2n • Turing Machine CS235 Languages and Automata • Unrestricted Grammar ww Department of Computer Science RE = Recursively Enumerable Wellesley College (Turing-Recognizable/Acceptable) Language Lan = All Languages Turing Machines 27-2 Early Theory of Computation The Church-Turing Thesis o In the 1920s – 1940s, before the advent of modern o Computability is the common spirit embodied by this collection of computing machines, mathematicians were wrestling formalisms. with the notion of effective computation: formalisms for expressing algorithms. o This thesis is a claim that is widely believed about the intuitive notions of algorithm and effective computation. It is not a theorem that can be proved. o Many formalisms evolved: • Turing Machines (Turing); CS235! o Because of their similarity to later computer hardware, Turing machines have become the gold standard for effectively • λ-calculus (Church, Kleene); CS251! computable. • combinatory logic (Schönfinkel, Curry); o Well see in CS251 that the λ-calculus formalism is the • Post systems (Post); foundation of modern programming languages. • µ-recursive functions (Gödel, Herbrand). o A consequence: programming languages all have the same o All of these formalisms were proven to be equivalent computational power in term of what they can express. (But it to each other! may be easier or more efficient to use one than another.) Turing machines 27-3 Turing machines 27-4 What Is A Turing Machine? special blank symbol Informal TM Example: {w#w | w ∈ {a,b}*} Model of computation proposed right –infinite tape 1. If there is no unprocessed symbol in the left substring: by Alan Turing in 1936: a. If there is no unprocessed symbol in the a b b a b a . a b b # a b b • A one-way infinite tape right-hand substring, accept. of cells holding symbols two-way, read/write tape head b. Otherwise, reject. x b b # a b b or blanks. • A tape head that can Otherwise, cross off leftmost unprocessed symbol in deterministic finite-state the left substring and remember it. x b b # x b b read/write the symbol in the Q controller cell under it. 2. Move to leftmost unprocessed symbol in the right substring. x x b # x b b • A deterministic finite-state controller that, based on the current state a. If there is no such symbol (all the right-hand and symbol under the tape head, writes a symbol under the tape head and symbols have been crossed off) or the symbol x x b # x x b moves it left or right. does not match the remembered one, reject. Execution begins in the initial state with a string written on the tape x x x # x x b b. If the symbol matches the remembered one, starting at the leftmost cell cross it off. x x x # x x x • The string is accepted if the controller enters the accept state. • The string is rejected if the controller enters the a reject state. 3. Move back to the leftmost unprocessed symbol in the left substring (if there is one, or back to #, otherwise) x x x # x x x • The machine may also loop -- continue processing the string forever and go to step 1. without accepting or rejecting it. accept! Turing machines 27-5 Turing machines 27-6 TM Transition Function TM State Transitions for {w#w | w ∈ {a,b}*} x R # R The core of a Turing Machine specfication is the q1 q8 qaccept definition of a deterministic transition function δ : R (current-state, current-symbol) → (next-state, new-symbol, left-or-right) R a,b R q 2 R R q3 a,b R The transition (q,σ) (q , σ, d) is typically represent as either: qreject # R # R , a • An entry in a 2D table keyed by q and σ; , # R q σ σ , d 4 , a,b, R q5 • A state transition in a diagram: q q x R x R a L x, Abbreviations: x, L b σ d σ σ, d q6 x L q q means q q , # R # L σ1 σ1 , d x R σ1 , σ2 d q q means q q q7 a,b L σ2 σ2 , d This picture is adapted Turing machines 27-7 from p. 145 of Sipser. Turing machines 27-8 TM State Transitions w/Implicit Reject State Formal Definition of a Turing Machine x R # R A deterministic one-tape Turing machine is a septuple q1 q8 qaccept R TM = (Q, Σ, Γ, δ, qstart, qaccept, qreject) where 1. Q is a finite set of states; a,b R q 2 q3 a,b R 2. Σ is a finite input alphabet, which does not include the blank symbol, # R # R 3. Γ is a finite tape alphabet, where (Σ ∪ { }) ⊆ Γ. 4. δ ∈ (Q x Γ ) → (Q x Γ x {L, R }) is the transition function; q4 q 5. q ∈ Q is the start state; x R 5 x R start 6. qaccept ∈ Q is the accept state; 7. qreject ∈ Q is the reject state, qreject ≠ qaccept. q6 x L (This is Sipsers formalism for a Turing machine. There are many variants.) # L x R q7 a,b L This picture is adapted from p. 145 of Sipser. Turing machines 27-9 Turing machines 27-10 Turing Machine Configurations Turing Machine Configuration Example A configuration specifies the state and tape head position of a TM. Show the full sequences of TM configurations for the w#w machine starting with q1ab#ab: E.g. xbb#q4abb x b b # a b b . q 4 The transition function defines a relation ⇒ between configurations: E.g. xbb#q4abb ⇒ xbbq6#xbb a x, L q4 q6 A Turing Machine accepts a string w iff qstartw ⇒* … qaccept … A Turing Machine rejects a string w iff qstartw ⇒* … qreject … Note that a string might neither be accepted nor rejected by a TM. The language of TM, L(TM) = all strings accepted by TM. Turing machines 27-11 Turing machines 27-12 Comparison: TMs vs. FAs and PDAs What about {ww | w ∈ {a,b}*}? a b b a b b o TM is necessarily deterministic. One idea: first transform a b b a b b o TM can both read and write input cells. to !a !b !b a" b" b" !a b b a b b o The tape head can move both left and right. where there are 4 new symbols: !a b b a b b" o The tape is infinite. !a, !b , a" , b" o Accept/reject states take effect immediately !a !b b a b b" (don't have to read/consume all input). !a !b b a b" b" o In all three kinds of machines, the controller is finite-state! !a !b !b a b" b" If time permits: 1. What is the TM for this process? !a !b !b a" b" b" (should reject if not even length) 2. How to insert # in the middle? what to do now? ! Turing machines 27-13 Turing machines 27-14 Subtlety: Detecting Left End of Tape Turing Machine for {anbncn | n ∈ Nat}? An attempt to move left from the leftmost tape cell leaves the position of the tape head unchanged. How can the left end of the tape be detected? Two ways: 1. Put a special left-end marker symbol (often written ) in the leftmost cell at the beginning of the computation. Sometimes another symbol (such as x in the w#w example) can serve this purpose. 2. When moving leftward, make a change to symbol in the current cell. If that change is still present after the left move, youre in the leftmost cell. Note: some TM formalizations (e.g. Kozen) require a special left-end marker in leftmost tape cell. Turing machines 27-15 Turing machines 27-16 High-Level Algorithm Descriptions are OK! High-Level Algorithm for {anbncn | n ∈ Nat} We can give a formal TM description for any algorithm, First verify that the string is of the form as followed by bs but it would be extremely tedious to do so. followed by cs. If not, reject because the string does not have Instead, we will usually describe algorithms at a higher-level: the correct form. Note: an empty string is considered to have the correct form. • A high-level English description of a Turing Machine or some other step-by-step process. (E.g., description on slide 27-6.) Next, process the string iteratively in passes. On each pass, scan • Pseudocode, such as in CLRS (CS231) the string from left to right and cross out the leftmost plain (not • A program in (or high-level description of a program in) your crossed out) occurrence of each a, b, and c. favorite programming language (SML, Python, Java, Scheme, o During a pass, if some, but not all, of three different plain etc.), assuming it has infinite memory. symbols are encountered, reject the string, because the count In high-level algorithms, we often want to manipulate various kinds of one of the symbols differs from the count of another. of complex values, such as lists, trees, graphs, grammars, and o During a pass, if no plain symbols are encountered, accept the descriptions of various kinds of automata themselves. We can string, because it is of the right form and the counts of all represent these via appropriate strings that are checked for well- three symbols are the same.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    5 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us