This commit is contained in:
Miloslav Ciz 2024-08-31 14:44:45 +02:00
parent 124b9d1e7c
commit 3f374a4713
85 changed files with 2281 additions and 2272 deletions

View file

@ -23,7 +23,7 @@ A Turing machine is composed of:
- **a set of finitely many rules** in the format *[stateFrom, inputSymbol, stateTo, outputSymbol, headShift]*, where *stateFrom* is the current state, *inputSymbol* is symbol currently under the read/write head, *stateTo* is the state the machine will transition to, *outputSymbol* is the symbol that will be written to the memory cell under read/write head and *headShift* is the direction to shift the read/write head in (either *left*, *right* or *none*). There must not be conflicting rules (ones with the same combination of *stateFrom* and *inputSymbol*).
The machine halts either when it reaches the end state, when it tries to leave the tape (go left from memory cell 0) or when it encounters a situation for which it has no defined rule.
The computation works like this: the input data we want to process (for example a [string](string.md) we want to reverse) are stored in the memory before we run the machine. Then we run the machine and wait until it finishes, then we take what's present in the memory as the machine's output (i.e. for example the reversed string). That is a Turing machine doesn't have a traditional [I/O](io.md) (such as a "[printf](printf.md)" function), it only works entirely on data in memory!
Let's see a simple **example**: we will program a Turing machine that takes a [binary](binary.md) number on its output and adds 1 to it (for simplicity we suppose a fixed number of bits so an [overflow](overflow.md) may happen). Let us therefore suppose symbols 0 and 1 as the tape alphabet. The control unit will have the following rules:
@ -95,7 +95,7 @@ Indeed, we see the number we got at the output is 0110 (6 in decimal, i.e. 5 + 1
#define SHIFT_LEFT 1
#define SHIFT_RIGHT 2
unsigned int state; // 0 = start state, 0xffff = end state
unsigned int state; // 0 = start state, 0xffff = end state
unsigned int headPosition;
unsigned char tape[CELLS]; // memory tape
@ -205,4 +205,4 @@ Turing machines can be used to define computable [formal languages](formal_langu
- [brainfuck](brainfuck.md)
- [busy beaver](busy_beaver.md)
- [counter machine](counter_machine.md)
- [counter machine](counter_machine.md)