1 / 32

The Definition of a Turing Machine

The Definition of a Turing Machine. Section 4.1 Mon, Nov 7, 2005. Shortcomings of DFAs and PDAs. DFAs and PDAs are good at recognizing simple patterns. They can recognize many of the patterns that are used in computer programs. But how would a DFA or a PDA compute the value of 2 + 2?.

estallings
Download Presentation

The Definition of a Turing Machine

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Definition of a Turing Machine Section 4.1 Mon, Nov 7, 2005

  2. Shortcomings of DFAs and PDAs • DFAs and PDAs are good at recognizing simple patterns. • They can recognize many of the patterns that are used in computer programs. • But how would a DFA or a PDA compute the value of 2 + 2?

  3. Shortcomings of DFAs and PDAs • The only possibility would be to design a DFA that would accept the string “2 + 2 = 4” and reject the string “2 + 2 = n” for any other value of n. • But this is not the same as computing 2 + 2. • A computer needs to be able to read a problem and then write the answer on an output tape.

  4. Turing Machines • A Turing Machine will be similar to a DFA except that • It can both read and write on the tape. • It can move both right and left on the tape. • For example, a Turing Machine might read 2 + 2 on the tape, erase it, and write 4 in its place. • A Turing Machine does not need a stack since it can use a portion of the tape to simulate a stack.

  5. Definition of a Turing Machine • A Turing machine is a quintuple (K, Σ, δ, s, H) where • K is a finite set of states. • Σ is a finite tape alphabet, including a left end marker and the blank, but not including the arrows ← and →. • sK is the start state. • H K is the set of halting states. • δ is the transition function δ : (K – H)  Σ → K (Σ  {, }) such that • for all qK – H, if δ(q, ) = (p, b), then b = . • for all q K – H and aΣ, if δ(q, a) = (p, b), then b.

  6. Transitions • Each transition is of one of the following forms • (p, a) = (q, b), for some bΣ. • (p, a) = (q, ) • (p, a) = (q, ) where a, b  Σ. • The two restrictions on  guarantee that • The head will not drop off the left end of the tape. • The left end-marker will never be written to any other location.

  7. a; b p q Transition Diagrams • In a diagram of a TM, the transition (p, a) = (q, b) will be denoted

  8. The Turing Machine ERASE • Design a TM that will erase the content of the tape from the current position to the next blank space to the right. • Is it feasible to design a TM that will erase the tape from the current position to the left end-marker? • Is it feasible to design a TM that will erase the tape from the current position to the last non-blank symbol to the right? • Is it feasible to design a TM that will erase the entire tape?

  9. The Turing Machine ERASE • Strategy: • Move to the right, erasing symbols as you go. • Pseudocode: • While the current symbol is not blank, • Write blank and move right.

  10. ;  s q ;  ;  h The Turing Machine ERASE

  11. The Turing Machine ERASE • Should the head be returned to its original position? • Strategy: • Write a $. • Move right, erasing symbols as you go. • Then move left, searching for the $. • Erase the $ and stop.

  12. The Turing Machine ERASE • Pseudocode: • If current symbol is not blank, then • Write $ and moveright. • While the current symbol is not blank, • Write blank and moveright. • While the current symbol is not $, • Moveleft. • Write blank.

  13. $;  ;  ; $ ;  $;  q r h p s ;  ;  The Turing Machine ERASE

  14. Configurations • A configuration represents the current status of a Turing machine. • To describe fully that status, we must specify • The current state. • The current contents of the tape. • The current position of the head. • To describe the last two parts, we will specify • The tape contents to the left of the head, including the current symbol. • The tape contents to the right of the head.

  15. Configurations • Thus, a configuration is a triple (q, w, u) where • qK. • w*. • u*(– {})  {e}. • We will abbreviate this as a pair (q, wau), where • qK. • w*. • a. • u*(– {})  {e}. • The underlined symbol a is the current symbol.

  16. Configurations • As before, we will write C1MC2 if configuration C1yields configuration C2in one step. • And we will write C1M*C2 if configuration C1yields configuration C2 in any number of steps. • A sequence C0MC1M … MCn is called a computation.

  17. Example • In the previous example, write the computation when the input is 001. • (s, 001) M (p, $01) M (q, $01) M (p, $ 1) M (q, $  1) M (p, $  ) M (q, $   ) M (r, $ ) M (r, $ ) M (r, $) M (h, )

  18. The Turing Machine INCR • Design a TM that will add 1 to the nonnegative integer on the input tape. • Strategy: • Move to the blank at the right end of the string. • As long as the cell to the left is 1, change it to a zero and move left. • If the cell to the left is a 0, change it to a 1 and halt. • Special case: The string is all 1s. • Change all but the first 1 to 0. • Add a 0 at the right end.

  19. The Turing Machine INCR • Pseudocode • While symbol is not blank, • Move right. • Move left. • While symbol is 1, • Write 0. • Move left. • If symbol is 0, • Write 1.

  20. The Turing Machine INCR • Else if symbol is , • Move right. • Write 1. • While symbol is not blank, • Move right. • Write 0. • While symbol is not , • Move left. • Move right.

  21. ;← ;→ 0;← 1; 0 ;← ;→ 0; 1 h ;→ ; 0 0; 1 ;→ The Turing Machine INCR

  22. INCR INCR Modular Turing Machines • It will be much simpler to design larger Turing Machines if we can use smaller Turing Machines as building blocks. • For example, to design a Turing Machine that adds 2 to a nonnegative integer, we could use two copies of INCR as modules.

  23. Basic Turing Machines • We begin with the basic Turing Machines representing the three basic actions. • Ma – Write the symbol a. • M – Move left. • M – Move right. • We will abbreviate these machines as a, L, and R. • Introduce one more machine S, abbreviated e, that does nothing. • Design the machines a, L, R, and S.

  24. Combining Turing Machines • In structured programming, there are three basic structures. • Sequence – Execute the instructions in the linear order in which they are written. • Decision – Based on the outcome of a comparison, perform a conditional jump forward. • Loop – Based on the outcome of a comparison, perform a conditional jump backwards.

  25. Sequence Structures • To combine two Turing Machines M1 and M2 in sequence, • From each halt state of M1 and for each tape symbol, create a transition to the initial state of M2. • Remove the halting status of the halt states of M1. • The combined machine will be written as M1M2 or M1 M2. • If a machine M is followed by itself n times in sequence, then we will write Mn.

  26. Decision Structures • Let M1, M2, and M3 be Turing Machines and let a. • After executing M1, we will execute M2 if the current symbol is a, and we will execute M3 if the current symbol is not a. • To build such a machine, • From each halt state of M1, build a transition labeled a to the initial state of M2. • From each halt state of M1 and for each symbol other than a, build a transition to the initial state of M3.

  27. M2 a M1 h a M3 Decision Structures • Create a new halt state h. • Add transitions for all symbols from the halt states of M2 and M3 to h. • Remove the halting status of the halt states of M1, M2, and M3. • This machine is represented as follows.

  28. a M a h Loop Structures • A loop structure is a simple variation of a decision structure: the branch goes back to a previously executed Turing Machine instead of forward.

  29. Some Useful Machines • Machines that search left or right for a specified symbol will be very useful. • Rx searches for the first cell containing x to the right of the current cell. • Rx searches for the first cell not containing x to the right of the current cell. • Lx searches for the first cell containing x to the left of the current cell. • Lx searches for the first cell not containing x to the left of the current cell.

  30. $ S  L $R $  Example • The Turing Machine ERASE.

  31. Examples • Design the Turing Machine INCR as a modular machine. • Design a Turing Machine DECR that decrements a positive integer. If the input is 0, then it remains unchanged. • Design a Turing Machine COPY that duplicates the string to the right. That is, it converts w into ww. • Design a Turing Machine ABC that accepts the language {anbncn | n 0}.

  32. Universal TM Program • Universal TM.exe

More Related