Real Brainfuck

From Esolang
Jump to navigation Jump to search

Real Brainfuck is a brainfuck variant that operates on the real-valued range {0, 1}. The tape starts with all cells set to 0.5. It also has a stack. This is a more usable version of an esolang i designed in the past.

Instructions

It has the following instructions:

Instruction Explanation
< Move data pointer left on tape
> Move data pointer right on tape
0 Set current cell c to (c + 0) / 2
1 Set current cell c to (c + 1) / 2
N Set current cell c to 1 - c
[ Randomly choose between 0 and 1 with probability c. if zero jump past matching ]
] Randomly choose between 0 and 1 with probability c. if not zero jump back to matching [
^ Push cell data to stack
V Pop item from stack to current cell
& Pops top two items on the stack, multiplies them together, and pushes the result back
X Pops top two items on the stack, averages them together, and pushes the result back
, Obtains real-valued or binary input from an implementation-dependent source and sets the cell to that value
. Outputs current real value
q Outputs either 0 or 1 with probability c

Real Brainfuck 2 Variant: operates on all complex real numbers. It has support for abnormal probabilities and the following additional Instructions:

Instruction Explanation
+ c = c + 1
- c = c - 1
; c = c-th root of c
\ pop two items from stack, a & b, and push c: c = loga(b)
/ c = sin(c)
z c = c ^ pi
: pop two items from stack, a & b, and push c: c = a ^ b
f c = c ^^ 2 (c tetrate 2)
e set cell to transcendental number e
p set cell to transcendental number pi
! c = c! (multiplication factorial)
? c = c? (addition factorial)
$ c = c$ (exponential factorial)
{ begin ()infinite loop (finishes in finite time, hyperloop)
} end ()infinite loop (finishes in finite time, hyperloop)

Examples

Cat program

The following numeric cat may randomly terminate for an input less than one (1.0):

,.[,.]

Truth-machine

A truth-machine is implemented in this program:

,.[.]

Multiples of π (pi)

This program prints the first five multiples of constant π (pi):

+++++
>+z
<[>.+<-]

Interpreter

  • Common Lisp implementation of a subset of the Real Brainfuck programming language. While both real- and complex-valued tape cells are supported, certain more complex operations, in particular the factorial functions, retain the more common integer behavior.