Integer is a Turing-complete integer-rewriting language. In this article the term number means non-negative integer.
Overview
Source code consists of a single number (non-negative integer). Input is also a single number. We create the main integer based on the source code and the input string, then we rewrite the main integer until the program halts, and finally we extract the output (which is also a single number).
Rewriting rules
First, we define the following helper functions to better explain how rewriting rules work.
Helper functions
Initialization
Before the program starts, we need to initialize the main number. The main number is the number that we rewrite during the program execution. The main number is denoted by .
Let be the source code and let be the input. We define to be the smallest number such that
The main number is initialized to:
Iteration
In each iteration, perform these steps until the program halts.
First, define the following numbers for this iteration:
If , then halt the program. Otherwise, define the following additional numbers for this iteration:
Finally, define for the next iteration:
When the program halts, the output is equal to:
Examples
Some examples have line breaks that are added for readability. Remove all whitespace characters before running on the interpreter.
Cat
0
Output constant 0
6
Infinite loop
70
Decrement the input by 1
Zero stays zero.
1152939097062396182
Increment the input by 1
309485009821345068994351110
Divide the input by 2
Rounds down.
9173994463960286046443283581208347763213219903346576852191495713375665208318111329792696452604547948
433686
Multiply the input by 2
9497114518078914140546986369588496999097156574631296911920877900450323135960192181045144766093709453
5660978509666584894170779877915934578796002563275301898134356610994269775078331695294614185134944592
1381741652194842497242855742293284839300722078236358064095580372493289042985035188303215631822733149
7180199102013493466141117373148941557708613501987350894765422523106464063285476558402824777007651467
1555285154428308898797515506032945032564446854433015556686006511836076831543072383949092673469495604
008688522888758168991401457612222023033157506841822272418164027655084280135958
Calculate the number of binary ones in the base-2 representation of the input
The shortest known program is approximately . It is too large to be pasted here.
Interpreters
Interpreter