Algorithm guide · arithmetic
QFT full adder
Add two binary registers and a carry-in bit; read the sum and carry-out separately.
Circuit size: 4–6 qubits (n = 1..2)
QFT half adder · Incoming carry in binary addition
Review quantum fundamentals →Notation used in this lesson
- |ψ⟩ and ⟨ψ|
- A state vector (ket) and its conjugate transpose (bra). ⟨a|b⟩ is their inner product.
- α, β and i
- α and β are complex amplitudes; i²=−1. A probability is the squared magnitude |α|².
- XOR, · and ⊗
- XOR adds bits modulo two. In s·x, multiply corresponding bits and XOR them. ⊗ combines registers or operations on different wires.
- U†, Σ and Tr
- U† is the adjoint (inverse for a unitary). Σ sums terms. Tr is the matrix trace, the sum of diagonal entries.
- Probability, shots and angles
- Ideal probabilities describe the model; measured shot frequencies fluctuate. Angles inside trigonometric expressions are in radians unless explicitly labeled turns.
1. The problem
Add two n-bit values and an incoming bit cin. Preserve a and cin, write the low result into b and keep the overflow on a carry-out wire.
2. How it works
The target Fourier phases accumulate two contributions: one from a and one from the incoming carry. The inverse transform decodes their combined integer shift.
Prepare registers
Encode a, b and cin; keep carry-out initially zero.
QFT target
Transform b plus carry-out into the Fourier basis.
Accumulate
Apply a-controlled phase additions and cin-controlled addition of one.
Decode and read
Inverse QFT produces the low sum and outgoing carry; a and cin stay unchanged.
3. The mathematics, one idea at a time
cin and cout have different roles. cin is supplied; cout is computed.
The two factors combine into one phase for adding a+cin.
Work this through by hand
4. One-bit 1+0+1
Four qubits: a, b, carry-out and carry-in. n=1 is the supported minimum.
Choose a=1, b=0, carry-in=1.
| Stage | Calculation or state | What it means |
|---|---|---|
| Compute the sum | 1+0+1=2=10₂ | The answer requires carry-out 1 and low bit 0. |
| Preserve inputs | a=1; cin=1 | These wires remain available after addition. |
| Classical layout | cin | cout | low | a = 1|1|0|1 | The leading bit is incoming carry, not a new high sum digit. |
Expected outcomes for this example
These are ideal predictions for the stated configuration, not a result already measured by your browser. Rows describing alternative modes or combined events are labeled explicitly.
| Outcome or event | Ideal probability | Interpretation |
|---|---|---|
| 1101 | 100% ideal | Extract cout|low = 10, meaning integer sum 2. |
5. Load the worked example in Composer
The worked example can use smaller or simpler inputs than the gallery defaults. The button below loads the exact circuit used in this lesson.
- Bits per input register (n)
- 1
- Input a
- 1
- Input b
- 0
- Carry-in
- 1 · incoming carry
- Save any current circuit you want to keep, then open the worked example. Loading it does not execute a paid hardware job.
- Trace the preparation, main operations and measurements against the worked table. Check the gate editor for controls, targets and angles.
- Start with an ideal noiseless simulator compatible with the circuit. Mid-circuit measurement, reset and feed-forward require support from the chosen backend.
- Inspect the live preview. For a recorded experiment, open Execute, set the available backend options and shots, and Run. Sign in when prompted to retain it in My Jobs.
- Read the output as described below before changing one setting and repeating. The guide describes the original example; edits can change the answer.
6. Read the output correctly
Read the layout before decoding the sum. The full label includes both preserved cin and a.
For general n: cin, cout, n low-sum bits, n original-a bits appear left to right.
A bit label is a register value; its bar height is a probability or count. For S shots and observed count k, the sampled frequency is k/S. A typical sampling scale for probability p is √[p(1−p)/S]; this is not a strict error bound. Finite samples do not have to match the ideal percentages exactly.
7. Common mistakes & limits
- Do not add the preserved incoming carry to the decoded answer a second time.
- This is a Fourier-based extension implemented by this gallery, not a generic built-in full-adder mode.
8. Check your understanding
With all three one-bit inputs equal to 1, what are low and carry-out?
Reveal the reasoning
1+1+1=3=11₂. low=1 and carry-out=1.
9. Further study
The lesson’s register mappings, supported inputs and loadable example follow Quantket’s implemented circuit. A reference may use different wire names, bit order or resource conventions.
Gallery reference: defaults, definitions & implementation notes
Inputs & default settings
Choose a, b, and carry-in. Composer preserves the inputs and writes the sum and carry-out using Fourier-basis phases.
These are the gallery defaults. The worked example above may override them. Configure the card to change the inputs before loading its editable circuit.
- Bits per input register (n)
- Default: 2 · Whole number from 1 to 2.
- Input a
- Default: 01 · 2 bits (0 or 1); leftmost character is the highest-numbered qubit.
- Input b
- Default: 10 · 2 bits (0 or 1); leftmost character is the highest-numbered qubit.
- Carry-in
- Default: 1 · Choices for the current settings: 0 · no incoming carry; 1 · incoming carry.
Implementation notes
The a and carry-in wires remain unchanged. The b wires hold the n low sum bits; the next wire is carry-out. In the classical histogram the bits read carry-in, carry-out, low sum, a from left to right. This is a QFT-based full-adder extension with an explicit carry-in, not a built-in Draper full-adder mode.
Default example: predictions & circuit facts
These values describe the unedited default setup. They are predictions and circuit properties, not measured results from your saved execution.
- Sum
- 100 (4)
- Carry-out
- 1
- Low sum bits
- 00
Read your saved result
Check the submitted circuit, measured register and execution settings in Run details. Exact results give computed probabilities; sampled results show frequencies from the recorded shots. Edited circuits and noise can change the expected outcome. The algorithm label records the circuit's origin; it does not certify an edited circuit or a measured result.