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.
Relations
| Paradigm(s) | Declarative |
|---|---|
| Designed by | User:Hakerh400 |
| Appeared in | 2026 |
| Computational class | Turing complete |
| Major implementations | Implemented |
| File extension(s) | .txt |
Relations is an esolang invented by User:Hakerh400 in 2026.
Overview
There is a ternary relation R on natural numbers. It can be seen as a set of ordered triples of natural numbers. The program establishes patterns for synthesizing new members of the relation R (adding new triples to the set R).
When program starts, relation R contains triples (n, 0, n + 1) for all natural numbers n. Additionally, R contains triples related to the input (see the I/O format section).
Program consists of rules. Each rule adds a triple to the set R if the triple is not already in the set. For example:
a 0 b -> b 0 c -> a 10 c
This program generates triples (n, 10, n + 2) for all n. The a 0 b and b 0 c are patterns to match, and a 10 c is the new triple to be added to R. All varables are universally quantified. The interpreter finds (0, 0, 1) (one of the builtin triples (n, 0, n + 1) for n = 0), and also finds (1, 0, 2), so it generates triple (0, 10, 2).
The order of rules in the source code does not matter. The order of patterns in the rule does not matter (except that the last triple in a rule always represent the triple to be added, while the previous triples represent patterns). It is irrelevant in which order triples are added to R. Triples can only be added, never removed.
Inline comments start with --. Multiline comments start with /- and end with -/.
I/O format
Let the source code be a finite list of characters. Let n be the length of the list, and let the character codes (natural numbers) be c0, c1, ..., cn-1. Before the program starts, the interpreter adds triples (0, 1, c0), (1, 1, c1), ..., (n - 1, 1, cn-1), and finally (n, 2, 0).
The interpreter adds new relations according to the rules. For any natural number n, if the interpreter displayed n characters so far, and a relation of the form (n, 3, c) is produced (for any c), then output charcater with character code c. if the interpreter displayed n characters so far, and a relation of the form (n, 4, 0) is produced, terminate the program. If there are multiple relations satisfying the conditions (for example (n, 3, 1) and (n, 3, 2), or (n, 3, 1) and (n, 4, 0)), then it is undefined behavior.
Examples
Cat
a 1 b -> a 3 b a 2 b -> a 4 b
Replace even digits with hashtag
-- eq a 10 a -- lt a 0 a1 -> 0 11 a1 a 11 b -> a 0 a1 -> b 0 b1 -> a1 11 b1 -- le a 10 b -> a 12 b a 11 b -> a 12 b -- parity 0 13 0 a 13 0 -> a 0 a1 -> a1 13 1 a 13 1 -> a 0 a1 -> a1 13 0 -- main a 1 b -> 48 12 b -> b 11 58 -> b 13 0 -> a 3 35 a 1 b -> b 11 48 -> a 3 b a 1 b -> 58 12 b -> a 3 b a 1 b -> b 13 1 -> a 3 b a 2 b -> a 4 b
For example, if the input is abc 0123456789 xy, the output would be abc #1#3#5#7#9 xy.