Group-Theory-Approach-to -Reversible-Logic

• April 25, 2011
A Constructive Group
Theory based
Algorithm for
Reversible Logic
Synthesis
Main Ideas
1. We know many representations of reversible
circuits, such as reversible vectors, truth tables,
Kmaps and permutative unitary matrices.
2. In this lecture we will learn one more useful
representation – a set of cycles.
3. A cycle can be decomposed to transpositions.
Set of transpositions is another representation.
4. This is the initial paper in “group-theory
approach to quantum circuits synthesis”
Background
•
Reversible logic plays an important role in quantum computing;
– oracles are reversible (permutative) circuits.
•
•
Any computing system of irreversible logic gates leads inevitably to energy
dissipation.
To avoid power dissipation, circuits must be constructed from reversible gates.
–
–
–
–
•
De Vos – CMOS
Optical
DNA
Nano-technologies
There are a lot of research on the construction of reversible logic gates and
circuits:
– De Vos 1998, group theory.
– Kerntopf 2000, enumerative – decision diagrams.
– Perkowski et al. 2001, exor logic, spectral, group theory, heuristic, genetic algorithm,
exhaustive.
– Markov et al 2002, exhaustive, group theory.
– Yang et al, 2003 – group theory approach – GAP and exhaustive search
– Miller, Dueck and Maslov 2003, spectral and heuristic non-optimal algorithm
– Aggrawal and Jha 2004, heuristic RM-transformation-based.
Definition 1 (Binary reversible gate):
• Let B = {0, 1}.
• A binary logic circuit f with n inputs and outputs is denoted by
a binary multiple-output function f : Bn  Bn.
• Let B1,…, Bn   Bn and P1,…, Pn   Bn be the input and
output vectors,
– where B1,…, Bn are input variables
– and P1,…, Pn are output variables.
• There are 2n different assignments for the input vectors.
• A binary logic circuit f is reversible if it is a one-to-one and
onto function (bijection).
• A binary reversible logic circuit with n inputs and n outputs is
also called an n-qubit binary reversible gate.
• There are a total of (2n)! different n-qubit binary reversible
circuits.
Permutations,
Cycles and
Transpositions
Permutation groups and their relationship
with reversible circuits
• Definition 2 (Permutation): Let M = {d1, d2 ,
, dk}.
• A bijection of M onto itself is called a permutation on M.
• The set of all permutations on M forms a group under
composition of mappings, called a symmetric group on M.
• It is denoted by Sk.
• A permutation group is simply a subgroup of a symmetric
group.
Mappings and cycles
• A mapping s : M  M can be written as:
(
(
d1 , d2 ,.., dk
di1 , di2 ,.., di1
(1)
• Here we use a product of disjoint cycles (Definition 3) as an
alternative notation for a mapping.
• For example,
can be written as (d2, d4) (d3, d7) (d6, d8).
(
(
d1 , d2 , d3 ., d4 , d5 , d6 , d7 , d8 , d9
d1, d4 , d7 , d2 ,d5 , d8 , d3 , d6 , d9
(2)
Identity
minterm
F(a14) = a14
F(1101) = 1101
F(13) = 13
0
1
2
3
4
5
6
7
0
1
2
3
4
5
6
7
Identity function as a mapping
Identity function as a circuit
Simple function
Simple function has
many identity
minterms, N is small
0
1
2
3
4
5
6
7
The function is a single 2cycle (6,7)
0
1
2
3
4
5
6
7
Toffoli gate as a mapping
Toffoli gate as a circuit
Simple function
Simple function has
no identity minterms
N is high but function is simple
0
1
2
3
4
5
6
7
The function has four 2-cycles
(0,1), (2,3), (4,5) and (6,7)
0
1
2
3
4
5
6
7
Identity function as a mapping
Identity function as a circuit
Problem to be solved has simple formulation
It is a kind of “Rubik Cube” game
0
1
2
3
4
5
6
7
0
1
2
3
4
5
6
7
Feynman
0
1
2
3
4
5
6
7
Toffoli
0
1
2
3
4
5
6
7
Feynman
0
1
2
3
4
5
6
7
0
1
2
3
4
5
6
7
Fredkin
Patterns based on
transpositions and
costs based on
transpositions
Distance Histogram of a function
0
1
2
3
4
5
6
7
0
1
2
3
4
5
6
7
How many minterms
in distance k cycle
6
How many
minterms in
distane k
cycle
0
1
2
3
Distance k cycle
8
0
1
2
3
4
5
6
7
0
1
2
3
4
5
6
7
0
1
2
3
Distance k cycle
Notation
• Denote “( )” as the identity mapping (i.e.,
direct wiring) and call this the unity element
in a permutation group.
• A product f * g of two permutations applies
mapping f before g.
Cascading gates and permutations
• A n-qubit reversible circuit is a permutation
in S2n, and vice versa.
• Cascading two gates is equivalent to
multiplying two permutations in S2n.
• Thus, in what follows, we will not
distinguish a n-qubit reversible circuit from
a permutation in S2n.
Definition 3 (‘j’-cycle):
• Let Sk be a symmetric group
of symbols {d1, d2,…,dk},
then (di1 , di2 ,…, dij ) is
called
a ‘j’-cycle,
– where j  k, 1  i1 ,
i2 ,…, ij  k.
0
1
2
3
4
5
6
7
0
1
2
3
4
5
6
7
Cycle (0,1,2,3)
Realizations of the same cycle
0
1
00
Cost 1+2=3
0
1
2
01
11
(0,1,2) = (0,2) * (1,2)
10
We should select the set of 2-cycles with the
minimum total distance
0
1
00
Cost 1+1=2
01
11
10
0
1
2
(0,1,2) = (0,1) * (0,2)
This is better
• Definition 4 (NOT gate):
• A NOT gate Nj connects an inverter to the j-th
wire, i.e.: Pj = Bj  1, Pi = Bi , if i  j . 1  j  n:
• An example NOT gate is shown in figure 1.
Definition 5 (‘n-1’-CNOT gate):
• A ‘n-1’-Controlled-NOT (CNOT)
gate Cj is defined as follows:
•
If m  j, then Pm = Cj (Bm) = Bm .
•
If m = j, and Bi = 1 for all i  j,
then Pj = Cj (Bj ) = Bj  1; else,
Pj = Bj .
• An example ‘4’-CNOT gate is
shown in figure 2.
• A ‘n-1’-CNOT gate is a
generalized Toffoli gate where
two inputs control an output of
another input.
These are “big Toffoli gates” that
we want to avoid in general
MMD and New
methods
1. MMD is a specific algorithm that processes
permutation vectors (truth table) in such a way
that the set of self-mapping minterms grows
from top.
2. This can be rewritten to our new notation.
3. But this is only one way of realizing
permutation from transpositions.
4. We should investigate more of them.
MMD method
0
1
2
3
4
5
6
7
0
1
2
3
4
5
6
7
0
1
2
3
4
5
6
7
Our idea here is to
decompose to 2-cycles
of the minimum total
distance
0
1
2
3
4
5
6
7
We add
identity
minterms
from top
MMD method can
start from function
with small N and
make it a new
function with big N
Distance 3 function – Miller
0
1
2
3
4
5
6
7
0
1
2
3
4
5
6
7
Distance 1 function – Toffoli
0
1
2
3
4
5
6
7
0
1
2
3
4
5
6
7
How many minterms in distane k
cycle
6
0
1
2
3 Distance k cycle
Distance 2 function – Fredkin
0
1
2
3
4
5
6
7
0
1
2
3
4
5
6
7
Programs for reversible logic
MMD
Function
(permutation)
with high N
MMDS
Greedy
Reduce N
This can be greedy
or evolutionary
algorithm
Perform
heuristic
search with
one ordering
Function
with small N
Perform heuristic
search with many
orderings
Template
Distance
Perform local
optimization to
reduce costs
of gates
Decompose to
smallest
distance gates
III. THEORETICAL RESULTS
on decomposing to cycles
• The process to constructively synthesize any
‘n’-qubit reversible circuit by Not and ‘n-1’CNOT gates without ancilla qubits.
• Lemma 1: Every permutation can be
decomposed to some ‘2’-cycles.
2-cycle = transposition
Hamming Distance one
Transpositions or “Neighboring 2cycles”
• Remark 1:
• This lemma is a well-known result in group
theory
• Definition 6 (neighboring ‘2’-cycle):
• If two n-dimension vectors u, s have only
one bit difference, we call the permutation
(u, s) a neighboring ‘2’-cycle.
Realizations of the same cycle
0
1
00
Cost 1+2=3
0
1
2
01
11
(0,1,2) = (0,2) * (1,2)
10
We should select the set of 2-cycles with the
minimum total distance
0
1
00
Cost 1+1=2
01
11
10
0
1
2
(0,1,2) = (0,1) * (0,2)
This is better
Lemma 2:
• Suppose between u and s, there is only one bit Bj
different, and i same bits are zeros.
• These zero bits are Bi1 ,…, Bil .
• Then,
(u , s) = Ni1 * … * Nil * Cj * Nil * … * Ni1 (4)
This is a distance 1 decomposition
of a 2-cycle
Lemma 3: Decomposition to
distance-1 transpositions
If two n-dimension vectors u , s have k bits different, then
there is an ordered set
M = {d1, d2 ,.., dk+1 }
such that d1 = u , dk+1 = s and for any i,
1  i < k + 1,
there is only one bit difference between di and di+1, and
(u , s) = (d1, d2)(d2 , d3) … (dk , dk+1)
(dk , dk-1) … (d2 , d1)
This is a decomposition of a 2-cycle to 1distance cycles. Total distance cost should
be minimized
(5)
• Decomposing to sequences of neighbor
minterms in transpositions
•
In order to make the number of NOT gates as small as possible, we give two rules for
constructing the ordered set M.
•
If the number of 1’s in the vector u is more than that in s,
then d1 = u , dk+1 = s. Else, d1 = s , dk+1 = u.
•
In the different bits between u and s, change the zero bit to one first, then change one bit to
zero bit.
•
For example, if u = (0 , 1 , 0 , 0 , 0 ), s = (0 , 0 , 1 , 1 , 1),
then k = 4; d1 = s , d5 = u and, d2 , d3 , d4 are given in the following table.
Hamming Distance anD “Distance-gates”
0
Various Distance 3 gates
1
00
When F(a) = b, (or (a,b) is a 2cycle) Hamming distance of a and
b is 3
01
11
10
0
1
All Distance 1 gates
00
01
11
10
When F(a) = b, Hamming distance
of a and b is 1
REMOVAL OF NOT gates
• can remove a pair of the adjacent NOT
gates in the same quantum wire.
• Lemma 4: (complexity of NOT gates)
• In decomposing ‘2’-cycle (u , s) to NOT gates and ‘n-1’-CNOT gates,
suppose there are j bits different between u and s, and there are j0 zero
bits in these bits in d1 and j1 one bits in these bits in d1, where j0  j1,
then the number of NOT gates is no more than 2(j - 2) + 2(j0 - 1) if j0 
1 , or 2(j-1) if j0 = 0.
Theorem 1:
• For a given n-qubit reversible circuit f, if
there are N distinct input patterns that are
different from their corresponding outputs,
where N  2n, and the other (2n - N) input
patterns are the same as their outputs, then
this circuit can be synthesized by at most 2n
* N ‘(n - 1)’- CNOT gates and 4n2 * N NOT
gates without ancilla qubit.
Theorem 2:
All n-qubit reversible circuits can be
constructed by:
• less than 2n * 2n NOT gates
• and less than (2n - 1) * 2n ‘n - 1’-CNOT
gates
• without ancilla qubit.
ALGORITHM
•
•
Step 1.
Check the truth table of f to determine before using equation 3 and lemma 3,
whether we need NOT gates or not.
•
•
Step 2.
After step 1, write the reversible circuit in a product of cycles form.
•
For every cycle (d1, d2 ,…, dk), calculate the number ri of different bits
between di and di+1, i = 1, 2 ,…, k where dk+1 = d1.
•
Let rj be the maximal number.
•
The basic idea to decompose the reversible circuit by equation 3 is to break
the mapping relation from dj to dj+1 without increasing the number of different
bits between adjacent vectors.
• (d1, d2 ,…, dk) = (dj , dj+1) (dj , dj+2 , dj+3 ,…, d1)
(6)
ALGORITHM (cont)
• Recursively repeating this process, we
decompose the reversible circuit to ‘2’cycles.
• Step 3.
• Decompose every ‘2’-cycles by NOT and ‘n1’-CNOT gates by Lemma 3, two rules in
remark 2, lemma 2, and remove pairs of
adjacent NOT gates when possible.
COMPLETE
SYNTHESIS
EXAMPLE WITH
NON-MINIMIZED
TOFFOLI GATES
SYNTHESIS EXAMPLE
•
Given a binary reversible
circuit f which has a truth
table as shown in Table II.
• Therefore,
f = (a1, a3, a4 , a16) (a2 , a6 ,
a14).
•
•
Step 1.
The total number of
changed vectors is 7, less
than 24-1 = 8, thus, we deal
with the input reversible
circuit f without precascading NOT gates.
•
•
Step 2.
Decompose each cycle into
the product of 2-cycles by
using equation 6.
a4=1100
a16=1111
d2
a4=1100
N2 * N2= ()
a3=0100
(a1,a3,a4,a16)
(a2,a6,a14)
(a4,a16) (a4,a3) (a1, a3)
d2
d1
d1
d1
(a6,a14) (a6,a2)
d1
d1
a6=1010
a6=1010
a14=1011
a2=1000
d1
d1
inverters
C3
(a4,a16) (a4,a3) (a1, a3)
d2
C3
N3
d1
C4
d1
(a6,a14) (a6,a2)
d1
d1
• The synthesis
process is finished,
and f is decomposed
into the product of 12
NOT gates and 7 ‘n1’-CNOT gates,
shown in figure 3.
IMPROVED
SYNTHESIS
METHOD BASED ON
“DISTANCE GATE”
New idea = a better way to
implement transpositions (13,14)
abcd
a
a4=1101
b
a16=1110
c
d2
d
Realization of transposition (1101, 1110) = (13,14)
HD =2
New idea = a better way to
implement transpositions (12,15)
abcd
a4=1100
a16=1111
d2
d2
a
b
c
d
0
1
0
1
1
Realization of transposition (1100, 1111) = (12,15)
a
b
HD =2
c
d
1
1
0
0
0
New idea = a better way to
implement transpositions (12,15)
abcd
1
a
a4=1100
b
a16=1111
c
d2
d
1
0
1
1
1
0
1
Realization of transposition (1100, 1111) = (12,15)
a
b
HD =2
c
d
1
1
1
0
0
0
0
1
New idea = a better way to
implement transpositions (12,11)
abcd
a
a4=1100
b
a16=1101
c
d2
d
1
1
1
1
1
0
0
0
0
0
0
11001100
no change
Realization of transposition (1001, 1110) = (9,14)
a
b
HD =2
c
d
1
1
1
1
0
0
0
0
1
1
1
0
1
11011101
no change
New idea = a better way to
implement transpositions
abcd
a
a4=1001
b
a16=1110
c
d2
d
1
0
1
0
0
1
1
1
0
0
0
1
0
10101010
Realization of transposition (1001, 1110) = (9,14)
a
b
HD =2
c
d
1
0
1
1
0
0
1
1
1
0
1
1
1
0
Here we see the transposition in action
10011110
Distance gates
1. The gates shown in last few slides are
called “Distance gates”.
2. They are all inexpensive and realize
transpositions.
3. By adding inverters on inputs and outputs
of these gates a wider category (called
family) of these gates is created.
4. We should consider the widest family and
find synthesis methods (algorithms) for
them.
CONCLUSIONS
• The concept of decomposition of permutation to cycles
• The concept of decomposition of cycle to 2-cycles
• The concept of distance-k-gates and decomposition with smallest total
distance
• A constructive algorithm for synthesizing reversible circuits by NOT and
‘n-1’-CNOT gates
• Synthesis examples based on this algorithm, which show that even by
hand, synthesizing any ‘4’-qubit reversible circuit is not difficult.
Especially for functions with small N.
• The computational complexity of our synthesis algorithm is exponentially
lower than the complexity of breadth-first search based synthesis
algorithm.
• To be used as part of a comprehensive system of programs
CONCLUSIONS
1. Knowledge reduces search – group theory
2. Knowledge is not sufficient to find minimal solution
– search is necessary
3. Role for evolutionary algorithms, PSO, immune,
etc
4. We found some heuristics, more are needed.
5. Based on last section, the method can be
improved, which is a good project.
What to remember?
1.
2.
3.
4.
5.
Permutation vectors, versus sets of cycles.
How to decompose cycles to transpositions?
The best decomposition to transpositions.
Old method of decomposition and its realization.
New proposed method of decomposition to
transpositions
6. Realization of a “distance gate” for a
transposition.
7. Useful theorems of group theory, their use in
synthesis.
8. How to compose transpositions?