Formal Models of Computation

Slides:



Advertisements
Similar presentations
Formal Models of Computation Part III Computability & Complexity
Advertisements

Turing Machines Memory = an infinitely long tape Persistent storage A read/write tape head that can move around the tape Initially, the tape contains only.
Introduction to Computability Theory
Variants of Turing machines
THE CHURCH-TURING T H E S I S “ TURING MACHINES” Pages COMPUTABILITY THEORY.
1 COMP 382: Reasoning about algorithms Unit 9: Undecidability [Slides adapted from Amos Israeli’s]
Foundations of (Theoretical) Computer Science Chapter 3 Lecture Notes (Section 3.2: Variants of Turing Machines) David Martin With.
Turing Machines (At last!). Designing Universal Computational Devices Was Not The Only Contribution from Alan Turing… Enter the year 1940: The world is.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Variants.
CS605 – The Mathematics and Theory of Computer Science Turing Machines.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture11: Variants of Turing Machines Prof. Amos Israeli.
Complexity ©D.Moshkovitz 1 Turing Machines. Complexity ©D.Moshkovitz 2 Motivation Our main goal in this course is to analyze problems and categorize them.
CS5371 Theory of Computation Lecture 11: Computability Theory II (TM Variants, Church-Turing Thesis)
Fall 2004COMP 3351 Turing Machines. Fall 2004COMP 3352 The Language Hierarchy Regular Languages Context-Free Languages ? ?
CS 310 – Fall 2006 Pacific University CS310 Turing Machines Section 3.1 November 6, 2006.
Computation Theory Introduction to Turing Machine.
CS5371 Theory of Computation Lecture 10: Computability Theory I (Turing Machine)
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Prof. Busch - LSU1 Turing Machines. Prof. Busch - LSU2 The Language Hierarchy Regular Languages Context-Free Languages ? ?
Chapter 9 Turing Machine (TMs).
AUTOMATA THEORY VIII.
Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses.
Turing Machines Chapter Plan Turing Machines(TMs) – Alan Turing Church-Turing Thesis – Definitions Computation Configuration Recognizable vs. Decidable.
CSE202: Introduction to Formal Languages and Automata Theory Chapter 9 The Turing Machine These class notes are based on material from our textbook, An.
CSCI 2670 Introduction to Theory of Computing September 28, 2005.
 Computability Theory Turing Machines Professor MSc. Ivan A. Escobar
Introduction to CS Theory Lecture 15 –Turing Machines Piotr Faliszewski
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 15-1 Mälardalen University 2012.
THE CHURCH-TURING T H E S I S “ TURING MACHINES” Part 1 – Pages COMPUTABILITY THEORY.
The Church-Turing Thesis Chapter 3 Giorgi Japaridze Theory of Computability.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 3 The Church-Turing Thesis Contents Turing Machines definitions, examples,
1 Turing’s Thesis. 2 Turing’s thesis: Any computation carried out by mechanical means can be performed by a Turing Machine (1930)
 2005 SDU Lecture13 Reducibility — A methodology for proving un- decidability.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Turing Machines.
Fundamentals of Informatics Lecture 3 Turing Machines Bas Luttik.
TM Design Macro Language D and SD MA/CSSE 474 Theory of Computation.
Donghyun (David) Kim Department of Mathematics and Computer Science North Carolina Central University 1 Chapter 3 Church-Turing Thesis Some slides are.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich
Lecture 9  2010 SDU Lecture9: Turing Machine.  2010 SDU 2 Historical Note Proposed by Alan Turing in 1936 in: On Computable Numbers, with an application.
CS 3240: Languages and Computation
1 Section 13.1 Turing Machines A Turing machine (TM) is a simple computer that has an infinite amount of storage in the form of cells on an infinite tape.
1 Turing Machines and Equivalent Models Section 13.1 Turing Machines.
Overview of the theory of computation Episode 3 0 Turing machines The traditional concepts of computability, decidability and recursive enumerability.
Lecture 24UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 24.
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 3 The Church-Turing Thesis Contents Turing Machines definitions, examples,
1 Introduction to Turing Machines
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 12 Mälardalen University 2007.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY * Read chapter 4 of the book for next time * Lecture9x.ppt.
Theory of Computation Automata Theory Dr. Ayman Srour.
Universal Turing Machine
Busch Complexity Lectures: Turing Machines
Turing Machines.
CS21 Decidability and Tractability
CSE 105 theory of computation
Turing Machines 2nd 2017 Lecture 9.
CSE 105 theory of computation
Turing Machines Acceptors; Enumerators
Chapter 9 TURING MACHINES.
فصل سوم The Church-Turing Thesis
Theory of Computation Turing Machines.
CS21 Decidability and Tractability
CSE 105 theory of computation
Variants of Turing machines
Intro to Theory of Computation
CSE 105 theory of computation
Presentation transcript:

Formal Models of Computation Turing Machines

formal models of computation Turing Machines Abstract but accurate model of computers Proposed by Alan Turing in 1936 There weren’t computers back then! Turing’s motivation: find out whether there exist mathematical problems that cannot be solved algorithmically. (This is Hilbert’s “Entscheidungsproblem”, i.e., decision problem) Similar to a FSA but with an Unlimited and unrestricted memory Able to do everything a real computer can do However: There are problems even a Turing Machine (TM) can’t solve! Such problems are beyond the theoretical limits of computation formal models of computation

Turing Machines: Features A tape is a countably infinite list of cells A tape head can read and write symbols from/onto a cell on the tape move forward and backward on the tape Schematically: Control Head a b □ . . . Tape formal models of computation

Turing Machines: Features (Cont’d) Initially the tape Contains only the input string Is blank everywhere else If the TM needs to store information It can write it onto the tape To read the info it has written TM can move the head back over it TMs have the following behaviours: They “compute” then stop in a “reject” state They “compute” then stop in an “accept” state They loop forever Compare FSAs: These have no “reject” states, and no looping forever. (Why not?) formal models of computation

Turing Machines vs. Finite Automata TMs can both write on the tape and read from it FSAs can only read (or only write if they are generators) The read/write head can move to the left and right FSAs cannot “go back” on the input The tape is infinite In FSAs the input and output is always finite The accept/reject states take immediate effect There is no need to “consume” all the input TMs come in different flavours. There differences are unimportant. formal models of computation

Turing Machine: an informal Example TM M1 to test if an input (on the tape) belongs to B = {w #w | w  {0,1}* } M1 checks if the contents of the tape consists of two identical strings of 0’s & 1’s separated by “#” M1 accepts inputs 0110#0110, 000#000, 010101010#010101010 M1 rejects inputs 1111#0000, 000#0000, 0001#1000 M1 should work for any size of input (general) There are infinitely many, so we cannot use “cases” How would you program this? All you have is a tape, and a head to read/write it formal models of computation

Turing Machine: an Example (Cont’d) Strategy for M1: “Zig-zag” to corresponding places at both sides of “#” and check if they match Mark (cross off) those places you have checked If it crosses off all symbols, then everything matches and M1 goes into an accept state If it discovers a mismatch then it enters a reject state formal models of computation

Turing Machine: an Example (Cont’d) M1 = “On input string S Scan the input to be sure it contains a single # symbol; if not, reject. Zig-zag across the tape to corresponding positions on either side of # to check if they contain the same symbol. If they do not match, reject. Cross off symbols as they are checked to keep track of things. When all symbols to the left of # have been crossed off, check for any remaining symbols to the right of #. If any symbols remain, reject; otherwise accept.” formal models of computation

Turing Machine: an Example (Cont’d) Snapshots of M1’s tape during stages 2 and 3: 1 □ . . . # x 1 □ . . . # x 1 □ . . . # x 1 □ . . . # x 1 □ . . . # x 1 □ . . . # . . . x □ . . . # Accept!! formal models of computation

Formal Definition of Turing Machines Previous slides give a flavour of TMs, but not their details. We can describe TMs formally, similarly to what you did for FAs We shall not always use formal descriptions for TMs because these would tend to be quite long but ultimately, our informal descriptions should be “translatable” into formal ones so it is crucial to understand these formal descriptions formal models of computation

Formal definition of Turing Machines The imperative model of “algorithmhood” is formulated in terms of actions: A TM is always in one of a specified number of states (these include the accept and reject states) The action of the TM, at a given moment, depends on its state and on what the TM is reading at that moment Always perform three types of actions: (1) replace the symbol that it reads by another (or the same) symbol, (2) move the head Left or Right, and (3) enter a new state (or the same state again). formal models of computation

Formal Definition of TMs (Cont’d) The heart of a TM is a function  mapping A state s of the machine The symbol a on the tape where the head is onto A new state t of the machine A symbol b to be written on the tape (over a) A movement L (left) or R (right) of the head That is, (s,a) = (t,b,L) “When the machine is in state s and the head is over a cell containing a symbol a, then the machine writes the symbol b (replacing a), goes to state t and moves the head to the Left.” formal models of computation

Formal Definition of TMs (Cont’d) A Turing Machine is a 7-tuple (Q, , , , q0, qacc , qrej ) where Q, ,  are all finite sets and Q is the set of states  is the input alphabet not containing the special blank symbol “□”  is the tape alphabet, where {□} : Q    Q    {L, R} is the transition function q0  Q is the start state qacc  Q is the accept state qrej  Q is the reject state, where qrej  qacc formal models of computation

How Turing Machines “Compute” M = (Q, , , , q0, qacc , qrej ) M receives its input w = w1w2…wn  * w is on the leftmost n cells of the tape. The rest of the tape is blank (infinite list of “□”) The head starts on the leftmost cell of the tape  does not contain “□”, so the first blank on the tape marks the end of the input M follows the “moves” encoded in  If M tries to move its head to the left of the left-hand end of the tape, the head stays in the same place The computation continues until it enters the accept or reject state, at which point M halts If neither occurs, M goes on forever… n suggests that w should be finite. Should it? formal models of computation

formal models of computation Formalisation of TMs Formalisation is needed to say precisely how TMs behave. For instance, TMs use “sudden death” (and “sudden life”) FSA accepts a string iff the (complete!) string is the label of a successful path. TM accepts a string if, while processing it, an accept state is reached; TM rejects a string if, while processing it, a reject state is reached What exactly does it mean to “move to the right”? What if the head is already at the rightmost edge? formal models of computation

formal models of computation Configurations of TMs As a TM computes, changes occur in its: State Tape contents Head location Configurations are represented in a special way: When the TM is in state q, and The contents of the tape is two strings uv, and The head is on the leftmost position of string v Then we represent this configuration as “u q v ” Example: 1011q7011111 These three items are a configuration of the TM 1 □ . . . q7 formal models of computation

Formalising TMs Computations Assume a, b, c in  (3 characters from the tape) u and v in * (2 strings from the tape) states qi and qj We can now say that (for all u and v) u a qi b v yields u qj a c v if (qi ,b ) = (qj ,c , L) Graphically: qi u □ . . . b a v qj u □ . . . c a v formal models of computation

Formalising TMs Computations (Cont’d) A similar definition for rightward moves u a qi b v yields u a c qj v if (qi ,b ) = (qj ,c , R) Graphically: qi u □ . . . b a v qj u □ . . . c a v formal models of computation

Formalising TMs Computations (Cont’d) Special cases when head at beginning of tape For the left-hand end, moving left: qi b v yields qj c v if (qi ,b ) = (qj ,c , L) We prevent the head from “falling off” the left-hand end of the tape: For the left-hand end, moving right: qi b v yields c qj v if (qi ,b ) = (qj ,c , R) □ . . . c v qi b qj □ . . . c v qi b qj formal models of computation

Formalising TMs Computations (Cont’d) For the right-hand “end” (not really the end…) infinite sequence of blanks follows the part of the tape represented in the configuration We thus handle the case above as any other rightward move formal models of computation

Formalising TMs Computations (Cont’d) The start configuration of M on input w is q0w M in start state q0 with head at leftmost position of tape An accepting configuration has state qacc A rejecting configuration has state qrej Rejecting and accepting configurations are halting configurations They do not yield further configurations No matter what else is in the configuration! Note:  is a function, and there is only one start state, so the TM (as defined here) is deterministic formal models of computation

Formalising TMs Computations (Cont’d) A TM M accepts input w if there is a sequence of configurations C 1, C 2,…,C k where 1. C 1 is the start configuration of M on input w 2. Each C i yields C i +1, and 3. C k is an accepting configuration Analogous to FSAs, the set of strings that M accepts is the language of M, denoted L(M ) we also say that a TM “accepts” or “recognizes” a language. formal models of computation

Sample Turing Machine (Cont’d) Some shorthands to simplify notation: “when in state q1 with the head reading 0, it goes to state q2, writes □ and moves the head to the right” “machine moves its head to the right when reading 0 in the state q3, but nothing is written onto the tape” Transitions from accept/reject states can be omitted (because of sudden death). q1 q2 0  □,R (q1,0) = (q2, □, R) q3 q4 0  R (q3,0) = (q4,0,R) formal models of computation

formal models of computation First TM example Given: w is a bitstring Construct TM that recognises L={w: w contains at least one 0} formal models of computation

A very simple TM (diagram and formal) Given: w is a bitstring Construct TM that recognises L={w: w contains at least one 0} 0 R q0 Acc 1R □R Rej formal models of computation

First TM example (diagram and formal) Given: w is a bitstring Construct TM that recognises L={w: w contains at least one 0} 0 R q0 Acc 1R □R Rej Using formal notation: d(q0,1)=(q0,1,R). d(q0,0)=(Acc,0,R). d(q0,□)=(Rej, □,R) formal models of computation

formal models of computation Observe .. The “transition function” in this graph is not a total function. However, The missing arrows (from the Acc and Rej states) can easily be added How you do this does not affect the language recognised by the TM formal models of computation

formal models of computation Second TM example How would you modify the previous TM to recognize L’ = {w: w is a bitstring and w contains at least two 0s}? formal models of computation

formal models of computation Given: w is a bitstring Construct TM that recognises L={w: w contains at least two 0s} 0  R q1 Acc 1R □ R 0  R Rej q0 □R 1  R formal models of computation

Third example: Draw a TM with this behaviour: Given: w is a bitstring Recognise L={w: w contains exactly one 0} formal models of computation

formal models of computation Given: w is a bitstring Construct TM that recognises L={w: w contains exactly one 0} □  R q1 Acc 1R 0R 0  R Rej q0 □R 1  R formal models of computation

formal models of computation Sample Turing Machine These TMs were very simple, and only solve problems that FSAs were able to solve already More sophisticated TMs get complicated A lengthy document We often settle for a higher-level description Easier to understand than transition rules or diagrams Every higher-level description is just a shorthand for its formal specification formal models of computation

Sample Turing Machine (Cont’d) M2 recognises all strings of 0s whose length is a power of 2, that is, the language A = { 02n | n  0} = {0,00,0000,00000000,0000000000000000, ...} M2 = “On input string w : 1. Sweep left to right across the tape, crossing off every other 0. If tape contains a single 0, accept If tape contains more than a single 0 and the number of 0s was odd, reject. 2. Return the head to the left-hand of the tape 3. Go to step 1” formal models of computation

Sample Turing Machine (Cont’d) Formally M2 = (Q, , , , q1, qacc , qrej ) Q = {q1, q2, q3, q4, q5, qacc, qrej}  = {0}  = {0, x, □}  is given as a state diagram (next slide) The start, accept and reject states are q1, qacc , qrej formal models of computation

Sample Turing Machine (Cont’d) ’s state diagram □  R x  R 0  □,R 0  x,R x  L 0  L 0  R □  L q1 q2 q5 q3 qrej qacc q4 formal models of computation

Sample Turing Machine (Cont’d) Sample run of M2 on input 0000: q10000 □q2000 □xq300 □x0q40 □x0xq3 □ □x0q5x □ □xq50x □ □q5x0x □ q5□x0x □ □xq20x □ □xxq3x □ □xxxq3 □ □xxq5x □ □q2x0x □ □xq5xx □ □q5xxx □ q5□xxx □ □q2xxx □ □xq2xx □ □xxq2x □ □xxxq2 □ □xxx □qacc formal models of computation

Sample Turing Machine (Cont’d) ’s state diagram q1 q2 q5 q3 qrej qacc q4 □  R x  R 0  □,R 0  x,R x  L 0  L 0  R □  L formal models of computation

Turing-Recognisable Languages Let’s use our newly gained knowledge of TMs to re-state our earlier insights about decidability and Recursive Enumerability formal models of computation

Turing-Recognisable Languages A language is Turing Recognisable if some TM recognises it This is what we called Recursively Enumerable before So if a TM recognises L, this means that all and only the elements of L are accepted by the TM these strings result in the Accept state But what happens with the strings that are not in L? formal models of computation

Turing-Recognisable Languages A language is Turing Recognisable if some TM recognises it This is what we called Recursively Enumerable before So if a TM recognises L, this means that all and only the elements of L are accepted by the TM these strings result in the Accept state But what happens with the strings that are not in L? these might end in the Reject state ... or the TM might never reach Accept or Reject on the input s formal models of computation

Turing-Recognisable Languages (Cont’d) A TM fails to accept an input either by Entering qrej and rejecting the input Looping forever It is not easy to distinguish a machine that is looping from one that is just taking a long time! Loops can be complex, not just C i  C j  C i  C j  … We prefer TMs that halt on all inputs They are called deciders A decider that recognises a language is said to decide that language A decider answers every question of the form “Does the TM accept this string?” in finite time Non-deciders keep you guessing on some strings formal models of computation

Turing-Decidable Languages A language is (Turing-)decidable if some TM decides it Every decidable language is Turing-recognisable Some Turing-recognisable languages are not decidable (though you haven’t seen any examples yet) formal models of computation

Variants of Turing Machines There are many alternative definitions of TMs They are called variants of the Turing machine They all have the same power as the original TM Some of these deviate from “our” TMs in minor ways. For example, Some TMs put strings in between two infinite sequences of blanks. This avoids the need that sometimes exists to mark the start of the string Some TMs halt only when they reach a state from which no transitions are possible. Compare our TM: “sudden death” after reaching qacc , qrej Let’s briefly look at some more interesting variants formal models of computation

Multitape Turing Machines A TM with several tapes instead of just one Each tape has its own head for reading/writing Initially, input appears on tape 1; other tapes blank Transition function caters for k different tapes: : Q  k  Q  k  {L, R}k The expression (qi ,a1 ,…,ak ) = (qj , b1 , …, bk , L, R, …, L ) Means If in qi and heads 1 through k read a1 through ak , Then go to qj , write b1 through bk and move heads to the left or right, as specified formal models of computation

Multitape Turing Machines (Cont’d) Theorem: “Every multitape Turing machine has an equivalent single tape Turing machine”. Proof: show how to convert a multitape TM M to an equivalent single tape TM S. (Sketch only!) M S . . . □ 1 . . . □ b a a . . . □ . . . □ 1 1 a a # b formal models of computation

Nondeterministic Turing Machines This time, at a given point in the computation, there may be various possibilities to proceed Transition function maps to powerset (options): : Q    2(Q    {L, R}) The expression (qi ,a ) = {(qj , b1 , L ), ..., (qj , b2 , R )} Means If in qi and head is on a Then go to any one of the options (some finite number!) If there is a sequence of choices that leads to the accept state, the machine accepts the input formal models of computation

Nondeterministic TMs (Cont’d) Theorem: “For every nondeterministic Turing machine there exists an equivalent deterministic Turing machine” “Equivalent”: -- accept the same strings -- reject the same strings (No proof offered here.) formal models of computation

formal models of computation Other types of TMs These lectures focus on TMs for accepting strings (recognizing languages) Other TMs were built primarily for manipulating strings. Examples: TM that count the number of symbols in a string (by producing a string that contains the right number of 1’s) TM that adds up two bit strings (by producing a string that contains the right number of 1’s) See your Practical Such TMs do not need Accept/Reject states. Their behaviour can be simulated in “our” TMs: accept if the tape contains inputs + the correct output. formal models of computation

TMs are cumbersome to specify in detail TM serves as a precise model for algorithms We shall often make do with informal descriptions We need to be comfortable enough with TMs to believe they capture all algorithms formal models of computation

formal models of computation Notation for TMs Input to TM is always a string If we want to provide something else such as Polynomial, matrix, list of students, etc. then we need to Represent these as strings (somehow) AND Program the TM to decode/act on the representation Notation: Encoding of O as a string is O  Encoding of O1, O2 ,… , Ok as a string is O1, O2 ,… , Ok  formal models of computation

TM: Additional example formal models of computation