FRACTRAN

from Wikipedia, the free encyclopedia

FRACTRAN is a Turing-complete esoteric programming language developed by the English mathematician John H. Conway . A FRACTRAN program consists of a finite sequence of positive fractions. The name FRACTRAN is a play on words and refers to the programming language FORTRAN (FORmula TRANslation = formula translation) and the English word for fraction . FRACTRAN means something like FRACtion TRANslation = fractional translation.

Execute FRACTRAN

FRACTRAN, also called fraction game by Conway , is "played" as follows:

  1. A positive whole number as a starting number is multiplied by the fractions one after the other until the product is again a whole number. In this case, is replaced by and you start over with the new number.
  2. If none of the fractions produce an integer, the program or game ends.

FRACTRAN can also be described more formally, where the FRACTRAN program is the sequence generated and the set of all indices for which the product becomes an integer:

FRACTRAN generates a finite or also an infinite sequence of natural numbers. If the last fraction in the FRACTRAN program has a 1 as a denominator, the sequence of natural numbers is definitely infinite. If an earlier fraction in the FRACTRAN program has a 1 as its denominator, the subsequent fractions are never reached during multiplication and are therefore unnecessary for the program. However, FRACTRAN programs in which none of the denominators is a 1 can possibly run endlessly with certain inputs.

A first example

The short program

generates the sequence with the start number But what does this have to do with a program, why is the start number 72 and why does the program end?

A closer look at the first example

In order to better understand a FRACTRAN program, it makes sense to decompose the numbers of the generated sequence into prime factors:

We are now primarily looking at the exponents of the starting number as inputs into the program, so if we now look at the exponents of the generated sequence, we see that by multiplying twice with the first fraction, the exponent of 3 is reduced by 1 and the exponent of 5, which was originally 0, is increased by 1 until the exponent of 3 reaches the value 0. Since the next two numbers in the sequence, namely 200 and 80, cannot be divided by 3 but by 5, the second fraction now comes into play twice: the exponent of 2 is increased by 1 and the exponent of 5 is decreased by 1 until it too has reached the value 0. Since the exponents of 3 and 5 both have the value 0, neither of the two fractions leads to an integer during multiplication, the program ends and the exponent of 2 is the sum of the original exponents of 2 and 3.

In general, the above FRACTRAN program converts the starting number into the number . So it was an addition program. With the FRACTRAN program, however, this could have been shorter, especially since it only takes half as many steps to find a solution.

Further examples

The (a - b) program

The starting number is again where a should be greater than or equal to b. The generated sequence ends with

The 2a program

The starting number is The generated sequence ends with

The max (a, b) program

The starting number is After max (a, b) steps the generated sequence ends with The program works as follows: First, by multiplying by the first fraction, the values ​​of a and b are simultaneously reduced by 1, while c, which was 0 at the beginning, is increased by 1 until a or b equals 0. With the two fractions , the value of a or b, which was not yet 0, is now gradually brought to 0, while c continues to be increased by 1.

The max (a, b) program can be very easily rewritten to a min (a, b) program by changing the last two counters from 5 to 1.

The Fibonacci Program

The following FRACTRAN program calculates the nth Fibonacci number :

The starting number is The generated sequence ends with the number . So z. B. the starting number for the result , where 13 is the 7th Fibonacci number.

Conway's PRIMEGAME

The most famous FRACTRAN program is Conway's PRIMEGAME:

With the starting number , a sequence is generated that contains exactly the powers of two in the correct order, the exponent of which is a prime number . In other words, PRIMEGAME generates all prime numbers, but very slowly:

A Java program

The following Java program multiplies 5 by 2:

public class Fractran {
    public static void main(String[] args) {
        long N = 288;
        long[] zaehler = {455, 11, 1, 3, 11, 1};
        long[] nenner  = {33, 13, 11, 7, 2, 3};
        int i = 0, j;
        boolean halt = false;
        System.out.println(i + ": " + N);
        while (!halt) {
            j = 0;
            while (!halt && ((N*zaehler[j])%nenner[j] != 0)) {
                j++;
                if (j == zaehler.length) halt = true;
            }
            i++;
            if (!halt) {
                N = (N*zaehler[j])/nenner[j];
                System.out.println(i + ": " + N);
            }
        }
    }
}

Since N can become very large in the course of the program, it makes sense to expand the above program so that only the exponents of N are no longer processed, but only.

Individual evidence

  1. ^ JH Conway: FRACTRAN: A Simple Universal Programming Language for Arithmetic. In: T. Jeffrey C. Lagarias (Ed.): The Ultimate Challenge: The 3x + 1 Problem. American Mathematical Soc., 2010, ISBN 978-0-8218-4940-8 , pp. 249-264.
  2. Dimitri Hendriks: FRACTRAN , 2011 (PDF; 256 kB)
  3. ^ The On-Line Encyclopedia of Integer Sequences, episode A007542

literature

  • John Horton Conway : FRACTRAN: A Simple Universal Programming Language for Arithmetic. In: Thomas M. Cover , B. Gopinath: Open Problems in Communication and Computation. Springer-Verlag, 1987, ISBN 0-387-96621-8 , pp. 4-26.
  • Julian Havil: Amazed ?! : Mathematical proofs of incredible ideas. Springer-Verlag, Berlin / Heidelberg 2009, ISBN 978-3-642-32318-8 , pp. 155-170.
  • Dominic Olivastro: The Chinese Triangle: The trickiest riddles from 10,000 years. Zweiausendeins, Frankfurt 2006, ISBN 3-86150-764-1 , pp. 30-38.

Web links