PhD
A pushdown automaton on one stack of bits, with an oracle that knows whether a piece of code halts.
Hakerh400, 2021 · Turing complete: unknown · ●●● hard · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
Hakerh400 made PhD in 2021. The name is short for Push halt Down automaton. There is one stack of bits with endless zeros under it, a loop, bit input and output, and one more instruction that asks whether some code would halt on the current stack. That code may not read, print or ask the oracle itself. The specification leaves the computational class open.
The machine
| Instruction | Does |
|---|---|
0 | Push a 0 |
~ | Invert the top bit |
* | Pop a bit; if it is 1, pop another and print it, else push the next input bit |
[...] | Pop a bit; while it is 1, run ... and pop again |
(...) | Push a 0 if ... would halt on the current stack; what ... does to the stack is undone |
Every other character is a comment. There is no push 1, so 0~ does it, 00~* prints a 0 and 0~0~* prints a 1. Input and output are bits, the characters 0 and 1. The program reads a 1 before each input bit and endless 0s after the last one, so a loop can tell where the input ends.
The oracle is exact. The code inside reads no input, so it is a deterministic pushdown automaton, and whether such a run halts can be decided. This implementation watches for the repeat that every endless run must make.
Example
The if-then-else prints 1011 on 0 and 001 on 1.
The if-then-else prints 1011 on 0 and 001 on 1.
The cat reads the 1 in front of a bit, then the bit, prints it and goes round while another 1 comes.
The oracle. 0~ puts a 1 on the stack. On it [0~] pops the 1 and pushes it back forever, while [] pops the 1 and then a 0 and stops. ~0~* then prints the top bit inverted, which is 1 when the oracle pushed its 0 and 0 when it did not.
The Hello World is 102 of those prints. Read eight to a character, least significant bit first, they spell Hello, World!, with the last two bits of !, both 0, left out.
Patterns it teaches
- Stack machines: one stack of single bits, and a loop that pops its own test.
Further
See also
Also in Turing tarpits
Write your own in Run Convert a program from PhD
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: phd.
Command line
shib run phd -e '*[0*0~*0*]' --input '1011'shib manual phdSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/phd.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org