Quantum Computing Notes, for a Python Programmer: Complex Numbers

Shubhadeep Roychowdhury
Towards Data Science
7 min readNov 11, 2018

--

Image from — https://phys.org/news/2017-11-simple-beautiful-quantum.html

But if quantum mechanics isn’t physics in the usual sense — if it’s
not about matter, or energy, or waves, or particles — then what is it about?

From my perspective, it’s about information and probabilities
and observables, and how they relate to each other.

Quantum Computing since Democritus by Scott Aaronson (page — 110)

These series of notes, originally I am writing for myself, are what I hope to become a small series on the fundamental aspects of Quantum Mechanics and more precisely on Quantum Computing. I am not gonna try to produce any kind of pop-sci, hand wavy explanation to anything I do not understand fully. When something like that comes up I will be honest and write down the fact that I did not understand that (may happen lots of times). But other than that, this particular set of notes will serve a very specific purpose. They are written from a developer’s perspective. Which means, even if they are rigorous in nature one main focus of them was placed on the implementation part, and to be precise using Python.

Why am I writing these notes?

I have already given one side of the argument above, but I would just like to state here that I belong to a class of people who are stupid and who do not understand anything unless they try to explain it to someone else, and also try to do it by hand. The reason I am writing these notes is also to try to explain the enigmatic yet riveting subject of Quantum Mechanics and Quantum Computing to myself.

They are, as the title suggests, purely notes. Which means, they may have scribbles, mistakes, half baked ideas and solutions thrown in. Nonetheless, these notes do have one useful feature. I can look back at them and correct my mistakes (and update them as I correct) and also (hopefully) someone like me can follow along and be benefited from them.

I, on the other hand, am not going to give any other reason for anyone to follow these notes. I am not gonna tell you that “Quantum Computing is going to change everything. You need to master it, it is the next ‘Data Science’ ” (We do not have proof, apart from a class of problems, QC actually provides any benefits over classical computation) or “RSA is in danger, let’s save it” or anything of that sort. Quantum Mechanics and Quantum Computing are, in their own right, very interesting and fascinating subjects to learn. I am having a great time learning them. I just want to share the joy as much as possible. That is all.

I have assumed a basic familiarity with high school level math like basic algebra, fundamental set theory, Trigonometry. Any other mathematical formalism will be derived on the way.

OK, are you convinced yet? Let’s jump in then!

Our Journey starts… At Complex Numbers

We remember complex numbers, right? Those funny looking numbers with i symbols everywhere at a certain stage of high school math? Well what are they? And more importantly why do we (in fact every quantum mechanics and quantum computing literature on the earth) need them? Let’s go back to the basics a bit. We start with the following equation.

In computer science we call these equations, “Polynomials”. Now, it may not be obvious, but if we think a bit we will see that we can uniquely represent a polynomial by just specifying the coefficients. As an example the above one is a polynomial P(x) = {1, -1} ({coefficient of highest power of x, then the next one, … until the constant term}) Looking at the polynomial we can say that P ⊂ ℝ, i.e. the members of P are taken from the set of all real numbers. The one other thing we usually ask about a polynomial is — “What are the roots of it?” Roots are the solutions of the equation. And they can be many. Solving the equation above like the following

Gives us two roots of the equation. e.g. +1 and -1 which are well inside the realm of ℝ. So far so good. What happens when we try to solve, let’s say

This gives us ±√3. Ah! We got an issue. We have a P ⊂ ℝ whose roots do not come from R. Mathematically we say — “ℝis not algebraically closed”.

Problem becomes even worse when we try to solve

Because the roots are…±√-1 Having a negative number under square root sign defies our standard algebraic intuition yet the equation we were trying to solve is a valid one and thus we need a way to express these new kind of numbers. This is the reason we developed the concept of imaginary number. The imaginary number, written as i, is defined as √-1. And a complex number is such a number which has two components in it, one real and one imaginary.

If we examine carefully then we will see that the set of numbers that is indeed “Algebraically closed” is ℂ, aka the set of all complex numbers. That is a very important property to have. And we will see how we can benefit from it many a times while doing Quantum Computing. Formally we say — “Any polynomial with coefficients from ℂ, has roots in ℂ”.

Check out the following excellent video from MIT OCW for further learning about the importance of Complex Numbers in Quantum Mechanics.

The Algebra of Complex Numbers

A complex number is usually expressed as this — a+ib where we say that a is the real part of the complex number and b is the imaginary part of the complex number. And we can define the following on a complex number

Let z = a +ib be a complex number then Re{z} = a and Im{z} = b thus giving us the real and the imaginary parts.

We can define the two basic operation, e.g. + and * (Addition and Multiplication) on complex numbers. They look like the following

  • To add two complex numbers we just add the real parts and imaginary parts separately. So, if a+ib and c+id are two complex numbers then their sum can be written as — (a+b) + i(c+d). And if we express them using Z1 and Z2 then it is clear from the definition of sum of complex numbers that Z1+Z2 = Z2 + Z1
  • To multiply two complex number described above, what we do is a simple multiplication and then re-arrangement (keeping in mind that i² = -1). It looks like this — (a+ib) * (c+id) = (ac-bd) + i(ad+bc). It is also clear that Z1 * Z2 = Z2 * Z1

As soon as we define addition and multiplication we can ask questions like “what is the additive identity?” “what is the multiplicative inverse?” etc. Some of the answers are straight forward. The additive identity is 0+i0. The additive inverse of a+ib is -a+i(-b) but what about the multiplication? Well, with a bit of thought we can see that the multiplicative identity is 1+i0. By using the identity that Z * (1/Z) = 1+0i we can find the multiplicative inverse. We can verify that the set of complex numbers, ℂ, forms a Field under these two operations. (If you do not know what is a Field then you may want to have a look here)

There are few other things about complex numbers we need to be aware about.

  • Conjugate- A conjugate of a complex number Z is written as a bar on top of Z, and is defined by changing the sign of the complex component. So the conjugate of a+ib is a-ib
  • The modulus of a complex number — Let a+ib be a complex number then the modulus is defined as √(a²+b²). We write it as two parallel bars beside the complex number. Like — |Z|. By using the definition of conjugate and how multiplication is defined, it is easy to show that √(Z*conjugate(Z)) = |Z| = √(a²+b²)

Choices that we made about defining various aspects of complex number’s algebra, and its own properties may seem a bit arbitrary when we first see them but if we look into the geometry of complex numbers then it does not look arbitrary or ad-hoc at all. We shall see that in the next page of these notes.

That is all for the first page. In the next page we will see the geometry of complex numbers and also the some Python code (it is a note for Python programmers, after all). If you liked this note please clap as many times as possible. This will be encouraging for me.

Here is the second part, go ahead if you liked this one :)

--

--

Machine Learning Engineer having > 16 years of experience. Living and working in Paris. Deeply interested in Science! Proud father and husband :)