esolang

Unary

One symbol. A program is a string of zeros, and only how many there are matters. cat is 56,623 zeros; Hello World needs more zeros than there are atoms in the universe.

Lode Vandevenne, 2005 · Turing complete: with unbounded memory · ●○○ easy · esolangs.org

Tested with 1 known program · Test method

Run it

Expected: 56623

The idea

How few symbols can a language have? Brainfuck needs eight, Ook! three. Lode Vandevenne's Unary needs one.

Read the story

The trick: any Brainfuck program can be written as a number, and any number can be written in unary (as that many marks). So a Unary program is a pile of 0s, and its meaning is its length.

It is perfectly well-defined and completely impractical. That is the lesson. "Minimal alphabet" and "minimal language" are different things: Unary has the smallest alphabet possible and the most bloated programs imaginable.

The machine

Brainfuck's machine. To find the Brainfuck program inside a Unary program of N zeros:

  1. Write N in binary.
  2. Drop the leading 1. (It is there so that leading > commands, coded 000, are not lost.)
  3. Read the rest three bits at a time:
Bits000001010011100101110111
Brainfuck><+-.,[]

Lengths whose binary form does not split this way are not programs at all.

Example

cat is ,[.,] in Brainfuck.

cat is ,[.,] in Brainfuck. Encode it:

1   101  110  100  101  111      the marker bit, then , [ . , ]
= binary 1101110100101111 = 56,623

So cat in Unary is a file of 56,623 zeros. This implementation takes the number directly with --mode length, or a real file of zeros, and --mode encode encodes a Brainfuck program.

Expected: hi there
Expected: 6071614181345224867348

The last one prints A. Its Unary form is about 6 × 10²¹ zeros, several zettabytes. The Hello World from the Brainfuck page encodes to a 96-digit number of zeros. There are only about 10⁸⁰ atoms in the observable universe.

Patterns it teaches

  • Encoding tricks: the extreme case. Every program is a natural number (Gödel numbering), and the language just writes that number in the dumbest possible way. Lenguage takes the same idea one step further.
  • Turing completeness: Unary is exactly as powerful as Brainfuck. Power does not care about program size, only about what can be expressed at all.

Try this

  1. Encode +. by hand and check with -c. How many zeros?
  2. Which is the shortest Unary program that prints anything at all?
  3. Find two Unary programs whose lengths differ by one and whose Brainfuck programs differ in more than one command.

Further

Unary builds on Brainfuck.

Zero-dimensional languages

Brainfuck equivalents

Write your own in Run Convert a program from Unary

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run unary program.txt --input 'hi there'

The program is long; save it as program.txt first.

shib manual unary

Source

Module
langs/museum/ports.js
Interpreter
langs/museum/unary.js, langs/common.js

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

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