Emanator
| Paradigm(s) | Imperative |
|---|---|
| Designed by | User:Hakerh400 |
| Appeared in | 2023 |
| Computational class | Turing complete |
| Major implementations | Implemented |
| File extension(s) | .txt |
Emanator is an esolang invented by User:Hakerh400 in 2023.
Overview
Source code consists of integers separated by dots.
Memory consist of a single tape, which can be represented as a function Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle f:\mathbb N\mapsto\mathbb Z} . All cells are initially Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle 0} , except the cells at addresses Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle 0,\dots,n-1} , which contain the source code, where Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle n} is the length of the source code. Here, by source code we mean the list of integers parsed from the source code and not the literal source code string.
Memory contains the entire program state. There are no external registers such as instruction pointer or data pointer.
If we want to access cell at address Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle i} , then there are two cases:
- If Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle i\ge0} , then we access cell Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle i} directly.
- Otherwise, let Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle j} be the value from cell Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle -i-1} . The result of accessing Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle i} is the result of accessing Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle j} . If accesses form a loop, then we either read from input (if we want to read a value), or write to the output (if we want to write a value).
Perform the following algorithm until the program outputs number . Let ip be the value from cell Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle 0}
. Let dest be the value from cell ip (keep in mind indirect addressing explained above). Let op1 be the value from cell ip + 1 and op2 be the value from cell ip + 2. Write value ip + 3 to cell Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle 0}
and then write value op1 - op2 to cell dest.
If anything in this explanation is unclear, see the implementation for details.
Examples
Cat program
3.0.3.-4.-5.1.0.2.1
Explanation. The cell Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle 0}
contains value Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle 3}
. It represents the initial value of ip (instruction pointer).
Each "instruction" is 3 cells long. Our first instruction is -4 -5 1. In pseudocode it means mem[-4] = mem[-5] - mem[1]. Of course, since memory contains only positive addresses, Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle -4}
and Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle -5}
represent indirect addressing, so we are effectively addressing Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle -(-4)-1=3}
and Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle -(-5)-1=4}
, respectively. However, since mem[3] = -4 and mem[4] = -5, we have a cycle in both cases. We first evaluate operands, so mem[-5] resolves to the next character code from the input string. The second operand mem[1] directly resolves to 0. The result is C - 0 = C, where C is the next character code from the input (because the indirect addressing formed a cycle at mem[-5]). Finally, since mem[-4] also forms a cycle, we output the result C directly to the output stream.
Instruction pointer gets incremented by Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle 3}
, so it becomes Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle 6}
. The next "instruction" is 0 2 1. It means mem[0] = mem[2] - mem[1] = 3 - 0 = 3, so we write value Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle 3}
to the instruction pointer, effectively jumping back to the first instruction. We perform these steps until we read integer Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle 0}
(the end of input stream) and output it, which terminates the program.
Kolakoski sequence
1.27.26.22.1.1.27.-2.26.22.1.1.24.-14.25.-7.6.6.24.26.24.26.0.4.-1.49.0
The instruction pointer follows a simple loop, increasing by 3 repeatedly up to 22, where it gets reset back to 1. This means that the program simply performs the same writes over and over:
mem[mem[1]] = mem[26] - mem[22] mem[1] = mem[1] - mem[mem[6]] mem[-2] = mem[26] - mem[22] mem[1] = mem[1] - mem[24] mem[-14] = mem[25] - mem[-7] mem[6] = mem[6] - mem[24] mem[26] = mem[24] - mem[26] mem[0] = mem[4] - mem[-1]
Making things a bit clearer by giving mem[1], mem[6], and mem[26] names (back, front, and current respectively), resolving negative addresses, and replacing constants, we get the following:
mem[back] = current - 0 back = back - mem[front] mem[back] = current - 0 back = back - -1 OUTPUT = 49 - mem[front] front = front - -1 current = -1 - current ip = 1 - 0
This basically forms a queue where a 1 in the Kolakoski sequence is represented as a 0, and a 2 is represented as a -1.
- Firstly,
currentgets placed at the back of the queue. - Then, to simplify control flow, the front of the queue is subtracted from
back.- If the front of the queue is
0(representing a 1), the back of the queue stays in place. - However, if the front of the queue is
-1(representing a 2), the back of the queue is incremented to point to the next memory cell.
- If the front of the queue is
- Depending on whether or not the back of the queue was moved,
currenteither gets redundantly written to the exact same position, or it gets enqueued a second time. - In either case, the back of the queue is incremented to point to the next memory cell to prepare for the next iteration.
- The character code
49 - mem[front]is outputted, which is either49or50as appropriate. - The front of the queue is incremented to point to the next memory cell, effectively dequeuing from the queue and advancing the sequence by one digit.
currentis flipped, becoming-1if it was previously0and0if it was previously-1.- Finally, the instruction pointer is set to
1, completing the loop.
Computational class
This language is Turing-complete. We leave to the readers to figure out why.