Quantum Computing · Chapter 17

Linear Algebra & Calculus Prerequisites

This chapter is the mathematical toolbox for everything else in quantum computing. Starting from vectors written in Dirac's "bra-ket" notation, it builds up inner products, linear operators and their matrices, the special families of operators (Hermitian, unitary, normal, positive) that quantum mechanics relies on, and the spectral theorem that lets us diagonalize them. It then covers tensor products (how to combine qubits), a refresher on complex numbers, and the number theory and continued fractions needed later for Shor's factoring algorithm. Everything assumes only high-school linear algebra and calculus, and each idea is stated precisely and then illustrated with worked examples.

≈ 120 min read68 worked examplesOriginal PDF ↗

The following content assumes a high school level understanding of Linear Algebra, Complex numbers, Probability, single-variable Calculus (Multi-Variable Calculus will be a plus) and Differential Equations. It contains all the pre-requisites required for understanding the contents of the given book. Standard references on quantum computation and linear algebra have been extensively used for the preparation of this appendix (see references). Note that this content assumes that the reader has only high school level exposure of the Quantum Mechanics (De Broglie Hypothesis, Schrödinger Equation, Young's Double Slit Experiment, Heisenberg's Uncertainty Principle) but still the important concepts of Quantum Mechanics are explained up to the required depth whenever it is found to be necessary for the explanation of Quantum computing concepts. A college level exposure of Quantum Mechanics will be a plus.

For a quick revision of the concepts of Linear Algebra the reader is suggested to watch the YouTube lectures by 3Blue1Brown. If it still feels difficult to follow the material, lectures by MIT Prof. Gilbert Strang on Linear Algebra are highly recommended. For basic Quantum Mechanics concepts, the reader is suggested to watch the lectures by MIT Prof. Allan Adams and for the mathematics of Quantum Mechanics, the lectures by MIT Prof. Barton Zwiebach are highly recommended. For the mathematics of Quantum Computing the short YouTube lectures by Quantum Sense and Advanced Maths will be helpful. Hope that these notes help in understanding the basics of Quantum Computing. For the coding part, you can also follow lectures by Qiskit and John Watrous. Many more such YouTube lectures are available, such as lectures by John Preskill. Short YouTube lectures covering the maths by David Deutsch and Michael Nielsen.

17.1 Linear Algebra

Mathematical Notation

For a complex number \(c=a+\iota b \in \mathbb{C}\) with \(a,b\in \mathbb{R}\) and \(\iota =\sqrt{-1}\), we use \(c^*=a-\iota b\) (or \(\overline{c}\)) to denote its complex conjugate. We will also need mathematical notation that is used throughout quantum information. Here we write vectors in a special way known as the "bra-ket" notation. While it may look a little cumbersome at first sight, it turns out to provide a convenient way of dealing with the many operations we will perform with such vectors. Let's start with two examples. We write \(\ket{v} \in \mathbb{C}^2\) to denote a vector in a 2-dimensional vector space. For example,

\[ \ket{v}=\begin{pmatrix} 1 \\ 0 \end{pmatrix} \]

The "bra" of this vector is the conjugate transpose, which for our example looks like

\[ \bra{v} = ((\ket{v})^*)^T=\begin{pmatrix} 1^* \\ 0^* \end{pmatrix}^T=\begin{pmatrix} 1 & 0 \end{pmatrix} \]

The general definition of the "bra-ket" notation is as follows:

Definition — Ket and Bra notation

A ket, denoted \(\ket{.}\), represents a \(d\)-dimensional column vector in the complex vector space \(\mathbb{C}^d\). A bra, denoted \(\bra{.}\), is a \(d\)-dimensional row vector equal to the complex conjugate of the corresponding ket, namely

\[ \bra{.}=(\ket{.}^*)^T \]

where \(*\) denotes the entry-wise conjugate, and \(T\) denotes the transpose.

In plain terms: a "ket" \(\ket{v}\) is just a column of numbers, and its matching "bra" \(\bra{v}\) is the same list turned into a row with every number complex-conjugated. This bookkeeping notation keeps track of which vectors are columns and which are rows, which makes the multiplications later almost automatic.

Basics of Linear Algebra

Definition — Linear Transformation

A function \(T:V\rightarrow W\) is called a linear transformation if for all \(\ket{v},\ket{w}\in V\) and \(a\in\mathbb{F}\) the following properties hold:

  1. \(T(\ket{v}+\ket{w})=T(\ket{v})+T(\ket{w})\)
  2. \(T(a\ket{v})=aT(\ket{v})\)
Worked Example

Let \(V\) be a vector space over a field \(\mathbb{F}\) and let \(A\) be a matrix in \(\mathbb{F}^{m\times n}\). The function \(T:\mathbb{F}^{n}\rightarrow\mathbb{F}^{m}\) defined by \(T(\ket{v})=A\ket{v}\) is a linear transformation.

Worked Example

Differentiation, Integration, and the Laplace transform are examples of linear transformations.

Definition — Composition Transformation

Let \(T:V\rightarrow W\) and \(U:W\rightarrow X\) be linear transformations. The composition transformation \(UT:V\rightarrow X\) is defined by \((UT)(\ket{v})=U(T(\ket{v}))\). If the composition transformation is also a linear transformation then it is called a composite linear transformation. Here, if \(T\) and \(U\) are linear transformations then \(UT\) is also a linear transformation.

Definition — Inverse Transformation

Let \(T:V\rightarrow W\) be a linear transformation. A linear transformation \(T^{-1}:W\rightarrow V\) is called the inverse transformation of \(T\) if \(TT^{-1}=T^{-1}T=I\) where \(I\) is the identity transformation.

Definition — Field (\(\mathbb{F}\))

A field is a set of elements that is closed under two operations, addition and multiplication, and satisfies the following axioms. Let \(a,b,c\in\mathbb{F}\):

  1. Commutative Property of Addition: \(a+b=b+a\)
  2. Associative Property of Addition: \((a+b)+c=a+(b+c)\)
  3. Distributive Property of Addition: \(a(b+c)=ab+ac\)
  4. Additive Identity: There exists an element \(0\) in the field such that \(a+0=a\)
  5. Additive Inverse: For every element \(a\) in the field, there exists an element \(-a\) such that \(a+(-a)=0\)
  6. Commutative Property of Multiplication: \(ab=ba\)
  7. Associative Property of Multiplication: \((ab)c=a(bc)\)
  8. Distributive Property of Multiplication: \((a+b)c=ac+bc\)
  9. Multiplicative Identity: There exists an element \(1\) in the field such that \(a1=a\)
  10. Multiplicative Inverse: For every element \(a\) in the field, there exists an element \(a^{-1}\) such that \(aa^{-1}=1\)

Note that it is up to us how we define the addition and multiplication operations on the field \(\mathbb{F}\), but for the purpose of these notes we will assume that the operations are the usual addition and multiplication operations unless stated otherwise. A more formal definition of a field can be defined using group theory but the above definition is sufficient for the purpose of these notes. The complications and more precise definition are left to mathematicians, which can be found in any standard textbook on Abstract Algebra.

Worked Example

The set of Rational Numbers (\(\mathbb{Q}\)), the set of Real Numbers (\(\mathbb{R}\)), and the set of Complex Numbers (\(\mathbb{C}\)) are examples of fields.

Worked Example

The set of Integers (\(\mathbb{Z}\)) is not a field as it does not satisfy the multiplicative inverse axiom. The set of Natural Numbers and Whole numbers is not a field because it does not satisfy the additive inverse axiom.

Generally, we have represented vectors as \(\vec{v}\), or with a bold letter \(\mathbf{v}\), but for the purpose of Quantum Mechanics and Quantum Computing we prefer Dirac notation which represents vectors as \(\ket{v}\) solely for the purpose of simplifying the notation. The Dirac notation is also called the bra-ket notation. The symbol \(\ket{v}\) represents a column vector \(v\) called ket-\(v\) and the symbol \(\bra{v}\) represents a row vector called bra-\(v\).

Definition — Vector Space

A vector space over a field \(\mathbb{F}\) is a set \(V\) of elements called vectors, that is closed under two operations, addition and scalar multiplication:

  1. Vector Addition: For every pair of vectors \(\ket{u},\ket{v}\in V\), there exists a vector \(\ket{u}+\ket{v}\in V\) called the sum of \(\ket{u}\) and \(\ket{v}\)
  2. Scalar Multiplication: For every vector \(\ket{u}\in V\) and every scalar \(a\in\mathbb{F}\), there exists a vector \(a\ket{u}\in V\) called the scalar multiple of \(\ket{u}\) by \(a\)

and satisfies the following axioms. Let \(\ket{u},\ket{v},\ket{w}\in V\) and \(a,b\in\mathbb{F}\):

  1. Closure Property over Vector Addition: \(\ket{u}+\ket{v}\in V\)
  2. Commutative Property of Addition: \(\ket{u}+\ket{v}=\ket{v}+\ket{u}\)
  3. Associative Property of Addition: \((\ket{u}+\ket{v})+\ket{w}=\ket{u}+(\ket{v}+\ket{w})\)
  4. Additive Identity: There exists a vector \(\ket{0}\) in \(V\) such that \(\ket{u}+\ket{0}=\ket{u}\)
  5. Additive Inverse: For every vector \(\ket{u}\) in \(V\), there exists a vector \(-\ket{u}\) in \(V\) such that \(\ket{u}+(-\ket{u})=\ket{0}\)
  6. Closure Property over Scalar Multiplication: \(a\ket{u}\in V\)
  7. Distributive Property of Scalar Multiplication over Vector Addition: \(a(\ket{u}+\ket{v})=a\ket{u}+a\ket{v}\)
  8. Distributive Property of Scalar Multiplication over Field Addition: \((a+b)\ket{u}=a\ket{u}+b\ket{u}\)
  9. Associative Property of Scalar Multiplication: \(a(b\ket{u})=(ab)\ket{u}\)
  10. Multiplicative Identity: There exists a scalar \(1\) in \(\mathbb{F}\) such that \(1\ket{u}=\ket{u}\)

The above axioms imply:

  1. \(\ket{0}\) is unique, i.e. if \(\ket{0'}\) has all the properties of \(\ket{0}\) then \(\ket{0'}=\ket{0}\)
  2. \(\ket{-u}=-\ket{u}\)
  3. \(\ket{-u}\) is the unique additive inverse of \(\ket{u}\)
Worked Example

The set of Real numbers \(\mathbb{R}\) is a vector space over the field of Real numbers \(\mathbb{R}\). It is called a Real Vector Space. The set of Complex numbers \(\mathbb{C}\) is a vector space over the field of Complex numbers \(\mathbb{C}\). It is called a Complex Vector Space.

Note the adjective Real and Complex before a vector space is used to denote the field over which the vector space is defined. In these notes we will be mostly dealing with the Complex Vector Space since the Real Vector Space is a special case of the Complex Vector Space.

Any element that satisfies the above said axioms of a vector space is called a vector. When we generally refer to a vector, the picture of an arrow comes to our mind, but arrows are just one of the manifestations of a representation of a Real Vector Space. Thus, to make the reader move away from thinking of vectors as arrows, and be more general, below are a few examples of manifestations of vectors in a vector space.

Worked Example

Matrices are vectors in the vector space of \(n\times n\) matrices over a field \(\mathbb{F}\). The vector addition is defined as the element-wise addition of the matrices and the scalar multiplication is defined as the element-wise multiplication of the matrix by the scalar. It satisfies the axioms of a vector space. Thus, they are elements of a vector space. Note that matrices have no notion of length (magnitude) and direction unlike arrows.

Worked Example

Functions are vectors in the vector space of functions over a field \(\mathbb{F}\). The vector addition and scalar multiplication are defined as the usual addition of two functions and scalar multiplication is simply multiplying the function by the scalar respectively. It satisfies the above said axioms of a vector space. Thus, they are elements of a vector space. Note that functions have no notion of length (magnitude) and direction unlike arrows. The functions are an example of an infinite dimensional vector space unlike a discrete dimensional vector space (such as matrices, vectors).

Thus when we say vector we refer to any element of a vector space and not just arrows. The arrows are just one of the manifestations of vectors in a vector space and the other examples include matrices and functions. In Quantum mechanics we generally deal with Hilbert Space (Complex Vector Space with inner product defined, more about it later). In Quantum Computing, we deal with finite dimensional complex vector spaces. Thus, it could not be imagined as arrows since they deal with real vector spaces (but imagining as arrows helps in general).

Definition — Subspace

A subset \(W\) of a vector space \(V\) over a field \(\mathbb{F}\) is called a subspace of \(V\) if \(W\) is itself a vector space over \(\mathbb{F}\) with the same operations of addition and scalar multiplication defined on \(V\). Note that a subspace must always contain the zero vector \(\ket{0}\) of the vector space \(V\) to satisfy the additive identity axiom.

Worked Example

The set of all real symmetric matrices is a subspace of the vector space of all real matrices.

Definition — Linear Combination

Let \(V\) be a vector space over a field \(\mathbb{F}\) and let \(\ket{v_1},\ket{v_2},\ldots,\ket{v_n}\) be vectors in \(V\). A vector of the form

\[ a_1\ket{v_1}+a_2\ket{v_2}+\ldots+a_n\ket{v_n} \]

where \(a_1,a_2,\ldots,a_n\in\mathbb{F}\) is called a linear combination of \(\ket{v_1},\ket{v_2},\ldots,\ket{v_n}\).

Worked Example

\(3x^2+2x+1=0\) is a linear combination of \(\ket{v_1}=x^2\), \(\ket{v_2}=x\) and \(\ket{v_3}=1\) in the vector space of polynomials with coefficients in \(\mathbb{R}\) as the field.

\[ 3x^2+2x+1=3\ket{v_1}+2\ket{v_2}+1\ket{v_3} \]
Worked Example

Consider the matrix \(\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}\) in the vector space of \(2\times 2\) matrices over the field \(\mathbb{R}\). It can be written as a linear combination of the matrices \(\begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}\), \(\begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix}\), \(\begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix}\) and \(\begin{pmatrix} 0 & 0 \\ 0 & 1 \end{pmatrix}\) as

\[ \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}=1\begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}+2\begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix}+3\begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix}+4\begin{pmatrix} 0 & 0 \\ 0 & 1 \end{pmatrix} \]
Definition — Span

Let \(V\) be a vector space over a field \(\mathbb{F}\) and let \(\ket{v_1},\ket{v_2},\ldots,\ket{v_n}\) be vectors in \(V\). The set of all linear combinations of \(\ket{v_1},\ket{v_2},\ldots,\ket{v_n}\) is called the span of \(\ket{v_1},\ket{v_2},\ldots,\ket{v_n}\) and is denoted by \(Span(\ket{v_1},\ket{v_2},\ldots,\ket{v_n})\).

Definition — Linear Independence

Let \(V\) be a vector space over a field \(\mathbb{F}\) and let \(\ket{v_1},\ket{v_2},\ldots,\ket{v_n}\) be vectors in \(V\). The vectors \(\ket{v_1},\ket{v_2},\ldots,\ket{v_n}\) are said to be linearly independent if the only solution to the equation

\[ a_1\ket{v_1}+a_2\ket{v_2}+\ldots+a_n\ket{v_n}=\ket{0} \]

is the trivial solution \(a_1=a_2=\ldots=a_n=0\).

If the vector equation has a non-trivial solution (i.e. infinitely many solutions or at least one of the \(a_i \neq 0\)) then the vectors are said to be linearly dependent.

Corollary

A set \(S\) with two or more vectors is not linearly independent (i.e. linearly dependent) if and only if at least one vector is expressible as a linear combination of other vectors in \(S\).

Corollary

If a finite set \(S\) contains the zero vector \(\ket{0}\) then the set \(S\) is linearly dependent.

Worked Example

Linear dependence example. Show that \((1,-1)\), \((1,2)\) and \((2,1)\) are linearly dependent.

Show solution

Recall that the vectors \(\ket{v_1},\ket{v_2}, \ldots, \ket{v_n}\) are said to be linearly independent if the only solution to the equation \(a_1\ket{v_1}+a_2\ket{v_2}+\ldots +a_n\ket{v_n}=0\) is the trivial solution \(a_1=a_2=\ldots=a_n=0\). Thus, writing the equation,

\[\begin{aligned} a_1(1,-1)+a_2(1,2)+a_3(2,1)&=(0,0)\\ (a_1,-a_1)+(a_2,2a_2)+(2a_3,a_3)&=(0,0)\\ (a_1+a_2+2a_3,-a_1+2a_2+a_3)&=(0,0)\\ \implies a_1+a_2+2a_3&=0\\ \implies -a_1+2a_2+a_3&=0 \end{aligned}\]

Thus, we have two independent equations and three variables, hence infinite solutions exist. Thus, along with the trivial solution, many other non-trivial solutions exist. Hence the vectors are linearly dependent. We can also observe that, putting \(a_1=1,a_2=1,a_3=-1\), we get

\[ \begin{bmatrix} 1 \\ -1 \end{bmatrix}+ \begin{bmatrix} 1 \\ 2 \end{bmatrix}-\begin{bmatrix} 2 \\ 1 \end{bmatrix}=\begin{bmatrix} 0 \\ 0 \end{bmatrix} \]

We can also apply the theorem that for any vector space \(V\) with \(\dim(V)=n\), any set of vectors with \(m\gt n\) in \(V\) will be linearly dependent. Here, \(V=\mathbb{R}^2, n=2, m=3\).

Definition — Basis

Let \(V\) be a vector space over a field \(\mathbb{F}\). A set of vectors \(\ket{v_1},\ket{v_2},\ldots,\ket{v_n}\) in \(V\) is called a basis of \(V\) if

  1. \(\ket{v_1},\ket{v_2},\ldots,\ket{v_n}\) are linearly independent
  2. \(Span(\ket{v_1},\ket{v_2},\ldots,\ket{v_n})=V\)
Worked Example

A collection of \(n\) linearly independent vectors always spans \(\mathbb{R}^n\) and is called a basis of \(\mathbb{R}^n\).

Definition — Dimension

Let \(V\) be a vector space over a field \(\mathbb{F}\). The number of vectors in a basis of \(V\) is called the dimension of \(V\) and is denoted by \(\dim(V)\). Note that this is because the number of vectors in a basis of any vector space is unique.

Theorem

The coefficients of expansion \(v_i\) of vector \(\ket{v}\) in terms of a linearly independent basis \(\ket{i}\) are called components of the vector in that basis. It is always a unique expansion in a given basis since the basis is linearly independent and only a trivial linear relation between them can exist. Given a basis, components are unique, but if we change the basis, the components will change.

Note that \(\ket{v}\) is an abstract object which satisfies various relations. When we choose a basis the vectors assume a concrete form and the relation between vectors is satisfied by the components. On changing basis, the components will change in numerical value, but the relation between them expressing the equality still holds between the set of new components.

Addition of two vectors in a basis (both the vectors are expressed in the same basis):

\[ \ket{v}=\sum_{i=1}^{n}v_i\ket{i}, \quad \ket{w}=\sum_{i=1}^{n}w_i\ket{i} \] \[ \ket{v}+\ket{w}=\sum_{i=1}^{n}(v_i+w_i)\ket{i} \]

To add two vectors, add their corresponding components in the same basis. Scalar multiplication of a vector in a basis:

\[ a\ket{v}=a\sum_{i=1}^{n}v_i\ket{i}=\sum_{i=1}^{n}(av_i)\ket{i} \]

To multiply a vector by a scalar, multiply each component by the scalar.

Inner Product

Similar to the definition of the dot product defined in \(\mathbb{R}^n\) we define the inner product in a vector space. The inner product is a generalization of the dot product in \(\mathbb{C}^n\). The inner product is a function that takes two vectors as input and returns a scalar as output. The inner product is denoted by \(\braket{u|v}\) and is defined as follows:

Definition — Inner Product

Let \(V\) be a vector space over a field \(\mathbb{F}\). An inner product on \(V\) is a function that assigns to each pair of vectors \(\ket{u},\ket{v}\in V\) a scalar \(\braket{u|v}\in\mathbb{F}\) such that for all \(\ket{u},\ket{v},\ket{w}\in V\) and \(a,b\in\mathbb{F}\) the following properties hold:

  1. Conjugate Symmetry: \(\braket{u|v}={\braket{v|u}}^*\)
  2. Linearity in the second argument: \(\braket{v|au+bw}=a\braket{v|u}+b\braket{v|w}\)
  3. Positive Definite: \(\braket{v|v}\geq 0\) and \(\braket{v|v}=0\) iff \(\ket{v}=\ket{0}\)

A vector space with an inner product defined is called an inner product space.

Worked Example

In \(\mathbb{R}^n\) as field the inner product is defined as \(\braket{u|v}=\sum_{i=1}^{n}u_iv_i\) and holds the following properties:

  1. Symmetry: \(\braket{u|v}=\braket{v|u}^*\)
  2. Linearity: \(\braket{au+bw|v}=a\braket{u|v}+b\braket{w|v}=\braket{v|au+bw}\)
  3. Positive Definite: \(\braket{v|v}=\sum_{i=1}^{n}v_i^2\geq 0\) and \(\braket{v|v}=0\) iff \(\ket{v}=\ket{0}\)

Here the properties of the inner product are reduced since it is defined on Real numbers. The conjugate symmetry property is reduced to the symmetry property. The linearity in the first argument reduces to linearity in both arguments. The positive definite property remains the same.

Worked Example

Verify that \(\braket{\cdot|\cdot}\) as defined is an inner product on \(\mathbb{C}^n\).

Show solution

Recall that on \(\mathbb{C}^n\) it was defined as:

\[ \braket{y|z}=\sum_i y_i^*z_i=\begin{bmatrix} y_1^* & y_2^* & \ldots & y_n^* \end{bmatrix} \begin{bmatrix} z_1 \\ \vdots \\ z_n \end{bmatrix} \]

Furthermore, recall the three conditions for the inner product, \(\braket{\cdot|\cdot}:V \times V \rightarrow \mathbb{C}\), to be considered an inner product:

  1. \(\braket{\cdot|\cdot}\) is linear in the second argument.
  2. \(\braket{v|w} =\braket{w|v}^*\)
  3. \(\braket{v|v}\geq 0\) with equality if and only if \(\ket{v}=0\).

We check that \(\braket{\cdot|\cdot}:\mathbb{C}^n \times \mathbb{C}^n\rightarrow \mathbb{C}\) satisfies the three conditions:

1.

\[\begin{aligned} \braket{y|\textstyle\sum_i \lambda_i z_i}&=\sum_i y_i^* \sum_k \lambda_k z_{ik}\\ &=\sum_k \lambda_k \sum_i y_i^* z_{ik}\\ &=\sum_k \lambda_k \braket{y|z_i} \end{aligned}\]

2.

\[\begin{aligned} \braket{y|z} &= \sum_i y_i^* z_i\\ &= \sum_i (y_iz_i^*)^*\\ &=\left(\sum_i z_i^*y_i\right)^*\\ &=\braket{z|y}^* \end{aligned}\]

3. Observe, \(\mathbf{0}=\begin{pmatrix} 0 & \ldots & 0 \end{pmatrix}\):

\[ \braket{0|0}=\sum_i 0 \cdot 0 = 0 \]

For \(y\neq 0\) we have that at least one \(y_i\) is non-zero, and hence

\[ \braket{y|y}=\sum_i y_i^*y_i=\sum_i|y_i|^2 \geq 0 \]

which proves the claim.

Worked Example

Show that any inner product is conjugate-linear in the first argument:

\[ \braket{\left(\textstyle\sum_i \lambda_i \ket{w_i}\right)|v} \]

This property is called Antilinearity: the inner product is linear in the second argument and antilinear in the first argument.

Show solution

Using property 1 (Conjugate Symmetry) we get,

\[ \braket{\left(\textstyle\sum_i \lambda_i \ket{w_i}\right)|v}=\braket{v|\left(\textstyle\sum_i \lambda_i \ket{w_i}\right)}^* \]

Using property 2 (Linearity in second argument) we get,

\[ = \left(\sum_i \lambda_i \braket{v|w_i} \right)^* \]

Using the properties of the complex conjugate we get,

\[ = \sum_i \lambda_i^* \braket{w_i|v} \]

where \(\lambda_i^*\) is the complex conjugate of \(\lambda_i\).

Inner products of a linear superposition with another vector are the corresponding superposition of inner products if the superposition occurs in the second factor, while it is the superposition with all coefficients conjugated if the superposition occurs in the first factor.

Intuition: the inner product \(\braket{u|v}\) is a "projection" — it measures how much of \(\ket{v}\) points along \(\ket{u}\). Unlike ordinary real vectors, order matters: \(\braket{u|v}\) and \(\braket{v|u}\) are complex conjugates of each other, so the projection of \(u\) onto \(v\) is the conjugate of the projection of \(v\) onto \(u\).

Another way in which the inner product can be thought of is as projections. The inner product \(\braket{u|v}\) is the projection of \(\ket{v}\) onto \(\ket{u}\). Similarly, the inner product \(\braket{v|u}\) is the projection of \(\ket{u}\) onto \(\ket{v}\). Note that unlike in the case of real vector spaces, here the projection of \(a\) on \(b\) is not the same as the projection of \(b\) on \(a\); the projections are complex conjugates of each other, as can be clearly observed since the inner product is conjugate symmetric (\(\braket{u|v}=\braket{v|u}^*\)).

Definition — Absolute value of a complex number

Consider a complex number \(z\in\mathbb{C}\) expressed as \(z=x+\iota y\) where \(x,y \in \mathbb{R}\) are real numbers representing the real and imaginary parts of \(z\) respectively. The absolute value, otherwise known as the modulus of \(z\), is given by

\[ |z|=\sqrt{z^*z}=\sqrt{x^2+y^2} \]
Worked Example

For example, for \(z=1+\iota 2\) its absolute value is given by \(|z|=\sqrt{1^2+2^2}=\sqrt{5}\).

Definition — Norm (length) of a vector

Let \(V\) be a vector space over a field \(\mathbb{F}\). The norm of a vector \(\ket{v}\in V\) is defined as \(\|\ket{v}\|=\sqrt{\braket{v|v}}\). A vector which has a norm of 1 is called a unit vector.

Worked Example

Consider a ket \(\ket{v}=\frac{1}{2}\begin{pmatrix} 1+\iota \\ 1-\iota \end{pmatrix} \in \mathbb{C}^2\). The corresponding bra is given by \(\bra{v} =\frac{1}{2}\begin{pmatrix} 1-\iota & 1+\iota \end{pmatrix}\), and the length of \(\ket{v}\) is

\[ \sqrt{\braket{v|v}} =\sqrt{\tfrac{1}{4}2(1+\iota)(1-\iota)}=\sqrt{\tfrac{1}{2}(1+\iota -\iota -\iota^2)}=\sqrt{\tfrac{1}{2}\cdot 2}=1 \]
Definition — Orthogonality

Let \(V\) be a vector space over a field \(\mathbb{F}\). Two vectors \(\ket{u},\ket{v}\in V\) are said to be orthogonal if \(\braket{u|v}=0\).

Definition — Orthonormal

Let \(V\) be a vector space over a field \(\mathbb{F}\). Two vectors \(\ket{u},\ket{v}\in V\) are said to be orthonormal if they are orthogonal and have unit norm.

Definition — Orthonormal Basis

Let \(V\) be a vector space over a field \(\mathbb{F}\). A basis \(\ket{v_1},\ket{v_2},\ldots,\ket{v_n}\) of \(V\) is called an orthonormal basis if

  1. \(\ket{v_1},\ket{v_2},\ldots,\ket{v_n}\) are orthogonal
  2. \(\|\ket{v_i}\|= \sqrt{\braket{v_i|v_i}} = 1\) for all \(i=1,2,\ldots,n\)
Worked Example

A general formula for the inner product: Let \(\ket{u}=\sum_{i=1}^{n}u_i\ket{i}\) and \(\ket{v}=\sum_{j=1}^{n}v_j\ket{j}\) be two vectors in a vector space \(V\) over a field \(\mathbb{F}\). Then the inner product of \(\ket{u}\) and \(\ket{v}\) is given by

\[ \braket{u|v}=\sum_{j=1}^{n} \sum_{i=1}^{n}u_i^*v_j \braket{i|j} \]

If the basis is orthonormal then the \(\braket{i|j}\) evaluates as follows:

\[ \braket{i|j}= \begin{cases} 1, & \text{if } i=j\\ 0, & \text{otherwise} \end{cases} \]

Thus, in the orthonormal basis this gets simplified to

\[ \braket{u|v}=\sum_{i=1}^{n}u_i^*v_i \]

For the norm of a vector \(\ket{v}\) in an orthonormal basis:

\[ \|\ket{v}\|=\sqrt{\braket{v|v}}=\sqrt{\sum_{i=1}^{n}v_i^*v_i}=\sqrt{\sum_{i=1}^{n}|v_i|^2} \] \[ \braket{v|v}=\sum_{i=1}^{n}|v_i|^2 \geq 0 \]

thus it is used to define the length of the vector. Also note that \(|v_i|\) is the modulus of a complex number (thus \(|v_i| \geq 0\)).

Worked Example

Verify that \(\ket{w}=(1,1)\) and \(\ket{v}=(1,-1)\) are orthogonal. What are the normalized forms of these vectors?

Show solution
\[ \braket{w|v}=1\cdot 1 + 1 \cdot (-1) = 1 + (-1) = 0 \]

Thus, clearly since \(\braket{w|v}=0\) they are orthogonal. Now, \(\|\ket{v}\|=\sqrt{\braket{v|v}}=\sqrt{1^2+1^2} = \sqrt{2}\) and \(\|\ket{w}\|=\sqrt{\braket{w|w}}=\sqrt{1^2+1^2}=\sqrt{2}\). Thus, their normalized forms are: \(\ket{v}/\|\ket{v}\|= \frac{1}{\sqrt{2}}(1,1)\) and \(\ket{w}/\|\ket{w}\|=\frac{1}{\sqrt{2}}(1,-1)\).

Now note that the inner product can be written as matrix multiplication between two vectors. Let \(\ket{u}=\begin{pmatrix} u_1 \\ u_2 \\ \vdots \\ u_n \end{pmatrix}\) and \(\ket{v}=\begin{pmatrix} v_1 \\ v_2 \\ \vdots \\ v_n \end{pmatrix}\) be two vectors in a vector space \(V\) over a field \(\mathbb{C}\) with basis vectors \(\ket{i}\) (with 1 in the \(i\)th row position). Then the inner product of \(\ket{u}\) and \(\ket{v}\) is given by

\[ \braket{u|v}=\begin{pmatrix} u_1^* & u_2^* & \ldots & u_n^* \end{pmatrix} \begin{pmatrix} v_1 \\ v_2 \\ \vdots \\ v_n \end{pmatrix}=\sum_{i=1}^{n}u_i^*v_i \]

Thus, the inner product can be written as matrix multiplication between two vectors. Note that here \(\bra{u}\) is called a bra vector and we can think of it as lying in some other vector space defined by the basis vectors \(\bra{i}\) (with 1 in the \(i\)th column position). Thus we have a vector space of \(\ket{v}\) and another vector space of \(\bra{v}\); these two spaces are called dual spaces. We can convert a vector from one space to the other by performing the adjoint operation (transpose-conjugate operation). Thus, \(\bra{v}=((\ket{v})^{T})^{*}\) or \(\ket{v}=((\bra{v})^{T})^{*}\).

Properties of the Adjoint Operation:

  1. \((a\ket{v}+b\ket{w})^{\dagger}=\bra{v}a^{*}+\bra{w}b^{*}\)
  2. \((\ket{v}^{\dagger})^{\dagger}=\ket{v}\)
Worked Example

Note that the inner product of two vectors \(\ket{v_1},\ket{v_2} \in \mathbb{C}^d\) is in general a complex number. Later on, we shall see that the modulus squared of the inner product \(|\braket{v_1|v_2}|^2\) is of much significance. As an example, let us consider the inner product of the vectors \(\ket{v}\) and \(\ket{w}\) given as

\[ \ket{v}=\begin{pmatrix} 1 \\0 \end{pmatrix},\quad \ket{w}=\begin{pmatrix} 2 \\ 3 \end{pmatrix} \]

We have

\[ \braket{v|w}=\begin{pmatrix} 1 & 0 \end{pmatrix} \begin{pmatrix}2 \\3 \end{pmatrix}=1\cdot 2+0\cdot 3 =2 \]

Note that \(|\braket{v_1|v_2}|^2=\braket{v_1|v_2}\braket{v_2|v_1}\).

Gram-Schmidt Orthogonalization

Given a set of linearly independent vectors \(\ket{v_1},\ket{v_2},\ldots,\ket{v_n}\) in a vector space \(V\) over a field \(\mathbb{F}\), the Gram-Schmidt orthogonalization process constructs an orthonormal basis \(\ket{u_1},\ket{u_2},\ldots,\ket{u_n}\) of \(V\) from the given set of linearly independent vectors. The process is as follows:

  1. Let \(\ket{u_1}=\dfrac{\ket{v_1}}{\|v_1\|}\)
  2. For \(i=2,3,\ldots,n\) do:
    1. Let \(\ket{u_i}=\ket{v_i}-\sum_{j=1}^{i-1}\braket{u_j|v_i}\ket{u_j}\)
    2. Normalize the vector \(\ket{u_i}\): \(\ket{u_i}=\dfrac{\ket{u_i}}{\|\ket{u_i}\|}\)
Proof

Proof that the Gram-Schmidt orthogonalization process constructs an orthonormal basis of \(V\) from a given set of linearly independent vectors. The proof can be shown by using induction.

Base Case. For \(i=1\), \(\ket{u_1}=\frac{\ket{v_1}}{\|v_1\|}\) is a unit vector and thus is an orthonormal basis.

Inductive Hypothesis. Assume that for some \(k\geq 1\), the vectors \(\ket{u_1},\ket{u_2},\ldots,\ket{u_k}\) are orthonormal.

Inductive Step. We need to show that the vector \(\ket{u_{k+1}}\) is orthonormal. We have

\[ \braket{u_i|u_j}=\delta_{ij}=\begin{cases} 1, & \text{if } i=j\\ 0, & \text{otherwise} \end{cases} \]

for \(i,j=1,2,\ldots,k\). Thus, we need to show that \(\braket{u_i|u_{k+1}}=0\) for \(i=1,2,\ldots,k\). We have

\[ \braket{u_i|u_{k+1}}=\braket{u_i|v_{k+1}}-\sum_{j=1}^{k}\braket{u_j|v_{k+1}}\braket{u_i|u_j} \]

Now, \(\braket{u_i|u_j}=\delta_{ij}\) and thus the above equation becomes

\[ =\braket{u_i|v_{k+1}}-\braket{u_i|v_{k+1}}\braket{u_i|u_i} \]

Using the fact that \(\ket{u_i}\) is a unit vector, we have

\[ =\braket{v_{k+1}|u_i}-\braket{u_i|v_{k+1}} = 0 \]

Thus, \(\ket{u_{k+1}}\) is orthogonal to \(\ket{u_1},\ket{u_2},\ldots,\ket{u_k}\). Now, we need to show that \(\ket{u_{k+1}}\) is a unit vector. We have

\[ \|\ket{u_{k+1}}\|=\frac{\braket{v_{k+1}|v_{k+1}}}{\|v_{k+1}\|^2}=\frac{\|v_{k+1}\|^2}{\|v_{k+1}\|^2}=1 \]

Thus, \(\ket{u_{k+1}}\) is a unit vector. By induction, the Gram-Schmidt orthogonalization process constructs an orthonormal basis of \(V\) from a given set of linearly independent vectors. ∎

Cauchy-Schwarz and Triangle Inequalities

Theorem

The Schwarz inequality: the dot product of two vectors cannot exceed the product of their lengths.

\[|\braket{V|W}| \leq \sqrt{\braket{V|V}\braket{W|W}}\]
Proof

Note that this is obviously true for arrows. Now say,

\[\ket{Z}=\ket{V}-\frac{\braket{W|V}}{|W|^2}\ket{W}\] \[\bra{Z}=\bra{V}-\frac{\braket{V|W}}{|W|^2}\bra{W}\]

Note here we are required to find \(\braket{Z|Z}\). Thus we can either write the bra form and then proceed solving with a direct inner product, or we can use the ket version in the first factor and then use the antilinearity axiom (for superposition in the first factor) to proceed further. Then, we have

\[\braket{Z|Z}=\braket{V|V}-\frac{\braket{V|W}\braket{W|V}}{|W|^2}-\frac{\braket{W|V}\braket{V|W}}{|W|^2}+\frac{\braket{V|W}\braket{W|V}\braket{W|W}}{|W|^4}\]

Now \(\braket{Z|Z}\geq 0\) from the axiom (with \(\braket{W|W}=|W|^2\)). Thus,

\[\braket{V|V} \geq \frac{\braket{V|W} \braket{W|V}}{|W|^2}\] \[\braket{V|V}\braket{W|W}\geq |{\braket{V|W}}|^2\] \[|\braket{V|W}|^2 \leq \braket{V|V}\braket{W|W}\] \[|{\braket{V|W}}| \leq \sqrt{\braket{V|V}\braket{W|W}}\]

Hence proved. ∎

Theorem

The Triangle Inequality: the length of a sum cannot exceed the sum of the lengths.

\[|V+W| \leq |V| + |W|\]
Proof

Note that this is obviously true for arrows. Now say,

\[\ket{Z}=\ket{V}+\ket{W}, \quad \bra{Z}=\bra{V}+\bra{W}\]

Thus, we have

\[\braket{Z|Z}=|Z|^2=\braket{V|V}+\braket{W|W}+\braket{V|W}+\braket{W|V}\] \[|V+W|^2=|V|^2 + |W|^2 + 2\,\mathrm{Re}(\braket{V|W})\]

Now using \(\mathrm{Re}(\braket{V|W}) \leq |{\braket{V|W}}|\), we get

\[|{V+W}|^2 \leq |{V}|^2 + |{W}|^2 + 2|{\braket{V|W}}|\]

Using the Schwarz Inequality, we get

\[|{V+W}|^2 \leq |{V}|^2 + |{W}|^2 + 2|{V}||{W}| = (|{V}|+|{W}|)^2\] \[|{V+W}| \leq |{V}| + |{W}|\]

Hence proved. ∎

Linear Operators and Matrix Representation

Definition — Linear Operator

Let \(V\) and \(W\) be vector spaces over a field \(\mathbb{F}\). A function \(A:V\rightarrow W\) is called a linear operator if for all \(\ket{v},\ket{w}\in V\) and \(a\in\mathbb{F}\) the following properties hold:

  1. \(A(\ket{v}+\ket{w})=A(\ket{v})+A(\ket{w})\)
  2. \(A(a\ket{v})=aA(\ket{v})\)

In general, when we say a linear operator is defined on a vector space \(V\), we mean that \(A\) is a linear operator from \(V\) to \(V\).

Once the action of a linear operator on the basis vectors is known, its action on any vector in the space is determined. For a basis \(\ket{1},\ket{2},\ldots,\ket{n}\) of a vector space \(V\), the action of a linear operator \(A\) on any vector \(\ket{v}=\sum_{i=1}^n v_i\ket{i}\) transforms the basis vectors to \(\ket{1'}, \ket{2'}, \ldots, \ket{m'}\) and thus the vector \(\ket{v}\) to \(\ket{v'}\) as follows:

\[A(\ket{v})=A\left(\sum_{i=1}^n v_i\ket{i}\right)=\sum_{i=1}^n v_iA(\ket{i})=\sum_{i=1}^n v_i \ket{i'}=\ket{v'}\]

This can be explained as follows:

\[\begin{aligned} A\ket{v}&=\sum_{i=1}^n v_i A\ket{i}\\ \braket{j'|A|v}&=\sum_{i=1}^n v_i \braket{j'|A|i} \end{aligned}\]

Thus the inner product with one of the basis vectors of the output basis results as shown above. This can be written in matrix form as follows:

\[ A\ket{v}=\begin{bmatrix} \braket{1'|A|1} & \braket{1'|A|2} & \ldots & \braket{1'|A|n} \\ \braket{2'|A|1} & \braket{2'|A|2} & \ldots & \braket{2'|A|n} \\ \vdots & \vdots & \ddots & \vdots \\ \braket{m'|A|1} & \braket{m'|A|2} & \ldots & \braket{m'|A|n} \end{bmatrix} \begin{bmatrix} v_1 \\ v_2 \\ \vdots \\ v_n \end{bmatrix} \]

where the input basis is \(\ket{1},\ket{2},\ldots,\ket{n}\) and the output basis is \(\ket{1'},\ket{2'},\ldots,\ket{m'}\). Thus, we have a matrix representation of \(A\) in the given input and output bases.

Thus, once we know the action of a linear operator on the basis vectors, we can determine the action of the linear operator on any vector in the vector space. It is the same linear combination of the vector in the new basis as it was in the old basis. Note we haven't talked about writing these operators in matrix format until now, so one must not think in terms of matrices and get confused. The above statement simply says that given the basis vectors of a Vector Space \(V\) and a linear operator \(A\), the action of \(A\) on any vector in the vector space is determined by the action of \(A\) on the basis vectors. The matrix representation and operators are equivalent for the purpose of these notes and this is applicable in Quantum Computing.

Definition — Matrix Representation of a Linear Operator

Let \(V\) be a vector space over a field \(\mathbb{F}\) with basis \(\ket{1},\ket{2},\ldots,\ket{n}\) and let \(W\) be a vector space over \(\mathbb{F}\) with basis \(\ket{1'},\ket{2'},\ldots,\ket{m'}\). Let \(A\) be a linear operator from \(V\) to \(W\). The matrix representation of \(A\) with respect to these bases is the \(m\times n\) matrix \([A]\) whose elements are given by

\[[A]_{ij}=\braket{i'|A|j}\]

which is the \(i\)th row and \(j\)th column entry.

To explain this in more depth: we must know what the operator does to the basis vectors. Then to represent this operator in some matrix representation we must first specify the input and output basis for the matrix to map. In general, the input and output bases are the same and they are the standard orthonormal basis that we use (i.e. \(\ket{1}=(1,0,0,\ldots,0)\), \(\ket{2}=(0,1,0,\ldots,0)\) and so on). Thus, the matrix representation of the operator in this basis will be given as follows:

\[ [A]=\begin{pmatrix} \braket{1'|A|1} & \braket{1'|A|2} & \ldots & \braket{1'|A|n} \\ \braket{2'|A|1} & \braket{2'|A|2} & \ldots & \braket{2'|A|n} \\ \vdots & \vdots & \ddots & \vdots \\ \braket{m'|A|1} & \braket{m'|A|2} & \ldots & \braket{m'|A|n} \end{pmatrix} \]

This indicates that the input basis here is chosen as \(\ket{1},\ket{2},\ldots,\ket{n}\) and the output basis is chosen as \(\ket{1'},\ket{2'},\ldots,\ket{m'}\). Note that the \(j\)th column represents the components of the \(j\)th transformed basis vector \(\ket{j'}=A\ket{j}\). Thus the value \(\bra{i'}A\ket{j}\) is a scalar which is the component of the \(j\)th basis vector \(\ket{j}\) after being transformed by the action of operator \(A\) to \(A\ket{j}\) on the \(i\)th transformed basis vector \(\ket{i'}\).

Generally for the purpose of these notes and for most applications we assume the input and output bases to be the standard orthonormal basis. Thus, the problems we will face will be of the kind where we will be given the action of an operator on some vectors (sufficient enough to find its matrix representation) and then we will be asked to find its matrix representation in some input and output basis. Consider the following example for more clarity.

Worked Example

(Matrix representations example) Suppose \(V\) is a vector space with basis vectors \(\ket{0}\) and \(\ket{1}\), and \(A\) is a linear operator from \(V\) to \(V\) such that \(A\ket{0}=\ket{1}\) and \(A\ket{1}=\ket{0}\). Find the matrix representation of \(A\) in the basis \(\ket{0}\) and \(\ket{1}\). Also find the matrix representation of \(A\) in the basis \(\ket{+}=\frac{1}{\sqrt{2}}\begin{pmatrix} 1 \\ 1 \end{pmatrix}\) and \(\ket{-}=\frac{1}{\sqrt{2}}\begin{pmatrix} 1 \\ -1 \end{pmatrix}\) represented in the standard orthonormal basis.

Show solution

Identifying \(\ket{0}=\begin{bmatrix} 1 \\ 0 \end{bmatrix}\) and \(\ket{1}=\begin{bmatrix} 0 \\ 1 \end{bmatrix}\), the matrix representation of \(A\) in the basis \(\ket{0}\) and \(\ket{1}\) is given by

\[[A]=\begin{pmatrix} \braket{0|A|0} & \braket{0|A|1} \\ \braket{1|A|0} & \braket{1|A|1} \end{pmatrix}=\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\]

The matrix representation of \(A\) in the basis \(\ket{+}\) and \(\ket{-}\) is given by

\[[A]=\begin{pmatrix} \braket{+|A|+} & \braket{+|A|-} \\ \braket{-|A|+} & \braket{-|A|-} \end{pmatrix}\]

Note that now we are not given the action of operator \(A\) on the vectors \(\ket{+}\) and \(\ket{-}\), thus we must find it first.

\[A\ket{+}=\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\frac{1}{\sqrt{2}}\begin{pmatrix} 1 \\ 1 \end{pmatrix}=\frac{1}{\sqrt{2}}\ket{0}+\frac{1}{\sqrt{2}}\ket{1}=\ket{+}\] \[A\ket{-}=\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\frac{1}{\sqrt{2}}\begin{pmatrix} 1 \\ -1 \end{pmatrix}=-\frac{1}{\sqrt{2}}\ket{0}+\frac{1}{\sqrt{2}}\ket{1}=-\ket{-}\]

Thus the matrix representation of \(A\) in the basis \(\ket{+}\) and \(\ket{-}\) using \(A\ket{+}=\ket{+}\) and \(A\ket{-}=-\ket{-}\) is given by

\[[A]=\begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}\]

Thus, given the action of a linear operator on some vectors (assumed sufficient to find the matrix representation) we can find its matrix representation in any input and output basis as shown by the above procedure. The matrix may be numerically different in different bases. Note that once the matrix is specified in a given input and output basis it can operate only on the vectors that are specified in the same input basis, and the output of the operation will result in a vector specified in the given output basis. To make the connection between matrices and linear operators one must specify a set of input and output basis states for the input and output vector spaces of the linear operator. Note that it is not at all necessary for the input and output basis to be the same or even orthonormal, as that property has not been used anywhere while deriving the formulation; the condition that needs to be satisfied is just that the basis vectors must be specified for the linear operator's input and output vector spaces.

Important

Remark. If we choose the output and the input basis to be different we can even represent \(A\) as an identity matrix. Specifically, if the input basis is chosen as \(\{\ket{0},\ket{1}\}\) and the output basis as \(\{\ket{1},\ket{0}\}\), the matrix representation of \(A\) looks like:

\[ \begin{bmatrix} \braket{1|A|0} & \braket{1|A|1} \\ \braket{0|A|0} & \braket{0|A|1} \end{bmatrix} = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \]

Note that this implies that even the order of the input and output basis matters!

Worked Example

(Basis Changes) Suppose \(A'\) and \(A''\) are matrix representations of an operator \(A\) on a vector space \(V\) with respect to two different orthonormal bases \(\ket{v_i}\) and \(\ket{w_i}\). Then the elements of \(A'\) and \(A''\) are \(A_{ij}'=\braket{v_i|A|v_j}\) and \(A_{ij}''= \braket{w_i|A|w_j}\). Characterize the relationship between \(A'\) and \(A''\).

Show solution
\[\begin{aligned} A_{ij}'=\braket{v_i|A|v_j}=\braket{v_i|IAI|v_j}&=\braket{v_i|\left(\textstyle\sum_{i'}\ket{w_{i'}}\bra{w_{i'}}\right)A\left(\textstyle\sum_{j'}\ket{w_{j'}}\bra{w_{j'}}\right)|v_j}\\ &=\sum_{i'}\sum_{j'}\braket{v_i|w_{i'}}\braket{w_{i'}|A|w_{j'}}\braket{w_{j'}|v_j}\\ &=\sum_{i'}\sum_{j'}\braket{v_i|w_{i'}}A_{i'j'}''\braket{w_{j'}|v_j} \end{aligned}\]
Worked Example

(Matrix representation for identity) Show that the identity operator on a vector space \(V\) has a matrix representation which is one along the diagonal and zero everywhere else, if the matrix representation is taken with respect to the same output and input bases. This matrix is known as the identity matrix.

Show solution

Let the basis for the vector space \(V\) be \(\ket{v_i}\), then the identity operator is such that \(I\ket{v_i}=\ket{v_i}\). Its matrix representation with respect to \(\ket{v_i}\) as input and output bases is given as

\[\begin{aligned} I_{ij}&=\braket{v_i|I|v_j}\\ &=\braket{v_i|v_j}\\ I_{ij}&=\delta_{ij} \end{aligned}\]

Thus, it is one along the diagonal where \(i=j\) and 0 everywhere else where \(i\neq j\).

From now on, when we speak of a matrix representation for a linear operator, we mean a matrix representation with respect to orthonormal input and output bases. We also use the convention that if the input and output spaces for a linear operator are the same, then the input and output bases are the same, unless noted otherwise. Some of the important linear operators:

  1. Identity Operator: The identity operator \(I\) is defined as \(I\ket{v}=\ket{v}\) for all \(\ket{v}\in V\). The matrix representation of the identity operator in any basis is the identity matrix. \[\bra{i}I\ket{j}=\braket{i|j}=\delta_{ij}\] where \(\delta_{ij}\) is the Kronecker delta function.
  2. Zero Operator: The zero operator \(0\) is defined as \(0\ket{v}=\ket{0}\) for all \(\ket{v}\in V\). The matrix representation of the zero operator in any basis is the zero matrix.
  3. Projection Operator: Consider a vector \(\ket{v}\) which can be written in some basis as \(\ket{v}=\sum_{i=1}^{n}v_i\ket{i}\). This can be further simplified using the inner product definition as \(v_i\) is the projection of \(\ket{v}\) onto the \(i\)th basis vector \(\ket{i}\). Thus, \(v_i=\braket{i|v}\). On substituting we get \(\ket{v}=\sum_{i=1}^{n}\braket{i|v}\ket{i}\). Rearranging we get, \[ \ket{v}=\sum_{i=1}^{n}\ket{i}\braket{i|v} =\left(\sum_{i=1}^n \ket{i}\bra{i} \right) \ket{v}\] Let \(\mathbb{P}_i = \ket{i}\bra{i}\) be the projection operator which projects any vector \(\ket{v}\) onto the subspace spanned by the basis vector \(\ket{i}\). Thus, \(\mathbb{P}_i\ket{v}=\ket{i}\braket{i|v}\), and \(\mathbb{P}=\sum_{i=1}^n \mathbb{P}_i = \sum_{i=1}^n \ket{i}\bra{i} = I\) (Identity Operator) is called the Completeness Relation. Now, \[\mathbb{P}_i\mathbb{P}_j=\ket{i}\braket{i|j}\bra{j}=\delta_{ij}\mathbb{P}_j\] This equation indicates that once \(\mathbb{P}_i\) projects out the part of \(\ket{V}\) along \(\ket{i}\), further applications of \(\mathbb{P}_i\) make no difference; and subsequent applications of \(\mathbb{P}_j\ (i \neq j)\) will result in zero, since a vector entirely along \(\ket{i}\) cannot have a projection along a perpendicular direction \(\ket{j}\). Thus, \(P^2=P\) must be satisfied by any projection matrix. In the standard orthonormal basis the projection operator \(\mathbb{P}_i=\ket{i}\bra{i}\) will be 1 at the \(i\)th position on the diagonal and zero everywhere else. The matrix elements of the projection operators are given as: \[(\mathbb{P}_i)_{kl}=\braket{k|i}\braket{i|l}=\delta_{ki}\delta_{il}\] \(I-P\) is also a projection operator which projects onto the subspace orthogonal to the subspace spanned by the basis vector \(\ket{i}\) and is called the orthogonal complement. Suppose \(W\) is a \(k\)-dimensional vector subspace of the \(d\)-dimensional vector space \(V\). Using the Gram-Schmidt procedure it is possible to construct an orthonormal basis \(\ket{1},\ldots,\ket{d}\) for \(V\) such that \(\ket{1},\ldots,\ket{k}\) is an orthonormal basis for \(W\). By definition, \(P=\sum_{i=1}^k \ket{i}\bra{i}\) is the projector onto the subspace \(W\). It can be shown that \(\ket{v}\bra{v}\) is Hermitian for any vector \(\ket{v}\), so \(P\) is Hermitian, \(P^{\dagger}=P\). The orthogonal complement of \(P\) is the operator \(Q=I-P\), which is a projector onto the vector space spanned by \(\ket{k+1},\ldots,\ket{d}\).
  4. Rotation operator: \(R(\theta)\) on \(\mathbb{R}^n\) is defined as rotation by an angle \(\theta = |\theta|\) about the axis parallel to the unit vector \(\hat{\theta}=\theta/|\theta|\). For example, \(R(\frac{\pi}{2}\hat{i})\) rotates the vector by \(\frac{\pi}{2}\) about the x-axis. The matrix representation of the rotation operator in the standard orthonormal basis is given by \[ [R(\theta)]=\begin{pmatrix} \cos(\theta) & -\sin(\theta) & 0 \\ \sin(\theta) & \cos(\theta) & 0 \\ 0 & 0 & 1 \end{pmatrix} \] Note that Unitary operators are a generalization of the Rotation operator in \(\mathbb{V}^n\) which will be seen later.
Big picture: an operator is an abstract rule for turning vectors into vectors; a matrix is just its "phone number" once you fix a basis. Change the basis and the matrix changes, but the operator is the same. The projection operator \(\ket{i}\bra{i}\) is the workhorse of quantum mechanics — it picks out the piece of a state along a chosen direction, and summing all of them gives back the identity (nothing is lost).

Matrix Representation for Product of Operators

Given two linear operators \(A\) and \(B\) acting on a vector space \(V\), the product \(AB\) is defined as the operator that results from applying \(B\) followed by \(A\) on any vector \(\ket{v}\in V\).

\[[AB]_{ij}=\bra{i}AB\ket{j}=\sum_{k=1}^n \bra{i}A\ket{k}\bra{k}B\ket{j}=\sum_{k=1}^n A_{ik}B_{kj}=([A][B])_{ij}\]

where \([A]\) and \([B]\) are the matrix representations of the operators \(A\) and \(B\). Note that the order of the product of the operators is important and the product of matrices is not commutative in general.

Worked Example

(Matrix representation of operator products) Suppose \(A\) is a linear operator from vector space \(V\) to vector space \(W\), and \(B\) is a linear operator from vector space \(W\) to vector space \(X\). Let \(\ket{v_i},\ket{w_j}\), and \(\ket{x_k}\) be bases for the vector spaces \(V,W\) and \(X\). Show that the matrix representation for the linear transformation \(BA\) is the matrix product of the matrix representations of \(B\) and \(A\).

Show solution

Recall that the matrix-vector multiplication, choosing the input basis itself as the vector along with the projection on the output basis, can be written as

\[ A\ket{v_i}=\sum_j \braket{w_j|A|v_i} \ket{w_j} \quad B\ket{w_j}=\sum_k \braket{x_k|B|w_j} \ket{x_k} \] \[\begin{aligned} BA\ket{v_i}&=B\left(\sum_j \braket{w_j|A|v_i} \ket{w_j}\right)\\ &=\sum_j \braket{w_j|A|v_i} \left( B\ket{w_j}\right)\\ &=\sum_j \braket{w_j|A|v_i} \left(\sum_k \braket{x_k|B|w_j}\ket{x_k}\right)\\ &= \sum_{j} \sum_k \braket{w_j|A|v_i} \braket{x_k|B|w_j} \ket{x_k}\\ &= \sum_{jk} A_{ji}B_{kj} \ket{x_k}\\ &=\sum_k \left(\sum_j B_{kj}A_{ji} \right) \ket{x_k}\\ BA\ket{v_i}&=\sum_k (BA)_{ki} \ket{x_k} \end{aligned}\]

which shows that the matrix representation of \(BA\) is indeed the matrix product of the representations of \(B\) and \(A\).

Outer Product Representation of Operators

Suppose we are required to represent an operator \(A\) acting on input vector space \(V\) and output vector space \(W\) as some linear combination of outer products. Suppose \(A:V\rightarrow W\) is a linear operator with \(\ket{v_i}\) as orthonormal basis for \(V\), and \(\ket{w_j}\) as orthonormal basis for \(W\). Thus, we obtain

\[ A = I_w A I_v = \sum_{i=1}^n \sum_{j=1}^m \ket{w_j}\bra{w_j}A\ket{v_i}\bra{v_i}=\sum_{i=1}^n \sum_{j=1}^m \bra{w_j}A\ket{v_i} \ket{w_j}\bra{v_i} \]

Thus, the operator \(A\) can be represented as a linear combination of outer products of the basis vectors of the input and output vector spaces.

Worked Example

Suppose \(\ket{v_i}\) is an orthonormal basis for an inner product space \(V\). What is the matrix representation for the operator \(\ket{v_j}\bra{v_k}\), with respect to the \(\ket{v_i}\) basis?

Show solution

The \(l,m\) element of the matrix will be

\[\begin{aligned} A_{lm}&=\braket{v_l|v_j}\braket{v_k|v_m}\\ &=\delta_{lj}\delta_{km} \end{aligned}\]

Thus, the matrix will be 1 at the \(j,k\) entry of the matrix and 0 everywhere else.

Properties of Adjoint of an Operator

We know, for a given ket \(A\ket{v}=\ket{Av}\), and for the corresponding bra \(\bra{Av}=\bra{v}A^{\dagger}\). Thus, the adjoint of an operator is defined as

\[ (A^{\dagger})_{ij}=\bra{i}A^{\dagger}\ket{j}=\bra{j}A\ket{i}^*=(A_{ji})^* \]

Also, \((AB)^{\dagger}=B^{\dagger}A^{\dagger}\).

Worked Example
\[\alpha_1\ket{V_1}=\alpha_2\ket{V_2}+\alpha_3\ket{v_3}\braket{V_4|V_5} + \alpha_4AB\ket{V_6}\]

Its adjoint will be given as:

\[\alpha_1^*\bra{V_1}=\alpha_2^*\bra{V_2}+\alpha_3^*\bra{v_3}\braket{V_5|V_4} + \alpha_4^*\bra{V_6}B^{\dagger}A^{\dagger}\]

Anti-linearity of the adjoint. The adjoint operation is anti-linear:

\[\left(\sum_i a_iA_i\right)^{\dagger}=\sum_i a_i^* A_i^{\dagger}\]

In words, when a product of operators, bras, kets and explicit numerical coefficients is encountered, reverse the order of all factors and make the substitutions \(A \rightarrow A^{\dagger}\), \(\ket{\cdot} \rightarrow \bra{\cdot}\) and \(\alpha \rightarrow \alpha^*\).

Hermitian and Unitary Operators

Note that both Hermitian and Unitary operators are defined only for square matrices.

Hermitian Operators (or Self-Adjoint operators)

Definition — Hermitian Operator

A Hermitian operator is defined as \(A^{\dagger}=A\). A Skew-Hermitian / Anti-Hermitian operator is defined as \(A^{\dagger}=-A\).

Properties of Hermitian operators:

Worked Example

If \(\ket{w}\) and \(\ket{v}\) are any two vectors, show that \((\ket{w}\bra{v})^{\dagger}=\ket{v}\bra{w}\).

Show solution

We observe that:

\[\begin{aligned} \braket{(\ket{w}\bra{v})^{\dagger}x|y}&=\braket{x|(\ket{w}\bra{v})|y}\\ &=\braket{x|w}\braket{v|y}\\ &=\braket{\braket{x|w}^{*} v|y}\\ &=\braket{\braket{w|x} v|y}\\ &=\braket{(\ket{v}\bra{w})x|y} \end{aligned}\]

Where in the third-to-last equality we use conjugate linearity in the first argument and in the second-to-last equality we use \(\braket{a|b}=\braket{b|a}^*\). Comparing the first and last expressions, we conclude that \((\ket{w}\bra{v})^{\dagger}=\ket{v}\bra{w}\).

Worked Example

Show that the adjoint operation is anti-linear: \(\left(\sum_i a_iA_i \right)^{\dagger} = \sum_i a_i^* A_i^{\dagger}\).

Show solution

We observe that:

\[\begin{aligned} \braket{\left(\textstyle\sum_i a_iA_i\right)^{\dagger}a|b}=\braket{a\textstyle\sum_ia_iA_i|b}&=\sum_i a_i \braket{a|A_i b}\\ &=\sum_i a_i\braket{A_i^{\dagger}a|b}\\ &=\braket{\textstyle\sum_i a_i^*A_i^{\dagger}a|b} \end{aligned}\]

where we invoke the definition of the adjoint in the first and third equalities, linearity in the second argument in the second equality, and conjugate linearity in the first argument in the last equality. The claim is proven by comparing the first and last expressions.

Worked Example

Show that \((A^{\dagger})^{\dagger}=A\).

Show solution

Applying the definition of the adjoint twice (and using conjugate symmetry of the inner product):

\[ \braket{(A^{\dagger})^{\dagger}a|b}=\braket{a|A^{\dagger}|b}=\braket{A^{\dagger}b|a}^*=\braket{b|A|a}^*=\left(\braket{Aa|b}^*\right)^*=\braket{Aa|b} \]

The claim follows by comparison of the first and last expressions.

Unitary Operators

Definition — Unitary operator

A Unitary operator is defined as \(U^{\dagger}U=UU^{\dagger}=I\), i.e. \(U^{\dagger}=U^{-1}\).

Properties of Unitary operators:

Unitarily Diagonalizable

Definition — Unitarily Diagonalizable

A matrix \(A\) is said to be unitarily diagonalizable if there exists a unitary matrix \(U\) such that \(U^{\dagger}AU=D\) where \(D\) is a diagonal matrix. Here, \(U\) is a unitary matrix whose columns are the orthonormal eigenvectors of \(A\). The matrix \(D\) is diagonal with entries the eigenvalues of \(A\) corresponding to the eigenvectors written in \(U\). Note that the matrix is diagonal in the basis of the eigenvectors of \(A\). Any matrix with \(n\) linearly independent eigenvectors can be written as \(AV=V\Lambda\) where \(V\) is the matrix whose columns are the eigenvectors of \(A\) and \(\Lambda\) is the diagonal matrix of eigenvalues. Thus, \(A= V\Lambda V^{-1}\), or in the orthonormal case \(V^{\dagger}AV=\Lambda\).

Normal Operators

Definition — Normal Operators

A normal operator is an operator that commutes with its adjoint, i.e. \(AA^{\dagger}=A^{\dagger}A\).

Theorem

An operator is normal if and only if it is unitarily diagonalizable.

Proof

Let \(A\) be unitarily diagonalizable. Then \(A=V\Lambda V^{\dagger}\), and

\[ AA^{\dagger} - A^{\dagger}A = V\Lambda \Lambda^{\dagger} V^{\dagger} - V\Lambda^{\dagger} \Lambda V^{\dagger} = 0 \]

since \(V^{\dagger}V=I\) and \(\Lambda^{\dagger}\Lambda=\Lambda \Lambda^{\dagger}\) (diagonal matrices commute). Thus \(A\) is normal.

Now let \(A\) be normal. We decompose \(A=A_H+A_{SH}\) where \(A_H=\frac{A+A^{\dagger}}{2}\) is Hermitian and \(A_{SH}=\frac{A-A^{\dagger}}{2}\) is skew-Hermitian. Expanding \(AA^{\dagger}-A^{\dagger}A=0\) and substituting \(A_H=A_H^{\dagger}\) and \(A_{SH}=-A_{SH}^{\dagger}\) gives \(A_{SH}A_H=A_HA_{SH}\), i.e. \(A_H\) and \(A_{SH}\) commute. Using the fact that two matrices commute if and only if they share the same eigenvectors, and that both \(A_H\) and \(A_{SH}\) are unitarily diagonalizable, we get the same unitary matrix \(V\):

\[ A_H=V\Lambda_H V^{\dagger}, \qquad A_{SH}=V\Lambda_{SH} V^{\dagger} \]

Then

\[ A=V\Lambda_H V^{\dagger} + V\Lambda_{SH} V^{\dagger} = V(\Lambda_H + \Lambda_{SH})V^{\dagger} = V\Lambda V^{\dagger} \]

Thus \(A\) is unitarily diagonalizable. Hence a matrix is normal if and only if it is unitarily diagonalizable. ∎

Properties of Normal operators:

Worked Example

Show that a normal matrix is Hermitian if and only if it has real eigenvalues.

Show solution

Let \(A\) be normal and Hermitian. Then it has a diagonal representation \(A=\sum_i \lambda_i\ket{i}\bra{i}\). By Hermiticity \(A=A^{\dagger}\), therefore

\[ A^{\dagger}=\left(\sum_i \lambda_i \ket{i}\bra{i}\right)^{\dagger}=\sum_i \lambda_i^* \ket{i}\bra{i}=A=\sum_i \lambda_i \ket{i}\bra{i} \]

Comparing, \(\lambda_i=\lambda_i^*\) and hence the eigenvalues are real.

Conversely, let \(A\) be normal with real eigenvalues, \(A=\sum_i \lambda_i \ket{i}\bra{i}\) with \(\lambda_i\) real. Then

\[ A^{\dagger}=\left(\sum_i \lambda_i \ket{i}\bra{i}\right)^{\dagger}=\sum_i \lambda_i^* \ket{i}\bra{i}=\sum_i \lambda_i \ket{i}\bra{i}=A \]

using \(\lambda_i=\lambda_i^*\). We conclude that \(A\) is Hermitian.

Positive Operators

Definition — Positive Operators

A positive operator is an operator such that for any vector \(\ket{v}\) in the vector space, the inner product \(\braket{v|A|v}\) is real and non-negative, i.e. \(\braket{v|A|v} \geq 0\). If \(\braket{v|A|v} \gt 0\) for all \(\ket{v} \neq 0\), then we say \(A\) is positive definite.

Properties of Positive Operators:

Eigen Value Problems

Given a linear operator \(A\) acting on a vector space \(V\) over a field \(\mathbb{F}\), the eigenvalue problem is to find the eigenvalues \(\lambda\) and the corresponding eigenvectors \(\ket{v}\) such that

\[A\ket{v}=\lambda\ket{v} \implies (A-\lambda I)\ket{v}=0\]

i.e. vectors such that upon the action of the operator \(A\) the vector \(\ket{v}\) is scaled by a factor \(\lambda\) (which could be positive or negative — a negative value indicates a change in direction and a value less than \(|1|\) indicates scaling down). Thus, the eigenvalues are the values of \(\lambda\) for which the operator \(A-\lambda I\) has a non-trivial null space. The eigenvectors are the vectors in the null space of \(A-\lambda I\).

\[\det(A-\lambda I)=0\]

This results in a characteristic equation of the form:

\[ P_A(\lambda)=\det(A-\lambda I)=\lambda^n - \beta_1\lambda^{n-1} + \ldots + (-1)^{r} \beta_r\lambda^{n-r}+\ldots + (-1)^n\beta_n = 0 \]

The solutions of the characteristic equation are the eigenvalues of the operator \(A\). By the fundamental theorem of algebra, every polynomial has at least one complex root, so every operator \(A\) has at least one eigenvalue and a corresponding eigenvector. The eigenspace corresponding to an eigenvalue is the set of vectors which have that eigenvalue. When an eigenspace is more than one dimensional we say that it is degenerate. For example,

\[ A=\begin{bmatrix} 2 & 0 & 0 \\ 0& 2 & 0 \\ 0 & 0 & 0 \end{bmatrix} \]

In general, we represent an eigenvalue as \(\omega\) and the corresponding eigenvector as \(\ket{\omega}\).

Worked Example

For the identity operator \(I\), the eigenvalue equation is \(I\ket{v}=\lambda\ket{v} \implies \ket{v}=\lambda\ket{v} \implies \lambda=1\). Thus, the eigenvalues of the identity operator are \(\lambda=1\) and the corresponding eigenvectors are all the vectors in the vector space.

Worked Example

Consider a projection operator \(\mathbb{P}_v\) which projects any vector onto the subspace spanned by \(\ket{v}\), so \(\mathbb{P}_v\ket{v}=\ket{v}\). The eigenvalue equation is \(\mathbb{P}_v\ket{v}=\lambda\ket{v}\).

Case 1: For any ket \(\alpha \ket{v}\) parallel to \(\ket{v}\), \(\mathbb{P}_v\ket{v}=\ket{v}=\lambda\ket{v}\). Thus, \(\lambda=1\) is an eigenvalue.
Case 2: For any ket \(\alpha \ket{v_{\perp}}\) perpendicular to \(\ket{v}\), \(\mathbb{P}_v\ket{v_{\perp}}=0=\lambda\ket{v_{\perp}}\). Thus, \(\lambda=0\) is an eigenvalue.
Case 3: For kets neither parallel nor perpendicular, \(\mathbb{P}_v(\alpha \ket{v_{\perp}}+\beta \ket{v})=\beta \ket{v} \neq \lambda(\alpha \ket{v_{\perp}} + \beta \ket{v})\), so \(\lambda\) is not an eigenvalue.

Thus, the eigenvalues of a projection matrix are either \(\lambda=0\) or \(\lambda=1\), with eigenvectors parallel and perpendicular to the subspace spanned by \(\ket{v}\) respectively.

Worked Example

Show that any projector \(P\) satisfies the equation \(P^2=P\).

Show solution

Let \(\ket{1},\ldots,\ket{k}\) be an orthonormal basis for the subspace \(W\) of \(V\). Then, using the definition of the projector onto \(W\):

\[ P^2=\left(\sum_{i=1}^k \ket{i}\bra{i}\right) \left(\sum_{i'=1}^k \ket{i'}\bra{i'}\right) = \sum_{i=1}^k \sum_{i'=1}^k \ket{i}\delta_{ii'}\bra{i'}=\sum_{i=1}^k \ket{i}\bra{i}=P \]

where we use the orthonormality of the basis to collapse the double sum.

Worked Example

Consider the Rotation operator \(R(\vec{\theta})\) which rotates any vector by an angle \(|\theta|\) about the \(\vec{\theta}\) axis. The eigenvalue equation is \(R(\vec{\theta})\ket{v}=\lambda\ket{v}\). Clearly, any ket parallel to the axis of rotation will not change direction upon rotation and thus is an eigenvector with eigenvalue \(\lambda=1\); the corresponding eigenvector is \(\vec{\theta}\). The other two eigenvalues are \(\lambda=e^{\pm i\theta}\) with eigenvectors perpendicular to the axis of rotation.

Properties of Eigen Roots:

Definition — Geometric Multiplicity

The number of linearly independent eigenvectors associated with a particular \(\lambda\) is called the geometric multiplicity. \(GM(\lambda_i)=k\) means that \(k\) linearly independent eigenvectors exist corresponding to \(\lambda_i\). These vectors form a vector space called the eigenspace. In the eigenspace all vectors are only scaled by \(\lambda_i\) and not rotated.

Definition — Algebraic Multiplicity

The multiplicity of \(\lambda\) as a root of the characteristic equation \(P_A(x)=0\) is called the algebraic multiplicity. \(AM(\lambda_i)=k\) means \(\lambda_i\) is a root of multiplicity \(k\).

For any matrix \(A\), the geometric multiplicity of an eigenvalue is always less than or equal to the algebraic multiplicity:

\[1 \leq GM(\lambda_i) \leq AM(\lambda_i) \leq n\]

Note that any matrix \(A\) will have \(n\) eigenvalues (possibly repeated), but it is not necessary for it to have \(n\) linearly independent eigenvectors. Corresponding to each unique eigenvalue there will be at least one eigenvector. If \(AM(\lambda_i)\gt 1\) there could be more than one linearly independent eigenvector, but still \(GM(\lambda_i)\leq AM(\lambda_i)\).

Theorem

A Hermitian matrix is always unitarily diagonalizable, i.e. it has \(n\) linearly independent eigenvectors (\(AM(\lambda_i)=GM(\lambda_i)\) for all \(\lambda_i\)).

Proof

Let \(A\) be Hermitian and let the geometric multiplicity for some eigenvalue be \(r\ (\lt n)\), so \(GM(\lambda)=r\). We can find \(r\) linearly independent orthogonal eigenvectors \(\{\ket{v_1},\ldots,\ket{v_r}\}\) corresponding to \(\lambda\), collected in \(V^E\). Let \(V^{\perp}\) be a set of orthonormal vectors spanning the space orthogonal to \(V^E\), and let

\[V=\begin{bmatrix} V^E & V^{\perp} \end{bmatrix}\]

Since \(A\ket{v_i}=\lambda\ket{v_i}\) for \(i=1,\ldots,r\), and any vector in \(\mathbb{C}^n\) can be written as a linear combination of the columns of \(V\), we obtain \(AV=VM\) for some matrix \(M\). Premultiplying by \(V^{\dagger}\) (with \(V^{\dagger}V=I\)):

\[V^{\dagger}AV=M \]

Taking the adjoint and using Hermiticity of \(A\), \(M=M^{\dagger}\), so \(M\) is Hermitian. Hence \(M\) has block form

\[ M=\begin{bmatrix} \lambda I_r & 0 \\ 0 & C \end{bmatrix}\]

where \(C\) is Hermitian. Since \(M=V^{\dagger}AV=V^{-1}AV\), \(M\) and \(A\) are similar and share the same characteristic polynomial:

\[(\lambda-z)^r\det(C-zI)=\det(A-zI)\]

We now show \(\lambda\) is not an eigenvalue of \(C\), by contradiction. Suppose \(Cu=\lambda u\) for \(u \in \mathbb{C}^{n-r}\). Extend to \(\hat{u} \in \mathbb{C}^n\) with zeros in the first \(r\) entries. Then \(M\hat{u}=\lambda\hat{u}\), so \(V^{\dagger}AV \hat{u}=\lambda \hat{u}\), and premultiplying by \(V\): \(A(V\hat{u})=\lambda(V\hat{u})\). Hence \(V\hat{u}\) is an eigenvector of \(A\) for \(\lambda\), but it lies in the span of \(\{\ket{v_{r+1}},\ldots,\ket{v_n}\}\), contradicting that \(\{\ket{v_1},\ldots,\ket{v_r}\}\) are the only linearly independent eigenvectors for \(\lambda\). Thus \(\lambda\) is not an eigenvalue of \(C\), and \(AM(\lambda)=GM(\lambda)=r\). Thus, a Hermitian matrix is always unitarily diagonalizable. A similar proof works for a skew-Hermitian matrix. ∎

Why this matters for quantum computing: the observables you measure (energy, spin, etc.) are Hermitian operators, and gates are unitary operators. Both are "normal," which by the theorem above guarantees a full orthonormal set of eigenvectors — a clean basis of states with definite measurement outcomes. Hermitian gives real eigenvalues (real measurement results); unitary gives unit-modulus eigenvalues (probability-preserving evolution).

Spectral Decomposition

Theorem

Any normal operator \(M\) on a vector space \(V\) is diagonal with respect to some orthonormal basis for \(V\). Conversely, any diagonalizable operator is normal.

This means that \(M\) can be written as a sum of orthogonal projection operators onto the eigenspaces of \(M\), where \(\ket{\lambda_i}\) are eigenvectors of \(M\):

\[ M=\sum_{i=1}^n \lambda_i \mathbb{P}_i \]

where \(\lambda_i\) are the eigenvalues and \(\mathbb{P}_i = \ket{\lambda_i}\bra{\lambda_i}\) are the orthogonal projection operators onto the eigenspaces. Equivalently, since any normal operator is unitarily diagonalizable,

\[M = V\Lambda V^{\dagger} = \sum_{i=1}^n \lambda_i \ket{\lambda_i}\bra{\lambda_i} = \sum_{i=1}^n \lambda_i \mathbb{P}_i \]
Worked Example

Prove that the matrix \(\begin{bmatrix} 1 & 0 \\ 1 & 1 \end{bmatrix}\) is not diagonalizable.

Show solution

A matrix is not diagonalizable if it is defective, i.e. \(AM(\lambda_i)\neq GM(\lambda_i)\). The eigenvalues are \(\lambda=1,1\) (lower triangular). The corresponding eigenvector is \(\begin{bmatrix} 0 \\1 \end{bmatrix}\). Thus \(GM(\lambda=1)=1\) but \(AM(\lambda=1)=2\); they are not equal and hence the matrix is defective, thus non-diagonalizable.

Commutator and Anti-Commutator

Definition — Commutator and Anti-Commutator

The commutator of two operators \(A\) and \(B\) is \([A,B]=AB-BA\). The anti-commutator is \(\{A,B\}=AB+BA\).

Properties of the Commutator:

Simultaneous Diagonalization of two Hermitian Operators

Definition

Suppose \(A\) and \(B\) are Hermitian operators. Then \([A,B]=0\) if and only if there exists an orthonormal basis such that both \(A\) and \(B\) are diagonal with respect to that basis. We say that \(A\) and \(B\) are simultaneously diagonalizable.

Operator Functions

We restrict ourselves to functions that can be written as a power series. Consider a series

\[ f(x)=\sum_{n=0}^{\infty} a_nx^n \]

where \(a_n\) are complex numbers. This is a function from complex numbers to complex numbers. Then we can define the same function for an operator to be

\[ f(A)=\sum_{n=0}^{\infty} a_nA^n \]

where \(A^n\) is the product of the operator \(A\) with itself \(n\) times.

It is possible to define a corresponding matrix function on normal matrices (or some subclass, such as the Hermitian matrices) by the following construction. Let \(A=\sum_a a\ket{a}\bra{a}\) be a spectral decomposition of a normal operator \(A\). Define \(f(A)=\sum_a f(a)\ket{a}\bra{a}\). This is uniquely defined and can be used to define, for example, the square root of a positive operator, the logarithm of a positive-definite operator, or the exponential of a normal operator. For example,

\[ \exp(\theta Z)=\begin{bmatrix} e^{\theta} & 0 \\ 0 & e^{-\theta} \end{bmatrix} \]

since \(Z\) has eigenvectors \(\ket{0}\) and \(\ket{1}\).

Worked Example

Consider the exponential series \(e^x=1+x+\frac{x^2}{2!}+\ldots = \sum_{n=0}^{\infty} \frac{x^n}{n!}\). Then the exponential of an operator \(A\) is defined as

\[ e^A=I+A+\frac{A^2}{2!}+\frac{A^3}{3!}+\ldots = \sum_{n=0}^{\infty} \frac{A^n}{n!}\]

Note that \(A\) must be a square matrix in order for the matrix multiplications and additions to be defined.

Note that the matrix exponential is defined for all kinds of matrices, not necessarily normal or non-defective matrices. A matrix to the 0th power is the identity matrix.

Worked Example

Consider the matrix \(A\) which does not have \(n\) independent eigenvectors:

\[A=\begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix}\]
Show solution

Its eigenvalues are \(\lambda=0,0\) and it has only one eigenvector \(\ket{v_1}=\begin{bmatrix} 1 \\ 0 \end{bmatrix}\). To find \(e^A\), use the exponential series. Calculating \(A^2\):

\[A^2=\begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix}\begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix}=\begin{bmatrix} 0 & 0 \\ 0 & 0 \end{bmatrix}\]

Thus, the series reduces to

\[e^A=I+A=\begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}\]

It is in general very difficult to calculate the matrix exponential, but when we restrict ourselves to an operator \(A\) which is non-defective (has a full independent set of eigenvectors), so \(A=V\Lambda V^{-1}\), it becomes easy to compute:

\[\begin{aligned} e^A&=I+A+\frac{A^2}{2!}+\ldots\\ &=V\left(I+\Lambda + \frac{\Lambda^2}{2!}+\frac{\Lambda^3}{3!}+\ldots\right)V^{-1} = V e^{\Lambda}V^{-1}\\ &=V\begin{pmatrix} e^{\lambda_1} & 0 & \ldots & 0 \\ 0 & e^{\lambda_2} & \ldots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \ldots & e^{\lambda_n} \end{pmatrix} V^{-1} \end{aligned}\]

In the case of \(A\) being a normal (or Hermitian) matrix, \(A=V\Lambda V^{\dagger}\). In the eigenbasis of \(A\), \(A^n\) has diagonal entries \(\lambda_i^n\), and thus

\[ e^A = \begin{pmatrix} e^{\lambda_1} & 0 & \ldots & 0 \\ 0 & e^{\lambda_2} & \ldots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \ldots & e^{\lambda_n} \end{pmatrix} \]
Worked Example

The square root and logarithm of the matrix

\[X=\begin{bmatrix} 4 & 3 \\ 3 & 4 \end{bmatrix}=7\begin{bmatrix} 1/\sqrt{2} \\ 1/\sqrt{2} \end{bmatrix} \begin{bmatrix} 1/\sqrt{2} & 1/\sqrt{2} \end{bmatrix} + \begin{bmatrix} 1/\sqrt{2} \\ -1/\sqrt{2} \end{bmatrix} \begin{bmatrix} 1/\sqrt{2} & -1/\sqrt{2} \end{bmatrix}\]
Show solution

Its square root is

\[\sqrt{X} = \sqrt{7}\begin{bmatrix} 1/\sqrt{2} \\ 1/\sqrt{2} \end{bmatrix} \begin{bmatrix} 1/\sqrt{2} & 1/\sqrt{2} \end{bmatrix} + \begin{bmatrix} 1/\sqrt{2} \\ -1/\sqrt{2} \end{bmatrix} \begin{bmatrix} 1/\sqrt{2} & -1/\sqrt{2} \end{bmatrix}=\begin{bmatrix} \frac{\sqrt{7}+1}{2} & \frac{\sqrt{7}-1}{2} \\ \frac{\sqrt{7}-1}{2} & \frac{\sqrt{7}+1}{2} \end{bmatrix}\]

and similarly the logarithm is

\[\log(X)=\begin{bmatrix} \frac{\log(7)}{2} & \frac{\log(7)}{2} \\ \frac{\log(7)}{2} & \frac{\log(7)}{2} \end{bmatrix}\]

Some results:

Trace of a Matrix

Definition — Trace

The trace of a matrix is the sum of the diagonal elements, denoted \(Tr(A)=\sum_{i=1}^n a_{ii}\).

Properties of Trace:

Norms

Definition — Norm

A real valued function defined on a vector space (\(\mathbb{C}^m \rightarrow \mathbb{R}\)) is called a norm (denoted \(\|x\|\)) if it satisfies:

  • \(\|x\| \geq 0\) and \(\|x\|=0\) if and only if \(x=0\).
  • \(\|\alpha x\|=|\alpha|\|x\|\) for any scalar \(\alpha\).
  • \(\|x+y\| \leq \|x\|+\|y\|\) (Triangle Inequality).

Thus, \(\|\alpha_1x_1+\cdots +\alpha_n x_n\| \leq |\alpha_1|\|x_1\|+\cdots + |\alpha_n|\|x_n\|\). In general, the norm of a vector is the measure of the length of the vector. The p-norm of a vector is defined as

\[ \|x\|_p=\left(\sum_{i=1}^n |x_i|^p\right)^{1/p} \]

The 1-norm is \(\|x\|_1=\sum_{i=1}^n |x_i|\). The 2-norm (Euclidean norm) is \(\|x\|_2=(\sum_{i=1}^n |x_i|^2)^{1/2}\). The \(\infty\)-norm is \(\|x\|_{\infty}=\max_{1\leq i \leq n} |x_i|\), the maximum of the absolute values of the elements.

Properties of Norms:

where \(x \in \mathbb{C}^n\).

Induced Matrix Norm

Definition — Induced Matrix Norm

The induced matrix norm of a matrix \(A\) is defined as \(\|A\|_p=\max_{\|v\|_p=1} \|Av\|_p\), where \(\|v\|_p\) is the p-norm of the vector \(v\).

In other words, it is the factor by which a matrix can scale a vector. It is also called the Spectral Norm. For the purpose of these notes, we consider the induced 2-norm (Euclidean norm).

Properties of Induced Matrix Norm:

Conditioning and Condition Number

In this section we find the condition number of a matrix-times-vector multiplication. Let \(y=Ax\) where \(A\) is a matrix and \(x\) is a vector. The input is a vector and the output is \(Ax\). Thus,

\[\begin{aligned} \kappa(x) &= \max_{\delta x}\frac{\|A(x+\delta x) - Ax\|/\|Ax\|}{\|\delta x\|/\|x\|}\\ &=\frac{\|x\|}{\|Ax\|}\left(\max_{\delta x} \frac{\|A\delta x\|}{\|\delta x\|}\right)=\frac{\|A\|\|x\|}{\|Ax\|} \end{aligned}\]

Let \(A\) be a square, non-singular matrix. Then \(A^{-1}\) exists, so \(\|x\|=\|A^{-1}Ax\|\leq \|A^{-1}\|\|Ax\|\), hence \(\frac{\|x\|}{\|Ax\|}\leq \|A^{-1}\|\). Substituting,

\[\kappa(x)\leq \|A\|\|A^{-1}\|\]

Thus, we define the condition number for a matrix-vector multiplication with \(\kappa(x)=\|A\|\|A^{-1}\|\). For the problem of solving \(Ax=b\) via \(x=A^{-1}b\), the condition number is \(\kappa(A)=\|A\|\|A^{-1}\|\). In the 2-norm sense,

\[\kappa(A)=\|A\|_2\|A^{-1}\|_2=\frac{\sigma_{max}}{\sigma_{min}}=\sqrt{\frac{\lambda_{max}(A^{\dagger} A)}{\lambda_{min}(A^{\dagger}A)}}\]

where \(\sigma_{max}\) and \(\sigma_{min}\) are the maximum and minimum singular values. If \(A\) is Hermitian then

\[\kappa(A)=\frac{|\lambda_{max}(A)|}{|\lambda_{min}(A)|}\]

where \(\lambda_{max}\) and \(\lambda_{min}\) are in the absolute sense.

17.2 Tensor Products

The tensor product is a method for combining two vector spaces to obtain a new, larger vector space.

Definition — Tensor Product

Suppose \(V\) and \(W\) are vector spaces of dimensions \(m\) and \(n\) respectively. For convenience we also suppose that \(V\) and \(W\) are Hilbert Spaces. Then \(V \otimes W\) (read as "\(V\) tensor \(W\)") is a vector space of dimension \(mn\) such that any vector in \(V \otimes W\) can be written as a linear combination of the tensor products of the vectors in \(V\) and \(W\). The elements of \(V \otimes W\) are linear combinations of tensor products \(\ket{v} \otimes \ket{w}\) of elements \(\ket{v}\) of \(V\) and \(\ket{w}\) of \(W\). For example, if \(\ket{i}\) and \(\ket{j}\) are orthonormal bases for the spaces \(V\) and \(W\) then \(\ket{i} \otimes \ket{j}\) is a basis for \(V \otimes W\). We often use abbreviated notations \(\ket{v}\ket{w}\), \(\ket{v,w}\), or \(\ket{vw}\) for the tensor product \(\ket{v} \otimes \ket{w}\).

  • For an arbitrary scalar \(z\): \(z(\ket{v} \otimes \ket{w}) = (z\ket{v}) \otimes \ket{w} = \ket{v} \otimes (z\ket{w})\)
  • For arbitrary \(\ket{v_1},\ket{v_2}\) in \(V\) and \(\ket{w}\) in \(W\): \((\ket{v_1}+\ket{v_2}) \otimes \ket{w} = \ket{v_1} \otimes \ket{w} + \ket{v_2} \otimes \ket{w}\)
  • For arbitrary \(\ket{v}\) in \(V\) and \(\ket{w_1},\ket{w_2}\) in \(W\): \(\ket{v} \otimes (\ket{w_1}+\ket{w_2}) = \ket{v} \otimes \ket{w_1} + \ket{v} \otimes \ket{w_2}\)
Worked Example

If \(V\) is a two-dimensional vector space with basis vectors \(\ket{0}\) and \(\ket{1}\) then \(\ket{0} \otimes \ket{0} + \ket{1} \otimes \ket{1}\) is an element of \(V \otimes V\).

Linear operators can act on the space \(V\otimes W\). Suppose \(\ket{v}\) and \(\ket{w}\) are vectors in \(V\) and \(W\), and \(A\) and \(B\) are linear operators on \(V\) and \(W\). Then we define a linear operator \(A \otimes B\) on \(V \otimes W\) by

\[ (A \otimes B)(\ket{v} \otimes \ket{w}) = A\ket{v} \otimes B\ket{w} \]

Consider the tensor products \(X = A \otimes B\) and \(Y = C \otimes D\). We have

\[ X = A \otimes B = \begin{pmatrix} a_{11} B & a_{12} B & \cdots & a_{1n} B \\ a_{21} B & a_{22} B & \cdots & a_{2n} B \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} B & a_{m2} B & \cdots & a_{mn} B \end{pmatrix}, \] \[ Y = C \otimes D = \begin{pmatrix} c_{11} D & c_{12} D & \cdots & c_{1r} D \\ c_{21} D & c_{22} D & \cdots & c_{2r} D \\ \vdots & \vdots & \ddots & \vdots \\ c_{n1} D & c_{n2} D & \cdots & c_{nr} D \end{pmatrix}. \]

Expanding the product \((A \otimes B)(C \otimes D)\):

\[\begin{aligned} (A \otimes B)(C \otimes D) &= \begin{bmatrix} \sum_{i} a_{1i} c_{i1} BD & \cdots & \sum_{i} a_{1i} c_{ir} BD \\ \vdots & \ddots & \vdots \\ \sum_{i} a_{ni} c_{i1} BD & \cdots & \sum_{i} a_{ni} c_{ir} BD \end{bmatrix}\\ &=\begin{bmatrix} \sum_{i} a_{1i} c_{i1} & \cdots & \sum_{i} a_{1i} c_{ir} \\ \vdots & \ddots & \vdots \\ \sum_{i} a_{ni} c_{i1} & \cdots & \sum_{i} a_{ni} c_{ir} \end{bmatrix} \otimes BD = AC \otimes BD \end{aligned}\]

This simplifies to

\[ (A \otimes B)(C \otimes D) = (AC) \otimes (BD). \]

It can be shown that \(A \otimes B\) is a well-defined linear operator on \(V\otimes W\). The definition is extended to all elements of \(V \otimes W\) in the natural way to ensure linearity:

\[ (A \otimes B)\left(\sum_{i} a_{i} \ket{v_i} \otimes \ket{w_i}\right) = \sum_{i} a_i A\ket{v_i} \otimes B\ket{w_i} \]

Consider the case where \(A:V \rightarrow V'\) and \(B:W \rightarrow W'\) are linear operators. Then an arbitrary linear operator \(C\) mapping \(V \otimes W\) to \(V' \otimes W'\) can be represented as a linear combination of tensor products of operators:

\[ C=\sum_{i} c_{i} A_i \otimes B_i \]

where \(\left( \sum_i c_i A_i \otimes B_i\right) \left(\ket{v} \otimes \ket{w}\right) = \sum_i c_i A_i \ket{v} \otimes B_i \ket{w}\).

The inner product on the spaces \(V\) and \(W\) can be used to define a natural inner product on \(V \otimes W\):

\[ \left( \sum_i a_i\ket{v_i}\otimes \ket{w_i}, \sum_j b_j \ket{v'_j} \otimes \ket{w'_j}\right) \equiv \sum_{ij} a_i^*b_j\braket{v_i|v'_j}\braket{w_i|w'_j} \]

The inner product space \(V \otimes W\) inherits the other structure we are familiar with, such as notions of an adjoint, unitarity, normality and Hermiticity. For four matrices \(A,B,C\) and \(D\), we have \((A\otimes B)(C\otimes D)=(AC\otimes BD)\), given that \(AC\) and \(BD\) are defined.

Kronecker Product. Suppose \(A\) is an \(m \times n\) matrix and \(B\) is a \(p \times q\) matrix. Then we have the matrix representation:

\[ A \otimes B \equiv \begin{pmatrix} a_{11}B & a_{12}B & \ldots & a_{1n}B \\ a_{21}B & a_{22}B & \ldots & a_{2n}B \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1}B & a_{m2}B & \ldots & a_{mn}B \end{pmatrix} \]

In this representation, terms like \(a_{11}B\) denote \(p \times q\) matrices whose entries are proportional to \(B\), with overall proportionality constant \(a_{11}\).

Useful notation: \(\ket{\psi}^{\otimes n}\) denotes \(\psi\) tensored with itself \(n\) times. For example, \(\ket{\psi}^{\otimes 2} = \psi \otimes \psi\). Similar notation is used for operators/matrices.

In plain terms: the tensor product is how you build the state space of many qubits out of the state space of one. Two qubits live in a \(2 \times 2 = 4\)-dimensional space, three qubits in an 8-dimensional space, and so on. This exponential growth (\(2^n\) dimensions for \(n\) qubits) is exactly the resource that makes quantum computers powerful. The Kronecker product is just the concrete "stack copies of B, scaled by each entry of A" recipe for writing it down as a matrix.

Properties of Tensor Products:

Worked Example

Consider one qubit \(\ket{\psi}=\alpha \ket{0} + \beta \ket{1}\). Then the tensor product of \(\ket{\psi}\) with itself is:

\[ \ket{\psi} \otimes \ket{\psi} = \alpha^2 \ket{00} + \alpha \beta \ket{01} + \alpha \beta \ket{10} + \beta^2 \ket{11} \]

Thus, in matrix form:

\[ \begin{pmatrix} \alpha \\ \beta \end{pmatrix} \otimes \begin{pmatrix} \alpha \\ \beta \end{pmatrix} = \begin{pmatrix} \alpha \begin{pmatrix} \alpha \\ \beta \end{pmatrix} \\ \beta \begin{pmatrix} \alpha \\ \beta \end{pmatrix} \end{pmatrix} = \begin{pmatrix} \alpha^2 \\ \alpha \beta \\ \alpha \beta \\ \beta^2 \end{pmatrix} \]
Worked Example

Consider the matrices \(A=\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}\) and \(B=\begin{pmatrix} 5 & 6 \\ 7 & 8 \end{pmatrix}\). Then the Kronecker product is:

\[ A \otimes B = \begin{pmatrix} 1 \, B & 2 \, B \\ 3 \, B & 4 \, B \end{pmatrix} = \begin{pmatrix} 5 & 6 & 10 & 12 \\ 7 & 8 & 14 & 16 \\ 15 & 18 & 20 & 24 \\ 21 & 24 & 28 & 32 \end{pmatrix} \]
Worked Example

Consider \(\ket{\psi}=\iota \ket{0} + 7 \ket{1}\) and \(\ket{\phi}=\ket{00}+3\ket{10}+7\ket{11}\). Then the tensor product is

\[ \ket{\psi}\otimes \ket{\phi} = \iota \ket{000} + 3\iota\ket{010} + 7\iota \ket{011} + 7\ket{100} +21 \ket{110} + 49 \ket{111} \]

Thus, in matrix form:

\[ \begin{pmatrix} \iota \\ 7 \end{pmatrix} \otimes \begin{pmatrix} 1 \\ 0 \\ 3 \\ 7 \end{pmatrix} = \begin{pmatrix} \iota \\ 0 \\ 3\iota \\ 7\iota \\ 7 \\ 0 \\ 21 \\ 49 \end{pmatrix} \]
Worked Example

Say \(\ket{\alpha}=3\ket{0}+\iota\ket{1}\) and \(\ket{\beta}=\ket{00}+2 \ket{10}+7\ket{11}\). Then the outer product \(\ket{\alpha}\bra{\beta}\) is:

\[ \ket{\alpha}\bra{\beta}=3\ket{0}\bra{00}+6\ket{0}\bra{10}+21\ket{0}\bra{11}+\iota\ket{1}\bra{00}+2\iota\ket{1}\bra{10}+7\iota\ket{1}\bra{11}\]

In matrix form, it can be written as:

\[\begin{pmatrix} 3 & 0 & 6 & 21 \\\iota & 0 & 2\iota & 7\iota \end{pmatrix}\]
Worked Example

Say a matrix \(A=\begin{pmatrix} 0 & 1\\3 & \iota \\7 & 0\\0 & 13\end{pmatrix}\). Then in outer product form it can be written as:

\[ A = \ket{00}\bra{1} + 3\ket{01}\bra{0} + \iota \ket{01}\bra{1} + 7\ket{10}\bra{0} + 13 \ket{11}\bra{1}\]
Worked Example

Let \(\ket{\psi}=(\ket{0}+\ket{1})/\sqrt{2}\). Write out \(\ket{\psi}^{\otimes 2}\) and \(\ket{\psi}^{\otimes 3}\) explicitly, both in terms of tensor products and using the Kronecker product.

Show solution
\[ \ket{\psi}^{\otimes 2} = \frac{\ket{00}+\ket{01}+\ket{10}+\ket{11}}{2}=\begin{bmatrix} 1/2 \\ 1/2 \\ 1/2 \\1/2 \end{bmatrix} \] \[ \ket{\psi}^{\otimes 3}=\frac{\ket{000}+\ket{001}+\ket{010}+\ket{011}+\ket{100}+\ket{101}+\ket{110}+\ket{111}}{2\sqrt{2}}=\begin{bmatrix} \frac{1}{2\sqrt{2}} \\ \frac{1}{2\sqrt{2}} \\\frac{1}{2\sqrt{2}}\\\frac{1}{2\sqrt{2}}\\\frac{1}{2\sqrt{2}}\\\frac{1}{2\sqrt{2}}\\\frac{1}{2\sqrt{2}}\\\frac{1}{2\sqrt{2}} \end{bmatrix} \]
Worked Example

Show that the transpose, complex conjugation and adjoint operations distribute over the tensor product.

Show solution

Using the Kronecker product of \(A \otimes B\):

\[ (A \otimes B)^* =\begin{bmatrix} A_{11}B & \ldots & A_{1n}B \\ \vdots & \ddots & \vdots \\ A_{m1}B & \ldots & A_{mn}B \end{bmatrix}^* = \begin{bmatrix} A_{11}^*B^* & \ldots & A_{1n}^*B^* \\ \vdots & \ddots & \vdots \\ A_{m1}^*B^* & \ldots & A_{mn}^*B^* \end{bmatrix}=A^* \otimes B^* \] \[ (A\otimes B)^T=\begin{bmatrix} A_{11}B^T & \ldots & A_{n1}B^T \\ \vdots & \ddots & \vdots \\ A_{1m}B^T & \ldots & A_{nm}B^T \end{bmatrix}=A^T \otimes B^T \]

The distributivity of the Hermitian conjugate then follows:

\[ (A \otimes B)^{\dagger}=((A\otimes B)^T)^*=(A^T\otimes B^T)^*=A^{\dagger} \otimes B^{\dagger} \]
Worked Example

Show that the tensor product of two unitary operators is unitary.

Show solution

Suppose \(A,B\) are unitary, so \(A^{\dagger}A=I\) and \(B^{\dagger}B=I\). Then

\[ (A\otimes B)^{\dagger}(A\otimes B)=(A^{\dagger} \otimes B^{\dagger})(A\otimes B)=(A^{\dagger}A \otimes B^{\dagger}B)=I\otimes I \]
Worked Example

Show that the tensor product of two Hermitian operators is Hermitian.

Show solution

Suppose \(A,B\) are Hermitian, so \(A^{\dagger}=A\) and \(B^{\dagger}=B\). Then \((A\otimes B)^{\dagger} = A^{\dagger} \otimes B^{\dagger} =A \otimes B\).

Worked Example

Show that the tensor product of two positive operators is positive.

Show solution

Suppose \(A\) and \(B\) are positive, so \(\braket{v|A|v}\geq 0\) and \(\braket{w|B|w}\geq 0\). Therefore, for any \(\ket{v}\otimes \ket{w}\):

\[ (\bra{v} \otimes \bra{w})(A \otimes B) (\ket{v} \otimes \ket{w})=\braket{v|A|v}\braket{w|B|w}\geq 0 \]
Worked Example

Show that the tensor product of two projectors is a projector.

Show solution

Let \(P_1,P_2\) be projectors, so \(P_1^2=P_1\) and \(P_2^2=P_2\). Then

\[ (P_1\otimes P_2)^2=(P_1\otimes P_2)(P_1\otimes P_2)=P_1^2\otimes P_2^2=P_1 \otimes P_2 \]

so \(P_1\otimes P_2\) is a projector.

Factorizing Tensor Products

Consider \(\ket{\psi}=\frac{1}{2}\ket{00}-\frac{\iota}{2}\ket{10}+\frac{1}{\sqrt{2}}\ket{11}\). We can factorize the tensor product as follows. Assume \(\ket{\psi}=\ket{\phi}\ket{\chi}\) where \(\ket{\phi}=a\ket{0}+b\ket{1}\) and \(\ket{\chi}=c\ket{0}+d\ket{1}\). Then

\[ \ket{\phi}\otimes \ket{\chi}=ac\ket{00}+ad\ket{01}+bc\ket{10}+bd\ket{11} \]

Equating with \(\ket{\psi}\):

\[ ac=\tfrac{1}{2}, \quad ad=0, \quad bc=-\tfrac{\iota}{2}, \quad bd=\tfrac{1}{\sqrt{2}} \]

Thus, \(a=\frac{1}{\sqrt{2}}, b=0, c=1, d=\frac{1}{\sqrt{2}}\) (one consistent solution), and the tensor product factorizes.

Now consider \(\ket{\psi}=\frac{1}{\sqrt{2}}\ket{00}+\frac{1}{\sqrt{2}}\ket{01}\). Assuming \(\ket{\psi}=\ket{\phi}\ket{\chi}\) as before and equating:

\[ ac=\tfrac{1}{\sqrt{2}}, \quad ad=0, \quad bc=0, \quad bd=\tfrac{1}{\sqrt{2}} \]

No such values of \(a,b,c\) and \(d\) exist. Hence it cannot be factorized.

A state that factorizes is called a product (separable) state — the two qubits are independent. A state that cannot be factorized, like the second example, is entangled: the qubits are correlated in a way that has no classical analogue. Entanglement is the engine behind teleportation, superdense coding, and much of quantum computing's advantage.

17.3 Complex Numbers

Complex Plane

The complex plane is as denoted in the figure below, with the \(y\)-axis as the imaginary axis and the \(x\)-axis as the real axis.

              Im
               ^
    -1+i  •     |     •  1+i
               |
  -------------+-------------> Re
               |
    -1-i  •     |     •  1-i
               |
Figure — The complex plane, showing the four points \(z=1+i\), \(z=1-i\), \(z=-1+i\) and \(z=-1-i\). The horizontal axis is the real part and the vertical axis is the imaginary part.

A complex number in cartesian coordinate form is denoted \(z=a+\iota b\) where \(\iota =\sqrt{-1}\) and \(a,b \in \mathbb{R}\), which can be written as a column vector \(z=\begin{pmatrix} a \\ b \end{pmatrix}\).

Addition of Complex Numbers

\[ z_1+z_2=(a_1+\iota b_1)+(a_2+\iota b_2)=(a_1+a_2)+\iota(b_1+b_2) \]

Thus, the addition of complex numbers is the same as the addition of vectors in the complex plane.

Properties:

Multiplication of Complex Numbers

\[ z_1z_2=(a_1+\iota b_1)(a_2+\iota b_2)=a_1a_2-b_1b_2+\iota(a_1b_2+a_2b_1) \]

Properties:

Complex Conjugate

The complex conjugate of a complex number \(z=a+\iota b\) is denoted \(\bar{z}=a-\iota b\). It is the reflection of the complex number about the real axis.

Properties:

Modulus of a Complex Number

The modulus of a complex number \(z=a+\iota b\) is denoted \(|z|=\sqrt{a^2+b^2}\), the distance of the complex number from the origin in the complex plane.

Properties:

Polar form

The polar form of a complex number \(z=a+\iota b\) is \(z=r(\cos\theta+\iota \sin\theta)\) where \(r=|z|\) and \(\theta=\tan^{-1}(\frac{b}{a})\). It represents the complex number in terms of its modulus and argument.

Properties:

Euler's Formula

\(z=a+\iota b=re^{\iota \theta}\). Recall that the expansion of \(e^x\) using the Taylor series is

\[ e^x=1+x+\frac{x^2}{2!}+\frac{x^3}{3!}+\ldots = \sum_{n=0}^{\infty} \frac{x^n}{n!}\]

Now substituting \(\iota \theta\) in place of \(x\):

\[ e^{\iota \theta}=1+\iota \theta-\frac{\theta^2}{2!}-\iota \frac{\theta^3}{3!}+\ldots \]

On rearranging the terms:

\[ e^{\iota \theta}= \left(1-\frac{\theta^2}{2!} + \frac{\theta^4}{4!} - \ldots\right) + \iota\left(\theta-\frac{\theta^3}{3!}+\frac{\theta^5}{5!}-\ldots\right) \]

Recall the Taylor series expansions of \(\sin\) and \(\cos\):

\[ \sin\theta=\theta-\frac{\theta^3}{3!}+\frac{\theta^5}{5!}-\ldots, \qquad \cos\theta=1-\frac{\theta^2}{2!}+\frac{\theta^4}{4!}-\ldots \]

Thus, Euler's formula states that \(e^{\iota \theta}=\cos\theta+\iota \sin\theta\). Substituting into the polar form:

\[ z=a+\iota b = r(\cos\theta+\iota \sin\theta)=re^{\iota \theta} \]

where \(r=|z|\) and \(\theta=\tan^{-1}(\frac{b}{a})\). Using this we can also write:

\[ \cos \theta = \frac{e^{\iota \theta}+e^{-\iota \theta}}{2}, \qquad \sin \theta = \frac{e^{\iota \theta}-e^{-\iota \theta}}{2\iota} \]

17.4 Probability Theory

This section is reserved for probability theory prerequisites; the essential probabilistic tools used later (measurement probabilities, expectation values) are introduced in context in the main quantum computing chapters.

17.5 Calculus

Exponentials of matrices generally arise in Quantum Mechanics as the solution to the Schrödinger equation when the matrix \(H\) is constant. The Schrödinger equation is given as

\[ \iota \hbar\frac{\partial}{\partial t}\ket{\psi}=\hat{H}\ket{\psi} \]

with the initial condition at \(t=0\) as \(\ket{\psi(0)}\). When the Hamiltonian \(\hat{H}\) is a constant matrix, the above equation can be simplified to

\[\begin{aligned} \frac{\partial}{\partial t}\ket{\psi(t)}&=- \frac{\iota\hat{H}}{\hbar}\ket{\psi}\\ \ket{\psi(t)}&=e^{-\iota \hat{H}t/\hbar }\ket{\psi(0)} \end{aligned}\]
The upshot: solving quantum dynamics with a constant Hamiltonian is exactly the matrix-exponential machinery from the Operator Functions section. Because \(\hat H\) is Hermitian, \(e^{-\iota \hat H t/\hbar}\) is unitary — so time evolution is a norm-preserving rotation of the state vector, consistent with total probability staying equal to 1.

17.6 Group Theory

The mathematical theory of groups is useful at several points in the study of quantum computation and quantum information. The generalization of the order-finding, factoring, and period-finding algorithms is based on the hidden subgroup problem; the stabilizer formalism for quantum error correction is based on some elementary group theory. Number theory uses the properties of the group \(Z_n^*\). And, implicitly, the quantum circuits used throughout are an example of the use of Lie groups. In this section we review some basic material on group theory.

Basic Definitions

Definition — Group

A group \((G,\cdot)\) is a non-empty set \(G\) with a binary group multiplication operation "\(\cdot\)", with the following properties:

  • (Closure) \(g_1 \cdot g_2 \in G\) for all \(g_1,g_2 \in G\)
  • (Associativity) \((g_1 \cdot g_2) \cdot g_3 = g_1 \cdot (g_2 \cdot g_3)\) for all \(g_1,g_2,g_3 \in G\)
  • (Identity) There exists \(e\in G\) such that \(\forall g\in G,\ g\cdot e =e\cdot g =g\)
  • (Inverses) \(\forall g \in G\), there exists \(g^{-1} \in G\) such that \(g\cdot g^{-1}=e\) and \(g^{-1}\cdot g=e\)

We often leave out \(\cdot\) and write \(g_1\cdot g_2\) as simply \(g_1g_2\).

A group \(G\) is finite if the number of elements in \(G\) is finite. The order of a finite group \(G\) is the number of elements it contains, denoted \(|G|\). A group \(G\) is said to be abelian if \(g_1g_2=g_2g_1\) for all \(g_1,g_2 \in G\). A simple example of a finite abelian group is the additive group \(\mathbb{Z}_n\) of integers modulo \(n\), with the "multiplication" operation being modular addition. There is an identity element \(0\), since \(x+0=x \pmod n\) for all \(x\), and every \(x\) has an inverse \(n-x\).

The order of an element \(g \in G\) is the smallest positive integer \(r\) such that \(g^r\) (\(g\) multiplied with itself \(r\) times) equals the identity element \(e\). A subgroup \(H\) of \(G\) is a subset of \(G\) which forms a group under the same group multiplication operation as \(G\).

Theorem — Lagrange's Theorem

If \(H\) is a subgroup of a finite group \(G\) then \(|H|\) divides \(|G|\).

Practice Problem

Prove that for any element \(g\) of a finite group, there always exists a positive integer \(r\) such that \(g^r=e\). That is, every element of such a group has an order.

Show solution

Consider the sequence \(g, g^2, g^3, \ldots\). Since \(G\) is finite, these powers cannot all be distinct, so there exist \(i \lt j\) with \(g^i=g^j\). Multiplying by \((g^{-1})^i\) gives \(g^{j-i}=e\) with \(j-i \geq 1\) a positive integer.

Practice Problem

Show that the order of an element \(g\in G\) divides \(|G|\).

Show solution

The powers \(\{e, g, g^2, \ldots, g^{r-1}\}\) (where \(r\) is the order of \(g\)) form a cyclic subgroup of \(G\) of size \(r\). By Lagrange's theorem, \(r\) divides \(|G|\).

If \(g_1\) and \(g_2\) are elements of \(G\), then the conjugate of \(g_2\) with respect to \(g_1\) is the element \(g_1^{-1}g_2g_1\). If \(H\) is a subgroup of \(G\), then it is known as a normal subgroup if \(g^{-1}Hg=H\) for all \(g \in G\). The conjugacy class \(G_x\) of an element \(x\) in a group \(G\) is defined by \(G_x \equiv \{g^{-1}xg\,|\,g\in G\}\).

Practice Problem

Show that if \(y\in G_x\) then \(G_y=G_x\).

Worked Example

Show that if \(x\) is an element of an abelian group \(G\) then \(G_x=\{x\}\).

Show solution

Since \(G\) is abelian, \(g_1g_2=g_2g_1\) for all \(g_1,g_2 \in G\). Thus \(G_x = \{g^{-1}xg\,|\,g\in G\} = \{g^{-1}gx\,|\,g\in G\} = \{x\,|\,g\in G\}\) since \(g^{-1}g=e\). Thus \(G_x = \{x\}\).

An interesting example of a group which is not abelian is the Pauli group on \(n\) qubits. For a single qubit, the Pauli group is defined to consist of all the Pauli matrices, with multiplicative factors \(\pm 1,\pm \iota\):

\[ G_1 \equiv \{\pm I,\pm \iota I,\pm X, \pm \iota X,\pm Y,\pm \iota Y,\pm Z, \pm \iota Z\} \]

This set of matrices forms a group under matrix multiplication. The reason the multiplicative factors \(\pm 1\) and \(\pm \iota\) are included is to ensure that \(G_1\) is closed under multiplication, and thus forms a legitimate group. The general Pauli group on \(n\) qubits is defined to consist of all \(n\)-fold tensor products of Pauli matrices, again with multiplicative factors of \(\pm 1, \pm \iota\).

Generators

The study of groups is often greatly simplified by the use of a set of group generators. A set of elements \(g_1,\ldots,g_l\) in a group \(G\) is said to generate the group \(G\) if every element of \(G\) can be written as a product of (possibly repeated) elements from the list \(g_1,\ldots, g_l\), and we write \(G=\braket{g_1,\ldots,g_l}\). For example, \(G_1=\braket{X,Z,\iota I}\), since every element in \(G_1\) can be written as a product of \(X\), \(Z\) and \(\iota I\). On the other hand, \(\braket{X}=\{I,X\}\), a subgroup of \(G_1\), since not every element of \(G_1\) can be written as a power of \(X\).

The great advantage of using generators to describe groups is that they provide a compact means of describing the group. Suppose \(G\) has size \(|G|\). Then it is easy to show that there is a set of \(\log(|G|)\) generators generating \(G\). To see this, suppose \(g_1,\ldots,g_l\) is a set of elements in \(G\), and \(g\) is not an element of \(\braket{g_1,\ldots,g_l}\). Let \(f \in\braket{g_1,\ldots,g_l}\). Then \(fg\notin \braket{g_1,\ldots,g_l}\), since if it were then we would have \(g=f^{-1}fg \in \braket{g_1,\ldots,g_l}\), which is false by assumption. Thus for each element \(f \in \braket{g_1,\ldots,g_l}\) there is an element \(fg\) which is in \(\braket{g_1,\ldots,g_l,g}\) but not in \(\braket{g_1,\ldots,g_l}\). Thus adding the generator \(g\) doubles (or more) the size of the group generated, from which we conclude that \(G\) must have a set of generators containing at most \(\log(|G|)\) elements.

The point of generators is compression: instead of listing every element of a group, you list a handful of building blocks and get everything else by multiplying them together. Because each new independent generator at least doubles the reachable set, you never need more than about \(\log_2|G|\) of them to describe the whole group — the same reason a few bits can index a large space.

17.7 Number Theory

The following section will be very useful in understanding the concepts behind the order-finding algorithm and will form the foundation for Shor's algorithm.

Fundamentals

We will start off by agreeing about a few conventions for nomenclature and notation. The set of integers is the set \(\{\ldots,-2,-1,0,1,2,\ldots\}\), denoted \(\mathbf{Z}\). We may occasionally refer to the natural numbers, meaning non-negative integers, but more often we'll say non-negative integer or positive integer, in order to make a distinction between the case when zero is included, and when zero is not included.

Suppose \(n\) is an integer. An integer \(d\) divides \(n\) (written as \(d\mid n\)) if there exists an integer \(k\) such that \(n=dk\). We say in this case that \(d\) is a factor or divisor of \(n\). Notice that \(1\) and \(n\) are always factors of \(n\). When \(d\) does not divide (is not a factor of) \(n\) we write \(d\nmid n\). For example, \(3\mid 6\) and \(3\mid 18\), but \(3\nmid 5\) and \(3\nmid 7\).

Worked Example

(Transitivity) If \(a\mid b\) and \(b\mid c\) then \(a\mid c\).

As \(a\mid b \implies b=pa\) and \(b\mid c \implies c=qb\) for some integers \(q\) and \(p\). Thus, substituting the value of \(b\) gives \(c=qb=(qp)a \implies a\mid c\) for some integer \(pq = p\times q\) (since the multiplication of two integers is an integer).

Worked Example

Show that if \(d\mid a\) and \(d\mid b\) then \(d\) also divides the linear combination of \(a\) and \(b\), namely \(ax+by\), where \(x\) and \(y\) are integers.

Show solution

\(d\mid a \implies a=pd\) and \(d\mid b \implies b=qd\) for some integers \(p\) and \(q\). Thus, \(ax+by= pdx+qdy = (px+qy)d \implies d\mid(ax+by)\), since \(px+qy\) is also an integer where \(p,q,x,y\) are all integers.

Worked Example

Suppose \(a\) and \(b\) are positive integers. Show that if \(a\mid b\) then \(a\leq b\). Conclude that if \(a\mid b\) and \(b\mid a\) then \(a=b\).

Show solution

Since \(a\mid b\) and \(a,b\) are both positive integers, thus \(b = pa\) for some positive integer \(p\). Thus \(p\geq 1\), so \(pa\geq a \implies b\geq a\) (since \(p,a,b\) are all positive integers). Hence, proved.

If \(a\mid b\) and \(b\mid a\) then \(b=pa\) and \(a=qb\) for some positive integers \(p,q\). Upon substituting, we get \(b=pqb \implies pq=1\). Now since both \(p\) and \(q\) are positive integers such that \(p\geq 1\) and \(q\geq 1\) and \(pq=1\), the only solution satisfying this equation is \(p=q=1\). Hence, \(a=b\).

Definition — Prime number

A prime number is an integer greater than \(1\) which has only itself and \(1\) as factors. The first few prime numbers are \(2,3,5,7,11,13,17,\ldots\).

The most important single fact about positive integers is that they may be represented uniquely as a product of factors which are prime numbers. This result is called the fundamental theorem of arithmetic.

Theorem — Fundamental Theorem of Arithmetic

Let \(a\) be any integer greater than \(1\). Then \(a\) has a prime factorization of the form

\[ a=p_1^{a_1}p_2^{a_2}\ldots p_n^{a_n} \]

where \(p_1,p_2,\ldots,p_n\) are distinct prime numbers, and \(a_1,\ldots,a_n\) are positive integers. Moreover, this prime factorization is unique, up to the order of the factors.

Proof

Either \(n\) is prime or it is composite; in the former case, there is nothing more to prove. If \(n\) is composite, then there exists an integer \(d\) satisfying \(d\mid n\) and \(1\lt d\lt n\). Among all such integers \(d\), choose \(p_1\) to be the smallest (this is possible by the Well-Ordering principle). Then \(p_1\) must be a prime number. Otherwise it too would have a divisor \(q\) with \(1\lt q\lt p_1\); but then \(q\mid p_1\) and \(p_1\mid n\) imply that \(q\mid n\), which contradicts the choice of \(p_1\) as the smallest divisor, not equal to \(1\), of \(n\).

We therefore may write \(n=p_1n_1\) where \(p_1\) is prime and \(1\lt n_1\lt n\). If \(n_1\) happens to be prime, then we have our representation. In the contrary case, the argument is repeated to produce a second prime \(p_2\) such that \(n_1 = p_2n_2\): that is,

\[ n=p_1p_2n_2\quad 1\lt n_2\lt n_1 \]

If \(n_2\) is prime, then it is not necessary to go further. Otherwise, write \(n_2 = p_3n_3\), with \(p_3\) prime:

\[ n=p_1p_2p_3n_3\quad 1\lt n_3\lt n_2 \]

The decreasing sequence

\[ n\gt n_1\gt n_2\gt \ldots \gt 1 \]

cannot continue indefinitely, so that after a finite number of steps \(n_{k-1}\) is a prime, call it \(p_k\). This leads to the prime factorization

\[ n=p_1p_2\ldots p_k \]

To establish the second part of the proof — the uniqueness of the prime factorization — let us suppose that the integer \(n\) can be represented as a product of primes in two ways: say

\[ n=p_1p_2 \ldots p_r = q_1q_2 \ldots q_s\quad r\leq s \]

where the \(p_i\) and \(q_i\) are all primes, written in increasing magnitude so that

\[ p_1 \leq p_2 \leq \ldots \leq p_r\quad q_1 \leq q_2 \leq \ldots \leq q_s \]

Because \(p_1 \mid q_1q_2 \ldots q_s\), this tells us that \(p_1=q_k\) for some \(k\): but then \(p_1\geq q_1\). Similar reasoning gives \(q_1 \geq p_1\), whence \(p_1=q_1\). We may cancel this common factor and obtain

\[ p_2p_3 \ldots p_r = q_2q_3 \ldots q_s \]

Now repeat the process to get \(p_2=q_2\) and, in turn

\[ p_3p_4\ldots p_r=q_3q_4\ldots q_s \]

Continue in this fashion. If the inequality \(r\lt s\) were to hold, we would eventually arrive at

\[ 1=q_{r+1}q_{r+2} \ldots q_s \]

which is absurd, because each \(q_j \gt 1\). Hence, \(r=s\) and

\[ p_1=q_1, \quad p_2 =q_2, \ldots, p_r=q_r \]

making the two factorizations of \(n\) identical. ∎

Worked Example

Find the prime factorization of \(697\) and \(36300\).

Show solution

Prime factorization of \(697=17\times 41\) and \(36300 = 2^2\times 3\times 5^2 \times 11^2\).

Modular Arithmetic and Euclid's Algorithm

We're all thoroughly familiar with the techniques of ordinary arithmetic. Another type of arithmetic, modular arithmetic, is extremely useful in understanding the properties of numbers. We assume that you are familiar with the elementary ideas of modular arithmetic, and so will quickly breeze through the basic ideas and notation, before coming to more advanced theory.

Modular arithmetic can be thought of as the arithmetic of remainders. If we divide \(18\) by \(7\) we get the answer \(2\), with a remainder \(4\). More formally, given any positive integers \(x\) and \(n\), \(x\) can be written (uniquely) in the form

\[ x=kn+r \]

where \(k\) is a non-negative integer, the result of dividing \(x\) by \(n\), and the remainder \(r\) lies in the range \(0\) to \(n-1\), inclusive. Modular arithmetic is simply ordinary arithmetic in which we only pay attention to remainders. We use the notation (mod \(n\)) to indicate that we are working in modular arithmetic. For instance \(2=5=8=11\) (mod \(3\)), because \(2,5,8\) and \(11\) all have the same remainder \(2\) when divided by \(3\). The appellation (mod \(n\)) reminds us that we are working in modular arithmetic, with respect to the number \(n\).

The congruence relation satisfies all the conditions of an equivalence relation:

If \(a_1 \equiv b_1 \pmod{m}\) and \(a_2 \equiv b_2 \pmod{m}\), or if \(a \equiv b \pmod{m}\), then:

If \(a \equiv b \pmod{m}\), then it is generally false that \(k^a \equiv k^b \pmod{m}\). However, the following is true:

For cancellation of common terms, we have the following rules:

The last rule can be used to move modular arithmetic into division. If \(b\) divides \(a\), then

\[ \frac{a}{b} \pmod{m} = \frac{a \pmod{bm}}{b}. \]

The modular multiplicative inverse is defined by the following rules:

The multiplicative inverse \(x \equiv a^{-1} \pmod{m}\) may be efficiently computed by solving Bézout's equation \(a x + m y = 1\) for \(x, y\), by using the Extended Euclidean algorithm.

In particular, if \(p\) is a prime number, then \(a\) is coprime with \(p\) for every \(a\) such that \(0 \lt a \lt p\); thus, a multiplicative inverse exists for all \(a\) that is not congruent to zero modulo \(p\).

In everyday language, "mod \(n\)" arithmetic is clock arithmetic: only the remainder after dividing by \(n\) matters, so \(11\) o'clock plus \(4\) hours is \(3\), not \(15\). A number has a multiplicative "reciprocal" mod \(n\) precisely when it shares no factors with \(n\) — that coprimality condition is what makes division well-behaved, and it is the hinge on which RSA and the order-finding algorithm turn.

Advanced Properties

Some of the more advanced properties of congruence relations are the following:

Fermat's Little Theorem: If \(p\) is prime and does not divide \(a\), then

\[ a^{p-1} \equiv 1 \pmod{p}. \]

Euler's Theorem: If \(a\) and \(m\) are coprime, then

\[ a^{\varphi(m)} \equiv 1 \pmod{m}, \]

where \(\varphi\) is Euler's totient function.

A simple consequence of Fermat's Little Theorem is that if \(p\) is prime, then

\[ a^{-1} \equiv a^{p-2} \pmod{p} \]

is the multiplicative inverse of \(0 \lt a \lt p\). More generally, from Euler's Theorem, if \(a\) and \(m\) are coprime, then

\[ a^{-1} \equiv a^{\varphi(m)-1} \pmod{m}. \]

Hence, if \(ax \equiv 1 \pmod{m}\), then

\[ x \equiv a^{\varphi(m)-1} \pmod{m}. \]

Another simple consequence is that if \(a \equiv b \pmod{\varphi(m)}\), where \(\varphi\) is Euler's totient function, then

\[ ka \equiv kb \pmod{m} \]

provided \(k\) is coprime with \(m\).

Wilson's Theorem: \(p\) is prime if and only if

\[ (p - 1)! \equiv -1 \pmod{p}. \]

Chinese Remainder Theorem: For any integers \(a\), \(b\) and coprime integers \(m\), \(n\), there exists a unique \(x \pmod{mn}\) such that

\[ x \equiv a \pmod{m} \quad \text{and} \quad x \equiv b \pmod{n}. \]

In fact, the solution is given by

\[ x \equiv b \cdot m^{n-1} \pmod{mn} + a \cdot n^{m-1} \pmod{mn}, \]

where \(m^{n-1}\) is the inverse of \(m\) modulo \(n\) and \(n^{m-1}\) is the inverse of \(n\) modulo \(m\).

Lagrange's Theorem: If \(p\) is prime and \(f(x) = a_0 x^d + \dots + a_d\) is a polynomial with integer coefficients such that \(p\) is not a divisor of \(a_0\), then the congruence

\[ f(x) \equiv 0 \pmod{p} \]

has at most \(d\) non-congruent solutions modulo \(p\).

Primitive Root Modulo \(m\): A number \(g\) is a primitive root modulo \(m\) if, for every integer \(a\) coprime to \(m\), there is an integer \(k\) such that

\[ g^k \equiv a \pmod{m}. \]

A primitive root modulo \(m\) exists if and only if \(m\) is equal to \(2\), \(4\), \(p^k\) or \(2p^k\), where \(p\) is an odd prime number and \(k\) is a positive integer. If a primitive root modulo \(m\) exists, then there are exactly \(\varphi(\varphi(m))\) such primitive roots, where \(\varphi\) is Euler's totient function.

Quadratic Residue: An integer \(a\) is a quadratic residue modulo \(m\) if there exists an integer \(x\) such that

\[ x^2 \equiv a \pmod{m}. \]

Euler's criterion asserts that, if \(p\) is an odd prime, and \(a\) is not a multiple of \(p\), then \(a\) is a quadratic residue modulo \(p\) if and only if

\[ a^{\frac{p-1}{2}} \equiv 1 \pmod{p}. \]

Addition, multiplication, and subtraction operations for modular arithmetic may all be defined in the obvious way, but it is perhaps not so obvious how to define a division operation. To understand how this may be done we introduce another key concept from number theory, that of the greatest common divisor of two integers. The greatest common divisor of integers \(a\) and \(b\) is the largest integer which is a divisor of both \(a\) and \(b\). We write this number as \(\gcd(a,b)\). For example, the greatest common divisor of \(18\) and \(12\) is \(6\). An easy way of seeing this is to enumerate the positive divisors of \(18\) (\(1,2,3,6,9,18\)) and \(12\) (\(1,2,3,4,6,12\)), and then pick out the largest common element in the two lists. This method is quite inefficient and impractical for large numbers. Fortunately, there is a much more efficient way of working out the greatest common divisor, a method known as Euclid's algorithm.

Theorem — Representation theorem for the gcd

The greatest common divisor of two integers \(a\) and \(b\) is the least positive integer that can be written in the form \(ax+by\), where \(x\) and \(y\) are integers.

Proof

Let \(s = ax+by\) be the smallest positive integer that can be written in this form. Since \(\gcd(a,b)\) is a divisor of both \(a\) and \(b\) it is also a divisor of \(s\). It follows that \(\gcd(a,b) \leq s\). To complete the proof we demonstrate that \(s \leq \gcd(a,b)\) by showing that \(s\) is a divisor of both \(a\) and \(b\). The proof is by contradiction. Suppose \(s\) is not a divisor of \(a\). Then \(a =ks+r\), where the remainder \(r\) is in the range \(1\) to \(s-1\). Rearranging this equation and using \(s=ax+by\) we see that \(r=a(1-kx)+b(-ky)\) is a positive integer that can be written as a linear combination of \(a\) and \(b\), which is smaller than \(s\). But this contradicts the definition of \(s\) as the smallest positive integer that can be written as a linear combination of \(a\) and \(b\). We conclude that \(s\) must divide \(a\). By symmetry \(s\) must also be a divisor of \(b\), which completes the proof. ∎

Corollary

Suppose \(c\) divides both \(a\) and \(b\). Then \(c\) divides \(\gcd(a,b)\).

Proof

From the previous theorem, \(\gcd(a,b)=ax+by\) for some integers \(x\) and \(y\). Since \(c\) divides \(a\) and \(b\) it must also divide \(ax+by\). ∎

When does a number \(a\) have a multiplicative inverse in modular arithmetic? That is, given \(a\) and \(n\), when does there exist a \(b\) such that \(ab=1\) (mod \(n\))? For example, note that \(2 \times 3 = 1\) (mod \(5\)), so the number \(2\) has multiplicative inverse \(3\) in arithmetic modulo \(5\). On the other hand, trial and error shows that \(2\) has no multiplicative inverse modulo \(4\). Finding a multiplicative inverse in modular arithmetic turns out to be related to the gcd by the notion of co-primality: integers \(a\) and \(b\) are said to be co-prime if their greatest common divisor is \(1\). For example, \(14\) and \(9\) are co-prime, since the positive divisors of \(14\) are \(1,2,7\) and \(14\), while \(1,3\) and \(9\) are the positive divisors of \(9\). The following corollary characterizes the existence of multiplicative inverses in modular arithmetic using co-primality.

Corollary

Let \(n\) be an integer greater than \(1\). An integer \(a\) has a multiplicative inverse modulo \(n\) if and only if \(\gcd(a,n) =1\), that is, \(a\) and \(n\) are co-prime.

Proof

Suppose \(a\) has a multiplicative inverse, which we denote \(a^{-1}\), modulo \(n\). Then \(aa^{-1}=1+kn\) for some integer \(k\), and thus \(aa^{-1}+(-k)n=1\). From the previous theorem we conclude that \(\gcd(a,n)=1\). Conversely, if \(\gcd(a,n)=1\) then there must exist integers \(a^{-1}\) and \(b\) such that \(aa^{-1} + bn=1\), and therefore \(aa^{-1}\equiv 1\) (mod \(n\)). ∎

Worked Example

For \(p\) a prime prove that all the integers in the range \(1\) to \(p-1\) have a multiplicative inverse modulo \(p\). Which integers in the range \(1\) to \(p^2-1\) do not have multiplicative inverses modulo \(p^2\)?

Show solution

From the previous result we see that an integer \(a\) has a multiplicative inverse modulo \(n\) if and only if \(\gcd(a,n)=1\). For a prime \(p\) its factors are \(1\) and itself. Thus, \(\gcd(a,p)=1\) for all \(a\) in the range \(1\) to \(p-1\) since \(p\nmid a\) as \(a\lt p\). Hence \(\forall a\) in the range \(1\) to \(p-1\) for a prime \(p\) have a multiplicative inverse modulo \(p\).

The integers which have \(\gcd(a,p^2)=1\) for \(a\) in the range \(1\) to \(p^2-1\) will have multiplicative inverses modulo \(p^2\). \(p^2\) has its prime factorization as \(p^2 = 1 \times p\times p\). Clearly, for \(a=p,2p,3p,\ldots, p(p-1)\), \(\gcd(a,p^2) =p\). Thus, except for \(a=rp\) for \(r\) in the range \(1\) to \(p-1\), all the others will have \(\gcd(a,p^2)=1\). Thus, \(\forall a\) with \(a \neq rp;\ 1\leq r \lt p\), \(\gcd(a,p^2)=1\) and hence will have a multiplicative inverse modulo \(p^2\).

Worked Example

Find the multiplicative inverse of \(17\) modulo \(24\).

Show solution

Clearly, \(\gcd(17,24)=1\), hence a multiplicative inverse exists. The multiplicative inverse is \(17\) itself, because \(17\times 17 = 289 = 24\times 12 + 1\). Thus, the multiplicative inverse of \(17\) is \(17\).

This can also be found using Euclid's algorithm as follows:

\[\begin{aligned} 24 &=17 \times 1 +7\\ 17 &= 7 \times 2 + 3\\ 7 &= 3\times 2 + 1\\ 3 &= 3 \times 1\\ 7 - 3 \times 2 &=1\\ - 17 \times 2 + 7 \times 5 &=1\\ 24 \times 5 +17 \times (-7)&=1 \end{aligned}\]

Thus, \(17 \times (-7) = 1\) (mod \(24\)), hence \(-7\) is a multiplicative inverse of \(17 \implies -7 + 24 = 17\). Thus, \(-7 \equiv 17\) (mod \(24\)).

Worked Example

Find the multiplicative inverse of \(n+1\) modulo \(n^2\), where \(n\) is any integer greater than \(1\).

Show solution

Since \((n+1)(n-1)\equiv(-1)\) (mod \(n^2\)) and since \((-1)^2\equiv1\) (mod \(n^2\)), you have that

\[ [(n+1)(n-1)]^2 \equiv 1 \ (\text{mod } n^2) \]

Therefore, the inverse of \((n+1)\) is \([(n+1)(n-1)^2]\).

Worked Example

(Uniqueness of the inverse) Suppose \(b\) and \(b'\) are multiplicative inverses of \(a\), modulo \(n\). Prove that \(b=b'\) (mod \(n\)).

Show solution

Since \(b\) and \(b'\) are both multiplicative inverses of \(a\), thus \(ab\equiv ab' \equiv 1\) (mod \(n\)), and so \(\gcd(a,n)=1\).

\[\begin{aligned} ab&=1 \ (\text{mod }n)\\ ab' &=1 \ (\text{mod }n)\\ \implies a(b-b')&=0 \ (\text{mod }n) \end{aligned}\]

Now, since \(n \nmid a\), thus \(n\mid(b-b')\). Hence, \(b\equiv b'\) (mod \(n\)). This is because congruent values are considered as the same in modular arithmetic. For example, \(3\times 2=6 =1\) (mod \(5\)) and \(3\times 7=21=1\) (mod \(5\)). Thus, what we mean by unique is that \(2=7\) (mod \(5\)); they belong to the same class, i.e. the same congruence. Thus congruent values are considered as the same in modular arithmetic.

The next theorem is the key to Euclid's efficient algorithm for finding the greatest common divisor of two positive integers.

Theorem

Let \(a\) and \(b\) be integers, and let \(r\) be the remainder when \(a\) is divided by \(b\). Then provided \(r\neq 0\),

\[ \gcd(a,b)=\gcd(b,r) \]
Proof

We prove the equality by showing that each side divides the other. To prove that the left hand side divides the right, note that \(r=a-kb\) for some integer \(k\). Since \(\gcd(a,b)\) divides \(a,b\) and linear combinations of these it follows that \(\gcd(a,b)\) divides \(r\), using the fact that if some integer \(c\mid a\) and \(c\mid b\) then \(c\mid\gcd(a,b)\). Thus, \(\gcd(a,b)\) divides \(\gcd(b,r)\). To prove that the right hand side divides the left, note that \(\gcd(b,r)\) divides \(b\) and \(r\), and since \(a=r+kb\) is a linear combination of \(b\) and \(r\) it follows that \(\gcd(b,r)\) also divides \(a\). Thus, \(\gcd(b,r)\) divides \(\gcd(a,b)\). ∎

Worked Example

Explain how to find \(\gcd(a,b)\) if the prime factorizations of \(a\) and \(b\) are known. Find the prime factorizations of \(6825\) and \(1430\), and use them to compute \(\gcd(6825,1430)\).

Show solution

Suppose the prime factorization of \(a = a_1^{\alpha_1}a_2^{\alpha_2} \ldots a_p^{\alpha_p}\) and \(b=b_1^{\beta_1}b_2^{\beta_2} \ldots b_q^{\beta_q}\). Clearly, all the \(a_i^{\alpha_i}\) for \(i=1,\ldots,p\) divide \(a\) and all the \(b_i^{\beta_i}\) for \(i=1,\ldots,q\) divide \(b\). We should choose \(a_i\) and \(b_i\) such that \(a_i=b_i\) along with their highest powers possible so that they divide both \(a\) and \(b\). Thus, we can get the \(\gcd(a,b)\) by this method.

Note that we can write \(6825 = 3\times 5\times 5 \times 7 \times 13\) and \(1430 = 2 \times 5 \times 11 \times 13\). Thus, taking the common prime factors along with their possible highest powers we get their gcd as \(5 \times 13 = 65\). Thus, \(\gcd(1430,6825)=65\).

Euclid's algorithm for finding the greatest common divisor of positive integers \(a\) and \(b\) works as follows. First, order \(a\) and \(b\) so that \(a\gt b\). Divide \(b\) into \(a\), with result \(k_1\) and remainder \(r_1\): \(a=k_1b+r_1\). Now using the theorem \(\gcd(a,b)=\gcd(b,r_1)\). Next, we perform a second division with \(b\) playing the role of \(a\), and \(r_1\) playing the role of \(b\): \(b=k_2r_1+r_2\). By the theorem, \(\gcd(a,b)=\gcd(b,r_1)=\gcd(r_1,r_2)\). Next, we perform a third division with \(r_1\) playing the role of \(b\): \(r_1 = k_3r_2+r_3\). By the theorem, \(\gcd(a,b)=\gcd(b,r_1)=\gcd(r_1,r_2)=\gcd(r_2,r_3)\). We continue in this manner, each time dividing the most recent remainder by the second most recent remainder, obtaining a new result and remainder. The algorithm halts when we obtain a remainder that is zero, that is, \(r_m=k_{m+1}r_{m+1}\) for some \(m\). We have \(\gcd(a,b)=\gcd(r_m,r_{m+1})=r_{m+1}\), so the algorithm returns \(r_{m+1}\).

As an example of the use of Euclid's algorithm we find \(\gcd(6825,1430)\):

\[\begin{aligned} 6825&=4\times 1430 + 1105\\ 1430 &=1\times 1105 + 325\\ 1105 &=3 \times 325 + 130\\ 325 &=2 \times 130 + 65\\ 130 &= 2 \times 65 \end{aligned}\]

From this we see that \(\gcd(6825,1430)=65\).

An adaptation of Euclid's algorithm may be used to efficiently find the integers \(x\) and \(y\) such that \(ax+by=\gcd(a,b)\). The first stage is to run through the steps of Euclid's algorithm, as before. The second stage begins at the second last line of the running of Euclid's algorithm, and involves successive substitution of the lines higher up in the algorithm as illustrated by the following example:

\[\begin{aligned} 65 &=325-2\times 130\\ &=325 - 2 \times (1105 - 3 \times 325) =-2\times 1105 + 7 \times 325\\ &= -2 \times 1105 + 7 \times (1430 - 1 \times 1105) =7\times 1430 - 9 \times 1105\\ &= 7 \times 1430 - 9 \times (6825 - 4 \times 1430) = -9 \times 6825 + 37 \times 1430 \end{aligned}\]

That is, \(65 = 6825 \times (-9) + 1430 \times 37\), which is the desired representation.

Euclid's algorithm is just repeated division: keep replacing the pair by "smaller number, remainder" until the remainder hits zero, and the last non-zero number is the gcd. Running it backwards (the extended version) also spits out the integers \(x,y\) with \(ax+by=\gcd(a,b)\) — which is exactly how you compute modular inverses in practice.

What resources are consumed by Euclid's algorithm? Suppose \(a\) and \(b\) may be represented as bit strings of at most \(L\) bits each. It is clear that none of the divisors \(k_i\) or remainders \(r_i\) can be more than \(L\) bits long, so we may assume that all computations are done in \(L\)-bit arithmetic. The key observation to make in a resource analysis is that \(r_{i+2} \leq r_i/2\). To prove this we consider two cases:

Since \(r_{i+2} \leq r_i/2\), it follows that the divide-and-remainder operation at the heart of Euclid's algorithm need be performed at most \(2\lceil \log_2 a\rceil = \mathcal{O}(L)\) times. Each divide-and-remainder operation requires \(\mathcal{O}(L^2)\) operations, so that the total cost of Euclid's algorithm is \(\mathcal{O}(L^3)\). Finding \(x\) and \(y\) such that \(ax+by = \gcd(a,b)\) incurs a minor additional cost: \(\mathcal{O}(L)\) substitutions are performed, at a cost of \(\mathcal{O}(L^2)\) per substitution to do the arithmetic involved, for a total resource cost of \(\mathcal{O}(L^3)\).

Euclid's algorithm may also be used to efficiently find multiplicative inverses in modular arithmetic. This is implicit in the proof of the corollary; we make it explicit. Suppose \(a\) is co-prime to \(n\), and we wish to find \(a^{-1}\), modulo \(n\). To do so, use Euclid's algorithm and the co-primality of \(a\) and \(n\) to find integers \(x\) and \(y\) such that

\[ ax+ny=1 \]

Note then that \(ax = (1-ny) = 1\) (mod \(n\)), that is, \(x\) is the multiplicative inverse of \(a\), modulo \(n\). Furthermore, this algorithm is computationally efficient, taking only \(\mathcal{O}(L^3)\) steps, where \(L\) is the length in bits of \(n\).

Now that we know how to efficiently find inverses in modular arithmetic, it is only a short step to solving simple linear equations, such as

\[ ax+b = c \ (\text{mod } n) \]

Suppose \(a\) and \(n\) are co-prime. Then using Euclid's algorithm we may efficiently find the multiplicative inverse \(a^{-1}\) of \(a\), modulo \(n\), and thus the solution to the previous equation,

\[ x=a^{-1}(c-b) \ (\text{mod } n) \]

An important result known as the Chinese remainder theorem extends the range of equations we can solve much further, allowing us to efficiently solve systems of equations in modular arithmetic.

Theorem — Chinese remainder theorem

Suppose \(m_1,\ldots,m_n\) are positive integers such that any pair \(m_i\) and \(m_j\) (\(i\neq j\)) are co-prime. Then the system of equations

\[\begin{aligned} x &= a_1 \ (\text{mod }m_1)\\ x &= a_2 \ (\text{mod }m_2)\\ &\ \vdots\\ x &= a_n \ (\text{mod } m_n) \end{aligned}\]

has a solution. Moreover, any two solutions to this system of equations are equal modulo \(M=m_1m_2\ldots m_n\).

Proof

The proof is to explicitly construct a solution to the system of equations. Define \(M_i \equiv M/m_i\), and observe that \(m_i\) and \(M_i\) are co-prime. It follows that \(M_i\) has an inverse modulo \(m_i\), which we denote \(N_i\). Define \(x \equiv \sum_i a_iM_iN_i\). To see that \(x\) is a solution to the system of equations, note that \(M_iN_i=1\) (mod \(m_i\)) and \(M_iN_i=0\) (mod \(m_j\)) when \(i\neq j\), so \(x=a_i\) (mod \(m_i\)), which demonstrates the existence of a solution.

Suppose \(x\) and \(x'\) are both solutions to the system of equations. It follows that \(x-x'=0\) (mod \(m_i\)) for each \(i\), and thus \(m_i\) divides \(x-x'\) for each \(i\). Since the \(m_i\) are co-prime, it follows that the product \(M=m_1\ldots m_n\) also divides \(x-x'\), so \(x=x'\) (mod \(M\)) as we set out to show. ∎

Worked Example

Consider the following system of linear equations

\[\begin{aligned} x &\equiv 2 \ (\text{mod }3)\\ x &\equiv 3 \ (\text{mod }5)\\ x&\equiv 2 \ (\text{mod }7) \end{aligned}\]
Show solution

Here \(M=3\times 5\times 7 = 105\), where \(m_1=3, m_2=5,m_3=7\). Thus,

\[ M_1 = \frac{M}{m_1}=\frac{105}{3} = 35\quad M_2 = \frac{M}{m_2}=\frac{105}{5} =21 \quad M_3 = \frac{M}{m_3} = \frac{105}{7} = 15 \]

Now finding the inverses of the following linear congruences we get,

\[ 35N_1 = 1 \ (\text{mod }3)\quad 21N_2=1 \ (\text{mod }5)\quad 15N_3 =1 \ (\text{mod }7) \]

The solutions to the above equations are \(N_1=2,N_2=1,N_3=1\). Thus, the solution is given by \(x=\sum_ia_iM_iN_i\):

\[ x=2\times 35 \times 2 + 3\times 21 \times 1 + 2 \times 15 \times 1 = 233 \]

Thus, \(x=233\) (mod \(105\)) \(\implies x=23\) (mod \(105\)).

Euclid's algorithm and the Chinese remainder theorem are two of the signal triumphs of algorithmic number theory. How ironic that they should play a role in the sequence of ideas leading up to the RSA cryptosystem, whose presumed security is based on the difficulty of performing certain algorithmic tasks in number theory. Nevertheless, this is indeed the case! We turn now to the number-theoretic background necessary to understand the RSA cryptosystem. The key ideas are a famous result of classical number theory, Fermat's little theorem — not to be confused with Fermat's last theorem — and a generalization of Fermat's little theorem due to Euler. The proof of Fermat's little theorem relies on the following elegant lemma.

Lemma

Suppose \(p\) is prime and \(k\) is an integer in the range \(1\) to \(p-1\). Then \(p\) divides \(\binom{p}{k}\).

Proof

Consider the identity

\[ p(p-1)\ldots (p-k+1) = \binom{p}{k} k! \]

Since \(k \geq 1\) the left hand side (and thus the right) is divisible by \(p\). Since \(k\leq p-1\) the term \(k!\) is not divisible by \(p\). It follows that \(\binom{p}{k}\) must be divisible by \(p\). ∎

Theorem — Fermat's little theorem

Suppose \(p\) is a prime, and \(a\) is any integer. Then \(a^p = a\) (mod \(p\)). If \(a\) is not divisible by \(p\) then \(a^{p-1} = 1\) (mod \(p\)).

Proof

The second part of the theorem follows from the first, since if \(a\) is not divisible by \(p\) then \(a\) has an inverse modulo \(p\), so \(a^{p-1}=a^{-1}a^p = a^{-1}a =1\) (mod \(p\)). We prove the first part of the theorem for positive \(a\) (the case of non-positive \(a\) follows easily) by induction on \(a\). When \(a=1\) we have \(a^p=1=a\) (mod \(p\)), as required. Suppose the result holds true for \(a\), that is, \(a^p=a\) (mod \(p\)), and consider the case of \(a+1\). By the binomial expansion,

\[ (1+a)^p = \sum_{k=0}^p \binom{p}{k} a^k \]

By the previous lemma, \(p\) divides \(\binom{p}{k}\) whenever \(1\leq k \leq p-1\), so all the terms except the first and last vanish from the sum modulo \(p\): \((1+a)^p = (1+a^p)\) (mod \(p\)). Applying the inductive hypothesis \(a^p =a\) (mod \(p\)) we see that \((1+a)^p = (1+a)\) (mod \(p\)), as required. ∎

There is a remarkable generalization of Fermat's little theorem due to Euler, based on the Euler \(\varphi\) function. \(\varphi(n)\) is defined to be the number of positive integers less than \(n\) which are co-prime to \(n\). As an example, note that all positive integers less than a prime \(p\) are co-prime to \(p\), and thus \(\varphi(p)=p-1\). The only integers less than \(p^{\alpha}\) which are not co-prime to \(p^{\alpha}\) are the multiples of \(p\): \(p,2p,3p,\ldots (p^{\alpha -1}-1)p\), from which we deduce

\[ \varphi(p^{\alpha}) =(p^{\alpha}-1) - (p^{\alpha -1}-1)=p^{\alpha-1} (p-1) \]

Furthermore, if \(a\) and \(b\) are co-prime, then the Chinese remainder theorem can be used to show that

\[ \varphi(ab)=\varphi(a)\varphi(b) \]

To see this, consider the system of equations \(x=x_a\) (mod \(a\)), \(x=x_b\) (mod \(b\)). Applying the Chinese remainder theorem to this set of equations we see that there is a one-to-one correspondence between pairs \((x_a,x_b)\) such that \(1 \leq x_a \lt a\), \(1\leq x_b \lt b\), \(\gcd(x_a,a)=1\), \(\gcd(x_b,b)=1\), and integers \(x\) such that \(1\leq x \lt ab\), \(\gcd(x,ab)=1\). There are \(\varphi(a)\varphi(b)\) such pairs \((x_a,x_b)\) and \(\varphi(ab)\) such \(x\).

Thus, together they imply a formula for \(\varphi(n)\) based on the prime factorization of \(n\), \(n=p_1^{\alpha_1}\ldots p_k^{\alpha_k}\):

\[ \varphi(n)=\prod_{j=1}^k p_j^{\alpha_j-1}(p_j-1) \]
Worked Example

What is \(\varphi(187)\)?

Show solution

Note that the prime factorization of \(187 = 11 \times 17\), so

\[ \varphi(187)=\varphi(11)\varphi(17) \]

We know that \(\varphi(p)=p-1\) where \(p\) is prime. Thus, \(\varphi(11)=10\) and \(\varphi(17)=16\). Thus, \(\varphi(187) =10 \times 16 = 160\).

Practice Problem

Prove that

\[ n = \sum_{d\mid n} \varphi(d) \]

where the sum is over all positive divisors \(d\) of \(n\), including \(1\) and \(n\).

Fermat's little theorem has the following beautiful generalization, due to Euler:

Theorem — Euler's theorem

Suppose \(a\) is co-prime to \(n\). Then \(a^{\varphi(n)}=1\) (mod \(n\)).

Proof

We first show by induction on \(\alpha\) that \(a^{\varphi(p^{\alpha})} = 1\) (mod \(p^{\alpha}\)). For \(\alpha=1\) the result is just Fermat's little theorem. Assume the result is true for \(\alpha \geq 1\), so

\[ a^{\varphi(p^{\alpha})} = 1 +kp^{\alpha} \]

for some integer \(k\). Then, using \(\varphi(p^{\alpha}) = p^{\alpha-1}(p-1)\),

\[\begin{aligned} a^{\varphi(p^{\alpha+1})} &= a^{p^{\alpha}(p-1)}\\ &=a^{p\varphi(p^{\alpha})}\\ &=(1+kp^{\alpha})^p\\ &=1+\sum_{j=1}^p \binom{p}{j} k^j p^{j\alpha} \end{aligned}\]

Using the fact that \(p\) divides \(\binom{p}{j}\) where \(1\leq j \leq p-1\), it is easy to see that \(p^{\alpha+1}\) divides every term in the sum, so

\[ a^{\varphi(p^{\alpha+1})} =1 \ (\text{mod }p^{\alpha+1}) \]

which completes the induction. The proof of the theorem is completed by noting that for arbitrary \(n = p_1^{\alpha_1}\ldots p_m^{\alpha_m}\), \(\varphi(n)\) is a multiple of \(\varphi(p_j^{\alpha_j})\). Applying the construction in the proof of the Chinese remainder theorem we find that any solution to the set of equations \(x = 1\) (mod \(p_j^{\alpha_j}\)) must satisfy \(x=1\) (mod \(n\)), and thus \(a^{\varphi(n)}=1\) (mod \(n\)). ∎

Define \(Z_n^*\) to be the set of all elements in \(Z_n\) which have inverses modulo \(n\), that is, the set of all elements in \(Z_n\) that are co-prime to \(n\). \(Z_n^*\) is easily seen to form a group of size \(\varphi(n)\) under multiplication, that is, it contains a multiplicative identity, products of elements in \(Z_n^*\) are in \(Z_n^*\), and \(Z_n^*\) is closed under the multiplicative inverse operation. For an overview of elementary group theory see the previous section. What is not so obvious is the remarkable structure \(Z_n^*\) has when \(n\) is a power of an odd prime \(p\), \(n=p^{\alpha}\). It turns out that \(Z_{p^{\alpha}}^*\) is a cyclic group, that is, there is an element \(g\) in \(Z_{p^{\alpha}}^*\) which generates \(Z_{p^{\alpha}}^*\) in the sense that any other element \(x\) may be written \(x=g^k\) (mod \(n\)) for some non-negative integer \(k\).

Theorem

Let \(p\) be an odd prime, \(\alpha\) a positive integer. Then \(Z_{p^{\alpha}}^*\) is cyclic.

All these classical results — Fermat, Euler, the totient \(\varphi\), and the fact that \(Z_{p^\alpha}^*\) is cyclic — are the gears that Shor's algorithm turns. The exponent that resets a number back to \(1\) under multiplication mod \(N\) is its "order", and \(\varphi(N)\) and Euler's theorem control what those orders can be. Finding that order fast is exactly what a quantum computer does, which is why this dry-looking number theory is the doorway to breaking RSA.

17.8 Reduction of factoring to order-finding

The problem of factoring numbers on a classical computer turns out to be equivalent to another problem, the order-finding problem. This equivalence is important as it turns out that quantum computers are able to quickly solve the order-finding problem, and thus can factor quickly. In this section we explain the equivalence between these two problems, focusing on the reduction of factoring to order-finding.

Suppose \(N\) is a positive integer, and \(x\) is co-prime to \(N\), \(1\leq x \lt N\). The order of \(x\) modulo \(N\) is defined to be the least positive integer \(r\) such that \(x^r =1\) (mod \(N\)). The order-finding problem is to determine \(r\) given \(x\) and \(N\).

Worked Example

Show that the order of \(x\) modulo \(N\) must divide \(\varphi(N)\).

Show solution

We know from Euler's generalization of Fermat's little theorem that \(a^{\varphi(N)} = 1\) (mod \(N\)) where \(a\) is co-prime to \(N\). Since the order \(r\) is the least positive integer with \(x^r=1\) (mod \(N\)), and \(x^{\varphi(N)}=1\) (mod \(N\)), writing \(\varphi(N)=qr+s\) with \(0\leq s\lt r\) gives \(x^s=1\) (mod \(N\)); by minimality of \(r\) this forces \(s=0\), so \(r\) divides \(\varphi(N)\).

The reduction of factoring to order-finding proceeds in two basic steps. The first step is to show that we can compute a factor of \(N\) if we can find a non-trivial solution \(x\neq \pm 1\) (mod \(N\)) to the equation \(x^2 = 1\) (mod \(N\)). The second step is to show that a randomly chosen \(y\) co-prime to \(N\) is quite likely to have an order \(r\) which is even, and such that \(y^{r/2} \neq \pm1\) (mod \(N\)), and thus \(x=y^{r/2}\) (mod \(N\)) is a solution to \(x^2=1\) (mod \(N\)).

Theorem

Suppose \(N\) is a composite number \(L\) bits long, and \(x\) is a non-trivial solution to the equation \(x^2=1\) (mod \(N\)) in the range \(1\leq x \leq N\), that is, neither \(x =1\) (mod \(N\)) nor \(x=N-1=-1\) (mod \(N\)). Then at least one of \(\gcd(x-1,N)\) and \(\gcd(x+1,N)\) is a non-trivial factor of \(N\) that can be computed using \(\mathcal{O}(L^3)\) operations.

Proof

Since \(x^2=1\) (mod \(N\)), it must be that \(N\) divides \(x^2-1=(x+1)(x-1)\), and thus \(N\) must have a common factor with one or the other of \((x+1)\) and \((x-1)\). But \(1\lt x\lt N-1\) by assumption, so \(x-1\lt x+1\lt N\), from which we see that the common factor cannot be \(N\) itself. Using Euclid's algorithm we may compute \(\gcd(x-1,N)\) and \(\gcd(x+1,N)\) and thus obtain a non-trivial factor of \(N\), using \(\mathcal{O}(L^3)\) operations. ∎

The trick behind factoring via order-finding: if you can find a number \(x\) that squares to \(1\) mod \(N\) but is not \(\pm 1\), then \((x-1)(x+1)\) is a multiple of \(N\) with the factors of \(N\) split between the two pieces. Taking gcd's peels off a real factor. Order-finding is what hands you such an \(x\), and that is the one step a quantum computer does exponentially faster than any known classical method.
Lemma

Let \(p\) be an odd prime. Let \(2^d\) be the largest power of \(2\) dividing \(\varphi(p^{\alpha})\). Then with probability exactly one-half \(2^d\) divides the order modulo \(p^{\alpha}\) of a randomly chosen element of \(\mathbf{Z}_{p^{\alpha}}^*\).

Proof

Note that \(\varphi(p^\alpha)=p^{\alpha-1}(p-1)\) is even, since \(p\) is odd, and thus \(d \geq 1\). By the theorem that for an odd prime \(p\) and positive integer \(\alpha\), \(\mathbf{Z}_{p^{\alpha}}^*\) is cyclic, there exists a generator \(g\) for \(\mathbf{Z}_{p^{\alpha}}^*\), so an arbitrary element may be written in the form \(g^k\) (mod \(p^{\alpha}\)) for some \(k\) in the range \(1\) through \(\varphi(p^{\alpha})\). Let \(r\) be the order of \(g^k\) modulo \(p^{\alpha}\) and consider two cases. The first case is when \(k\) is odd. From \(g^{kr}=1\) (mod \(p^{\alpha}\)) we deduce that \(\varphi(p^{\alpha})\mid kr\), and thus \(2^d\mid r\), since \(k\) is odd. The second case is when \(k\) is even. Then

\[ g^{k\varphi(p^{\alpha})/2}=(g^{\varphi(p^{\alpha})})^{k/2}=1^{k/2}=1 \ (\text{mod }p^{\alpha}) \]

Thus \(r\mid\varphi(p^{\alpha})/2\) from which we deduce that \(2^d\) does not divide \(r\).

Summarizing, \(\mathbf{Z}_{p^{\alpha}}^*\) may be partitioned into two sets of equal size: those which may be written \(g^k\) with \(k\) odd, for which \(2^d\mid r\), where \(r\) is the order of \(g^k\), and those which may be written \(g^k\) with \(k\) even, for which \(2^d \nmid r\). Thus, with probability \(1/2\) the integer \(2^d\) divides the order \(r\) of a randomly chosen element of \(\mathbf{Z}_{p^{\alpha}}^*\), and with probability \(1/2\) it does not. ∎

17.9 Continued fractions

There are many remarkable connections between the continuum of real numbers and the integers. One such connection is the beautiful theory of continued fractions. In this section we develop a few elements of the theory of continued fractions, elements crucial to the application of the fast quantum algorithms for order-finding and factoring.

As an example of a continued fraction, consider the number \(s\) defined by the expression

\[ s=\frac{1}{2+\frac{1}{2+\frac{1}{2+\ldots}}} \]

Informally, note that \(s=\frac{1}{2+s}\), from which it is easy to satisfy oneself that \(s=\sqrt{2}-1\). The idea of the continued fractions method is to describe real numbers in terms of integers alone, using expressions such as the above. A finite simple continued fraction is defined by a collection \(a_0,\ldots,a_N\) of positive integers,

\[ [a_0,\ldots,a_N] = a_0 + \frac{1}{a_1+\frac{1}{a_2+\frac{1}{\ldots+\frac{1}{a_N}}}} \]

We define the \(n\)th convergent (\(0\leq n\leq N\)) to this continued fraction to be \([a_0,\ldots,a_n]\).

Theorem

Suppose \(x\) is a rational number greater than or equal to one. Then \(x\) has a representation as a continued fraction, \(x=[a_0,\ldots,a_N]\), which may be found by the continued fractions algorithm.

Proof

The continued fractions algorithm is best understood by example. Suppose we are trying to decompose \(31/13\) as a continued fraction. The first step of the continued fraction is to split \(31/13\) into its integer and fractional part,

\[ \frac{31}{13}=2+\frac{5}{13} \]

Next we invert the fractional part, obtaining

\[ \frac{31}{13}=2+\frac{1}{\frac{13}{5}} \]

These steps — split then invert — are now applied to \(13/5\), giving

\[ \frac{31}{13}=2+\frac{1}{2+\frac{3}{5}}=2+\frac{1}{2+\frac{1}{\frac{5}{3}}} \]

Next we split and invert \(5/3\):

\[ \frac{31}{13}=2+\frac{1}{2+\frac{1}{1+\frac{1}{1+\frac{1}{2}}}} \]

The decomposition into a continued fraction now terminates, since \(3/2=1+1/2\) may be written with a \(1\) in the numerator without any need to invert, giving a final continued fraction representation of \(31/13\) as

\[ \frac{31}{13}=2+\frac{1}{2+\frac{1}{1+\frac{1}{1+\frac{1}{2}}}} \]

It's clear that the continued fractions algorithm terminates after a finite number of split-and-invert steps for any rational number, since the numerators which appear (\(31,23,2,1\)) in the example are strictly decreasing. How quickly does the termination occur? We'll come back to that question shortly. ∎

The theorem above has been stated for \(x\geq1\); however, in practice it is convenient to relax the requirement that \(a_0\) be positive and allow it to be any integer, which results in the restriction \(x\geq1\) becoming superfluous. In particular, if \(x\) is in the range \(0\) through \(1\), as occurs in applications to quantum algorithms, then the continued fraction expansion has \(a_0=0\).

The continued fractions algorithm provides an unambiguous method for obtaining a continued fraction expansion of a given rational number. The only possible ambiguity comes at the final stage, because it is possible to split an integer in two ways, either \(a_n=a_n\) or \(a_n=(a_n-1)+1/1\), giving two alternate continued fraction expansions. This ambiguity is actually useful, since it allows us to assume without loss of generality that the continued fraction expansion of a given rational number has either an odd or even number of convergents, as desired.

Worked Example

Find the continued fraction expansion for \(x=19/17\) and \(x=77/65\).

Show solution
\[ \frac{19}{17}=1+\frac{1}{8+\frac{1}{2}} \]

and

\[ \frac{77}{65}=1+\frac{1}{5+\frac{1}{2+\frac{1}{2+\frac{1}{2}}}} \]
Theorem

Let \(a_0,\ldots,a_N\) be a sequence of positive numbers. Then

\[ [a_0,\ldots,a_n]=\frac{p_n}{q_n} \]

where \(p_n\) and \(q_n\) are real numbers defined inductively by \(p_0=a_0,q_0=1\) and \(p_1=1+a_0a_1,q_1=a_1\), and for \(2\leq n\leq N\),

\[\begin{aligned} p_n&=a_np_{n-1}+p_{n-2}\\ q_n&=a_nq_{n-1}+q_{n-2} \end{aligned}\]

In the case where the \(a_j\) are positive integers, so too are the \(p_j\) and \(q_j\).

Proof

We induct on \(n\). The result is easily checked directly for the cases \(n=0,n=1,2\). By definition, for \(n\geq3\),

\[ [a_0,\ldots,a_n]=[a_0,\ldots,a_{n-2},a_{n-1}+1/a_n] \]

Applying the inductive hypothesis, let \(\tilde{p}_j/\tilde{q}_j\) be the sequence of convergents associated with the continued fraction on the right hand side:

\[ [a_0,\ldots,a_{n-2},a_{n-1}+1/a_n]=\frac{\tilde{p}_{n-1}}{\tilde{q}_{n-1}} \]

It is clear that \(\tilde{p}_{n-3}=p_{n-3}\), \(\tilde{p}_{n-2}=p_{n-2}\) and \(\tilde{q}_{n-2}=q_{n-2}\), so the recurrence for the convergents carries over, completing the induction. ∎

Continued fractions turn a messy decimal into a staircase of whole numbers, and truncating that staircase early (the "convergents") gives the best possible rational approximations for a given size of denominator. In Shor's algorithm the quantum computer produces a number very close to a fraction \(s/r\); running the continued-fractions algorithm on it recovers the hidden denominator \(r\) — the order — exactly.

Key Takeaways