3 Multi
3 Multi
There are two common ways to combine vector spaces in linear algebra, one is the direct sum
(denoted by ⊕) in which the dimensions add, and the other is the tensor product (denoted by
⊗) in which they multiply. For an n-qubit system, the former leads to a 2n-dimensional space
while the latter yields a 2n dimensions. Nature chose the latter: the vector space of the multi-
qubit system is the tensor product of the spaces of the constituent qubits. This fact has a pivo-
tal implication for quantum computing because it means the computing power and the infor-
mation content grows exponentially rather than linearly with the number of qubits.
2. The Space
Given two complex vector spaces S1 and S2, with basis sets B1 and B2, their tensor product S is
a complex vector space (with vector addition plus scaling by a complex number) of dimension
equal to the product of the dimensions of S1 and S2. Its basis B is derived from B1 and B2 via a
function f that maps each ordered pair in B1xB2 to a basis vector in B. The function is not linear,
it does not map sums to sums or scaled arguments to scaled images in both arguments, but it is
linear in each individual argument (aka bilinear): If a ∈B1 and b ∈B1 and n is a complex num-
ber, then:
f(a, b) = f(b,a)
f(a1 + a2, b) = f(a1, b) + f(a2, b)
f(a, b1 + b2) = f(a, b1) + f(a, b2)
f(na, b) = f(a, nb) = nf(a, b)
Let us rewrite the properties of our bilinear map using the operator notation for the tensor
product:
• Commutative:
|a> ⊗ |b> = |b> ⊗ |a>
• Bilinear with respect to multiplication by a complex number n:
n x (|a> ⊗ |b>) = (n x |a>) ⊗ |b>) = |a> ⊗ (n x |b>)
• Distributive over vector addition:
|a> ⊗ (|b1> + |b2>) = |a> ⊗ |b1> + |a> ⊗ |b2>
(|a1> + |a2>) ⊗ |b> = |a1> ⊗ |b> + |a2> ⊗ |b>
For 2 qubits, the four (standard) basis vectors of the tensor product are:
|0>1 ⊗ |0>2 , |0>1 ⊗ |1>2 , |1>1 ⊗ |0>2 , |1>1 ⊗ |1>2
This (inconvenient) notation can be simplified through a number of successive steps:
à Drop the tensor operator symbol, e.g. |0>1 |1>2 for |0>1 ⊗ |1>2.
à Drop the subscript, e.g. |0> |1> for |0>1 |1>2.
à Put both vectors in one ket, e.g. |01> for |0> |1>.
à Put the decimal values of the bit pattern, e.g. |1> for |01>.
We will adopt the very last simplification and revert to the explicit notation when needed to
avoid ambiguity. As such, the four basis vectors for the tensor product of 2 qubits are:
|0>, |1>, |2>, |3>
And similarly, the eight basis vectors for the tensor product of 3 qubits are:
|0>, |1>, |2>, |3>, |4>, |5>, |6>, |7>
And for n qubits, the 2n basis vectors are:
|k>, k = 1 … 2n
Finally, we need to define an inner product on the composite space so we can turn it into a
Hilbert space. For the basis vectors, we define it as the product of the two inner products:
(<a| ⊗ <b|) ⋅ (<c| ⊗ <d|) ≡ <a|c> <b|d>
As indicated in the single qubit case, there is redundancy in the underlying vector space (vis-à-
vis states) because vectors that differ by a scale represent the same state. For multiple qubits,
the redundancy is even larger because the tensor product allows us to apply a phase to either
factor and still end up with the same vector. This observation does not affect our calculations,
because we always work in the full (redundant) vector space, but it should be kept in mind in
order to correctly interpret vectors as states.
3. The State
Now that we understand the space in which a multi-qubit system resides, let us look at state
vectors in such a system. For a two-qubit system, this is a 4d vector and we like to see how it
relate to the two state vectors of the individual qubits. We'll start with an example: a vector in
the 2-qubit space is expressed in the standard basis as something like this:
|ψ> = ( 0.6|00> + 0.8|01> + 0.6|10> + 0.8|11> ) / √2
Note that this state is normalized:
( 0.62 + 0.82 + 0.62 + 0.82 )/2 = 1
Note also that the state expression can be simplified using the properties of the tensor product:
|ψ> = [ 0.6 ( |0> + |1> ) ⊗ |0> + 0.8 ( |0> + |1> ) ⊗ |1>] / √2
|ψ> = ( 0.6 |0> + 0.8 |1> ) ⊗ ( |0> + |1> ) / √2
The composite state in this case is thus separable (aka a product state) and is easy to interpret:
one qubit in state 0.6 |0> + 0.8 |1> and the other in |+>.
However, not all states in the composite space are separable. Take for example any of the
following four states that are known as the Bell states:
Each is a normalized state, but no simplification can reduce it to a product state. Such states are
known as entangled. It is difficult to interpret these states in terms of the states of their constit-
uent qubits. For example, you may be tempted to interpret the first Bell state above as an equal
superposition of |0> and |1> for each of the two constituent qubits, but this is wrong because
such an interpretation describes the following different state:
|ψ> = [ ( |0> + |1> ) / √2 ] ⊗ [ ( |00> + |11> ) / √2 ]
Most of the states in the tensor product space are in fact entangled and cannot be written as a
product (although you can always write them as a linear combination of products), and few are
separable. Here is why: for the most general composite state:
|𝜑> = a|00> + b|01> + c|10> + d|11>
to be separable, we should be able to write it as a product:
|𝜑> = (x|0> + y|1>) ⊗ (z|0> + t|1>)
Equating the above expressions and simplifying yields the following 4 equations:
a = xz, b = xt, c = yz, d = yt
The equations have no solution except when x=0, or y=0, or z=0, or t=0, or a/b = c/d. Only then
would the state be separable. In all other cases, it would be entangled.
It is interesting to see how the components of a product state derives from the components of
the states of its constituent qubits. Given the most general product state:
|s> = (⍺|0> + β|1>) ⊗ (ɣ|0> + 𝛅|1>)
use the properties of the tensor product (just think of it as multiplication):
|s> = ⍺ɣ|00> + ⍺𝛅|01> + βɣ|10> + β𝛅|11>
Or in column matrix form:
𝛼𝛾
𝛼 𝛾 𝛼𝛿
# & ⊗ . 1 = 3𝛽𝛾 4
𝛽 𝛿
𝛽𝛿
(Note that this is similar to an outer product but the 2d matrix is reshaped as a 4d vector.) This
result allows us to easily switch from the bra-ket to the matrix representation. It works for any
state, not just a separable one, because all states can be written as linear combinations of the
basis states, which are separable. As an example, let us apply it to the first Bell state:
|ψ> = ( |00> + |11> ) / √2
1 0
1 1 0 0
|𝜓 > = # & × # & /√2 + # & × # & /√2 = >0 0
0? /√2 + >0? /√2
0 0 1 1
0 1
1
|𝜓 > = >0
0? /√2
1
A key difference in the multi-qubit case is that the transforming device can operate on one of
the qubits without affecting the other. We represent such a case mathematically by applying
two operators (or two matrices) on the composite state: one performing the desired transfor-
mation on the affected qubit, and one doing nothing on the other (an identity operator). In the
matrix representation, this amounts to computing the outer product of the transforming matrix
with the unit matrix. Here is an example: a device that flips the state of the second qubit only.
The corresponding operator would be:
Flip2 = 𝟙1X2
In matrix format, this would be:
0 1 0 0
𝐹𝑙𝑖𝑝2 = >1 0 0 0?
0 0 0 1
0 0 1 0
Note that the matrix is block diagonal when it affects only one qubit—no cross talk. Applying
this to the first Bell state: |ψ> = ( |00> + |11> ) / √2 yields:
0 1 0 0 1 0
𝐹𝑙𝑖𝑝2|𝜓 >= >1 0 0 0? >0? /√2 = >1? /√2 = (|01 > +|10 >)/√2
0 0 0 1 0 1
0 0 1 0 1 0
5. Measurement
Recall from the single-qubit case that each measuring device has a preferred basis, and it forces
the state vector to become one of its basis vectors. The choice of which basis vector is random,
with distribution governed by the amplitudes of the state vector in that basis. The same applies
to a multi-qubit measurement except for the fact that not all qubits need to be measured, and
the measurement need not be projective (are you 0 or 1) but can also be comparative (is qubit
1 and 2 in the same state). To represent such a measurement, we associate with each device a
decomposition of the vector space. In other words, it views S as a direct sum of orthogonal sub-
spaces and projects the state onto one of them. Which subspace is chosen is random with dis-
tribution governed by the amplitude of the state vector within that subspace. This approach,
albeit more abstract, is not different from the one used in the single-qubit case, in which the
device also partitioned the space into a direct sum of two subspaces each spanned by one of its
two basis vectors.
6. Gates
Recall that when transformations are performed as part of an algorithm), we call them gates.
For single-qubit gates, we found that the rotation gate set is universal, and hence, we can build
any gate out of its elements. For multi-qubit systems, it can be shown that any universal single-
qubit set plus CNOT (discussed below) is approximately universal. Moreover, the Solovay-Kitaev
theorem proves that we can approximate any n-qubit gate using only 2n lgc(1/ε) gates from the
universal set, where ε is the approximation error. Let us take a look at a few multi-qubit gates:
|a>
|b>
|a ⊕ b>
🅇 |a>
|b>
|a>
|a ⊕ b> ✅
It is customary to refer to this gate as CX, since X is a NOT gate and C standard for "Controlled".
It is also customary to draw this gate as shown in the figure to the
right. The filled circle is on the control input (the one whose state |a> |a>
controls whether we negate or not). The "xor" ⊕ symbol is placed
on the so-called target input (the target of the possible negation).
It should be kept in mind, however, that the "control" / "target" |b> |a⊕b>
terminology stems from treating all inputs as classical bits. Once
we promote either input to a qubit in a superposition state, these terms lose their meanings,
and can in fact become misleading, as we shall see.
Let us now look at the quantum case. If the input qubits are not in superposition, the output is
similar to the classical case (we treat the top input as the leftmost qubit):
CX |0>|0> = |0>|0 ⊕ 0> = |00>
CX |0>|1> = |0>|0 ⊕ 1> = |01>
CX |1>|0> = |1>|1 ⊕ 0> = |11>
CX |1>|1> = |1>|1 ⊕ 1> = |10>
For inputs with superposition, we figure out the output through linearity, e.g.
CX 1/✓2 (|0> + |1>) |0> = 1/✓2 CX |00> + 1/✓2 CX |10>) = 1/✓2 (|00> + |11>)
Note that the 2-qubit input is a product (separable) state, yet the output is an entangled Bell
state. Note also that the classical notions of an unchanging control in the upper output and a
conditionally negated target in the lower have both lost their meanings.
To compute the CNOT matrix, we can compute its elements from the classical definition since
its rows and columns are labeled by classical 0/1 labels (non-superposition). This leads to:
1 0 0 0
𝐶𝑋 = >0 1 0 0?
0 0 0 1
0 0 1 0
Similarly:
|0 > − |1 > |0 > − |1 > |0 > − |1 >
𝑊|11111 … 1 > = ⨂ …
√2 √2 √2
Hence:
"! $%
1
𝑊|11111 … 1 > = P (−1))(&) |𝑘 >
√2# &'(
where f(k) is the number of 1-bits in the binary representation of k. This can also be captured by
the dot notation: x.y is the number of common 1's in the binary representations of the integer x
and the integer y. Hence, our f(k) can be expressed as k.2n – 1 because 2n – 1 has all 1's in its bina-
ry representation.
The dot notation allows us to write an expression for the transformation of any state by W, as
follows:
"! $%
1
𝑊|𝑚 > = P (−1)&.- |𝑘 >
√2# &'(
|𝜑> |𝜑>
>
|0> |𝜑>
We start with classical bits. If we denote the gate's operator by CL (for Clone) then:
CL |0>|0> = |00> and CL |1>|0> = |11>
For an arbitrary (unknown) superposition |𝜑> = a|0> + b|1>, we compute the output of the
sought gate in two ways:
à From linearity:
CL |𝜑>|0> = (a|0> + b|1>) ⊗|0> = a|00> + b|10>
à From the gate's definition:
CL |𝜑>|0> = |𝜑> |𝜑> = (a|0> + b|1>) ⊗ (a|0> + b|1>) = a2|00> + ab|01> + ba|10> + b2|11>
The gate can be generalized to handle the case of an integer function of an integer variable. If
the integer variable can be represented in m bits and the function value in n bits, then the gate
would have m+n inputs and outputs—the number of qubits in c and f must be the same.
import numpy as np
from qiskit import *
backend = Aer.get_backend('qasm_simulator')
q = QuantumRegister(2,'q')
c = ClassicalRegister(2,'c')
qc = QuantumCircuit(q,c)
qc.initialize([0,0,1,0], q)
qc.save_statevector(label='v0')
qc.h(q[0])
qc.save_statevector(label='v1')
qc.cx(q[0], q[1])
qc.save_statevector(label='v2')
qc.measure(q,c)
print(qc.draw(output='text'))
job = execute(qc, backend, shots=1000)
result = job.result()
counts = result.get_counts()
print(counts)
for i in range(0,3):
print("At barrier "+str(i)+":")
print(np.asarray(result.data(0)['v'+str(i)]))
Note: the two input states are unknown, and this circuit swaps them without leaking any
information about them, i.e. it is a transformation, not a measurement. For this reason, it is
referred to as a SWAP Gate.
• Create a circuit for the Fredkin Gate F, which is a singly controlled Swap gate. Show that F
can be adapted to implement NOT, OR, and AND.