Varphi
A Turing machine written as code, with pattern matching and as many tapes as the tuples are long.
Hassan El-Sheikha, 2025 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
Hassan El-Sheikha made Varphi in 2025 to write Turing machines as text instead of diagrams or state tables. Each line is one arrow of the diagram. In a state, reading these symbols, go to that state, write these symbols and move the heads like so.
Read the story
Two things make it more than a plain table. The tuples can hold more than one symbol, one per tape, so a line in a two-tape machine reads and writes both tapes at once. And a symbol can be a variable such as $x, which matches whatever is under the head. ($x, $x) matches only when both tapes show the same symbol, so one line can stand for a whole family of rules.
The machine
| Part | Means |
|---|---|
start (1) start (1) (RIGHT) | State, read tuple, next state, write tuple, shift tuple |
0 a 0x2C | A literal symbol, by itself or as a hexadecimal key |
BLANK | The empty cell |
$x | A variable; binds to what is read, writes it back |
LEFT RIGHT STAY | How each head moves |
The machine starts in the state of the first line and halts when no line fits. When several lines fit, the most specific wins, the one with the fewest distinct variables and then the fewest variables. Tape n starts as line n of the input. When the machine halts, the run prints each tape and then the state it halted in.
The first Varphi had one tape, plain lines of five words, 0 as the blank and moves L and R. Programs in that form still run.
Example
The binary incrementer walks right to the end, then carries back to the left.
The binary incrementer walks right to the end, then carries back to the left.
The equality tester has two tapes. ($x, $x) uses one variable and ($x, $y) uses two, so the second line only runs when the first does not fit.
The first form adds one to a number in unary.
Patterns it teaches
- Turing completeness: a Turing machine with any number of tapes.
See also
Nondeterministic
Cell-based
Write your own in Run Convert a program from Varphi
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: varphi.
Command line
shib run varphi -e 'q0 1 q0 1 R
q0 0 q1 1 L' --input '111'shib manual varphiSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/varphi.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org