# On the Definition of Quantum Programming Modules
## 3 Towards Modular Quantum Programming
### Quantum Modules
(**b**) Module with two sequential gates. Figure 5: Module with a gate applied to a subset of qubits: (**a**) a single gate to a qubit; (**b**) the equivalence using identity gates; and (**c**) the situation when there is entanglement. should be possible to make use of the module without knowing its construction, as a black box. Please note that, according to the \"no-go\" theorem described in [17], the implementation in circuits of certain quantum algorithms may force to rebuild almost entirely the circuit after changing some input data. These types of circuits are not considered modular according to the given constraints, as they can reveal information regarding which algorithm was used beyond its black-box properties;
5. It is possible to include a controlled sub-module to decide, at run-time, if the sub-module should be executed or not. Controlled modules are a particularly important class of modules where one qubit (the controller) turns on or off a unitary operation \(U\). This is a very relevant question in quantum computing because in many cases it is not clear how to directly add a control to a quantum operation, especially in situations where the module implementation is unknown. This is a matter of research that has generated a lot of theorical work [29]. For our purposes and considering the desired black-box properties of the modules, the only way to accomplish that is through the use of the SWAP gate, as it is described in [30];
6. Any explicit sequence of universal gates or sub-modules integration is also considered a quantum module, provided that all the stated constraints are satisfied;
7. Input qubits should not be entangled (though superposition is allowed) with other qubits that do not enter the module or a sub-module. Otherwise, the execution of the module will generate changes beyond the output qubits specified in the definition of a module as a black box, effectively breaking encapsulation. In addition, it could hinder reversibility since the module does not have enough information to reverse the computation. This last rule is added more as a recommendation than an obligation but is needed in order to achieve universal module reuse (for more details on this see the Discussion Section). Figure 6 shows a possible abstract structure of a general module. Some scratch (ancilla) qubits could be considered (as auxiliary) in order to make the computation reversible. The result of the computation could be stored in the relative phase of the output qubit/s (or directly as magnitude). The scheme showed corresponds to a module which itself includes the reverse of the operation performed. As long as the computation does not interfere with the relative phases of the output registers, the information can survive the uncompute step [30]. Please note that not all parts of the figure are mandatory. For instance, a module may not need scratch qubits or to perform the uncompute step. Figure 7 shows an example of a module developed to add two integer numbers encoded in 4 and 3 qubits, respectively. This module implements the expression \(a=a+b\). This in an example of a module that follows the aforementioned structure, but which: (1) does not require scratch qubits to store temporary values, (2) does not require additional qubits to store the result of the computation, and (3) does not require an uncompute step, since the result is stored on the input qubits. In addition, the operation is performed in such a way that is reversible: Input values can be re-constructed from output one just by subtracting the second number from the first one.