1 / 7

Section 13.1 Turing Machines A Turing machine (TM) is a simple computer

Tape. …. …. a. Tape head. Executes a finite set of instructions. Control Unit. i. j. 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. There is a

bbooth
Download Presentation

Section 13.1 Turing Machines A Turing machine (TM) is a simple computer

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. Tape … … a Tape head Executes a finite set of instructions Control Unit i j 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. There is a control unit that contains a finite set of state transition instructions. • An instruction reads the symbol in the current tape cell, writes a symbol to the same cell, • and then moves the tape head one cell left or right or remains at the same cell, after which • the machine enters a new state. • Assumptions: • The symbol L denotes a blank cell. • The tape head is initially at the left end of a nonempty input string (unless specified • otherwise) • There is a designated start state. • There is one “halt” state. • The moves are denoted by L, S, R for move left, stay, and move right. Instructions are represented in graphical form or as 5-tuples, as shown in the example to the right. This instruction executes if the current state of the TM is i and the current input symbol is a. The TM writes b into that cell, moves right one cell and enters state j. (i, a, b, R, j)

  2. Acceptance An input string on the tape is accepted by the TM if the machine enters the halt state. The language of a TM is the set of all strings accepted by the machine. Example/Quiz. Given the following simple TM. (0, a, a, R, halt). What is the language of the TM? Answer: If an input string begins with the letter a, then the TM executes the instruction and halts. So the string is accepted. Therefore, the language of the TM is the set of all strings that begin with the letter a. Example. Construct a TM to accept the language {abn | nN}. Solution. Let the start state be state 0. The idea is to see whether a is in the current cell. If so, move right to scan b’s until  is found. (0, a, a, R, 1) (1, , , S, halt) (1, b, b, R, 1). Quiz. Construct a TM to accept the language {abna | nN}. Solution. Let the start state be state 0. The idea is to see whether a is in the current cell. If so, move right to scan b’s until a is found. Then make sure there is  to the right. (0, a, a, R, 1) (1, a, a, R, 2) (1, b, b, R, 1) (2, , , S, halt).

  3. Quiz. Construct a TM to accept the language of the regular expression a(a + b)*. Solution. Let the start state be state 0. The idea is to see whether a is in the current cell. If so, move right to scan any a’s or b’s until  is found. (0, a, a, R, 1) (1, a, a, R, 1) (1, b, b, R, 1) (1, , , S, halt). Example/Quiz. Find a TM to accept {anbn | nN}. Solution. Let the start state be state 0. The idea is to see whether a is in the current cell. If so, write X and scan right looking for a b to replace by Y. (0, , , S, halt) accept  (0, a, X, R, 1) mark a with X (0, Y, Y, R, 3) no more a’s Scan right looking for b to pair with a: (1, a, a, R, 1) (1, Y, Y, R, 1) (1, b, Y, L, 2) mark b with Y Scan back left looking for X: (2, a, a, L, 2) (2, Y, Y, L, 2) (2, X, X, R, 0) Scan right looking for  and halt: (3, Y, Y, R, 3) (3, , , S, halt) TMs are very powerful. For example, the preceding example can be generalized to a TM that accepts the non-context free language {anbncn | nN}. (See Example 13.2 in the Text.) So a TM can handle two stacks. In fact, a TM can handle any number of stacks.

  4. Turing Machines with Output Specify the form of the output on the tape when the machine halts. Example/Quiz. Find a TM to add 4 to a natural number represented in binary. Start with the tape head at the right end of the input string and halt with the tape head at the left end of the output string. Solution. Let the start state be 0. Move two cells left: (0, 0, 0, L, 1) (0, 1, 1, L, 1) (1, 0, 0, L, 2) (1, 1, 1, L, 2) (1, , 0, L, 2) Add 1: (2, 0, 1, L, 3) Move left (2, 1, 0, L, 2) Carry (2, , 1, S, halt) Done Find left end of the string: (3, 0, 0, L, 3) (3, 1, 1, L, 3) (3, , , R, halt) Done Quiz. How would you construct a TM to add 5 to a binary number? One Solution: Add 1, move back to right end, and then use the preceding solution. For this purpose, let the start state be 4. Add 1: (4, 0, 1, R, 5) Move right (4, 1, 0, L, 4) Carry (4, , 1, R, 5) Move right Find right end of the string: (5, 0, 0, R, 5) (5, 1, 1, R, 5) (5, , , L, 0) Go add 4

  5. Example/Quiz. Find a TM to move any string over {a, b} to the left one cell position. Assume the tape head ends at the left end of any nonempty output string. Solution. Let the start state be 0. Find a or b to move: (0, a, , L, 1) Go write a (0, b, , L, 2) Go write b (0, , , L, 4) Done Write a or b: (1, , a, R, 3) Write a (2, , b, R, 3) Write b (3, , , R, 0) Skip  Move to left end of output: (4, , , L, 5) (5, a, a, L, 5) (5, b, b, L, 5) (5, , , R, halt). A trace for input aba (tape head is red): a b a (0, a, , L, 1) b a (1, , a, R, 3) ab a (3, , , R, 0) ab a (0, b, , L, 2) aa  (2, , b, R, 3) a ba (3, , , R, 0) a ba (0, a, , L, 1) a b (1, , a, R, 3) a ba (3, , , R, 0) a ba (0, , , L, 4) a ba (4, , , L, 5) a ba (5, a, a, L, 5) a ba (5, b, b, L, 5) a ba (5, a, a, L, 5) a ba (5, , , R, halt)  a ba Output. Quiz. (Exercise 2). Find a TM to search for the symbol # on an otherwise empty tape, where the tape head starts at a random cell. A Solution: Use a new symbol, say x, to mark cells that have been searched as the machine alternately looks left and right. A Sample Trace: #    #  x  # x x  # x x   # x x x # x x x #x x x.

  6. … … … … a … … X input stack … … … … Alternative Definitions of Turing Machine One-way Infinite Tape Multihead Multitape Quiz. Why are they all equal in power to the original definition of a Turing machine? An n-head or n-tape instruction contains n-tuples for the cell contents and move operations. Example. A typical instruction for a 2-head or a 2-tape TM is (0, (a, b), (c, d), (L, R), 1). Example/Quiz. Implement some sample PDA instructions as TM instructions for a 2-tape TM. Assume one tape holds the input string and the other tape holds the stack. Assume the input is scanned left to right and the the stack grows from right to left. PDA Instruction: 1. (i, a, X, nop, j) 2. (i, a, X, pop, j) 3. (i, a, X, push(Y), j) 4. (i, L, X, pop, j). TM Instruction: 1. (i, (a, X), (a, X),(R, S), j) 2. (i, (a, X), (a, L),(R, R), j) 3. (i, (a, X), (a, X),(S, L), k) and (k, (a, L), (a, Y),(R, S), j) 4. For each letter a: (i, (a, X), (a, L),(S, R), j).

  7. Nondeterministic Turing Machines Example. Generate an arbitrary string over {a, b} of length n. Solution: Assume the input is any string over {a, b} of length n. The tape head is at the right end of the output string. (0, a, a, R, 0) (0, a, b, R, 0) (0, b, a, R, 0) (0, b, b, R, 0) (0, L, L, L, halt). Nondeterministic TMs have the same power as deterministic TMs The idea: Any nondeterministic TM can be simulated by a deterministic TM that simulates all 1-step computations, then all 2-step computations, and so on. The process stops if some computation enters the halt state.

More Related