Three different representations of qubits

In this section, you will learn to use Python code to simulate other representations of a qubit and their superposition. |"0"> and |"1"> will remain our standard basis, but this chapter will show you that a variety of possibilities exist and help you to read and follow writing on quantum computation.

Primarily, we'll be dealing with the |"0"> and |"1"> basis, but this section should help illustrate that just like a classic bit, which we can represent by many different physical and conceptual things, qubits can have a variety of different representations. This section will illustrate the most common representations: the |"0"> and |"1">, the |"+"> and |"-">, and the  and  basis. Which basis you use is dependent on the algorithm; in some choices, writing an algorithm is easier in a particular basis. In addition, the physics of each basis is different, so it may be more convenient to describe a physical system in a particular basis. As a final note, with some code or math, it is possible to switch from one basis to another, which might be useful in a calculation the same way that looking at the same object from a different angle might help tell what shape it is, metaphorically, for example. We won't cover that in this section.

The important part when choosing a basis is making sure its parts are "opposite" in some sense. This is defined mathematically (for details, see the Appendix of the book), and for each of the examples here the two parts of the basis are opposite. This makes sense in the paint analogy. If we had only white paint and one shade of gray paint, we wouldn't be able to make any shade of gray. For that, we'd need the two opposites: white and black paint. The same goes with the basis. If the choices weren't completely "opposite," then we'd be missing out on the types of things we could represent.

To prepare for different representations, we can write some code that will return a qubit for any basis:

def qubit(percentage_first,percentage_second,basis_first,basis_second):
if not percentage_first+percentage_second==100
or percentage_first<0 or percentage_second<0:
raise Exception(
"percentages must add up to 100\% and both be positive ")
return sqrt(percentage_first/100.)
*basis_first+sqrt(percentage_second/100.)*basis_second

This means, in terms of our previous function, qubit(50,50,zero_qubit,one_qubit) is the same as zero_to_one_qubit(50,50) and qubit(10,90,zero_qubit,one_qubit) is the same as zero_to_one_qubit(10,90).