Post Format

Quantum Computing with Ruby

cat

Few know that you already can do quantum computing with the Japanese programming language Ruby.

If you have a Ruby interpreter installed on your computer, you can follow the following experiment, which is inspired by Erwin Schrödinger. (See also my article from 1997)

In the quantum world, states are interlaced. In Ruby this is also possible. We produce an interlaced quantum hash like this:

q = Hash.new Hash.new

In this hash we store a box with a cat

q[:box][:cat] = "meow"

Is the cat comfortable?

q[:box][:cat]
→ "meow"

In our experiment we need to simulate the decay of a α-particle with a probability of 0.5. When the particle is detected, poison is set free and will kill the cat. Now there is an important detail for the experiment: we shall not get any knowledge of the result. Otherwise the wave function will collapse. However, the Ruby interpreter will show us each evaluation result. We solve this challenge by using a conjunction. It returns always “false”, regardless of the random value.

(q[:box][:poison] = true if rand > 0.5) && false
→ false

Now according to Erwin Schrödinger, the cat should be in a special state of superposition, neither alive nor dead.
What does our quantum hash says about this?

q
→ {}

What, we have just heard the cat’s meow, is the hash really empty?

q.empty?
→ true

We expected that maybe the cat is in some strange state, but now it seem to disappeared. Have we understood the experiment correctly? Let’s ask Mr Schrödinger for his cat.

q[:schroedinger][:cat]
→ "meow"

The cat is apparently emerged in a new reality. But how? Was this quantum tunnelling, or is Everett right with his “many-worlds theory“?

More information soon on this blog. Stay tuned.

Update

If you are interested in languages for quantum computing, have a look to this video interview with Benoît Valiron

Author: Karsten Meier

Weil ich gerne Probleme löse bin ich Informatiker geworden. Für meine Kunden berate und konzeptioniere ich und entwickle mit fast allem, was einen Prozessor hat. Sie finden mich auch auf Twitter

4 comments

  1. Nothing is strange here. The truth is that in the beginning you’re creating hash having default value set as new hash. So once you write q[:some] = ‘asd’ then q[:other] will also be ‘asd’. In fact be calling q[:some][:thing] = “other” you’re just setting default value to the first Hash.new being {:thing => “other”}. Then the first hash is always empty, but if you call q[:whatever_you_want] then the answer will be the default value {:thing => “other”}.

  2. You will not necessarily need it, but quantum computing will use concepts from higher mathematics, so it will be easier to learn for people with good mathematical background.

Leave a Reply

Required fields are marked *.