BareMinimum

From Esolang
Jump to navigation Jump to search

BareMinimum is a programming language with only two operators: subtract and minimum.

Expressions

All expressions in BareMinimum are in prefix notation. There are two binary operators: - and +. - is the usual binary subtraction operator, and + returns the minimum of its arguments. Integer constants and variables are also supported. Spaces can be used to separate arguments

Statements

There are three kinds of statements in BareMinimum: variable, loop, and output.

Variables

Variables are defined using the = assignment operator like so: var = expr Variables can be accessed by simply putting their name.

Loop

Loops are done by typing a variable name, and an opening curly brace. Then enter some statements and a closing curly brace. For example:

x{
x = y
}

The variable's value will be queried each time the loop is run and if it equals zero the loop will end, otherwise the loop will repeat.

Output

Simply typing an expression without an equal sign will output the value of the expression.

Comments

A line starting with a space becomes a comment and is not executed.

Examples

Useful subexpressions

 x+y
z = -x-0y
 max(x,y)
z = -0+-0x-0y
 abs(x)
z = --0+0-0x+0x
 x == y (0 or 1)
z = +1--0+0-0-x y+0-x y

Minimization

Using the loops, the minimum operator can actually be implemented using the subtraction operator. (Prove it? That's, uh, left as an exercise to the reader.) Also, no literals are needed except the 1. Of course, comments can be removed. We can remove support for multiple operations on one line, and we're left with a fairly minimal version of this language. One other thing to do is combine the looping function with the subtraction function, producing an OISC. Replacing it with a "GOTO if nonzero" would work. This gives us an OISC where the operation is "subtract and jump if nonzero". Seems kinda similar to another OISC on this wiki...

Computational class

BareMinimum is Turing complete because you can implement a Minsky machine in it. The registers are variables, and we can test if they're zero using a loop that immediately breaks out of itself after running once, so we have an if statement. We can store the state in another variable and compare it to each value, running some code on a success. This also shows that we don't need the minimum operator.