Divmeq: Difference between revisions
I formally add a new case for A == 0 |
|||
Line 4: | Line 4: | ||
Divmeq has a single accumulator, <code>x</code>. Lines in Divmeq have two parameters, <code>A</code> and <code>B</code>. |
Divmeq has a single accumulator, <code>x</code>. Lines in Divmeq have two parameters, <code>A</code> and <code>B</code>. |
||
If x is divisible by A, divide X by A and jump to line B. Else, move 1 line forward. |
''If x is divisible by A, divide X by A and jump to line B. Else, move 1 line forward.'' |
||
There is 1 exception to this rule, the special case that A == 0. |
|||
''If the line number is even, find 2 ** x and jump to line B. If the line number is odd, if x is positive but not 1, find the binary log of x and move 1 line forward, else jump to line B.'' |
|||
Line numbers start at 0 and increment by 1 for each line in the program. If the line number is greater than the length of the program, halt. The line number is generally omitted. |
Line numbers start at 0 and increment by 1 for each line in the program. If the line number is greater than the length of the program, halt. The line number is generally omitted. |
||
Line 26: | Line 30: | ||
==Implementations== |
==Implementations== |
||
The following Python script is an interpreter. |
The following Python script is an interpreter. |
||
<pre> |
<pre>import math |
||
prgm = [[]] |
|||
prgm.pop(0) |
prgm.pop(0) |
||
while True: |
while True: |
||
Line 43: | Line 48: | ||
global x |
global x |
||
global inst |
global inst |
||
⚫ | |||
if x % A < 1e-16 or x % A > (A - 1e-16): # Hinders TC, but fixes issues with floats |
if x % A < 1e-16 or x % A > (A - 1e-16): # Hinders TC, but fixes issues with floats |
||
⚫ | |||
x /= A |
|||
inst = B |
|||
else: inst += 1 |
|||
else: |
|||
if inst % 2 == 0: |
|||
x = 2 ** x |
|||
inst = B |
|||
else: |
|||
if x > 0 and x != 1: |
|||
x = math.log2(x) |
|||
inst += 1 |
|||
else: inst = B |
|||
inst = 0 |
inst = 0 |
||
while inst < len(prgm): |
while inst < len(prgm): |
Revision as of 22:03, 26 July 2024
Divmeq (derived from 'DIVide and branch, if Modulo EQuals 0') is a one-instruction Turing-complete esoteric programming language created by User:TheCanon2.
Commands
Divmeq has a single accumulator, x
. Lines in Divmeq have two parameters, A
and B
.
If x is divisible by A, divide X by A and jump to line B. Else, move 1 line forward.
There is 1 exception to this rule, the special case that A == 0.
If the line number is even, find 2 ** x and jump to line B. If the line number is odd, if x is positive but not 1, find the binary log of x and move 1 line forward, else jump to line B.
Line numbers start at 0 and increment by 1 for each line in the program. If the line number is greater than the length of the program, halt. The line number is generally omitted.
Divmeq accepts a numeric input at the beginning of a program, which is written to the accumulator. The accumulator is set to 1 if no input is given.
Examples
Truth machine
0: 2 2 1: 1 1
This halts if 0 and doesn't halt if 1.
XKCD Random Number
0: 0.25 1
Sets the accumulator to 4.
Computational class
Divmeq is Turing-complete for it can simulate a one-register Minsky machine.
0: 1/n 1
Multiply by n
0: n A
Check if x is divisible by n, and if so, divide by n and jump to A
Implementations
The following Python script is an interpreter.
import math prgm = [[]] prgm.pop(0) while True: line = input('%s: ' % len(prgm)) # Does not accept line numbering if line != "eof": line = list(line.split(" ")) prgm.append([float(line[0]), int(line[1])]) else: break init = input('>i ') # Grabs user input if init == "": x = 1 else: x = float(init) # Executes the program def divmeq(A, B): global x global inst if A != 0: if x % A < 1e-16 or x % A > (A - 1e-16): # Hinders TC, but fixes issues with floats x /= A inst = B else: inst += 1 else: if inst % 2 == 0: x = 2 ** x inst = B else: if x > 0 and x != 1: x = math.log2(x) inst += 1 else: inst = B inst = 0 while inst < len(prgm): divmeq(prgm[inst][0], prgm[inst][1]) print(x, end=" ")
This interpreter uses the symbol eof
to mark the end of a program.
Any subsequent parameters after A and B are ignored, allowing for comments. This interpreter also prints the value of the accumulator after every instruction for ease of programming.