After an hour of drawing this abomination, I realized that this probably does very little to clarify the paradox. In the illustration (which loosely mirrors the setup in the Ars Technica article), you can see some sort of interaction in which box “A” flips a coin and sends the corresponding state to “B”, which creates a green arrow inside an egg. Then, as “a.” and “b.” measure this from the outside with their cheese graters, their eggs are different, causing the universe to collapse. You can think of the green arrows as representing quantum states, where “sideways” is a superposition of “up” and “down”. When the coin flips “heads”, the quantum state visible to “A” will be an “down” arrow, and if “tails” the state will be a “sideways” superposition arrow. If the coin flip happens to be “tails” and “b.” measures a “down” arrow, “B” actually has a 50/50 chance of measuring “down” because his measurement still accounts for an unresolved superposition between the original coin flip of “heads” or “tails”. Bleeeeeeeeargh. This contradiction is extremely important to our understanding of quantum theory, but it’s amazingly difficult f̶o̶r̶ ̶m̶e̶ to explain.

Coming from a software engineering background, I would much rather see this written as an executable block of code rather than trying to think about coins and boxes and arrows. Since quantum computers are slowly becoming more accessible for the everyday enthusiast, I also wanted to make this algorithm available for anyone to splinter reality for their own twisted enjoyment.

If you haven’t yet delved into the quagmires of quantum computing, even the simplest algorithms tend to look really horrifying for beginners, involving enormous unitary matrices and circuits that require a fairly in-depth understanding of linear algebra, signal processing, circuit diagramming, and of course quantum mechanical “bra-ket” notation. Just look at the Wikipedia page for quantum logic gates, which is possibly the “simplest” concept in quantum computing.

I’m personally not a fan of this approach, so I built my own hybrid quantum programming language, FunQy, for writing algorithms that can be understandable by those familiar with JavaScript, Python, C#, Haskell, Rust, and any other mainstream programming language with features such as first-class functions and polymorphic data types.

Before diving into the implementation, let’s clarify some of FunQy’s language constructs so that the code is easier to follow. The language’s standard library defines the boolean values F and T , which are also equivalent to orthogonal qubit state vectors (usually written as |0⟩ and |1⟩). The operator ^ designates a superposition between two states, and should not be confused with the bitwise XOR operator from most programming languages. For example, the expression F ^ T corresponds to the quantum state (|0⟩+|1⟩)/√2, which has an equal chance of being measured as F or T . Measurement is designated using the measure() function, which collapses a state to one constituent value based on its probability distribution from quantum mechanics.

It is also possible to entangle states using expressions such as if a then t else f , which returns the value t to the extent that a equals T , and f to the extent that a equals F . For those who are interested in the specifics, I highly recommend checking out the documentation and examples on FunQy’s GitHub repository.

And now, for the code that breaks reality:

let coin = F ^ T

let r: Bool = measure(coin) let box1 = if r then (F ^ T) else F

let box1_m: Bool = measure(box1)

let box2 = if coin then box1_m else F let m1 = box1_m

let m2: Bool = measure(box2) print (m1, m2)

Turns out it only takes about 8 lines of code to fracture the universe.

Here’s an in-depth breakdown with comments:

// Define the superposition of both possible coin flip outcomes.

1. let coin = F ^ T // Simulate flipping a coin by sampling from the (coin) superposition. The result will be either (F) or (T) with equal probabilities.

2. let r: Bool = measure(coin) // Create a quantum state dependent on the coin flip (r), which is the superposition (F ^ T) if (r == T), otherwise (F).

3. let box1 = if r then (F ^ T) else F // Measure the previous state (collapse the wave function from the second box's perspective).

4. let box1_m: Bool = measure(box1) // Define the state of the second box according to the measurement of the first box. This step encodes the "knowledge of quantum mechanics" because, from this perspective, the coin flip is still a superposition. Swapping (coin) with (r) here will resolve the discrepancy, but this corresponds to a different experimental setup and therefore does not resolve the paradox.

5. let box2 = if coin then box1_m else F // Measure (box1) as an external observer. The wave function has already collapsed, so it will be the same as (box1_m).

6. let m1 = box1_m // Measure (box2) as an external observer. According to quantum theory, this measurement depends on unresolved superpositions from both the coin flip (r) and the second box's measurement (box1_m).

7. let m2: Bool = measure(box2) // Return a tuple of measurements to show that the external measurements (m1, m2) do not necessarily agree. Quantum theory expects these to always be the same, but there is a 25% chance of a discrepancy due to the superposition in line 5.

8. print (m1, m2)

Running this code repeatedly through the FunQy simulator confirms that the measurements do, in fact, occasionally disagree:

$ funqy eval Contradiction.fqy

>> (F, F)

$ funqy eval Contradiction.fqy

>> (F, F)

$ funqy eval Contradiction.fqy

>> (F, F)

$ funqy eval Contradiction.fqy

>> (T, T)

$ funqy eval Contradiction.fqy

>> (F, F)

$ funqy eval Contradiction.fqy

>> (F, F)

$ funqy eval Contradiction.fqy

>> (T, F)

$ funqy eval Contradiction.fqy

>> (F, F)

Even better, you can try this yourself using FunQy Online, which is a (delightfully low-budget) online interpreter for writing FunQy code. It works on both desktop and mobile, and comes preloaded with the code from this article so you don’t have to worry about copy-pasting anything.