Expand description
§rstm
rstm is a Rust library dedicated to the construction and execution 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 various 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 behavior. The library provides a set of abstractions and utilities to define and manipulate these components.
§Examples
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::prelude::{Program, TMH};
fn main() -> rstm::Result<()> {
// initialize the logger
tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.with_target(false)
.with_timer(tracing_subscriber::fmt::time::uptime())
.init();
tracing::info!("Welcome to rstm!");
// define some input for the machine
let input = [0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0];
// initialize the state of the machine
let initial_state: isize = 0;
// define the ruleset for the machine
let program: Program<isize, usize> = rstm::program! {
#[default_state(initial_state)]
rules: {
(0, 0) -> Right(1, 0);
(0, 1) -> Left(-1, 1);
(1, 0) -> Right(0, 1);
(1, 1) -> Right(-1, 0);
(-1, 0) -> Left(<isize>::MAX, 0);
(-1, 1) -> Left(1, 1);
};
};
// create a new instance of the machine
let tm = TMH::new(initial_state, input.to_vec());
// execute the program
dbg!(tm).execute(program).run()?;
Ok(())
}Modules§
- actors
- The
actorsmodule establishes a framework for defining and managing Turing machines - error
- The
errormodule defines the coreErrortype used throughout the library and provides a convenient alias forResulttypes. - head
- prelude
- programs
- The
programsmodule provides various structures and utilities for defining and managing Turing machine programs, including rules, rule spaces, and program execution. - rule
- state
- The
statemodule provides abstractions and implementations for managing state within therstmframework. - 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 - tape
- Idealized Turing machines consider a tape, or memory, that is infinite in both directions. This tape is a one-dimensional array of symbols manipulated by the tape head according to some set of pre-defined rules.
- traits
- types
- The core types used throughout the library such as the
Directionenum - utils
- useful utilities for managing and creating Turing machines and related constructs
Macros§
- 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: - rulemap
- a macro to create a
HashMapof rules for a Turing machine. The macro takes a list of rules in the form of - rules
- [
rules!] is a macro that simplifies the creation of an array ofRuleinstances for a Turing machine. The macro adheres to the syntax outlined in the [rule!] macro, treating each “statement” as an individual rule:
Structs§
- 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). - 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. - 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. - State
- State is a generalized state implementation, representing the state of a system or object.
- Tail
- The
Tailof a rule in a Turing machine
Enums§
- Direction
- Direction enumerates the various directions a head can move, namely: left, right, and stay.
- Error
- The
Errorimplementation describes the various errors that can occur within the library
Traits§
- Alphabet
- Alphabet describes a finite set of symbols used to construct a formal language.
- AsDirection
- The AsDirection trait provides a convience method for converting a type into a Direction.
- AsHead
- Converts to a
Headby reference. - AsTail
- Converts a type into a
Tailby reference. - Decrement
- Decrement is a trait that provides a common interface for decrementing values; i.e., subtracting one from a value.
- Decrement
Assign - DecrementAssign is a trait that provides a common interface for decrementing values in place.
- Directive
- The
Directivetrait is used to define the expected behaviors of all tail-like objects within the system - Increment
- Increment is a trait that provides a common interface for incrementing values; i.e., adding one to a value.
- Increment
Assign - IncrementAssign is a trait that provides a common interface for incrementing values in place.
- Incremental
- Incremental is a trait that provides a common interface for incrementing and decrementing values.
- Instruction
- The
Instructiontrait defines the expected behaviors of a particular rule within a Turing machine program. - Into
Direction - The IntoDirection trait provides a convience method for converting a type into a Direction.
- Into
Head - Consumes the caller to convert it into a
Head. - Into
Tail - A consuming trait for converting a type into a
Tail. - RawState
RawStateis a trait describing objects capable of being used as states in our library. The trait contains a single associated trait, the context, or inner value of the state.- RawSymbol
- The
RawSymboltrait establishes the minimum requirements for a type to be used as a symbol within a Turing machine. - Scope
- The
Scopetrait establishes a common interface for all head-like objects; - Symbol
- The
Symboltrait extends theRawSymbolto define the expected behaviors of a symbol used within a Turing machine. - Symbolic
Symbolicis a marker trait used to signal a type that can be displayed.
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§
- 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 - Result
- A type alias for a
Resultwith an error type ofError - 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.