Simple Quantum Algorithms

The gates presented in the previous chapters can now be used to create simple algorithms on circuits. To do this, we first need to examine the application of several gates to a qubit illustrated as follows:

Placeholder Image Alt

In the QASM language, we can define three different u3 gates to achieve the three different gates


OPENQASM 2.0; include ""; qreg q[1]; u(pi,pi,pi) q[0]; u(pi/2,pi/2,pi/2) q[0]; u(pi/4,pi/4,pi/4) q[0];


Not run yet

The states of the intermediate steps and are calculated analogously to the application of a single gate:

Please note that the order of the gates cannot generally be reversed.

Random Number Generator

The states and the corresponding probability of obtaining a certain final state can be calculated, but certainty can only be achieved by measuring, which in turn destroys the possible superposition of the qubit(s). During the course of this lecture, we will often see that this effect of measurement can also be used as a specific tool for tasks.

A simple example is the combination of a Hadamard gate and a measurement, which creates a real random number generator:


OPENQASM 2.0; include ""; qreg q[1]; creg c[1]; h q[0]; measure q[0] -> c[0];


Not run yet

The state of the input qubit can be either or , as in both cases the Hadamard gate places the qubit in a state in which and are equally probable as measurement results.


Another circuit that looks very simple at first glance is the entanglement of two qubits.


OPENQASM 2.0; include ""; qreg q[2]; h q[0]; cx q[0], q[1];


Not run yet

If , the states in the intermediate steps are as follows:

At time step , the measured value of each qubit is not determined and it is equally likely to obtain or . Yet, the state also shows that the measurement results of both qubits will be the same in any case. So if we measure for , the measurement result of is also fixed (namely ). It also means that even if we separate the two qubits spatially and then measure them independently of each other, the results still correlate.

This state is named after the Irish physicist John Bell; there are a total of four such states depending on the input register :

The four states differ mainly in that the same result is measured for and on both qubits, whereas and produce opposite measurement results. The two states with positive amplitude and are also described as EPR pair, named after a publication by Einstein, Podolski and Rosen1. We can also calculate the Bell states using the matrix representation, e.g. :

We can see from this final state that it cannot be written as a tensor product of individual qubits. This is precisely how entanglement is defined2:

To create an entangled state, we need a unitary transformation, which itself cannot be represented as a tensor product on individual qubits. Alongside superposition, entanglement is one of the most powerful tools for quantum computing. Physically, these states are difficult to produce and therefore expensive, which is particularly true if they are to be produced over long distances.


  1. Einstein, Albert, Boris Podolsky, and Nathan Rosen. "Can quantum-mechanical description of physical reality be considered complete?." Physical review 47.10 (1935): 777..

  2. Aaronson, Scott. "Introduction to quantum information science II lecture notes." (2022). p.40

QuBit Measurements
Linear Optics Quantum Computing

Copyright © 2024 Walther Group, Faculty of Physics, University of Vienna. All rights reserved.