Crates.io | turing-machine-rs |
lib.rs | turing-machine-rs |
version | 0.2.0 |
source | src |
created_at | 2022-01-02 17:53:32.279903 |
updated_at | 2022-01-04 20:48:53.339682 |
description | Open library for implementation Turing Machines. |
homepage | |
repository | https://github.com/Helltraitor/turing-machine-rs |
max_upload_size | |
id | 506651 |
size | 130,032 |
A library for implementing any Turing machine with minimal limitations for the Rust programming language. It is:
Low-cost: Turing Machine RS designed to simulate execution. That's why it cannot be simple, flexible and zero-cost at the same time.
Flexible: Turing Machine RS works with not the specific types nor even copy-only types! Instead, the library supports any struct or object that implements Clone + Debug + Display + Eq + PartialEq
trait.
Turing Machine RS includes a "Classic" realization for Turing Machine (a minimal version for simulation) and a "Debugger" Turing Machine that works with any type that implements the Turing Machine Trait.
This is a simple example of a Turing Machine that replaces nice
by test
and test
by nice
words.
extern crate turing_machine_rs;
use turing_machine_rs::instruction::{Move, State};
use turing_machine_rs::machines::Classic;
use turing_machine_rs::program::{Extend, Program};
use turing_machine_rs::state::Tape;
use turing_machine_rs::TuringMachine;
// For more comfortable coding, use Result<(), String>:
// `?` postfix symbol is better then `.unwrap()` postfix method call.
fn main() -> Result<(), String> {
let alphabet = vec!['t', 'e', 's', 'n', 'i', 'c', 'e', '_'];
let mut program = Program::new(alphabet, State(4));
program.extend([
(1, 't', 2, 'n', Move::Right),
(2, 'e', 3, 'i', Move::Right),
(3, 's', 4, 'c', Move::Right),
(4, 't', 0, 'e', Move::None),
// Revers
(1, 'n', 2, 't', Move::Right),
(2, 'i', 3, 'e', Move::Right),
(3, 'c', 4, 's', Move::Right),
(4, 'e', 0, 't', Move::None),
])?;
let machine = Classic::new(program, '_')?;
let test = Tape::from("test");
let nice = machine.translate_nrm(test.clone())?;
println!(
"{} {}!",
String::from_iter(nice.as_vec()),
String::from_iter(test.as_vec())
);
Ok(())
}
But this library is not just for the simplest types: you can even use other Turing machines as symbols! More examples can be found here.
First, read examples or docs. If examples can't provide answers for you, then you can try to read docs, and after all of that, you can contact me: helltraitor@hotmail.com
If you want to improve this crate, just open an issue (you can use example as a template). The issue must contain these headings: Problem
or Enhancement
, Motivation
(reasons to solve the problem or implement the enhancement). It would be very useful to add Useful sources
for documentation and examples.
Turing Machine RS was created in the latest stable version (2021, 1.57) but this library also supports 1.56 (at least) and above.
This project is licensed under the MIT license.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Turing Machine RS by you, shall be licensed as MIT, without any additional terms or conditions.