https://github.com/made2591/go-tm
A Golang library to implement both deterministic and non deterministic Turing machines easily.
https://github.com/made2591/go-tm
computable computational go golang interfaces machine patterns theory turing
Last synced: about 1 year ago
JSON representation
A Golang library to implement both deterministic and non deterministic Turing machines easily.
- Host: GitHub
- URL: https://github.com/made2591/go-tm
- Owner: made2591
- License: mit
- Created: 2018-12-18T16:42:01.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-22T20:02:54.000Z (over 7 years ago)
- Last Synced: 2025-01-13T10:50:12.759Z (over 1 year ago)
- Topics: computable, computational, go, golang, interfaces, machine, patterns, theory, turing
- Language: Go
- Homepage:
- Size: 67.4 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-tm - Make a Turing Machine easily
[](https://travis-ci.org/made2591/go-tm)
[](https://codebeat.co/projects/github-com-made2591-go-tm-master)
[](https://coveralls.io/github/made2591/go-tm?branch=master)
[](https://opensource.org/licenses/MIT)
[](https://godoc.org/github.com/made2591/go-tm)

**go-tm** is a library to implement both deterministic and non deterministic Turing machines easily. A related [blog-post](https://made2591.github.io/posts/golang-turing-machine) is here.
The Turing machine is a mathematical model of computation that defines an abstract machine which manipulates symbols on a strip of tape according to a list of rules. Formally, it is defined as an infinite tape of 0 with a pointer (identified by square bracket) to one specific zero,
```sh
... 0 0 0 0 0 [0] 0 0 0 0 0 ...
```
a set of states identified by letters (or numbers),
```sh
{A, B, C}
```
and a list of transactions, like the one
```sh
(A, 0, B, 1, R);
```
where a single transaction like *(A, 0, B, 1, R)* has to been read as
> *Given a Turing machine in state A with the pointer over a 0, write 1, evolve to state B and move the pointer by one position in right direction over the tape*.
The pointer can only be moved by one position at time, left, right, or stay where it is.
## Table of Contents
- [go-tm - Make a Turing Machine easily](#go-tm---make-a-turing-machine-easily)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [Usage](#usage)
- [Support](#support)
- [Contributing](#contributing)
## Installation
Just get the library by:
```sh
go get github.com/made2591/go-tm
```
## Usage
To create a new ```Symbol```, use the ```NewSymbol()``` factory method
```sh
// will create a new Symbol with value 0
sym := NewSymbol(uint8(0))
```
To create a new ```State```, use the ```NewState()``` or ```NewStateInitial()``` or ```NewStateFinal()``` factory methods
```sh
// will create a three new State, one with Identifier "A", one INITIAL and one FINAL
sts := NewState("A")
ins := NewStateInitial()
fis := NewStateFinal()
```
To create a new ```Transaction```, use the ```NewTransaction()``` factory method
```sh
// will move from INITIAL State, reading 0, writing 0, to state "B"
tr0 := transaction.NewTransaction(state.NewInitialState(), symbol.NewSymbol(uint8(0)), state.NewState("B"), symbol.NewSymbol(uint8(1)), "N")
```
To init a new ```TuringMachine``` to play the [BB-2 Game](https://en.wikipedia.org/wiki/Busy_beaver)
```sh
// create states set
iss := set.NewSet()
fss := set.NewSet()
trs := set.NewSet()
// create transaction
tr0 := transaction.NewTransaction(state.NewInitialState(), symbol.NewSymbol(uint8(0)), state.NewState("A"), symbol.NewSymbol(uint8(0)), "N")
tr1 := transaction.NewTransaction(state.NewState("A"), symbol.NewSymbol(uint8(0)), state.NewState("B"), symbol.NewSymbol(uint8(1)), "R")
tr2 := transaction.NewTransaction(state.NewState("A"), symbol.NewSymbol(uint8(1)), state.NewState("B"), symbol.NewSymbol(uint8(1)), "L")
tr3 := transaction.NewTransaction(state.NewState("B"), symbol.NewSymbol(uint8(0)), state.NewState("A"), symbol.NewSymbol(uint8(1)), "L")
tr4 := transaction.NewTransaction(state.NewState("B"), symbol.NewSymbol(uint8(1)), state.NewFinalState(), symbol.NewSymbol(uint8(1)), "R")
// add transaction to set
trs.Add(tr0)
trs.Add(tr1)
trs.Add(tr2)
trs.Add(tr3)
trs.Add(tr4)
// init the Turing Machine
tm := turingMachine.NewTuringMachine(iss, fss, trs, state.NewState(state.INITIAL), symbol.NewSymbol(uint8(0)))
// run the Turing Machine
tm.Run()
```
or, from inside the ```root``` folder of the project
```sh
go run main.go
```
## Support
Please [open an issue](https://github.com/made2591/go-tm/issues/new) for support.
## Contributing
Please contribute using [Github Flow](https://guides.github.com/introduction/flow/). Create a branch, add commits, and [open a pull request](https://github.com/made2591/go-tm/compare/).