A 2-dimensional Turing machine has an infinite \"chessboard\" as its storage dev
ID: 3799293 • Letter: A
Question
A 2-dimensional Turing machine has an infinite "chessboard" as its storage device (one cell for every address (i, j) Element Z times Z). In one step the head moves Left (i--), Right (i ++), Up (j++), or Down (j--). Show that a 2-dimensional TM is not more powerful, i.e., every language accepted by a 2-dimensional TM M is accepted by our standard 1-dim TM M'. To be specific, let's assume the 2-dimensional TM has an additional input tape, form which it only reads (moving in any way), but on which it does not write.Explanation / Answer
#define MAX_TRANSITIONS five
#define MAX_STATES twenty five
// forward declare structs
struct State;
struct Transition;
typedef enum Direction;
typedef enum Bool;
struct Transition ;
typedef struct Transition Transition;
struct State ;
typedef struct State State;
struct mathematician ;
typedef struct mathematician Turing;
#endif
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "turing.h"
// disable rectify mode
#define NDEBUG
#include "debug.h"
// wont to gift ids
int state_id = 0;
void die( char *message )
allot memory
Transition *trans = malloc( sizeof( Transition ));
if( ! trans ) die( "Memory error" );
trans->input = input;
trans->write = write;
trans->move = move;
trans->next = next;
come back trans;
}
void Transition_destroy( Transition* trans )
State* State_create( Bool settle for, Bool reject )
allot letter of the alphabet
State *state = malloc( sizeof( State ));
if( ! state ) die( "Memory error" );
state->id = state_id++;
state->accept = accept;
state->reject = reject;
state->trans_count = 0;
come back state;
}
void State_add_transition( State *state, Transition *trans )
we are able to still add another transition
if( state->trans_count == MAX_TRANSITIONS ) fifty ];
sprintf( buffer, "State gave up the ghost already has the most quantity of transitions.", state->id );
die( buffer );
}
// add the transition
state->transitions[ state->trans_count ] = trans;
state->trans_count++;
}
void State_destroy( State *state )
allot letter of the alphabet
{turing|Turing|Alan mathematician|Alan Mathison Turing|mathematician} *machine = malloc( sizeof( Turing ));
machine->state_count = 0;
machine->current = NULL;
machine->head = 0;
come back machine;
}
void mathematician_destroy( Turing *machine )
{
int i = 0;
// loop over it's states
for( i = 0; i < machine->state_count; i++ ) {
State *state = machine->states[ i ];
if( !state ) die( "Could not fetch mathematician state" );
State_destroy( state );
}
free( machine );
}
void mathematician_add_state( Turing *machine, State *state )
rummage around for a transition on the given input
for( i = 0; i < state->trans_count; i++ ) zero ) one >= tape_len ) the beginning state is organized properly
if( !machine->current ) die( "Turing machine has currently begin state" );
while( TRUE ) this fall = State_create( FALSE, FALSE );
State* q5 = State_create( FALSE, FALSE );
State* qaccept = State_create( TRUE, FALSE );
State* qreject = State_create( FALSE, TRUE );
Transition* q1_r_space = Transition_create( ' ', '', RIGHT, qreject );
Transition* q1_r_x = Transition_create( 'x', '', RIGHT, qreject );
Transition* q1_q2_zero = Transition_create( '0', ' ', RIGHT, q2 );
Transition* q2_q2_x = Transition_create( 'x', '', RIGHT, q2 );
Transition* q2_a_space = Transition_create( ' ', '', RIGHT, qaccept );
Transition* q2_q3_zero = Transition_create( '0', 'x', RIGHT, q3 );
Transition* q3_q3_x = Transition_create( 'x', '', RIGHT, q3 );
Transition* q3_q4_zero = Transition_create( '0', '', RIGHT, q4 );
Transition* q3_q5_space = Transition_create( ' ', '', LEFT, q5 );
Transition* q4_q3_zero = Transition_create( '0', 'x', RIGHT, q3 );
Transition* q4_q4_x = Transition_create( 'x', '', RIGHT, q4 );
Transition* q4_r_space = Transition_create( ' ', '', RIGHT, qreject );
Transition* q5_q5_zero = Transition_create( '0', '', LEFT, q5 );
Transition* q5_q5_x = Transition_create( 'x', '', LEFT, q5 );
Transition* q5_q2_space = Transition_create( ' ', '', RIGHT, q2 );
State_add_transition( q1, q1_r_space );
State_add_transition( q1, q1_r_x );
State_add_transition( q1, q1_q2_zero );
State_add_transition( q2, q2_q2_x );
State_add_transition( q2, q2_a_space );
State_add_transition( q2, q2_q3_zero );
State_add_transition( q3, q3_q3_x );
State_add_transition( q3, q3_q4_zero );
State_add_transition( q3, q3_q5_space );
State_add_transition( this fall, q4_q3_zero );
State_add_transition( this fall, q4_q4_x );
State_add_transition( this fall, q4_r_space );
State_add_transition( q5, q5_q5_zero );
State_add_transition( q5, q5_q5_x );
State_add_transition( q5, q5_q2_space );
Turing_add_state( machine, q1 );
Turing_add_state( machine, q2 );
Turing_add_state( machine, q3 );
Turing_add_state( machine, q4 );
Turing_add_state( machine, q5 );
Turing_add_state( machine, qaccept );
Turing_add_state( machine, qreject );
machine->current = q1;
char* input = "0000000000000000 ";
int len = strlen( input );
char* tape = malloc( len * sizeof( char ));
strcpy( tape, input );
Turing_run( machine, tape, len );
// close up
Turing_destroy( machine );
free( tape );
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.