This code is an API for defining turing machines.
Special thanks to Undumendil for providing a turing machine implementation: https://github.com/Undumendil/tm. A Compiled version of tm
is available under out/tm
(compiled via Ubuntu on Windows).
$ tm subtraction.dtm --fast
for tape:
. . . . * 1 1 1 1 1 . 1 1 1 X . .
results in:
. . . . . . . . . . . . . . . . 1 1 . . . . . . . X . . . . . .
$ tm universal.dtm --fast
for tape stored in subtraction.utm
results in:
. . . . . . . . . . . . . . . . M I Qin 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Sin 0 0 Sout 0 0 Qout 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 r I Qin 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Sin 1 0 Sout 1 0 Qout 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 r I Qin 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Sin 1 1 Sout 1 1 Qout 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 r I Qin 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Sin 0 0 Sout 0 0 Qout 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 l I Qin 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Sin 1 0 Sout 1 0 Qout 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 l I Qin 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Sin 1 1 Sout 1 1 Qout 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 l I Qin 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Sin 0 0 Sout 0 0 Qout 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 r I Qin 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Sin 1 0 Sout 1 0 Qout 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 r I Qin 1 1 1 0 0 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0 0 r I Qin 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Sin 0 0 Sout 0 0 Qout 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 r I Qin 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Sin 1 0 Sout 1 0 Qout 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 r I Qin 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Sin 1 1 Sout 1 1 Qout 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 r Q 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 T S 0 0 S 0 0 S 0 0 S 0 0 ^ S 1 0 S 1 0 S 0 0 S 0 0 S 0 0 S 0 0 S 0 0 S 0 0 S 0 0 S 1 1 S 0 0 S 0 0 . . . .
Where S 0 0
is .
, S 1 0
is 1
and S 1 1
is X
.
Notice that takes 79455398 steps to finish.
Action is a way to describe the transition from one state to another.
Defined in turing.py
Slot as a helper object for constructing
transitions. In fact, it's only purpose is
to provide a simple .on(SYMBOL).<do_something>()
API.
Defined in turing.py
Creates a cycling transition from a state into itself.
Creates a transition to some new state.
Creates a transition to a particular state.
Describes a state)
Defined in turing.py
Returns a slot for constructing a transition from this state through the given symbol.
Alias for machine.state().
Allows to chain functions that take a state as an argument with other state functions.
E. g.:
state.move_right_until('1')
.apply(<move_somewhere_particular>)
.drop('0')
Keeps track of allocated states.
Encapsulates alphabet info.
Knows where are the BEGIN
, END
states
and has a TAPE
representation.
Defined in turing.py
Allocates a state within the machine.
A state of a machine that can describe its movement direction via 'l', 'n' and 'r'.
Defined in lnr.py
move_while(self, condition, direction, overstep=N)
move_left_while(self, condition, overstep=N)
move_right_while(self, condition, overstep=N)
move_until(self, condition, direction, overstep=N)
move_left_until(self, condition, overstep=N)
move_right_until(self, condition, overstep=N)
step(self, direction, symbol=KEEP)
step_left(self, symbol=KEEP)
step_right(self, symbol=KEEP)
drop(self, symbol, direction=N)
end(self)
Helper functions for turning a TM description into a particular text representation.
Defined as compiler.py
Writes the data
to the filename
and
logs messages with task
prefix.
Compiles a machine into the representation that can be used by Danya's turing machine implementation.
Compiles a machine into the representation
that the universal turing machine (universal.py
)
can handle. Don't forget about putting enough symbols
on the tape before compiling!