Quantum Computation & Cryptography · Lecture 2

Lecture 2
Complex Linear Algebra and Dirac Notation

Week 1  |  the language of amplitudes  |  reading: Watrous Ch. 1, de Wolf Appendix A

Cartoon: multiplying by i is a quarter turnA stick figure points at an arrow lying along the real axis. A curved arrow swings it a quarter turn up to the imaginary axis. A speech bubble says: multiplying by i? That is just turning left. multiplying by i?that's just turning left. 1i x i
the imaginary unit is not imaginary; it is a rotation
In this lecture
  1. Why amplitudes need complex numbers
  2. Complex numbers as arrows
  3. Roots of unity: arrows that cancel
  4. Complex vectors and the inner product
  5. Dirac notation: kets, bras, brackets
  6. Outer products and projectors
  7. Unitary and Hermitian matrices
  8. The spectral theorem
  9. Try it in code
  10. Summary and exercises

In Lecture 1 we met amplitudes: numbers attached to the outcomes of a qubit, whose squared sizes are probabilities, and which, unlike probabilities, can cancel. This lecture builds the language they are written in. By the end you should be able to compute with complex numbers in both rectangular and polar form; add up roots of unity; take inner products in \(\mathbb C^n\) without forgetting the conjugate; move freely between column vectors and Dirac's kets and bras; and recognise the two families of matrices that run the rest of the course, unitary and Hermitian.

1 — Why amplitudes need complex numbers

The Lecture 1 example used real amplitudes, and a minus sign was enough to make two paths cancel. Why not stop there? Because between "reinforce" (+) and "cancel" (−) there is a whole circle of possibilities, and nature uses all of them. Two amplitudes of the same size can meet at any relative angle, and the result depends continuously on that angle. A plus or minus sign is just the two ends of that circle, and a complex number is exactly an arrow that can point anywhere on it.

There is also a practical reason. The six states that will appear in every lab this semester are \(|0\rangle,|1\rangle,|+\rangle,|-\rangle\) and two more, \(|{+i}\rangle\) and \(|{-i}\rangle\), and the last two cannot be written with real numbers at all. Neither can the gates that rotate one into another, and neither can the quantum Fourier transform at the heart of Shor's algorithm. So we need complex numbers. The good news is that you need them only as arrows: the algebra is the algebra of rotating and stretching.

history — the numbers nobody wanted

Complex numbers were not invented to be useful; they forced their way in. In 1545 Gerolamo Cardano published a formula for solving cubic equations, and it had an embarrassing habit: for some cubics with three perfectly real answers, the formula passed through square roots of negative numbers on the way. In 1572 Rafael Bombelli simply wrote down rules for calculating with these objects and watched the imaginary parts cancel to give the right real answers. René Descartes named them "imaginary" in 1637, meaning it as an insult. In 1748 Leonhard Euler found \(e^{i\theta}=\cos\theta+i\sin\theta\), and around 1800 Caspar Wessel and Jean-Robert Argand drew them as points in a plane. Four centuries later, they are the native language of the smallest things in the universe.

2 — Complex numbers as arrows

definition 2.1 — complex number, conjugate, modulus

A complex number is \(z=a+bi\) with \(a,b\) real and \(i^2=-1\). We draw it as the point, or arrow, \((a,b)\) in the plane. Its conjugate is its mirror image across the real axis, and its modulus is its length:

$$\bar z=a-bi,\qquad |z|=\sqrt{a^2+b^2},\qquad |z|^2=z\,\bar z .$$

The identity \(|z|^2=z\bar z\) is the one to remember: multiplying a number by its own conjugate kills the imaginary part and leaves the squared length. It is why conjugates will appear in every inner product below.

An arrow can also be described by its length \(r=|z|\) and the angle \(\theta\) it makes with the positive real axis, its argument or phase. Euler's formula packages the pair into one symbol:

$$z=r\,(\cos\theta+i\sin\theta)=r\,e^{i\theta}.$$
proposition 2.1 — multiplication is rotate-and-stretch

If \(z=r\,e^{i\theta}\) and \(w=s\,e^{i\varphi}\), then

$$z\,w=rs\;e^{i(\theta+\varphi)},\qquad \frac{z}{w}=\frac{r}{s}\;e^{i(\theta-\varphi)},\qquad \bar z=r\,e^{-i\theta}.$$

Lengths multiply and angles add. In particular, multiplying by \(e^{i\varphi}\), a number of length 1, is a pure rotation by \(\varphi\). Multiplying by \(i=e^{i\pi/2}\) is a quarter turn, and multiplying by \(-1=e^{i\pi}\) is a half turn.

Expand with the angle-addition formulas:

$$\begin{aligned}(\cos\theta+i\sin\theta)(\cos\varphi+i\sin\varphi)&=(\cos\theta\cos\varphi-\sin\theta\sin\varphi)\\[4pt] &\quad+i(\sin\theta\cos\varphi+\cos\theta\sin\varphi)\\[4pt] &=\cos(\theta+\varphi)+i\sin(\theta+\varphi).\end{aligned}$$

Multiply by \(rs\) for the first identity. The second follows because \(w\cdot\tfrac1s e^{-i\varphi}=1\), and the third because \(\overline{\cos\theta+i\sin\theta}=\cos(-\theta)+i\sin(-\theta)\).

Let \(z=2e^{i\pi/3}\) and \(w=3e^{i\pi/6}\). Find the length and the phase (in radians) of \(zw\).

Proposition 2.1: lengths multiply and angles add. You never need rectangular form here.
\(|zw|=2\cdot3=6\) and the phase is \(\tfrac\pi3+\tfrac\pi6=\tfrac\pi2\), so \(zw=6e^{i\pi/2}=6i\).
example 2.1 — rectangular versus polar

Let \(z=\sqrt3+i\) and \(w=1+i\). Write both in polar form, then find \(zw\) and \(z/w\) in both forms. Check that the two methods agree.

\(|z|=\sqrt{3+1}=2\) at angle \(\pi/6\), and \(|w|=\sqrt2\) at angle \(\pi/4\). So

$$z=2e^{i\pi/6},\qquad w=\sqrt2\,e^{i\pi/4}.$$

Polar: lengths multiply and angles add,

$$zw=2\sqrt2\;e^{i\,5\pi/12},\qquad \frac zw=\sqrt2\;e^{-i\pi/12}.$$

Rectangular: expand, using \(i^2=-1\),

$$zw=(\sqrt3+i)(1+i)=\sqrt3+\sqrt3\,i+i+i^2=(\sqrt3-1)+(\sqrt3+1)\,i .$$

Check the length: \((\sqrt3-1)^2+(\sqrt3+1)^2=2(3+1)=8\), and \(\sqrt8=2\sqrt2\). For the quotient, multiply top and bottom by \(\bar w\) so that the denominator becomes the real number \(|w|^2\):

$$\frac{z}{w}=\frac{z\,\bar w}{|w|^2}=\frac{(\sqrt3+i)(1-i)}{2}=\frac{(\sqrt3+1)+(1-\sqrt3)\,i}{2}.$$

Rectangular form is best for adding; polar form is best for multiplying. Quantum computing does a lot of both.

The complex number z = sqrt(3) + i, its conjugate, and i times zComplex plane with real axis horizontal and imaginary axis vertical. The point z = sqrt(3) + i sits at distance 2 from the origin at angle 30 degrees. Its conjugate sqrt(3) - i is the mirror image across the real axis, at angle minus 30 degrees. The point i z = -1 + i sqrt(3) is z turned a quarter turn counterclockwise, at angle 120 degrees and the same distance 2. A dashed circle of radius 2 passes through all three.ReIm-2-11234-2i-1i1i2i30 degtimes i: +90 degz = sqrt3 + iconj(z) = sqrt3 - iiz = -1 + i sqrt3|z| = 2
The number \(z=\sqrt3+i\) has length 2 and phase \(30^\circ\). Its conjugate is the mirror image; multiplying by \(i\) turns it a quarter turn to \(iz=-1+i\sqrt3\), at \(120^\circ\), without changing its length.

Multiply two arrows

Set the length and phase of \(z\) (blue) and \(w\) (gold). The product \(zw\) (rose) has length \(|z||w|\) and phase equal to the sum of the phases. Set \(|w|=1\) to see a pure rotation.

idea — phase is the part you cannot see

Probabilities are squared lengths, \(|z|^2\), so they cannot see phase at all: \(e^{i\theta}\) has length 1 for every \(\theta\). Yet phase decides what happens when two amplitudes meet, because it decides whether their arrows line up or point apart. Much of quantum computing is the craft of steering phases you cannot observe directly so that, at the moment of measurement, they have arranged themselves into lengths you can.

Two amplitudes of length 1 meet with a relative phase of \(60^\circ\). Compute \(\big|1+e^{i\pi/3}\big|^2\).

Write \(e^{i\pi/3}=\tfrac12+\tfrac{\sqrt3}{2}i\), add 1, then take (real part)\(^2\) + (imaginary part)\(^2\). It is not \(1^2+1^2\): lengths do not add like that unless the arrows are perpendicular.
\(1+e^{i\pi/3}=\tfrac32+\tfrac{\sqrt3}2i\), whose squared length is \(\tfrac94+\tfrac34=3\): between the 4 of "in phase" and the 0 of "opposite".

3 — Roots of unity: arrows that cancel

definition 2.2 — roots of unity

For a whole number \(N\ge1\), let \(\omega=e^{2\pi i/N}\). The \(N\)th roots of unity are the \(N\) numbers

$$1,\;\omega,\;\omega^2,\;\dots,\;\omega^{N-1},$$

equally spaced around the unit circle. Each satisfies \(z^N=1\), and \(\omega^N=1\) means the powers repeat with period \(N\).

proposition 2.2 — the cancellation identity

For every whole number \(j\),

$$\sum_{k=0}^{N-1}\omega^{jk}=\begin{cases}N, & \text{if } N \text{ divides } j,\\[4pt] 0, & \text{otherwise.}\end{cases}$$

Write \(q=\omega^j\). If \(N\) divides \(j\), then \(q=1\) and the sum is \(1+1+\dots+1=N\). Otherwise \(q\neq1\), and the geometric-series formula applies:

$$\sum_{k=0}^{N-1}q^k=\frac{q^N-1}{q-1}=\frac{(\omega^N)^j-1}{q-1}=\frac{1-1}{q-1}=0 .$$

Geometrically, the arrows \(q^0,q^1,\dots,q^{N-1}\) are spread symmetrically around the circle, so they pull equally in every direction and cancel.

Let \(\omega=e^{2\pi i/10}\). Then \(\sum_{k=0}^{9}\omega^{5k}\) equals and \(\sum_{k=0}^{9}\omega^{20k}\) equals .

Proposition 2.2 with \(N=10\): ask whether 10 divides \(j\).
10 does not divide 5, so the first sum is 0 (the terms alternate \(+1,-1\)); 10 divides 20, so every term is 1 and the second sum is 10.
example 2.2 — the fourth roots

List the fourth roots of unity and compute \(\sum_{k=0}^{3} i^{2k}\) and \(\sum_{k=0}^{3} i^{4k}\) directly. Check the answers against Proposition 2.2.

Here \(\omega=e^{2\pi i/4}=i\), so the roots are \(1,\,i,\,-1,\,-i\): quarter turns around the circle. Then \(\sum i^{2k}=1-1+1-1=0\), matching \(j=2\), which 4 does not divide. And \(\sum i^{4k}=1+1+1+1=4\), matching \(j=4\), which 4 divides.

Adding the sixth roots of unity, head to tailThree panels. Each adds the six numbers omega to the power j k, for k = 0 to 5, where omega = e^(2 pi i/6), by laying unit arrows head to tail. Left, j = 1: the arrows turn 60 degrees each time and trace a closed hexagon, so the sum is 0. Middle, j = 2: the arrows turn 120 degrees and trace a triangle twice, sum 0. Right, j = 6: every arrow points the same way, so they line up and the sum is 6.startj = 1: hexagon closessum = 0startj = 2: triangle, twicesum = 0startj = 6: all alignedsum = 6omega = e^(2 pi i / 6); each panel adds omega^(j k) for k = 0,...,5
Adding the six numbers \(\omega^{jk}\) (\(\omega=e^{2\pi i/6}\)) by laying unit arrows head to tail. When 6 does not divide \(j\) the walk returns to its start and the sum is 0; when it does, every arrow points the same way and the sum is 6.

Walk the roots of unity

Choose \(N\) and \(j\). Left: the \(N\) arrows \(\omega^{jk}\) on the unit circle. Right: the same arrows laid head to tail. The walk closes unless \(N\) divides \(j\). Try \(N=8\) with \(j=2\), \(4\) and \(8\).

crypto connection — the engine of Shor's algorithm

Proposition 2.2 looks like a curiosity. It is the single most important identity in this course. The quantum Fourier transform (Lecture 13) sends a state that repeats with some hidden period into a state concentrated on multiples of \(N\) divided by that period. It works because every other outcome collects a sum of roots of unity that cancels exactly. Shor's algorithm uses that to find the period of \(a^x \bmod N\), and from the period it factors \(N\) and breaks RSA. When you see a quantum speedup, look for a sum of roots of unity quietly adding up to zero.

4 — Complex vectors and the inner product

A qubit state lives in \(\mathbb C^2\), and \(n\) qubits live in \(\mathbb C^{2^n}\). Vectors there add and scale exactly as in \(\mathbb R^n\). The one thing that changes is how we measure lengths and angles.

Try the real formula on \(u=(1,\,i)\): \(u_1^2+u_2^2=1+i^2=0\). A nonzero vector of "length zero" is useless, so the real dot product has to be repaired. The repair is the identity \(|z|^2=z\bar z\): conjugate one side.

definition 2.3 — inner product and norm on \(\mathbb C^n\)

For \(u,v\in\mathbb C^n\),

$$\langle u,v\rangle=\sum_{k=1}^{n}\overline{u_k}\,v_k,\qquad \lVert u\rVert=\sqrt{\langle u,u\rangle}=\sqrt{\sum_k |u_k|^2}.$$

The conjugate goes on the first vector; this is the physicists' convention, and the one Qiskit and NumPy's vdot use. Two vectors are orthogonal if \(\langle u,v\rangle=0\). A basis of unit vectors that are pairwise orthogonal is orthonormal.

Three properties do all the work. The inner product is linear in the second slot; swapping the slots conjugates it, \(\langle v,u\rangle=\overline{\langle u,v\rangle}\); and \(\langle u,u\rangle\ge0\), with equality only for \(u=0\). The second property is new: in \(\mathbb C^n\) the order of an inner product matters.

Let \(u=(i,\;2)\) and \(v=(1+i,\;1)\). Compute \(\langle u,v\rangle\) and give its real and imaginary parts.

Conjugate the first vector: \(\bar u=(-i,\;2)\). Then \(\langle u,v\rangle=(-i)(1+i)+2\cdot1\).
\((-i)(1+i)=-i+1\), so \(\langle u,v\rangle=3-i\). Without the conjugate you would get \(1+i\).
example 2.3 — computing an inner product

Let \(u=(1,\;i)\) and \(v=(2,\;1-i)\). Find \(\langle u,v\rangle\), \(\langle v,u\rangle\), \(\lVert u\rVert\) and \(\lVert v\rVert\). What does the unconjugated formula give?

Conjugate the entries of \(u\) first: \(\bar u=(1,\,-i)\). Then

$$\langle u,v\rangle=1\cdot2+(-i)(1-i)=2-i+i^2=1-i,$$ $$\langle v,u\rangle=\overline{1-i}=1+i .$$

For the norms, \(\lVert u\rVert^2=|1|^2+|i|^2=2\) and \(\lVert v\rVert^2=4+|1-i|^2=4+2=6\), so \(\lVert u\rVert=\sqrt2\) and \(\lVert v\rVert=\sqrt6\). Without the conjugate you would get \(2+i(1-i)=3+i\), a different and meaningless number.

Orthonormal bases are useful because coordinates become inner products. If \(b_1,\dots,b_n\) is orthonormal, then every vector satisfies

$$v=\sum_k c_k\,b_k\qquad\text{with}\qquad c_k=\langle b_k,v\rangle .$$

No linear system to solve: just take inner products. To check, take the inner product of both sides with \(b_j\); every term vanishes except \(c_j\langle b_j,b_j\rangle=c_j\).

example 2.4 — the plus/minus basis

Show that \(b_+=\tfrac{1}{\sqrt2}(1,\,1)\) and \(b_-=\tfrac{1}{\sqrt2}(1,\,-1)\) form an orthonormal basis of \(\mathbb C^2\), and find the coordinates of a general state \((\alpha,\beta)\) in this basis.

\(\langle b_+,b_+\rangle=\tfrac12(1+1)=1\), likewise \(\langle b_-,b_-\rangle=1\), and \(\langle b_+,b_-\rangle=\tfrac12(1-1)=0\). Two orthonormal vectors in a 2-dimensional space form a basis. The coordinates are inner products:

$$c_+=\langle b_+,(\alpha,\beta)\rangle=\frac{\alpha+\beta}{\sqrt2},\qquad c_-=\langle b_-,(\alpha,\beta)\rangle=\frac{\alpha-\beta}{\sqrt2}.$$

For the Lecture 1 state \((0.6,\,0.8)\) this gives \(c_+=1.4/\sqrt2\approx0.990\) and \(c_-\approx-0.141\), exactly the numbers we got from the Hadamard gate. That is no coincidence, as Section 7 will show.

idea — a measurement is a choice of basis

Reading a qubit "in the standard basis" gives outcome \(k\) with probability \(|\text{coordinate } k|^2\). Nothing is special about the standard basis. Pick any orthonormal basis, compute the coordinates of your state by inner products, and their squared lengths are the probabilities of a different measurement. The state stays the same; the question you ask it changes. This is the Born rule, and Lecture 3 makes it official.

5 — Dirac notation: kets, bras, brackets

Physicists write quantum states in a notation invented by Paul Dirac in 1939. It looks odd for about a week and then becomes indispensable, because the notation does half the algebra for you.

definition 2.4 — ket, bra, bracket

A ket \(|v\rangle\) is a column vector. Its bra \(\langle v|\) is the conjugate transpose, a row vector. Putting a bra next to a ket multiplies them as matrices and produces the inner product, a bracket:

$$|v\rangle=\begin{pmatrix}v_1\\[2pt] \vdots\\[2pt] v_n\end{pmatrix},\qquad \langle v|=\begin{pmatrix}\overline{v_1} & \cdots & \overline{v_n}\end{pmatrix},\qquad \langle u|v\rangle=\langle u|\,|v\rangle=\sum_k\overline{u_k}\,v_k .$$

The label inside the ket is just a name. \(|0\rangle\), \(|+\rangle\) and \(|\psi\rangle\) are vectors named 0, plus and psi.

The six single-qubit states below will follow us all semester. The first two are the standard basis; each row pair is an orthonormal basis.

ketcolumnbra (conjugate row)basis
\(|0\rangle\), \(|1\rangle\)\((1,0)^{\mathsf T}\), \((0,1)^{\mathsf T}\)\((1\;\;0)\), \((0\;\;1)\)standard (Z)
\(|\pm\rangle\)\(\tfrac{1}{\sqrt2}(1,\,\pm1)^{\mathsf T}\)\(\tfrac{1}{\sqrt2}(1\;\;\pm1)\)Hadamard (X)
\(|{\pm i}\rangle\)\(\tfrac{1}{\sqrt2}(1,\,\pm i)^{\mathsf T}\)\(\tfrac{1}{\sqrt2}(1\;\;\mp i)\)circular (Y)

Notice the \(\mp\) in the last bra: the conjugate flips the sign of \(i\). The standard basis turns any vector into kets immediately: \((\alpha,\beta)^{\mathsf T}=\alpha|0\rangle+\beta|1\rangle\).

What is the bra of \(|\psi\rangle=\tfrac12\big(\sqrt3\,|0\rangle-i|1\rangle\big)\)?

Definition 2.4: transpose to a row, and conjugate every entry.
Conjugating \(-i\) gives \(+i\) and leaves \(\sqrt3\) unchanged, so \(\langle\psi|=\tfrac12(\sqrt3\;\;i)\).
example 2.5 — the conjugate at work

Show that \(|{+i}\rangle\) and \(|{-i}\rangle\) are orthogonal. Then compute the same product without the conjugate and see what goes wrong.

The bra of \(|{+i}\rangle\) is \(\tfrac1{\sqrt2}(1\;\;-i)\). So

$$\begin{aligned}\langle{+i}|{-i}\rangle&=\frac12\begin{pmatrix}1 & -i\end{pmatrix}\begin{pmatrix}1\\[2pt] -i\end{pmatrix}\\[4pt] &=\frac12\big(1+(-i)(-i)\big)=\frac12(1+i^2)=\frac12(1-1)=0 .\end{aligned}$$

Forgetting to conjugate gives \(\tfrac12(1\cdot1+i\cdot(-i))=\tfrac12(1+1)=1\): the two states would look identical instead of perfectly distinguishable. This is the most common slip in all of this material.

Bra-ket calculator

Pick a bra and a ket. The readout shows the bracket \(\langle u|v\rangle\), its squared size (the probability that a measurement in the \(u\)-basis finds \(|v\rangle\) looking like \(|u\rangle\)), and what you get if you forget the conjugate.

idea — why the notation is worth it

In Dirac notation, a bra next to a ket is a number and a ket next to a bra is a matrix. The shapes enforce the algebra: \(\langle u|v\rangle\) can only be a scalar, and \(|u\rangle\langle v|\), coming next, can only be a matrix. Once you trust the shapes, long calculations become bookkeeping: move the brackets around and let the scalars fall out.

6 — Outer products and projectors

definition 2.5 — outer product, projector

The outer product \(|u\rangle\langle v|\) is the matrix column times row. It acts on a ket by

$$\big(|u\rangle\langle v|\big)\,|w\rangle=|u\rangle\,\langle v|w\rangle=\langle v|w\rangle\,|u\rangle .$$

If \(|u\rangle\) is a unit vector, \(P_u=|u\rangle\langle u|\) is the projector onto the line through \(|u\rangle\): it keeps the \(|u\rangle\)-component of any vector and discards the rest.

Projecting a vector onto a lineA unit vector u at 30 degrees spans a line. A vector v = (1.5, 2) is projected onto the line: the projection P v = (u . v) u lands at about (1.99, 1.15), and the leftover v - P v meets the line at a right angle.line spanned by uuvPv = (u.v) uv - Pvu.v = 2.299
A real picture of a projector. \(P=|u\rangle\langle u|\) sends \(v\) to its shadow \(\langle u|v\rangle\,u\) on the line through \(u\), and the leftover \(v-Pv\) is perpendicular to that line. Here \(u\) is at \(30^\circ\), \(v=(1.5,\,2)\) and \(\langle u|v\rangle\approx2.299\).

Two facts follow straight from the notation. Projecting twice changes nothing, \(P_u^2=|u\rangle\langle u|u\rangle\langle u|=P_u\), because \(\langle u|u\rangle=1\). And the projectors onto an orthonormal basis add up to the identity, the completeness relation:

$$\sum_k |b_k\rangle\langle b_k|=I.$$

For example,

$$ |0\rangle\langle0|+|1\rangle\langle1|=|+\rangle\langle+|+|-\rangle\langle-|=I .$$

Completeness is the expansion \(v=\sum_k c_k b_k\) of Section 4 written as a matrix identity, and it will save you pages of algebra: you can insert \(I=\sum_k|b_k\rangle\langle b_k|\) anywhere in a calculation.

Let \(|u\rangle=0.6|0\rangle+0.8|1\rangle\). Find the top row of the projector \(P_u=|u\rangle\langle u|\).

Column times row: entry \((j,k)\) of \(|u\rangle\langle u|\) is \(u_j\,\overline{u_k}\).
The top row is \((0.6\cdot0.6,\;0.6\cdot0.8)=(0.36,\;0.48)\). The diagonal entries 0.36 and 0.64 are the outcome probabilities of \(|u\rangle\) in the standard basis.
example 2.6 — Lecture 1's coin was a projector

Write \(|+\rangle\langle+|\) as a matrix. Compare it with the fair-coin matrix \(F\) of Lecture 1. Then compute \(\langle\psi|\,P_+\,|\psi\rangle\) for \(|\psi\rangle=0.6|0\rangle+0.8|1\rangle\).

$$|+\rangle\langle+|=\frac{1}{\sqrt2}\begin{pmatrix}1\\[2pt] 1\end{pmatrix}\frac{1}{\sqrt2}\begin{pmatrix}1 & 1\end{pmatrix}=\frac12\begin{pmatrix}1 & 1\\[2pt] 1 & 1\end{pmatrix}=F .$$

The fair coin was a projector all along, which explains why applying it twice gave nothing new: \(F^2=F\). Next,

$$\langle\psi|P_+|\psi\rangle=\langle\psi|+\rangle\langle+|\psi\rangle=|\langle+|\psi\rangle|^2=\Big(\frac{0.6+0.8}{\sqrt2}\Big)^2=0.98 .$$

That is the probability 0.98 we found in Lecture 1, now computed as "how much of \(|\psi\rangle\) lies along \(|+\rangle\)". The pattern \(\langle\psi|P|\psi\rangle=\) probability is the general rule of measurement.

7 — Unitary and Hermitian matrices

definition 2.6 — adjoint

The adjoint (or conjugate transpose, or "dagger") of a matrix \(A\) is \(A^\dagger=\overline{A}^{\mathsf T}\). It is the matrix version of turning a ket into a bra: \((|v\rangle)^\dagger=\langle v|\). It reverses products and moves across brackets:

$$(AB)^\dagger=B^\dagger A^\dagger,\qquad \langle u|\,A\,v\rangle=\langle A^\dagger u\,|\,v\rangle .$$
definition 2.7 — unitary matrix

A square matrix \(U\) is unitary if

$$U^\dagger U=I,$$

so \(U\) is invertible and its inverse is simply its adjoint. Unitary matrices are the quantum gates: every step of a quantum computation, short of measurement, is one.

proposition 2.3 — what unitaries preserve

If \(U\) is unitary, then (a) \(\langle Uu|Uv\rangle=\langle u|v\rangle\) for all \(u,v\), so \(U\) preserves lengths, angles and orthogonality; (b) the columns of \(U\) form an orthonormal basis; (c) every eigenvalue of \(U\) has \(|\lambda|=1\).

(a) Move \(U\) across the bracket: \(\langle Uu|Uv\rangle=\langle u|U^\dagger U v\rangle=\langle u|v\rangle\).

(b) The \((j,k)\) entry of \(U^\dagger U\) is (row \(j\) of \(U^\dagger\)) times (column \(k\) of \(U\)), which is \(\langle \text{col}_j|\text{col}_k\rangle\). Setting \(U^\dagger U=I\) says exactly that these brackets are 1 when \(j=k\) and 0 otherwise. (The converse, that orthonormal columns make \(U\) unitary, is HW1.)

(c) Save it for exercise 6.

A unitary matrix has an eigenvalue \(\lambda\). Which of these could \(\lambda\) be?

Proposition 2.3: \(U\) preserves lengths, and \(\lVert Uv\rVert=\lVert\lambda v\rVert=|\lambda|\,\lVert v\rVert\).
Only \(\tfrac{1+i}{\sqrt2}=e^{i\pi/4}\) has \(|\lambda|=1\). It really occurs, for instance as an eigenvalue of \(\mathrm{diag}(1,e^{i\pi/4})\).
definition 2.8 — Hermitian matrix

A square matrix \(A\) is Hermitian if \(A^\dagger=A\): it equals its own conjugate transpose. Hermitian matrices are the quantum version of real numbers. They will describe measurements and energies, and their key property is that their eigenvalues are real.

Tick every Hermitian matrix.

For each matrix, conjugate every entry and transpose. Is the result the same matrix?
The first, third and fifth equal their conjugate transposes. The second is only symmetric, and the fourth has imaginary diagonal entries.
proposition 2.4 — Hermitian matrices have real eigenvalues

If \(A^\dagger=A\) and \(A|v\rangle=\lambda|v\rangle\) with \(|v\rangle\neq0\), then \(\lambda\) is real. Eigenvectors for different eigenvalues are orthogonal.

Compute \(\langle v|A|v\rangle\) two ways. Using \(A|v\rangle=\lambda|v\rangle\) gives \(\lambda\langle v|v\rangle\). Moving \(A\) to the bra, \(\langle A^\dagger v|v\rangle=\langle Av|v\rangle=\bar\lambda\langle v|v\rangle\), where the conjugate appears because the first slot is conjugated. Since \(\langle v|v\rangle>0\), \(\lambda=\bar\lambda\). For orthogonality, if \(A|w\rangle=\mu|w\rangle\) with \(\mu\neq\lambda\), the same trick gives \(\lambda\langle w|v\rangle=\langle w|A|v\rangle=\mu\langle w|v\rangle\), so \(\langle w|v\rangle=0\).

example 2.7 — a gallery of gates

Decide which of these matrices are unitary and which are Hermitian:

$$X=\begin{pmatrix}0 & 1\\[2pt] 1 & 0\end{pmatrix},\qquad Y=\begin{pmatrix}0 & -i\\[2pt] i & 0\end{pmatrix},\qquad Z=\begin{pmatrix}1 & 0\\[2pt] 0 & -1\end{pmatrix},$$ $$H=\frac{1}{\sqrt2}\begin{pmatrix}1 & 1\\[2pt] 1 & -1\end{pmatrix},\qquad S=\begin{pmatrix}1 & 0\\[2pt] 0 & i\end{pmatrix},\qquad F=\frac12\begin{pmatrix}1 & 1\\[2pt] 1 & 1\end{pmatrix}.$$
matrixunitary?Hermitian?reason
\(X,\;Y,\;Z\)yesyescolumns orthonormal, and each equals its conjugate transpose
\(H\)yesyesreal and symmetric, and \(H^2=I\), so \(H^\dagger H=H^2=I\)
\(S\)yesno\(S^\dagger=\mathrm{diag}(1,-i)\neq S\), but \(S^\dagger S=\mathrm{diag}(1,|i|^2)=I\)
\(F\)noyes\(\det F=0\): not invertible, so it cannot be unitary

So unitary and Hermitian are independent properties. The Pauli matrices and \(H\) happen to be both, which is why they turn up both as gates and as measurements.

One more look at \(H\): its rows are the bras \(\langle+|\) and \(\langle-|\), so \(H|\psi\rangle=(\langle+|\psi\rangle,\;\langle-|\psi\rangle)\) lists the coordinates of \(|\psi\rangle\) in the plus/minus basis. That is why Example 2.4 reproduced the Lecture 1 numbers.

stochastic (Lecture 1)unitary (from now on)
acts onprobability vectorsamplitude vectors
preserves1-norm \(\sum p_k=1\)2-norm \(\sum|\psi_k|^2=1\)
entriesnonnegative realsany complex numbers
inverseusually none: information is lostalways, \(U^{-1}=U^\dagger\): nothing is lost
examplefair coin \(F\)Hadamard \(H\)
idea — quantum computation runs backwards

The last row of the table is profound. A fair coin destroys information: after flipping it you cannot tell what it was before. A unitary destroys nothing, since \(U^\dagger\) undoes it exactly. Between measurements a quantum computer is perfectly reversible, and the only irreversible step is measurement itself. This is why, in Lecture 7, even ordinary AND gates must be rebuilt in reversible form before a quantum computer can run them.

8 — The spectral theorem

theorem 2.5 — spectral theorem (statement)

Let \(A\) be Hermitian or unitary (more generally, normal: \(A^\dagger A=AA^\dagger\)). Then \(A\) has an orthonormal basis of eigenvectors \(|e_1\rangle,\dots,|e_n\rangle\) with eigenvalues \(\lambda_1,\dots,\lambda_n\), and

$$A=\sum_{k=1}^{n}\lambda_k\,|e_k\rangle\langle e_k| .$$

In words: every such matrix is a weighted sum of projectors onto perpendicular lines. It stretches each line by its own eigenvalue and leaves the lines perpendicular.

A matrix has eigenvector \(|+\rangle\) with eigenvalue 2 and eigenvector \(|-\rangle\) with eigenvalue 4, so \(A=2|+\rangle\langle+|+4|-\rangle\langle-|\). Find the top row of \(A\).

\(|+\rangle\langle+|=\tfrac12\begin{pmatrix}1&1\\ 1&1\end{pmatrix}\) and \(|-\rangle\langle-|=\tfrac12\begin{pmatrix}1&-1\\ -1&1\end{pmatrix}\). Weight them and add.
The top row is \(\big(\tfrac{2+4}{2},\ \tfrac{2-4}{2}\big)=(3,\,-1)\), so \(A=\begin{pmatrix}3&-1\\ -1&3\end{pmatrix}\).
idea — what about matrices that are not normal?

Many matrices have no orthonormal basis of eigenvectors. The shear

$$\begin{pmatrix}1&1\\[2pt] 0&1\end{pmatrix}$$

has the single eigenvalue 1 and only one eigenvector direction, so it cannot be diagonalised at all. Lecture 5 needs to analyse arbitrary \(2\times2\) matrices (the coefficient matrices of two-qubit states), and there we meet the singular value decomposition, which works for every matrix by using two orthonormal bases instead of one. It is built from this theorem, applied to the Hermitian matrix \(A^\dagger A\).

example 2.8 — decomposing X

Find the eigenvalues and eigenvectors of \(X\) and write its spectral decomposition.

\(X\) swaps the two entries of a vector, so it fixes \((1,1)\) and negates \((1,-1)\): \(X|+\rangle=|+\rangle\) and \(X|-\rangle=-|-\rangle\). Hence

$$\begin{aligned}X&=(+1)\,|+\rangle\langle+|+(-1)\,|-\rangle\langle-|\\[4pt] &=\frac12\begin{pmatrix}1 & 1\\[2pt] 1 & 1\end{pmatrix}-\frac12\begin{pmatrix}1 & -1\\[2pt] -1 & 1\end{pmatrix}=\begin{pmatrix}0 & 1\\[2pt] 1 & 0\end{pmatrix}.\end{aligned}$$
Pauli matrixeigenvalue \(+1\)eigenvalue \(-1\)spectral form
\(Z\)\(|0\rangle\)\(|1\rangle\)\(|0\rangle\langle0|-|1\rangle\langle1|\)
\(X\)\(|+\rangle\)\(|-\rangle\)\(|+\rangle\langle+|-|-\rangle\langle-|\)
\(Y\)\(|{+i}\rangle\)\(|{-i}\rangle\)\(|{+i}\rangle\langle{+i}|-|{-i}\rangle\langle{-i}|\)

This is why the three bases in the Section 5 table are named Z, X and Y: each is the eigenbasis of one Pauli matrix.

Going further: functions of a matrix, and a square root of NOT

The spectral form lets you apply any function to a matrix by applying it to the eigenvalues:

$$f(A)=\sum_k f(\lambda_k)\,|e_k\rangle\langle e_k| .$$

Here is a gate that no classical machine can have. Take \(f(\lambda)=\sqrt\lambda\) for \(X\), choosing \(\sqrt{1}=1\) and \(\sqrt{-1}=i\):

$$\sqrt{X}=|+\rangle\langle+|+i\,|-\rangle\langle-|=\frac12\begin{pmatrix}1+i & 1-i\\[2pt] 1-i & 1+i\end{pmatrix}.$$

It is unitary, and applying it twice gives \(|+\rangle\langle+|+i^2|-\rangle\langle-|=X\): a genuine "half of a NOT".

proposition 2.6 — no random process is half of a NOT

There is no \(2\times2\) stochastic matrix \(M\) with \(M^2=\mathrm{NOT}\).

Every \(2\times2\) stochastic matrix has the form

$$M=\begin{pmatrix}a & b\\[2pt] 1-a & 1-b\end{pmatrix},\qquad 0\le a,b\le1 .$$

Its columns sum to 1, so \((1\;\;1)\,M=(1\;\;1)\) and \(1\) is an eigenvalue. The eigenvalues add up to the trace \(a+1-b\), so the other eigenvalue is the real number \(a-b\). The eigenvalues of \(M^2\) are therefore \(1\) and \((a-b)^2\ge0\). But NOT has eigenvalue \(-1\), so \(M^2\neq\mathrm{NOT}\).

idea — what the square root of NOT tells you

Probabilities are stuck on the nonnegative half of the number line, so they cannot take the square root of \(-1\). Amplitudes live on the whole complex plane, where \(i\) is waiting. That single extra degree of freedom is enough to create operations with no classical counterpart, and "half a NOT" is the simplest one you can hold in your hand.

9 — Try it in code

tool — inner products, adjoints, eigenvectors (numpy)
import numpy as np

u = np.array([1, 1j])
v = np.array([2, 1 - 1j])
print(np.vdot(u, v))          # <u|v>: vdot conjugates its FIRST argument
print(u @ v)                  # plain dot product: no conjugate, wrong for C^n

H = np.array([[1, 1], [1, -1]]) / np.sqrt(2)
S = np.array([[1, 0], [0, 1j]])
print((S.conj().T @ S).round(12))      # S-dagger S: the identity, so S is unitary
print(np.allclose(S.conj().T, S))      # is S Hermitian?

X = np.array([[0, 1], [1, 0]])
vals, vecs = np.linalg.eigh(X)         # eigh: for Hermitian matrices
print(vals)
print(vecs.round(4))                   # columns: eigenvectors, each up to a sign
(1-1j)
(3+1j)
[[1.+0.j 0.+0.j]
 [0.+0.j 1.+0.j]]
False
[-1.  1.]
[[-0.7071  0.7071]
 [ 0.7071  0.7071]]

The first eigenvector column is \(-|-\rangle\) rather than \(|-\rangle\). Both are fine: an eigenvector times any nonzero number, including \(-1\), is still an eigenvector. In HW1 you will package the unitarity check into a function of your own.

tool — the same ideas in qiskit (tested with qiskit 2.5)
import numpy as np
from qiskit.quantum_info import Operator, Statevector
from qiskit.circuit.library import HGate, SGate

plus_i  = Statevector([1,  1j] / np.sqrt(2))
minus_i = Statevector([1, -1j] / np.sqrt(2))
print(plus_i.inner(minus_i))                        # <+i|-i>, conjugate included
print(Operator(HGate()).is_unitary(), Operator(SGate()).is_unitary())
print(Operator(SGate()).data)
0j
True True
[[1.+0.j 0.+0.j]
 [0.+0.j 0.+1.j]]

10 — Summary and exercises

summary

Next time: the qubit made official: the Born rule, global versus relative phase, and the Bloch sphere. HW1 is due at the start of Week 2, and Lab 1 launches in Lecture 4.

exercises 2
  1. Let \(z=1-i\sqrt3\). Find \(|z|\), its phase and its polar form; then compute \(\bar z\), \(z^2\) (in both forms) and \(1/z\).
  2. Let \(\omega=e^{2\pi i/8}\). Evaluate \(\sum_{k=0}^{7}\omega^{3k}\) and \(\sum_{k=0}^{7}\omega^{8k}\) without adding anything up. Then compute \(1+i+i^2+i^3\) directly.
  3. Let \(u=\tfrac{1}{\sqrt2}(1,\;i)\) and \(v=\tfrac12(1+i,\;1-i)\). Check that both are unit vectors and decide whether they are orthogonal.
  4. Show that \(Y\) is unitary and Hermitian, verify that \(|{\pm i}\rangle\) are its eigenvectors with eigenvalues \(\pm1\), and check the spectral form in the Pauli table.
  5. Write \(P=|{+i}\rangle\langle{+i}|\) as a matrix. Check that \(P^2=P\) and \(P^\dagger=P\), and compute \(\langle0|P|0\rangle\). What probability does that number represent?
  6. Prove part (c) of Proposition 2.3: if \(U\) is unitary and \(U|v\rangle=\lambda|v\rangle\) with \(|v\rangle\neq0\), then \(|\lambda|=1\).
  7. Is the fair-coin matrix \(F\) unitary? Answer in two ways: with a determinant, and with the reversibility idea of Section 7.
  1. \(|z|=\sqrt{1+3}=2\) and the phase is \(-\pi/3\), so \(z=2e^{-i\pi/3}\). Then \(\bar z=1+i\sqrt3=2e^{i\pi/3}\). Squaring in polar form gives \(z^2=4e^{-2\pi i/3}\); in rectangular form, \((1-i\sqrt3)^2=1-2i\sqrt3+3i^2=-2-2i\sqrt3\), which agrees. Finally \(1/z=\bar z/|z|^2=(1+i\sqrt3)/4=\tfrac12e^{i\pi/3}\).
  2. 8 does not divide 3, so the first sum is 0; 8 divides 8, so the second is 8. Directly, \(1+i+i^2+i^3=1+i-1-i=0\).
  3. \(\lVert u\rVert^2=\tfrac12(1+1)=1\) and \(\lVert v\rVert^2=\tfrac14(|1+i|^2+|1-i|^2)=\tfrac14(2+2)=1\). Then \(\langle u|v\rangle=\tfrac{1}{2\sqrt2}\big(1\cdot(1+i)+(-i)(1-i)\big)=\tfrac{1}{2\sqrt2}\big(1+i-i+i^2\big)=0\). Yes, they are orthogonal.
  4. Conjugate every entry of \(Y\), then transpose: $$\begin{pmatrix}0 & -i\\[2pt] i & 0\end{pmatrix}\;\xrightarrow{\ \text{conjugate}\ }\;\begin{pmatrix}0 & i\\[2pt] -i & 0\end{pmatrix}\;\xrightarrow{\ \text{transpose}\ }\;\begin{pmatrix}0 & -i\\[2pt] i & 0\end{pmatrix},$$ which is \(Y\) again. So \(Y^\dagger=Y\) and \(Y\) is Hermitian. Also \(Y^2=I\), so \(Y^\dagger Y=Y^2=I\) and \(Y\) is unitary. \(Y(1,\,i)^{\mathsf T}=(-i\cdot i,\;i\cdot1)^{\mathsf T}=(1,\,i)^{\mathsf T}\) and \(Y(1,\,-i)^{\mathsf T}=(-1,\,i)^{\mathsf T}=-(1,\,-i)^{\mathsf T}\). The spectral form follows from Theorem 2.5.
  5. $$P=\frac{1}{\sqrt2}\begin{pmatrix}1\\[2pt] i\end{pmatrix}\frac{1}{\sqrt2}\begin{pmatrix}1 & -i\end{pmatrix}=\frac12\begin{pmatrix}1 & -i\\[2pt] i & 1\end{pmatrix}.$$ Direct multiplication gives \(P^2=P\), and conjugating and transposing gives \(P^\dagger=P\). \(\langle0|P|0\rangle=P_{11}=\tfrac12=|\langle{+i}|0\rangle|^2\): the probability that \(|0\rangle\) is found to be \(|{+i}\rangle\) when measured in the Y basis.
  6. By Proposition 2.3(a), \(\lVert v\rVert=\lVert Uv\rVert=\lVert\lambda v\rVert=|\lambda|\,\lVert v\rVert\), and \(\lVert v\rVert\neq0\), so \(|\lambda|=1\).
  7. No. \(\det F=\tfrac14-\tfrac14=0\), so \(F\) has no inverse, while every unitary does. In terms of information, \(F\) sends both \(|0\rangle\) and \(|1\rangle\) to the same vector \(\tfrac12(1,1)\), so its input cannot be recovered from its output, and a unitary never loses information.

Reading and sources

all numbers and figures in these notes are computed in python (verify_L02.py) and follow the page theme