Skip to documentation
← Algorithm guides

Algorithm guide · arithmetic

Cuccaro ripple-carry adder

Add two binary registers with a CX/CCX carry ladder, keeping the final carry-out.

Circuit size: 4–8 qubits (n = 1..3)

Before you begin

Full-adder carry logic · Reversible computation · Uncomputing temporary work

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 registers using a ripple-carry CX/CCX circuit, preserve A, overwrite B with the low sum and expose the final carry. Restore the scratch wire to zero rather than leaving garbage.

2. How it works

A forward MAJ sweep carries information from low bits to high bits. After copying the final carry, a backward UMA sweep restores the input and scratch information while writing the sum. This is computation followed by carefully chosen uncomputation.

  1. Prepare

    Encode A and B; scratch and carry-out begin at zero.

  2. MAJ sweep

    Compute successive carries from least to most significant bit.

  3. Copy final carry

    Write the overflow onto its own output wire.

  4. UMA sweep

    Reverse temporary carry work while forming sum bits in B.

3. The mathematics, one idea at a time

s_i=a_i XOR b_i XOR c_i

Each bit’s sum includes its incoming carry c_i.

c_(i+1)=a_i b_i XOR a_i c_i XOR b_i c_i; c_0=0

The recurrence is the same arithmetic as a classical full adder. The reversible gate sequence preserves information.

Work this through by hand

4. One-bit 1+1

n=1 gives four qubits: A, B, scratch and carry-out. It is the supported minimum.

Set A=1, B=1.

StageCalculation or stateWhat it means
Carry recurrencec1=1·1=1There is no incoming carry.
Low sums0=1 XOR 1 XOR 0=0The bit wraps to zero.
After uncomputationA=1, B=0, scratch=0, cout=1Only carry and sum are measured as the answer.

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 eventIdeal probabilityInterpretation
10100% idealClassical carry|sum gives binary two.

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
1
  1. Save any current circuit you want to keep, then open the worked example. Loading it does not execute a paid hardware job.
  2. Trace the preparation, main operations and measurements against the worked table. Check the gate editor for controls, targets and angles.
  3. Start with an ideal noiseless simulator compatible with the circuit. Mid-circuit measurement, reset and feed-forward require support from the chosen backend.
  4. 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.
  5. 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 output-only Classical bits register. For width n it has n+1 bits: carry-out then low sum.

At larger widths work and operand wires can make the Qubits view much wider than the actual answer.

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

  • A scratch wire that ends entangled with the operands is not properly cleaned work.
  • The MAJ/UMA gate count is implementation cost, separate from the arithmetic operation’s logical meaning.

8. Check your understanding

For n=2, A=01 and B=11, what do the output bits say?

Reveal the reasoning

1+3=4=100₂. Carry-out is 1 and low sum is 00; A stays 01.

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 and b, then inspect the forward majority and reverse unmajority ladder in Composer.

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 3.
Input a
Default: 01 · 2 bits (0 or 1); leftmost character is the highest-numbered qubit.
Input b
Default: 11 · 2 bits (0 or 1); leftmost character is the highest-numbered qubit.

Implementation notes

The MAJ gates move carry from the low bits to the high bit. After copying the final carry to its own output wire, UMA gates run backward: they restore A and return the one scratch qubit to |0⟩ while replacing B with the low sum bits. The Classical bits histogram reads carry-out followed by the sum. At n=3 the circuit uses eight physical qubits, so choose Classical bits to view its output histogram. Based on Cuccaro et al., arXiv:quant-ph/0410184.

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
Histogram c2c1c0
100
Logical gates
4 CCX + 9 CX

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.