Finish Rams, Nondeterministic TMs




CS154

Chris Pollett

Apr. 22, 2020

Outline

Introduction

Runtime of a RAM

Simulation Set-up

Theorem. If `L` is in `mbox{TIME}(f(n))`, then there is a RAM which computes it in times `O(f(n))`.

Proof: Let `M` be the TM recognizing `L`. We assume one blank space is added to any input and the tape alphabet has been encoded as integers. The RAM first moves the input to Registers 4 through `n+3`. This is actually a little tricky to do. First, the RAM reads Registers 1 and 2. Since the tape alphabet of `M` is finite, the RAM can "remember" these values without having to write them to some other register by branching to different subroutines to execute. As these values are now remembered, Register 1 can be used as a counter to count up. By doing Read (1) instructions and incrementing Register 1, until the encoding of the `\square` for the end of the input is found we scan to the end of the input. We look one register before this, read it, and store it into Register 2. Adding 3 to Register 1, we can then load the accumulator with Register 2's values and do a Store (1). This moves the `n`th symbol to Register `n+3`. By subtracting 4 from Register 1 and doing a Read (1) we can get the next symbol to move and so on. We are now almost ready to begin the simulation.

Proof cont'd

Register 1 is used to hold the current tape square number being read by the TM in the simulation and this is initially set to 4 , the first square of the input. Register 3 holds a special start of tape symbol. The program now tries to simulate steps of the Turing machine. The program has a sequence of instructions simulating each state `q` of `M` and has a sub-sequence of these instruction, `N(q,j)`, for handling the transition for state `q` while reading the `j`th type of alphabet symbol.

`N(q,j)`

Suppose `delta(q, j) = (p, k, D)`. Here `D` is a direction. To simulate this we do:

N(q,j) Load j
N(q,j)+1 Store 2 
N(q,j)+2 Read (1) 
N(q,j)+3 Sub 2 //(if the tape position we are 
    //reading has value `j` this will be `0`) 
N(q,j)+4 JZero N(q, j) + 6 
N(q,j)+5 Jump N(q, j+1) //(if we are not reading a 
    //`j` check if we are reading a `j+1`) 
N(q,j)+6 Load k 
N(q,j)+7 Store (1) 
N(q,j)+8 Load -1, 0, 1 //(depending on which direction the move was) 
N(q,j)+9 Add 1 
N(q,j)+10 Store 1 
N(q,j)+11 Jump N(p, k)

Simulating RAMs on TMs

Theorem. If `L` is recognized by a RAM in time `f(n)` then it is in `mbox{TIME}(O(f(n)^3))`.

Proof: Let `P` be a RAM program. We will simulate it by a seven tape machine. The first tape will be used to hold the input string and it will never be overwritten. The second tape will be used to represent the content of all the registers. This will be represented by a sequence of semicolon separated pairs `i, v`. Here i says the register (which may be `0`) and `v` says its value. When a register is updated we copy the pair to the end of our sequence, update the value, then `X` over the old value. An example sequence might be: `0, 101; XXX; 1, 10; `

The states of `M` are split into `m` groups where `m` is the number of instructions in `P`. Each group implements one instruction. Tape 3 is used to store the current program counter. This is initially `1`. At the start of the simulation Tape 2 is initialized to the input configuration of a RAM based on the contents of the input tape. Thereafter, at the start of simulating an instruction. The program counter is read and the start state of the group of states of `M` for that instruction is entered. (see next slide)

Proof cont'd

An instruction is then processed, Tape 2 is updated, and the program counter on Tape 3 is updated, then the next step can be simulated and so on. Most instructions are reasonably straightforward to carry out: To process an instruction that uses indirect addressing of the form (j), Tape 4 is used to store the value `k` of the Register `j` so that we can then go access Register `k` on Tape 2. For operations like Add and Sub, Tape 5 and Tape 6 are used to store the operands and Tape 7 is used to compute the result. If the RAM halts, the contents of Register 0 (the accumulator) are looked up on Tape 2, and the TM accepts if the value is positive.

Nondeterministic Turing Machines

In-Class Exercise

  1. Give an example NTM which has two possible actions in state `q` reading an `a`.
  2. Give an example accepting computation for your machine.
  3. Post your solution to the Apr 22 In-Class Exercise thread.