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:

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

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:

Diagram

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

Simulation

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.

Entanglement

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

Diagram

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

Simulation

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 Rosen^{1}. 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
defined^{2}:

Definition

Let be the state of a quantum register of qubits. The
state is called unentangled if it is the product of the
states of the individual bits:

If there is no such decomposition, the state is called entangled.

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.