Efficient Algorithms for Optimal 4-Bit Reversible Logic System Synthesis

Owing to the exponential nature of the memory and run-time complexity, many methods can only synthesize 3-bit reversible circuits and cannot synthesize 4-bit reversible circuits well. We mainly absorb the ideas of our 3-bit synthesis algorithms based on hash table and present the efficient algorithms which can construct almost all optimal 4-bit reversible logic circuits with many types of gates and at mini-length cost based on constructing the shortest coding and the specific topological compression; thus, the lossless compression ratio of the space of n-bit circuits reaches near 2×n!.This paper presents the first work to create all 3120218828 optimal 4-bit reversible circuits with up to 8 gates for the CNT (Controlled-NOT gate, NOT gate, and Toffoli gate) library, and it can quickly achieve 16 steps through specific cascading created circuits.


Introduction
Quantum computer is equivalent to quantum Turing machine, and quantum Turing machine is equivalent to a quantum logic circuit.Therefore, the quantum computer can be constructed by cascading and combining the quantum logical gates.Nowadays, many kinds of reversible quantum gates have been proposed, for example, CNOT gate [1], Toffoli gate, and Fredkin gate [2].How to automatically construct the quantum circuit at small cost using given quantum gates?Several approaches for reversible logic circuit synthesis have been presented.Song et al. [3] presented algebraic characteristics of reversible gates.Iwama et al. [4] introduced transformation rules for CNOT-based circuits.Miller et al. [5] gave a synthesis method based on truth table and used template technology to simplify the circuit.Mishchenko and Perkowski [6] proposed a Reed Muller-based algorithm for optimizing quantum circuit.Gupta et al. [7] also gave a heuristic algorithm based on Reed Muller; Li et al. [8] proposed a general template algorithm.Shende et al. [9,10] reduced the synthesis for reversible logic circuit to permutation and gave an effective recursive algorithm.Then, Yang et al. [11] reduced the synthesis for reversible logic circuit to group theory and presented a novel algorithm based on group-theory algebraic software GAP, while its performance was better than most others.Until today, we have not found a general and effective algorithm for multivariable quantum circuit synthesis.Owing to the exponential nature of the memory and run-time complexity, many existing methods can only synthesize 3-bit reversible circuits, and they perform only four steps for the CNP library in 4-bit circuit synthesis with mini-length for memory overflow [11][12][13], however, [14][15][16] are able to achieve 12 steps by using an enhanced bidirectional synthesis approach.We mainly absorb the ideas of our efficient 3-bit synthesis algorithms based on hash table and present the novel and efficient algorithms which can construct almost all optimal 4-bit reversible logic circuits [17].Using lossless compression and cascading created circuits, our algorithms can get all the mini-length circuits whose lengths range from 0 to 8 with numbers 1,28,576,9886,147841,1986374,24375385,274500662, and 2819198076, respectively; it can synthesize all the optimal 16-gate mini-length circuits for the CNT library.

Background
Definition 1.Let  be a finite set; then, a permutation of  is a bijection  :  → .
(5) Let cost() be the cost of quantum circuit  and cost() be the cost of quantum gate .
(6) All the circuits in the paper are the reversible logic circuits.
Because permutation is often used in our algorithms, the effective expression of permutation is very important to improve the algorithms.Thus, we present the shortest coding scheme with saving plenty of space, which maps a permutation to an integer with the fewest bytes.

Lemma 6.
If the ordinal number sequences of two permutations are the same, then the two permutations must be also the same.

Proof by Mathematical Induction
Basis.Clearly, and  has  2  −2− elements which are both lesser than and before )th small element in  −   .Now, using the inductive assumption, we get   =   ; that is,  −   =  −   , and so

Lemma 7. The coding function Code maps each ordinal number sequence to a distinct coding.
Proof.
) to coding , and so the remainder is , and the remainder is  2  when this quotient is divided by 3. Follow the same steps; the recursive formula is Clearly, the coding function Code maps each ordinal number sequence to a distinct coding, and vice versa; so, it is a one-to-one correspondence between each coding and ordinal number sequence.

Theorem 8. The function Code is the shortest coding function.
Proof. 2  different elements in {0, 1, . . ., 2  −1} totally have 2  !permutations.According to Lemma 6, two different ordinal number sequences corresponding to two permutations must be different, and according to Lemma 7, coding function Code maps each ordinal number sequence to a distinct coding.So, the codings of all permutations are different.
Figure 2: The line permutation of quantum circuit.

By Definition 5, max(𝑂
. There are 2  different elements in {0, 1, . . ., 2  − 1} corresponding to 2  !different coding, and thus the minimum number of all the codings is 2  !. Therefore, the function Code is the shortest coding function. The subject of topology is concerned with those features of geometry which remain unchanged after twisting, stretching, or other deformations of a geometrical space; any continuous change which can be continuously undone is allowed, but cannot be broken.Definition 9. Line permutation is the operation which permutes quantum lines in quantum circuit without break.Obviously, it is a specific topological transformation.Let   () be quantum gate  being operated by line permutation .The circuit  =  1  2 , operated by line permutation , is For example, in Figure 2, quantum circuit  is operated by line permutation , where  = ( 0 1 2 2 0 1 ) = (0 2)(0 1).The circuit after applying topological transformation can be simplified, because the gate's function cannot be changed when the order of its same kind of points is changed. Consider If there are  basal gates in quantum gate library ,  1 ,  2 , . .., and   , then  = ⋃ ∈,∈    (  ) , and the set of all permutations of the gates in  is  = ⋃ ∈,∈    ((  )).
The set of all circuits of  operated by line permutation  is denoted by   () = {  () |  ∈ }.Definition 10.Direction transform (Figure 3) has two kinds of operations, obverse direction transform and reverse direction transform.It is also a specific topological transformation; the obverse direction transform  of gate  is denoted by   ().Thus,  0 () = ,  1 () =  −1 .Gate  is symmetric, if  =  −1 , and otherwise it is asymmetric.Let circuit  =  1  2 , and the two gates are symmetric; then, , if all the gates in  are symmetric.Direction transform can be used in our synthesis algorithms only if all quantum gates are symmetric or their inverse gates are all in the quantum gate library.
The set of all circuits of  operated by direction transform  is denoted by   () = {  () |  ∈ }.
From Definitions 9 and 10, the following properties can be gotten.
Property 3.   (  ()) =   (  ()), where   (  ()) denotes the circuit  being operated by line permutation  and direction transform , and   (  ()) denotes that the circuit  is operated by direction transform  and line permutation .Line permutation is vertical transform, and direction transform is horizontal transform; so, the order of the two operations does not affect their compound function, and thus   (  ()) =   (  ()).
We show by Properties 1, 2, and 3 that the order of the previous topological transformations except the line permutations in quantum circuits can not affect their compound functions.
Proof.Consider any quantum gate , operated by any line permutation   , whose type is not changed so, cost(   ()) = cost().When any quantum circuit  is operated by any direction transform, its direction may be changed, but its cost can not be changed; thus, for all  ∈ , cost(  ()) = cost(), and then cost(  ( , where cost() of optimal  should be minimal with the cost function.If for all  ∈ {1, 2, . . ., }, cost(  ) = 1, then cost() = ; that is, the length of  is minimal, and thus minimum cost standard degenerates to mini-length standard.
Let  , be an -bit quantum gate library with gates , and ( , ) a set of all -bit reversible circuits synthesized by any gates in  , .For example, 2 × !| =4 = 48.The average compression ratio of ( 4,CNT ), whose circuits are synthesized 8 layers at minimal cost, is 47.95.
Taking all specific topological transformations of a 3-bit circuit as an example, there are 2 × !| =3 = 12 kinds of transformations.In Table 2, the bidirectional arrow expresses exchanging the two quantum lines, and the minimal permutation circuit of all circuits is circuit  by computing coding.
The way of computing the shortest coding of circuit  in Table 2 is given.
Definition 16.Given two circuit sets  and , the set of all circuits of  cascaded by all circuits of  is denoted by Lemma 17.Given two circuit sets  and ,   (×) =   ()×   ().
For saving memory, we only store minimal permutation circuits Min(  ).The common computing method is that, firstly,   can be gotten by decompressing Min(  ), secondly,  +1 can be gotten by   ×, and lastly, Min ( +1 ) can be gotten by compressing   × .Its number of decompressing circuit is 2 × ! × |Min(  )|, but ours is zero based on Theorem 15.The number of cascading circuit and the number of compressing circuit in the common method all are ! times than ours; so, our method is better.

New Synthesis Algorithm
A quantum logic gate realizes certain permutation in essence; quantum circuit is the cascade of some quantum gates, and so the basic function of quantum circuit can be represented the multiplication of permutations.The basic idea of the hash-based 3-bit synthesis algorithm which we previously Hash table Key: advanced is constructing an optimal circuit using WFS, making a one-to-one correspondence between the elements in the hash table and different circuits.Thus, we need only one step to check whether the circuit of the same function has already been found to decide whether it is optimal.But it is unfeasible if we use this algorithm directly in 4-bit circuit synthesis, since the length of the hash table is at least  2 !; so, it is extremely memory consuming.Otherwise, if we use DFS, it will be meaningless that the algorithm runs too slowly or can not realize optimal.To sum up, we adopt the BFS, with higher speed and more synthesis capability, and some lossless data compression methods to reduce memory consumption.
(1) Represent the permutation using the shortest encoding.Only ⌈log 2  ! 2 | =4 ⌉ = 45 bits is required to represent 4-bit circuit permutations using the permutation encoding method in Definition 5, rather than 64 bits as usual.
(2) Compress the optimal circuits without loss.Using line permutation alone, nearly !| =4 = 24 times compression can be reached, while using both line permutation and direction transformation, nearly !× 2| =4 = 48 times compression can be reached, which is the backbone of this paper.
(3) Use hash table with length 2 16 in the top of the data structure, with each element pointing to a different RB tree in Figure 4 and each node in the tree reduces 2 bytes.Hash table and RB tree always remain effective, and RB tree can also allocate the memory dynamically.Therefore the data structure can not only permit a faster access speed, but also save memory space.
How to determine the length of hash table?Let the permutation of -bit circuit be , whose shortest coding is Code(Min()), {0, 1} ⌈log ! 2 ⌉ in binary.Use the rear  × 8 bits as the hash address, the rest ⌈log ! 2 ⌉ −  × 8 bits as the value of the nodes in the RB tree.Suppose that the length of the elements in hash table is  bytes; so, hash table uses  × 2 8 bytes while the RB tree saves  × |[]| bytes, and the maximum space this structure saves is max (, , ) =  × |[]| −  × 2 8 .Take the 4-bit circuit based on CNT quantum gate library as an example; each element in hash table is a pointer pointing to the different tree, taking 4 bytes.The number of minimum permutation circuits with length 8 is 58777916, when  = 2, and the maximum of the function is (2, 4, 8) = 117293688; so, the optimal length of hash table is 2 8 | =2 = 65536.
In this paper, we use BFS to get all the first  layers of optimal circuits.If the gate library is determined, then the optimal circuits are determined.In order to save time, we store all minimum permutation circuits in the first  layers in a file.If CNT gate library is used, then  = 8, and we get a 700 MB file.As there are considerable gates in the 4-bit circuit quantum gate library, thus lots of optimal circuits are generated at each length.When a circuit reaches a certain length, the memory will overflow, and so  has practical upper lower limit related to memory.After the lossless compression mentioned earlier, only the minimum permutation circuits are stored, saving 47.95 times less of circuits.The length of the overall synthesis circuits reaches 8 instead of 6, 117.7 times larger; the synthesizable length grows form 12 to 16 [14].

}
To enhance readability, two ways are used to simplify the algorithms.
(1) All permutations are not transformed into the relevant shortest codings.
(2) The hash table in the top of Figure 4 is omitted, and all the minimum permutation circuits in each layer are only saved in a RB tree; for example, [] is the RB tree which has saved all minimum permutation circuits with length .

Algorithm for the Minimal Permutation Quantum
Reversible Logic Circuits Representation in QML.For more details, see Algorithm 2.

General Algorithm for the Quantum Reversible Logic Circuits Representation in QML (Algorithm 1).
For more details, see Algorithm 3.

Experimental Results
Our experiments were conducted using many benchmark functions for 4-bit reversible logic circuits synthesis, and [14,15] dealt with the synthesis of 4-qubit circuit for the high complexity of the algorithm.Based on CNP quantum gate library, using the mini-length as criteria, [14]  in the basis of [11] through bidirection synthesis, and another 4 layers by combining DFS, thus realized a 12 layers synthesis of arbitrary circuits.Yet [14] can only synthesize the first 4 layers of the optimal circuit at a time, while in our previous study, for example, the hash-based 3-bit synthesis algorithm, the average speed of the mini-length and minimum cost are 49.15 and 365.13 times of [11], respectively.In this paper, we used CNT quantum gate library and mini-length criteria, creating all optimal circuits with up to 8 gates.By bidirection cascading the generated circuits, we can quickly synthesize the optimal quantum circuits within the length of 16, without consuming more memory.Our bidirection cascading is quite different with the bidirection synthesis used in [14]; they calculated the head and tail of the circuit, respectively, then moved forward to the middle.In order to avoid repeated computation, we first synthesize the former parts of the circuit, then perform specific topology transformations on them and reuse them in the latter part.

Conclusions
Based on the idea that the synthesis of reversible logic circuit is a permutation problem in essence, we present the novel and efficient quantum circuit synthesis algorithms.Among them, we elaborately construct a shortest encoding method of the permutation and compress the memory space of the -bit optimal circuits to 2 × ! times less using certain topology transformation of quantum circuits.By bidirectional cascading of the generated optimal circuits, using several quantum gates and the mini-length cost metric, our algorithms can efficiently generate most optimal 4-bit reversible logic circuits.

Figure 3 :
Figure 3: The direction transform of quantum circuit.

Figure 4 :
Figure 4: The data structure of the minimal permutation circuit with length .

Table 2 :
All the specific topological transformations of 3-bit logic circuit.