A FRACTRAN program can be seen as a type of register machine where the registers are stored in prime exponents in the argument n.

Using Gödel numbering, a positive integer n can encode an arbitrary number of arbitrarily large positive integer variables.[note 2] The value of each variable is encoded as the exponent of a prime number in the prime factorization of the integer. For example, the integer

60=22×31×51{\displaystyle 60=2^{2}\times 3^{1}\times 5^{1}}

represents a register state in which one variable (which we will call v2) holds the value 2 and two other variables (v3 and v5) hold the value 1. All other variables hold the value 0.

A FRACTRAN program is an ordered list of positive fractions. Each fraction represents an instruction that tests one or more variables, represented by the prime factors of its denominator. For example:

Since the FRACTRAN program is just a list of fractions, these test-decrement-increment instructions are the only allowed instructions in the FRACTRAN language. In addition the following restrictions apply:

Each time an instruction is executed, the variables that are tested are also decremented.

The same variable cannot be both decremented and incremented in a single instruction (otherwise the fraction representing that instruction would not be in its lowest terms). Therefore each FRACTRAN instruction consumes variables as it tests them.

It is not possible for a FRACTRAN instruction to directly test if a variable is 0 (However, an indirect test can be implemented by creating a default instruction that is placed after other instructions that test a particular variable.).

This program can be represented as a (very simple) algorithm as follows:

FRACTRANInstruction

Condition

Action

32{\displaystyle {\frac {3}{2}}}

v2 > 0

Subtract 1 from v2Add 1 to v3

v2 = 0

Stop

Given an initial input of the form 2a3b{\displaystyle 2^{a}3^{b}}, this program will compute the sequence 2a−13b+1{\displaystyle 2^{a-1}3^{b+1}}, 2a−23b+2{\displaystyle 2^{a-2}3^{b+2}}, etc., until eventually, after a{\displaystyle a} steps, no factors of 2 remain and the product with 32{\displaystyle {\frac {3}{2}}} no longer yields an integer; the machine then stops with a final output of 3a+b{\displaystyle 3^{a+b}}. It therefore adds two integers together.

We can create a "multiplier" by "looping" through the "adder". In order to do this we need to introduce states into our algorithm. This algorithm will take a number 2a3b{\displaystyle 2^{a}3^{b}} and produce 5ab{\displaystyle 5^{ab}}:

Current State

Condition

Action

Next State

A

v7 > 0

Subtract 1 from v7Add 1 to v3

A

v7 = 0 andv2 > 0

Subtract 1 from v2

B

v7 = 0 andv2 = 0 andv3 > 0

Subtract 1 from v3

A

v7 = 0 andv2 = 0 andv3 = 0

Stop

B

v3 > 0

Subtract 1 from v3Add 1 to v5Add 1 to v7

B

v3 = 0

None

A

State B is a loop that adds v3 to v5 and also moves v3 to v7, and state A is an outer control loop that repeats the loop in state B v2 times. State A also restores the value of v3 from v7 after the loop in state B has completed.

We can implement states using new variables as state indicators. The state indicators for state B will be v11 and v13. Note that we require two state control indicators for one loop; a primary flag (v11) and a secondary flag (v13). Because each indicator is consumed whenever it is tested, we need a secondary indicator to say "continue in the current state"; this secondary indicator is swapped back to the primary indicator in the next instruction, and the loop continues.

Adding FRACTRAN state indicators and instructions to the multiplication algorithm table, we have:

When we write out the FRACTRAN instructions, we must put the state A instructions last, because state A has no state indicators - it is the default state if no state indicators are set. So as a FRACTRAN program, the multiplier becomes:

Conway's prime generating algorithm above is essentially a quotient and remainder algorithm within two loops. Given input of the form 2n7m{\displaystyle 2^{n}7^{m}} where 0 ≤ m < n, the algorithm tries to divide n+1 by each number from n down to 1, until it finds the largest number k that is a divisor of n+1. It then returns 2n+1 7k-1 and repeats. The only times that the sequence of state numbers generated by the algorithm produces a power of 2 is when k is 1 (so that the exponent of 7 is 0), which only occurs if the exponent of 2 is a prime. A step-by-step explanation of Conway's algorithm can be found in Havil(2007).

^Gödel numbering cannot be directly used for negative integers, floating point numbers or text strings, although conventions could be adopted to represent these data types indirectly. Proposed extensions to FRACTRAN include FRACTRAN++ and Bag.