Fractran: Difference between revisions
→Vector Representation: Note how size works in vec rep |
RobinCodes (talk | contribs) →Sequential programs: minor grammar fix |
||
| (9 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
'''Fractran''' (originally styled FRACTRAN) is an esoteric Turing complete model of computation invented by John Conway in 1987.<ref>Conway, John H. (1987). "FRACTRAN: A Simple Universal Programming Language for Arithmetic". ''Open Problems in Communication and Computation''. Springer-Verlag New York, Inc. pp. 4–26. <nowiki>http://doi.org/10.1007/978-1-4612-4808-8_2</nowiki></ref> In this model a program is simply a finite list of fractions, the program state is an integer. For more details see https://en.wikipedia.org/wiki/FRACTRAN | '''Fractran''' (originally styled FRACTRAN) is an esoteric Turing complete model of computation invented by John Conway in 1987.<ref>Conway, John H. (1987). "FRACTRAN: A Simple Universal Programming Language for Arithmetic". ''Open Problems in Communication and Computation''. Springer-Verlag New York, Inc. pp. 4–26. <nowiki>http://doi.org/10.1007/978-1-4612-4808-8_2</nowiki></ref> In this model a program is simply a finite list of fractions (rational numbers), the program state is an integer. For more details see https://en.wikipedia.org/wiki/FRACTRAN | ||
'''BB_fractran'''(n) or '''BBf'''(n) is the Busy Beaver function for Fractran programs. | '''BB_fractran'''(n) or '''BBf'''(n) is the Busy Beaver function for Fractran programs. | ||
== Definition == | == Definition == | ||
A fractran program is a list of rational numbers <math>[q_0, q_1, ... q_{k-1}]</math>called rules and a fractran state is an integer <math>s \in \mathbb{Z}</math>. We say that a rule <math>q_i</math> applies to state <math>s</math> if <math>s \cdot q_i \in \mathbb{Z}</math>. If no rule applies, we say that the computation has halted otherwise we apply the first applicable rule at each step. In that case we say <math>s \to t</math> and <math>t = s \cdot q_i</math> and <math>i = \min \{ i : s \cdot q_i \in \mathbb{Z} \}</math>. We say that a program has runtime N (or halts in N steps) starting in state s if <math>s \ | A fractran program is a list of rational numbers <math>[q_0, q_1, ... q_{k-1}]</math>called rules and a fractran state is an integer <math>s \in \mathbb{Z}</math>. We say that a rule <math>q_i</math> applies to state <math>s</math> if <math>s \cdot q_i \in \mathbb{Z}</math>. If no rule applies, we say that the computation has halted otherwise we apply the first applicable rule at each step. In that case we say <math>s \to t</math> and <math>t = s \cdot q_i</math> and <math>i = \min \{ i : s \cdot q_i \in \mathbb{Z} \}</math>. As with [[Turing machines]], we will write <math>s \xrightarrow{N} t</math> if <math>s \to s_1 \to \cdots \to s_{N-1} \to t </math> (s goes to t after N steps) and <math>s \to^* t</math> or <math>s \to^+ t</math> if <math>s \xrightarrow{N} t</math> for some N≥0 or N≥1 (respectively). We say that a program has runtime N (or halts in N steps) starting in state s if <math>s \xrightarrow{N} t</math> and computation halts on t. | ||
Let <math>\Omega(n)</math> be the total number of prime factors of a positive integer n. In other words <math>\Omega( | Let <math>\Omega(n)</math> be the total number of prime factors of a positive integer n. In other words, <math>\Omega(2^{a_0} 3^{a_1} \cdots p_n^{a_n}) = \sum_{k=0}^n a_n</math>. Then given a rule <math>\frac{a}{b} </math> we say that <math>\text{size} \left( \frac{a}{b} \right) = \Omega(a) + \Omega(b) </math>. And the size of a fractran program <math>[q_0, q_1, ... q_{k-1}]</math> is <math>k + \sum_{i=0}^{k-1} \text{size}(q_i) </math>. | ||
BB_fractran(n) or BBf(n) is the maximum runtime starting in state 2 for all halting fractran programs of size n. It is a non-computable function akin to the [[Busy Beaver Functions]] since Fractran is Turing Complete. | BB_fractran(n) or BBf(n) is the maximum runtime starting in state 2 for all halting fractran programs of size n. It is a non-computable function akin to the [[Busy Beaver Functions]] since Fractran is Turing Complete. | ||
| Line 35: | Line 35: | ||
!Example Champion | !Example Champion | ||
!Vector Representation | !Vector Representation | ||
|- | |- | ||
| 2 || 1 || <code>[1/2]</code> | | 2 || 1 || <code>[1/2]</code> | ||
| Line 157: | Line 154: | ||
5 & 0 & 1 & -1 | 5 & 0 & 1 & -1 | ||
\end{bmatrix}</math> | \end{bmatrix}</math> | ||
|} | |||
=== Behavior of Champions === | |||
==== Sequential programs ==== | |||
All champions up to BBf(14) have very simple behavior. They are all of the form: <math>\left[ \frac{3^{a_1}}{2}, \frac{5^{a_2}}{3}, ... \frac{p_n^{a_k}}{p_{k-1}}, \frac{1}{p_k} \right]</math> or in vector representation (limited to k=4): | |||
<math display="block">\begin{bmatrix} | |||
-1 & a_1 & 0 & 0 & 0 \\ | |||
0 & -1 & a_2 & 0 & 0 \\ | |||
0 & 0 & -1 & a_3 & 0 \\ | |||
0 & 0 & 0 & -1 & a_4 \\ | |||
0 & 0 & 0 & 0 & -1 | |||
\end{bmatrix}</math> | |||
These champions repeatedly apply the rules in sequence, never going back to a previous rule. They apply the first rule until they've exhausted all 2s, then the second rule until they've exhausted all 3s, etc. They have a runtime of <math>1 + a_1 + a_1 a_2 + a_1 a_2 a_3 + \cdots = \sum_{i=0}^k \prod_{j=1}^i a_j</math> and size <math>2k+2 + \sum_{i=1}^k a_i</math>. This grows linearly for k=1 (BBf(5) to BBf(10)) and quadratically for k=2 (BBf(11) ot BBf(14)). Letting k grow with the size, the maximum runtime grows exponentially in the program size. | |||
==== BBf(17) Family ==== | |||
The BBf(17) to BBf(19) champions are members of a family of programs (parameterized by <math>m,n \ge 0</math>) | |||
<math display="block">\begin{bmatrix} | |||
-1 & -1 & 1 & 0 \\ | |||
-1 & 0 & 0 & n \\ | |||
0 & 1 & -1 & 0 \\ | |||
m & 0 & 1 & -1 | |||
\end{bmatrix}</math> | |||
which have size <math>m+n+12</math> | |||
This family obeys the following rules: | |||
# <math>[1, 0, 0, 0] \xrightarrow{1} [0, 0, 0, n]</math> | |||
# if d≥1 and b≤m:<math display="block">[0, b, 0, d] \xrightarrow{m+b+2} [0, b+1, 0, d - 1 + n(m-b)]</math> | |||
# if d≥1 and b≥m:<math display="block">[0, b, 0, d] \xrightarrow{2m+2} [0, b+1, 0, d - 1]</math> | |||
#if d=0: [0,b,0,d] has halted | |||
and furthermore these rules are applied in order since b is always increasing (and d is eventually decreasing). Combining these together we get runtime:<math display="block">1 + n(m+1)(m(m+1)+2) - \frac{m(m+1)}{2}</math> | |||
The optimal choices for n,m for various program sizes are: | |||
{| class="wikitable" | |||
|+ | |||
!Size | |||
!n | |||
!m | |||
!Runtime | |||
|- | |||
|16 | |||
|1 | |||
|3 | |||
|51 | |||
|- | |||
|17 | |||
|2 | |||
|3 | |||
|107 | |||
|- | |||
|18 | |||
|2 | |||
|4 | |||
|211 | |||
|- | |||
|19 | |||
|2 | |||
|5 | |||
|370 | |||
|- | |||
|20 | |||
|2 | |||
|6 | |||
|596 | |||
|- | |||
|21 | |||
|3 | |||
|6 | |||
|904 | |||
|} | |} | ||
== References == | == References == | ||
<references /> | <references /> | ||
Latest revision as of 06:05, 11 November 2025
Fractran (originally styled FRACTRAN) is an esoteric Turing complete model of computation invented by John Conway in 1987.[1] In this model a program is simply a finite list of fractions (rational numbers), the program state is an integer. For more details see https://en.wikipedia.org/wiki/FRACTRAN
BB_fractran(n) or BBf(n) is the Busy Beaver function for Fractran programs.
Definition
A fractran program is a list of rational numbers called rules and a fractran state is an integer . We say that a rule applies to state if . If no rule applies, we say that the computation has halted otherwise we apply the first applicable rule at each step. In that case we say and and . As with Turing machines, we will write if (s goes to t after N steps) and or if for some N≥0 or N≥1 (respectively). We say that a program has runtime N (or halts in N steps) starting in state s if and computation halts on t.
Let be the total number of prime factors of a positive integer n. In other words, . Then given a rule we say that . And the size of a fractran program is .
BB_fractran(n) or BBf(n) is the maximum runtime starting in state 2 for all halting fractran programs of size n. It is a non-computable function akin to the Busy Beaver Functions since Fractran is Turing Complete.
Vector Representation
Fractran programs are not easy to interpret, in fact it may be completely unclear at first that they can perform any computation at all. One of the key insights is to represent all numbers (states and rules) in their prime factorization form. For example, we can use a vector to represent the number .
Let the vector representation (for a sufficiently large n) for a state be and the vector representation for a rule be (Note that this is just an extension of the original definition extended to allow negative ).
Now, rule q applies to state s iff (all components of the vector are ≥0) and if then . So the fractran multiplication model is completely equivalent to the vector adding model. For presentation, we will represent a fractran program with a matrix where each row is the vector representation for a rule.
For example, the BBf(15) champion ([1/45, 4/5, 3/2, 25/3]) in vector representation would be:
In this representation, it becomes much easier to reason about fractran programs and describe general rules. It is also very easy to calculate the size of a rule or program in vector representation. It is the sum of absolute values of all elements in the matrix + number of rules (number of rows).
Champions
| n | BBf(n) | Example Champion | Vector Representation |
|---|---|---|---|
| 2 | 1 | [1/2]
|
|
| 3 | 1 | [3/2]
|
|
| 4 | 1 | [9/2]
|
|
| 5 | 2 | [3/2, 1/3]
|
|
| 6 | 3 | [9/2, 1/3]
|
|
| 7 | 4 | [27/2, 1/3]
|
|
| 8 | 5 | [81/2, 1/3]
|
|
| 9 | 6 | [243/2, 1/3]
|
|
| 10 | 7 | [729/2, 1/3]
|
|
| 11 | 10 | [27/2, 25/3, 1/5]
|
|
| 12 | 13 | [81/2, 25/3, 1/5]
|
|
| 13 | 17 | [81/2, 125/3, 1/5]
|
|
| 14 | 21 | [243/2, 125/3, 1/5]
|
|
| 15 | 28 | [1/45, 4/5, 3/2, 25/3]
|
|
| 16 | 53 | [1/45, 4/5, 3/2, 125/3]
|
|
| 17 | 107 | [5/6, 49/2, 3/5, 40/7]
|
|
| 18 | 211 | [5/6, 49/2, 3/5, 80/7]
|
|
| 19 | ≳ 370 | [5/6, 49/2, 3/5, 160/7]
|
Behavior of Champions
Sequential programs
All champions up to BBf(14) have very simple behavior. They are all of the form: or in vector representation (limited to k=4):
These champions repeatedly apply the rules in sequence, never going back to a previous rule. They apply the first rule until they've exhausted all 2s, then the second rule until they've exhausted all 3s, etc. They have a runtime of and size . This grows linearly for k=1 (BBf(5) to BBf(10)) and quadratically for k=2 (BBf(11) ot BBf(14)). Letting k grow with the size, the maximum runtime grows exponentially in the program size.
BBf(17) Family
The BBf(17) to BBf(19) champions are members of a family of programs (parameterized by )
which have size
This family obeys the following rules:
- if d≥1 and b≤m:
- if d≥1 and b≥m:
- if d=0: [0,b,0,d] has halted
and furthermore these rules are applied in order since b is always increasing (and d is eventually decreasing). Combining these together we get runtime:
The optimal choices for n,m for various program sizes are:
| Size | n | m | Runtime |
|---|---|---|---|
| 16 | 1 | 3 | 51 |
| 17 | 2 | 3 | 107 |
| 18 | 2 | 4 | 211 |
| 19 | 2 | 5 | 370 |
| 20 | 2 | 6 | 596 |
| 21 | 3 | 6 | 904 |
References
- ↑ Conway, John H. (1987). "FRACTRAN: A Simple Universal Programming Language for Arithmetic". Open Problems in Communication and Computation. Springer-Verlag New York, Inc. pp. 4–26. http://doi.org/10.1007/978-1-4612-4808-8_2