# How to produce the basis states of a quantum computer?

Suppose you have a one qubit system; the (traditional) basis states are $|0\rangle$ and $|1\rangle$, and any state of the qubit can be described by a linear combination of these two. Now suppose you have a two qubit system; the basis states are now $|00\rangle$, $|01\rangle$, $|10\rangle$, and $|11\rangle$ and again any state of the system can be described by a linear combination of these states. This can be continued for any number of qubits.

My question is, how does one mathematically generate the basis states? Or, for example, if I am writing a program to generate the basis states, and I have an input x that is the number of qubits in the system, what do I do with x to get an output? Obviously, if x = 1 then the output would be $|0\rangle$ and $|1\rangle$, but what do I do inbetween to get to that series of basis states?

Note that I'm not asking about how many basis states there will be, that is $2^n$ where $n$ is the number of qubits in the system, rather I'm asking for how a list of the basis states could be generated.

Edit: A more specific example of the output would be, if x=1, the output would be something like [np.array([0,1]), np.array([1,0])] (this is using list notation and numpy in python). Or, if x=2, the output would be [np.array([0,1,0,1]), np.array([1,0,0,1), np.array([0,1,1,0]), np.array([1,0,1,0])]. In other words, vector outputs that could be manipulated would be ideal. However, this isn't necessarily about how to program it, it's just about how to produce these states, whether on paper or in a program.

• I don't understand your question. If you have $n$ qubits then one possible basis is list all $n$-digit binary strings 0000, 0001, 0010, 0011, 0100, ..., 1110, 1111. – kennytm Mar 19 '17 at 14:39
• @kennytm, I'm asking about the standard basis used in most papers, etc, of which several examples are given in the question - I'm not sure I understand your objection =) – heather Mar 19 '17 at 14:40
• I don't understand the question. What do you mean by "generate a list of basis states"? Can you provide a description of what such a code should take as input and give as output? E.g., would bitget(x+1,1:n) in MATLAB do? Or do you want to create the basis vectors as vectors in a Hilbert space? – Norbert Schuch Mar 19 '17 at 14:44
• @NorbertSchuch, see the edit to the question. – heather Mar 19 '17 at 16:02
• @heather your edit does not help older folks like me who are useless in python. Can you be more explicit? – ZeroTheHero Mar 19 '17 at 16:22

You want to represent the tensor product!

# What is the tensor product?

In a rough sense, we define the tensor product as the obvious bilinear binary operator $\otimes$ such that we can write things like:$$\big(\langle a|~\otimes\langle b|\big) ~\big(X \otimes Y\big)~\big(|c\rangle \otimes |d\rangle\big) = \langle a |X|c\rangle\langle b|Y|d\rangle.$$You might implement this in a programming language with whatever tuple or pair operators you have available: however we have one big nuance, which is that we want to make this into a new vector space atop the field $\mathbb C$, and therefore this operator $\otimes$ injects into a smaller part of a larger space. So we can define basis elements like $|01\rangle = |0\rangle \otimes |1\rangle$ for the space, but please be aware that while you can use linearity make sense of e.g. $$\big(a |0\rangle + b |1\rangle\big) \otimes \big(c |0\rangle + d |1\rangle\big) = ac |00\rangle + ad |01\rangle + bc |10\rangle + bd |11\rangle,$$you cannot in general go from an arbitrary vector $\alpha|00\rangle + \beta|01\rangle + \gamma |10\rangle + \delta |11\rangle$ in this new space on the right, back to a separated version as you see on the left. (A criterion: notice that for the separable states $\alpha\delta = \beta\gamma = abcd$; you can do it therefore when this "determinant" $\alpha\delta-\beta\gamma$ vanishes.)

Similarly to the basis states, we can expand the operator states in terms of their basis matrix elements like $|01\rangle\langle 11|,$ and that gives us the full space of possible operators and vectors in the space.

# How can I concretely represent this?

Well I notice that your "intuitive" approach appears to be to combine the two vectors into another big vector, so you take the pair ([1, 0], [0, 1]) which would represent $|01\rangle$ and represent it as the vector [1, 0, 0, 1]. This has a certain elegance at first because it means that your tensor product of operators looks like:$$X \otimes Y = \begin{bmatrix}X & 0\\ 0 & Y\end{bmatrix}.$$However, what do you notice about the vector [a, b, c, d]?

It is always separable into ([a, b], [c, d]). D'oh! We can't express entanglement in this language without storing explicit linear combinations of vectors.

There is a better way: it turns out that you can just renumber the states by their binary encoding, so $$|00\rangle \mapsto |0'\rangle,\\ |01\rangle \mapsto |1'\rangle,\\ |10\rangle \mapsto |2'\rangle,\\ |11\rangle \mapsto |3'\rangle.$$ Now the primed space on the right is just $\mathbb C^4$. (The mathematical kind, not the explosive kind.) So [α, β, γ, δ] can just be your programming representation of $\alpha |0'\rangle + \beta |1'\rangle + \gamma |2'\rangle + \delta |3'\rangle.$

What about our tensor product on operators, though? They must have a very complicated form! Well, yes and no. Yes it's a little complicated, but no you don't have to program it, it's in your programming language already as the "Kronecker product", obscure enough to be a little buried but useful enough that somebody needed it and added it. It is just the formula: $$\hat X \otimes \hat Y = \begin{bmatrix} X_{00}~\hat Y & X_{01}~\hat Y\\X_{10}~\hat Y&X_{11}~\hat Y\end{bmatrix},$$ where $X_{ij} = \langle i|\hat X|j\rangle.$ This space of 4x4 complex matrices inherits all of the nice theory that you want, too: for example you may be able to see that the product of Hermitian matrices is Hermitian.