Details and Options
FRACTRAN is an esoteric programming language invented by the mathematician John H. Conway.
The result of a FRACTRAN execution is a list of integers.
A FRACTRAN program can have one of the following forms:
FRACTRAN-1 program | {f1,f2,…} | where each fi is a positive fraction |
FRACTRAN-n program | {…,{fl1→l1,fl2→l2,…},…} | where flm are positive fractions and each lm is an integer between 1 and n (the length of the list) |
The FRACTRAN-1 program ResourceFunction["Fractran"][{f1,f2,…,fi,…},n] repeatedly multiplies the integer at any stage (initially n) against the earliest fraction fi in the list that yields an integer product, stopping the execution when there is no such fi.
The FRACTRAN-n program ResourceFunction["Fractran"][{…,{fl1→l1,fl2→l2,…},…},n] repeatedly multiplies the integer at any stage (initially n) against the earliest fraction flm in line l (initially 1) that yields an integer product, then proceeds to the line indicated by lm, stopping the execution when there is no such flm.
The first element of the resulting list is always the starting integer n.
If ResourceFunction["Fractran"] terminates early, the last element of the resulting list is 0.
ResourceFunction["Fractran"] has the following options:
MaxIterations | Infinity | maximum number of iterations |
"MaxResults" | Infinity | maximum number of integers in the result |
"SelectionCriterion" | Automatic | test to determine whether an integer should be included in the result |
"ShowProgramLines" | False | if set to True, show the program line currently being executed |
The FRACTRAN language can be considered a type of register machine where: 1) The integer
n stores the contents of the registers in the exponents of prime factors of
n. For example
34992 = 24×37 represents a register state in which the register "2" holds the value 4 and the register "3" the value 7. 2) Each positive fraction
fi in a program represents an instruction that operates on the integer
n. The instruction is executed only if
fi × n yields an integer product, otherwise, a negative value will be stored in the register state
n. For example, the fraction
can operate on
24×37 resulting in
23×38, but not on
311 as the final register state would be
2-1×312.