Expand description
§rstm
rstm is a Rust library dedicated to the constructtapen and executtapen of Turing Machines.
The crate is designed to be flexible and easy to use while preserving the abstract nature
of the models.
§Features
The crate employs the use of vartapeus feature flags for modularity and to keep the core lightweight.
§Overview
The core of the library is built around the concept of a Turing Machine, which consists of a tape, a head that reads and writes symbols on the tape, and a set of rules that dictate the machine’s behavtaper. The library provides a set of abstracttapens and utilities to define and manipulate these components.
§Basic Usage
For more examples, please refer to the examples directory in the repository.
§Creating and executing a simple Turing Machine with a Moving Head
use rstm::{MovingHead, program};
// define an initial state
let initial_state: isize = 0;
// create a program to execute
let program = program! {
#[default_state(initial_state)]
rules: {
(0, 0) -> Right(1, 0),
(0, 1) -> Stay(-1, 1),
(1, 0) -> Right(0, 1),
(1, 1) -> Right(-1, 0),
(-1, 0) -> Left(<isize>::MAX, 0),
(-1, 1) -> Left(1, 1),
};
};
// initialize the machine
let mut tm = MovingHead::tmh(program);
// load the input
tm.extend_tape([0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0]);
// execute the workload
tm.run().expect("failed to execute...");Modules§
- actors
- actors for modular Turing machine implementations
- error
- this module defines the
Errortype alongisde other useful primitives that are used throughout the rules crate. - motion
- programs
- the
programmodule implements the coreProgramstructure and its associated traits - rules
- the
rulesmodule implements theRulestructure and its associated traits - state
- The
statemodule provides abstractions and implementations for managing state within therstmframework. - traits
- traits used to define common behaviors, operations, and interfaces for Turing machines and their components.
Macros§
- fsm
- The
fsm!generates a finite state machine implementation - head
- The [
head!] macro simplifies the creation of aHeadstruct by providing a concise syntax for specifying the state and symbol. - head_
map - a macro to create a
HashMapof rules for a Turing machine. The macro takes a list of rules in the form of - program
- The [
program!] macro facilitates the creation of newPrograminstances using familiar syntax - rule
- The [
rule!] macro enables the definition of a single, Turing compatible rule using the following syntax: - ruler
- The
ruler!generates a finite state machine implementation - ruleset
- [
ruleset!] is a macro that simplifies the creation of an array ofRules. - s
- the [
s!] macro is a simple helper macro to create aStateinstance. - tail
- ! the [
tail!] macro facilitates the creation of aTailstruct ! by providing a concise syntax for specifying the direction, next state, and symbol to write. As with other macros in this module, the variants of theDirectionare hygenically imported based on usage, meaning one only needs to specify the variant name ! directly, i.e.Left,Right, orStay.
Structs§
- Direction
Iter - An iterator over the variants of Direction
- Head
- The
Headof a Turing machine is defined to be a two-tuple consisting of a state and a symbol. Our implementation is generic over both the state and symbol types, allowing for flexibility in their representation(s). - Head
Step HeadStepis a structure responsible for managing the step operation of a moving head in a Turing machine simulation.- Instruction
Set - The
InstructionSetimplementation is a generic structure representing a set of instructions or rules capable of transforming states within a computational model. - Learned
Rule - A
LearnedRuleis an extension of the basicRulestructure, incorporating a confidence metric to quantify the reliability or certainty of the rule within the scope of a learning context. This is particularly useful in scenarios where rules are derived from data or experience, allowing for a more nuanced application of rules based on their confidence levels. - Program
- The
Programimplementation is designed to provide a structured representation of a set of rules and an optional initial state for a Turing machine or similar computational model. It encapsulates the rules that dictate the machine’s behavior and the starting point for its execution. - Rule
- The
Ruleimplementation is a concrete representation of a single instruction, or rule, within a given Turing machine program. It encapsulates the necessary components to define the behavior of the Turing machine when it encounters a specific state and symbol. - Rule
Builder RuleBuilderis a utilitarian structure designed to facilitate the construction of newRuleinstances through a step-by-step approach. This builder pattern allows for incremental specification of rule components, enhancing code readability and maintainability.- State
- The
Statewrapper is a generic container used to denote objects being used as a state in a Turing machine, finite-state machine, or similar computational model. - Tail
- The
Tailof a rule defines the reaction of the actor under specific conditions. Specifically, it defines the next state, the symbol to write, and the direction to move
Enums§
- Direction
- The
Directionimplementation enumerates the directions the head of a Turing machine is allowed to move, namely: left, right, or stay in place. - Error
Errorenumerates the various errors encountered when dealing with rules and their components.- Halt
- Inline with the formal definition of a halt state, the
Haltimplementation extends a stateful object, enabling any given state to be halted.
Constants§
- DEFAULT_
DISPLAY_ RADIUS - defines the radius around the head position to be displayed when printing the tape
Traits§
- Alphabet
Alphabetdescribes a finite set of symbols used to construct a formal language.- Alphabet
Mut - AsHead
- Converts to a
Headby reference. - AsTail
- Converts a type into a
Tailby reference. - Decrement
- An unary operator defining a decremental operation
- Decrement
Mut - A mutable unary operator defining a self-decrementing operation
- Driver
- The
Driveris the basis for all compatible actors within the system. Each implementation is required to define the type of internal store it will use to manage its data. This abstraction allows for flexibility in the choice of data structures, enabling the actor to adapt to various use cases and performance requirements. - Execute
- A trait denoting the ability to execute a given operation, transaction, etc.
- Execute
Mut - The
ExecuteMuttrait is similar toExecute, but it allows for mutable execution of the operation, transaction, etc. This is useful when the operation needs mutable access to the data being operated on. - Execute
Once - The
ExecuteOncedefines the ability for an object to perform exactly one execution or computation. - Executor
- The
Executortrait defines the basis for compatible engines within the system. - Halting
- The
Haltingtrait establishes an interface for determining whether a given state is in a halted condition. This trait is essential for Turing machine simulations, as it allows for the identification of states that signify the end of computation. - Halting
State - The
HaltingStatetrait is used to define states that are capable of representing halting conditions within a Turing machine simulation. For instance, if our state is of typeisize, then we might define<isize>::MAXto represent a halting state. - Handle
- The
Handletrait - Head
Space - A
HeadSpaceis a particular kind of space that deals with the heads of rules. - Increment
- An unary operator defining an incremental operation
- Increment
Mut - A mutable unary operator defining a self-incrementing operation
- Instruction
- The
Instructiontrait establishes the base interface for all compatible rules for the automata. - Into
Direction IntoDirectionis a simple conversion trait for consuming types to turn into aDirection.- Into
Head - Consumes the caller to convert it into a
Head. - Into
Tail - A consuming trait for converting a type into a
Tail. - Percent
Change - A binary operator defining the percent difference between two values where given input is compared to the caller meaning the caller is said to be the original value whilst the input is said to be the new value.
- Percent
Difference - RawHead
RawHeadis a marker trait used to define an interface for objects capable of being used as a head in the context of Turing machine rules.- RawState
RawStateis a sealed marker trait used to define objects used to represent states. The primary benefit of such a trait is preventing cases where theStateimplementation is used as a state itself:State<State<Q>>.- RawTail
RawTailis a sealed marker trait used to denote objects capable of being used to represent the tail of a rule for a Turing machine.- Read
Readtrait defines an interface for objects capable of reading data into a buffer.- ReadBuf
- Reader
Readerestablishes an interface for objects capable of reading data from internal sources.- RuleSet
- The
RuleSettrait establishes an interface common to all compatible sets of rules for the framework. - Rule
Space - If a headspace, or configuration space, defines all possible configurations of a system, then a rulespace defines how those configurations can change or evolve over time. In other words, if a c-space is a disconnected point cloud, then a rulespace is a set of rules that connect those points together, defining morphisms between them.
- State
Ext - The
StateExttrait is used to extend the baseRawStatetrait, introducing additional traits and constraints that are commonly required for state representations. - Symbolic
- The
Symbolictrait is a marker trait used to define types that can be used as symbols in formal languages. - TryExecute
- TryExecute
Mut - TryExecute
Once - The
TryExecuteOncetrait defines the ability for an object to perform one execution or computation that may fail, returning aResultconfigured to use the defined error type. - TryStep
- A trait defining an unary step operation primarily intended to enable iterable execution patterns from implemented machines.
- Write
- The
Writetrait defines an interface for objects that can perform write operations.
Functions§
- get_
range_ around - returns a range, as a 2-tuple, around a given position within the bounds of some length and with some radius
Type Aliases§
- Halt
State - A type alias for a
Stateequipped with the dedicatedHaltenum as its inner type. - Head
Entry - a type alias for a
Headcontaining a reference to the state and a mutable reference to the symbol - HeadMap
- A type alias for a
HashMapwhere each key is aHeadand each value is aTail. - HeadMut
- a type alias for a
Headcontaining mutable references to its state and symbol - HeadRef
- a type alias for a
Headcontaining immutable references to its state and symbol - HeadVec
- Moving
Head - A type alias for an
EngineBaseinstance configured with a moving head model using theHead<Q, usize>structure to maintain the head’s position on the tape. - Result
- A type alias for a
Resultwith a custom error type (Error) - Rule
Array - a type alias for an array of
Rule’s - Rule
Hash Map - A type alias for a
HashMapwithusizekeys andRulevalues. - Rule
Hash Set - A type alias for a
HashSetcontainingRuleelements. - Rule
Slice - A type alias for a slice containing
Ruleelements. - RuleVec
- A type alias for a
VeccontainingRuleelements. - TailMut
- A type alias for a
Tailcontaining mutable references to the next state and symbol. - TailRef
- A type alias for a
Tailcontaining immutable references to the next state and symbol. - TailVec
- Tuple
Rule Array - a type alias for an array whose elements are 2-tuples consisting of a
Headand aTail - Tuple
Rule Slice - a type alias for a slice whose elements are 2-tuples consisting of a
Headand aTail