Main Page | Modules | Alphabetical List | Compound List | File List | Compound Members | Related Pages

turing_machine< T > Class Template Reference
[TuringMachineDefinition]

turing machine with an arbitrary (but small) alphabet. More...

#include <turing_machine.hpp>

Collaboration diagram for turing_machine< T >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef std::vector< state<
T > >::size_type 
transition_index_type
typedef infinite_tape< T
>::direction 
move_type
typedef state< T >::transition_result result_type
typedef unsigned long int transition_count_type

Public Member Functions

 turing_machine (const turing_machine< T > &rhs)
 copies a turing machine.

 turing_machine (T default_tape_value)
 default-most constructor.

 turing_machine (transition_index_type N, T default_tape_value)
 creates an N-state stturing_machine whose tape has a given T as its default value

 turing_machine (const infinite_tape< T > &new_tape)
 creates a machine with an empty set of states and the given tape.

 ~turing_machine ()
 trivial destructor

transition_index_type add_state ()
 adds an additional state to the transition function.

bool set_halt_state (transition_index_type new_halt_state)
 set the halt state.

bool add_transition (transition_index_type start_state, T read, T write, move_type move, transition_index_type end_state)
 adds a full transition.

bool add_write_transition (transition_index_type start_state, T read, T write, transition_index_type end_state)
 adds a 4-tuple write-only transition

bool add_move_transition (transition_index_type start_state, T read, move_type move, transition_index_type end_state)
 adds a 4-tuple move-only transition

bool bounds_check (transition_index_type to_check)
 returns whether to_check refers to an existing state in the FA or not

result_type run_one ()
 run one step and return whether the machine is running or has halted

transition_index_type count_occurrences (T to_count) const
 count occurrences of to_count on the tape ...

const infinite_tape< T > & access_tape () const
 provides fairly low-overhead read-only access to the infinite_tape.

infinite_tape< T > & access_tape_read_write ()
 provides read-write access to the tape.

bool in_standard_position () const
 determine if the tape is in standard position or not.

bool blank_tape () const
 determine if the tape is blank or not.

transition_index_type count_states () const
 provide access to certain information about the FA.

transition_index_type get_current_state () const
 returns the number of the FA's current state

result_type get_status () const
 whether or not the machine is running.

transition_count_type get_steps_count () const
 returns how many times the transition function has been called.

bool in_halt_state () const
 returns if the machine is in the halt state

long_int number_represented () const
 number of equivalent machines that this machine represents

long_int number_represented_explicit () const
 number of equivalent machines that this machine represents

void print (std::ostream &out) const
 prints the turing machine in a rather messy (but correct and informative) form.

bool is_tn_possible () const
 is it possible to tree-normalise this machine?

template<typename OutputIterator> void generate_tn_quadruple_children (const std::list< T > &alphabet, OutputIterator destination) const
 creates children in the tree for quadruple implicit halt

template<typename OutputIterator> void generate_tn_quadruple_children_explicit (const std::list< T > &alphabet, OutputIterator destination) const
 creates children in the tree for quadruple explicit halt

template<typename OutputIterator> void generate_all_tn_quadruple_children (const std::list< T > &alphabet, OutputIterator destination) const
 creates all children (implicit and explicit) in the tree for the quadruple formulation.

bool resetMachine ()
 resets the machine to a blank tape and current state to starting state

turing_machine< T > reverseMachine ()
 get the mirror machine of *this.

void rigMachine (typename std::vector< T > &riggedTape, int originalReadHead, int desiredReadHead, typename std::vector< state< T > >::size_type state, typename std::list< T >::iterator &leftBound, typename std::list< T >::iterator &rightBound, typename std::list< T >::iterator &desiredLocation)
 Rig the machine to a specified set of conditions Used for testing non-halt transformations, sets a portion of the tape equal to the elements in riggedTape; the read head is updated to the corresponding location of originalReadHead on the riggedTape; the desiredReadHead is used to set the desiredLocation iterator which is the hopeful location of the read head on the tape after the non-halt transformation is performed.

std::vector< state< T > > & stateSet ()
 accessor to the states.

transition_index_type haltState ()
 accessor to the halt_state

move_type nextMove ()
 simulates the next move on the tape without actually running the tape.

void printTMO (std::ostream &out) const
 prints the turing machine in tmo (Turing Machine Owen) format.

bool implicitMachine () const
 Returns whether this machine is an implicit halt machine.


Static Public Attributes

const move_type left = infinite_tape<T>::left
const move_type right = infinite_tape<T>::right
const move_type do_nothing = infinite_tape<T>::do_nothing
const move_type halt_move = infinite_tape<T>::halt_move
const result_type run = state<T>::run
const result_type halt = state<T>::halt

Protected Attributes

bool halt_state_exists
transition_index_type current
transition_index_type halt_state
transition_index_type first_unreachable_state
std::vector< state< T > > transition_function
infinite_tape< T > tape
transition_count_type steps
result_type run_status

Private Member Functions

template<typename OutputIterator> void output_machine (turing_machine< T > &to_output, OutputIterator destination) const
template<typename OutputIterator> void output_machine (turing_machine< T > &to_output, OutputIterator destination, const std::list< T > &alphabet) const
bool run_checks (const turing_machine< T > &to_check, const std::list< T > &alphabet) const
 run normalization checks


Detailed Description

template<typename T>
class turing_machine< T >

turing machine with an arbitrary (but small) alphabet.

Definition at line 112 of file turing_machine.hpp.


Constructor & Destructor Documentation

template<typename T>
turing_machine< T >::turing_machine const turing_machine< T > &  rhs  )  [inline]
 

copies a turing machine.

Precondition:
rhs is a valid turing_machine
Postcondition:
*this is a functionally-equivalent turing_machine to rhs
Parameters:
rhs machine to be copied
Author:
Kyle Ross

Definition at line 133 of file turing_machine.hpp.

template<typename T>
turing_machine< T >::turing_machine default_tape_value  )  [inline]
 

default-most constructor.

creates a turing machine from T representing default tape value

Postcondition:
*this refers to a turing_machine with a default-constructed tape that has default_tape_value as its blank-symbol
Parameters:
default_tape_value default value to be set on the tape
Author:
Kyle Ross

Definition at line 148 of file turing_machine.hpp.

template<typename T>
turing_machine< T >::turing_machine transition_index_type  N,
default_tape_value
[inline]
 

creates an N-state stturing_machine whose tape has a given T as its default value

Precondition:
N>=0
Postcondition:
a turing machine with N default states has been constructed with a default-size tape whose blank-symbol is default_tape_value
Parameters:
N number of states
default_tape_value default value to be set on the tape
Author:
Kyle Ross

Definition at line 164 of file turing_machine.hpp.

template<typename T>
turing_machine< T >::turing_machine const infinite_tape< T > &  new_tape  )  [inline]
 

creates a machine with an empty set of states and the given tape.

Precondition:
new_tape is a valid infinite_tape
Postcondition:
a turing_machine with no states has been constructed with a tape that is functionally-equivalent to new_tape
Parameters:
new_tape tape to be used for the new machine
Author:
Kyle Ross

Definition at line 179 of file turing_machine.hpp.

template<typename T>
turing_machine< T >::~turing_machine  )  [inline]
 

trivial destructor

Author:
Kyle Ross

Definition at line 191 of file turing_machine.hpp.


Member Function Documentation

template<typename T>
const infinite_tape<T>& turing_machine< T >::access_tape  )  const [inline]
 

provides fairly low-overhead read-only access to the infinite_tape.

Returns:
constant reference to the tape
Author:
Kyle Ross

Definition at line 363 of file turing_machine.hpp.

Referenced by simpleLoopCheck().

template<typename T>
infinite_tape<T>& turing_machine< T >::access_tape_read_write  )  [inline]
 

provides read-write access to the tape.

hmmm, I can't really justify this function except that it's sometimes useful to mangle the contents of the tape ... it's a gross violation of encapsulation, so it should be used *very* carefully used carefully by Owen in non-halt routines :)

Returns:
reference to the tape
Author:
Kyle Ross

Definition at line 375 of file turing_machine.hpp.

Referenced by checkCounterConversion(), checkCounterRun(), checkLeaningChristmasTree(), checkLeaningChristmasTreeGrammar(), checkMultiSweepChristmasTree(), checkMultiSweepFirstPass(), checkMultiSweepSecondPass(), establishSweep(), getNextBlankLocation(), getNextChunk(), getNextChunkUnevenCheck(), getNextLeaningRightBound(), getNextRightBound(), simpleLoopCheck(), and testCounter().

template<typename T>
bool turing_machine< T >::add_move_transition transition_index_type  start_state,
read,
move_type  move,
transition_index_type  end_state
[inline]
 

adds a 4-tuple move-only transition

Postcondition:
a new full transition as defined by the parameter values has been created iff each of start_state, end_state are >=0 and <transition_function.size()
Parameters:
start_state starting state of transition
read read symbol for transition
move direction to move read head new state to transition to
Returns:
true if transition successfully added
Author:
Kyle Ross

Definition at line 306 of file turing_machine.hpp.

References turing_machine< T >::add_transition().

Referenced by turing_machine< T >::generate_all_tn_quadruple_children(), turing_machine< T >::generate_tn_quadruple_children(), turing_machine< T >::generate_tn_quadruple_children_explicit(), and turing_machine< T >::reverseMachine().

template<typename T>
transition_index_type turing_machine< T >::add_state  )  [inline]
 

adds an additional state to the transition function.

Precondition:
there are zero or more states in the FA of the turing_machine
Postcondition:
an additional default state has been added to the turing_machine's FA and the current number of states in the FA is returned
Returns:
the current number of states in the machine
Author:
Kyle Ross

Definition at line 205 of file turing_machine.hpp.

template<typename T>
bool turing_machine< T >::add_transition transition_index_type  start_state,
read,
write,
move_type  move,
transition_index_type  end_state
[inline]
 

adds a full transition.

Postcondition:
a new full transition as defined by the parameter values has been created iff each of start_state, end_state are >=0 and <transition_function.size()
Parameters:
start_state starting state of transition
read read symbol for transition
write symbol to be written on the tape
move direction to move read head new state to transition to
Returns:
true if transition successfully added
Author:
Kyle Ross

Definition at line 258 of file turing_machine.hpp.

References turing_machine< T >::bounds_check().

Referenced by turing_machine< T >::add_move_transition(), and turing_machine< T >::add_write_transition().

template<typename T>
bool turing_machine< T >::add_write_transition transition_index_type  start_state,
read,
write,
transition_index_type  end_state
[inline]
 

adds a 4-tuple write-only transition

Postcondition:
a new full transition as defined by the parameter values has been created iff each of start_state, end_state are >=0 and <transition_function.size()
Parameters:
start_state starting state of transition
read read symbol for transition
write symbol to be written on the tape new state to transition to
Returns:
true if transition successfully added
Author:
Kyle Ross

Definition at line 291 of file turing_machine.hpp.

References turing_machine< T >::add_transition().

Referenced by turing_machine< T >::generate_all_tn_quadruple_children(), turing_machine< T >::generate_tn_quadruple_children(), turing_machine< T >::generate_tn_quadruple_children_explicit(), and turing_machine< T >::reverseMachine().

template<typename T>
bool turing_machine< T >::blank_tape  )  const [inline]
 

determine if the tape is blank or not.

Returns:
true is returned iff the tape is blank; false else
Author:
Kyle Ross

Definition at line 399 of file turing_machine.hpp.

Referenced by simpleLoopCheck().

template<typename T>
bool turing_machine< T >::bounds_check transition_index_type  to_check  )  [inline]
 

returns whether to_check refers to an existing state in the FA or not

Precondition:
transition_function holds zero or more states
Postcondition:
true has been returned iff 0<=to_check<transition_function.size(), false else
Parameters:
to_check state to check
Author:
Kyle Ross

Definition at line 318 of file turing_machine.hpp.

Referenced by turing_machine< T >::add_transition(), and turing_machine< T >::set_halt_state().

template<typename T>
transition_index_type turing_machine< T >::count_occurrences to_count  )  const [inline]
 

count occurrences of to_count on the tape ...

e.g. to find productivity.

Precondition:
the tape has zero or more cells
Postcondition:
the number of occurrences of to_count on the tape have been returned
Parameters:
to_count symbol to count
Returns:
number of occurences of to_count on the tape
Author:
Kyle Ross

Definition at line 353 of file turing_machine.hpp.

template<typename T>
transition_index_type turing_machine< T >::count_states  )  const [inline]
 

provide access to certain information about the FA.

Returns:
how many states the FA has
Author:
Kyle Ross

Definition at line 409 of file turing_machine.hpp.

Referenced by turing_machine< T >::number_represented(), and turing_machine< T >::number_represented_explicit().

template<typename T>
template<typename OutputIterator>
void turing_machine< T >::generate_all_tn_quadruple_children const std::list< T > &  alphabet,
OutputIterator  destination
const [inline]
 

creates all children (implicit and explicit) in the tree for the quadruple formulation.

Postcondition:
quadruple child machines for this machine have been outputed to destination
Parameters:
alphabet alphabet for which the machines are defined
destination mechanism to load child machines onto stack
Author:
Owen Kellett

Definition at line 763 of file turing_machine.hpp.

References turing_machine< T >::add_move_transition(), turing_machine< T >::add_write_transition(), turing_machine< T >::number_represented(), and turing_machine< T >::number_represented_explicit().

template<typename T>
template<typename OutputIterator>
void turing_machine< T >::generate_tn_quadruple_children const std::list< T > &  alphabet,
OutputIterator  destination
const [inline]
 

creates children in the tree for quadruple implicit halt

Postcondition:
quadruple implicit child machines for this machine have been outputed to destination
Parameters:
alphabet alphabet for which the machines are defined
destination mechanism to load child machines onto stack
Author:
Kyle Ross

Definition at line 566 of file turing_machine.hpp.

References turing_machine< T >::add_move_transition(), turing_machine< T >::add_write_transition(), and turing_machine< T >::number_represented().

template<typename T>
template<typename OutputIterator>
void turing_machine< T >::generate_tn_quadruple_children_explicit const std::list< T > &  alphabet,
OutputIterator  destination
const [inline]
 

creates children in the tree for quadruple explicit halt

Postcondition:
quadruple explicit child machines for this machine have been outputed to destination
Parameters:
alphabet alphabet for which the machines are defined
destination mechanism to load child machines onto stack
Author:
Kyle Ross

Definition at line 661 of file turing_machine.hpp.

References turing_machine< T >::add_move_transition(), and turing_machine< T >::add_write_transition().

template<typename T>
transition_index_type turing_machine< T >::get_current_state  )  const [inline]
 

returns the number of the FA's current state

Returns:
the number of the FA's current state
Author:
Kyle Ross

Definition at line 419 of file turing_machine.hpp.

Referenced by checkCounterConversion(), checkCounterRun(), checkLeaningChristmasTree(), checkLeaningChristmasTreeGrammar(), checkMultiSweepChristmasTree(), checkMultiSweepFirstPass(), checkMultiSweepSecondPass(), simpleLoopCheck(), and testCounter().

template<typename T>
result_type turing_machine< T >::get_status  )  const [inline]
 

whether or not the machine is running.

Postcondition:
the run status of the machine has been returned, defined to be run if no transitions have been executed
Returns:
run status of the machine
Author:
Kyle Ross

Definition at line 430 of file turing_machine.hpp.

template<typename T>
transition_count_type turing_machine< T >::get_steps_count  )  const [inline]
 

returns how many times the transition function has been called.

Returns:
number of transitions the machine has made
Author:
Kyle Ross

Definition at line 440 of file turing_machine.hpp.

template<typename T>
transition_index_type turing_machine< T >::haltState  )  [inline]
 

accessor to the halt_state

Returns:
the index of the halt_state
Author:
Owen Kellett

Definition at line 986 of file turing_machine.hpp.

Referenced by backTrack(), and loopStates().

template<typename T>
bool turing_machine< T >::implicitMachine  )  const [inline]
 

Returns whether this machine is an implicit halt machine.

Returns:
true if machine is implicit halt
Author:
Owen Kellett

Definition at line 1110 of file turing_machine.hpp.

Referenced by turing_machine< T >::printTMO(), and turing_machine< T >::run_checks().

template<typename T>
bool turing_machine< T >::in_halt_state  )  const [inline]
 

returns if the machine is in the halt state

Returns:
true if the machine is in the halt state
Author:
Kyle Ross

Definition at line 450 of file turing_machine.hpp.

template<typename T>
bool turing_machine< T >::in_standard_position  )  const [inline]
 

determine if the tape is in standard position or not.

standard position is defined as: the read head is on either the leftmost or rightmost symbol ... may also be accomplished (by user) in the following way: turing_machine<T> x; x.access_tape.in_standard_position();

Returns:
true is returned iff the tape is in standard position as defined in the infinite_tape::in_standard_position
Author:
Kyle Ross

Definition at line 389 of file turing_machine.hpp.

template<typename T>
bool turing_machine< T >::is_tn_possible  )  const [inline]
 

is it possible to tree-normalise this machine?

Returns:
true if machine is halted in a non-halting state
Author:
Kyle Ross

Definition at line 546 of file turing_machine.hpp.

template<typename T>
move_type turing_machine< T >::nextMove  )  [inline]
 

simulates the next move on the tape without actually running the tape.

Returns:
whether or not the machine halts
Author:
Owen Kellett

Definition at line 998 of file turing_machine.hpp.

Referenced by checkCounterConversion(), checkCounterRun(), checkLeaningChristmasTree(), checkMultiSweepChristmasTree(), establishSweep(), getNextBlankLocation(), getNextChunk(), getNextChunkUnevenCheck(), getNextLeaningRightBound(), getNextRightBound(), and testCounter().

template<typename T>
long_int turing_machine< T >::number_represented  )  const [inline]
 

number of equivalent machines that this machine represents

Returns:
number of equivalent machines that this machine represents
Author:
Kyle Ross

Definition at line 460 of file turing_machine.hpp.

References turing_machine< T >::count_states().

Referenced by turing_machine< T >::generate_all_tn_quadruple_children(), turing_machine< T >::generate_tn_quadruple_children(), turing_machine< T >::printTMO(), and turing_machine< T >::run_checks().

template<typename T>
long_int turing_machine< T >::number_represented_explicit  )  const [inline]
 

number of equivalent machines that this machine represents

Returns:
number of equivalent machines that this machine represents in the explicit formulation
Author:
Owen Kellett

Definition at line 487 of file turing_machine.hpp.

References turing_machine< T >::count_states().

Referenced by turing_machine< T >::generate_all_tn_quadruple_children(), and turing_machine< T >::run_checks().

template<typename T>
void turing_machine< T >::print std::ostream &  out  )  const [inline]
 

prints the turing machine in a rather messy (but correct and informative) form.

Author:
Kyle Ross

Definition at line 517 of file turing_machine.hpp.

template<typename T>
void turing_machine< T >::printTMO std::ostream &  out  )  const [inline]
 

prints the turing machine in tmo (Turing Machine Owen) format.

parsable by Owen's TM Simulator and also in valid dot format for creating visual graphs

Postcondition:
*this is printed in tmo format to out
Author:
Owen Kellett

Definition at line 1014 of file turing_machine.hpp.

References turing_machine< T >::implicitMachine(), and turing_machine< T >::number_represented().

template<typename T>
bool turing_machine< T >::resetMachine  )  [inline]
 

resets the machine to a blank tape and current state to starting state

Postcondition:
the machine's tape has been cleared, step count has been set to 0, and the current state is reset to the starting state
Author:
Owen Kellett

Definition at line 869 of file turing_machine.hpp.

Referenced by checkCounterRun(), checkLeaningChristmasTree(), checkLeaningChristmasTreeGrammar(), checkMultiSweepChristmasTree(), checkMultiSweepChristmasTreeGrammar(), turing_machine< T >::rigMachine(), simpleLoopCheck(), and testCounter().

template<typename T>
turing_machine<T> turing_machine< T >::reverseMachine  )  [inline]
 

get the mirror machine of *this.

Returns:
a turing machine identical to *this except with all left and right transitions reversed
Author:
Owen Kellett

Definition at line 885 of file turing_machine.hpp.

References turing_machine< T >::add_move_transition(), and turing_machine< T >::add_write_transition().

Referenced by counter(), leaningChristmasTree(), and multiSweepChristmasTree().

template<typename T>
void turing_machine< T >::rigMachine typename std::vector< T > &  riggedTape,
int  originalReadHead,
int  desiredReadHead,
typename std::vector< state< T > >::size_type  state,
typename std::list< T >::iterator &  leftBound,
typename std::list< T >::iterator &  rightBound,
typename std::list< T >::iterator &  desiredLocation
[inline]
 

Rig the machine to a specified set of conditions Used for testing non-halt transformations, sets a portion of the tape equal to the elements in riggedTape; the read head is updated to the corresponding location of originalReadHead on the riggedTape; the desiredReadHead is used to set the desiredLocation iterator which is the hopeful location of the read head on the tape after the non-halt transformation is performed.

Parameters:
riggedTape a vector of symbols representing a portion of a tape to which the machine should be set
originalReadHead location on riggedTape of the read head at the start of the desired transformation
desiredReadHead location on riggedTape of the read head at the end of the desired transformation
state state to set the machine to
leftBound reference to an iterator to set the leftBound of riggedTape when it is loaded on the tape
rightBound reference to an iterator to set the rightBound of riggedTape when it is loaded on the tape
desiredLocation reference to an iterator to set the location of riggedTape of the desired readhead after the transformation
Author:
Owen Kellett

Definition at line 940 of file turing_machine.hpp.

References turing_machine< T >::resetMachine().

Referenced by checkCounterConversion().

template<typename T>
bool turing_machine< T >::run_checks const turing_machine< T > &  to_check,
const std::list< T > &  alphabet
const [inline, private]
 

run normalization checks

Author:
Kyle Ross

Definition at line 1169 of file turing_machine.hpp.

References turing_machine< T >::current, turing_machine< T >::first_unreachable_state, turing_machine< T >::halt_state, turing_machine< T >::implicitMachine(), turing_machine< T >::number_represented(), turing_machine< T >::number_represented_explicit(), turing_machine< T >::tape, and turing_machine< T >::transition_function.

template<typename T>
result_type turing_machine< T >::run_one  )  [inline]
 

run one step and return whether the machine is running or has halted

Precondition:
bounds_check(current)==true, the tape is in a valid state
Postcondition:
the transition, given the current read-symbol, is processed properly and the current run-status of the machine is returned
Returns:
whether or not the machine is running
Author:
Kyle Ross

Definition at line 330 of file turing_machine.hpp.

Referenced by checkCounterConversion(), checkCounterRun(), checkLeaningChristmasTree(), checkLeaningChristmasTreeGrammar(), checkMultiSweepChristmasTree(), checkMultiSweepFirstPass(), establishSweep(), getNextBlankLocation(), getNextChunk(), getNextChunkUnevenCheck(), getNextLeaningRightBound(), getNextRightBound(), simpleLoopCheck(), and testCounter().

template<typename T>
bool turing_machine< T >::set_halt_state transition_index_type  new_halt_state  )  [inline]
 

set the halt state.

Parameters:
new_halt_state index of the state to set as halt
Returns:
true if halt state successfully set
Author:
Kyle Ross

Definition at line 217 of file turing_machine.hpp.

References turing_machine< T >::bounds_check().

template<typename T>
std::vector<state<T> >& turing_machine< T >::stateSet  )  [inline]
 

accessor to the states.

Returns:
reference to the set of states
Author:
Owen Kellett

Definition at line 976 of file turing_machine.hpp.

Referenced by backTrack(), and loopStates().


The documentation for this class was generated from the following file:
Generated on Thu Nov 20 00:17:34 2003 for BusyBeaver by doxygen 1.3.3