Introduction to Quantum Computing 

Superposition
In this lesson, you will learn about the Hadamard gate and its applications.
1) Superposition
Previously, we used the Bloch sphere to represent a qubit. However, the output from your first program could only show the probability of the qubits being in the 0 or 1 state. To get values in between, we use superposition. That is, we organise for the qubit to be set to a mixture of 0 and 1 states, such that the probability of being in between can be shown.
For example, if I wanted to have half a chance of drawing a black ball from a hat containing 100 balls, I would put in 50 white and 50 black balls. So when we use superposition, we are arranging the qubit to be a bit like the hat – we set it up so that over one hundred observations, the ratio of times when it is seen as a ‘1’ or as a ‘0’ are exactly in the proportion we want. Since this ratio (expressed as a probability) will lie between 0 (never) and 1 (always) we can effectively use a qubit to represent a decimal number in the range 0 to 1. Perhaps the easiest way to see this is to program a qubit to represent the value 0.5 (a half). The power of this demonstration is that a binary digit in a conventional computer can NEVER hold such a value!
Log into https://quantumexperience.ng.bluemix.net to try this out.
A qubit has some properties of a continuous variable, and some properties of a discrete one.
2) The Hadamard gate
Set up this program in the composer. It only works on one qubit (q(0)) but comes up with a rather interesting result: 
3) Interpreting the output of the Hadamard gate
The first time I ran this program, I got:
So, there was a probability of 0.47 the result came to 1>, and a chance of 0.53 the output was 0>.
Try running your program several more times in the simulator, and write down the values from the output. I ran it a few more times and got the following probability results – compare them with yours:
Output Run 
00001 = 1> 
00000 = 0> 
1 
0.51 
0.49 
2 
0.5 
0.5 
3 
0.5 
0.5 
4 
0.42 
0.58 
5 
0.5 
0.5 
Isn’t that strange! You don’t get the same result every time! And I thought computers were accurate… But this is a Quantum Computer, and therefore we have to average our results over time, and beware of instabilities. Would you agree the result is getting close to 0.5 for 1> and 0.5 for 0>? In which case, we can average these results and agree the qubit is in the halfway state between 0 and 1 – so it is telling us the result is 0.5>.
The Hadamard gate can put a qubit into an inbetween state, not quite 1, and not quite 0. It combines two rotations: 180° about the Xaxis followed by 90° about the Yaxis. We can represent this on the Bloch Sphere as a turn:
4) Intermediate states
Previously, you saw the output from a qubit can only be 0> or 1>, but if we run our programs 100 times, these values can occur with different probabilities. This tells us the qubit is in an intermediate state. We have learned the Hadamard gate can put a qubit into a state which corresponds to the value 0.5>.
Here are the output runs from three different quantum composer programs. Can you find what the qubit state represents for each one?
Program 1
Output Run 
00001 = 1> 
00000 = 0> 
1 
0.31 
0.69 
2 
0.29 
0.71 
3 
0.3 
0.7 
4 
0.28 
0.72 
5 
0.32 
0.68 
Program 2
Output Run 
00001 = 1> 
00000 = 0> 
1 
0.45 
0.55 
2 
0.44 
0.56 
3 
0.46 
0.54 
4 
0.42 
0.58 
5 
0.45 
0.55 
Program 3
Output Run 
00001 = 1> 
00000 = 0> 
1 
0.75 
0.25 
2 
0.73 
0.27 
3 
0.74 
0.26 
4 
0.76 
0.24 
5 
0.77 
0.23 
You may find taking the average of the first or 1> column the easiest way to calculate the number our qubit is representing!
5) Superposition for multiple qubits
By now, you should be able to write a quantum program that measures the state of three qubits started in the 0> state. I will guess there is a 100% chance (probability = 1) they will all be in the 000> state. Now prove it!
However, here is a tricky question. What happens if you apply a Hadamard gate to each of these three qubits before measuring their values? Try it and see!
Your program should look like this:
And the output might look a bit like this:
This shows us that multiple Hadamard gates can create multiple qubit values which have low probabilities.
6) Running a more complicated quantum program.
Here is a quantum program which is a bit more complicated. The text below gives an idea of the way in which is works (from Robert Lisiecki here).
N 2 # create a new quantum bit and identify it as '2'
E 1 2 # entangle qubits '1' and '2', qubit 1 already exists and is considered input
M 1 0 # measure qubit '1' with an angle of zero (angle can be anything in [0,2pi]
# qubit '1' is destroyed and the result is either True or False
# operations beyond this point can be dependent on the signal of '1'
X 2 1 # if the signal of qubit '1' is True, execute the PauliX operation on qubit '2'
Create a new program in the Quantum Experience using ibmqx4. As before, drag the gates to the indicated point on the score. If you make a mistake, doubleclick on the gate to delete it, or drag it to the top left (a delete bin will appear). With the + gates, place them on the score line, then click on the adjacent control line. This is how your program should look: 
Run the program using the ‘Simulate’ button (you may not have enough credits to run it on the real quantum computer just yet!). Show your teacher the output probability bar chart.