Palace
Peano arithmetic as a programming language. The only constant is 0 and the only operation is one more.
Hakerh400, 2020 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 9 known programs · Test method
Run it
The idea
Hakerh400 made Palace in 2020. A program is a list of functions on the natural numbers, each written as cases. An argument is matched against 0, a name, or + in front of either, so a case for 0 and a case for +y split a number the way a proof by induction does. There is no addition built in. The specification defines it, and on top of it subtraction, multiplication, division, powers and roots.
Read the story
The last worked examples are the Ackermann and Sudan functions. Both always halt, and neither is primitive recursive.
The machine
| Form | Means |
|---|---|
f(x, 0) = x | One case of f, for a second argument of 0 |
+x | One more than x. As an argument it fits any number above 0 and names the one below |
0 | The only constant |
f(a, b) | A call |
The first function in the source is the main one. It takes the numbers of the input, exactly as many as it has arguments, and its result is printed. A call works out its arguments first and takes the first case that fits.
Example
Addition counts the second number down into the first.
Addition counts the second number down into the first.
The Ackermann function. A(2, 3) is 9 and A(3, 3) is 61.
Division counts z up from 0 until y times z+1 is more than x, and then gives z. It needs the specification's own leq, isZero, sub, pred, mul and add.
Patterns it teaches
- Turing completeness: recursion with no bound, like
div1counting upward, takes it past primitive recursion.
Further
See also
Also in Functional and concatenative
Write your own in Run Convert a program from Palace
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: palace.
Command line
shib run palace -e 'succ(x) = +x' --input '41'shib manual palaceSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/palace.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org