Optimization of Reversible Circuits Using Toffoli Decompositions with Negative Controls

: The synthesis and optimization of quantum circuits are essential for the construction of quantum computers. This paper proposes two methods to reduce the quantum cost of 3-bit reversible circuits. The ﬁrst method utilizes basic building blocks of gate pairs using different Toffoli decompositions. These gate pairs are used to reconstruct the quantum circuits where further optimization rules will be applied to synthesize the optimized circuit. The second method suggests using a new universal library, which provides better quantum cost when compared with previous work in both cost015 and cost115 metrics; this proposed new universal library “Negative NCT” uses gates that operate on the target qubit only when the control qubit’s state is zero. A combination of the proposed basic building blocks of pairs of gates and the proposed Negative NCT library is used in this work for synthesis and optimization, where the Negative NCT library showed better quantum cost after optimization compared with the NCT library despite having the same circuit size. The reversible circuits over three bits form a permutation group of size 40,320 ( 2 3 ! ) , which is a subset of the symmetric group, where the NCT library is considered as the generators of the permutation group.


Introduction
One of the problems in classical computers is heat dissipation and energy loss. The amount of energy dissipated for any lost bit of information is calculated by R. Landauer's principle, which is KTln2, where K is the Boltzmann's constant (1.3807 × 10 −23 JK −1 ) and T is the temperature of the system. Reversible computing has one of many features, where no heat dissipation is produced by the system [1]; hence, no information is destroyed. This feature has many applications [2], such as low-power CMOS [3], nanotechnology [4], DNA-based logic circuit with self error recovery capability employing massive parallelism [5] and many more [6].
Quantum computing is reversible by nature [7]. Recently, using group theory in studying the reversible logic synthesis problem has gained attention [8,9]. Group theory is also used to find a relationship between the decomposition of a reversible circuit and a quantum circuit in [10]. A relationship between the reversible logic synthesis problem and Young subgroups is introduced in [11]. A reversible gate is the basic building block of a reversible circuit [3]. Quantum gates are reversible gates/functions, which are considered as a special case of symmetry groups of finite spaces (Young subgroups) [10]. Many methods have been proposed to optimize the quantum cost of circuits [12,13]. The quantum cost of the NCT library is reduced in [14]; a further reduction of the quantum cost of the NCT library is made in [15]. The algorithms in [16,17] use an ancillary qubit to achieve less quantum cost. Universal reversible gate libraries are proposed in [18][19][20], which use GAP-based algorithms to synthesize reversible circuits using different types of gates with various gate costs. Different Toffoli decompositions are proposed in [21] to reduce the quantum cost of reversible circuits. Toffoli gates have control qubits, which can be positive or negative. The positive control is applied if the system is in the excited state, whereas the negative control is applied if the system is in the ground state. The importance of the ground state over the excited state in systems for better stability is discussed in [22], which shows that systems tend to be more stable in the ground state compared with the excited state, so using negative controls is more stable and has less quantum cost for the system compared with using positive controls [23][24][25][26].
The paper has two aims: the first aim of this paper is to propose an algorithm that optimizes the quantum cost of 3-bit reversible circuits based on a modified version of the NCT library; the second aim is to propose a new gate library by modifying the NCT library to replace positive control with negative control, which shows less quantum cost compared with the NCT library.
This paper is organized as follows: Section 2 gives a brief introduction to elementary quantum gates used to build quantum circuits, permutation group, definitions and terminologies used in this paper. Section 3 introduces the proposed library and proposed synthesis algorithm. Section 4 shows the experimental results. The paper concludes in Section 5.

Background
This section gives a brief introduction on the basics of reversible circuit, Negative NCT library gates and permutation group.

Reversible Boolean Function
A Boolean function f with n inputs and n outputs f : X n → X n is considered to be reversible if and only if each input vector x ∈ X n is mapped to a unique output vector y ∈ X n where X = {0, 1}. For n inputs there are 2 n ! different reversible Boolean functions, for n = 3 there is 2 3 ! = 40,320 3-input/output reversible Boolean functions.
Given a finite set A = {1, 2, . . . , 2 n }, α is permutation and a bijection function that maps an input to an output from A such that α : A → A, it can be represented as a permutation as follows in (1).
The top row is ordered so that it can be eliminated, so α can be written as in (2).

Reversible Quantum Logic
Quantum computers use qubit as the basic unit of information, which is represented by a state vector. The vector: |ψ = α|0 + β|1 represents a single qubit where α and β are complex numbers that satisfy the condition |α| 2 + |β| 2 = 1. The measurement of |ψ determines the state of the system. Four states of the system are used in this paper; the first state is the standard state |0 where β is 0, the second state is the standard state |1 where α is 0, the third state is |+ where |+ = (1+i)|0 +(1−i)|1

Reversible Gates
A reversible gate is a reversible Boolean function in which each input vector has a unique output vector.

One-Qubit Gates
This section introduces the one qubit reversible gates that are used in this paper. NOT gate (N): A reversible gate that maps |0 to |1 and vice versa, also maps |+ to |− and vice versa. The superscript of N gate is 3 when N gate is applied on a three-qubit reversible circuit (N 3 ) and the subscript of N gate refers to a specific qubit that NOT gate is applied on. For example, N 3 2 applies a NOT gate on the second qubit in a three-qubit reversible circuit. Table 1 shows the effect of a NOT gate on one qubit.
There are three possible gates of a NOT gate for three-qubit reversible circuits as shown in Figure 1a with the following permutations in (3): (3)

Condition on Control Qubits
Controlled gates that operate on two or more qubits have at least one control qubit. The condition on control qubit(s) must be satisfied in order for the gate to operate on the target qubit. Definition 1. The condition on a control qubit is a condition that must be satisfied so that the gate on the target qubit is applied. The condition on the control qubit could be negative or positive.
If the condition on the control qubit is negative or positive, then the gate on the target qubit will be applied if the control qubit's state is |0 or |1 , respectively [27]. For example, a gate that has n control qubits with a negative condition on the control qubits will operate on the target qubit if all of the control qubits' states are |0 . In this paper, the negative control is represented in figures by • and the positive control is represented by •. Only negative control gates are used in this paper because the quantum systems are more stable in the ground state, where the negative control gates are used compared with the excited state in which the positive control gates are applied [22][23][24][25][26].

Two-Qubit Gates
These gates operate on two qubits in which one qubit is the control qubit and the other qubit is the target qubit.
In the CNOT gate and OCNOT gate, if the control qubit's state is |1 and |0 , respectively, then negation will be applied on the target qubit, while the control qubit's state remains unchanged; otherwise it does nothing.
The superscript of the C gate is 3 when the CNOT/OCNOT gate is applied on a threequbit reversible circuit (C 3 ). The subscript of C 3 gate consists of two adjacent numbers, the Symmetry 2021, 13, 1025 4 of 23 number on the left-hand side represents the control qubit and the number on the right-hand side represents the target qubit. For example, C 3 12 represents the CNOT gate with a positive control on the first qubit and a target on the second qubit; C 3 12 represents the OCNOT gate with a negative control on the first qubit and a target on the second qubit.
The truth table of the CNOT gate is shown in Table 1. There are six possible gates for the CNOT gate for three-qubit reversible circuits as shown in Figure 1b. The truth table of the OCNOT gate is shown in Table 1. There are six possible gates of the OCNOT gate for three-qubit reversible circuits as shown in Figure 1c with the following permutations in (4):

Controlled-V:
A two-qubit gate that has two versions: positive V (CV) and negative V (OV). In the CV gate and OV gate, if the control qubit's state is |1 and |0 , respectively, then the v gate is applied to the target qubit and the control qubit's state remains unchanged; otherwise it does nothing.
Controlled-V † : A two-qubit gate that has two versions: positive V † (CV † ) and negative V † (OV † ). In the CV † gate and OV † gate, if the control qubit's state is |1 and |0 , respectively, then the v † gate is applied to the target qubit and the control qubit's state remains unchanged; otherwise it does nothing.
The truth table of the CV, CV † , OV and OV † gates are shown in Table 1. There are six possible gates for the OV gate and six possible gates of the OV † gate for three-qubit reversible circuits as shown in Figure 1d, (5):  The quantum cost of a reversible circuit, which is denoted by Q.C in this paper is

Three-Qubit Gate
These gates operate on three qubits, where two qubits are the control qubits and the third qubit is the target qubit.

Controlled controlled NOT (CCNOT) or (Toffoli/T gate):
In this paper, we use two different versions of the Toffoli gate: positive Toffoli (Toffoli) and negative Toffoli (OToffoli). In the Toffoli gate and OToffoli gate, if the control qubits' states are |1 and |0 , respectively, then the negation will be applied on the target qubit, while the control qubits' states remain unchanged; otherwise it does nothing. Mixed Control Toffoli gates also exist where one of the control qubits is negative and the other control qubit is positive.
The superscript of T gate is 3 when the Toffoli/OToffoli gate is applied on a three-qubit reversible circuit (T 3 ). The subscript of T 3 gate consists of three adjacent numbers: the first two numbers starting from the left-hand side indicate the control qubits and the number on the right-hand side indicates the target qubit. For example, T 3 123 represents the Toffoli gate with positive control qubits. T 3 132 represents the OToffoli gate with negative control qubits. T 3 132 and T 3 231 represent the Mixed Control Toffoli gates with mixed control qubits. There are three possible gates for a Toffoli gate for three-qubit reversible circuits as shown in Figure 1f. There are three possible gates for an OToffoli gate for three-qubit reversible circuits as shown in Figure 1g. Some examples of Mixed Control Toffoli gates are shown in Figure 1h. The truth table for the Toffoli and OToffoli gates are shown in Table 1.
The following OToffoli permutations are introduced in (5):

Quantum Cost of a Reversible Circuit
The quantum cost of a reversible circuit, which is denoted by Q.C in this paper is the count of the one-qubit and the two-qubit elementary gates in the decomposition of the circuit.
In this paper, two methods for calculating the quantum cost are used: the cost015 metric [28] and cost115 metric [29]. In the cost015 metric: the quantum cost of a one-qubit gate is 0, two-qubit gate is 1 and three-qubit gate is 5 [30]. In the cost115 metric: the quantum cost of a one-qubit gate is 1, two-qubit gate is 1 and three-qubit gate is 5.

Optimization Rules of Quantum Gates: Moving, Merging and Splitting
For a three-qubit quantum circuit with a set of wires W = {1, 2, 3}, where the first qubit is 1, the second qubit is 2 and the third qubit is 3. Let K 12 be any two-qubit gate whose control qubit is negative on qubit 1 and its target qubit is on qubit 2, where 1 = 2 = 3. Table 2 shows the moving rules where a gate can be swapped with its adjacent gate. For example, the one-qubit NOT gate N 3 1 that acts on the first qubit can be swapped with its adjacent one-qubit gate that acts on any of the other two qubits; the N 3 1 gate can also be swapped with its adjacent two-qubit gate if the control qubit in the two-qubit gate is not the same as the qubit that N 3 1 acts on; in this case N 3 1 can be swapped with C 3 21 , C 3 31 , OV 21 , OV 31 , OV † 21 , OV † 31 , C 3 23 , C 3 32 ,OV 23 , OV 32 , OV † 23 and OV † 32 . Adjacent two-qubit gates can be swapped if they have the same control qubit or if they have the same target qubit. For example, C 3 23 can be swapped with C 3 13 , C 3 21 , OV 13 , OV 21 , OV † 13 and OV † 21 . Table 3 shows the merging rules in which two adjacent gates can be merged to form a new gate. For example, any two adjacent one-qubit gates that are applied on the same qubit can be merged to form an identity gate if the application of the second gate reverses the first gate. Any two adjacent two-qubit gates with the same control qubit and the same target qubit can form a new gate. For example, OV 12 C 3 12 are merged to form OV † 12 . Furthermore, if two adjacent two-qubit gates in which the control qubit of the first gate is the same as the target qubit of its adjacent gate, and the target qubit of the first gate is the same as the control qubit in its adjacent gate, then these gates can form a new gate and the resulting two-qubit gate has a quantum cost of 1 in both of the cost015 and cost115 metrics [15]. For example, C 3 12 OV 21 can be merged to form a two-qubit gate [C 3 12 OV 21 ]. In this paper, the visual representation of this gate is shown by surrounding this two-qubit gate with a dashed box and its quantum cost is 1 [15]. The splitting rules are the reverse of the merging rules, these optimization rules are used in [14][15][16][17][18]21].

Gate
Swappable Gates

The Proposed Negative NCT-Gate Library
This section explains the proposed Negative NCT gate library for building three-qubit reversible circuits. The Negative NCT gate library that works on three-qubit reversible circuits consists of three types of gates: one-qubit gates, two-qubit gates and three-qubit gates. This proposed library consists of 12 gates and their detailed information is represented in Section 2. The 12 gates are three NOT gates, six OCNOT gates and three OToffoli gates. An implementation of the Schreier-Sims algorithm on the GAP software is used to generate the set of all possible three-qubit reversible circuits with the least length (40,319 circuits excluding the identity [20]), which shows the universality of the Negative NCT gate library for 3-bit reversible circuits.

Gate Decomposition
Definition 2. Gate symbol L num is a unique symbol that refers to a gate where num is an integer number. For example, L 1 and L 23 . Table 4 shows the gates with their corresponding gate symbol (sym.).
The decomposition (L num ) d of a gate is a set of elementary gates that can be used to synthesize a quantum circuit equivalent to this gate, each set of these elementary gates is given a number d starting from 0. For example, (L 2 ) 0 represents the gate symbol L 2 in its 0th decomposition. One-qubit gates and two-qubit gates are elementary gates themselves; hence, each gate has only one decomposition denoted by the 0th decomposition, which is the gate itself. Table 5 shows the Negative NCT gates with their corresponding decomposition(s) where each one-qubit gate or two-qubit gate has only one decomposition, which is the gate itself, while each three-qubit gate can be decomposed using (NOT, CNOT, V, V † ) gates, which was shown to be optimal [30]. The three-qubit gate has eight different decompositions. Figures 2-4 show the eight different decompositions for each OToffoli gate that depend on the Toffoli decompositions in [21]. This paper uses only negative control decompositions, while [21] uses only positive control decompositions. where each one-qubit gate or two-qubit gate has only one decomposition which is the 199 gate itself, while each three-qubit gate can be decomposed using (NOT, CNOT, V, V † ) 200 gates as shown to be optimal [31]. The three-qubit gate has eight different decomposi-201 tions. Figure 2, Figure 3 and Figure 4 show the eight different decompositions for each 202 OToffoli gate which depend on the Toffoli decomositions in [22]. This paper uses only 203 negative control decompositions, while [22] uses only positive control decompositions.
where in (a) the first control qubit is on qubit 1 and the second control qubit is on qubit 2, and in (b) the first control qubit is on qubit 2 and the second control qubit is on qubit 1. These decompositions are the negative decompositions which are based on the positive decompositions in [22]. where in (a) the first control qubit is on qubit 1 and the second control qubit is on qubit 2, and in (b) the first control qubit is on qubit 2 and the second control qubit is on qubit 1. These decompositions are the negative decompositions, which are based on the positive decompositions in [21]. gate itself, while each three-qubit gate can be decomposed using (NOT, CNOT, V, V ) 200 gates as shown to be optimal [31]. The three-qubit gate has eight different decomposi-201 tions. Figure 2, Figure 3 and Figure 4 show the eight different decompositions for each 202 OToffoli gate which depend on the Toffoli decomositions in [22]. This paper uses only 203 negative control decompositions, while [22] uses only positive control decompositions.
where in (a) the first control qubit is on qubit 1 and the second control qubit is on qubit 2, and in (b) the first control qubit is on qubit 2 and the second control qubit is on qubit 1. These decompositions are the negative decompositions which are based on the positive decompositions in [22]. where in (a) the first control qubit is on qubit 1 and the second control qubit is on qubit 3, and in (b) the first control qubit is on qubit 3 and the second control qubit is on qubit 1. These decompositions are the negative decompositions, which are based on the positive decompositions in [21].

Gate
Gate Decomposition
Each decomposition of the OToffoli gates contains two gate sets; the rg set and the 220 lg set where each of these sets contains OP elements, the OP of a gate is concerned with 221 the control qubit and the target qubit only, and it does not concern with the condition

Right and Left Gate Sets of a Decomposition
Definition 3. The ordered pair of a gate (OP) is an ordered pair that contains the control qubit and the target qubit of a gate (control − qubit, target − qubit).
An example of an OP for a three-qubit system is (1, 3), where the control is on the first qubit and the target is on the third qubit.  The rg set or the lg set contains ordered pairs with the same control qubit or the same target qubit; otherwise the rg set or the lg set contains one OP element only. An example of the rg set of (L 1 ) 0 gate in Figure 2a is {(1, 3), (1, 2)}, where the two ordered pairs in the rg set have the same control qubit in this example and the lg set of (L 1 ) 0 gate is {(2, 3)}. Another example of the rg set of (L 2 ) 5 gate in Figure 3b is {(1, 2)} and the lg set of (L 2 ) 5 gate is {(3, 2), (3, 1)}, where the two ordered pairs in the lg set have the same target qubit in this example.
Each decomposition of the OToffoli gates contains two gate sets; the rg set and the lg set where each of these sets contains OP elements, the OP of a gate is concerned with the control qubit and the target qubit only, and it does not concern with the condition on the control qubit nor the functionality of the gate itself. The rg set and the lg set of a decomposition contain the OP of the gate on the right-hand side and the left-hand side, respectively. For example, (L 1 ) 0 decomposition, which is shown in Figure 2a has a lefthand side gate, which is V 23 , where the control qubit is on qubit 2 (the second qubit) and the target qubit is on qubit 3 (the third qubit), so this gate's OP is (2,3); hence, the lg set of (L 1 ) 0 is {(2, 3)}, if V 23 gate and its next gate can be swapped, then the OP of the V 23 next gate can also be added to the lg set; C 3 12 cannot be swapped with V 23 ; hence, the lg set for this decomposition remains unchanged. The right-hand side gate in (L 1 ) 0 decomposition is V 13 where this gate's OP is (1,3); hence, the rg set of (L 1 ) 0 is {(1, 3)} if the V 13 gate and its prior gate can be swapped then the OP of V 13 gate's prior gate can be added to the rg set; C 3 12 can be swapped with V 13 ; hence, the rg set is updated to {(1, 3), (1, 2)}.
In two-qubit gates, the rg set = the lg set = the OP of the gate. Table 6 shows the Negative NCT gates that have corresponding lg and rg sets.

Definition 5.
A basic pair is a circuit that consists of two consecutive decomposed gates with minimal quantum cost and lower decomposition number.
The set of all possible circuits that represent a pair of gates is calculated by multiplying the count of decompositions of each gate inside this pair. For example, the L 1 L 2 pair begins with the L 1 gate, which has eight different decompositions as shown in Figure 2, and the second gate is the L 2 gate, which has eight different decompositions as shown in Figure 3, so there are 64 different circuits for this pair of gates. Section 3.2.1 shows a technique that chooses the circuit with the least quantum cost out of these 64 different circuits in order to represent the basic pair for this pair of gates L 1 L 2 .

Choosing the Basic Pair
Definition 6. The sets RG and LG of a circuit are the sets of all rg and lg sets, respectively.
Two adjacent gates with the same control and target qubits can be combined to form a new gate according to the merging rules in Table 3. Therefore, the technique to choose the circuit with minimal cost works through finding the largest set that results from the intersection of the RG set of the first gate with the LG set of the second gate inside the basic pair, if the two sets are mutually exclusive, then it finds the largest set that results from intersecting the invert of the RG set of the first gate with the LG set of the next gate. For example, if the RG set of the first gate includes {(1, 3)}, and there are no mutual elements in the LG set of the next gate, then it searches for {(3, 1)} in the LG set of the second gate instead, since these two gates can form a two-qubit gate with a quantum cost of 1 according to the merging rules in [15].
For example, the L 1 L 2 pair has 64 different circuits to represent it. The basic pair with the least quantum cost of this pair is (L 1 ) 0 (L 2 ) 1 in which the decomposition number of the first gate is 0 and the decomposition number of the next gate is 1 since the intersection of the RG set of L 1 and the LG set of L 2 is {(1, 2)(1, 3)} according to Table 6, then the final quantum cost of this basic pair is 7 instead of 10. Figure 5 shows the (L 1 ) 0 (L 2 ) 1 basic pair where Figure 5a shows the basic pair before optimization with a quantum cost of 10, the gate on the right-hand side of (L 1 ) 0 and the gate on the left-hand side of (L 2 ) 1 are marked with arrows. Figure 5b shows the basic pair after swapping the marked gates, then the gates in the solid boxes are prepared for merging. Figure 5c shows the basic pair after applying the merging rules and forming two two-qubit gates, then the newly formed two-qubit gate on the left hand-side is marked. Figure 5d shows the basic pair after moving the marked gate to the right-hand side and marking the other resulting two-qubit gate. Figure 5e shows the basic pair after moving the marked gate to the left-hand side and finally applying further optimization, where the quantum cost is reduced to 7 after forming a two-qubit gate with a quantum cost of 1 [15]. ted to Journal Not Specified 12 of 25 Figure 5. (L 1 ) 0 (L 2 ) 1 basic pair where (a) represents the basic pair before optimization with a quantum cost of 10, (b) represents the basic pair after swapping the two marked gates and the solid box shows the gates which will be merged, (c) represents the basic pair after applying the merging rules, where two two-qubit gates are formed and the quantum cost is reduced to 8, (d) represents the basic pair after moving the marked gate to the right-hand side and marking the other resulting two-qubit gate, and (e) represents the basic pair after moving the marked gate to the left-hand side and applying the optimization rules, where the dashed box indicates forming a two-qubit gate [16]; hence, the final quantum cost is 7.   Figure 5. (L 1 ) 0 (L 2 ) 1 basic pair where (a) represents the basic pair before optimization with a quantum cost of 10; (b) represents the basic pair after swapping the two marked gates and the solid box shows the gates that will be merged; (c) represents the basic pair after applying the merging rules, where two two-qubit gates are formed and the quantum cost is reduced to 8; (d) represents the basic pair after moving the marked gate to the right-hand side and marking the other resulting two-qubit gate; (e) represents the basic pair after moving the marked gate to the left-hand side and applying the optimization rules, where the dashed box indicates forming a two-qubit gate [15]; hence, the final quantum cost is 7.
Another example is L 2 L 27 , where L 27 is a two-qubit gate, then it has only one decomposition (L 27 ) 0 , choosing (L 2 ) 4 or (L 2 ) 6 will reduce the quantum cost of this basic pair to 4 instead of 6, where the rg of the (L 2 ) 4 gate matches the lg of the (L 27 ) 0 gate, while choosing (L 2 ) 0 , (L 2 ) 1 , (L 2 ) 2 or (L 2 ) 3 will reduce the quantum cost to 5 after optimization. Finally, choosing (L 2 ) 5 or (L 2 ) 7 will not reduce the quantum cost at all, a visual explanation of this example is shown in Figure 6, where (L 2 ) 4 (L 27 ) 0 and (L 2 ) 6 (L 27 ) 0 have the least quantum cost but the basic pair of L 2 L 27 circuit is (L 2 ) 4 (L 27 ) 0 since the basic pair with lower decomposition number (num) is considered to be the basic pair for this pair as shown in Table 7.
The Negative NCT library consists of 12 gates and the total number of basic pairs (which have the lowest quantum cost) for this library is 12 × 12 = 144 basic pairs. Table 7 shows the Negative NCT library's basic pairs excluding basic pairs that contain NOT gates and basic pairs in which both gates are OCNOT gates because there is no further reduction. Table 7 also shows the quantum cost of the basic pair before and after optimization and its corresponding circuit. tted to Journal Not Specified 13 of 25   Table 7. Negative NCT library's basic pairs, where BO refers to the quantum cost before optimization and AO refers to the quantum cost after optimization.

Pair of Gates
Gate Decomposition/Basic Pair AO BO Basic Pair Circuit

Build a Circuit with Basic Pairs
Definition 7. The solitary gate of a gate is the gate in its 0th decomposition.
Basic pairs are concatenated to form circuits, the rg of the basic pair and the lg of the next basic pair are called a "point of connection". For example, the L 2 L 27 L 1 L 2 circuit consists of four gates, each two gates starting from the left-hand side are replaced with their corresponding basic pair, so in this case the circuit consists of two basic pairs where the first basic pair is (L 2 ) 4 (L 27 ) 0 and the next basic pair is (L 1 ) 0 (L 2 ) 1 as shown in Figure    Let S be the total number of gates in a circuit; whether, S is even or odd determines the number of basic pairs and solitary gates, which are used to build the circuit, where the number of solitary gates in a circuit is ≤2. Two methods are going to be proposed in the next sections in order to choose the basic pairs to reconstruct a circuit. FunctionI (Algorithm 1) is used by the proposed circuit optimization algorithm (Algorithm 2) to reconstruct each circuit of the three-qubit system by using basic pairs of gates. In FunctionI (Algorithm 1), the gates are paired starting from the left-hand side gate of the circuit. BasicPair(C i , C i+1 ) represents the corresponding basic pairs of the ith and ith + 1 gates in the circuit C, if S is odd, then the last gate on the right-hand side of the circuit is merged with the circuit as a solitary gate where Solitary(C i ) decomposes the OToffoli gate in its 0th decomposition and returns other gates unchanged. Finally, optimize(C) applies optimization rules on the points of connection of the circuit.  Table 7, the gate on the right-hand side is L 22 and it will be decomposed into its decomposition number 0 since S is odd, where (L 22 ) 0 has a quantum cost of 1, the BPS quantum cost of this reconstructed circuit is 12 instead of 17 in the cost015 metric, the optimization rules are then applied on points of connection of the reconstructed circuit and the final quantum cost for this reconstructed circuit is 11. Figure 8 shows the decomposition steps of the L 22 L 1 L 3 L 1 L 22 circuit before and after applying the optimization rules. The dashed box in Figure 8 refers to a two-qubit gate with a quantum cost of 1 [15].

Circuit Optimization Algorithm
to Journal Not Specified 17 of 25 Figure 9 illustrates L 13 L 1 L 2 L 22 L 13 circuit example before and after applying the 349 optimization rules in the cost015 metric, the dashed box indicates forming a two-qubit 350 gate with a quantum cost of 1 [16]. Figure 8. L 22 L 1 L 3 L 1 L 22 circuit where (a) represents the quantum circuit with a quantum cost of 17, (b) represents the reconstructed circuit using basic pairs of gates and a solitary gate with a quantum cost of 12, and (c) represents the quantum circuit after applying the optimization rules and forming a two-qubit gate. The final quantum cost after optimization is 11.

Modified Circuit Optimization Algorithm
In Algorithm 2, the optimization technique depends on FunctionI (Algorithm 1). FunctionII (Algorithm 3) splits the circuit into basic pairs starting from the second gate on the left-hand side instead of the first gate. If S is odd and S ≥ 3, then the circuit is reconstructed as a solitary gate and basic pairs(s), while for even S ≥ 4, then the circuit is reconstructed as a solitary gate then basic pair(s) and finally a solitary gate. For example, the L 13 L 1 L 2 L 22 L 13 circuit has a quantum cost of 11, which can be reconstructed using FunctionI (Algorithm 1) which results in two basic pairs and one solitary gate on the righthand side: (L 13 ) 0 (L 1 ) 0 with a quantum cost of 5, (L 2 ) 0 (L 22 ) 0 with a quantum cost of 5 and (L 13 ) 0 with a quantum cost of 0, the BPS quantum cost for this circuit using FunctionI (Algorithm 1) is 10; using FunctionII (Algorithm 3) gives one solitary gate on the left-hand side and two basic pairs: (L 13 ) 0 with a quantum cost of 0, (L 1 ) 0 (L 2 ) 1 with a quantum cost of 7 and (L 22 ) 0 (L 13 ) 0 with a quantum cost of 1, where the BPS quantum cost for this circuit using FunctionII (Algorithm 3) is 8, the latter function shows a better quantum cost for this circuit and the final quantum cost using FunctionII (Algorithm 3) is 7 after applying the optimization rules on the points of connection instead of 11 in the cost015 metric as shown in Figure 9. Figure 9 illustrates the L 13 L 1 L 2 L 22 L 13 circuit example before and after applying the optimization rules in the cost015 metric, the dashed box indicates forming a two-qubit gate with a quantum cost of 1 [15]. Figure 9. L 13 L 1 L 2 L 22 L 13 circuit where (a) represents the quantum circuit with a quantum cost of 11, (b) represents the quantum circuit, which is reconstructed by using FunctionI 11.1 with a BPS quantum cost of 10, (c) represents the quantum circuit, which is reconstructed by using FunctionII 11.3 with a BPS quantum cost of 8, and (d) represents the quantum circuit, which is reconstructed using FunctionII 11.3 after applying the optimization rules on the points of connection and the final quantum cost is 7. ≡ • Figure 10. Preparing the gate for IBM Quantum Experience implementation, where a negative control is equivalent to adding NOT gates before and after a positive control.
The reconstructed circuit L 13 L 1 L 2 L 22 L 13 , which is obtained from applying Function 364 Figure 9. The L 13 L 1 L 2 L 22 L 13 circuit where (a) represents the quantum circuit with a quantum cost of 11; (b) represents the quantum circuit, which is reconstructed by using FunctionI (Algorithm 1) with a BPS quantum cost of 10; (c) represents the quantum circuit, which is reconstructed by using FunctionII (Algorithm 3) with a BPS quantum cost of 8; (d) represents the quantum circuit, which is reconstructed using FunctionII (Algorithm 3) after applying the optimization rules on the points of connection and the final quantum cost is 7.
IBM Quantum Experience ibmq − ourense system [31] was used to implement the L 13 L 1 L 2 L 22 L 13 circuit, whose permutation was (5,8,6). The ibmq − ourense system has five qubits, a Canary r2 processor, with an average CNOT error of 8.750e −3 , and average readout error of 2.800e −2 . The IBM Quantum Experience does not currently support the V † ab gate where qubit a = qubit b, so this gate is replaced with V ab C 3 ab gates since they are equivalent according to the splitting rules, which are the reverse of the merging rules in Table 3. The IBM Quantum Experience does not also support the negative control qubit, so the positive control qubit is used and NOT gates are added before and after each positive control qubit in the quantum circuit as shown in Figure 10 since they are equivalent according to [32]. Figure 9. L 13 L 1 L 2 L 22 L 13 circuit where (a) represents the quantum circuit with a quantum cost of 11, (b) represents the quantum circuit, which is reconstructed by using FunctionI 11.1 with a BPS quantum cost of 10, (c) represents the quantum circuit, which is reconstructed by using FunctionII 11.3 with a BPS quantum cost of 8, and (d) represents the quantum circuit, which is reconstructed using FunctionII 11.3 after applying the optimization rules on the points of connection and the final quantum cost is 7. ≡ • Figure 10. Preparing the gate for IBM Quantum Experience implementation, where a negative control is equivalent to adding NOT gates before and after a positive control.
The reconstructed circuit L 13 L 1 L 2 L 22 L 13 , which is obtained from applying Function 364 11.3 is modified to be compatible with the ibmq − ourense system by applying the 365 splitting rules and the rule in Figure 10. The implementation of L 13 L 1 L 2 L 22 L 13 circuit 366 on the ibmq − ourense system has a quantum cost of 7 as shown in Figure 11, while the 367 implementation of the equivalent quantum circuit, which permutation is (5,8,6) using 368 the NCT library has a quantum cost of 11 as shown in Figure 12. The reconstructed circuit L 13 L 1 L 2 L 22 L 13 , which is obtained from applying FunctionII (Algorithm 3) is modified to be compatible with the ibmq − ourense system by applying the splitting rules and the rule in Figure 10. The implementation of the L 13 L 1 L 2 L 22 L 13 circuit on the ibmq − ourense system has a quantum cost of 7 as shown in Figure 11, while the implementation of the equivalent quantum circuit, whose permutation is (5,8,6) using the NCT library has a quantum cost of 11 as shown in Figure 12.  The modified circuit optimization algorithm (Algorithm 4) calculates the BPS quantum cost for each circuit using BPS(C) of FunctionI (Algorithm 1) and FunctionII (Algorithm 3), then it chooses the function, which has less BPS quantum cost in order to reconstruct the quantum circuit, where m represents a mark to the function having less BPS quantum cost.
For example, the L 25 L 2 L 26 L 25 circuit, which is equivalent to the (6, 7) permutation has a quantum cost of 8. The BPS quantum cost for the L 25 L 2 L 26 L 25 circuit using FunctionI (Algorithm 1) is 6 and the BPS quantum cost using FunctionII (Algorithm 3) is 7, so Algorithm 4 chooses FunctionI (Algorithm 1) to decompose the circuit, where the circuit is reconstructed using two basic pairs, which are (L 25 ) 0 (L 2 ) 0 with a quantum cost of 5, followed by (L 26 ) 0 (L 25 ) 0 with a quantum cost of 1 according to [15]. The L 25 L 2 L 26 L 25 circuit is shown in Figure 13 before optimization, after optimization, and the equivalent circuit on the ibmq − ourense system after using the splitting rules and the preparation of negative gates as shown in Figure 10. While the implementation of the equivalent L 25 L 2 L 26 L 25 quantum circuit, whose permutation is (6, 7) using the NCT library on the ibmq − ourense system has a quantum cost of 15 as shown in Figure 14. From the examples in Figures 13 and 14, it is shown that the Negative NCT library has less quantum cost for this example compared with the NCT library. Extending the Negative NCT library for n-qubits, where n > 3 is achievable since higher order gates can be decomposed into three-qubit gates according to [30,33].
(c) Figure 13. The L 25 L 2 L 26 L 25 circuit, where (a) represents the quantum circuit with a quantum cost of 8, (b) represents the quantum circuit after optimization with a quantum cost of 6, and (c) represents the circuit implementation on the ibmq − ourense system with a quantum cost of 6. The dashed box indicates forming a two qubit gate and the solid box indicates forming V † gate. Figure 14. The equivalent L 25 L 2 L 26 L 25 circuit using the NCT library, where (a) represents the quantum circuit with a quantum cost of 15 and (b) represents the circuit implementation on the ibmq − ourense system with a quantum cost of 15. From the examples in Figure 13 and Figure 14, it is shown that the Negative NCT 389 library has less quantum cost for this example compared with the NCT library. Extending 390 the Negative NCT library for n-qubits, where n > 3 is achievable since higher order 391 gates can be decomposed into 3-qubit gates according to [31,34].  [17][18][19][20] and [16]. The Negative NCT library shows an average length as in the NCT

Experimental Results
This section describes the experiments on three-qubit reversible circuits based on the proposed Negative NCT library and compares the results with relevant libraries in [15][16][17][18][19]. The Negative NCT library shows an average length as in the NCT library, which equals 5.86. The comparison includes the proposed circuit optimization algorithm (Algorithm 2) and the proposed modified circuit optimization algorithm (Algorithm 4). Table 8 compares the average quantum cost of three-qubit reversible circuits in the cost015 metric using the proposed Negative NCT library and the works found in the literature, where the average quantum cost of the Negative NCT library after using the proposed modified circuit optimization algorithm (Algorithm 4) is 10.078, while the average quantum cost of the Negative NCT library using the proposed circuit optimization algorithm (Algorithm 2) is 10.202. Finally, the quantum cost of the Negative NCT library before optimization is 13.364. Table 8 compares the obtained results with other libraries in [15,18,19], where the average quantum cost after optimization is 10.348 in [15], 13.388 in [18] and 13.290 in [19]. Table 9 compares the average quantum cost of three-qubit reversible circuits in cost115 metric using the proposed Negative NCT library after applying the proposed optimization algorithms (Algorithms 2 and 4) with the works found in the literature. Table 9 shows the average quantum cost of the Negative NCT library after applying the proposed modified circuit optimization algorithm (Algorithm 4) is 11.209, while the average quantum cost of the Negative NCT library after applying the proposed circuit optimization algorithm (Algorithm 2) is 11.333. The average quantum cost of the NCT library using the optimization algorithm in [15] is 12.591.
There is an inverse proportional relationship between the quantum cost and the number of ancillary qubits that are used by an algorithm to optimize a quantum circuit. The quantum cost obtained [17] is 10.69 in cost115 metric, which is less than the proposed method in this paper because this method uses a single ancillary qubit, while Algorithm 4 is applied without using any ancillary qubits.
The proposed approach uses negative control gates, which is more stable because it depends on the ground state of the quantum system, which will help in building real quantum computers because one of the biggest challenges in building practical quantum computers is the decoherence and the instability of the quantum system. Furthermore, the proposed algorithm produces low-cost quantum circuits, which will help in building stable medium scale and small scale quantum computers because it will help in making the computation perform faster to overcome the decoherence of the quantum system over a long period of time. Table 8. Comparing the quantum cost of the proposed Negative NCT library using the proposed optimization algorithms (Algorithms 2 and 4) with related work in cost015, where A 0 denotes the Negative NCT library's specification before optimization. A 1 and A 2 denote the number of specification with minimum quantum cost produced by the proposed circuit optimization algorithm (Algorithm 2) and the proposed modified circuit optimization algorithm (Algorithm 4), respectively. The NT denotes the number of specifications with minimum quantum cost shown in [18], NR 3 denotes the number of specifications with minimum quantum cost shown in [18], N M 3 denotes the number of specifications with minimum quantum cost shown in [19], and NCT denotes the number of specifications with minimum quantum cost shown in [15].