ArticleslgStudy

mathematics

FRACTRAN

FRACTRAN is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand FRACTRAN rather than just read about it. In short: FRACTRAN is a Turing-complete esoteric programming language invented by the mathematician John Conway. A FRACTRAN program is an ordered list of positive fractions together with an initial positive integer input n.

FRACTRAN — main illustration
FRACTRAN — illustration

Key takeaways

  • FRACTRAN belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect FRACTRAN to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of FRACTRAN from memory before moving on to harder problems.

Reference excerpt

FRACTRAN is a Turing-complete esoteric programming language invented by the mathematician John Conway. A FRACTRAN program is an ordered list of positive fractions together with an initial positive integer input n. The program is run by updating the integer n as follows:

for the first fraction f in the list for which nf is an integer, replace n by nf repeat this rule until no fraction in the list produces an integer when multiplied by n, then halt. The name FRACTRAN is a portmanteau of "fraction" and the programming language FORTRAN. Conway 1987 gives the following FRACTRAN program, called PRIMEGAME, which finds successive prime numbers: (1791,7885,1951,2338,2933,7729,9523,7719,117,1113,1311,152,17,551) Starting with n = 2, this FRACTRAN program generates the following sequence of integers:

2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290, 770, … (sequence A007542 in the OEIS), i.e. the sequence of PRIMEGAME numbers After 2, this sequence contains the following powers of 2 in order: 22=4,23=8,25=32,27=128,211=2048,213=8192,217=131072,219=524288,… (sequence A034785 in the OEIS) The exponent part of these powers of two are primes, 2, 3, 5, etc.

Understanding a FRACTRAN program 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. 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 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: f1=2120=3×722×51 tests v2 and v5. If v2 ≥ 2 and v5 ≥ 1, then it subtracts 2 from v2 and 1 from v5, and adds 1 to v3 and 1 to v7. For example: 60⋅f1=22×31×51⋅3×722×51=32×71=63 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 (a fraction with a denominator of 1) that is placed after other instructions that test a particular variable.

Creating simple programs

Addition The simplest FRACTRAN program is a single instruction such as (32) This program can be represented as a (very simple) algorithm as follows:

Given an initial input of the form 2a × 3b, this program will compute the sequence 2a − 1 × 3b + 1, 2a − 2 × 3b + 2, and so on, until eventually, after a steps, no factors of 2 remain and the product with ⁠3/2⁠ no longer yields an integer; the program then stops with a final output of 3a + b. It therefore adds the two integers a and b together.

Multiplication 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 2a × 3b and produce 5ab:

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: (45533,1113,111,37,112,13) With input 2a × 3b this program produces output 5ab.

Subtraction and division In a similar way, we can create a FRACTRAN "subtractor", and repeated subtractions allow us to create a "quotient and remainder" algorithm as follows:

Writing out the FRACTRAN program, we have: (9166,1113,133,8511,57119,1719,1117,13) and input 2n × 3d × 11 produces output 5q × 7r where n = qd + r and 0 ≤ r < d.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with FRACTRAN

Start with the simplest possible case. Write down what FRACTRAN claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to FRACTRAN before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about FRACTRAN ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of FRACTRAN

In research
FRACTRAN appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses FRACTRAN in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
FRACTRAN is common in secondary-school and first-year university syllabi. It links to neighbouring topics Esoteric programming languages, Models of computation, Recreational mathematics, so understanding it makes those chapters shorter.
In everyday life
Look for FRACTRAN outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “FRACTRAN” →

How to study FRACTRAN in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what FRACTRAN means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain FRACTRAN out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is FRACTRAN in simple terms?

FRACTRAN is a Turing-complete esoteric programming language invented by the mathematician John Conway. A FRACTRAN program is an ordered list of positive fractions together with an initial positive integer input n.

Why does FRACTRAN matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study FRACTRAN?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on FRACTRAN.

Tags

  • Esoteric programming languages
  • Models of computation
  • Recreational mathematics

Keep exploring