Algorithm guide · arithmetic
Full adder
Add A, B and carry-in as single bits. Three CX gates make the sum; three CCX gates make carry-out.
Circuit size: 5 qubits · three one-bit inputs
Half adder · Three-input parity · Toffoli controls
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 A, B and cin as individual bits. Preserve all three inputs and place the low sum and outgoing carry in two clean output wires.
2. How it works
Three CX operations compute the parity of the three inputs into the sum. Three CCX operations compute the parity of their pairwise products into the carry. For three bits, that second parity is exactly the majority function.
Prepare five wires
Three inputs plus sum=0 and carry=0.
Sum
Toggle sum once for each input that is 1.
Carry
Toggle carry for AB, A·cin and B·cin.
Measure outputs
Only sum and carry are the classical answer.
3. The mathematics, one idea at a time
The sum bit is 1 when an odd number of inputs are 1.
With two 1 inputs exactly one product is 1. With three 1 inputs all three products are 1, whose XOR is also 1.
This verifies the arithmetic meaning of both output bits.
Work this through by hand
4. Add 1+0+1
The clean-output implementation always uses five qubits for these three one-bit inputs.
Set A=1, B=0, cin=1.
| Stage | Calculation or state | What it means |
|---|---|---|
| Sum calculation | 1 XOR 0 XOR 1 = 0 | Two toggles cancel on the sum wire. |
| Carry calculation | 0 XOR 1 XOR 0 = 1 | Only A·cin contributes. |
| Check | 2·1+0=2 | This agrees with 1+0+1. |
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 |
|---|---|---|
| 10 | 100% ideal | carry-out 1 followed by sum 0. |
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.
- Input A
- 1
- Input B
- 0
- Carry-in
- 1
- 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
Classical bits c1c0 records carry-out then sum.
The preserved input wires are not part of that two-bit output. Unlike the QFT full adder, this card does not accept multi-bit operands.
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
- Carry is not the XOR of the three inputs; that expression gives the sum bit.
- The product XOR formula happens to equal majority for three bits. Do not replace a general OR by XOR without checking its truth table.
8. Check your understanding
What happens for A=B=cin=1?
Reveal the reasoning
S=1 and C=1, so output 11 means three. Three carry toggles leave the carry at 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
Set A, B and carry-in, then inspect the PDF's five-qubit circuit. Select Classical bits in Composer for sum and carry-out.
These are the gallery defaults. The worked example above may override them. Configure the card to change the inputs before loading its editable circuit.
- Input A
- Default: 1 · Choices for the current settings: 0; 1.
- Input B
- Default: 0 · Choices for the current settings: 0; 1.
- Carry-in
- Default: 1 · Choices for the current settings: 0; 1.
Implementation notes
The three input bits stay unchanged. CX writes A ⊕ B ⊕ Cin into a fresh sum qubit. CCX toggles carry-out for AB, A·Cin and B·Cin; their XOR is 1 exactly when at least two inputs are 1. In Composer, choose Classical bits to read c1c0 as carry-out then sum. The QFT full adder is a separate, multi-bit Fourier-basis construction.
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 bit
- 0
- Carry-out
- 1
- Histogram c1c0
- 10
- Logical gates
- 3 CX + 3 CCX
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.