Quantum computing done right
I know as a good microsoftee I should be supportive of what my employer does no matter what it is, and I might get fired for this post, but Eilon’s latest article is wrong on so many levels I have to step up with whatever integrity I have left and fix this mess.
In his post, he exposes the new ShrödingOr<TDead, TAlive> type that will be introduced in .NET 5.0 as part of the System.QuantumEntanglement namespace. Well, let’s face it, the current implementation has nothing quantum about it.
Here’s how I would have written it:
namespace System.QuantumEntanglement { public class SchrödingOr<TDead, TAlive> { private Complex _howDead; private Complex _howAlive; public SchrödingOr(Complex howDead, Complex howAlive) { _howDead = howDead; _howAlive = howAlive; } public Type Measure() { double howAliveSquareModulus = _howAlive.Real * _howAlive.Real + _howAlive.Imaginary * _howAlive.Imaginary; double howDeadSquareModulus = _howDead.Real * _howDead.Real + _howDead.Imaginary * _howDead.Imaginary; double probabilityOfBeingAlive = howAliveSquareModulus / (howAliveSquareModulus + howDeadSquareModulus); if ((new Random()).NextDouble() < probabilityOfBeingAlive) { _howAlive = new Complex(1, 0); _howDead = new Complex(0, 0); return typeof(TAlive); } else { _howAlive = new Complex(0, 0); _howDead = new Complex(1, 0); return typeof(TDead); } } } }
This way, the state really is a (complex) linear combination of the dead and alive types, which are the eigenstates of the system. Once you’ve created the state, you can never get it back unless you do a measurement. When you do that, the object collapses its state to one of the eigenstates based on probabilities determined by the actual quantum state of the system.
The first measurement is random but once you’ve measured it, the cat remains alive or dead forever (the entanglement is destroyed by the measure).
Here’s a little console app that creates a cat, puts it in the box and then opens the box:
static void Main(string[] args) { // put the cat in the box var cat = new SchrödingOr<DeadCat, LiveCat>( new Complex(1, 0), new Complex(1, 0)); // Open the box Console.Write(cat.Measure() == typeof(DeadCat) ? "Cat is dead." : "Cat is alive"); Console.ReadKey(); }
This, I believe, is a much more realistic and useful implementation of SchrödingOr.
The code: http://weblogs.asp.net/blogs/bleroy/Samples/Quantum.zip
Eilon’s original article: http://weblogs.asp.net/leftslipper/archive/2009/04/01/the-string-or-the-cat-a-new-net-framework-library.aspx