Bitwise Cyclic Tag
From Esolang
Bitwise Cyclic Tag (BCT) is a Turing-complete programming language using only two commands (0 and 1) to operate on a finite data-bitstring extensible without bound on the right.
Contents |
[edit] BCT programs
A BCT program is any finite string of bits (commands), executed as follows:
Command Execution
------- ---------------------------------------------
0 delete the leftmost data-bit
1 goto the next command (say x)
if the leftmost data-bit is 1:
copy x to the right end of the data-string
If the program-string or the data-string is initially empty, execution halts immediately; otherwise, starting at the leftmost program-bit and halting only when the data-string becomes empty, the commands are executed in cyclic sequence from left to right (the leftmost bit following next after the rightmost bit).
The program pointer advances one bit after each command-execution, and also advances one bit when the goto in a 1-command is executed; consequently, a 1-command always pairs with the next command after it (say x), such that 1x is effectively a composite command whose execution is
if the leftmost data-bit is 1:
copy x to the right end of the data-string
Four equivalent variations of BCT are obtained by exchanging the roles of symbols 0 and 1 as commands, and by varying the parity required in the condition for copying a bit to the end of the data-string.
[edit] Example
Program: 00111
Execution sequence: 00111 (00111) (00111) (00111) ...
= 0 (0 11 10) (0 11 10) (0 11 10) ...
Initial data-string: 101
System evolution:
Commands Data-
Executed String
-------- -------
0 101
0 01
11 1
10 11
0 110
11 10
10 101
0 1010
11 010
10 010
0 010
11 10
... ...
[edit] BCT emulation of cyclic tag systems
For any cyclic tag system on a binary alphabet, there is a BCT program that emulates it (thus establishing that BCT is Turing-complete, since the set of cyclic tag systems is Turing-complete).
Specifically, a BCT program that emulates a given cyclic tag system is obtained by writing the cyclic tag system productions as ';'-terminated strings, concatenating these strings, and then applying the following substitutions:
0 <-- 10
1 <-- 11
; <-- 0
The initial data-string for the BCT program is the unaltered initial binary word for the cyclic tag system.
[edit] The language CT
BCT was created upon noticing that the operation of a cyclic tag system is exactly duplicated by interpreting the concatenation of its semicolon-terminated productions as a program that uses three commands {0, 1, ;} to operate on the current word (interpeted as a data bit-string). Calling this three-instruction language CT, with programs that may be any finite string on {0, 1, ;}, the commands of a CT program are executed left-to-right in cyclic sequence, halting only when the data-string becomes empty:
CT Command Execution Equivalent BCT Command
---------- --------------------------------------------- ----------------------
0 if the leftmost data-bit is 1, append 0 10
1 if the leftmost data-bit is 1, append 1 11
; delete the leftmost data-bit 0
The purpose of replacing CT by BCT was merely to obtain a language whose programs are binary (rather than ternary) strings.
[edit] Example (simple illustration)
This is just to illustrate how things work ...
Cyclic tag system Productions: (011, 10, 101) CT program: 011;10;101; Translation to a BCT program 011;10;101; --> 10 11 11 0 11 10 0 11 10 11 0 Initial data-string: 1 System evolution: Commands Executed Data-string -------- ------------- 10 1 11 10 11 101 0 1011 * 11 011 10 011 0 011 * 11 11 10 111 11 1110 0 11101 * 10 1101 11 11010 11 110101 0 1101011 * 11 101011 10 1010111 0 10101110 * 11 0101110 10 0101110 11 0101110 0 0101110 * 10 101110 ... ...
The data-strings marked by '*' are those just after each deletion, and are the strings occurring in the evolution of the equivalent cyclic tag system, as follows:
Production Data-string ---------- ------------- 011 1 10 011 101 11 011 1101 10 101011 101 0101110 011 101110 ... ...
[edit] Example (Collatz sequences)
Here are B/CT programs that compute Collatz sequences for the Collatz function in the form C(n) = (if n is even then n/2 else (3n+1)/2).
Cyclic tag system: (010001, 100, 100100100, e, e, e) (where e is the empty word) CT program: 010001;100;100100100;;;; BCT program: 10 11 10 10 10 11 0 11 10 10 0 11 10 10 11 10 10 11 10 10 0 0 0 0 Initial data-string: (100)n (n concatenated copies of '100', where n is a postive integer)
In the computation, when (and only when) the data-string takes the form (100)k immediately before beginning a cycle through the program, it represents the integer k -- and these will be the successive terms of the Collatz sequence for n. Here is a sample computation for n = 3, showing the data-strings at the beginning of each program-cycle:
B/CT step# Collatz term B/CT data-string ----- ------------ ------------------------ 0000 3 100100100 0024 100010001 0048 001010001 0072 001100100100 0096 5 100100100100100 0120 100100100010001 0144 100010001010001 0168 001010001010001 0192 001010001100100100 0216 001100100100100100100 0240 8 100100100100100100100100 0264 100100100100100100010001 0288 100100100100010001010001 0312 100100010001010001010001 0336 010001010001010001010001 0360 010001010001010001100 0384 010001010001100100 0408 010001100100100 0432 4 100100100100 0456 100100010001 0480 010001010001 0504 010001100 0528 2 100100 0552 010001 0576 1 100 0600 001 0624 2 100100 0648 010001 0672 1 100 ... ... ...
(The step-numbers are the multiples of 24, because there are 24 commands executed in each program-cycle.)
[edit] Arithmetic interpretation of BCT
The BCT data-string can be interpreted as the unique numeral of a nonnegative integer written in bijective base-2 representation, as follows:
BCT data-string Bijective base-2 numeral Integer represented
--------------- ---------------------------- -------------------------
b0 b1 ... bk (bk + 1)(bk-1 + 1)...(b0 + 1) SUM{(bi + 1) 2i: i = 0..k}
Note that the digits 1,2 are represented by the bits 0,1 respectively, and the numeral is read in reverse order from the bit-string. E.g., the BCT data-string 011 corresponds to the bijective base-2 numeral 221, representing the integer 2*22 + 2*21 + 1*20 = 13.
Each BCT command in a program then corresponds to an explicit numerical function defined on the set N of nonnegative integers, as follows:
Command Equivalent numerical function (mapping N to N) ------- ---------------------------------------------- 0 f(n) = floor+((n-1)/2) 10 g0(n) = n + (n mod 2) * 2(floor(log2(n+1)) + 0) 11 g1(n) = n + (n mod 2) * 2(floor(log2(n+1)) + 1)
where we've shown separately the two cases for the program-bit that's next after the 1-command. Here floor+ denotes the positive part of the floor function — so the integer 0 is a fixed-point of all three of the functions f, g0, g1, and represents a permanent "halt" condition. (Also note that floor(log2(n+1)) is just the number of digits in the bijective base-2 numeral for n.)
Thus a BCT program is equivalent to a composition of finitely-many instances of the three functions f, g0, g1, all but some initial portion of which is iterated. Just as the sequence of successive data-strings encodes all input and output in a BCT computation, in the arithmetic interpretation the same role is fulfilled by the sequence of successive nonnegative integer arguments.
[edit] Gödel numbering
A Gödel numbering of BCT programs is automatically provided by similarly interpreting each BCT program as the bijective base-2 numeral of an integer (now in the usual digit-order, unlike the data-string). Thus, a BCT program is (the numeral of) its own Gödel number. E.g., the program 011 is interpreted as the integer 10 (ten = 122 in bijective base-2) — and indeed 011 is the tenth nonempty BCT program in a shortlex ordering of the set of all BCT programs.
[edit] Example
bit-string bij. base-2 decimal
---------- ----------- -------
Program: 110100 221211 115
Initial data: 10 12 4
Execution-trace:
data (at beginning of each step)
--------------------------------
step# cmd function bit-string bij. base-2 decimal function evaluation
----- ---- -------- ---------- ----------- ------- -------------------
0001 11 * g1 10 12 4
0002 0 f 101 212 12 = g1(4)
0003 10 g0 01 21 5 = f(12)
0004 0 f 01 21 5 = g0(5)
0005 11 * g1 1 2 2 = f(5)
0006 0 f 11 22 6 = g1(2)
0007 10 g0 1 2 2 = f(6)
0008 0 f 10 12 4 = g0(2)
0009 11 * g1 0 1 1 = f(4)
0010 0 f 0 1 1 = g1(1)
(halt) - - 0 = f(1)
-----
deletion sequence: 10110
An asterisk marks the first command executed in each cycle through the program — the first function evaluated in each iteration.
[edit] Computations in BCT
It can be shown that for any Turing machine computation, there is a BCT system (program plus data-string) that simulates it — halting if and only if the TM halts, and encoding the TM's input and output in the sequence of deleted data-bits. For further details, see the BCT source page (external link) below.
[edit] Authorship
The languages CT and BCT were created by "r.e.s." in December 2005.
[edit] External resources
- Bitwise Cyclic Tag interpreter written in brainfuck and in Thue (Keymaker)
- Cyclic Tag systems (Wikipedia)
Categories: Languages | Turing tarpits | 2005 | No IO

