Some Quantum Gates

Single-Qubit Gates

In Notebook2_ 1.nb  we introduced the Mathematica command for the basic ket and bra representation as column and row vectors respectively.

ClearAll["Global`*"]
ket0={1,0};
bra0={1,0};
ket1={0,1};
bra1={0,1};

Operators are then expressed as 2×2 matrices. Gates are unitary matrices.

Examples

Pauli Gates

The Pauli-X gate is given by

PauliX={{0,1},{1,0}};
MatrixForm[PauliX]

Note that

PauliX.ket0
PauliX.ket0==ket1

PauliX.ket1
PauliX.ket1==ket0

For a general qubit

qubit=α ket0+ β ket1
PauliX.qubit
PauliX.qubit==β ket0+α ket1

The Pauli-Y gate is

PauliY={{0,-I},{I,0}};
MatrixForm[PauliY]

Note that

PauliY.ket0
PauliY.ket0==I ket1

PauliY.ket1
PauliY.ket1==-I ket0

PauliY.qubit
PauliY.qubit==-I β ket0+I α ket1

Finally, the Pauli-Z gate

PauliZ={{1,0},{0,-1}};
MatrixForm[PauliZ]

Note that

PauliZ.ket0
PauliZ.ket0== ket0

PauliZ.ket1
PauliZ.ket1==- ket1

PauliZ.qubit
PauliZ.qubit== α ket0 - β ket1

Hadamard gate

One of the most common one-qubit gates is the Hadamard gate, whose matrix representation is

Had=1/Sqrt[2]{{1,1},{1,-1}};
MatrixForm[Had]

It is unitary, as its product with the conjugate transpose

Hadagger=ConjugateTranspose[Had];
MatrixForm[Hadagger]

begets the unit matrix

Hadagger.Had // MatrixForm
QED

Note also the adjoint of the Hadamard gate is the same as the Hadamard (i.e. it is also Hermitian).

Had.ket0 // MatrixForm
Had.ket1 // MatrixForm

Note that the Hadamard gate maps the basis kets into a linear combinations of the latter

Had.qubit // MatrixForm

2-Qubit Gates

We represent 2-qubit gates whose wire diagrams contain two input, and output leads respectively. One of the most important of such gates is called the Control-Not, or CNOT, gate. Its wire diagram is

In this notation the two input leads represent the two-qubit state |(Subscript[x, 1])(Subscript[x, 0])⟩ ≡ |(Subscript[x, 1]) ⟩ ⊗| (Subscript[x, 0])⟩ , and the gate’s  output is a direct product of |(Subscript[x, 1]) ⟩  and |(Subscript[x, 1])⊕ (Subscript[x, 0])⟩.  The ⊕ symbol represent the modular sum of the bit values (Subscript[x, 1]),(Subscript[x, 0]). The upper wire is said to be the control bit and is denoted by the solid node symbol in the diagram. It’s job is to ``turn-on’’ the one-qubit gate ⊕ on the bottom wire, and which is called the target bit.  So if |(Subscript[x, 1]) ⟩ = | 0 ⟩, no action is taken and the gate as a whole acts simply as an identity. If |(Subscript[x, 1]) ⟩ = |1⟩ , the one-qubit gate on the lower wire becomes effective. The truth tables for some possible input values are shown below.

The matrix representation, with respect to the computational basis, is given by Eq. (3.16) in the text.

CNOT={{1,0,0,0},{0,1,0,0},{0,0,0,1},{0,0,1,0}};
MatrixForm[CNOT]

The basis vectors for a 2-qubit is constructed as direct products of the qubit basis vectors. So

ket00=Flatten[KroneckerProduct[ket0,ket0]];
ket01=Flatten[KroneckerProduct[ket0,ket1]];
ket10=Flatten[KroneckerProduct[ket1,ket0]];
ket11=Flatten[KroneckerProduct[ket1,ket1]];

That is,

MatrixForm[ket00]

MatrixForm[ket01]

MatrixForm[ket10]

MatrixForm[ket11]

as in Eq. (3.17) of the text. The operation of the CNOT gate on these column matrices reproduces the graphical truth table above.

CNOT.ket00 // MatrixForm
CNOT.ket00==ket00

CNOT.ket01 // MatrixForm
CNOT.ket01==ket01

CNOT.ket10 // MatrixForm
CNOT.ket10==ket11

CNOT.ket11 // MatrixForm
CNOT.ket11==ket10

Direct Product 2-Qubit Gates.

We can also form 2-qubit gates from direct, or tensor, products of two single qubit gates. (Note: The CNOT gate cannot be factored into a single direct product). One of the most useful of such gates is the direct product of two Hadamard gates. In matrix form it is written as the following Kronecker product.

Had2=KroneckerProduct[Had,Had];
MatrixForm[Had2]

Let’s investigate the action of this gate on the state |00⟩

Had2.ket00 // MatrixForm

This output is a linear combination of all the 2-qubit basis vectors, as

Had2.ket00==1/2 (ket00+ket01+ket10+ket11)

This feature, in which a direct product of Hadamard gates engenders a linear combination of a basis vectors in the multi-qubit Hilbert space is called quantum parallelism. It is widely used in some of the quantum algorithms that we discuss later.

Example: Direct Product of Hadamard Gates in a 3-Qubit Hilbert space.

First we construct, as above, the basis vectors in a 3-qubit Hilbert space.

ket000=Flatten[KroneckerProduct[ket0,ket0,ket0]];
ket001=Flatten[KroneckerProduct[ket0,ket0,ket1]];
ket010=Flatten[KroneckerProduct[ket0,ket1,ket0]];
ket011=Flatten[KroneckerProduct[ket0,ket1,ket1]];
ket100=Flatten[KroneckerProduct[ket1,ket0,ket0]];
ket101=Flatten[KroneckerProduct[ket1,ket0,ket1]];
ket110=Flatten[KroneckerProduct[ket1,ket1,ket0]];
ket111=Flatten[KroneckerProduct[ket1,ket1,ket1]];

The direct product of three Hadamard gates is a 8 × 8 unitary matrix given by

Had3=KroneckerProduct[Had,Had,Had];
MatrixForm[Had3]

Exercises

(a) Demonstrate, explicitly using its matrix representation, the unitarity of  H⊗H⊗H where H is the single qubit Hadamard gate
(b) Using its matrix representation, evaluate H⊗H⊗H|000⟩, show that it is a linear combination of all eight basis vectors in this Hilbert space.

Toffoli Gate

The Toffoli Gate is a generalization of the CNOT gate for two-qubits. Its wire diagram is shown below. Note that it contains two control bits, which if they both have bit value 1, will “turn-on” the  ⊕  gate on the first qubit.

Exercises

(a) Construct a matrix representation for the Toffoli gate. (Hint: first construct a truth table for this gate).

(b) Operate the Toffoli on the three-qubit basis vectors constructed above. Show that these operations generate the truth table given in part (a).

Though the Toffoli gate has, from a historical perspective played an important role, many of the algorithms discussed in later chapters require only single qubit, and Control-2 qubit gates, for their implementation.