User:H. H. P. M. P. Cole/Modulo 2 v2
Modulo 2 v2 is a programming language created by User:H. H. P. M. P. Cole. It is based off User:I am islptng's modification of the original language but with features present in the original, like multiple "codeblocks". This operates on an infinite array of constants/functions.
The infinite array is thus:
n₁ n₂ n₃ n₄ ... (Numbers) f₁ f₂ f₃ f₄ ... (Functions)
Symbols
Modulo 2 v2 uses the following symbols:
. ˈ | \ < > 0 1
Semantics
Variables are designated by . followed by an integer number of apostrophes (can be zero).
Polish notation is used for the | operator.
|ab
meansa NAND b
(the NAND is bitwise).\
separates codeblocks in the same 'program'.0
and1
make up constants in binary.<
and>
shift the input and output by 1 step left and right respectively.
Here is an example Modulo 2 v2 program: 1\10\||..'..\>.'.'
. This will show how a program is executed with example.
1. Start by loading all variables expressible by constants.
- 1.1. The variable
.
is given the number (if any) in the first position in the array. Here it is1
, so the infinite array becomes
1 0 0 0 (Numbers) ||..ˈ..ˈˈˈ >.ˈ.ˈ (Functions)
- 1.2. The variable
.ˈ
is given the number (if any) in the second position in the array. Here it is10
, so the infinite array becomes
1 10 0 0 (Numbers) ||..ˈ..ˈˈˈ >.ˈ.ˈ (Functions)
- 1.3. The variable
.ˈˈ
is given the number (if any) in the third position in the array, etc, etc, etc. Here there are no more constants, so we carry on.
2. Execute all functions from left to right. There is always a stray variable at the end of every codeblock, which signals the position of which to load the number in.
- 2.1. The function
||..ˈ..ˈˈˈ
means(n₁ NAND n₂) NAND n₁
and put the result in array position 3 (array positions are zero-indexed). Hence the array becomes
1 10 0 10 (Numbers) ||..ˈ..ˈˈˈ >.ˈ.ˈ (Functions)
- 2.2. The function
>.ˈ.ˈ
means to shift the number at array position 1 one bit to the right and put the result in position 1. Here we get:
1 1 0 10 (Numbers) ||..ˈ..ˈˈˈ >.ˈ.ˈ (Functions)
- 3. Redo the functions to infinity. (If there are no stray variables in a codeblock then output the output of that codeblock.) The second iterations of the function become:
1 0 0 1 (Numbers) ||..ˈ..ˈˈˈ >.ˈ.ˈ (Functions)
- Then the third iteration:
1 0 0 0 (Numbers) ||..ˈ..ˈˈˈ >.ˈ.ˈ (Functions)
- Then the fourth:
1 0 0 1 (Numbers) ||..ˈ..ˈˈˈ >.ˈ.ˈ (Functions)
It is clear we have reached an oscillation of period 2. The program repeats indefinitely in this oscillation of period 2.
Example program
Cat program
This is actually a number cat. Just put whatever number you want in X.
X
A program to add two numbers*
The numbers are X and Y.
X\Y\||.|..ˈ|.ˈ|..ˈ
Checking the parity of a number*
The number is X. The parity is 0 if the number is even and 1 if the number is odd.
X\||.|.<>.|<>.|.<>.
Finding the digits of a number in reverse in binary
X\||.|.<>.|<>.|.<>.\>..
Note that the first number is always decreasing until it hits 0.
* The numbers are actually not numbers in the ordinary sense. They are polynomials in GF(2).