<<

S S symmetry

Article Optimization of Reversible Circuits Using Toffoli Decompositions with Negative Controls

Mariam Gado 1,2,* and Ahmed Younes 1,2,3

1 Department of Mathematics and Computer Science, Faculty of Science, Alexandria University, Alexandria 21568, Egypt; [email protected] 2 Academy of Scientific Research and Technology(ASRT), Cairo 11516, Egypt 3 School of Computer Science, University of Birmingham, Birmingham B15 2TT, UK * Correspondence: [email protected]; Tel.: +203-39-21595; Fax: +203-39-11794

Abstract: 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- reversible circuits. The first 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 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 form a permutation group of size 40,320 (23!), which

Citation: Gado, M.; Younes, A. is a subset of the symmetric group, where the NCT library is considered as the generators of the Optimization of Reversible Circuits permutation group. Using Toffoli Decompositions with Negative Controls. Symmetry 2021, 13, Keywords: reversible circuit optimization; NCT library; negative quantum library; quantum cost; 1025. https://doi.org/10.3390/ reversible circuit; Toffoli decomposition sym13061025

Academic Editor: Basil Papadopoulos and Sergei D. Odintsov 1. Introduction One of the problems in classical computers is heat dissipation and energy loss. Received: 2 May 2021 The amount of energy dissipated for any lost bit of information is calculated by R. Lan- Accepted: 1 June 2021 dauer’s principle, which is KTln2, where K is the Boltzmann’s constant (1.3807 10 23 JK 1) Published: 7 June 2021 × − − and T is the temperature of the system. Reversible has one of many features,

Publisher’s Note: MDPI stays neutral where no heat dissipation is produced by the system [1]; hence, no information is destroyed. with regard to jurisdictional claims in This feature has many applications [2], such as low-power CMOS [3], nanotechnology [4], published maps and institutional affil- DNA-based logic circuit with self error recovery capability employing massive paral- iations. lelism [5] and many more [6]. is reversible by nature [7]. Recently, using group theory in study- ing 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 in [10]. A relationship between the reversible logic synthesis problem and Young Copyright: © 2021 by the authors. Licensee MDPI, Basel, Switzerland. subgroups is introduced in [11]. A reversible gate is the basic building block of a reversible This article is an open access article circuit [3]. Quantum gates are reversible gates/functions, which are considered as a special distributed under the terms and case of symmetry groups of finite spaces (Young subgroups) [10]. Many methods have conditions of the Creative Commons been proposed to optimize the quantum cost of circuits [12,13]. The quantum cost of the Attribution (CC BY) license (https:// NCT library is reduced in [14]; a further reduction of the quantum cost of the NCT library creativecommons.org/licenses/by/ is made in [15]. The in [16,17] use an ancillary qubit to achieve less quantum 4.0/). cost. Universal reversible gate libraries are proposed in [18–20], which use GAP-based

Symmetry 2021, 13, 1025. https://doi.org/10.3390/sym13061025 https://www.mdpi.com/journal/symmetry Symmetry 2021, 13, 1025 2 of 23

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 , which can be positive or negative. The positive control is applied if the system is in the , whereas the negative control is applied if the system is in the . 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–26]. The paper has two aims: the first aim of this paper is to propose an 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: Section2 gives a brief introduction to elementary quantum gates used to build quantum circuits, permutation group, definitions and ter- minologies used in this paper. Section3 introduces the proposed library and proposed synthesis algorithm. Section4 shows the experimental results. The paper concludes in Section5.

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

2.1. Reversible Boolean Function A Boolean function f with n inputs and n outputs f : Xn Xn is considered to be → reversible if and only if each input vector x Xn is mapped to a unique output vector ∈ y Xn where X = 0, 1 . For n inputs there are 2n! different reversible Boolean functions, ∈ { } for n = 3 there is 23! = 40,320 3-input/output reversible Boolean functions. Given a finite set A = 1, 2, ... , 2n , α 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).

1 2 3 2n α = ··· (1) α(1) α(2) α(3) α(2n)  ···  The top row is ordered so that it can be eliminated, so α can be written as in (2).

α = α(1) α(2) α(3) α(2n) (2) ··· The permutation can also be represented as a product of disjoint cycles. For example, 1 2 3 4 5 6 7 8 can be written as (1, 4, 3)(6, 8). 4 2 1 3 5 8 7 6   2.2. Reversible 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 β | i | i | i are complex numbers that satisfy the condition α 2 + β 2 = 1. The measurement of ψ | | | | | i 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 | i (1+i) 0 +(1 i) 1 | i α is 0, the third state is + where + = | i − | i and the fourth state is where | i | i √2 |−i (1 i) 0 +(1+i) 1 = − | i | i . |−i √2 Symmetry 2021, 13, 1025 3 of 23

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

2.3.1. 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 | i | i | i and vice versa. The superscript of N gate is 3 when N gate is applied on a three-qubit |−i reversible circuit (N3) and the subscript of N gate refers to a specific qubit that NOT gate 3 is applied on. For example, N2 applies a NOT gate on the second qubit in a three-qubit reversible circuit. Table1 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 Figure1a with the following permutations in (3):

N3 : (x , x , x ) (x 1, x , x ) 1 1 2 3 → 1 ⊕ 2 3 = (1, 5)(2, 6)(3, 7)(4, 8), 3 N : (x1, x2, x3) (x1, x2 1, x3) 2 → ⊕ (3) = (1, 3)(2, 4)(5, 7)(6, 8), N3 : (x , x , x ) (x , x , x 1) 3 1 2 3 → 1 2 3 ⊕ = (1, 2)(3, 4)(5, 6)(7, 8).

Square-root of NOT gate (v): A reversible gate that maps 0 to + , 1 to , + | i | i | i |−i | i to 1 , and to 0 . | i |−i | i Square-root of NOT gate (v†): A reversible gate that maps 0 to , 1 to + , + | i |−i | i | i | i to 0 and to 1 . | i |−i | i 2.3.2. 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, | i | i 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 | i 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–26].

2.3.3. 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. Controlled NOT gate(CNOT/C): A two-qubit gate, which has two versions: positive CNOT (CNOT) and negative CNOT (OCNOT). In the CNOT gate and OCNOT gate, if the control qubit’s state is 1 and 0 , respec- | i | i tively, 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 three- qubit reversible circuit (C3). The subscript of C3 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 3 side represents the target qubit. For example, C12 represents the CNOT gate with a positive control on the first qubit and a target on the second qubit; C3 represents the OCNOT gate 12 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 Table1. There are six possible gates for the CNOT gate for three-qubit reversible circuits as shown in Figure1b. The truth table of the OCNOT gate is shown in Table1. There are six possible gates of the OCNOT gate for three-qubit reversible circuits as shown in Figure1c with the following permutations in (4):

C3 : (x , x , x ) (x , x x , x ) = (1, 3)(2, 4), 12 1 2 3 → 1 2 ⊕ 1 3 C3 : (x , x , x ) (x , x , x x ) = (1, 2)(3, 4), 13 1 2 3 → 1 2 3 ⊕ 1 3 C : (x1, x2, x3) (x1 x2, x2, x3) = (1, 5)(2, 6), 21 → ⊕ (4) C3 : (x , x , x ) (x , x , x x ) = (1, 2)(5, 6), 23 1 2 3 → 1 2 3 ⊕ 2 C3 : (x , x , x ) (x , x x , x ) = (1, 3)(5, 7), 32 1 2 3 → 1 2 ⊕ 3 3 C3 : (x , x , x ) (x x , x , x ) = (1, 5)(3, 7). 31 1 2 3 → 1 ⊕ 3 2 3 Version June 2, 2021 submitted to Journal Not Specified 5 of 25 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, | i | i then the v gate is applied to the target qubit and the control qubit’s state remains unchanged; 1h. The truth tableotherwise of Toffoli it does and nothing. OToffoli gates are shown in Table1. The following OToffoli permutationsControlled- are introducedV†: A in two-qubit (5): gate that has two versions: positive V† (CV†) and neg- ative V† (OV†). In the CV† gate and OV† gate, if the control qubit’s state is 1 and 0 , T3 : (x , x , x ) †(x , x , x x x ) = (1, 2), | i | i respectively,123 1 then2 3 the→v gate1 2 is3 applied⊕ 1 2 to the target qubit and the control qubit’s state remains3 unchanged; otherwise it does nothing. T : (x1, x2, x3) (x1, x2 x1x3, x3) = (1, 3), (5) 132 → ⊕ † † The3 truth table of the CV, CV , OV and OV gates are shown in Table1. There are T : (x , x , x ) (x x x , x , x ) = (1, 5). † six possible231 1 gates2 3 for→ the OV1 ⊕ gate2 3 and2 six3 possible gates of the OV gate for three-qubit reversible circuits as shown in Figure1d,e, respectively.

3 3 3 N1 N2 N3 (a) NOT Gates

• • • • 3 3 3 3 •3 •3 C3 C3 C3 C3 C3 C3 C12 C13 C21 C23 C32 C31 12 13 21 23 32 31

(b) CNOT Gates (c) OCNOT Gates

† † V V V V V V V† V† V V V† V† V12 V13 V21 V23 V32 V31 V† V† V† V† V† V† 12 13 21 23 32 31

(d) OV Gates (e) OV† Gates

• • • • • • T3 T3• T3 3 3• •3 T3 T3 T3 123 132 231 T123 T132 T231 123 132 231 (h) Some Mixed Polarity (f) Toffoli Gates (g) OToffoli Gates Toffoli Gates Figure 1. The possible gates for 3-qubit reversible circuits. Figure 1. The possible gates for three-qubit reversible circuits. 138

139 3.0.3. Quantum Cost of a Reversible Circuit

140 The quantum cost of a reversible circuit, which is denoted by Q.C in this paper is

141 the count of the one-qubit and the two-qubit elementary gates in the decomposition of

142 the circuit.

143

144 In this paper, two methods for calculating the quantum cost will be used: the

145 cost015 metric [29] and cost115 metric [30]. In the cost015 metric: the quantum cost of

146 a one-qubit gate is 0, two-qubit gate is 1 and three-qubit gate is 5 [31]. In the cost115

147 metric: the quantum cost of a one-qubit gate is 1, two-qubit gate is 1 and three-qubit

148 gate is 5.

149 3.0.4. Optimization Rules of Quantum Gates: Moving, Merging and Splitting

150 For a 3-qubit quantum circuit with a set of W = 1, 2, 3 , where the first qubit { } 151 is 1, the second qubit is 2 and the third qubit is 3. Let K12 be any two-qubit gate whose 152 control qubit is negative on qubit 1 and its target qubit is on qubit 2, where 1 = 2 = 3. 6 6 153

154 Table2 shows the moving rules where a gate can be swapped with its adjacent 3 155 gate. For example, one-qubit NOT gate N1 that acts on the first qubit can be swapped Symmetry 2021, 13, 1025 5 of 23

Table 1. The Truth table of NOT, CNOT, OCNOT CV, CV†, OV, OV†, Toffoli and OToffoli gates for three-qubit system.

NOT gate (N3) Input Output 0 1 | i | i 1 0 | i | i CNOT OCNOT Input Output Input Output 00 00 00 01 | i | i | i | i 01 01 01 00 | i | i | i | i 10 11 10 10 | i | i | i | i 11 10 11 11 | i | i | i | i CV(PositiveV) CV†(PositiveV†) Input Output Input Output 00 00 00 00 | i | i | i | i 01 01 01 01 | i | i | i | i 10 1+ 10 1 | i | i | i | −i 11 1 11 1+ | i | −i | i | i OV(NegativeV) OV†(NegativeV†) Input Output Input Output 00 0+ 00 0 | i | i | i | −i 01 0 01 0+ | i | −i | i | i 10 10 10 10 | i | i | i | i 11 11 11 11 | i | i | i | i Toffoli OToffoli Input Output Input Output 000 000 000 001 | i | i | i | i 001 001 001 000 | i | i | i | i 010 010 010 010 | i | i | i | i 011 011 011 011 | i | i | i | i 100 100 100 100 | i | i | i | i 101 101 101 101 | i | i | i | i 110 111 110 110 | i | i | i | i 111 110 111 111 | i | i | i | i

2.3.4. 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 : 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, | i | i 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 (T3). The subscript of T3 gate consists of three adjacent numbers: the first two numbers starting from the left-hand side indicate the control qubits and the number 3 on the right-hand side indicates the target qubit. For example, T123 represents the Toffoli gate with positive control qubits. T3 represents the OToffoli gate with negative control 132 qubits. T3 and T3 represent the Mixed Control Toffoli gates with mixed control qubits. 132 231 Symmetry 2021, 13, 1025 6 of 23

There are three possible gates for a Toffoli gate for three-qubit reversible circuits as shown in Figure1f. There are three possible gates for an OToffoli gate for three-qubit reversible circuits as shown in Figure1g. Some examples of Mixed Control Toffoli gates are shown in Figure1h. The truth table for the Toffoli and OToffoli gates are shown in Table1. The following OToffoli permutations are introduced in (5):

T3 : (x , x , x ) (x , x , x x x ) = (1, 2), 123 1 2 3 → 1 2 3 ⊕ 1 2 T3 : (x , x , x ) (x , x x x , x ) = (1, 3), (5) 132 1 2 3 → 1 2 ⊕ 1 3 3 T3 : (x , x , x ) (x x x , x , x ) = (1, 5). 231 1 2 3 → 1 ⊕ 2 3 2 3 2.3.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.

2.3.6. 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 K12 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. 6 6 Table2 shows the moving rules where a gate can be swapped with its adjacent gate. 3 For example, the one-qubit NOT gate N1 that acts on the first qubit can be swapped with 3 its adjacent one-qubit gate that acts on any of the other two qubits; the N1 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 N3 acts on; in this case N3 can be swapped with C3 , C3 , OV , 1 1 21 31 21 OV , OV† , OV† , C3 , C3 ,OV , OV , OV† and OV† . Adjacent two-qubit gates can be 31 21 31 23 32 23 32 23 32 swapped if they have the same control qubit or if they have the same target qubit. For example, C3 can be swapped with C3 , C3 , OV , OV , OV† and OV† . 23 13 21 13 21 13 21 Table3 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 C3 are merged to form OV† . Furthermore, 12 12 12 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, C3 OV can be merged to form a two-qubit gate [C3 OV ]. In this paper, 12 21 12 21 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–18,21].

Table 2. The moving rules of quantum gates.

Gate Swappable Gates 3 3 3 N1 N2 , N3 , K2,3, K2,1, K3,2, K3,1 3 3 K1,2 N2 , N3 , K1,3, K3,2 Symmetry 2021, 13, 1025 7 of 23

Table 3. The merging rules of quantum gates.

Gates before Optimization Gates after Optimization N3N3, C3 C3 I 1 1 1,2 1,2 OV OV† , OV† OV I 1,2 1,2 1,2 1,2 OV OV , OV† OV† C3 1,2 1,2 1,2 1,2 1,2 OV C3 , C3 OV OV† 1,2 1,2 1,2 1,2 1,2 OV† C3 , C3 OV† OV 1,2 1,2 1,2 1,2 1,2 K1,2K2,1 [K1,2K2,1]

3. 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 cir- cuits 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 Section2. 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.

3.1. Gate Decomposition

Definition 2. Gate symbol Lnum is a unique symbol that refers to a gate where num is an in- teger number. For example, L1 and L23. Table4 shows the gates with their corresponding gate symbol (sym.).

Table 4. Negative NCT gates with their corresponding gate symbol.

Gate Gate Sym. Gate Gate Sym. Gate Gate Sym. Gate Gate Sym.

T3 L C3 L C3 L N3 L 123 1 12 22 23 25 1 13 T3 L C3 L C3 L N3 L 132 2 13 23 32 26 2 14 T3 L C3 L C3 L N3 L 231 3 21 24 31 27 3 15

The decomposition (Lnum)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, (L2)0 represents the gate symbol L2 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. Table5 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. Figures2–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. Version June 2, 2021 submitted to Journal Not Specified 8 of 25 Version June 2, 2021 submitted to Journal Not Specified 8 of 25

198 Table5 shows the Negative NCT gates with their corresponding decomposition(s)

199198 whereTable each5 one-qubitshows the gate Negative or two-qubit NCT gates gate with has their only corresponding one decomposition decomposition(s) which is the † 200199 gatewhere itself, each while one-qubit each three-qubitgate or two-qubit gate can gate be has decomposed only one decomposition using (NOT, CNOT, whichV is, V the) † 201200 gatesgate itself, as shown while to each be optimal three-qubit [31]. gate Thecan three-qubit be decomposed gate has using eight different(NOT, CNOT, decomposi-V, V )

202201 tions.gates as Figure shown2, Figure to be3 optimal and Figure [31].4 The show three-qubit the eight different gate has eight decompositions different decomposi- for each

203202 OToffolitions. Figure gate2 which, Figure depend3 and Figure on the4 Toffolishow the decomositions eight different in decompositions[22]. This paper for uses each only

204203 negativeOToffolicontrol gate which decompositions, depend on the while Toffoli [22] decomositions uses only positive in [22control]. This decompositions. paper uses only Symmetry 2021, 13, 1025 8 of 23 204 negative control decompositions, while [22] uses only positive control decompositions.

V V† V V V† V V† V V† V† V V† † † † † † † DecompV . (LV1)0 V V (LV1)1 V V (L1V)2 V V (L1V)3 V Decomp. (L1)0 (L1)1 (L1)2 (L1)3 (a) (a)

V V† V V V† V V† V V† V† V V† † † † † † † DecompV . (LV1)4 V V (LV1)5 V V (L1V)6 V V (L1V)7 V Decomp. (L1)4 (L1)5 (L1)6 (L1)7 (b) Figure 2. Decompositions (Decomp.) of T3 where in (a) the first control qubit is on qubit 1 and 123 (b) theFigure second 2. Decompositions control qubit is on(Decomp.) qubit 2, and of T in3 (b)where the first in (a) control the first qubit control is on qubit qubit is2 and on qubit the second1 and Figure 2. Decompositions (Decomp.) of T1233 where in (a) the first control qubit is on qubit 1 and controlthe second qubit control is on qubit qubit1 is. These on qubit decompositions2, and in123 (b) the are first the negative control qubitdecompositions is on qubit 2 whichand the are second based the second control qubit is on qubit 2, and in (b) the first control qubit is on qubit 2 and the second oncontrol the positive qubit isdecompositions on qubit 1. These in decompositions [22]. are the negative decompositions which are based control qubit is on qubit 1. These decompositions are the negative decompositions, which are based on the positive decompositions in [22]. on the positive decompositions in [21].

V V† V V V† V V† V V† V† V V† V V† V V V† V V† V V† V† V V†

Decomp. (L2)0 (L2)1 (L2)2 (L2)3 Decomp. (L2)0 (L2)1 (L2)2 (L2)3 (a) (a)

V V† V V V† V V† V V† V† V V† V V† V V V† V V† V V† V† V V†

Decomp. (L2)4 (L2)5 (L2)6 (L2)7 Decomp. (L2)4 (L2)5 (L2)6 (L2)7 (b) Figure 3. Decompositions (Decomp.) of T3 where in (a) the first control qubit is on qubit 1 and Figure 3. Decompositions (Decomp.) of T1323 where(b) in (a) the first control qubit is on qubit 1 and theFigure second 3. Decompositions control qubit is on(Decomp.) qubit 3, and of T in3132 (b)where the first in (a) control the first qubit control is on qubit qubit is3 and on qubit the second1 and the second control qubit is on qubit 3, and132 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 controlthe second qubit control is on qubit is1. on These qubit decompositions3, and in (b) the are first the control negative qubit decompositions, is on qubit 3 and which the secondare based on the positive decompositions in [22]. oncontrol the positive qubit is ondecompositions qubit 1. These in decompositions [21]. are the negative decompositions which are based on the positive decompositions in [22]. 205 5.0.1. Right and Left Gate Sets of a Decomposition Table 5. Negative NCT gates with their equivalent gate decomposition (Decomp.). 206205 Definition5.0.1. Right 6. andThe Left ordered Gate Sets pair of of a a Decomposition gate (OP) is an ordered pair that contains the control

207 qubitGate and the Gate target Decomposition qubit of a gate (control qubit, target qubit). 206 Definition 6. The ordered pair of a gate (OP−) is an ordered− pair that contains the control 3 207 qubitT and theL target, L qubit, L of, aL gate, L(control, L , Lqubit,,Ltarget qubit). 123 (1)0 (1)1 (1)2 (1)3 (1)4 (1)−5 (1)6 (1)7 − T3 L , L , L , L , L , L , L , L 132 (2)0 (2)1 (2)2 (2)3 (2)4 (2)5 (2)6 (2)7 T3 L , L , L , L , L , L , L , L 231 (3)0 (3)1 (3)2 (3)3 (3)4 (3)5 (3)6 (3)7 Gate Gate Decomp. Gate Gate Decomp. Gate Gate Decomp. C3 L C3 L N3 L 12 (22)0 23 (25)0 1 (13)0 C3 L C3 L N3 L 13 (23)0 32 (26)0 2 (14)0 C3 L C3 L N3 L 21 (24)0 31 (27)0 3 (15)0 Version June 2, 2021 submitted to Journal Not Specified 9 of 25

208 An example of an OP for 3-qubit system is (1, 3), where the control is on the first 3 3 † † 209 qubit and the target is on the third qubit. C , C , V , V , V and V are some 13 12 13 13 13 13 210 examples of gates in which their OP is (1, 3).

211 Definition 7. The sets rg and lg of a circuit are the sets that contain the OP of the

212 right-hand side gate and left-hand side gate respectively.

213 The rg set or the lg set contains ordered pairs with the same control qubit or the

214 same target qubit; otherwise the rg set or the lg set contains one OP element only. An

215 example of the rg set of (L ) gate in Figure 2a is (1, 3), (1, 2) , where the two ordered 1 0 { } 216 pairs in the rg set have the same control qubit in this example and the lg set of (L1)0 gate 217 is (2, 3) . Another example of the rg set of (L ) gate in Figure 3b is (1, 2) and the { } 2 5 { } Symmetry 2021, 13, 1025 218 lg set of (L ) gate is (3, 2), (3, 1) , where the two ordered pairs in the lg set have the9 of 23 2 5 { } 219 same target qubit in this example.

V V† V V V† V V† V V† V† V V†

Decomp. (L3)0 (L3)1 (L3)2 (L3)3

(a)

V V† V V V† V V† V V† V† V V†

Decomp. (L3)4 (L3)5 (L3)6 (L3)7

(b) Figure 4. Decompositions (Decomp.) of T3 where in (a) the first control qubit is on qubit 2 and Figure 4. Decompositions (Decomp.) of T2313 where in (a) the first control qubit is on qubit 2 and the second control qubit is on qubit 3, and in231 (b) the first control qubit is on qubit 3 and the second 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 2. These decompositions are the negative decompositions which are based control qubit is on qubit 2. These decompositions are the negative decompositions, which are based on the positive decompositions in [22]. on the positive decompositions in [21].

RightTable and 5: LeftNegative Gate NCTSets of gates a Decomposition with their equivalent gate decomposition (Decomp.).

Definition 3. TheGate ordered Gate pair of Decomposition a gate (OP) is an ordered pair that contains the control qubit and the target qubit of a gate (control qubit, target qubit). T3 L , L −, L , L , L − , L , L , L 123 (1)0 (1)1 (1)2 (1)3 (1)4 (1)5 (1)6 (1)7 T3 L , L , L , L , L , L , L , L An example of132 an OP for(2)0 a three-qubit(2)1 (2)2 system(2)3 (2 is)4 (1,(2 3))5, where(2)6 the(2)7 control is on the first 3 3 3 † † qubit and the targetT is on theL(3) third0 , L(3) qubit., L(3)2C, L(3,)C3 , L,(3V) , ,LV(3)5,,VL(3)and6 , L(3V)7 are some examples 231 1 13 13 134 13 13 13 of gates in whichGate their OP Gateis (1, 3). Gate Gate Gate Gate Decomp. Decomp. Decomp. Definition 4. The sets rg and lg of a circuit are the sets that contain the OP of the right-hand side C3 L C3 L N3 L gate and left-hand side12 gate,(22 respectively.)0 23 (25)0 1 (13)0 C3 L C3 L N3 L 13 (23)0 32 (26)0 2 (14)0 C3 L C3 L N3 L The rg set or21 the lg set(24) contains0 ordered31 ( pairs27)0 with the3 same(15 control)0 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 (L1)0 gate in Figure2a is (1, 3), (1, 2) , where the two ordered pairs in the 220 Each decomposition of the OToffoli{ gates contains} two gate sets; the rg set and the rg set have the same control qubit in this example and the lg set of (L1)0 gate is (2, 3) . 221 lg set where each of these sets contains OP elements, the OP of a gate is concerned{ with } Another example of the rg set of (L2)5 gate in Figure3b is (1, 2) and the lg set of (L2)5 222 the control qubit and the target qubit only, and it does not{ concern} with the condition gate is (3, 2), (3, 1) , where the two ordered pairs in the lg set have the same target qubit 223 on the control{ qubit} nor the functionality of the gate itself. The rg set and the lg set of in this example. 224 a decomposition contain the OP of the gate on the right-hand side and the left-hand Each decomposition of the OToffoli gates contains two gate sets; the rg set and the 225 side respectively. For example, (L1) decomposition which is shown in Figure 2a has a lg set where each of these sets contains0 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, (L1)0 decomposition, which is shown in Figure2a has a left- hand side gate, which is V23, 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 ) is (2, 3) , if V gate and its next gate can be swapped, then the OP of the V next 1 0 { } 23 23 gate can also be added to the lg set; C3 cannot be swapped with V ; hence, the lg set for 12 23 this decomposition remains unchanged. The right-hand side gate in (L1)0 decomposition is V where this gate’s OP is (1,3); hence, the rg set of (L ) is (1, 3) if the V gate and 13 1 0 { } 13 its prior gate can be swapped then the OP of V13 gate’s prior gate can be added to the rg set; C3 can be swapped with V ; hence, the rg set is updated to (1, 3), (1, 2) . 12 13 { } In two-qubit gates, the rg set = the lg set = the OP of the gate. Table6 shows the Negative NCT gates that have corresponding lg and rg sets. Symmetry 2021, 13, 1025 10 of 23

Table 6. Negative NCT gate decomposition with their corresponding lg and rg sets.

Gate Decomposition lg Set rg Set L ,L (2, 3) (1, 2), (1, 3) (1)0 (1)2 { }{ } L ,L (1, 2), (1, 3) (2, 3) (1)1 (1)3 { }{ } L ,L (1, 3) (2, 1), (2, 3) (1)4 (1)6 { }{ } L ,L (2, 1), (2, 3) (1, 3) (1)5 (1)7 { }{ } L ,L (3, 2) (1, 2), (1, 3) (2)0 (2)2 { }{ } L ,L (1, 2), (1, 3) (3, 2) (2)1 (2)3 { }{ } L ,L (1, 2) (3, 1), (3, 2) (2)4 (2)6 { }{ } L ,L (3, 1), (3, 2) (1, 2) (2)5 (2)7 { }{ } L ,L (3, 1) (2, 3), (2, 1) (3)0 (3)2 { }{ } L ,L (2, 3), (2, 1) (3, 1) (3)1 (3)3 { }{ } L ,L (2, 1) (3, 2), (3, 1) (3)4 (3)6 { }{ } L ,L (3, 2), (3, 1) (2, 1) (3)5 (3)7 { }{ } L (1, 2) (1, 2) (22)0 { }{ } L (1, 3) (1, 3) (23)0 { }{ } L (2, 1) (2, 1) (24)0 { }{ } L (2, 3) (2, 3) (25)0 { }{ } L (3, 2) (3, 2) (26)0 { }{ } L (3, 1) (3, 1) (27)0 { }{ }

3.2. Basic Pairs

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 L1L2 pair begins with the L1 gate, which has eight different decompositions as shown in Figure2, and the second gate is the L2 gate, which has eight different decompositions as shown in Figure3, 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 L1L2.

3.2.1. 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 Table3. 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 L1L2 pair has 64 different circuits to represent it. The basic pair with the least quantum cost of this pair is (L1)0(L2)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 and the LG set of L is (1, 2)(1, 3) according to Table6, then the final 1 2 { } quantum cost of this basic pair is 7 instead of 10. Figure5 shows the (L1)0(L2)1 basic Symmetry 2021, 13, 1025 11 of 23

pair where Figure5a shows the basic pair before optimization with a quantum cost of 10, the gate on the right-hand side of (L1)0 and the gate on the left-hand side of (L2)1 are marked with arrows. Figure5b shows the basic pair after swapping the marked gates, then the gates in the solid boxes are prepared for merging. Figure5c 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. Figure5d shows the basic pair after moving the marked gate to the right-hand side and marking the other resulting two-qubit gate. Version June 2, 2021 submitted to Journal Not Specified Figure5e shows the basic pair after moving the marked gate12 to of the 25 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].

V V† V V V† V

↑ ↑ (a)

V V† V V V† V

(b)

V† V† V V V† V†

↑ (c)

V† V V† V V† V†

↑ (d)

V† V V† V† V V†

(e)

Figure 5. (L1)0(L2)1 basic pair where (a) represents the basic pair before optimization with a Figure 5. (L1)0(L2)1 basic pair where (a) represents the basic pair before optimization with a quantum quantum cost of 10, (b) representscost of 10;( theb)represents basic pair the after basic swapping pair after theswapping two marked the two marked gates and gates the and the solid box shows solid box shows the gates whichthe gates will that be will merged, be merged; (c) represents (c) represents the the basic basic pair pair after after applying applying the the merging rules, where merging rules, where twotwo two-qubit two-qubit gates gates are are formed formed and and the the quantum quantum cost cost is is reduced reduced to to8;(8d,) (d) represents the basic pair represents the basic pair afterafter moving moving the the marked marked gate gate to the to the right-hand right-hand side and side marking and marking the other the resulting two-qubit gate; other resulting two-qubit gate,(e) represents and (e) represents the basic pair the after basic moving pair after the markedmoving gate the markedto the left-hand gate to side and applying the the left-hand side and applyingoptimization the optimization rules, where rules, the dashed where thebox dashed indicates box forming indicates a two-qubit forming gate a [15]; hence, the final two-qubit gate [16]; hence,quantum the final cost quantum is 7. cost is 7.

292 9.0.1. Build a Circuit with Basic Pairs th 293 Definition 10. The solitary gate of a gate is the gate in its 0 decomposition.

294 Basic pairs are concatenated to form circuits, the rg of the basic pair and the lg of 295 the next basic pair are called a "point of connection". For example, L2L27L1L2 circuit 296 consists of four gates, each two gates starting from the left-hand side are replaced with

297 their corresponding basic pair, so in this case the circuit consists of two basic pairs where 298 the first basic pair is (L2)4(L27)0 and the next basic pair is (L1)0(L2)1 as shown in Figure 299 7. Symmetry 2021, 13, 1025 12 of 23

Another example is L2L27, where L27 is a two-qubit gate, then it has only one decom- position (L27)0, choosing (L2)4 or (L2)6 will reduce the quantum cost of this basic pair to 4 instead of 6, where the rg of the (L2)4 gate matches the lg of the (L27)0 gate, while choosing (L2)0, (L2)1, (L2)2 or (L2)3 will reduce the quantum cost to 5 after optimization. Finally, choosing (L2)5 or (L2)7 will not reduce the quantum cost at all, a visual explanation of this example is shown in Figure6, where (L2)4(L27)0 and (L2)6(L27)0 have the least quantum cost but the basic pair of L2L27 circuit is (L2)4(L27)0 since the basic pair with lower decomposition number (num) is considered to be the basic pair for this pair as shown in Table7. 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. Table7 × shows the Negative NCT library’s basic pairs excluding basic pairs that contain NOT gates Version June 2, 2021 submitted to Journal Not Specified 13 of 25 and basic pairs in which both gates are OCNOT gates because there is no further reduction. Table7 also shows the quantum cost of the basic pair before and after optimization and its corresponding circuit.

V V† V V† V V†

(L2)4(L27)0 (L2)6(L27)0 Q.C = 4 Q.C = 4

(a)

V V† V V† V V†

(L2)0(L27)0 (L2)2(L27)0 Q.C = 5 Q.C = 5

(b)

V V† V V† V V†

(L2)1(L27)0 (L2)3(L27)0 Q.C = 5 Q.C = 5

(c) Figure 6. Possible basic pairs for L2L27 where the quantum cost is reduced. Q.C stands for Figure 6. Possible basic pairs for L2L27 where the quantum cost is reduced. Q.C stands for quantum quantum cost. (a) showscost; the (a) shows lowest the quantum lowest quantum cost of costL2 ofL27L2possibleL27 possible basic basic pairs pairs with with quantum quantum cost cost of 4;(b,c) of 4, (b) and (c) show showL2L27L2possibleL27 possible basic basic pairs pairs with with quantum quantum cost ofcost 5. of 5.

V V† V V† V V† V† V V† Point.o f .connection

Figure 7. Point of connection of basic| pairs{z (}L2)4(L27)0 and (L1)0(L2)1 in L2L27L1L2 circuit.

300 Let S be the total number of gates in a circuit; whether, S is even or odd determines

301 the number of basic pairs and solitary gates, which are used to build the circuit, where

302 the number of solitary gates in a circuit is 2. Two methods are going to be proposed in ≤ 303 the next sections in order to choose the basic pairs to reconstruct a circuit. Symmetry 2021, 13, 1025 13 of 23

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.

Negative NCT Library’s Basic Pairs That Include OCNOT or OToffoli Gates Pair of Gates Gate Decomposition/Basic Pair AO BO Basic Pair Circuit T3 T3 (L ) (L ) 7 10 V† V C3 [V† V† ]C3 V V† 123 132 1 0 2 1 13 23 12 23 32 13 32 12 T3 T3 (L ) (L ) 7 10 V† V C3 [V† V† ]C3 V V† 123 231 1 4 3 1 23 13 21 13 31 23 31 21 T3 C3 (L ) (L ) 4 6 V C3 V† V 123 12 1 0 22 0 23 12 23 13 T3 C3 (L ) (L ) 5 6 V C3 V† C3 V† 123 13 1 0 23 0 23 12 23 12 13 T3 C3 (L ) (L ) 4 6 V C3 V† V 123 21 1 4 24 0 13 21 13 23 T3 C3 (L ) (L ) 5 6 V C3 V† C3 V† 123 23 1 4 25 0 13 21 13 21 23 T3 C3 (L ) (L ) 5 6 V C3 V† C3 [V C3 ] 123 32 1 1 26 0 13 12 23 12 23 32 T3 C3 (L ) (L ) 5 6 V C3 V† C3 [V C3 ] 123 31 1 5 27 0 23 21 13 21 13 31 T3 T3 (L ) (L ) 7 10 V† V C3 [V† V† ]C3 V V† 132 123 2 0 1 1 12 32 13 32 23 12 23 13 T3 T3 (L ) (L ) 7 10 V† V C3 [V† V† ]C3 V V† 132 231 2 4 3 5 32 12 31 12 21 32 21 31 T3 C3 (L ) (L ) 5 6 V C3 V† C3 V† 132 12 2 0 22 0 32 13 32 13 12 T3 C3 (L ) (L ) 4 6 V C3 V† V 132 13 2 0 23 0 32 13 32 12 T3 C3 (L ) (L ) 5 6 V C3 V† C3 [V C3 ] 132 21 2 5 24 0 32 31 12 31 12 21 T3 C3 (L ) (L ) 5 6 V C3 V† C3 [V C3 ] 132 23 2 1 25 0 12 13 32 13 32 23 T3 C3 (L ) (L ) 5 6 V C3 V† C3 V† 132 32 2 1 26 0 12 13 32 13 32 T3 C3 (L ) (L ) 4 6 V C3 V† V 132 31 2 4 27 0 12 31 12 32 T3 T3 (L ) (L ) 7 10 V† V C3 [V† V† ]C3 V V† 231 123 3 0 1 5 21 31 23 31 13 21 13 23 T3 T3 (L ) (L ) 7 10 V† V C3 [V† V† ]C3 V V† 231 132 3 4 2 5 31 21 32 21 12 31 12 32 T3 C3 (L ) (L ) 5 6 V C3 V† C3 [V C3 ] 231 12 3 5 22 0 31 32 21 32 21 12 T3 C3 (L ) (L ) 5 6 V C3 V† C3 [V C3 ] 231 13 3 1 23 0 21 23 31 23 31 13 T3 C3 (L ) (L ) 5 6 V C3 V† C3 V† 231 21 3 0 24 0 31 23 31 23 21 T3 C3 (L ) (L ) 4 6 V C3 V† V 231 23 3 0 25 0 31 23 31 21 T3 C3 (L ) (L ) 4 6 V C3 V† V 231 32 3 4 26 0 21 32 21 31 T3 C3 (L ) (L ) 5 6 V C3 V† C3 V† 231 31 3 1 27 0 21 23 31 23 31 C3 T3 (L ) (L ) 4 6 V V† C3 V 12 123 22 0 1 1 13 23 12 23 C3 T3 (L ) (L ) 5 6 V† C3 V† C3 V 12 132 22 0 2 1 12 13 32 13 32 C3 T3 (L ) (L ) 5 6 [C3 V ]C3 V† C3 V 12 231 22 0 3 4 12 21 32 21 32 31 C3 C3 (L ) (L ) 1 2 [C3 C3 ] 12 21 22 0 24 0 12 21 C3 T3 (L ) (L ) 5 6 V† C3 V† C3 V 13 123 23 0 1 1 13 12 23 12 23 C3 T3 (L ) (L ) 4 6 V V† C3 V 13 132 23 0 2 1 12 32 13 32 C3 T3 (L ) (L ) 5 6 [C3 V ]C3 V† C3 V 13 231 23 0 3 0 13 31 23 31 23 21 C3 C3 (L ) (L ) 1 2 [C3 C3 ] 13 31 23 0 27 0 13 31 C3 T3 (L ) (L ) 4 6 V V† C3 V 21 123 24 0 1 5 23 13 21 13 C3 T3 (L ) (L ) 5 6 [C3 V ]C3 V† C3 V 21 132 24 0 2 4 21 12 31 12 31 32 C3 T3 (L ) (L ) 5 6 V† C3 V† C3 V 21 231 24 0 3 4 21 32 21 32 31 C3 C3 (L ) (L ) 1 2 [C3 C3 ] 21 12 24 0 22 0 21 12 C3 T3 (L ) (L ) 5 6 V† C3 V† C3 V 23 123 25 0 1 0 23 12 23 12 13 C3 T3 (L ) (L ) 5 6 [C3 V ]C3 V† C3 V 23 132 25 0 2 0 23 32 13 32 13 12 C3 T3 (L ) (L ) 4 6 V V† C3 V 23 231 25 0 3 1 21 31 23 31 C3 C3 (L ) (L ) 1 2 [C3 C3 ] 23 32 25 0 26 0 23 32 C3 T3 (L ) (L ) 5 6 [C3 V ]C3 V† C3 V 32 123 26 0 1 0 32 23 12 23 12 13 C3 T3 (L ) (L ) 5 6 V† C3 V† C3 V 32 132 26 0 2 0 32 13 32 13 12 C3 T3 (L ) (L ) 4 6 V V† C3 V 32 231 26 0 3 5 31 21 32 21 C3 C3 (L ) (L ) 1 2 [C3 C3 ] 32 23 26 0 25 0 32 23 C3 T3 (L ) (L ) 5 6 [C3 V ]C3 V† C3 V 31 123 27 0 1 4 31 13 21 13 21 23 C3 T3 (L ) (L ) 4 6 V V† C3 V 31 132 27 0 2 5 32 12 31 12 C3 T3 (L ) (L ) 5 6 V† C3 V† C3 V 31 231 27 0 3 0 31 23 31 23 21 C3 C3 (L ) (L ) 1 2 [C3 C3 ] 31 13 27 0 23 0 31 13

3.2.2. 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 L2L27L1L2 circuit Version June 2, 2021 submitted to Journal Not Specified 13 of 25

V V† V V† V V†

(L2)4(L27)0 (L2)6(L27)0 Q.C = 4 Q.C = 4

(a)

V V† V V† V V†

(L2)0(L27)0 (L2)2(L27)0 Q.C = 5 Q.C = 5

(b)

V V† V V† V V†

(L2)1(L27)0 (L2)3(L27)0 Q.C = 5 Q.C = 5

(c) Symmetry 2021, 13, 1025 14 of 23 Figure 6. Possible basic pairs for L2L27 where the quantum cost is reduced. Q.C stands for quantum cost. (a) shows the lowest quantum cost of L2L27 possible basic pairs with quantum cost consists of four gates, each two gates starting from the left-hand side are replaced with of 4, (b) and (c) showtheirL2 correspondingL27 possible basic basic pair, so pairs in this with case the quantum circuit consists cost of two of basic 5. pairs where the first basic pair is (L2)4(L27)0 and the next basic pair is (L1)0(L2)1 as shown in Figure7.

V V† V V† V V† V† V V† Point.o f .connection

Figure 7. Point of connection of basic pairs (L2)4(L27)0 and (L1)0(L2)1 in the L2L27L1L2 circuit. Figure 7. Point of connection of basic| pairs{z (}L2)4(L27)0 and (L1)0(L2)1 in L2L27L1L2 circuit. 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 300 Let S be the totalnumber number of solitary gates of gatesin a circuit in is a circuit;2. Two methods whether, are goingS tois be even proposed or in odd the determines ≤ next sections in order to choose the basic pairs to reconstruct a circuit. 301 the number of basic pairs and solitary gates, which are used to build the circuit, where

302 the number of solitary3.3. Circuit gates Optimizationin a circuit Algorithm is 2. Two methods are going to be proposed in ≤ 303 the next sections inDefinition order 8. toThe choose basic pair solitary the basic (BPS) quantum pairs cost to is reconstructthe summation of all a quantum circuit. costs of all basic pairs and solitary gates, which are used to build the circuit.

FunctionI (Algorithm1) is used by the proposed circuit optimization algorithm (Algorithm2) to reconstruct each circuit of the three-qubit system by using basic pairs of gates. In FunctionI (Algorithm1), the gates are paired starting from the left-hand side gate of the circuit. BasicPair(Ci, Ci+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(Ci) 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.

Algorithm 1 FunctionI (C) function if S = 1 then return (C) else if S = 1 6 then for i 0 to S/2 ← BasicPair(Ci, Ci+1) do O+ = BasicPair  i+ = 2 if S mod 2 = 1  then O+ = Solitary(CS) O = optimize(O) return (O)

Algorithm 2 Circuit Optimization (ONCT) procedure for each C ONCT ∈ do C = FunctionI(C) −

For example, the L22L1L3L1L22 circuit has a quantum cost of 17 and is translated to C3 T3 T3 T3 C3 , and this circuit consists of five gates (where S = 5), the reconstructed 12 123 231 123 12 Symmetry 2021, 13, 1025 15 of 23

circuit is paired from the left-hand side into two pairs L22L1 and L3L1 maintaining the Version June 2, 2021 submitted to Journal Not Specified order of pairs from left to right; these pairs are replaced with their corresponding17 of 25 basic pairs; (L22)0(L1)1 with a quantum cost of 4 and (L3)0(L1)5 with a quantum cost of 7 according to Table7, the gate on the right-hand side is L22 and it will be decomposed into its decomposition number 0 since S is odd, where (L22)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 349 Figure9 illustratesoptimizationL13L1L2 rulesL22L are13 thencircuit applied example on points before of connection and ofafter the reconstructed applying the circuit and 350 optimization rules in thethe final cost015 quantum metric, cost for the this dashed reconstructed box circuit indicates is 11. Figure forming8 shows a two-qubit the decomposition steps of the L22L1L3L1L22 circuit before and after applying the optimization rules. The 351 gate with a quantum cost of 1 [16]. dashed box in Figure8 refers to a two-qubit gate with a quantum cost of 1 [15].

V† V V†

V V† V V† V V† Basicpair1 Basicpair2 Solitarygate |{z} | {z } (a) | (b) {z }

V† V V†

V V† V V† V V†

(c) Figure 8. circuit where (a) represents the quantum circuit with a quantum cost of Figure 8. LThe22LL122LL31L31LL122L22 circuit where (a) represents the quantum circuit with a quantum cost of 17;(b) represents the 17,reconstructed (b) represents circuit the using reconstructed basic pairs of gates circuit and a usingsolitary basic gate with pairs a quantum of gates cost and of 12 a;(solitaryc) represents gate thewith quantum a quantumcircuit after cost applying of 12, the and optimization (c) represents rules and the forming quantum a two-qubit circuit gate. after The applyingfinal quantum the cost optimization after optimization rules is 11. and forming a two-qubit3.4. gate. Modified The final Circuit quantum Optimization cost Algorithm after optimization is 11. In Algorithm2, the optimization technique depends on FunctionI (Algorithm1). FunctionII (Algorithm3) splits the circuit into basic pairs starting from the second gate UNCTION Algorithm 11.3: F on the left-handII(C) 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 ≥ if S = 1 reconstructed as a solitary gate then basic pair(s) and finally a solitary gate. For example, then return (C) the L13L1L2L22L13 circuit has a quantum cost of 11, which can be reconstructed using else if S = 2 FunctionI (Algorithm1) which results in two basic pairs and one solitary gate on the right- hand side: (L13)0(L1)0 with a quantum cost of 5, (L2)0(L22)0 with a quantum cost of 5 and BasicPair(Ci, Ci+1) (L13)0 with a quantum cost of 0, the BPS quantum cost for this circuit using FunctionI then O+ = BasicPair  (Algorithm1) is 10; using FunctionII (Algorithm3) gives one solitary gate on the left-hand return (O) side and two basic pairs: (L13)0 with a quantum cost of 0, (L1)0(L2)1 with a quantum cost else if S > 2 of 7 and (L22)0(L13)0 with a quantum cost of 1, where the BPS quantum cost for this circuit 352  using FunctionII (Algorithm3) is 8, the latter function shows a better quantum cost for this O+ = Solitarycircuit(C0 and) the final quantum cost using FunctionII (Algorithm3) is 7 after applying the for i 1 tooptimizationS/2 rules on the points of connection instead of 11 in the cost015 metric as shown  ← then BasicPairin Figure(C9,.C )  i i+1  do O+ = BasicPairFigure9 illustrates the L13L1L2L22L13 circuit example before and after applying the   optimization rules in the cost015 metric, the dashed box indicates forming a two-qubit gate i+ =with2 a quantum cost of 1 [15].  if S mod 2 = 0   then O+ = Solitary(CS) O = optimize(O) return (O)

353

354 IBM Quantum Experience ibmq ourense system [32] has been used to implement − 355 L13L1L2L22L13 circuit, which permutation is (5, 8, 6). The ibmq ourense system has five − 3 356 qubits, Canary r2 , with average CNOT error of 8.750e− and average readout 2 † 357 error of 2.800e− . IBM Quantum Experience does not currently support Vab gate where 3 358 qubit a = qubit b, so this gate is replaced with V C gates since they are equivalent 6 ab ab 359 according to the splitting rules, which are the reverse of the merging rules in Table

360 3. IBM Quantum Experience does not also support negative control qubit, so positive

361 control qubit is used and NOT gates are added before and after each positive control

362 qubit in the quantum circuit as shown in Figure 10 since they are equivalent according

363 to [33]. Symmetry 2021, 13, 1025 16 of 23

Algorithm 3 FunctionII (C) function if S = 1 then return (C) else if S = 2 BasicPair(Ci, Ci+1) then O+ = BasicPair  return (O) else if S > 2 O+ = Solitary(C0) for i 1 to S/2  ← then BasicPair(C , C )  i i+1  do O+ = BasicPair   i+ = 2  if S mod 2 = 0   Version June 2, 2021 submitted to Journal Not Specified then O+ = Solitary(CS) 18 of 25 O = optimize(O) return (O)

(a)

V V† V† V V† V Basicpair1 Basicpair2 Solitarygate | {z } |{z} | {z }(b)

V† V V† V† V V† Solitarygate Basicpair1 Basicpair2 |{z} | {z } | {z } (c)

V† V V V† V V†

(d) Figure 9. L13L1L2L22L13 circuit where (a) represents the quantum circuit with a quantum cost of Figure 9. The L L L L L circuit where (a) represents the quantum circuit with a quantum cost 11, (b) represents the quantum circuit,13 which1 2 22 is13 reconstructed by using FunctionI 11.1 with a BPS of 11;(b) represents the quantum circuit, which is reconstructed by using FunctionI (Algorithm1) quantum cost of 10, (c) represents the quantum circuit, which is reconstructed by using FunctionII with a BPS quantum cost of 10;(c) represents the quantum circuit, which is reconstructed by using 11.3 with a BPS quantum cost of 8, and (d) represents the quantum circuit, which is reconstructed FunctionII (Algorithm3) with a BPS quantum cost of 8;(d) represents the quantum circuit, which is using FunctionII 11.3 after applying the optimization rules on the points of connection and the reconstructed using FunctionII (Algorithm3) after applying the optimization rules on the points of final quantum cost is 7. 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.

364 The reconstructed circuit L13L1L2L22L13, which is obtained from applying Function 365 11.3 is modified to be compatible with the ibmq ourense system by applying the − 366 splitting rules and the rule in Figure 10. The implementation of L13L1L2L22L13 circuit 367 on the ibmq ourense system has a quantum cost of 7 as shown in Figure 11, while the − 368 implementation of the equivalent quantum circuit, which permutation is (5, 8, 6) using

369 the NCT library has a quantum cost of 11 as shown in Figure 12. Version June 2, 2021 submitted to Journal Not Specified 18 of 25

(a)

V V† V† V V† V Basicpair1 Basicpair2 Solitarygate | {z } |{z} | {z }(b)

V† V V† V† V V† Solitarygate Basicpair1 Basicpair2 |{z} | {z } | {z } (c)

Symmetry 2021, 13, 1025 17 of 23

V† V V † V † V IBMV Quantum Experience ibmq ourense system [31] was used to implement the − L13L1L2L22L13 circuit, whose permutation was (5, 8, 6). The ibmq ourense system has − 3 five qubits,( ad Canary) r2 processor, with an average CNOT error of 8.750e− , and average 2 Figure 9. L13L1L2L22L13 circuit wherereadout (a) represents error of 2.800 the quantume− . The circuit IBM with Quantum a quantum Experience cost of does not currently support the V† gate where qubit a = qubit b, so this gate is replaced with V C3 gates since they 11, (b) represents the quantum circuit,ab which is reconstructed6 by using FunctionI 11.1 with a BPS ab ab quantum cost of 10, (c) representsare the quantum equivalent circuit, according which is to reconstructed the splitting by rules, using which FunctionII are the reverse of the merging rules 11.3 with a BPS quantum cost of 8in, and Table (d) represents3. The IBM the quantum Quantum circuit, Experience which is does reconstructed not also support the negative control using FunctionII 11.3 after applyingqubit, the so optimization the positive rules control on the qubit points is ofused connection and NOT and gates the are added before and after each final quantum cost is 7. positive control qubit in the quantum circuit as shown in Figure 10 since they are equivalent according to [32].

≡ • Figure 10. Preparing the gate forFigure IBM Quantum 10. Preparing Experience the gate implementation, for IBM Quantum where Experience a negative implementation, where a negative control Version June 2, 2021 submittedcontrol to isJournal equivalent Not Specifiedto adding NOTis equivalent gates before to andadding after NOT a positive gates beforecontrol. and after a positive control. 19 of 25

364 The reconstructed circuit L13L1TheL2L22 reconstructedL13, which is circuit obtainedL13 fromL1L2L applying22L13, which Function is obtained from applying FunctionII 365 11.3 is modified to be compatible(Algorithm with3 the) is modifiedibmq ourense to be compatiblesystem by with applying the ibmq the ourense system by applying the − − 366 splitting rules and the rule insplitting Figure 10 rules. The and implementation the rule in Figure of L 1310L.1 TheL2L22 implementationL13 circuit of the L13L1L2L22L13 circuit 367Versionon Junethe ibmq 2, 2021 submittedourense tosystemJournal Not hason Specified the a quantumibmq ourense cost of 7systemas shown has in a quantumFigure 11, cost while of the7 as shown in Figure 11,19 while of 25 the − − 368 implementation of the equivalentimplementation quantum circuit, of the which equivalent permutation quantum is circuit,(5, 8, 6) whoseusing permutation is (5, 8, 6) using the

369 the NCT library has a quantumNCT cost library of 11 as has shown a quantum in Figure cost 12 of. 11 as shown in Figure 12.

Figure 11. L L L L L circuit implementation on the ibmq ourense system, where the quan- 13 1 2 22 13 − tum cost of this circuit is 7. The solid box indicates merging the two gates to form V† gate, while Figure 11. The L13L1L2L22L13 circuit implementation on the ibmq ourense system, where the the dashed boxFigure indicates 11. L formingL L L L acircuit two-qubit implementation gate with on a quantumthe ibmq ourense cost of−system, 1 [16]. where the quan- quantum cost13 1 of2 this22 circuit13 is 7. The solid box indicates merging− the two gates to form V† gate; the tum cost of this circuit is 7. The solid box indicates merging the two gates to form V† gate, while dashed box indicates forming a two-qubit gate with a quantum cost of 1 [15]. the dashed box indicates forming a two-qubit gate with a quantum cost of 1 [16]. • • • • • • • •• • (a) (a)

(b) Figure 12. The equivalent(b) L13L1L2L22L13 circuit using the NCT library, where (a) represents the quantum circuit with a quantum cost of 11 and (b) represents the circuit implementation on the Figure 12. The equivalent L13L1L2L22L13 circuit using the NCT library, where (a) represents the ibmqFigureourense 12. Thesystem equivalent with aL quantum13L1L2L22 costL13 ofcircuit 11. using the NCT library, where (a) represents the quantum circuitquantum with− a circuit quantum with costa quantum of 11 and cost of (b)11 representsand (b) represents the circuit the circuit implementation implementation on on the the ibmq ourense370 ibmqsystemSomeourense with circuitssystem a quantum have with less a costquantum of 11. cost cost of if 11. they are reconstructed using FunctionI 11.1, − − 371 other circuits have less quantum cost if FunctionII 11.3 is used to reconstruct them. Some circuits have less quantum cost if they are reconstructed using FunctionI 370 Some372 circuitsThe Modified have less Circuit quantum Optimization cost if Algorithm they are reconstructed11.4 calculates the usingBPS FunctionIquantum cost 11.1, 373 for(Algorithm each circuit1), otherusing circuitsBPS(C) haveof FunctionI less quantum 11.1 and cost FunctionII if FunctionII 11.3 (Algorithm, then it chooses3) is used the to 371 other circuits have less quantum cost if FunctionII 11.3 is used to reconstruct them. 374 function,reconstruct which them. has less BPS quantum cost in order to reconstruct the quantum circuit, 372 The Modified Circuit Optimization Algorithm 11.4 calculates the BPS quantum cost 375 where m represents a mark to the function having less BPS quantum cost. 373 for each circuit using BPS(C) of FunctionI 11.1 and FunctionII 11.3, then it chooses the Algorithm 11.4: MODIFIED CIRCUIT OPTIMIZATION(ONCT) 374 function, which has less BPS quantum cost in order to reconstruct the quantum circuit,

375 where m represents a mark to the function having less BPS quantum cost. for each C ONCT ∈ Algorithm376 11.4: MmODIFIED= BPS(CC)IRCUIT OPTIMIZATION(ONCT) if m = 1  do  then C = FunctionI(C)  for each C ONCT else if m = 2 =∈ ( )then C = FunctionII(C) 376 m BPSC 377  if m = 1   378 For example, the L25L2L26L25 circuit, which is equivalent to (6, 7) permutation has do then C = FunctionI(C)  379 a quantum cost of 8. The BPS quantum cost for L L L L circuit using Function  25 2 26 25  380else11.1 if ism6=and2 the BPS quantum cost using Function 11.3 is 7, so Algorithm 11.4 chooses 381thenFunctionC = FunctionII 11.1 to decompose(C) the circuit, where the circuit is reconstructed using two basic  382 pairs which are (L25)0(L2)0 with a quantum cost of 5, followed by (L26)0(L25)0 with a 377   383 quantum cost of 1 according to [16]. The L25L2L26L25 circuit is shown in Figure 13 before 378 For384 example,optimization, the L25 afterL2L optimization26L25 circuit, and which the equivalent is equivalent circuit on to the(6,ibmq 7) permutationourense system has − 379 a quantum385 costafter ofusing8. the The splittingBPS quantum rules and the cost preparation for L25L of2Lnegative26L25 circuitgates as using shown Function in Figure 386 10. While the implementation of the equivalent L L L L quantum circuit, which 380 11.1 is 6 and the BPS quantum cost using Function 11.325 is 27,26 so25 Algorithm 11.4 chooses 387 permutation is (6, 7) using the NCT library on the ibmq ourense system has a quantum 381 Function 11.1 to decompose the circuit, where the circuit is reconstructed− using two basic 388 cost of 15 as shown in Figure 14. 382 pairs which are (L25)0(L2)0 with a quantum cost of 5, followed by (L26)0(L25)0 with a 383 quantum cost of 1 according to [16]. The L25L2L26L25 circuit is shown in Figure 13 before 384 optimization, after optimization and the equivalent circuit on the ibmq ourense system − 385 after using the splitting rules and the preparation of negative gates as shown in Figure 386 10. While the implementation of the equivalent L25L2L26L25 quantum circuit, which Symmetry 2021, 13, 1025 18 of 23

The modified circuit optimization algorithm (Algorithm4) calculates the BPS quantum cost for each circuit using BPS(C) of FunctionI (Algorithm1) and FunctionII (Algorithm3), 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.

Algorithm 4 Modified Circuit Optimization (ONCT) procedure for each C ONCT m =∈BPS(C) if m = 1  do  then C = FunctionI(C)   else if m = 2 then C = FunctionII(C)    For example, the L25L2L26L25 circuit, which is equivalent to the (6, 7) permutation has a quantum cost of 8. The BPS quantum cost for the L25L2L26L25 circuit using FunctionI (Algorithm1) is 6 and the BPS quantum cost using FunctionII (Algorithm3) is 7, so Algorithm4 chooses FunctionI (Algorithm1) to decompose the circuit, where the circuit is reconstructed using two basic pairs, which are (L ) (L ) with a quantum cost of 5, Version June 2, 2021 submitted to Journal Not Specified 25 0 2 0 20 of 25 followed by (L26)0(L25)0 with a quantum cost of 1 according to [15]. The L25L2L26L25 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 387 permutation is (6, 7) using the NCT library on the ibmq ourense system has a quantum L25L2L26L25 quantum circuit, whose permutation is (6, 7−) using the NCT library on the 388 cost of 15 as shown in Figure 14. ibmq ourense system has a quantum cost of 15 as shown in Figure 14. −

V V† V

(a) (b)

(c)

FigureFigure 13. 13.TheThe L25LL22LL2626LL2525circuit,circuit, where where (a) represents (a) represents the quantum the quantum circuit with circuit a quantum with a cost quantum of cost8,( ofb)8 represents, (b) represents the quantum the quantum circuit after circuit optimization after optimization with a quantum with cost a quantum of 6, and cost(c) represents of 6, and (c) the circuit implementation on the ibmq ourense system with a quantum cost of 6. The dashed box represents the circuit implementation on− the ibmq ourense system with a quantum cost of 6. The indicates forming a two qubit gate and the solid box− indicates forming V† gate. dashed box indicates forming a two qubit gate and the solid box indicates forming V† gate. 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]. • • (a)

(b) Figure 14. The equivalent L25L2L26L25 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. −

389 From the examples in Figure 13 and Figure 14, it is shown that the Negative NCT

390 library has less quantum cost for this example compared with the NCT library. Extending

391 the Negative NCT library for n-qubits, where n > 3 is achievable since higher order

392 gates can be decomposed into 3-qubit gates according to [31,34].

393 12. Experimental Results

394 This section describes the experiments on 3-qubit reversible circuits based on the

395 proposed Negative NCT library and compares the results with relevant libraries in

396 [17–20] and [16]. The Negative NCT library shows an average length as in the NCT

397 library which equals 5.86. The comparison includes the proposed Circuit Optimization

398 Algorithm 11.2 and the proposed Modified Circuit Optimization Algorithm 11.4.

399 Table8 compares the average quantum cost of 3-qubit reversible circuits in cost015

400 metric using the proposed Negative NCT library and the work in literature, where the

401 average quantum cost of the Negative NCT library after using the proposed optimization Version June 2, 2021 submitted to Journal Not Specified 20 of 25

387 permutation is (6, 7) using the NCT library on the ibmq ourense system has a quantum − 388 cost of 15 as shown in Figure 14.

V V† V

(a) (b)

(c)

Figure 13. The L25L2L26L25 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 Symmetry 2021, 13, 1025 − 19 of 23 dashed box indicates forming a two qubit gate and the solid box indicates forming V† gate.

• • • • • • (a)

(b) Figure 14. The equivalent L L L L circuit using the NCT library, where (a) represents the Figure 14. 25The2 26 equivalent25 L L L L circuit using the NCT library, where (a) represents the quantum circuit with a quantum cost of 15 and25 (b)2 represents26 25 the circuit implementation on 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. − ibmq ourense system with a quantum cost of 15. − 389 From the examples4. Experimental in Figure Results 13 and Figure 14, it is shown that the Negative NCT 390 library has less quantum cost for this example compared with the NCT library. Extending This section describes the experiments on three-qubit reversible circuits based on the 391 the Negative NCT library for n-qubits, where n > 3 is achievable since higher order proposed Negative NCT library and compares the results with relevant libraries in [15–19]. 392 gates can be decomposed into 3-qubit gates according to [31,34]. The Negative NCT library shows an average length as in the NCT library, which equals

393 12. Experimental5.86 Results. The comparison includes the proposed circuit optimization algorithm (Algorithm2) and the proposed modified circuit optimization algorithm (Algorithm4). 394 This section describes the experiments on 3-qubit reversible circuits based on the Table8 compares the average quantum cost of three-qubit reversible circuits in the 395 proposed Negative NCT library and compares the results with relevant libraries in cost015 metric using the proposed Negative NCT library and the works found in the 396 [17–20] and [16]. The Negative NCT library shows an average length as in the NCT literature, where the average quantum cost of the Negative NCT library after using the 397 library which equals 5.86. The comparison includes the proposed Circuit Optimization proposed modified circuit optimization algorithm (Algorithm4) is 10.078, while the av- 398 Algorithm 11.2 and the proposed Modified Circuit Optimization Algorithm 11.4. erage quantum cost of the Negative NCT library using the proposed circuit optimization 399 Table8 compares the average quantum cost of 3-qubit reversible circuits in cost015 algorithm (Algorithm2) is 10.202. Finally, the quantum cost of the Negative NCT library 400 metric using the proposed Negative NCT library and the work in literature, where the before optimization is 13.364. Table8 compares the obtained results with other libraries 401 average quantum cost of the Negative NCT library after using the proposed optimization 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]. Table9 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 (Algorithms2 and4) with the works found in the literature. Table9 shows the average quantum cost of the Negative NCT library after applying the proposed mod- ified circuit optimization algorithm (Algorithm4) is 11.209, while the average quantum cost of the Negative NCT library after applying the proposed circuit optimization algo- rithm (Algorithm2) 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 Algorithm4 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. Symmetry 2021, 13, 1025 20 of 23

Table 8. Comparing the quantum cost of the proposed Negative NCT library using the proposed optimization algorithms (Algorithms2 and4) with related work in cost015, where A0 denotes the Negative NCT library’s specification before optimization. A1 and A2 denote the number of specification with minimum quantum cost produced by the proposed circuit optimization algorithm (Algorithm2) and the proposed modified circuit optimization algorithm (Algorithm4), respectively. The NT denotes the number of specifications with minimum quantum cost shown in [18], NR3 denotes the number of specifications with minimum quantum cost shown in [18], NM3 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].

3 3 Minimum Cost NT [18] NR [18] NM [19] NCT [15] A0 A1 Algorithm2 A2 Algorithm4 0 8 8 8 8 8 8 8 1 0 0 0 48 48 109 111 2 0 0 0 324 189 488 459 3 0 0 0 607 402 467 459 4 0 192 192 601 465 604 705 5 94 0 0 1148 240 1319 1492 6 0 0 0 2462 366 2605 2594 7 0 851 2136 3576 1386 3204 3338 8 16 2591 1300 2710 3087 3844 4358 9 340 0 0 2855 2921 4159 4115 10 288 636 0 5601 537 4733 4408 11 32 6050 11,916 6567 1255 4342 4175 12 179 9354 4064 3183 4563 4184 4184 13 790 396 0 2043 7305 3693 3741 14 1487 2829 3294 3771 3141 2801 2711 15 324 7175 7242 3496 447 1488 1373 16 574 6331 6137 1284 2178 1020 983 17 2052 344 0 36 4819 680 648 18 3616 1200 1117 0 3809 280 240 19 1462 1278 1484 0 574 128 83 20 1041 1053 1387 0 501 79 66 21 3405 9 0 0 1185 57 48 22 5357 14 0 0 614 25 18 23 2894 2 0 0 37 3 3 24 1435 7 43 0 0 0 0 25 3191 0 0 0 149 0 0 26 4369 0 0 0 86 0 0 27 2436 0 0 0 4 0 0 28 806 0 0 0 0 0 0 29 1444 0 0 0 0 0 0 30 1482 0 0 0 4 0 0 31 761 0 0 0 0 0 0 32 125 0 0 0 0 0 0 33 126 0 0 0 0 0 0 34 109 0 0 0 0 0 0 35 60 0 0 0 0 0 0 36 6 0 0 0 0 0 0 Avg 22.321 13.388 13.290 10.348 13.364 10.202 10.078 Symmetry 2021, 13, 1025 21 of 23

Table 9. Comparing the quantum cost of the proposed Negative NCT library using the proposed optimization algorithms (Algorithms2 and4) with related work in cost115, where B1, B2 denotes the number of specification with minimum quantum cost produced by the proposed circuit optimization algorithm (Algorithm2) and the proposed modified circuit optimization algorithm (Algorithm4), respectively. The NCT denotes the number of specifications of the NCT library with minimum quantum cost shown in [15].

Minimum Cost NCT [15] B1 Algorithm2 B2 Algorithm4 0 0 0 0 1 9 18 18 2 72 133 130 3 299 428 400 4 551 545 564 5 519 720 803 6 728 1334 1430 7 1715 2256 2371 8 2976 3315 3385 9 3060 3867 4064 10 2366 4099 4322 11 2923 4256 4110 12 4417 4336 4150 13 4717 4018 3918 14 3513 3625 3656 15 2637 2803 2777 16 2385 1711 1607 17 2260 1142 1046 18 2021 752 738 19 1543 464 427 20 994 225 191 21 474 127 91 22 130 73 67 23 10 47 32 24 0 20 17 25 0 4 4 26 0 1 1 Avg 12.591 11.333 11.209

5. Conclusions This paper proposed two algorithms (The circuit optimization algorithm and the modified circuit optimization algorithm), both of which use basic pairs as building blocks to reconstruct the circuit, choosing between the two proposed pairing functions (FunctionI and FunctionII) depending on the nature of the circuit; both show better results compared to reconstructing the circuit with a fixed pairing function regardless of the nature of the circuit as in the modified circuit optimization algorithm and the circuit optimization algorithm, respectively. The modified circuit optimization algorithm is applied to the Negative NCT library with an average quantum cost of 11.209 in cost115 metric and 10.078 in cost015 metric without using any ancillary qubits. The paper also proposed optimization methods for the quantum cost of the three- qubit reversible circuit using Negative NCT library. The proposed method was compared with related optimization methods from the literature and the comparisons show that the average minimum cost of the proposed Negative NCT library is 10.078 in the cost015 metric and 11.209 in the cost115 metric, which is less than NT, NCT, NR3, and NM3 libraries. The comparison showed that using Negative NCT library instead of NCT library gives less quantum cost, which equals 10.078. Symmetry 2021, 13, 1025 22 of 23

The proposed algorithms work with universal libraries that use a set or a subset of NOT, OCNOT, and OToffoli gates. This work can be extended by finding other pairing functions for each circuit in the Negative NCT library to minimize the BPS quantum cost. Another extension is to apply the proposed algorithms on different universal libraries.

Author Contributions: Conceptualization, M.G. and A.Y.; supervision, A.Y.; software M.G.; vali- dation M.G. and A.Y.; writing the paper, M.G. and A.Y. All authors have read and agreed to the published version of the manuscript. Funding: This project was supported financially by the Academy of Scientific Research and Technol- ogy (ASRT), Egypt, Grant No 6565, (ASRT) is the 2nd affiliation of this research. Institutional Review Board Statement: Not applicable. Informed Consent Statement: Not applicable. Data Availability Statement: Not applicable Acknowledgments: We acknowledge the use of IBM Quantum services for this work. The views expressed are those of the authors, and do not reflect the official policy or position of IBM or the IBM Quantum team. Conflicts of Interest: The authors declare that they have no conflict of interest.

References 1. Landauer, R. Irreversibility and Heat Generation in the Computing Process. IBM J. Res. Dev. 1961, 5, 183–191. [CrossRef] 2. Nielsen, M.A.; Chuang, I.L. (Eds.) Quantum Computation and ; Cambridge University Press: Cambridge, UK, 2011; pp. 604–605. 3. De Vos, A.; Raa, B.; Storme, L. Generating the group of reversible logic gates. J. Phys. A Math. Gen. 2002, 35, 7063–7078. [CrossRef] 4. Haghparast, M.; Shams, M.; Navi, K. Novel Reversible Multiplier Circuit in Nanotechnology. World Appl. Sci. J. 2008, 5, 806–810. 5. Sarker, A.; Ahmed, T.; Rashid, S.M.M.; Anwar, S.; Jaman, L.; Tara, N.; Alam, M.M.; Babu, H.M.H. Realization of reversible logic in DNA computing. In Proceedings of the 2011 11th IEEE International Conference on Bioinformatics and Bioengineering (BIBE 2011), Taichung, Taiwan, 24–26 October 2011; pp. 261–265. 6. Mamataj, S.; Saha, D.; Banu, N. A review of reversible gates and its application in logic design. Am. J. Eng. Res. 2014, 3, 151–161. 7. Green, A.S.; Altenkirch, T. From Reversible to Irreversible Computations. . Notes Theor. Comput. Sci. 2008, 210, 65–74. [CrossRef] 8. Zakablukov, D.V. Application of Permutation Group Theory in Reversible Logic Synthesis. In International Conference on Reversible Computation; Springer: Cham, Switzerland, 2015; pp. 1–15. 9. Yang, G.; Xie, F.; Hung, W.N.N.; Song, X.; Perkowski, M.A. Realization and synthesis of reversible functions. Theor. Comput. Sci. 2011, 5, 1606–1613. [CrossRef] 10. De Vos, A.; De Baerdemacker, S. Symmetry groups for the decomposition of reversible computers, quantum computers, and computers in between. Symmetry 2011, 3, 305–324. [CrossRef] 11. Chattopadhyay, A.; Baksi, A. Reversible Logic Circuit Complexity Analysis via Functional Decomposition. arXiv 2016, arXiv:1602.00101v2. 12. He, X.; Guan, Z.; Ding, F. The Mapping and Optimization Method of Quantum Circuits for Clifford + T Gate. J. Appl. Math. Phys. 2019, 7, 2796–2810. [CrossRef] 13. Selim, M. Quantum Cost Optimization for Reversible Sequential Circuit. Int. J. Adv. Comput. Sci. Appl. 2013, 4, 15–21. [CrossRef] 14. Osman, M. Integration of Irreversible Gates in Reversible Circuits Using NCT Library. IOSR J. Comput. Eng. 2013, 14, 69–79. [CrossRef] 15. Montaser, R.; Younes, A.; Abdel-Aty, M. Improving the quantum cost of NCT-based reversible circuit. Quantum Inf. Process. 2015, 14, 1249–1263. [CrossRef] 16. Miller, D.M.; Dueck, G.W. Translation Techniques for Reversible Circuit Synthesis with Positive and Negative Controls. In Recent Findings in Boolean Techniques; Drechsler, R., Grosse, D., Eds.; Springer: Cham, Switzerland, 2021. 17. Sasanian, Z.; Miller, D.M. NCV realization of MCT gates with mixed controls. In Proceedings of the 2011 IEEE Pacific Rim Conference on Communications, Computers and Signal Processing, Victoria, BC, Canada, 23–26 August 2011; pp. 567–571. [CrossRef] 18. Montaser, R.; Younes, A.; Abdel-Aty, M. New Design of Universal Reversible Gate Library. Quantum Matter 2017, 6, 89–96. [CrossRef] 19. Osman, M.; Younes, A.; Ismail, G.; Farouk, R. An Improved Design of n-Bit Universal Reversible Gate Library. Int. J. Theor. Phys. 2019, 58, 2531–2549. [CrossRef] 20. Younes, A. On the universality of n-bit reversible gate libraries. Appl. Math. Inf. Sci. 2015, 9, 2579–2588. Symmetry 2021, 13, 1025 23 of 23

21. Ali, M.B.; Hirayama, T.; Yamanaka, K.; Nishitani, Y. Quantum cost reduction of reversible circuits using new toffoli decomposition techniques. In Proceedings of the 2015 International Conference on Computational Science and Computational Intelligence (CSCI 2015), Las Vegas, CA, USA, 7–9 December 2016; Volume 9, pp. 59–64. 22. Puthoff, H.E. Quantum ground states as equilibrium particle–vacuum interaction states. Quantum Stud. Math. Found. 2016, 3, 5–10. [CrossRef] 23. Moraga, C. Using negated control signals in Quantum Computing Circuits. Facta Univ. Ser. Electron. Energetics 2011, 24.[CrossRef] 24. Moraga, C. Mixed polarity reversible Peres gates. Electron. Lett. 2014, 50, 987–989. [CrossRef] 25. Rahman, M.Z.; Rice, J.E. Templates for Positive and Negative Control Toffoli Networks. In Reversible Computation. RC 2014. Lecture Notes in Computer Science; Yamashita, S., Minato, S., Eds.; Springer: Cham, Switzerland, 2014; Volume 8507. 26. Soeken, M.; Kirkedal Thomsen, M. White Dots do Matter: Rewriting Reversible Logic Circuits. In Procceedings of the 5th International Conference on Reversible Computation, Victoria, BC, Canada, 4–5 July 2013; pp. 196–208. 27. Cheng, X.; Guan, Z.; Wang, W.; Zhu, L. A simplification algorithm for reversible logic network of positive/negative control gates. In Proceedings of the 2012 9th International Conference on Fuzzy Systems and Knowledge Discovery (FSKD 2012), Chongqing, China, 29–31 May 2012; pp. 2442–2446 28. Storme, L.; De Vos, A.; Jacobs, G. Group theoretical aspects of reversible logic gates. J. Univers. Comput. Sci. 1999, 5, 307–321. 29. Maslov, D.; Miller, D.M. Comparison of the Cost Metrics for Reversible and Quantum Logic Synthesis. IET Comput. Digit. Tech. 2007, 1, 98–104. [CrossRef] 30. Barenco, A.; Bennett, C.H.; Cleve, R.; Divincenzo, D.P.; Margolus, N.; Shor, P.; Sleator, T.; Smolin, J.A.; Weinfurter, H. Elementary gates for quantum computation. Phys. Rev. A 1995, 52, 3457–3467. [CrossRef][PubMed] 31. IBM Quantum Team. ibmq_ourense v1.0.2. Available online: https://quantum-computing.ibm.com (accessed on 18 December 2020). 32. Arabzadeh, M.; Saeedi, M.; Zamani, M.S. Rule-based optimization of reversible circuits. In Proceedings of the Asia and South Pacific Design Automation Conference (ASP-DAC), Taipei, Taiwan, 18–21 January 2010; pp. 849–854. 33. He, Y.; Luo, M.-X.; Zhang, E.; Wang, H.-K.; Wang, X.-F. Decompositions of n-qubit Toffoli Gates with Linear Circuit Complexity. Int. J. Theor. Phys. 2017, 56, 2350–2361. [CrossRef]

Short Biography of Authors

Mariam Gado is a MSc. student of computer science at Alexandria University, Egypt. She obtained her BSc. degree in computer science (Special Degree) from Alexandria University, Egypt in 2016. She is a member of Alexandria Quantum Computing Group (AleQCG). She is currently a teaching assistant at Egypt-Japan University of Science and Technology (E-JUST), she was a research assistant and laboratory engineer at E-JUST University from 2017 to 2020.

Ahmed Younes is a Professor of Computer Science at Alexandria University and Honorary Research Fellow at School of Computer Science, University of Birmingham, United Kingdom. He is the founder and leader of Alexandria Quantum Computing Group (AleQCG). He obtained his PhD from University of Birmingham, United Kingdom in 2004. He introduced a new technique, now known as ‘Partial Diffusion Operator’ in the field of amplitude amplification and made a contribution in representing Quantum Boolean circuits as Reed-Muller logic. He published many papers in Quantum Algorithms, and Reversible Circuits.