QCFundamentals home

Bra-Ket Notation for Quantum Computing

Bra-ket notation, also called Dirac notation, is a way to write vectors, inner products and linear operators. In quantum computing, it gives us a compact language for describing quantum states and the gates that act on them.

We'll build on the linear algebra we already know, work through examples with basis vectors, and finish with exercises using the Pauli operators.

What you will learn

  • Read bras and kets, and distinguish inner from outer products.
  • Write a vector as a sum of orthonormal basis vectors.
  • Express linear operators as outer products and apply them to kets.

Prerequisites

You should be comfortable with complex numbers and conjugation, vector spaces and bases, and the inner products and operators introduced in linear algebra.

Definitions

There are 4 fundamental objects we will use:

A Ket looks like this ∣v⟩\ket{v} and it will represent a vector.

A Bra looks like this ⟨v∣\bra{v}. It's a bit more tricky to define straight away so I'll defer a proper explanation until later on.

Next are operators. An operator will typically be represented by a capital roman letter e.g. AA. These will be the exact same as operators from the previous article.

And then just as before, we will have scalars represented as lowercase roman letters. The one slight difference we'll introduce here is that scalars can multiply bras, kets and operators:a∣v⟩a\ket{v}, b⟨v∣b\bra{v} or cAcA. We'll see more about what this means later. As alluded to in the previous article, we are primarily interested in the case when these scalars are complex numbers.

The Inner Product

With bra-ket notation we would represent the inner product of two vectors ∣v⟩\ket{v} and ∣w⟩\ket{w} as ⟨v∣w⟩\braket{v|w}. Notice that we've flipped the ket ∣v⟩\ket{v} into a bra ⟨v∣\bra{v} here. So this is in effect a bra acting on a ket. This is our first clue as to what a bra actually is.

We can represent the 3 rules discussed in the previous articles as such:

Linearity in the second argument

⟨u∣(a∣v⟩+b∣w⟩)=a⟨u∣v⟩+b⟨u∣w⟩\bra{u}\bigl(a\ket{v} + b\ket{w}\bigr) = a\braket{u|v} + b\braket{u|w}

Conjugate symmetry

⟨v∣w⟩=⟨w∣v⟩∗\braket{v|w}=\braket{w|v}^*

Positive definiteness

⟨v∣v⟩≥0  and  ⟨v∣v⟩=0⟷∣v⟩=0\braket{v|v}\geq0\ \ \text{and}\ \ \braket{v|v}=0 \longleftrightarrow \ket{v}=0

Outer Product

Another operation we can perform here is called the outer product. It looks like this: ∣v⟩⟨w∣\ket{v}\bra{w}. The result of this operation is an operator. We will define what this operator does in the following way:

∣u⟩⟨v∣∣w⟩≡⟨v∣w⟩∣u⟩\ket{u}\bra{v}\ket{w}\equiv\braket{v|w}\ket{u}

So when an outer product acts on a ket, we get the inner product of the right bra with that ket, multiplied as a coefficient of the left ket.

Remember, a bra acting on a ket (⟨v∣w⟩\braket{v|w}) gives us a scalar and a ket acting on a bra (∣v⟩⟨w∣\ket{v}\bra{w}) gives us an operator.

Bringing it all together

Now we've got some definitions in our mathematical toolkit, let's see what we can do with them!

To kick things off, I'll define some new notation. Instead of using ∣v⟩\ket{v} and ∣w⟩\ket{w} as vectors I'm going to define the following:

∣0⟩,∣1⟩,…,∣d−1⟩∈Vand⟨i∣j⟩={1 if i=j0 if i≠j\ket{0},\ket{1},\ldots,\ket{d-1} \in V \qquad \text{and} \qquad \braket{i|j}=\begin{cases}1\text{ if }i = j \\ 0\text{ if }i\neq j\end{cases}

So we have dd vectors in the dd-dimensional vector space VV, with labels from 0 to d−1d-1. Distinct basis vectors are orthogonal: their inner product is 0. Each vector is also normalised, with an inner product of 1 with itself.

So the vectors ∣0⟩,∣1⟩,…,∣d−1⟩\ket{0}, \ket{1}, \ldots, \ket{d-1} form an orthonormal basis of dimension dd.

An arbitrary vector ∣v⟩\ket{v} in our space VV can then be defined as:

∣v⟩=v0∣0⟩+v1∣1⟩+…+vd−1∣d−1⟩=∑i=0d−1vi∣i⟩\ket{v}= v_0\ket{0} + v_1\ket{1} + \ldots + v_{d-1}\ket{d-1} = \sum_{i=0}^{d-1}{v_i\ket{i}}

Linear operators as outer products

We've already seen how the outer product of two vectors can give us a linear operator. What we will show now is how we can represent a linear operator as a sum of coefficients of outer products.

The most basic operator we will investigate first is the identity operator:

I=∣0⟩⟨0∣+∣1⟩⟨1∣+…+∣d−1⟩⟨d−1∣=∑i=0d−1∣i⟩⟨i∣I = \ket{0}\bra{0} + \ket{1}\bra{1} + \ldots + \ket{d-1}\bra{d-1} = \sum_{i=0}^{d-1}\ket{i}\bra{i}

It might not be intuitive how that works at first, so let's try it out on our arbitrary vector ∣v⟩\ket{v} defined above:

I∣v⟩=(∑i∣i⟩⟨i∣)(∑jvj∣j⟩)I\ket{v} = \bigl(\sum_i\ket{i}\bra{i}\bigr)\bigl(\sum_j{v_j\ket{j}}\bigr)

Note here that I've changed the iterator ii to jj in the second sum to ease our calculation here.

Our operators are linear so they distribute over addition:

=∑i,j∣i⟩⟨i∣vj∣j⟩=∑i,jvj∣i⟩⟨i∣∣j⟩=∑i,jvj⟨i∣j⟩∣i⟩=\sum_{i,j}\ket{i}\bra{i}v_j\ket{j} \\[3ex] =\sum_{i,j}v_j\ket{i}\bra{i}\ket{j} \\[3ex] =\sum_{i,j}v_j\braket{i|j}\ket{i}

But we know from our definition from earlier that ⟨i∣j⟩\braket{i|j} is 0 when i≠ji\neq j and 1 when i=ji=j . This means we can simplify our sum to:

=∑ivi∣i⟩=∣v⟩=\sum_i v_i\ket{i} = \ket{v}

So we have proved that this does indeed implement the identity operator!

Here are some definitions of interesting 2-dimensional linear operators. Note that in these definitions we assume that ∣0⟩\ket{0} is the first basis vector and ∣1⟩\ket{1} is the second.

X=∣0⟩⟨1∣+∣1⟩⟨0∣Y=−i∣0⟩⟨1∣+i∣1⟩⟨0∣Z=∣0⟩⟨0∣−∣1⟩⟨1∣X = \ket{0}\bra{1} + \ket{1}\bra{0} \\[3ex] Y = -i\ket{0}\bra{1} + i\ket{1}\bra{0} \\[3ex] Z = \ket{0}\bra{0} - \ket{1}\bra{1}

Let's define a 2D vector ∣v⟩=a∣0⟩+b∣1⟩\ket{v} = a\ket{0} + b\ket{1} and see how the XX operator acts on it:

X∣v⟩=(∣0⟩⟨1∣+∣1⟩⟨0∣)(a∣0⟩+b∣1⟩)=a(∣0⟩⟨1∣+∣1⟩⟨0∣)∣0⟩+b(∣0⟩⟨1∣+∣1⟩⟨0∣)∣1⟩=a(∣0⟩⟨1∣∣0⟩+∣1⟩⟨0∣∣0⟩)+b(∣0⟩⟨1∣∣1⟩+∣1⟩⟨0∣∣1⟩)=a(⟨1∣0⟩∣0⟩+⟨0∣0⟩∣1⟩)+b(⟨1∣1⟩∣0⟩+⟨0∣1⟩∣1⟩)X\ket{v} = \bigl(\ket{0}\bra{1} + \ket{1}\bra{0}\bigr)\bigl(a\ket{0} + b\ket{1}\bigr) \\[3ex] = a\bigl(\ket{0}\bra{1} + \ket{1}\bra{0}\bigr)\ket{0} + b\bigl(\ket{0}\bra{1} + \ket{1}\bra{0}\bigr)\ket{1} \\[3ex] = a\bigl(\ket{0}\bra{1}\ket{0} + \ket{1}\bra{0}\ket{0}\bigr) + b\bigl(\ket{0}\bra{1}\ket{1} + \ket{1}\bra{0}\ket{1}\bigr) \\[3ex] = a\bigl(\braket{1|0}\ket{0} + \braket{0|0}\ket{1}\bigr) + b\bigl(\braket{1|1}\ket{0} + \braket{0|1}\ket{1}\bigr)

Then we apply our inner product rules in our definition:

=a(0∣0⟩+1∣1⟩)+b(1∣0⟩+0∣1⟩)=a∣1⟩+b∣0⟩= a\bigl(0\ket{0} + 1\ket{1}\bigr) + b\bigl(1\ket{0} + 0\ket{1}\bigr) \\[3ex] = a\ket{1} + b\ket{0}

So the effect of the XX operator was to flip the coefficients of ∣0⟩\ket{0} and ∣1⟩\ket{1}. I encourage you to have a play with the other operators and see what they do.

Let's take a second to reflect here, this is really interesting. Just in the same way that we can represent any vector as a sum of multiples of basis vectors, we can also represent any linear operator as a sum of multiples of outer-products of basis vectors. You may recall in the previous article where we said to define a linear operator, we only need to define how it acts on the basis vectors. And this proves just that. You can see, for example, in the definition of XX that it takes the basis vector ∣0⟩\ket{0} to ∣1⟩\ket{1} and the basis vector ∣1⟩\ket{1} to ∣0⟩\ket{0}.

Exercises

Exercise 1

Show that XY=iZXY = iZ.

Show solution

Exercise 2

Continuing on from the previous exercise, check what the other XX, YY and ZZ operators do when multiplied together. What patterns do you notice?

Show solution

Related lessons

  • Qubits: use bra-ket notation to describe quantum states and measurement.
  • Single Qubit Gates: see the Pauli operators act as quantum gates.
  • Grover Search: see how outer products describe reflections in a quantum algorithm.
> Next Chapter (Qubits and Gates)