esolang

Hypercube

One cube of bits, two operations, no variables and no branches. A test is a NAND that skips work.

Alex Meiburg, 2011 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 13 known programs · Test method

Run it

Expected: 11010000

The idea

Alex Meiburg made hypercube in 2011. The memory is one cube of bits with n inds, an ind being one dimension, so it holds 2 to the n bits. Only two operations change it. = copies the cube into a new first dimension and @ NANDs the two halves together. NAND is enough for every Boolean function, and recursion makes the language Turing complete.

Read the story

There is no if. The only tests are a speed rule and a failure. In @(X,Y) the right part is skipped when the left part gives only false bits, because NAND with false is always true. And a block can catch a failure, which is how a loop over a cube of unknown size ends.

The machine

A program runs from right to left, as function composition does.

ProgramDoes
=Copy; the cube gets one ind more and both halves equal the old cube
@NAND the two halves; one ind less
(A,B)Run A on the left half and B on the right half, then join them
[BODY,HANDLER]A block; if BODY fails, HANDLER runs on the block's input
# #&Run this block again, or the block one level out
NAME := PROGRAMName a program for other lines to use

A failure is @ or a split on a cube of 0 inds, or a split whose two halves come back with a different number of inds. The IO interface, which runs the program again and again to read and write bytes, is not built. A program takes a cube in the specification's own notation as its input, 1101 being the cube with left half 11 and right half 01, and prints the cube it ends with.

Example

This program doubles a cube and puts the old bits in the low half.

This program doubles a cube and puts the old bits in the low half. Its own words are (,FALSE)= on 1101 gives 11010000.

@= is NOT. It copies every bit and NANDs each bit with its copy.

Expected: 0010

ALL ANDs the two halves and calls itself on what is left. On a cube of 0 inds @ fails, the empty handler gives the bit back, and each level copies it out again. One 0 anywhere makes it 0 everywhere.

Expected: 0000

The XOR is AND (OR, NAND) =. It runs on the halves 0011 and 0101.

Expected: 0110

Patterns it teaches

  • Combinators: copy and NAND, composed and split, build every gate.
  • Turing completeness: a cube that copies itself grows without bound, and a failure ends the recursion.

Further

Functional paradigm

Write your own in Run Convert a program from Hypercube

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: hypercube.

Command line

shib run hypercube -e '@=' --input '1101'
shib manual hypercube

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/hypercube.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org