Integer

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 ===
 \begin{align}
 f_1\left(x, y, z\right) &= \begin{cases}
 \left(y\mod x\right)+x\cdot\left(\left(z\mod x\right)+x\cdot f_1\left(x, \left\lfloor\frac yx\right\rfloor, \left\lfloor\frac zx\right\rfloor\right)\right), &y+z\neq0\\
 0, &y+z=0
 \end{cases}\\
 f_2\left(x, y\right) &= \begin{cases}
 \left(y\mod x\right)+x\cdot f_2\left(x, \left\lfloor\frac y{x^2}\right\rfloor\right), &y\neq0\\
 0, &y=0
 \end{cases}\\
 f_3\left(x, y\right) &= f_2\left(x,\left\lfloor\frac yx\right\rfloor\right)\\
 f_4\left(x, y\right) &= x^y-1\\
 f_5\left(x, y\right) &= \begin{cases}
 1+f_5(x,\left\lfloor\frac yx\right\rfloor), &y\not\equiv0\pmod x\\
 0, &y\equiv0\pmod x
 \end{cases}\\
 f_6\left(x, y, z\right) &= \begin{cases}
 f_6\left(x, f_3\left(x, y\right), z - 1\right), &z\neq0\\
 f_2\left(x, y\right), &z=0
 \end{cases}\\
 \end{align}
=== 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 n.
Let R be the source code and let I be the input. We define e>1 to be the smallest number such that
R\equiv0\pmod e
The main number is initialized to:
n=f_1\left(e,\left\lfloor\frac Re\right\rfloor, f_1\left(e, 0, f_4\left(e, I\right)\right)\right)
=== Iteration ===
In each iteration, perform these steps until the program halts.
First, define the following numbers for this iteration:
 \begin{align}
 a &= f_2(e, n)\\
 b &= f_2(e, a)
 \end{align}
If b=0, then halt the program. Otherwise, define the following additional numbers for this iteration:
 \begin{align}
 c &= f_3(e, a)\\
 d &= f_6(e, c, b - 1)\\
 g &= f_2(e, d)\\
 h &= f_3(e, d)\\
 i &= f_3(e, n)\\
 j &= f_2(e, i)\\
 k &= f_3(e, i)
 \end{align}
Finally, define n for the next iteration:
 n_\text{next} = \begin{cases}
 f_1\left(e, f_1\left(e, h, c\right), f_1\left(e, \left\lfloor\frac je\right\rfloor \cdot e + e - \left(j\mod e\right) - 1, k\right)\right), &g\equiv0\pmod4\\
 f_1\left(e, f_1\left(e, h, c\right), f_1\left(e, k, j\right)\right), &g\equiv1\pmod4\\
 f_1\left(e, f_1\left(e, h, c\right), f_1\left(e, j \cdot e, k\right)\right), &g\equiv2\pmod4\\
 f_1\left(e, f_1\left(e, f_3\left(e, h\right), c\right), f_1\left(e, \left\lfloor\frac je\right\rfloor, k\right)\right), &g\equiv3\pmod4\land j\not\equiv0\pmod e\\
 f_1\left(e, f_1\left(e, f_2\left(e, h\right), c\right), f_1\left(e, \left\lfloor\frac je\right\rfloor, k\right)\right), &g\equiv3\pmod4\land j\equiv0\pmod e
 \end{cases}
=== Extracting the output ===
When the program halts, the output is equal to:
f_5(e, f_3(e, f_3(e, n)))
== 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 1.6\cdot10^{342102016}. It is too large to be pasted here.
== Interpreters ==
Interpreter
Category:Languages
Category:Turing complete
Category:Implemented
Category:2020