LogStack
A stack of logical sentences. Every test asks whether the rest of the stack proves the one on top.
Silver, 2020 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Silver made LogStack in 2020. Each item on its stack is a sentence of propositional logic, built from 52 letters, a contradiction * and a tautology %. There are no numbers. A conditional pops a sentence and tries to prove it, with everything still on the stack as assumptions.
Read the story
So false and unprovable are not the same. p? on a stack that never mentions p prints no, though nothing said p was false. And a contradiction anywhere on the stack proves everything, after which every test passes.
The specification shows LogStack is Turing complete by translating 3-cell brainfuck into it, and adds that the logic is hardly needed. Three letters, %, /, $, @ and the loop are enough.
The machine
| Char | Does |
|---|---|
a to Z | Push an atom |
* % | Push a contradiction or a tautology |
& | ^ = | And, or, xor, if and only if of the top two |
: | Implies; ab: is a => b |
! | Not |
/ ; $ @ | Swap, duplicate, drop, move the top to the bottom |
? | Pop; print yes if the rest proves it, else no |
~ | Pop; if the rest proves it, swap the top two |
( ... ) | Loop while the popped sentence is proved |
. # | Halt; print the stack |
Each yes and no ends its line, and the letters of the input make the starting stack.
Example
ab: is a => b, and with a on the stack too, b follows.
ab: is a => b, and with a on the stack too, b follows. In the last one the stack holds a and not a, which proves b and anything else.
The truth machine from the specification takes its input as the starting stack, a single p for true. Read by these rules, the quoted parentheses inside its comments close its loop too early, so this version runs without them. On an empty stack it prints no once; with p it prints yes forever.
%/( ... ab)( ... ab)$ is an if-else. The a and b pushed at the end of each branch are not provable, so each loop stops after one pass.
Patterns it teaches
- Stack machines: with sentences instead of numbers.
- Turing completeness: reached through a 3-cell brainfuck.
Further
See also
Stack-based
Write your own in Run Convert a program from LogStack
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: logstack.
Command line
shib run logstack -e 'p?'shib manual logstackSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/logstack.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org