Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

iniestarchen/quantum-adder

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Quantum Half-Adder

Category: arithmetic  |  Difficulty: beginner  |  Qubits: 3  |  Gates: 5  |  Depth: 4

A quantum half-adder computes the sum and carry of two 1-bit numbers reversibly. The carry is computed using a Toffoli (CCX) gate (AND), and the sum using a CNOT (XOR). Because quantum gates are reversible, the input is not destroyed. This is a primitive building block of quantum arithmetic used in Shor's algorithm and quantum simulation. This circuit adds a=1, b=1 → sum=0, carry=1.

Expected Output

c[0]=0 (sum=0), c[1]=1 (carry=1) — correct for 1+1=10

Circuit

The OpenQASM 2.0 circuit is in circuit.qasm.

OPENQASM 2.0;
include "qelib1.inc";
// Quantum half-adder: a=1, b=1 -> sum=0, carry=1
// q[0]=a, q[1]=b, q[2]=carry ancilla
qreg q[3];
creg c[2];
// Initialize inputs: a=1, b=1
x q[0];
x q[1];
// Carry = a AND b (Toffoli)
ccx q[0],q[1],q[2];
// Sum = a XOR b (CNOT)
cx q[0],q[1];
// q[1] now holds sum, q[2] holds carry
measure q[1] -> c[0];
measure q[2] -> c[1];

Tags

arithmetic adder reversible toffoli

References

License

MIT — part of the OpenQC Algorithm Catalog.

About

Reversible quantum half-adder: computes sum = a XOR b and carry = a AND b for 1-bit inputs.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.