Fractran

From BusyBeaverWiki
Revision as of 07:09, 11 November 2025 by Sligocki (talk | contribs) (Cryptids)
Jump to navigation Jump to search

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 [q0,q1,...qk1]called rules and a fractran state is an integer s. We say that a rule qi applies to state s if sqi. 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 st and t=sqi and i=min{i:sqi}. As with Turing machines, we will write sNt if ss1sN1t (s goes to t after N steps) and s*t or s+t if sNt 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 sNt and computation halts on t.

Let Ω(n) be the total number of prime factors of a positive integer n. In other words, Ω(2a03a1pnan)=k=0nan. Then given a rule ab we say that size(ab)=Ω(a)+Ω(b). And the size of a fractran program [q0,q1,...qk1] is k+i=0k1size(qi).

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 [a0,a1,,an1]n to represent the number 2a03a1pn1an1.

Let the vector representation (for a sufficiently large n) for a state a=2a03a1pn1an1 be v(a)=[a0,a1,,an1]n and the vector representation for a rule ab be v(ab)=v(a)v(b)n (Note that this is just an extension of the original definition extended to allow negative ai).

Now, rule q applies to state s iff v(s)+v(q)n (all components of the vector are ≥0) and if st then v(t)=v(s)+v(q). 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:

[021201110012]

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] [1]
3 1 [3/2] [11]
4 1 [9/2] [12]
5 2 [3/2, 1/3] [1101]
6 3 [9/2, 1/3] [1201]
7 4 [27/2, 1/3] [1301]
8 5 [81/2, 1/3] [1401]
9 6 [243/2, 1/3] [1501]
10 7 [729/2, 1/3] [1601]
11 10 [27/2, 25/3, 1/5] [130012001]
12 13 [81/2, 25/3, 1/5] [140012001]
13 17 [81/2, 125/3, 1/5] [140013001]
14 21 [243/2, 125/3, 1/5] [150013001]
15 28 [1/45, 4/5, 3/2, 25/3] [021201110012]
16 53 [1/45, 4/5, 3/2, 125/3] [021201110013]
17 107 [5/6, 49/2, 3/5, 40/7] [1110100201103011]
18 211 [5/6, 49/2, 3/5, 80/7] [1110100201104011]
19 ≳ 370 [5/6, 49/2, 3/5, 160/7] [1110100201105011]

Behavior of Champions

Sequential programs

All champions up to BBf(14) have very simple behavior. They are all of the form: [3a12,5a23,...pnakpk1,1pk] or in vector representation (limited to k=4):

[1a100001a200001a300001a400001]

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 1+a1+a1a2+a1a2a3+=i=0kj=1iaj and size 2k+2+i=1kai. 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 m,n0)

[1110100n0110m011]

which have size m+n+12

This family obeys the following rules:

  1. [1,0,0,0]1[0,0,0,n]
  2. if d≥1 and b≤m:[0,b,0,d]m+b+2[0,b+1,0,d1+n(mb)]
  3. if d≥1 and b≥m:[0,b,0,d]2m+2[0,b+1,0,d1]
  4. 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:1+n(m+1)(m(m+1)+2)m(m+1)2

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

Cryptids

No fractran Cryptids have been found via enumeration, but Shawn Ligocki constructed by hand a program of size 37 that simulates Hydra (here the 0s have been omitted to avoid clutter):

[1+3+11+11+11+2+1111+1+21+1+111+1+11+11]

The intended interpretation is that if we let S(h,w) = [0, w, h, 0, 1, 0, 0, 0] then it follows the following rules:

S(2k,0)*haltS(2k,w+1)*S(3k,w)S(2k+1,w)*S(3k+1,w+2)

References

  1. 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