Computation-System
Simulate computational models, such as Turing machines.
It also supports the conversion of a computational model into a computational model that simulates it.
This can be used in Typescript.
Usage
Execute a Turing Machine
Code (Folded)
import { TMRuleSet, TMStateFrom, TMSymbolFrom, TuringMachine } from "computation-system";
let [A, B, Blank] = TMSymbolFrom("A", "B", "S");
let [q1, q2, qf] = TMStateFrom("q1", "q2", "qf");
let ruleset = TMRuleSet.builder()
.state(q1)
.add(A, B, "R")
.add(B, A, "R", q2)
.state(q2)
.add(B, B, "R", qf)
.state(qf)
.build();
let tm = new TuringMachine(Blank, ruleset, q1, qf);
tm.start([[A, A, B, B], 0]);
tm.proceed(10);
const afterConfig = tm.getConfiguration()!;
console.log(afterConfig.tape.toString());
Execute a TagSyetem
Code (Folded)
import { TagSystem, TagSystemLetterFrom, TagSystemRuleSet } from "computation-system";
const [a, b, c, H] = TagSystemLetterFrom("a", "b", "c", "H");
const ruleset = TagSystemRuleSet.builder()
.add(a, [c, c, b, a, H])
.add(b, [c, c, a])
.add(c, [c, c])
.addStop(H)
.build();
const ts = new TagSystem(2, ruleset);
ts.start([[b, a, a]]);
ts.proceed(20);
const afterConfig = ts.getConfiguration()!;
console.log(afterConfig.word.toString());
Converter (Beta)
Code (Folded)
import {
TagSystem,
TagSystemConfiguration,
TagSystemLetterFrom,
TagSystemRuleSet,
Converter,
createHierarchy,
ITransformHierarchy,
Tag2SystemToTuringMachine218TransformLog,
TuringMachine,
TMConfiguration,
} from "computation-system";
const [A, B, H] = TagSystemLetterFrom("A", "B", "H");
const tagSystemRuleSet = TagSystemRuleSet.builder().add(A, [B, H]).add(B, [A]).addStop(H).build();
const tagSystem = new TagSystem(2, tagSystemRuleSet);
const transformHierarchy: ITransformHierarchy<
[TagSystem, TuringMachine],
[Tag2SystemToTuringMachine218TransformLog]
> = createHierarchy(Converter.tag2SystemToTuringMachine218());
transformHierarchy.start(tagSystem, [[A, B, B]]);
while (!transformHierarchy.stopped()) {
transformHierarchy.proceed(1);
}
const configOfTagSystem: TagSystemConfiguration = transformHierarchy.getConfiguration(0)!;
console.log(configOfTagSystem.word.toString());
const configOfTM: TMConfiguration = transformHierarchy.getConfiguration(1)!;
console.log(configOfTM.tape.toString());
const table = transformHierarchy.getTransFormLogOf(0)!;
Supported Features
(This lib is WIP, so functions are few.)
Execute
- Turing Machine
- Tag System
- Write-First Turing Machine (Usually used in the middle of a conversion of a computational models by a Converter.)
Convert (Beta)
-
"Turing Machine with 2-symbol" simulates "Turing Machine"
(SHANNON, Claude E. A universal Turing machine with two internal states. Automata studies, 1956, 34: 157-165.)
-
"Write-First Turing Machine with 2-symbol" simulates "Turing Machine with 2-symbol"
-
"Tag System" simulates "Write-First Turing Machine with 2-symbol"
(COCKE, John; MINSKY, Marvin. Universality of tag systems with P= 2. Journal of the ACM (JACM), 1964, 11.1: 15-20.)
-
"Turing Machine" simulates "2-Tag System"
(ROGOZHIN, Yurii. Small universal Turing machines. Theoretical Computer Science, 1996, 168.2: 215-240.)
Documents
TSDoc: https://snowman-s.github.io/computation-system/
LICENSE
This software is released under the MIT License, see LICENSE.
Thanks!
This repository created from "TypeScript library starter"(https://github.com/alexjoverm/typescript-library-starter)! Thanks!