User blog:Ikosarakt1/My Turing machine programs

Below are list of Turing machines programmed by me with its description. You can simulate all these program here.

Despite that these programs are written for the simulator above, you can also rewrite them for the simulator with "computing" ability (run program without showing steps), which is placed here.

Concatenating two strings of ones
Enter two strings and TM concatenates it (separate it by only one space).

Code:

0 _ * l halt 0 1 _ r 1 1 1 * r 1 1 _ * r 2 2 1 * r 2 2 _ 1 l 3 3 1 * l 3 3 _ * l 4 4 1 * l 4 4 _ * r 0

Concatenating multiple strings of ones
Enter arbitrary number of strings and TM concatenates it (separate it by only one space).

Code:

0 _ * r 5 0 1 _ r 1 1 1 * r 1 1 _ * r 2 2 1 * r 2 2 _ 1 l 3 3 1 * l 3 3 _ * l 4 4 1 * l 4 4 _ * r 0 5 _ * r 6 5 1 * r 5 6 _ * r halt 6 1 * l 7 7 _ * l 8 8 1 * l 8 8 _ * r 0

Removing one string of ones from other
Enter two strings and TM remove the one string from other.

Code:

0 1 * r 0 0 _ * r 1 1 _ * l 2 1 1 * r 1 2 _ * r halt 2 1 * r 3 3 _ * l 4 3 1 * r 3 4 1 _ l 5 5 1 * l 5 5 _ * l 6 6 1 * l 6 6 _ * r 7 7 1 _ r 0 7 _ * l halt

Double string of ones in size
Basically it is designed as unary function, but if you enter two strings, then the total number of ones is 2a+b, where a and b are lengths of 1 and 2 strings respectively.

Code:

0 _ _ l halt 0 1 _ r 1 1 1 * r 1 1 _ * r 2 2 _ 1 r 3 2 1 * r 2 3 _ 1 l 4 4 _ * l 5 4 1 * l 4 5 _ * r 0 5 1 * l 5

Simulating \(f_2(n)\) in the FGH
Enter two strings of ones and my program doubles the second string, first number of times.

Code:

0 1 * r 0 0 _ * r 1 1 _ * r 1 1 1 * l 1a 1a _ * r 2 2 _ _ l 3 2 1 _ r 3 3 1 * r 3 3 _ * r 4 4 _ 1 r 5 4 1 * r 4 5 _ 1 l 6 6 _ * l 7 6 1 * l 6 7 _ * r 8 7 1 * l 7 8 _ * l 9 8 1 _ r 3 9 _ * l 9 9 1 _ l 10 10 _ * l halt 10 1 * r 0

\(f_2(n)\) exactly in FGH
As previous machine, but with one string.

Code:

0 _ * r 7 0 1 _ r 1 1 1 * r 1 1 _ * r 2 2 _ 1 l 3 2 1 1 r 2 3 _ * l 4 3 1 * l 3 4 1 * l 4 4 _ 1 r 0 5 1 * r 5 5 _ * r 6 6 _ * r 6 6 1 * l 6a 6a _ * r 7 7 _ _ l 8 7 1 _ r 8 8 1 * r 8 8 _ * r 9 9 _ 1 r 10 9 1 * r 9 10 _ 1 l 11 11 _ * l 12 11 1 * l 11 12 _ * r 13 12 1 * l 12 13 _ * l 14 13 1 _ r 8 14 _ * l 14 14 1 _ l 15 15 _ * l halt 15 1 * r 5

\(f_3(n)\) exactly in FGH
When only seven ones entered, the total number of ones after halting will be larger than Poincaire recurrence time in the Planck times for the observable universe.

Code:

0 _ * r 5 0 1 _ r 1 1 1 * r 1 1 _ * r 2 2 _ 1 l 3 2 1 * r 2 3 1 * l 3 3 _ * l 4 4 1 * l 4 4 _ 1 r 0 5 _ * r 10 5 1 _ r 6 6 1 * r 6 6 _ * r 7 7 _ 1 l 8 7 1 * r 7 8 1 * l 8 8 _ * l 9 9 1 * l 9 9 _ 1 r 5 10 _ * r halt 10 1 _ r 11 11 1 * r 11 11 _ * r 12 12 _ 1 r 13 12 1 * r 12 13 _ 1 l 14 14 1 * l 14 14 _ * l 15 15 _ * l 17 15 1 * l 16 16 _ * r 10 16 1 * l 16 17 _ * l 17 17 1 _ l 18 18 _ * l 21 18 1 * r 19 19 _ * r 19 19 1 * l 20 20 _ * r 10 21 _ * l 21 21 1 _ l 22 22 _ * l halt 22 1 * r 23 23 _ * r 23 23 1 * l 24 24 _ * r 5

\(f_4(n)\) exactly in FGH
Enter n ones and TM returns number of ones greater or equal than \(2 \uparrow\uparrow\uparrow n\). For instance, entering merely 2 ones will return more than \(2 \uparrow\uparrow 2048\) ones.

Code:

0 _ * r 5 0 1 _ r 1 1 1 * r 1 1 _ * r 2 2 _ 1 l 3 2 1 * r 2 3 1 * l 3 3 _ * l 4 4 1 * l 4 4 _ 1 r 0 5 _ * r 10 5 1 _ r 6 6 1 * r 6 6 _ * r 7 7 _ 1 l 8 7 1 * r 7 8 1 * l 8 8 _ * l 9 9 1 * l 9 9 _ 1 r 5 10 _ * r 15 10 1 _ r 11 11 1 * r 11 11 _ * r 12 12 _ 1 l 13 12 1 * r 12 13 1 * l 13 13 _ * l 14 14 1 * l 14 14 _ 1 r 10 15 _ * r halt 15 1 _ r 16 16 1 * r 16 16 _ * r 17 17 _ 1 r 18 17 1 * r 17 18 _ 1 l 19 19 1 * l 19 19 _ * l 20 20 1 * l 21 20 _ * l 22 21 1 * l 21 21 _ * r 15 22 _ * l 22 22 1 _ l 23 23 1 * r 24 23 _ * l 26 24 _ * r 24 24 1 * l 25 25 _ * r 15 26 _ * l 26 26 1 _ l 27 27 _ * l 30 27 1 * r 28 28 _ * r 28 28 1 * l 29 29 _ * r 10 30 _ * l 30 30 1 _ l 31 31 _ * l halt 31 1 * r 32 32 _ * r 32 32 1 * l 33 33 _ * r 5

Note: the general pattern for \(f_m(n)\) and some lower bounds for \(\Sigma(n)\)
I've discovered the general method for constructing the TM that compute \(f_m(n)\). The table for \(f_m(n)\) \((m \geq 2)\) requires at most 9n-2 states and looks like that:

0 _ * r 5 0 1 _ r 1 1 1 * r 1 1 _ * r 2 2 _ 1 l 3 2 1 * r 2 3 1 * l 3 3 _ * l 4 4 1 * l 4 4 _ 1 r 0 T (transition table for TM for f_m-1(n) expect that in every rule, for states A ... B we replace it to A+5 ... B+5) 9m-6 _ * l 9m-6 9m-6 1 _ l 9m-5 9m-5 _ * l halt 9m-5 1 * r 9m-4 9m-4 _ * r 9m-4 9m-4 1 * l 9m-3 9m-3 _ * r 5

Therefore, I can state that table for \(f_m(n)\) would require 9n-2 states. For the \(\Sigma(n)\) condition, we need to start initially with the blank tape. Since \(f_m(1) = 2\) for every m, it is necessary to write at least two ones to start to perform the function. Hence, two additional states are required and thereby \(\Sigma(9n) \geq f_m(2)\) \((m \geq 2)\). This bound is weaker than Milton Green's one.

Also I can compare specific \(\Sigma(n)\) outputs with up-arrow notation:

\(\Sigma(18) \geq f_2(2) = 8\)

\(\Sigma(27) \geq f_3(2) = 2048\)

\(\Sigma(36) \geq f_4(2) > 2 \uparrow\uparrow 2048 > 2 \uparrow\uparrow\uparrow 3\)

\(\Sigma(45) \geq f_5(2) > 2 \uparrow\uparrow\uparrow (2 \uparrow\uparrow 2048) > 2 \uparrow\uparrow\uparrow\uparrow 3\)

\(\Sigma(54) \geq f_6(2) > 2 \uparrow^{5} 3\)

\(\Sigma(63) \geq f_7(2) > 2 \uparrow^{6} 3\)

In general:

\(\Sigma(9n) \geq f_m(2) > 2 \uparrow^{m-1} 3\)

Copy of string of ones
I found that it is possible using merely 5 states.

Code:

0 _ * r halt 0 1 _ r 1 1 1 * r 1 1 _ * r 2 2 _ 1 l 3 2 1 1 r 2 3 _ * l 4 3 1 * l 3 4 1 * l 4 4 _ 1 r 0

Square string of ones
Leaves \(n^2\) ones at the tape when n are written (in the form: n separated blocks of n's). Furthermore, it allows me to create \(f_\omega(n)\). Maybe this code can be optimized:

0 _ * r halt 0 1 _ r 1 1 1 * r 1 1 _ * r 2 2 _ * r 3 3 _ 1 l 4 3 1 * r 3 4 _ * l 5 4 1 * l 4 5 _ * l 6 6 _ 1 r 7 6 1 * l 6 7 1 _ r 1 7 _ * l 15 8 _ * l 13 8 1 _ r 9 9 1 * r 9 9 _ * r 10 10 _ 1 l 11 10 1 1 r 10 11 _ * l 12 11 1 * l 11 12 1 * l 12 12 _ 1 r 8 13 1 * l 13 13 _ * l 14 14 _ * l 15 14 1 * l 13 15 _ * l 15 15 1 _ l 16 16 _ * l halt 16 1 * r 17 17 _ * r 17 17 1 * r 18 18 1 * r 18 18 _ * r 19 19 1 * r 18 19 _ * l 20 20 _ * l 21 21 1 * l 21 21 _ * r 8

Square string of ones, n times
Input two strings: the first indicates the number of squarings, the second indicates the base.

0 1 * r 0 0 _ * r 1 1 _ * r halt 1 1 _ r 2 2 1 * r 2 2 _ * r 3 3 _ * r 4 4 _ 1 l 5 4 1 * r 4 5 _ * l 6 5 1 * l 5 6 _ * l 7 7 _ 1 r 8 7 1 * l 7 8 1 _ r 2 8 _ * l 16 9 _ * l 14 9 1 _ r 10 10 1 * r 10 10 _ * r 11 11 _ 1 l 12 11 1 1 r 11 12 _ * l 13 12 1 * l 12 13 1 * l 13 13 _ 1 r 9 14 1 * l 14 14 _ * l 15 15 _ * l 16 15 1 * l 14 16 _ * l 16 16 1 _ l 17 17 _ * r 23 17 1 * r 18 18 _ * r 18 18 1 * r 19 19 1 * r 19 19 _ * r 20 20 1 * r 19 20 _ * l 21 21 _ * l 22 22 1 * l 22 22 _ * r 9 23 _ * r 23 23 1 * * 24 24 _ * r 29 24 1 _ r 25 25 1 * r 25 25 _ * r 26 26 1 * r 26 26 _ 1 l 27 27 1 * l 27 27 _ * l 28 28 1 * l 28 28 _ * r 24 29 _ * r 30 29 1 * r 29 30 _ * l 33 30 1 * l 31 31 _ * l 32 32 1 * l 32 32 _ * r 24 33 _ * l 33 33 1 * l 34 34 1 * l 34 34 _ * l 35 35 _ * l 35 35 1 _ l 36 36 _ * l halt 36 1 * r 37 37 _ * r 37 37 1 * * 1

Division with integer result
(This version remains here because I want to discover its general behavior.)

Enter two strings and it computes their ratio if it is integer. If it is not integer, then it can either produces incorrect result or work infinitely (I believe it should be fixed using remainders).

Code:

0 1 * r 0 0 _ * r 1 1 _ * r 6 1 1 _ r 2 2 1 * r 2 2 _ * r 3 3 _ 1 l 4 3 1 * r 3 4 1 * l 4 4 _ * l 5 5 1 * l 5 5 _ 1 r 1 6 1 * r 6 6 _ * r 7 7 _ 1 l 8 7 1 * r 7 8 1 * l 8 8 _ * l 9 9 _ * l 10 9 1 _ l 10 10 1 * l 10 10 _ * l 11 11 1 * l 11 11 _ * l 12 12 1 * l 12 12 _ * r 13 13 _ * r 17 13 1 _ r 14 14 1 * r 14 14 _ * r 15 15 1 * r 15 15 _ * r 16 16 1 * r 16 16 _ * l 9 17 _ _ r 18 17 1 * r 0 18 1 _ r 18 18 _ * l halt

Also challenging problem: determine when input leads to infinite looping and when not.

Fixed division
Now it works correctly with any positive integer values, computing ceil(a/b), where ceil(n) rounds up to the nearest integer.

Code:

0 1 * r 0 0 _ * r 1 1 _ * r 6 1 1 _ r 2 2 1 * r 2 2 _ * r 3 3 _ 1 l 4 3 1 * r 3 4 1 * l 4 4 _ * l 5 5 1 * l 5 5 _ 1 r 1 6 1 * r 6 6 _ * r 7 7 _ 1 l 8 7 1 * r 7 8 1 * l 8 8 _ * l 9 9 _ * l 19 9 1 _ l 10 10 1 * l 10 10 _ * l 11 11 1 * l 11 11 _ * l 12 12 1 * l 12 12 _ * r 13 13 _ * r 17 13 1 _ r 14 14 1 * r 14 14 _ * r 15 15 1 * r 15 15 _ * r 16 16 1 * r 16 16 _ * l 9 17 1 _ r 17 17 _ * r 18 18 1 _ r 18 18 _ * l halt 19 1 * l 19 19 _ * l 20 20 _ * r 17 20 1 * r 21 21 _ * r 1

Decimal-unary converter
Enter the decimal number and TM will return that number of ones.

Code:

0 0 * r 0 0 1 * r 0 0 2 * r 0 0 3 * r 0 0 4 * r 0 0 5 * r 0 0 6 * r 0 0 7 * r 0 0 8 * r 0 0 9 * r 0 0 _ * l 1 1 0 9 l 1 1 1 0 r 2 1 2 1 r 2 1 3 2 r 2 1 4 3 r 2 1 5 4 r 2 1 6 5 r 2 1 7 6 r 2 1 8 7 r 2 1 9 8 r 2 1 _ * r 5 2 _ * r 3 2 9 * r 2 3 _ 1 l 4 3 1 * r 3 4 _ * l 1 4 1 * l 4 5 9 _ r 5 5 _ * l halt

String subsequence determiner
Determine whether the one string is a subsequence of another. It returns 1 if the subsequence operation is true, and none otherwise. It works only with 2-symbol alphabet for the second string and 1-symbol alphabet for the first string (I will try to improve it), and the syntax as follows:


 * Write first string and 1 at the end.
 * Immediately after it write second string and 1 at the end.

Code:

0 a _ r 1 0 1 * r 7 1 a * r 1 1 b * r 1 1 1 * r 2 2 a _ l 3 2 _ * r 2 2 b * r 2 2 1 _ l 5 3 _ * l 3 3 a * l 3 3 b * l 3 3 1 * l 4 4 a * l 4 4 b * l 4 4 _ * r 0 5 a _ l 5 5 b _ l 5 5 _ * l 5 5 1 _ l 6 6 a _ l 6 6 b _ l 6 6 _ * l halt 7 _ * r 7 7 a _ r 7 7 b _ r 7 7 1 _ r halt

Improved string subsequence determiner
As previous: 2-symbol alphabet, but now it allows to have 2-symbol typed 1st string. Also you need to write "12" after the first string instead of "1". Symbol "2" is used to keep the ordering of strings. Enter long strings to see how it works.

0 a _ r 1 1 a * r 1 1 b * r 1 1 1 * r 2 2 a * r 2 2 _ * r 2 2 b * r 2 2 2 _ r 3 3 a 2 l 4 3 b * r 3 3 1 _ l 9 4 a * l 4 4 b * l 4 4 2 * l 4 4 _ * l 4 4 1 * l 5 5 a * l 5 5 b * l 5 5 _ * r 0 0 b _ r 6 6 a * r 6 6 b * r 6 6 1 * r 7 7 _ * r 7 7 a * r 7 7 b * r 7 7 2 _ r 8 8 a * r 8 8 b 2 l 4 8 1 _ l 9 9 a _ l 9 9 b _ l 9 9 _ * l 9 9 1 _ l 10 9 2 _ l 9 10 a _ l 10 10 b _ l 10 10 _ * r halt 0 _ * r 0 0 1 * r 11 11 _ * r 11 11 a _ r 11 11 b _ r 11 11 2 _ r 11 11 1 _ r halt

Multiplication of strings
Computes a*b, where a and b represented by string of ones separated by the one space.

0 _ * r halt 0 1 _ r 15 1 1 * r 1 1 _ * r 2 2 _ * l 7 2 1 * r 10 3 1 * r 3 3 _ * r 4 4 _ 1 l 5 4 1 * r 4 5 _ * l 6 5 1 * l 5 6 1 * l 6 6 _ 1 r 14 7 1 * l 7 7 _ * l 8 8 1 * l 7 8 _ * r 9 9 _ * r 0 10 1 * r 10 10 _ * r 11 11 1 * r 10 11 _ * l 12 12 _ * l 13 13 1 * l 13 13 _ * r 14 14 1 _ r 3 14 _ * l 7 15 _ * r 16 15 1 * r 1 16 _ * r halt 16 1 _ r 17 17 1 * r 17 17 _ 1 r 18 18 _ * r 19 18 1 * r 18 19 _ * r halt 19 1 * l 20 20 _ * l 21 21 1 * l 21 21 _ * r 16

Factorial
Computes \(n!\). It works also for 0! = 1.

0 _ 1 r halt 0 1 _ r 50 1 1 * r 1 1 _ * r 2 2 _ * r 3 3 _ 1 l 4 3 1 * r 3 4 _ * l 5 4 1 * l 4 5 _ * l 6 6 _ 1 r 7 6 1 * l 6 7 1 _ r 1 7 _ 2 l 8 8 2 * l 8 8 1 * l 8 8 _ * r 9 9 1 _ r 10 9 2 _ r halt 10 1 _ r 11 10 2 * r 40 11 1 * r 11 11 2 * r 11 11 _ * r 12 12 _ * r 12 12 1 * r 13 13 1 * r 13 13 _ * r 14 14 1 * r 14 14 _ 1 l 15 15 _ * l 16 15 1 * l 15 16 1 * l 16 16 _ * l 45 17 2 * l 17 17 1 * l 17 17 _ 1 r 10 18 _ * r 46 18 1 _ r 33 19 1 * r 19 19 _ * r 20 20 _ * l 25 20 1 * r 28 21 1 * r 21 21 _ * r 22 22 _ 1 l 23 22 1 * r 22 23 _ * l 24 23 1 * l 23 24 1 * l 24 24 _ 1 r 32 25 1 * l 25 25 _ * l 26 26 1 * l 25 26 _ * r 27 27 _ * r 18 28 1 * r 28 28 _ * r 29 29 1 * r 28 29 _ * l 30 30 _ * l 31 31 1 * l 31 31 _ * r 32 32 1 _ r 21 32 _ * l 25 33 _ * r 34 33 1 * r 19 34 _ * r halt 34 1 _ r 35 35 1 * r 35 35 _ 1 r 36 36 _ * r 37 36 1 * r 36 37 _ * l 41 37 1 * l 38 38 _ * l 39 39 1 * l 39 39 _ * r 34 40 _ * r 18 41 _ * l 42 42 1 * l 42 42 _ * l 43 43 _ * l 43 43 2 * l 44 44 1 * l 47 44 _ * r 9 45 _ * l 45 45 2 * l 17 46 _ * r 46 46 1 _ r 33 47 _ * r 49 47 1 * l 48 48 1 * l 48 48 _ * r 9 49 1 _ r 49 49 2 _ r halt 50 _ 1 l halt 50 1 * r 1