&brainfuck

From Esolang
Jump to navigation Jump to search

&brainfuck (pronounced "reference brainfuck") is a brainfuck variant discovered by User:Orby in May of 2020.

Model

&brainfuck uses a right-unbounded tape of unbounded non-negative cells. Decrementing a data pointer that is zero, decrementing a cell that is zero, and decrementing an indirection level that is zero all produce undefined behavior.

Commands

Command Action
> Increment the data pointer
< Decrement the data pointer
* Increment the level of indirection
& Decrement the level of indirection
[ If the cell pointed to by the data pointer is zero, jump after matching ]
] If the cell pointed to by the data pointer is non-zero, jump after matching [

The level of indirection begins at zero. At this point all commands behave normally. When the level of indirection is one, > becomes "Increment the cell pointed to by the data pointer". When the level of indirection is two, > becomes "Increment the cell pointed to by the cell pointed to by the data pointer", and so on. Therefore, + can be represented as *>& and - can be represented as *<&. Notice that [ and ] inherently contain one level of indirection, but their level of indirection is also increased with * and decreased with &.

Reversible variant

A reversible variant of &brainfuck can be achieved by altering the loop construct.

Command Action
[ If the cell pointed to by the data pointer is zero, jump after matching ]
] If the cell pointed to by the data pointer is zero, jump after matching [

To compute the inverse of a program, simply reverse the program string and replace characters according to the following table

Command Inverse
> <
< >
* &
& *
[ ]
] [

Converting from brainfuck

Brainfuck programs can trivially be converted to &brainfuck programs, but the converse is not true.

bf &bf
> >
< <
+ *>&
- *<&
[ [
] ]

See also