A programming language whose programs run in two directions
A program in 42 denotes a relation rather than a function. Run it forwards and it computes. Run the same definition backwards and it gives you every input the answer could have come from, without your having written that direction yourself.
Start here
42 — User Manual
A guide from the ground up, assuming no prior knowledge of reversible computing. Thirteen primitives and seven ways of combining them, then worked programs: arithmetic, exact rationals, text, and a Turing machine.
Read the manual →Q42 — User Manual
The same language with complex numbers in place of set membership, which is enough to make it quantum. The physics is developed from scratch, and the manual is explicit about what Q42 does not model.
Read the manual →In one minute
$ 42 prelude add "(2, 3)"
add(2, 3) =
5
-- 1 result
$ 42 prelude add 5 --backward
add!(5) =
(0, 5)
(1, 4)
(2, 3)
(3, 2)
(4, 1)
(5, 0)
-- 6 resultsThe same definition, both ways
Forwards, add is a function. Backwards, it lists every
pair that sums to 5. You do not write that second direction or any
search to go with it: it is the dagger of the first, computed
from the definition you already gave.
Q42 runs the same machinery over the complex numbers, where it
produces quantum circuits and ! is the adjoint
† instead of the converse.
$ 42q gates hh "|0>"
hh |0>
= |0>Why now?
I first defined 42 in 1991 at the Philips Research Labs in Eindhoven, as part of the Rosetta machine translation project. In 1993 the language was set as the subject of a master's thesis by Paul Jansen. After that it was never taken any further. I left the Rosetta project soon afterwards, but I never forgot 42.
Thirty-three years later, retired by then, I picked up what documentation was left to see whether I could finish the work with the help of Anthropic's Claude. That worked out very well. Along the way I came across the conferences on reversible computation and found that it had become a research field with its own community, which did not exist in the early 1990s. I was also surprised to find a real connection with quantum computing. That led to Q42, the same language over the complex numbers, for programming quantum computers.
The result is this site, and the source is on GitHub.
Going deeper
Running it
Python 3.12 or later, and nothing else. Clone the repository and the two interpreters are scripts in its root.
$ git clone https://github.com/ubrowz/42.git
$ cd 42
$ ./42 tour swap "(1, 2)"
$ ./42q gates bell "|00>"The repository holds both interpreters, the OpenQASM 3 emitter and a separate circuit simulator to check it against, the example libraries the manuals draw on, and a test suite that re-runs the claims the documentation makes.
- rel42/
- the 42 interpreter: values, terms, types, dagger
- q42/
- the same over ℂ, plus the OpenQASM 3 emitter
- *.42
- libraries: arithmetic, rationals, text, a Turing machine
- tools/
- the renderer for this site, and a circuit simulator
- tests/
- one of which executes every transcript in the manuals