CS201: HW3 - Turing Machines

The homework file is (https://zoo.cs.yale.edu/classes/cs201/Fall_2021/materials/hws/hw3.rkt)

Unless the problem specifies otherwise:

Turing Machines

Turing machines were described in the lectures; see also the lecture notes on the course web page. Here is a top-level procedure to simulate a Turing machine starting from a given configuration until either it halts or it has executed n steps. The procedure returns the list of the successive configurations of the computation, starting with the initial one. The length of the list of configurations is one more than the number of steps taken by the machine.

mach is a representation of a Turing machine config is a representation of a configuration of the machine n is the maximum number of steps to simulate

The procedures halted? and next-config will be written by you in the problems below; you will then have a complete Turing machine simulator.

The test solutions at the bottom specify a number of steps, n, that the simulation should run before stopping. Your code may in fact need more steps to solve the given problem. The auto-grade program will account for this, allowing roughly twice as many steps for your code to run. Still, there is a limit. We have yet to solve the halting problem.

(simulate-lite tm config n) is like simulate, but does not return the intermediate states - just the final tape contents. Thus, we can use simulate-lite in the public tests without revealing the Turing machine instructions.

Turing machine representation.

A Turing machine is represented as a list of instructions, where each instruction is a 5-tuple, represented as a struct defined as follows:

The fields represent the following components of an instruction: current state, current symbol, new state, new symbol, and move direction

The current state and new state are Racket symbols, the current symbol and new symbol are Racket symbols or non-negative integers and the move direction must be either the symbol 'L or the symbol 'R, representing a move to the left or right, respectively.

We discussed the struct special form in (https://zoo.cs.yale.edu/classes/cs201/Fall_2021/lectures/Structs.html)

Here is an example of an instruction struct.

creates an instruction with current state 'q1, current symbol 0, new state 'q3, new symbol 1, and move direction 'L, and names it i1.

Because we've made ins "transparent", its field values will be printed out.

We can access the components of i1 via the struct selectors:

Example (from lecture):

A Turing machine that when started in state 'q1 on the leftmost of a string of 0's and 1's changes all the 0's to 1's and all the 1's to 0's and then returns the head to the leftmost symbol and halts.

Another example (from lecture notes)

Below is the Turing machine from the lecture notes, which we simulated in class, with your classmates in the roles of the states of the machine. This machine makes a copy of its input on the tape, separated by the symbol c</t>. It is also available in the file: tmcopy.rkt.