Problemadvanced
Reversible logic synthesis
Also called reversible circuit synthesis.
Build a circuit of reversible gates, such as Toffoli gates, that computes a given permutation of bit vectors with the fewest gates or quantum cost.
Reversible logic synthesis takes a reversible Boolean function, a bijection of the bit vectors of length , and builds a cascade of reversible gates that computes it. The usual gates are NOT, CNOT, the Toffoli gate and their generalization with more controls. The circuit has no fan-out and no feedback: each gate acts on the current values of the lines and replaces them. The goal is few gates, a low quantum cost, or few extra lines. The problem comes from reversible computation and from quantum computing, where every classical subroutine of a quantum algorithm, such as an oracle, must be a reversible circuit.
In plain words
Write the function as a table with rows. Each row has an input pattern of bits and an output pattern of bits, and no two rows have the same output, so the table only shuffles the patterns. You have wires and one kind of move: flip one wire, but only in the rows where some other chosen wires are all 1. Find a short list of moves that turns every input pattern into its output pattern at the same time.
A function that loses information, such as AND, is not a shuffle. Before synthesis it is padded with extra input wires set to constants and extra output wires whose values are not needed, until it becomes one.
Definition
Reversible function. A function that is a bijection. Read each bit vector as a binary number, line 0 as the lowest bit. Then is a permutation of , given as the list . The input has bits.
Gates. A multiple-control Toffoli gate has a set of control lines and a target line . It flips line when every line of is 1, and changes nothing else:
With it is NOT, with it is CNOT, and with it is the Toffoli gate. Each such gate is its own inverse. On lines there are of them: choices of target and sets of controls. The NCT library has only NOT, CNOT and Toffoli, which is gates on lines. The MCT library has all of them. Other libraries add negative controls (the gate fires when a control is 0), the Fredkin gate (a controlled swap), the Peres gate, or the quantum gates of the NCV library.
Circuit. A list of gates on the lines. It computes : acts first.
Problem. Given and a library , find a circuit of gates from that computes and has the least cost. The decision version asks if a circuit of cost at most exists.
Costs. The gate count is the usual one. The quantum cost counts the elementary quantum gates of each gate: a Toffoli gate costs 5 two-qubit gates (the decomposition is on the Toffoli gate page), and a gate with more controls costs more. For fault-tolerant hardware the cost is the number of T gates. The number of lines also counts, since each line is a qubit.
Irreversible functions. A function that is not a bijection is first embedded in a reversible one: add constant inputs and garbage outputs whose values are not used, so that the inputs and outputs have the same number of lines and every output pattern is used once. Let be the largest number of inputs that sends to the same output. Then the embedding needs at least garbage outputs (Saeedi and Markov, Section 2.1). Proof: the inputs with the same value of must get different full output patterns, and they agree on the outputs of , so they differ only in the garbage bits; garbage bits take at most values, so .
Variants
- Exact or heuristic. Exact synthesis finds a circuit of least cost and works only for a few lines. Heuristics find some circuit, usually larger, for many more lines.
- Libraries. NCT, MCT, MCT with negative controls, MCT with Fredkin gates, or a quantum library such as NCV, where the gates are not all permutations but the whole circuit must be.
- Cost. Gate count, quantum cost, T count, depth, or the number of lines.
- Lines. Ancilla-free synthesis uses exactly lines. With ancilla lines that start at 0 and must end at 0, or with garbage lines that may end in any state, larger functions become easy, at the price of qubits.
- Input form. A truth table for small , or a compact form such as an exclusive-or sum of products or a decision diagram for large . The truth table grows as , so it limits to about 20.
Examples
Decrement on 3 bits. Take on lines (bit 0), (bit 1) and (bit 2), that is . The circuit NOT(), then CNOT from to , then Toffoli with controls and target computes it. After the NOT, line holds . The CNOT sets to , which is bit 1 of . The Toffoli flips when , that is when both low bits were 0 and the subtraction borrows from bit 2. So the circuit has 3 gates. No circuit has fewer: differs from 0 in all three bits, and each gate flips at most one bit of each row. The transformation-based algorithm finds this circuit only in its bidirectional form; its output-only form uses 7 gates here (Miller, Maslov and Dueck, Section 3.3).
AND. sends three inputs to 0, so and the embedding needs garbage outputs. Two inputs and three outputs need one constant input. The Toffoli gate with the constant 0 on its target is such an embedding: , with and as the garbage.
A function with no circuit on its own lines. On 4 lines, let exchange the patterns 1110 and 1111 and fix the other 14. This is one transposition, an odd permutation. A NOT, CNOT or Toffoli gate on 4 lines is a product of 8, 4 or 2 disjoint transpositions, an even permutation, so every NCT circuit on 4 lines is even (see parity of a permutation), and no NCT circuit on 4 lines computes . The MCT gate with controls on lines 1, 2 and 3 and target line 0 computes it in one gate, and with one extra line NCT gates can compute it too.
Known algorithms
- Exact search. A circuit is a path in the graph whose vertices are the permutations and whose edges are the gates, so a breadth-first search from the identity finds an optimal circuit for every function at once. Shende, Prasad, Markov and Hayes (2003) did this for all functions of 3 bits. For 4 bits the space has elements. Golubitsky et al. (2010) stored all optimal circuits of half the length in a hash table and joined two halves, a meet-in-the-middle form of bidirectional search, and used the symmetries of the problem to cut the search by a factor of more than 48. Some 4-bit functions need 15 NCT gates (Saeedi and Markov, Section 4.1).
- Satisfiability. Encode "there is a circuit of gates" as a formula, with variables for the controls and the target of each gate and for the values on the lines, and give it to a SAT solver for The first that is satisfiable is optimal. This works for a few lines and short circuits (Section 4.1).
- Transformation-based. The algorithm of Miller, Maslov and Dueck (DAC 2003) walks the truth table in order and adds gates at the outputs, or at the inputs in the bidirectional form, until each row maps to itself. It always ends, with at most MCT gates, in time polynomial in .
- Cycle-based. Write the permutation as a product of cycles and build each cycle, or each pair of disjoint transpositions, from a fixed small circuit. Shende et al. build every even permutation this way from NCT gates.
- ESOP and decision diagrams. For functions with many inputs, an exclusive-or sum of products or a binary decision diagram of the function gives one Toffoli gate per term or a few gates per node, with extra lines. These scale to large functions but add many lines (Section 4.3).
- Templates. After synthesis, rewrite rules replace a part of a circuit by a shorter equal one. A template is a circuit that computes the identity; when a long part of a template appears in the circuit, it is replaced by the inverse of the short rest (Maslov, Dueck and Miller, 2005).
| Algorithm | Time | Space | Properties | Code |
|---|---|---|---|---|
| Transformation-based reversible synthesis | O(n 4^n) worst | O(n 2^n) circuit | deterministicnot exactiterative | 1 language |
Bounds
Which functions have a circuit. Every gate is a bijection, so every circuit computes a reversible function. On lines every NOT, CNOT and Toffoli gate is an even permutation, as in the example above, so NCT circuits with no extra line compute only even permutations (Shende et al., Lemma 11). They compute all of them (Theorem 12), and every odd permutation with one extra line (Corollary 13). On 3 lines or fewer, every permutation has an NCT circuit (Theorem 33). The MCT library computes every permutation on lines, as the transformation-based algorithm shows by construction.
Lower bounds. Each gate flips at most one bit of each row, so a circuit for has at least gates, where is the Hamming distance. A counting argument gives the worst case. There are at most MCT circuits of at most gates (each position holds a gate or nothing), and there are functions, so some function needs
MCT gates, using . This is . The same count with the NCT gates gives a bound of the order of NCT gates (Shende et al., Corollary 34).
Upper bounds. The transformation-based algorithm uses at most MCT gates, and the bound is tight for that algorithm (Maslov, Dueck and Miller, Theorem 1; the proof is on the algorithm page). Every even permutation has an NCT circuit of gates (Shende et al., Theorem 33), within a factor of the lower bound.
Three bits. Every function of 3 bits has an NCT circuit of at most 8 gates. The numbers of functions whose optimal circuit has gates are 1, 12, 102, 625, 2,780, 8,921, 17,049, 10,253 and 577, a mean of 5.87 gates (Shende et al., Table 1). On 3 lines the NCT and MCT libraries are the same 12 gates. The test file of the transformation-based page finds the same numbers by breadth-first search.
Hardness. The exact methods above search a space of functions or of all circuits up to a length, which grows much faster than the size of the truth table. The sources of this page give no exact method that runs in time polynomial in , and no proof that the minimum gate count problem is NP-hard.
Reductions
To shortest paths. Optimal synthesis with gate count is the shortest path from the identity to in the graph on the permutations whose edges are the gates of the library. Since every gate is its own inverse, the graph is undirected, and the distance of equals that of .
To satisfiability. As in Known algorithms: for each , a formula with one copy of the lines per gate and one constraint per row of the truth table is satisfiable exactly when a circuit of gates exists.
From irreversible functions. The embedding above turns synthesis of any multiple-output function into reversible synthesis with or more garbage outputs. Bennett's method and uncomputation turn a garbage output back into a constant at the cost of more gates.
Applications
- Quantum oracles. Grover's search and many other quantum algorithms call a classical function as a reversible circuit on qubits, . Its gates are then decomposed into Clifford and T gates and mapped onto the hardware by qubit mapping.
- Quantum arithmetic. The adders and multipliers inside modular exponentiation for Shor's algorithm are reversible circuits, and their gate and line counts set the size of the quantum computer.
- Low-power and emerging logic. Landauer's principle ties the erasure of a bit to dissipated heat. Reversible logic erases nothing, which was the first reason to study it, and it is used in proposals for adiabatic CMOS, optical and other emerging technologies.
References
- Vivek V. Shende, Aditya K. Prasad, Igor L. Markov and John P. Hayes, Synthesis of reversible logic circuits, IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 22(6), 2003, pages 710 to 722, numbered as in arXiv version 4: Lemma 11 (gates on fewer than n wires give even permutations), Theorem 12 (every even permutation is a circuit of NOT, CNOT and Toffoli gates with no extra wire), Corollary 13 (one extra wire for odd permutations), Theorem 33 (every permutation on 3 wires, and O(n 2^n) gates), Corollary 34 (some circuits need a number of gates of the order of n 2^n / log n), Table 1 (the number of 3-wire functions whose optimal circuit has k gates)
- D. Michael Miller, Dmitri Maslov and Gerhard W. Dueck, A transformation based algorithm for reversible logic synthesis, Proceedings of the 40th Design Automation Conference (DAC 2003), pages 318 to 323, Section 3 (synthesis as the transformation of the function into the identity by gates on the outputs or the inputs), Section 5 and Table 4 (all 40,320 functions of 3 bits)
- Dmitri Maslov, Gerhard W. Dueck and D. Michael Miller, Toffoli network synthesis with templates, IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 24(6), 2005, pages 807 to 817, Section III and Theorem 1 (the basic algorithm uses at most (n - 1) 2^n + 1 gates, and some function needs that many), the templates that remove gates afterwards
- Mehdi Saeedi and Igor L. Markov, Synthesis and optimization of reversible circuits, a survey, ACM Computing Surveys 45(2), 2013, article 21 (arXiv:1110.2574), Section 2.1 (ancillae, garbage lines and the ceil(log2 M) garbage lines that an irreversible function needs), Section 2.3 (cost models), Section 4.1 (optimal methods, by search and by satisfiability), Section 4.3 (transformation, search, cycle, ESOP and BDD-based heuristics)
- Tommaso Toffoli, Reversible computing, ICALP 1980, Lecture Notes in Computer Science 85, Springer, 1980, pages 632 to 644, the realization of every function by Toffoli gates with constant inputs and garbage outputs
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag W2MCTV Edit this page History Report an error Markdown