The Waterfall Model
No instructions and no instruction pointer. Clocks drain at the same speed, and a clock that runs dry refills the others.
ais523, 2018 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 3 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
ais523 named The Waterfall Model in 2018, though ais523 and zzo38 had both defined the same semantics in 2017. It is a counter machine stripped further than a Minsky machine: there is no way to decrease a counter on purpose. Instead every counter, called a waterclock, runs down at the same rate all the time, so the smallest one always empties first.
Read the story
That makes it easy to build inside other systems. It has been used to prove that very odd things are Turing complete, including a combo of cards in Magic: the Gathering.
The machine
The program is a square matrix written as JSON. The first row is metadata: a number larger than any other in the matrix, then the number of clocks, repeated. Each further row is one clock. Its first number is the clock's starting value. The rest is its zeroing trigger, how much it adds to clock 1, clock 2 and so on when it reaches zero.
| Rule | What happens |
|---|---|
| Time passes | Every clock goes down by the same amount until one reaches 0 |
| A clock reaches 0 | Its trigger adds its amounts to every clock, itself included |
| Its trigger does not refill it | The program halts |
| Two reach 0 together | The language leaves it open; here the first one in the matrix goes first |
Output is an optional extension. An output clock is one whose trigger only refills itself. Whenever a trigger adds exactly 7 to it, a hidden count goes up by one. Adding 8 prints the count as a number and adding 9 prints it as a character; both reset the count to 0.
Programs like TIO's hello world store their text in one clock that is about 2.7 times 10 to the 31. Draining that one unit at a time would never finish, so this implementation spots a stretch of firings that repeats exactly and skips many turns of it at once, and then a loop around that loop, as optimising interpreters do. The hello world takes 422 steps that way.
Example
Four clocks.
Four clocks. Clock 1 starts at 10 and never refills, so the program halts at time 10. Clock 2 is the output clock. Clock 3 empties at times 1, 4 and 7, adding 7 to the output clock each time, so the count reaches 3. Clock 4 empties at time 9 and adds 8, which prints the count.
Clock 5 is the output clock. Clock 4 empties every time unit and counts one up. Clock 1 empties at time 73, after 72 counts, and prints H. Clock 2 empties at time 178, after 105 more, and prints i. Clock 3 empties at the same moment and halts the program; it comes after clock 2 in the matrix, so the i is printed first.
Patterns it teaches
- Counter machines: a handful of counters is enough for any computation, even when they can only go down together.
- Turing completeness: its main use is as a source language, compiled into stranger systems to prove they can compute anything.
- Turing tarpit: a conditional decrement takes doubled counters and a careful race between clocks.
Try this
- Change the first example to print 5.
- Print
Aand halt. - Hard: build a loop that moves the value of one clock into another.
Further
- esolangs.org/wiki/The_Waterfall_Model
- The Waterfall Model Online, an interpreter and debugger
See also
Also in Turing tarpits
Write your own in Run Convert a program from The Waterfall Model
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: waterfall.
Command line
shib run waterfall -e '[[100, 4, 4, 4, 4], [10, 0, 0, 0, 0], [3, 0, 3, 0, 0], [1, 0, 7, 3, 0], [9, 0, 8, 0, 99]]'shib manual waterfallSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/waterfall.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org