SUNY Geneseo Department of Mathematics
Monday, April 18
Math 304
Spring 2016
Prof. Doug Baldwin
...
tape = ...
...
tape = ...
...
tape
:% Part A
tape = 'tape = [ q(tape), tape ]';
% Part B
tape = [ q(tape), tape ]
>> selfClass
tape =
tape = 'tape = [ q(tape), tape ]';tape = [ q(tape), tape ]
>> % This is an accurate enough reproduction that it can be executed too:
>> eval( tape )
tape =
tape = 'tape = [ q(tape), tape ]';tape = [ q(tape), tape ]
% A MATLAB script that acts as Sipser's "SELF" Turing machine from his
% proof of the Recursion Theorem. This script generates a string containing
% its own code (less comments) when run. To closely model a Turing machine,
% this script places key values in a variable named "tape," as a Turing
% machine stores information on its tape. Furthermore, this script expands
% the "q" function inline, since Turing machines, unlike Matlab, don't call
% external functions.
%% A part. Put the code of part B into the tape variable.
tape = 'tape = [ ''tape = '''''', strrep( tape, '''''''', '''''''''''' ), '''''';'', tape ]';
%% B part. Retrieve the description of B from the tape variable, use it
% to generate the code of the A part, then put that followed by the old
% tape contents (the description of the B part) into the tape variable.
tape = [ 'tape = ''', strrep( tape, '''', '''''' ), ''';', tape ]