heapfuck : Documentation

Summary:


I: Introduction

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 <)


II: Environment

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.


III: Instructions

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)

IV: turing completness

Attempt at a proof by reduction of heapfuck's turing completness :

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).

Using a similar construction (with Tnodes and constrained movement) we could emulate any brainfuck derivative ( by adding other constraints if necessary).


illustration of the general structure of the heap used for this proof

brainfuck heapfuck equivalent
+ +
- -
[ [
] ]
> ^><
< ^^<

the idea of this proof was found by Pacidus