# On the Definition of Quantum Programming Modules
## 2 Brief Background on Quantum Programming  
This section is devoted to providing a brief introduction to the basic notions of quantum programming and to show the way in which QP are written. The first aspect that distinguishes quantum programming from classical programming is the use of quantum bits (_qubits_) instead of bits. Unlike a traditional bit, which can only take the value 0 or 1, a qubit can be in a superposition of those two states, that is, a probabilistic combination of both (macroscopic) values. A quantum state will be given by the different values that the qubits can take plus the amplitude (\(\alpha\)) which is set by a complex number. The magnitude associated with the amplitude is the absolute value of this complex number, while the relative phase is the angle of the complex number in polar form. Thus, each qubit is also defined by a _magnitude_ and a _relative phase_ (see [18] for a complete explanation of the mathematical foundation). Two qubits may be in four possible states, each parameterized by its amplitude, in which the quare represents the probability that the qubits, once read, will collapse to that value. A two-qubit state can be characterized as follows:  
\[ \begin{array}{l}\text{\emph{System state of }2 qubits}\ \equiv\ \alpha_{0}|00\rangle\,+\alpha_{1}|01\rangle\,+\alpha_{2}|10\rangle\,+\alpha_{ 3}|11\rangle\\ \text{\emph{where }}\alpha_{i}\in\ \mathbb{C}\text{\emph{and }}|\alpha_{0}|^{2}+| \alpha_{1}|^{2}+|\alpha_{2}|^{2}+|\alpha_{3}|^{2}=1\end{array} \]  
where \(\alpha_{0}\), \(\alpha_{1}\), \(\alpha_{2}\), and \(\alpha_{3}\) are the amplitudes of each state; thus, the square of the absolute value of each one is the probability of reading such values when collapsing the former two qubits system. Thus, the superposition of \(2^{n}\) states can be described with just \(n\) qubits, which is a tremendous computational advantage over the classical \(n\) bits, where only a single fixed state is available. In each execution time, and prior to measuring, the qubit can be a superposition of the previous states. In other words, we no longer have a classical bit with a specific value (0 or 1), but a qubit given by a superposition of values 0 and 1. Computation in quantum programming is performed, under the circuit representation of QP, by means of gates, which provide the primitive operations to manipulate the magnitude and phase of the system qubits. This notation resembles the origins of current electronic computation, where the gates implemented the traditional Boolean operations. A quantum computer implements in practice a set of primitive gates which are used to build others, using circuits as a collection of interconnected quantum gates and operations. The type of available gates depends on the hardware infrastructure of the quantum computer, determining the way in which a program is solved in a specific machine [19]. Without loss of generality, we restricted the discussion of this work to the universal set of gates described in the seminal article [20]. Among the basic set of gates, the Hadamard (H) is one of the most used as it provides an equal superposition of states. Other gates such as NOT (the quantum equivalent of the conventional gate), Z, ROTX, ROTY (for the manipulation of qubits properties by manipulating the relative phase in different axis), SWAP (for exchanging two qubits), and CNOT (a two-qubits gate that applies the NOT operation to a target qubit only if the condition qubit has the value 1) are among the basic operations that can be considered on a set of qubits before collapsing through a READ operation. A set of single-qubit gates plus CNOT is called universal when they can be used to construct any unitary matrix (see [20; 21] for more details). As an example, Figure 1 shows a system with two qubits in superposition after applying two H gates and Z to the second qubit. Each qubit has a 50% of probability of collapsing to 0 or 1 but the second one has a relative phase of 180\({}^{\circ}\) (see the angle of the radius drawn).