Quantum computing (QC) is a big topic, and last time I was only able to walk you through the construction of a few logic gates, but you have to start somewhere. If you haven’t read that part, you probably should, because you’ll need to understand the simulator I’m using and some basic concepts.

I like to get right into practice, but with this topic, there’s no avoiding some theory. But don’t despair. We’ll have a little science fiction story you can try by the end of this installment, where we manage to pack two bits of information into a single physical qubit. Last time I mentioned that qubits have 1 and 0 states and I hinted that they were really |1> and |0> states. Why create new names for the two normal binary states? Turns out there is more to the story.

## What’s the Vector, Victor?

In Dirac notation, |1> is a vector. So is |hackaday> and |123>. You can get into a lot of math with these, but I’m going to try to avoid most of that. This is also called ket notation (the last part of the word bracket) so you’ll hear people say “one ket” or “hackaday ket.” Either way, the vector can represent one or more qubits and there are several ways to represent them.

One way to represent the state of a qubit is with a vector in a Bloch sphere. The Bloch sphere is one unit in radius and has a center at XYZ=(0,0,0). Easy, right? By calling out the XYZ point, I can tell where the end point of the vector is and it starts at (0,0,0) so I have length and direction. There is one strange bit: by convention, |0> is (0,0,1) and |1> is (0,0,-1). Historically, this represents electrons having spin up or spin down.

The closer a vector is to the |0> position, the more likely it is that we will measure that vector as a |0>. That means that any point on (or under) the equator is equally likely to be a |0> or a |1>. That also means that any interior parts of the sphere represent the superposition states. The states |0> and |1> have length one since those states are definite: the vector goes from the origin to the edge of the sphere either straight up (0) or straight down (1).

## Superposition

So what does it mean to have a qubit be both |0> and |1> at the same time? Remember, according to quantum mechanics, until we measure the system, a superposed state is really some part |0> and some part |1>. States with a given probability of measuring as |0> are represented as horizontal slices through the sphere. On the equator slice (Z=0), all points are equally likely to resolve to a |1> or a |0>. On a slice near, but not on, the North pole all points might be 10% likely to be a |1> and 90% likely to be a |0>. (Remember, the |0> is at the top — spin up.)

However, unlike a regular computer, you can’t just set Z to some value. You have to take the vector you’ve got and perform certain operations on it. These have to meet certain mathematical tests and also have to be something the underlying hardware can perform.

Armed with the Bloch sphere, you can now see how the inverter — the X gate — really works. It actually rotates the vector 180 degrees around the X axis. So a |0> becomes a |1> and vice versa. But other vectors will behave differently, as we’ll see.

The Hadamard gate (the box with the H in it) lets you move a |0> or |1> to a 50-50% chance superimposed state. The H gate rotates the vector 180 degrees around the XZ axis. That is, it turns it 90 degrees around X and Z at the same time.

Try this circuit in the simulator. The top qubit shows a 50% chance of being a |1>. It also shows a Bloch sphere where XYZ=(1,0,0). The vector pointing straight up (|0>) is rotated 90 degrees around X (which points to Y) and then 90 degrees around Z (which points to X).

Note the bottom qubit. Two H rotations gives me the same state back. Since they are 180-degree rotations, that makes sense. If you turn 180 degrees then do it again, you’ll be back where you started. Or, more accurately, rotating 90 more degrees around Z and X simultaneously again.

There is a catch, though. Add an inverter in the very front of both qubits. Now we get a |1> at the bottom. No surprise, because we just turned 180 degrees twice from a different starting position. However, the top qubit is still 50%. Conceptually, there’s no difference between one qubit that is 50% |1> and one that is 50% |0> — that’s like asking if a glass is half empty or half full. But in QC, there is a difference because although Z is 0 in both cases, X=1 in the case of an H gate processing a |0> and X=-1 in the |1> case. Since the distance between |0> and |1> is the same, the qubits are different and the H gate can tell that difference. If you want, put a Bloch display between the two H gates and you can verify that the state is the same as the top qubit.

You can think of a qubit that started as a |0> as differing in phase from the one that started as a |1>, just as two sine waves can be the same frequency and amplitude, but different phases. Remember I said that each slice of the Bloch sphere is surface of constant probability? The position on the edge of that slice is the phase of the qubit.

Try adding a Y1/4 gate to the circuit. Then change it to Y-1/4. The probability changes as the vector gets closer to |0> or closer to |1>. The trick is to use all these rotations to manipulate multiple qubits to represent different states, just like we use binary numbers to represent states.

## Super Dense Teleportation

I promised you a little science fiction, so here goes. At the bottom of a crater on the far side of the moon is a quantum communication portal left there by aliens unknown. The portal can only send or receive four qubits at a time. This is inconvenient for us, because we like to use eight bits. After painfully communicating with the aliens for quite some time, we come up with a QC scheme to let either side send eight bits of information using four qubits. This will really cut down on the amount of time it takes us to send the aliens reruns of the Jerry Springer show.

Putting two bits into one bit would seem to violate some universal law, but a qubit is not just a bit. We are going to use entanglement and superposition to make it work. Here’s the general plan: First we will prepare two qubits that are entangled. We don’t know the state of either one, but we do know that they are the same (and they started as |0>). We hang on to one and we send the other across the portal.

Now the aliens want to encode one of four items: 00, 01, 10, or 11. If they want to send 00, they just send us the same qubit back. If they want to send 01, they invert the qubit and send it back. If they want to send 10, they rotate the qubit using a Z gate (180 degrees around Z flips the phase; the point around the slice of the Bloch sphere). To send 11 they both invert and do a phase flip.

When we get the qubit back, we will do a simple operation. We will do a CNOT with our original bit as the target and the received bit as the control and then do the H gate on the received bit.

Think about the 00 case. The right-hand H is going to put things back to how they were, so that takes care of that zero. We don’t know the state in the middle, but we do know that it was a zero the bottom bit will stay a zero. If the middle state were a one, the bottom qubit will flip twice, so it will still be a zero. If the middle state is a 0 then the CNOT gates do nothing and, still, the bottom qubit stays 0. Easy. By the way, the ellipses (…) don’t do anything. They just add to the science fiction feel that we are teleporting qubits across the galaxy.

The 01 case is a bit trickier. Inverting doesn’t change the phase of the qubit, so we still get 0 along the top qubit once we run the H gate at the destination. Regardless of the value of the top qubit, though, both inverters can’t be on at the same. The bottom qubit will either be inverted on the left or on the right. That’s where the bottom qubit’s |1> comes from.

The 10 case uses the Z rotation to change phase. That flips the output of the righthand H gate. However, changing the phase doesn’t change the value, so the bottom qubit is handled just like in the 00 case — it is either never inverted or it is inverted twice. Either way, we get our 0.

Now, look at 11. Here the aliens change the phase and the value. This is like a combination of 01 and 10.

If you want to see the aliens do a full byte, I made them send 00011011 so you could see all four at one time. If any of this doesn’t make sense, try adding some displays like the Bloch to different spots. In a real quantum system that would destroy our algorithm, but in a simulator, we are allowed to peek and it can really help you understand.

Just a few buzz words. The left side of the algorithm (before the first set of ellipses) is preparing a “Bell state.” The right hand side is known as “projective measurment.”

By the way, if you had a machine that had controlled inverters and Z gates, you could automate the encoding process. Oh, look, a program that actually keeps running!

## What’s It Mean?

Remember I mentioned that there are a lot of oversimplifications surrounding QC? It would be easy to get a press release saying that QC can let computers pack two bits in the space of one. If you really think about it, though, you are sending two bits, just not in the same direction. This is actually the reverse of quantum teleportation and you hear enough about “scientists get closer to transporter” every time there is a press release about that.

Is it practical? Well, we haven’t found the aliens unless you count the ones storing stuff in Las Vegas. We don’t have qubit portals to the gamma quadrant. We also don’t have qubits that last long enough to make any sort of trip. However, it does show something that could possibly be useful that requires superposition and entanglement. It demonstrates how a qubit can store multiple states where a normal bit stores two.

An interesting side note: although the theories behind QC date back to early in the 20th century, this superdense algorithm wasn’t published until 1992. There are probably still secrets waiting to be found in this field if you want to make a name for yourself.

## IBM

Perhaps you thought I’d forgotten about the IBM Quantum Experience. If you have an account, you can do the same experiments. The blocks look about the same, but there are fewer of them. Also, the hardware topology forces you to move things around. For example, look below and you’ll see I had to flip where the CNOT gates are because the qubits don’t connect in both directions.

The hardest part is that you simply don’t have the same number of gates. The user’s guide explains how to create more sophisticated gates using elementary gates, but it is often fairly painful to do so. If you really want to use IBM’s site, here’s a tip: if you create your own topology and click advanced on the tool palette, you’ll get a lot more options for making subroutines and using macros like CCNOT. However, those won’t run on the real hardware and if you are just simulating, you might as well stick with Quirk.

## The End?

This isn’t even scratching the surface of QC, but it should get you started. Next time, I’m going to show you the often-misundestood Grover’s algorithm. If you are still struggling with how this would work to create practical programs, that ought to help clear things up.

Meanwhile, if you want a sneak preview, you can look at Quirk’s example of Grover’s, although mine will look a little different.

“QUANTUM COMMUNICATIONS IN YOUR BROWSER”

And the last mile monopoly has been solved.

|pho>

Nah, QC almost makes sense, now. Thanks, Al!

My favorite new joke (props to The IT Crowd)…

User: “My quantum computer isn’t working.”

IT: “Have you tried turning it off and on at the same time?”

“Have you tried stuffing a cat in it?”

No, it didn’t say “FEED ME A CAT”

I thought only ATMs did that . . .

Perhaps they’re running Windows XP and Vista simultaneously!

Yesterday upon the stair

I saw a bit that was and wasn’t there

It is 50% there today

I think it decrypts for the CIA

OK, now imagine the bit position as a percentile part of qbit probability… you can now store 2^x bits based on probability values like with QPCM, but in 3D… the future will be interesting… an dodecahedron inside a sphere makes 20 vertices, each with a possible bit representation, making it possible to store big numbers in a small set of qbits…

Dirac Notation is (arguably) more commonly known as Bra-Ket notation. This notation applies (mainly) to the subject of Linear-Algebra and pervades not only in theoretical Physics but the application of Coding and Information Theory in Electrical Engineering and Computer Science:

This introductory article chips-away at the Bra-Ket iceberg:

* Bra-Ket Notation Trivializes Matrix Multiplication:

http://algassert.com/post/1629

Then there’s this

* Bra–ket notation:

https://en.wikipedia.org/wiki/Bra-ket_notation

Q. What does a quantum physicist sell at a rave?

A. |$20>

(Alright, I butchered this)