We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.
Varphi
| Paradigm(s) | Turing machine, automata |
|---|---|
| Designed by | Hassan El-Sheikha |
| Appeared in | 2025 |
| Computational class | Turing-complete |
| Major implementations | Varphi Interpreter (vpi), Varphi-to-Python Compiler (vp2py) |
Varphi is a domain-specific esoteric programming language created by Hassan El-Sheikha in 2025. It is designed to define, simulate, and study Turing machines and finite automata using code rather than visual diagrams or traditional state tables. It brings modern software engineering concepts to theoretical computation, including pattern matching, native multi-tape support, and interactive debugging capabilities.
Syntax
A Varphi program describes the state transition diagram of a Turing machine. Execution begins at the state of the first transition line in the file. The modern syntax is line-oriented, where each transition line must contain exactly five components:
<Current State> <Read Tuple> <Next State> <Write Tuple> <Shift Tuple>
Tuples are enclosed in parentheses, and the dimension of the tuples determines the number of tapes (k) the machine operates on.
- Literals: Represent exact Unicode characters (e.g.
0,a) or hexadecimal keys (e.g.0x2C). - BLANK: A built-in keyword representing an empty tape cell.
- Variables: Prefixed with a
$(e.g.,$x), these allow pattern matching. When read, a variable binds to the symbol under the tape head. When written, it evaluates to that bound symbol. Variables are local to the transition line they appear in. - Shift directions: Dictate head movement using the context-specific keywords
LEFT,RIGHT, orSTAY.
If multiple transitions match a state, Varphi uses a specificity engine to prioritize transitions with the fewest unique and total variables (favoring exact literal matches over catch-all variables). If ties occur, the machine exhibits nondeterministic branching.
Legacy syntax (v1)
In its initial v1 release, Varphi was restricted to defining standard unary Turing machines with a single two-way infinite tape. The blank symbol was denoted by 0. Transition rules were strictly positional without tuples, specifying five components per line: the current state, the symbol at the current tape cell, the next state, the symbol to write at the current tape cell, and the head movement (L or R).
Example of a v1 addition-by-one machine:
q0 1 q0 1 R q0 0 q1 1 L
This legacy format was completely overhauled in v2 to support multi-tape algorithms and pattern matching.
Examples
Binary incrementer
This single-tape machine takes a binary number and adds 1 to it (e.g. 1011 becomes 1100).
// Step 1: Move to the far right of the string start (0) start (0) (RIGHT) start (1) start (1) (RIGHT) start (BLANK) carry (BLANK) (LEFT) // Step 2: Perform the addition carry (1) carry (0) (LEFT) carry (0) halt (1) (STAY) carry (BLANK) halt (1) (STAY)
Multi-tape equality tester
This 2-tape machine compares two strings and determines if they are identical.
// Case 1: Both characters match // Specificity: ($x, $x) uses 1 unique variable. compare ($x, $x) compare ($x, $x) (RIGHT, RIGHT) // Case 2: Both characters are BLANK (strings are equal) compare (BLANK, BLANK) accept (BLANK, BLANK) (STAY, STAY) // Case 3: Mismatch. // Specificity: ($x, $y) uses 2 unique variables. // This catch-all rule only runs if ($x, $x) fails to match. compare ($x, $y) reject ($x, $y) (STAY, STAY)
Implementations
The official compiler toolchain is written in Python. The core is the Varphi Interpreter (vpi), a CLI compiler driver that parses .vp files, compiles them to Python intermediate representations via the vp2py backend, and executes them. It includes a built-in step-by-step debugger and supports the Debug Adapter Protocol (DAP) via vp2pydap for direct integration with the Varphi Visual Studio Code extension.