FALSE

From Esolang
Jump to: navigation, search

FALSE (named after the author's favourite truth value) is an early Forth-like esoteric programming language invented by Wouter van Oortmerssen in 1993, with the goal of creating a powerful (and obfuscated) language with as small a compiler as possible. The original compiler is 1024 bytes, written in 68000 assembler. FALSE inspired the prominent esoteric languages Brainfuck and Befunge, among other languages.

Despite the small compiler size FALSE has a lot of features. A stack is used extensively, but there are also a few variables (characters a-z). FALSE has also lambda functions, ability to do arithmetics, some stack functions, means of doing if and while structures, and input/output support. Also, comments can be used.

Commands[edit]

Literals

  • 123 put integer onto the stack
  • 'c put character code onto the stack

Stack

  • $ DUP
  • % DROP
  • \ SWAP
  • @ ROT
  • ø PICK (dup the nth stack item)

Arithmetic

  • +
  • -
  • *
  • /
  • _ negate (negative numbers are entered "123_")
  • & bitwise AND
  • | bitwise OR
  • ~ bitwise NOT

Comparison (false is zero, true is all bits set (-1 or ~0) so that bitwise operators may be used)

  • > greater than
  • = equals

Lambdas and flow control (tests are for non-zero)

  • [...] define and put a lambda onto the stack
  • ! execute lambda
  • ? conditional execute: condition[true]?
    • if-else can be expressed as: condition$[\true\]?~[false]?
  • # while loop: [condition][body]#

Names

  • a-z put a reference to one of the 26 available variables onto the stack
  • : store into a variable
  • ; fetch from a variable

I/O

  • ^ read a character (-1 for end-of-input)
  • , write a character
  • "string" write a string (may contain embedded newlines)
  • . write top of stack as a decimal integer
  • ß flush buffered input/output

Other

  • {...} comment
  • ` compile short as 68000 machine instruction in the original Amiga FALSE implementation
  • whitespace is ignored, may be needed to separate consecutive integers

Computational Class[edit]

Even assuming as usual that all memory size limits of the implementation are ignored, proving Turing-completeness of FALSE is subtle, because FALSE has no way to change items deep in the stack without popping most of those above, nor a way to construct new functions.

However, FALSE is indeed Turing-complete, as the command subset $%\[]! is equivalent to the Underload command subset :!~()^ which is Turing-complete (% is optional but convenient). The construction there essentially uses the call stack as an extra stack to be able to implement the tape of a Turing machine.

Other strategies for showing Turing-completeness rely on also having unbounded integers:

It might be possible to use the command ø to copy elements from arbitrarily deep in the stack. Rather than changing the original contents of the stack, it is possible to create a complete, but slightly modified copy of the stack above the old one, at least if it is formatted suitably. This is enough to simulate changing the stack, and so give Turing completeness, but only if ø can be given arbitrarily large arguments, which requires unbounded integers on the stack.

In False dialects which use unbounded integers, there is another way to demonstrate Turing completeness, via unlimited register machines. Since False allows full access to the top three stack positions, these can be used to simulate a register machine with 2 registers. It was shown by Minsky (see for instance wikipedia) that 2-register unlimited register machines are Turing complete. Note however that the False specification states that "all variables (and also stack-items) are 32bits"; interpreters adhering to this cannot simulate an unlimited register machine using only three stack positions.

External resources[edit]