Java2K
A language where every built-in function only probably works. Programming in it means fighting the odds with redundancy.
Gerson Kurz, 2000 · Turing complete: unknown · ●●○ moderate · esolangs.org
The idea
Gerson Kurz made Java2K around 2000 (its interpreter versions date to the early 2000s). The premise is a dig at real software: functions sometimes do the wrong thing. In Java2K this is official. Each built-in has two implementations, and a random number generator picks one at run time. Almost all of them return the right answer about 90% of the time.
Read the story
It is not related to Java. The name is part of the joke, as is the number system: Java2K counts in base 11, offered as a close approximation of base 10.
So the interesting question is not how to compute something, but how to compute it reliably. That turns a joke language into a lesson in fault tolerance.
The machine
The details are documented on Kurz's site rather than on esolangs.org, and the syntax is dense. The parts that matter:
| Feature | What it means |
|---|---|
| Probabilistic built-ins | Each call is right with probability around 0.9, wrong otherwise |
| Base 11 | Numbers are written in base 11, so "13" means 14 |
| Garbage collection | Memory is freed when the program exits, or at random, whichever comes first |
The goal Kurz sets is finding techniques that raise the chance of a correct result.
Example
Not Java2K syntax, only the arithmetic of its main technique.
Not Java2K syntax, only the arithmetic of its main technique. If one call is right with p = 0.9, call it several times and take the majority answer:
| Calls per step | One step right | 100 steps all right |
|---|---|---|
| 1 | 0.900 | 0.00003 |
| 3 | 0.972 | 0.058 |
| 5 | 0.991 | 0.423 |
| 7 | 0.997 | 0.761 |
A program of a hundred unreliable calls almost never works. With five-way voting it works almost half the time. (This assumes the wrong answers disagree with each other, so they cannot outvote the right one.) These numbers were computed, not taken from a Java2K run.
Patterns it teaches
- Nondeterminism: randomness inside each operation, not in the order of operations as in Whenever. Errors compound with program length.
Try this
- Check the table: work out the 3-call row by hand.
- If wrong answers are always the same wrong value, does voting still help? When does it fail?
- Hard: simulate a 90%-reliable
addin Node and find the cheapest scheme that adds 100 numbers correctly 99% of the time.
Further
- esolangs.org/wiki/Java2K
- Gerson Kurz's Java2K page, with sample programs: p-nand-q.com/programming/languages/java2k
See also
Nondeterministic
Source esolangs.org (CC0) · Edit on esolangs.org