Genadder generates a quantum circuit to add two binary numbers of any width. It is implemented in C. The number of bits is given on the command line.
The circuit generated is a ripple-carry adder. It follows the block scheme in Jozef Gruska's Quantum Computing, page 96, and uses optimized implementations by Paul E. Black (unpublished 11 July 2002) using Generate. The circuits were checked with QCSim. For N bit wide arithmetic, the circuit uses 3N qubits: 2N for inputs, N-1 ancilla, and a carry out. One of the inputs serves as the output sums. It is assumed that there is no carry in. Although it uses ancilla, they are reset to 0, thus there is no "garbage". The circuit uses 7N-6 gates, N > 1.
A simple example is a 2-bit wide adder. It uses six qubits: inp0, inp1, sum0, sum1, anc0, and carryOut. The input is inp0/1 and sum0/1. The output is sum0, sum1, and carryOut. The least significant bits are at the top.

Notice that we could save one gate by removing the last gate, cnot(inp0, anc0), and moving the second gate, cnot(inp0, sum0), to the end. This kind of optimization could be folded into the generator, or added as a post-processing step.
Slightly more complex is a 3-bit wide adder. This is the first instance of all three variants of adders circuits: first stage (no carry in), middle stage, and final stage (no need to undo the carry). Following the picture are the jaQuzzi and QHDL files. The jaQuzzi version came from Qhdl2Jaq. Genadder declares the qubits from most to least significant so density matrix rows in QCSim correspond to the binary interpretations. We reversed the order here so the jaQuzzi images correspond with Gruska's diagrams.

|
qubit_0="inp0"
qubit_1="sum0"
qubit_2="anc0"
qubit_3="inp1"
qubit_4="sum1"
qubit_5="anc1"
qubit_6="inp2"
qubit_7="sum2"
qubit_8="carryOut"
gate0={1:1:NOT:-:-:-:-:-:-}
gate1={1:NOT:-:-:-:-:-:-:-}
gate2={-:-:-:1:1:NOT:-:-:-}
gate3={-:-:-:1:NOT:-:-:-:-}
gate4={-:-:1:-:1:NOT:-:-:-}
gate5={-:-:-:-:-:-:1:1:NOT}
gate6={-:-:-:-:-:-:1:NOT:-}
gate7={-:-:-:-:-:1:-:1:NOT}
gate8={-:-:-:-:-:1:-:NOT:-}
gate9={-:-:1:-:1:NOT:-:-:-}
gate10={-:-:-:1:1:NOT:-:-:-}
gate11={-:-:-:1:-:NOT:-:-:-}
gate12={-:-:1:-:NOT:-:-:-:-}
gate13={1:1:NOT:-:-:-:-:-:-}
gate14={1:-:NOT:-:-:-:-:-:-}
# Quantum circuit to add 3 qubits without garbage # Produced by genadder version 1.0 # $Header: /home/black/Quantum/GenAdder/RCS/genadder.C,v 1.1 2003/08/20 13:28:20 $ # For more information, contact Paul E. Black |
Finally we show part of a 5-bit wide adder, along with its jaQuzzi and QHDL representations.

|
qubit_0="inp0"
qubit_1="sum0"
qubit_2="anc0"
qubit_3="inp1"
qubit_4="sum1"
qubit_5="anc1"
qubit_6="inp2"
qubit_7="sum2"
qubit_8="anc2"
qubit_9="inp3"
qubit_10="sum3"
qubit_11="anc3"
qubit_12="inp4"
qubit_13="sum4"
qubit_14="carryOut"
gate0={1:1:NOT:-:-:-:-:-:-:-:-:-:-:-:-}
gate1={1:NOT:-:-:-:-:-:-:-:-:-:-:-:-:-}
gate2={-:-:-:1:1:NOT:-:-:-:-:-:-:-:-:-}
gate3={-:-:-:1:NOT:-:-:-:-:-:-:-:-:-:-}
gate4={-:-:1:-:1:NOT:-:-:-:-:-:-:-:-:-}
gate5={-:-:-:-:-:-:1:1:NOT:-:-:-:-:-:-}
gate6={-:-:-:-:-:-:1:NOT:-:-:-:-:-:-:-}
gate7={-:-:-:-:-:1:-:1:NOT:-:-:-:-:-:-}
gate8={-:-:-:-:-:-:-:-:-:1:1:NOT:-:-:-}
gate9={-:-:-:-:-:-:-:-:-:1:NOT:-:-:-:-}
gate10={-:-:-:-:-:-:-:-:1:-:1:NOT:-:-:-}
gate11={-:-:-:-:-:-:-:-:-:-:-:-:1:1:NOT}
gate12={-:-:-:-:-:-:-:-:-:-:-:-:1:NOT:-}
gate13={-:-:-:-:-:-:-:-:-:-:-:1:-:1:NOT}
gate14={-:-:-:-:-:-:-:-:-:-:-:1:-:NOT:-}
gate15={-:-:-:-:-:-:-:-:1:-:1:NOT:-:-:-}
gate16={-:-:-:-:-:-:-:-:-:1:1:NOT:-:-:-}
gate17={-:-:-:-:-:-:-:-:-:1:-:NOT:-:-:-}
gate18={-:-:-:-:-:-:-:-:1:-:NOT:-:-:-:-}
gate19={-:-:-:-:-:1:-:1:NOT:-:-:-:-:-:-}
gate20={-:-:-:-:-:-:1:1:NOT:-:-:-:-:-:-}
gate21={-:-:-:-:-:-:1:-:NOT:-:-:-:-:-:-}
gate22={-:-:-:-:-:1:-:NOT:-:-:-:-:-:-:-}
gate23={-:-:1:-:1:NOT:-:-:-:-:-:-:-:-:-}
gate24={-:-:-:1:1:NOT:-:-:-:-:-:-:-:-:-}
gate25={-:-:-:1:-:NOT:-:-:-:-:-:-:-:-:-}
gate26={-:-:1:-:NOT:-:-:-:-:-:-:-:-:-:-}
gate27={1:1:NOT:-:-:-:-:-:-:-:-:-:-:-:-}
gate28={1:-:NOT:-:-:-:-:-:-:-:-:-:-:-:-}
# Quantum circuit to add 5 qubits without garbage # Produced by genadder version 1.0 # $Header: /home/black/Quantum/GenAdder/RCS/genadder.C,v 1.1 2003/08/20 13:28:20 $ # For more information, contact Paul E. Black |
Genadder was originally written by Paul E. Black August 2003.
Send comments to: webmaster-sdct
Privacy Policy
Created Wed Aug 20 10:07:24 2003 by Paul E. Black
This page's URL is: http://hissa.nist.gov/~black/Quantum/genadder.html