esolang

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:

FeatureWhat it means
Probabilistic built-insEach call is right with probability around 0.9, wrong otherwise
Base 11Numbers are written in base 11, so "13" means 14
Garbage collectionMemory 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 stepOne step right100 steps all right
10.9000.00003
30.9720.058
50.9910.423
70.9970.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

  1. Check the table: work out the 3-call row by hand.
  2. If wrong answers are always the same wrong value, does voting still help? When does it fail?
  3. Hard: simulate a 90%-reliable add in Node and find the cheapest scheme that adds 100 numbers correctly 99% of the time.

Further

Nondeterministic

Source esolangs.org (CC0) · Edit on esolangs.org