Heapfuck is a brainfuck like Esolang. It's goal is to
be a brainfuck where the environment is a binary heap
instead of a list/array.
The language's lexic and syntax are very similar to brainfuck.
Heapfuck also supports a few instructions to make manipulating a heap easier/possible.
Some brainfuck instructions are also redefined to make sense
in the context of a heap (cf documentation of ,
, >
and
<
)
The environment of heapfuck is a binary heap. At the beginning of the program, the heap is empty. The maximal size of the heap is theoretically infinite. Each node of the heap contains a signed integer. Note that the structure of the heap is always maintained and that the heap is updated after each instruction.
heapfuck accepts brainfuck like instruction adapted to the binary heap structure. The behavior of some bf-like instruction is changed to be more suited for heap manipulation. Noe that after every instruction the environment will restructure itself to remain a binary heap. If the heap is empty, every instruction other than the creation of nodes will be ignored. NB: Every character that isn't an instruction is ignored.
Command | Description |
---|---|
% |
Initialises a node in the heap at 0 |
, |
Reads a character and initialises a node in the heap at the character's value |
< |
moves the node pointer to the left child of the current node if it exists |
> |
moves the node pointer to the right child of the current node if it exists |
^ |
moves the node pointer to the parent of the current node if it exists |
! |
removes the node under the pointer from the heap |
+ |
increments the node under the pointer by 1 |
- |
decrements the node under the pointer by 1 |
[ |
jumps past the matching ] if the value of the node under the pointer is 0 |
] |
jumps back to the matching [ if the value of the node under the pointer is nonzero |
. |
prints the value of the node under the pointer as a char |
: |
prints the value of the node under the pointer as a decimal int |
♯ |
prints the heap as an array as well as informations on the heap (size, number of elements, index of node pointer) |
The general goal of this proof is to define a subset of heapfuck behaving like brainfuck. We will not map the I/O instruction of brainfuck because they are not necessary for turing completness. The self preserving properties of a binary heap makes the behavior of the data structure hard to predict. It is thus important to structure the heap in a way that makes it possible to emulate brainfuck (or P'' for that matter).
-
and +
operators
trivially behave the
same as the heapfuck ones in this context (as long as we assume that you don't overflow the
cell's value, in order to prevent that we could assume that the negative cells are set to an
arbitrary low value and the positive ones to an arbitrary high one).>
and <
instructions. This is where the Tnodes will come in handy.
We assume that the pointer is at an arbitrary Tnode (this allows to emulate the infinite tape)
In order to reach the next Tnode the Heapfuck sequence of instruction will ALWAYS be
^><
this sequence of instruction allows us to emulate the brainfuck
>
instruction.^^<
. This thus emulates the brainfuck
<
instruction.brainfuck | heapfuck equivalent |
---|---|
+ |
+ |
- |
- |
[ |
[ |
] |
] |
> |
^>< |
< |
^^< |
the idea of this proof was found by Pacidus