23
symmetry S S Article Optimization of Reversible Circuits Using Toffoli Decompositions with Negative Controls Mariam Gado 1,2, * and Ahmed Younes 1,2,3 Citation: Gado, M.; Younes, A. Optimization of Reversible Circuits Using Toffoli Decompositions with Negative Controls. Symmetry 2021, 13, 1025. https://doi.org/10.3390/ sym13061025 Academic Editor: Basil Papadopoulos and Sergei D. Odintsov Received: 2 May 2021 Accepted: 1 June 2021 Published: 7 June 2021 Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affil- iations. Copyright: © 2021 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https:// creativecommons.org/licenses/by/ 4.0/). 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-bit 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 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. Keywords: reversible circuit optimization; NCT library; negative quantum library; quantum cost; reversible circuit; Toffoli decomposition 1. 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. Lan- dauer’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 paral- lelism [5] and many more [6]. Quantum computing 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 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 [1820], which use GAP-based Symmetry 2021, 13, 1025. https://doi.org/10.3390/sym13061025 https://www.mdpi.com/journal/symmetry

Optimization of Reversible Circuits Using Toffoli

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Optimization of Reversible Circuits Using Toffoli

symmetryS S

Article

Optimization of Reversible Circuits Using ToffoliDecompositions with Negative Controls

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

�����������������

Citation: Gado, M.; Younes, A.

Optimization of Reversible Circuits

Using Toffoli Decompositions with

Negative Controls. Symmetry 2021, 13,

1025. https://doi.org/10.3390/

sym13061025

Academic Editor: Basil Papadopoulos

and Sergei D. Odintsov

Received: 2 May 2021

Accepted: 1 June 2021

Published: 7 June 2021

Publisher’s Note: MDPI stays neutral

with regard to jurisdictional claims in

published maps and institutional affil-

iations.

Copyright: © 2021 by the authors.

Licensee MDPI, Basel, Switzerland.

This article is an open access article

distributed under the terms and

conditions of the Creative Commons

Attribution (CC BY) license (https://

creativecommons.org/licenses/by/

4.0/).

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, Egypt3 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 constructionof quantum computers. This paper proposes two methods to reduce the quantum cost of 3-bitreversible circuits. The first method utilizes basic building blocks of gate pairs using differentToffoli decompositions. These gate pairs are used to reconstruct the quantum circuits where furtheroptimization rules will be applied to synthesize the optimized circuit. The second method suggestsusing a new universal library, which provides better quantum cost when compared with previouswork in both cost015 and cost115 metrics; this proposed new universal library “Negative NCT” usesgates that operate on the target qubit only when the control qubit’s state is zero. A combinationof the proposed basic building blocks of pairs of gates and the proposed Negative NCT library isused in this work for synthesis and optimization, where the Negative NCT library showed betterquantum cost after optimization compared with the NCT library despite having the same circuitsize. The reversible circuits over three bits form a permutation group of size 40,320 (23!), whichis a subset of the symmetric group, where the NCT library is considered as the generators of thepermutation group.

Keywords: reversible circuit optimization; NCT library; negative quantum library; quantum cost;reversible circuit; Toffoli decomposition

1. 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. Lan-dauer’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 paral-lelism [5] and many more [6].

Quantum computing 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 alsoused to find a relationship between the decomposition of a reversible circuit and a quantumcircuit in [10]. A relationship between the reversible logic synthesis problem and Youngsubgroups is introduced in [11]. A reversible gate is the basic building block of a reversiblecircuit [3]. Quantum gates are reversible gates/functions, which are considered as a specialcase of symmetry groups of finite spaces (Young subgroups) [10]. Many methods havebeen proposed to optimize the quantum cost of circuits [12,13]. The quantum cost of theNCT library is reduced in [14]; a further reduction of the quantum cost of the NCT libraryis made in [15]. The algorithms in [16,17] use an ancillary qubit to achieve less quantumcost. 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

Page 2: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 2 of 23

algorithms to synthesize reversible circuits using different types of gates with various gatecosts. Different Toffoli decompositions are proposed in [21] to reduce the quantum costof 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 negativecontrol is applied if the system is in the ground state. The importance of the ground stateover the excited state in systems for better stability is discussed in [22], which shows thatsystems tend to be more stable in the ground state compared with the excited state, sousing negative controls is more stable and has less quantum cost for the system comparedwith using positive controls [23–26].

The paper has two aims: the first aim of this paper is to propose an algorithm thatoptimizes the quantum cost of 3-bit reversible circuits based on a modified version of theNCT library; the second aim is to propose a new gate library by modifying the NCT libraryto replace positive control with negative control, which shows less quantum cost comparedwith the NCT library.

This paper is organized as follows: Section 2 gives a brief introduction to elementaryquantum gates used to build quantum circuits, permutation group, definitions and ter-minologies used in this paper. Section 3 introduces the proposed library and proposedsynthesis algorithm. Section 4 shows the experimental results. The paper concludes inSection 5.

2. Background

This section gives a brief introduction on the basics of reversible circuit, Negative NCTlibrary 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 bereversible if and only if each input vector x ∈ Xn is mapped to a unique output vectory ∈ 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 thatmaps an input to an output from A such that α : A → A, it can be represented as apermutation as follows in (1).

α =

(1 2 3 · · · 2n

α(1) α(2) α(3) · · · α(2n)

)(1)

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 84 2 1 3 5 8 7 6

)can be written as (1, 4, 3)(6, 8).

2.2. Reversible Quantum Logic

Quantum computers use qubit as the basic unit of information, which is representedby 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 firststate 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〉√

2and the fourth state is |−〉 where

|−〉 = (1−i)|0〉+(1+i)|1〉√2

.

Page 3: Optimization of Reversible Circuits Using Toffoli

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 aunique 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

|−〉 and vice versa. The superscript of N gate is 3 when N gate is applied on a three-qubitreversible circuit (N3) and the subscript of N gate refers to a specific qubit that NOT gateis applied on. For example, N3

2 applies a NOT gate on the second qubit in a three-qubitreversible 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 asshown in Figure 1a with the following permutations in (3):

N31 : (x1, x2, x3)→ (x1 ⊕ 1, x2, x3)

= (1, 5)(2, 6)(3, 7)(4, 8),

N32 : (x1, x2, x3)→ (x1, x2 ⊕ 1, x3)

= (1, 3)(2, 4)(5, 7)(6, 8),

N33 : (x1, x2, x3)→ (x1, x2, x3 ⊕ 1)

= (1, 2)(3, 4)(5, 6)(7, 8).

(3)

Square-root of NOT gate (v): A reversible gate that maps |0〉 to |+〉, |1〉 to |−〉, |+〉to |1〉, and |−〉 to |0〉.

Square-root of NOT gate (v†): A reversible gate that maps |0〉 to |−〉, |1〉 to |+〉, |+〉to |0〉 and |−〉 to |1〉.

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 thetarget qubit.

Definition 1. The condition on a control qubit is a condition that must be satisfied so that the gateon 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 targetqubit 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 operateon the target qubit if all of the control qubits’ states are |0〉. In this paper, the negativecontrol is represented in figures by ◦ and the positive control is represented by •. Onlynegative control gates are used in this paper because the quantum systems are more stablein the ground state, where the negative control gates are used compared with the excitedstate 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 otherqubit is the target qubit.

Controlled NOT gate(CNOT/C): A two-qubit gate, which has two versions: positiveCNOT (CNOT) and negative CNOT (OCNOT).

In the CNOT gate and OCNOT gate, if the control qubit’s state is |1〉 and |0〉, respec-tively, then negation will be applied on the target qubit, while the control qubit’s stateremains 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

Page 4: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 4 of 23

number on the left-hand side represents the control qubit and the number on the right-handside represents the target qubit. For example, C3

12 represents the CNOT gate with a positivecontrol on the first qubit and a target on the second qubit; C3

12represents 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 ofthe OCNOT gate is shown in Table 1. There are six possible gates of the OCNOT gate forthree-qubit reversible circuits as shown in Figure 1c with the following permutations in (4):

C312 : (x1, x2, x3)→ (x1, x2 ⊕ x1, x3) = (1, 3)(2, 4),

C313 : (x1, x2, x3)→ (x1, x2, x3 ⊕ x1) = (1, 2)(3, 4),

C321 : (x1, x2, x3)→ (x1 ⊕ x2, x2, x3) = (1, 5)(2, 6),

C323 : (x1, x2, x3)→ (x1, x2, x3 ⊕ x2) = (1, 2)(5, 6),

C332 : (x1, x2, x3)→ (x1, x2 ⊕ x3, x3) = (1, 3)(5, 7),

C331 : (x1, x2, x3)→ (x1 ⊕ x3, x2, x3) = (1, 5)(3, 7).

(4)

Controlled-V: A two-qubit gate that has two versions: positive V (CV) and negativeV (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 neg-ative 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 stateremains unchanged; otherwise it does nothing.

The truth table of the CV, CV†, OV and OV† gates are shown in Table 1. There aresix possible gates for the OV gate and six possible gates of the OV† gate for three-qubitreversible circuits as shown in Figure 1d,e, respectively.

Version June 2, 2021 submitted to Journal Not Specified 5 of 25

1h. The truth table of Toffoli and OToffoli gates are shown in Table 1. The followingOToffoli permutations are introduced in (5):

T3123 : (x1, x2, x3)→ (x1, x2, x3 ⊕ x1x2) = (1, 2),

T3132 : (x1, x2, x3)→ (x1, x2 ⊕ x1x3, x3) = (1, 3),

T3231 : (x1, x2, x3)→ (x1 ⊕ x2x3, x2, x3) = (1, 5).

(5)

N31 N3

2 N33

(a) NOT Gates

• •• •

• •C3

12 C313 C3

21 C323 C3

32 C331

(b) CNOT Gates

C312

C313

C321

C323

C332

C331

(c) OCNOT Gates

V VV V

V VV12 V13 V21 V23 V32 V31

(d) OV Gates

V† V†

V† V†

V† V†

V†12

V†13

V†21

V†23

V†32

V†31

(e) OV† Gates

• •• •

• •T3

123 T3132 T3

231

(f) Toffoli Gates

T3123

T3132

T3231

(g) OToffoli Gates

• ••

T3123

T3132

T3231

(h) Some Mixed PolarityToffoli Gates

Figure 1. The possible gates for 3-qubit reversible circuits.138

3.0.3. Quantum Cost of a Reversible Circuit139

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

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

the circuit.142

143

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

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

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

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

gate is 5.148

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

For a 3-qubit quantum circuit with a set of wires W = {1, 2, 3}, where the first qubit150

is 1, the second qubit is 2 and the third qubit is 3. Let K12 be any two-qubit gate whose151

control qubit is negative on qubit 1 and its target qubit is on qubit 2, where 1 6= 2 6= 3.152

153

Table 2 shows the moving rules where a gate can be swapped with its adjacent154

gate. For example, one-qubit NOT gate N31 that acts on the first qubit can be swapped155

Figure 1. The possible gates for three-qubit reversible circuits.

Page 5: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 5 of 23

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

NOT gate (N3)

Input Output

|0〉 |1〉|1〉 |0〉

CNOT OCNOT

Input Output Input Output

|00〉 |00〉 |00〉 |01〉|01〉 |01〉 |01〉 |00〉|10〉 |11〉 |10〉 |10〉|11〉 |10〉 |11〉 |11〉

CV(PositiveV) CV†(PositiveV†)

Input Output Input Output

|00〉 |00〉 |00〉 |00〉|01〉 |01〉 |01〉 |01〉|10〉 |1+〉 |10〉 |1−〉|11〉 |1−〉 |11〉 |1+〉

OV(NegativeV) OV†(NegativeV†)

Input Output Input Output

|00〉 |0+〉 |00〉 |0−〉|01〉 |0−〉 |01〉 |0+〉|10〉 |10〉 |10〉 |10〉|11〉 |11〉 |11〉 |11〉

Toffoli OToffoli

Input Output Input Output

|000〉 |000〉 |000〉 |001〉|001〉 |001〉 |001〉 |000〉|010〉 |010〉 |010〉 |010〉|011〉 |011〉 |011〉 |011〉|100〉 |100〉 |100〉 |100〉|101〉 |101〉 |101〉 |101〉|110〉 |111〉 |110〉 |110〉|111〉 |110〉 |111〉 |111〉

2.3.4. Three-Qubit Gate

These gates operate on three qubits, where two qubits are the control qubits and thethird 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. MixedControl Toffoli gates also exist where one of the control qubits is negative and the othercontrol qubit is positive.

The superscript of T gate is 3 when the Toffoli/OToffoli gate is applied on a three-qubitreversible circuit (T3). The subscript of T3 gate consists of three adjacent numbers: the firsttwo numbers starting from the left-hand side indicate the control qubits and the numberon the right-hand side indicates the target qubit. For example, T3

123 represents the Toffoligate with positive control qubits. T3

132represents the OToffoli gate with negative control

qubits. T3132

and T3231

represent the Mixed Control Toffoli gates with mixed control qubits.

Page 6: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 6 of 23

There are three possible gates for a Toffoli gate for three-qubit reversible circuits asshown in Figure 1f. There are three possible gates for an OToffoli gate for three-qubitreversible circuits as shown in Figure 1g. Some examples of Mixed Control Toffoli gates areshown 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):

T3123 : (x1, x2, x3)→ (x1, x2, x3 ⊕ x1x2) = (1, 2),

T3132 : (x1, x2, x3)→ (x1, x2 ⊕ x1x3, x3) = (1, 3),

T3231 : (x1, x2, x3)→ (x1 ⊕ x2x3, x2, x3) = (1, 5).

(5)

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 isthe count of the one-qubit and the two-qubit elementary gates in the decomposition ofthe circuit.

In this paper, two methods for calculating the quantum cost are used: the cost015metric [28] and cost115 metric [29]. In the cost015 metric: the quantum cost of a one-qubitgate is 0, two-qubit gate is 1 and three-qubit gate is 5 [30]. In the cost115 metric: thequantum 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 firstqubit is 1, the second qubit is 2 and the third qubit is 3. Let K12 be any two-qubit gate whosecontrol qubit is negative on qubit 1 and its target qubit is on qubit 2, where 1 6= 2 6= 3.

Table 2 shows the moving rules where a gate can be swapped with its adjacent gate.For example, the one-qubit NOT gate N3

1 that acts on the first qubit can be swapped withits adjacent one-qubit gate that acts on any of the other two qubits; the N3

1 gate can also beswapped with its adjacent two-qubit gate if the control qubit in the two-qubit gate is notthe same as the qubit that N3

1 acts on; in this case N31 can be swapped with C3

21, C3

31, OV21,

OV31, OV†21

, OV†31

, C323

, C332

,OV23, OV32, OV†23

and OV†32

. Adjacent two-qubit gates can beswapped if they have the same control qubit or if they have the same target qubit. Forexample, C3

23can be swapped with C3

13, C3

21, OV13, OV21, OV†

13and OV†

21.

Table 3 shows the merging rules in which two adjacent gates can be merged to form anew gate. For example, any two adjacent one-qubit gates that are applied on the same qubitcan be merged to form an identity gate if the application of the second gate reverses the firstgate. Any two adjacent two-qubit gates with the same control qubit and the same targetqubit can form a new gate. For example, OV12C3

12are merged to form OV†

12. Furthermore,

if two adjacent two-qubit gates in which the control qubit of the first gate is the same asthe target qubit of its adjacent gate, and the target qubit of the first gate is the same as thecontrol qubit in its adjacent gate, then these gates can form a new gate and the resultingtwo-qubit gate has a quantum cost of 1 in both of the cost015 and cost115 metrics [15].For example, C3

12OV21 can be merged to form a two-qubit gate [C3

12OV21]. In this paper,

the visual representation of this gate is shown by surrounding this two-qubit gate with adashed box and its quantum cost is 1 [15]. The splitting rules are the reverse of the mergingrules, these optimization rules are used in [14–18,21].

Table 2. The moving rules of quantum gates.

Gate Swappable Gates

N31 N3

2 , N33 , K2,3, K2,1, K3,2, K3,1

K1,2 N32 , N3

3 , K1,3, K3,2

Page 7: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 7 of 23

Table 3. The merging rules of quantum gates.

Gates before Optimization Gates after Optimization

N31 N3

1 , C31,2

C31,2

IOV1,2OV†

1,2, OV†

1,2OV1,2 I

OV1,2OV1,2, OV†1,2

OV†1,2

C31,2

OV1,2C31,2

, C31,2

OV1,2 OV†1,2

OV†1,2

C31,2

, C31,2

OV†1,2

OV1,2K1,2K2,1 [K1,2K2,1]

3. The Proposed Negative NCT-Gate Library

This section explains the proposed Negative NCT gate library for building three-qubitreversible 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 inSection 2. The 12 gates are three NOT gates, six OCNOT gates and three OToffoli gates. Animplementation of the Schreier–Sims algorithm on the GAP software is used to generatethe set of all possible three-qubit reversible circuits with the least length (40,319 circuitsexcluding the identity [20]), which shows the universality of the Negative NCT gate libraryfor 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. Table 4 shows the gates with their corresponding gatesymbol (sym.).

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

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

T3123

L1 C312

L22 C323

L25 N31 L13

T3132

L2 C313

L23 C332

L26 N32 L14

T3231

L3 C321

L24 C331

L27 N33 L15

The decomposition (Lnum)d of a gate is a set of elementary gates that can be used tosynthesize a quantum circuit equivalent to this gate, each set of these elementary gates isgiven a number d starting from 0. For example, (L2)0 represents the gate symbol L2 in its0th 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 isthe 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 thegate 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 differentdecompositions. Figures 2–4 show the eight different decompositions for each OToffoligate that depend on the Toffoli decompositions in [21]. This paper uses only negativecontrol decompositions, while [21] uses only positive control decompositions.

Page 8: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 8 of 23

Version June 2, 2021 submitted to Journal Not Specified 8 of 25

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

where each one-qubit gate or two-qubit gate has only one decomposition which is the199

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 each202

OToffoli gate which depend on the Toffoli decomositions in [22]. This paper uses only203

negative control decompositions, while [22] uses only positive control decompositions.204

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

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

(a)

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

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

(b)Figure 2. Decompositions (Decomp.) of T3

123where 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 secondcontrol qubit is on qubit 1. These decompositions are the negative decompositions which are basedon the positive decompositions in [22].

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

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

(a)

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

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

(b)Figure 3. Decompositions (Decomp.) of T3

132where 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 secondcontrol qubit is on qubit 1. These decompositions are the negative decompositions which are basedon the positive decompositions in [22].

5.0.1. Right and Left Gate Sets of a Decomposition205

Definition 6. The ordered pair of a gate (OP) is an ordered pair that contains the control206

qubit and the target qubit of a gate (control − qubit, target− qubit).207

Figure 2. Decompositions (Decomp.) of T3123

where in (a) the first control qubit is on qubit 1 andthe second control qubit is on qubit 2, and in (b) the first control qubit is on qubit 2 and the secondcontrol qubit is on qubit 1. These decompositions are the negative decompositions, which are basedon the positive decompositions in [21].

Version June 2, 2021 submitted to Journal Not Specified 8 of 25

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

where each one-qubit gate or two-qubit gate has only one decomposition which is the199

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 each202

OToffoli gate which depend on the Toffoli decomositions in [22]. This paper uses only203

negative control decompositions, while [22] uses only positive control decompositions.204

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

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

(a)

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

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

(b)Figure 2. Decompositions (Decomp.) of T3

123where 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 secondcontrol qubit is on qubit 1. These decompositions are the negative decompositions which are basedon the positive decompositions in [22].

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

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

(a)

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

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

(b)Figure 3. Decompositions (Decomp.) of T3

132where 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 secondcontrol qubit is on qubit 1. These decompositions are the negative decompositions which are basedon the positive decompositions in [22].

5.0.1. Right and Left Gate Sets of a Decomposition205

Definition 6. The ordered pair of a gate (OP) is an ordered pair that contains the control206

qubit and the target qubit of a gate (control − qubit, target− qubit).207

Figure 3. Decompositions (Decomp.) of T3132

where in (a) the first control qubit is on qubit 1 andthe second control qubit is on qubit 3, and in (b) the first control qubit is on qubit 3 and the secondcontrol qubit is on qubit 1. These decompositions are the negative decompositions, which are basedon the positive decompositions in [21].

Table 5. Negative NCT gates with their equivalent gate decomposition (Decomp.).

Gate Gate Decomposition

T3123

L(1)0, L(1)1

, L(1)2, L(1)3

, L(1)4, L(1)5

, L(1)6, L(1)7

T3132

L(2)0, L(2)1

, L(2)2, L(2)3

, L(2)4, L(2)5

, L(2)6, L(2)7

T3231

L(3)0, L(3)1

, L(3)2, L(3)3

, L(3)4, L(3)5

, L(3)6, L(3)7

Gate Gate Decomp. Gate Gate Decomp. Gate Gate Decomp.

C312

L(22)0C3

23L(25)0

N31 L(13)0

C313

L(23)0C3

32L(26)0

N32 L(14)0

C321

L(24)0C3

31L(27)0

N33 L(15)0

Page 9: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 9 of 23

Version June 2, 2021 submitted to Journal Not Specified 9 of 25

An example of an OP for 3-qubit system is (1, 3), where the control is on the first208

qubit and the target is on the third qubit. C313, C3

12, V13, V13, V†

13and V†

13 are some209

examples of gates in which their OP is (1, 3).210

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

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

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

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

example of the rg set of (L1)0 gate in Figure 2a is {(1, 3), (1, 2)}, where the two ordered215

pairs in the rg set have the same control qubit in this example and the lg set of (L1)0 gate216

is {(2, 3)}. Another example of the rg set of (L2)5 gate in Figure 3b is {(1, 2)} and the217

lg set of (L2)5 gate is {(3, 2), (3, 1)}, where the two ordered pairs in the lg set have the218

same target qubit in this example.219

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

231where in (a) the first control qubit is on qubit 2 and

the second control qubit is on qubit 3, and in (b) the first control qubit is on qubit 3 and the secondcontrol qubit is on qubit 2. These decompositions are the negative decompositions which are basedon the positive decompositions in [22].

Table 5: Negative NCT gates with their equivalent gate decomposition (Decomp.).

Gate Gate Decomposition

T3123

L(1)0, L(1)1

, L(1)2, L(1)3

, L(1)4, L(1)5

, L(1)6, L(1)7

T3132

L(2)0, L(2)1

, L(2)2, L(2)3

, L(2)4, L(2)5

, L(2)6, L(2)7

T3231

L(3)0, L(3)1

, L(3)2, L(3)3

, L(3)4, L(3)5

, L(3)6, L(3)7

Gate Gate Gate Gate Gate GateDecomp. Decomp. Decomp.

C312

L(22)0C3

23L(25)0

N31 L(13)0

C313

L(23)0C3

32L(26)0

N32 L(14)0

C321

L(24)0C3

31L(27)0

N33 L(15)0

Each decomposition of the OToffoli gates contains two gate sets; the rg set and the220

lg set where each of these sets contains OP elements, the OP of a gate is concerned with221

the control qubit and the target qubit only, and it does not concern with the condition222

on the control qubit nor the functionality of the gate itself. The rg set and the lg set of223

a decomposition contain the OP of the gate on the right-hand side and the left-hand224

side respectively. For example, (L1)0 decomposition which is shown in Figure 2a has a225

Figure 4. Decompositions (Decomp.) of T3231

where in (a) the first control qubit is on qubit 2 andthe second control qubit is on qubit 3, and in (b) the first control qubit is on qubit 3 and the secondcontrol qubit is on qubit 2. These decompositions are the negative decompositions, which are basedon the positive decompositions in [21].

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 qubitand 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 firstqubit and the target is on the third qubit. C3

13, C313

, V13, V13, V†13

and V†13 are some examples

of gates in which their OP is (1, 3).

Definition 4. The sets rg and lg of a circuit are the sets that contain the OP of the right-hand sidegate and left-hand side gate, respectively.

The rg set or the lg set contains ordered pairs with the same control qubit or the sametarget qubit; otherwise the rg set or the lg set contains one OP element only. An exampleof the rg set of (L1)0 gate in Figure 2a is {(1, 3), (1, 2)}, where the two ordered pairs in therg set have the same control qubit in this example and the lg set of (L1)0 gate is {(2, 3)}.Another example of the rg set of (L2)5 gate in Figure 3b is {(1, 2)} and the lg set of (L2)5gate is {(3, 2), (3, 1)}, where the two ordered pairs in the lg set have the same target qubitin this example.

Each decomposition of the OToffoli gates contains two gate sets; the rg set and thelg set where each of these sets contains OP elements, the OP of a gate is concerned withthe control qubit and the target qubit only, and it does not concern with the conditionon the control qubit nor the functionality of the gate itself. The rg set and the lg set of adecomposition 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 Figure 2a has a left-hand side gate, which is V23, where the control qubit is on qubit 2 (the second qubit) andthe target qubit is on qubit 3 (the third qubit), so this gate’s OP is (2,3); hence, the lg set of(L1)0 is {(2, 3)}, if V23 gate and its next gate can be swapped, then the OP of the V23 nextgate can also be added to the lg set; C3

12cannot be swapped with V23; hence, the lg set for

this decomposition remains unchanged. The right-hand side gate in (L1)0 decompositionis V13 where this gate’s OP is (1,3); hence, the rg set of (L1)0 is {(1, 3)} if the V13 gate andits prior gate can be swapped then the OP of V13 gate’s prior gate can be added to the rgset; C3

12can be swapped with V13; 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.

Page 10: Optimization of Reversible Circuits Using Toffoli

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(1)0,L(1)2

{(2, 3)} {(1, 2), (1, 3)}L(1)1

,L(1)3{(1, 2), (1, 3)} {(2, 3)}

L(1)4,L(1)6

{(1, 3)} {(2, 1), (2, 3)}L(1)5

,L(1)7{(2, 1), (2, 3)} {(1, 3)}

L(2)0,L(2)2

{(3, 2)} {(1, 2), (1, 3)}L(2)1

,L(2)3{(1, 2), (1, 3)} {(3, 2)}

L(2)4,L(2)6

{(1, 2)} {(3, 1), (3, 2)}L(2)5

,L(2)7{(3, 1), (3, 2)} {(1, 2)}

L(3)0,L(3)2

{(3, 1)} {(2, 3), (2, 1)}L(3)1

,L(3)3{(2, 3), (2, 1)} {(3, 1)}

L(3)4,L(3)6

{(2, 1)} {(3, 2), (3, 1)}L(3)5

,L(3)7{(3, 2), (3, 1)} {(2, 1)}

L(22)0{(1, 2)} {(1, 2)}

L(23)0{(1, 3)} {(1, 3)}

L(24)0{(2, 1)} {(2, 1)}

L(25)0{(2, 3)} {(2, 3)}

L(26)0{(3, 2)} {(3, 2)}

L(27)0{(3, 1)} {(3, 1)}

3.2. Basic Pairs

Definition 5. A basic pair is a circuit that consists of two consecutive decomposed gates withminimal quantum cost and lower decomposition number.

The set of all possible circuits that represent a pair of gates is calculated by multiplyingthe count of decompositions of each gate inside this pair. For example, the L1L2 pair beginswith the L1 gate, which has eight different decompositions as shown in Figure 2, and thesecond gate is the L2 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 thatchooses the circuit with the least quantum cost out of these 64 different circuits in order torepresent 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 forma new gate according to the merging rules in Table 3. Therefore, the technique to choosethe circuit with minimal cost works through finding the largest set that results from theintersection of the RG set of the first gate with the LG set of the second gate inside the basicpair, if the two sets are mutually exclusive, then it finds the largest set that results fromintersecting the invert of the RG set of the first gate with the LG set of the next gate. Forexample, if the RG set of the first gate includes {(1, 3)}, and there are no mutual elementsin the LG set of the next gate, then it searches for {(3, 1)} in the LG set of the second gateinstead, since these two gates can form a two-qubit gate with a quantum cost of 1 accordingto the merging rules in [15].

For example, the L1L2 pair has 64 different circuits to represent it. The basic pair withthe least quantum cost of this pair is (L1)0(L2)1 in which the decomposition number of thefirst gate is 0 and the decomposition number of the next gate is 1 since the intersection ofthe RG set of L1 and the LG set of L2 is {(1, 2)(1, 3)} according to Table 6, then the finalquantum cost of this basic pair is 7 instead of 10. Figure 5 shows the (L1)0(L2)1 basic

Page 11: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 11 of 23

pair where Figure 5a 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 aremarked 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 pairafter applying the merging rules and forming two two-qubit gates, then the newly formedtwo-qubit gate on the left hand-side is marked. Figure 5d shows the basic pair after movingthe 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 andfinally applying further optimization, where the quantum cost is reduced to 7 after forminga two-qubit gate with a quantum cost of 1 [15].

Version June 2, 2021 submitted to Journal Not Specified 12 of 25

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 aquantum cost of 10, (b) represents the basic pair after swapping the two marked gates and thesolid box shows the gates which will be merged, (c) represents the basic pair after applying themerging 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 theother resulting two-qubit gate, and (e) represents the basic pair after moving the marked gate tothe left-hand side and applying the optimization rules, where the dashed box indicates forming atwo-qubit gate [16]; hence, the final quantum cost is 7.

9.0.1. Build a Circuit with Basic Pairs292

Definition 10. The solitary gate of a gate is the gate in its 0th decomposition.293

Basic pairs are concatenated to form circuits, the rg of the basic pair and the lg of294

the next basic pair are called a "point of connection". For example, L2L27L1L2 circuit295

consists of four gates, each two gates starting from the left-hand side are replaced with296

their corresponding basic pair, so in this case the circuit consists of two basic pairs where297

the first basic pair is (L2)4(L27)0 and the next basic pair is (L1)0(L2)1 as shown in Figure298

7.299

Figure 5. (L1)0(L2)1 basic pair where (a) represents the basic pair before optimization with a quantumcost of 10; (b) represents the basic pair after swapping the two marked gates and the solid box showsthe gates that will be merged; (c) represents the basic pair after applying the merging rules, wheretwo two-qubit gates are formed and the quantum cost is reduced to 8; (d) represents the basic pairafter 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 theoptimization rules, where the dashed box indicates forming a two-qubit gate [15]; hence, the finalquantum cost is 7.

Page 12: Optimization of Reversible Circuits Using Toffoli

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 pairto 4 instead of 6, where the rg of the (L2)4 gate matches the lg of the (L27)0 gate, whilechoosing (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 explanationof this example is shown in Figure 6, where (L2)4(L27)0 and (L2)6(L27)0 have the leastquantum cost but the basic pair of L2L27 circuit is (L2)4(L27)0 since the basic pair withlower decomposition number (num) is considered to be the basic pair for this pair as shownin 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 7shows the Negative NCT library’s basic pairs excluding basic pairs that contain NOT gatesand 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 optimizationand its corresponding 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)Figure 6. Possible basic pairs for L2L27 where the quantum cost is reduced. Q.C stands forquantum cost. (a) shows the lowest quantum cost of L2L27 possible basic pairs with quantum costof 4, (b) and (c) show L2L27 possible basic pairs with quantum cost of 5.

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 L2L27L1L2 circuit.

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

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

the number of solitary gates in a circuit is ≤ 2. Two methods are going to be proposed in302

the next sections in order to choose the basic pairs to reconstruct a circuit.303

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

Page 13: Optimization of Reversible Circuits Using Toffoli

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 thequantum 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

T3123

T3132

(L1)0(L2)1 7 10 V†13

V23C312[V†

23V†

32]C3

13V32V†

12T3

123T3

231(L1)4(L3)1 7 10 V†

23V13C3

21[V†

13V†

31]C3

23V31V†

21T3

123C3

12(L1)0(L22)0 4 6 V23C3

12V†

23V13

T3123

C313

(L1)0(L23)0 5 6 V23C312

V†23

C312

V†13

T3123

C321

(L1)4(L24)0 4 6 V13C321

V†13

V23T3

123C3

23(L1)4(L25)0 5 6 V13C3

21V†

13C3

21V†

23T3

123C3

32(L1)1(L26)0 5 6 V13C3

12V†

23C3

12[V23C3

32]

T3123

C331

(L1)5(L27)0 5 6 V23C321

V†13

C321[V13C3

31]

T3132

T3123

(L2)0(L1)1 7 10 V†12

V32C313[V†

32V†

23]C3

12V23V†

13T3

132T3

231(L2)4(L3)5 7 10 V†

32V12C3

31[V†

12V†

21]C3

32V21V†

31T3

132C3

12(L2)0(L22)0 5 6 V32C3

13V†

32C3

13V†

12T3

132C3

13(L2)0(L23)0 4 6 V32C3

13V†

32V12

T3132

C321

(L2)5(L24)0 5 6 V32C331

V†12

C331[V12C3

21]

T3132

C323

(L2)1(L25)0 5 6 V12C313

V†32

C313[V32C3

23]

T3132

C332

(L2)1(L26)0 5 6 V12C313

V†32

C313

V†32

T3132

C331

(L2)4(L27)0 4 6 V12C331

V†12

V32T3

231T3

123(L3)0(L1)5 7 10 V†

21V31C3

23[V†

31V†

13]C3

21V13V†

23T3

231T3

132(L3)4(L2)5 7 10 V†

31V21C3

32[V†

21V†

12]C3

31V12V†

32T3

231C3

12(L3)5(L22)0 5 6 V31C3

32V†

21C3

32[V21C3

12]

T3231

C313

(L3)1(L23)0 5 6 V21C323

V†31

C323[V31C3

13]

T3231

C321

(L3)0(L24)0 5 6 V31C323

V†31

C323

V†21

T3231

C323

(L3)0(L25)0 4 6 V31C323

V†31

V21T3

231C3

32(L3)4(L26)0 4 6 V21C3

32V†

21V31

T3231

C331

(L3)1(L27)0 5 6 V21C323

V†31

C323

V†31

C312

T3123

(L22)0(L1)1 4 6 V13V†23

C312

V23C3

12T3

132(L22)0(L2)1 5 6 V†

12C3

13V†

32C3

13V32

C312

T3231

(L22)0(L3)4 5 6 [C312

V21]C332

V†21

C332

V31C3

12C3

21(L22)0(L24)0 1 2 [C3

12C3

21]

C313

T3123

(L23)0(L1)1 5 6 V†13

C312

V†23

C312

V23C3

13T3

132(L23)0(L2)1 4 6 V12V†

32C3

13V32

C313

T3231

(L23)0(L3)0 5 6 [C313

V31]C323

V†31

C323

V21C3

13C3

31(L23)0(L27)0 1 2 [C3

13C3

31]

C321

T3123

(L24)0(L1)5 4 6 V23V†13

C321

V13C3

21T3

132(L24)0(L2)4 5 6 [C3

21V12]C

331

V†12

C331

V32C3

21T3

231(L24)0(L3)4 5 6 V†

21C3

32V†

21C3

32V31

C321

C312

(L24)0(L22)0 1 2 [C321

C312]

C323

T3123

(L25)0(L1)0 5 6 V†23

C312

V†23

C312

V13C3

23T3

132(L25)0(L2)0 5 6 [C3

23V32]C

313

V†32

C313

V12C3

23T3

231(L25)0(L3)1 4 6 V21V†

31C3

23V31

C323

C332

(L25)0(L26)0 1 2 [C323

C332]

C332

T3123

(L26)0(L1)0 5 6 [C332

V23]C312

V†23

C312

V13C3

32T3

132(L26)0(L2)0 5 6 V†

32C3

13V†

32C3

13V12

C332

T3231

(L26)0(L3)5 4 6 V31V†21

C332

V21C3

32C3

23(L26)0(L25)0 1 2 [C3

32C3

23]

C331

T3123

(L27)0(L1)4 5 6 [C331

V13]C321

V†13

C321

V23C3

31T3

132(L27)0(L2)5 4 6 V32V†

12C3

31V12

C331

T3231

(L27)0(L3)0 5 6 V†31

C323

V†31

C323

V21C3

31C3

13(L27)0(L23)0 1 2 [C3

31C3

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 ofthe next basic pair are called a “point of connection”. For example, the L2L27L1L2 circuit

Page 14: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 14 of 23

consists of four gates, each two gates starting from the left-hand side are replaced withtheir corresponding basic pair, so in this case the circuit consists of two basic pairs wherethe first basic pair is (L2)4(L27)0 and the next basic pair is (L1)0(L2)1 as shown in Figure 7.

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)Figure 6. Possible basic pairs for L2L27 where the quantum cost is reduced. Q.C stands forquantum cost. (a) shows the lowest quantum cost of L2L27 possible basic pairs with quantum costof 4, (b) and (c) show L2L27 possible basic pairs with quantum cost of 5.

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 L2L27L1L2 circuit.

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

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

the number of solitary gates in a circuit is ≤ 2. Two methods are going to be proposed in302

the next sections in order to choose the basic pairs to reconstruct a circuit.303

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

Let S be the total number of gates in a circuit; whether, S is even or odd determinesthe number of basic pairs and solitary gates, which are used to build the circuit, where thenumber of solitary gates in a circuit is ≤2. Two methods are going to be proposed in thenext sections in order to choose the basic pairs to reconstruct a circuit.

3.3. Circuit Optimization Algorithm

Definition 8. The basic pair solitary (BPS) quantum cost is the summation of all quantum costsof all basic pairs and solitary gates, which are used to build the 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 ofgates. In FunctionI (Algorithm 1), the gates are paired starting from the left-hand sidegate of the circuit. BasicPair(Ci, Ci+1) represents the corresponding basic pairs of the ithand ith + 1 gates in the circuit C, if S is odd, then the last gate on the right-hand sideof the circuit is merged with the circuit as a solitary gate where Solitary(Ci) decomposesthe 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)functionif S = 1

then return (C)else if S 6= 1then for i← 0 to S/2

do

BasicPair(Ci, Ci+1)O+ = BasicPairi+ = 2

if S mod 2 = 1then O+ = Solitary(CS)

O = optimize(O)return (O)

Algorithm 2 Circuit Optimization (ONCT)procedurefor each C ∈ ONCT

do C = FunctionI(C) −

For example, the L22L1L3L1L22 circuit has a quantum cost of 17 and is translated toC3

12T3

123T3

231T3

123C3

12, and this circuit consists of five gates (where S = 5), the reconstructed

Page 15: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 15 of 23

circuit is paired from the left-hand side into two pairs L22L1 and L3L1 maintaining theorder of pairs from left to right; these pairs are replaced with their corresponding basicpairs; (L22)0(L1)1 with a quantum cost of 4 and (L3)0(L1)5 with a quantum cost of 7according to Table 7, the gate on the right-hand side is L22 and it will be decomposed intoits decomposition number 0 since S is odd, where (L22)0 has a quantum cost of 1, the BPSquantum cost of this reconstructed circuit is 12 instead of 17 in the cost015 metric, theoptimization rules are then applied on points of connection of the reconstructed circuit andthe final quantum cost for this reconstructed circuit is 11. Figure 8 shows the decompositionsteps of the L22L1L3L1L22 circuit before and after applying the optimization rules. Thedashed box in Figure 8 refers to a two-qubit gate with a quantum cost of 1 [15].

Version June 2, 2021 submitted to Journal Not Specified 17 of 25

Figure 9 illustrates L13L1L2L22L13 circuit example before and after applying the349

optimization rules in the cost015 metric, the dashed box indicates forming a two-qubit350

gate with a quantum cost of 1 [16].351

(a)

V† V V†

V V† V V† V V†

Basicpair1 Basicpair2 Solitarygate︸ ︷︷ ︸ ︸ ︷︷ ︸︸︷︷︸

(b)

V† V V†

V V† V V† V V†

(c)Figure 8. L22L1L3L1L22 circuit where (a) represents the quantum circuit with a quantum cost of17, (b) represents the reconstructed circuit using basic pairs of gates and a solitary gate with aquantum cost of 12, and (c) represents the quantum circuit after applying the optimization rulesand forming a two-qubit gate. The final quantum cost after optimization is 11.

Algorithm 11.3: FUNCTIONII(C)

if S = 1then return (C)else if S = 2

then

BasicPair(Ci, Ci+1)O+ = BasicPairreturn (O)

else if S > 2

then

O+ = Solitary(C0)for i← 1 to S/2

do

BasicPair(Ci, Ci+1)O+ = BasicPairi+ = 2

if S mod 2 = 0then O+ = Solitary(CS)

O = optimize(O)return (O)

352

353

IBM Quantum Experience ibmq− ourense system [32] has been used to implement354

L13L1L2L22L13 circuit, which permutation is (5, 8, 6). The ibmq− ourense system has five355

qubits, Canary r2 processor, with average CNOT error of 8.750e−3 and average readout356

error of 2.800e−2. IBM Quantum Experience does not currently support V†ab gate where357

qubit a 6= qubit b, so this gate is replaced with VabC3ab gates since they are equivalent358

according to the splitting rules, which are the reverse of the merging rules in Table359

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

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

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

to [33].363

Figure 8. The L22L1L3L1L22 circuit where (a) represents the quantum circuit with a quantum cost of 17; (b) represents thereconstructed circuit using basic pairs of gates and a solitary gate with a quantum cost of 12; (c) represents the quantumcircuit after applying the optimization rules and forming a two-qubit gate. The final quantum cost after optimization is 11.

3.4. 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 gateon the left-hand side instead of the first gate. If S is odd and S ≥ 3, then the circuit isreconstructed as a solitary gate and basic pairs(s), while for even S ≥ 4, then the circuit isreconstructed as a solitary gate then basic pair(s) and finally a solitary gate. For example,the L13L1L2L22L13 circuit has a quantum cost of 11, which can be reconstructed usingFunctionI (Algorithm 1) 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(L13)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-handside and two basic pairs: (L13)0 with a quantum cost of 0, (L1)0(L2)1 with a quantum costof 7 and (L22)0(L13)0 with a quantum cost of 1, where the BPS quantum cost for this circuitusing FunctionII (Algorithm 3) is 8, the latter function shows a better quantum cost for thiscircuit and the final quantum cost using FunctionII (Algorithm 3) is 7 after applying theoptimization rules on the points of connection instead of 11 in the cost015 metric as shownin Figure 9.

Figure 9 illustrates the L13L1L2L22L13 circuit example before and after applying theoptimization rules in the cost015 metric, the dashed box indicates forming a two-qubit gatewith a quantum cost of 1 [15].

Page 16: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 16 of 23

Algorithm 3 FunctionII (C)functionif S = 1

then return (C)else if S = 2

then

BasicPair(Ci, Ci+1)O+ = BasicPairreturn (O)

else if S > 2

then

O+ = Solitary(C0)for i← 1 to S/2

do

BasicPair(Ci, Ci+1)O+ = BasicPairi+ = 2

if S mod 2 = 0then O+ = Solitary(CS)

O = optimize(O)return (O)

Version June 2, 2021 submitted to Journal Not Specified 18 of 25

(a)

V V† V†

V V† V

Basicpair1 Basicpair2 Solitarygate︸ ︷︷ ︸ ︸ ︷︷ ︸ ︸︷︷︸

(b)

V† V V†

V† V V†

Solitarygate Basicpair1 Basicpair2

︸︷︷︸︸ ︷︷ ︸ ︸ ︷︷ ︸

(c)

V† V V

V† V V†

(d)Figure 9. L13L1L2L22L13 circuit where (a) represents the quantum circuit with a quantum cost of11, (b) represents the quantum circuit, which is reconstructed by using FunctionI 11.1 with a BPSquantum cost of 10, (c) represents the quantum circuit, which is reconstructed by using FunctionII11.3 with a BPS quantum cost of 8, and (d) represents the quantum circuit, which is reconstructedusing FunctionII 11.3 after applying the optimization rules on the points of connection and thefinal quantum cost is 7.

≡ •

Figure 10. Preparing the gate for IBM Quantum Experience implementation, where a negativecontrol is equivalent to adding NOT gates before and after a positive control.

The reconstructed circuit L13L1L2L22L13, which is obtained from applying Function364

11.3 is modified to be compatible with the ibmq − ourense system by applying the365

splitting rules and the rule in Figure 10. The implementation of L13L1L2L22L13 circuit366

on the ibmq− ourense system has a quantum cost of 7 as shown in Figure 11, while the367

implementation of the equivalent quantum circuit, which permutation is (5, 8, 6) using368

the NCT library has a quantum cost of 11 as shown in Figure 12.369

Figure 9. The L13L1L2L22L13 circuit where (a) represents the quantum circuit with a quantum costof 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 usingFunctionII (Algorithm 3) with a BPS quantum cost of 8; (d) represents the quantum circuit, which isreconstructed using FunctionII (Algorithm 3) after applying the optimization rules on the points ofconnection and the final quantum cost is 7.

Page 17: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 17 of 23

IBM Quantum Experience ibmq − ourense system [31] was used to implement theL13L1L2L22L13 circuit, whose permutation was (5, 8, 6). The ibmq − ourense system hasfive qubits, a Canary r2 processor, with an average CNOT error of 8.750e−3, and averagereadout error of 2.800e−2. The IBM Quantum Experience does not currently support theV†

ab gate where qubit a 6= qubit b, so this gate is replaced with VabC3ab gates since they

are equivalent according to the splitting rules, which are the reverse of the merging rulesin Table 3. The IBM Quantum Experience does not also support the negative controlqubit, so the positive control qubit is used and NOT gates are added before and after eachpositive control qubit in the quantum circuit as shown in Figure 10 since they are equivalentaccording to [32].

Version June 2, 2021 submitted to Journal Not Specified 18 of 25

(a)

V V† V†

V V† V

Basicpair1 Basicpair2 Solitarygate︸ ︷︷ ︸ ︸ ︷︷ ︸ ︸︷︷︸

(b)

V† V V†

V† V V†

Solitarygate Basicpair1 Basicpair2

︸︷︷︸︸ ︷︷ ︸ ︸ ︷︷ ︸

(c)

V† V V

V† V V†

(d)Figure 9. L13L1L2L22L13 circuit where (a) represents the quantum circuit with a quantum cost of11, (b) represents the quantum circuit, which is reconstructed by using FunctionI 11.1 with a BPSquantum cost of 10, (c) represents the quantum circuit, which is reconstructed by using FunctionII11.3 with a BPS quantum cost of 8, and (d) represents the quantum circuit, which is reconstructedusing FunctionII 11.3 after applying the optimization rules on the points of connection and thefinal quantum cost is 7.

≡ •

Figure 10. Preparing the gate for IBM Quantum Experience implementation, where a negativecontrol is equivalent to adding NOT gates before and after a positive control.

The reconstructed circuit L13L1L2L22L13, which is obtained from applying Function364

11.3 is modified to be compatible with the ibmq − ourense system by applying the365

splitting rules and the rule in Figure 10. The implementation of L13L1L2L22L13 circuit366

on the ibmq− ourense system has a quantum cost of 7 as shown in Figure 11, while the367

implementation of the equivalent quantum circuit, which permutation is (5, 8, 6) using368

the NCT library has a quantum cost of 11 as shown in Figure 12.369

Figure 10. Preparing the gate for IBM Quantum Experience implementation, where a negative controlis equivalent to adding NOT gates before and after a positive control.

The reconstructed circuit L13L1L2L22L13, which is obtained from applying FunctionII(Algorithm 3) is modified to be compatible with the ibmq− ourense system by applying thesplitting rules and the rule in Figure 10. The implementation of the L13L1L2L22L13 circuiton the ibmq− ourense system has a quantum cost of 7 as shown in Figure 11, while theimplementation of the equivalent quantum circuit, whose permutation is (5, 8, 6) using theNCT library has a quantum cost of 11 as shown in Figure 12.

Version June 2, 2021 submitted to Journal Not Specified 19 of 25

Figure 11. L13L1L2L22L13 circuit implementation on the ibmq− ourense system, where the quan-tum cost of this circuit is 7. The solid box indicates merging the two gates to form V† gate, whilethe dashed box indicates forming a two-qubit gate with a quantum cost of 1 [16].

• • ••

(a)

(b)Figure 12. The equivalent L13L1L2L22L13 circuit using the NCT library, where (a) represents thequantum circuit with a quantum cost of 11 and (b) represents the circuit implementation on theibmq− ourense system with a quantum cost of 11.

Some circuits have less quantum cost if they are reconstructed using FunctionI 11.1,370

other circuits have less quantum cost if FunctionII 11.3 is used to reconstruct them.371

The Modified Circuit Optimization Algorithm 11.4 calculates the BPS quantum cost372

for each circuit using BPS(C) of FunctionI 11.1 and FunctionII 11.3, then it chooses the373

function, which has less BPS quantum cost in order to reconstruct the quantum circuit,374

where m represents a mark to the function having less BPS quantum cost.375

Algorithm 11.4: MODIFIED CIRCUIT OPTIMIZATION(ONCT)

for each C ∈ ONCT

do

m = BPS(C)if m = 1

then C = FunctionI(C)else if m = 2then C = FunctionI I(C)

376

377

For example, the L25L2L26L25 circuit, which is equivalent to (6, 7) permutation has378

a quantum cost of 8. The BPS quantum cost for L25L2L26L25 circuit using Function379

11.1 is 6 and the BPS quantum cost using Function 11.3 is 7, so Algorithm 11.4 chooses380

Function 11.1 to decompose the circuit, where the circuit is reconstructed using two basic381

pairs which are (L25)0(L2)0 with a quantum cost of 5, followed by (L26)0(L25)0 with a382

quantum cost of 1 according to [16]. The L25L2L26L25 circuit is shown in Figure 13 before383

optimization, after optimization and the equivalent circuit on the ibmq− ourense system384

after using the splitting rules and the preparation of negative gates as shown in Figure385

10. While the implementation of the equivalent L25L2L26L25 quantum circuit, which386

permutation is (6, 7) using the NCT library on the ibmq− ourense system has a quantum387

cost of 15 as shown in Figure 14.388

Figure 11. The L13L1L2L22L13 circuit implementation on the ibmq − ourense system, where thequantum cost of this circuit is 7. The solid box indicates merging the two gates to form V† gate; thedashed box indicates forming a two-qubit gate with a quantum cost of 1 [15].

Version June 2, 2021 submitted to Journal Not Specified 19 of 25

Figure 11. L13L1L2L22L13 circuit implementation on the ibmq− ourense system, where the quan-tum cost of this circuit is 7. The solid box indicates merging the two gates to form V† gate, whilethe dashed box indicates forming a two-qubit gate with a quantum cost of 1 [16].

• • ••

(a)

(b)Figure 12. The equivalent L13L1L2L22L13 circuit using the NCT library, where (a) represents thequantum circuit with a quantum cost of 11 and (b) represents the circuit implementation on theibmq− ourense system with a quantum cost of 11.

Some circuits have less quantum cost if they are reconstructed using FunctionI 11.1,370

other circuits have less quantum cost if FunctionII 11.3 is used to reconstruct them.371

The Modified Circuit Optimization Algorithm 11.4 calculates the BPS quantum cost372

for each circuit using BPS(C) of FunctionI 11.1 and FunctionII 11.3, then it chooses the373

function, which has less BPS quantum cost in order to reconstruct the quantum circuit,374

where m represents a mark to the function having less BPS quantum cost.375

Algorithm 11.4: MODIFIED CIRCUIT OPTIMIZATION(ONCT)

for each C ∈ ONCT

do

m = BPS(C)if m = 1

then C = FunctionI(C)else if m = 2then C = FunctionI I(C)

376

377

For example, the L25L2L26L25 circuit, which is equivalent to (6, 7) permutation has378

a quantum cost of 8. The BPS quantum cost for L25L2L26L25 circuit using Function379

11.1 is 6 and the BPS quantum cost using Function 11.3 is 7, so Algorithm 11.4 chooses380

Function 11.1 to decompose the circuit, where the circuit is reconstructed using two basic381

pairs which are (L25)0(L2)0 with a quantum cost of 5, followed by (L26)0(L25)0 with a382

quantum cost of 1 according to [16]. The L25L2L26L25 circuit is shown in Figure 13 before383

optimization, after optimization and the equivalent circuit on the ibmq− ourense system384

after using the splitting rules and the preparation of negative gates as shown in Figure385

10. While the implementation of the equivalent L25L2L26L25 quantum circuit, which386

Figure 12. The equivalent L13L1L2L22L13 circuit using the NCT library, where (a) represents thequantum circuit with a quantum cost of 11 and (b) represents the circuit implementation on theibmq− ourense system with a quantum cost of 11.

Some circuits have less quantum cost if they are reconstructed using FunctionI(Algorithm 1), other circuits have less quantum cost if FunctionII (Algorithm 3) is used toreconstruct them.

Page 18: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 18 of 23

The modified circuit optimization algorithm (Algorithm 4) calculates the BPS quantumcost 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 thequantum circuit, where m represents a mark to the function having less BPS quantum cost.

Algorithm 4 Modified Circuit Optimization (ONCT)procedurefor each C ∈ ONCT

do

m = BPS(C)if m = 1

then C = FunctionI(C)else if m = 2then C = FunctionI I(C)

For example, the L25L2L26L25 circuit, which is equivalent to the (6, 7) permutation hasa quantum cost of 8. The BPS quantum cost for the L25L2L26L25 circuit using FunctionI(Algorithm 1) is 6 and the BPS quantum cost using FunctionII (Algorithm 3) is 7, soAlgorithm 4 chooses FunctionI (Algorithm 1) to decompose the circuit, where the circuitis reconstructed using two basic pairs, which are (L25)0(L2)0 with a quantum cost of 5,followed by (L26)0(L25)0 with a quantum cost of 1 according to [15]. The L25L2L26L25circuit is shown in Figure 13 before optimization, after optimization, and the equivalentcircuit on the ibmq− ourense system after using the splitting rules and the preparationof negative gates as shown in Figure 10. While the implementation of the equivalentL25L2L26L25 quantum circuit, whose permutation is (6, 7) using the NCT library on theibmq− ourense system has a quantum cost of 15 as shown in Figure 14.

Version June 2, 2021 submitted to Journal Not Specified 20 of 25

permutation is (6, 7) using the NCT library on the ibmq− ourense system has a quantum387

cost of 15 as shown in Figure 14.388

(a)

V V† V

(b)

(c)

Figure 13. The L25L2L26L25 circuit, where (a) represents the quantum circuit with a quantumcost 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. Thedashed box indicates forming a two qubit gate and the solid box indicates forming V† gate.

• • ••

• •

(a)

(b)Figure 14. The equivalent L25L2L26L25 circuit using the NCT library, where (a) represents thequantum circuit with a quantum cost of 15 and (b) represents the circuit implementation on theibmq− ourense system with a quantum cost of 15.

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

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

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

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

12. Experimental Results393

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

proposed Negative NCT library and compares the results with relevant libraries in395

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

library which equals 5.86. The comparison includes the proposed Circuit Optimization397

Algorithm 11.2 and the proposed Modified Circuit Optimization Algorithm 11.4.398

Table 8 compares the average quantum cost of 3-qubit reversible circuits in cost015399

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

average quantum cost of the Negative NCT library after using the proposed optimization401

Figure 13. The L25L2L26L25 circuit, where (a) represents the quantum circuit with a quantum cost of8, (b) represents the quantum circuit after optimization with a quantum cost of 6, and (c) representsthe circuit implementation on the ibmq− ourense system with a quantum cost of 6. The dashed boxindicates 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 libraryhas less quantum cost for this example compared with the NCT library. Extending theNegative NCT library for n-qubits, where n > 3 is achievable since higher order gates canbe decomposed into three-qubit gates according to [30,33].

Page 19: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 19 of 23

Version June 2, 2021 submitted to Journal Not Specified 20 of 25

permutation is (6, 7) using the NCT library on the ibmq− ourense system has a quantum387

cost of 15 as shown in Figure 14.388

(a)

V V† V

(b)

(c)

Figure 13. The L25L2L26L25 circuit, where (a) represents the quantum circuit with a quantumcost 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. Thedashed box indicates forming a two qubit gate and the solid box indicates forming V† gate.

• • ••

• •

(a)

(b)Figure 14. The equivalent L25L2L26L25 circuit using the NCT library, where (a) represents thequantum circuit with a quantum cost of 15 and (b) represents the circuit implementation on theibmq− ourense system with a quantum cost of 15.

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

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

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

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

12. Experimental Results393

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

proposed Negative NCT library and compares the results with relevant libraries in395

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

library which equals 5.86. The comparison includes the proposed Circuit Optimization397

Algorithm 11.2 and the proposed Modified Circuit Optimization Algorithm 11.4.398

Table 8 compares the average quantum cost of 3-qubit reversible circuits in cost015399

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

average quantum cost of the Negative NCT library after using the proposed optimization401

Figure 14. The equivalent L25L2L26L25 circuit using the NCT library, where (a) represents thequantum circuit with a quantum cost of 15 and (b) represents the circuit implementation on theibmq− ourense system with a quantum cost of 15.

4. Experimental Results

This section describes the experiments on three-qubit reversible circuits based on theproposed Negative NCT library and compares the results with relevant libraries in [15–19].The Negative NCT library shows an average length as in the NCT library, which equals5.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 thecost015 metric using the proposed Negative NCT library and the works found in theliterature, where the average quantum cost of the Negative NCT library after using theproposed modified circuit optimization algorithm (Algorithm 4) is 10.078, while the av-erage quantum cost of the Negative NCT library using the proposed circuit optimizationalgorithm (Algorithm 2) is 10.202. Finally, the quantum cost of the Negative NCT librarybefore optimization is 13.364. Table 8 compares the obtained results with other librariesin [15,18,19], where the average quantum cost after optimization is 10.348 in [15], 13.388in [18] and 13.290 in [19].

Table 9 compares the average quantum cost of three-qubit reversible circuits in cost115metric using the proposed Negative NCT library after applying the proposed optimizationalgorithms (Algorithms 2 and 4) with the works found in the literature. Table 9 showsthe average quantum cost of the Negative NCT library after applying the proposed mod-ified circuit optimization algorithm (Algorithm 4) is 11.209, while the average quantumcost of the Negative NCT library after applying the proposed circuit optimization algo-rithm (Algorithm 2) is 11.333. The average quantum cost of the NCT library using theoptimization algorithm in [15] is 12.591.

There is an inverse proportional relationship between the quantum cost and thenumber 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 proposedmethod in this paper because this method uses a single ancillary qubit, while Algorithm 4is applied without using any ancillary qubits.

The proposed approach uses negative control gates, which is more stable becauseit depends on the ground state of the quantum system, which will help in building realquantum computers because one of the biggest challenges in building practical quantumcomputers is the decoherence and the instability of the quantum system. Furthermore,the proposed algorithm produces low-cost quantum circuits, which will help in buildingstable medium scale and small scale quantum computers because it will help in makingthe computation perform faster to overcome the decoherence of the quantum system overa long period of time.

Page 20: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 20 of 23

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 A0 denotes the Negative NCT library’s specification beforeoptimization. A1 and A2 denote the number of specification with minimum quantum cost produced by the proposed circuitoptimization 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], NR3 denotes the number ofspecifications with minimum quantum cost shown in [18], NM3 denotes the number of specifications with minimumquantum cost shown in [19], and NCT denotes the number of specifications with minimum quantum cost shown in [15].

Minimum Cost NT [18] NR3 [18] N M3 [19] NCT [15] A0 A1 Algorithm 2 A2 Algorithm 4

0 8 8 8 8 8 8 81 0 0 0 48 48 109 1112 0 0 0 324 189 488 4593 0 0 0 607 402 467 4594 0 192 192 601 465 604 7055 94 0 0 1148 240 1319 14926 0 0 0 2462 366 2605 25947 0 851 2136 3576 1386 3204 33388 16 2591 1300 2710 3087 3844 43589 340 0 0 2855 2921 4159 411510 288 636 0 5601 537 4733 440811 32 6050 11,916 6567 1255 4342 417512 179 9354 4064 3183 4563 4184 418413 790 396 0 2043 7305 3693 374114 1487 2829 3294 3771 3141 2801 271115 324 7175 7242 3496 447 1488 137316 574 6331 6137 1284 2178 1020 98317 2052 344 0 36 4819 680 64818 3616 1200 1117 0 3809 280 24019 1462 1278 1484 0 574 128 8320 1041 1053 1387 0 501 79 6621 3405 9 0 0 1185 57 4822 5357 14 0 0 614 25 1823 2894 2 0 0 37 3 324 1435 7 43 0 0 0 025 3191 0 0 0 149 0 026 4369 0 0 0 86 0 027 2436 0 0 0 4 0 028 806 0 0 0 0 0 029 1444 0 0 0 0 0 030 1482 0 0 0 4 0 031 761 0 0 0 0 0 032 125 0 0 0 0 0 033 126 0 0 0 0 0 034 109 0 0 0 0 0 035 60 0 0 0 0 0 036 6 0 0 0 0 0 0

Avg 22.321 13.388 13.290 10.348 13.364 10.202 10.078

Page 21: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 21 of 23

Table 9. Comparing the quantum cost of the proposed Negative NCT library using the proposedoptimization algorithms (Algorithms 2 and 4) with related work in cost115, where B1, B2 denotes thenumber of specification with minimum quantum cost produced by the proposed circuit optimizationalgorithm (Algorithm 2) and the proposed modified circuit optimization algorithm (Algorithm 4),respectively. The NCT denotes the number of specifications of the NCT library with minimumquantum cost shown in [15].

Minimum Cost NCT [15] B1 Algorithm 2 B2 Algorithm 4

0 0 0 01 9 18 182 72 133 1303 299 428 4004 551 545 5645 519 720 8036 728 1334 14307 1715 2256 23718 2976 3315 33859 3060 3867 406410 2366 4099 432211 2923 4256 411012 4417 4336 415013 4717 4018 391814 3513 3625 365615 2637 2803 277716 2385 1711 160717 2260 1142 104618 2021 752 73819 1543 464 42720 994 225 19121 474 127 9122 130 73 6723 10 47 3224 0 20 1725 0 4 426 0 1 1

Avg 12.591 11.333 11.209

5. Conclusions

This paper proposed two algorithms (The circuit optimization algorithm and themodified circuit optimization algorithm), both of which use basic pairs as building blocksto reconstruct the circuit, choosing between the two proposed pairing functions (FunctionIand FunctionII) depending on the nature of the circuit; both show better results compared toreconstructing the circuit with a fixed pairing function regardless of the nature of the circuitas in the modified circuit optimization algorithm and the circuit optimization algorithm,respectively. The modified circuit optimization algorithm is applied to the Negative NCTlibrary with an average quantum cost of 11.209 in cost115 metric and 10.078 in cost015metric 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 comparedwith related optimization methods from the literature and the comparisons show that theaverage minimum cost of the proposed Negative NCT library is 10.078 in the cost015 metricand 11.209 in the cost115 metric, which is less than NT, NCT, NR3, and NM3 libraries. Thecomparison showed that using Negative NCT library instead of NCT library gives lessquantum cost, which equals 10.078.

Page 22: Optimization of Reversible Circuits Using Toffoli

Symmetry 2021, 13, 1025 22 of 23

The proposed algorithms work with universal libraries that use a set or a subset ofNOT, OCNOT, and OToffoli gates. This work can be extended by finding other pairingfunctions 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 thepublished 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 viewsexpressed are those of the authors, and do not reflect the official policy or position of IBM or the IBMQuantum team.

Conflicts of Interest: The authors declare that they have no conflict of interest.

References1. 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 Quantum Information; 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. Electron. 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.

Page 23: Optimization of Reversible Circuits Using Toffoli

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 decompositiontechniques. 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 obtainedher 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 teachingassistant at Egypt-Japan University of Science and Technology (E-JUST), she was a research assistantand laboratory engineer at E-JUST University from 2017 to 2020.

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