Algorithm guide · oracle
Bernstein–Vazirani: CCNOT + phase correction
One secret like standard BV, but this CCNOT oracle needs phase correction. Unlike two-secret BV, it returns the same string every run.
Circuit size: n = 1..5 input qubits + 2 ancillas
Standard Bernstein–Vazirani · Controlled-controlled-X · Entanglement with a selector
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
Recover one parity secret using the gallery’s selector-controlled CCNOT construction and its phase-correction block. Understand why this is a distinct circuit from standard BV, even though its corrected answer is the same.
2. How it works
The selector divides the state into two branches. The CCNOT block writes the parity phase on one branch; a separate CZ correction writes it on the other. Once both branches agree, the inputs can decode the same secret without depending on the selector.
Prepare
Create input superpositions, a selector |+⟩ and a phase helper |−⟩.
Apply T_f
Use the selector and inputs as controls of CCNOT parity terms.
Apply P_f and decode
The optional phase correction aligns the branches; final input Hadamards expose s.
3. The mathematics, one idea at a time
This describes selector/input branches after decoding, up to branch conventions and spectator helpers. Ignoring the selector gives a mixture.
The correction removes which-branch dependence from the recovered input. If s=0ⁿ, the two labels coincide.
Work this through by hand
4. One input bit, secret 1
Three qubits: n=1 input plus selector and helper. This is the supported minimum for this variant.
Enter secret 1 and leave Apply phase correction enabled.
| Stage | Calculation or state | What it means |
|---|---|---|
| Selector branches | One branch acquires the parity phase in T_f | The other still needs the correction. |
| Corrected branches | Both decode to input 1 | The selector no longer changes the answer. |
| Comparison experiment | Disable P_f: 0 and 1 each have probability 1/2 | This exposes the role of the missing block. |
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 |
|---|---|---|
| 1 | 100% with correction | Secret recovered. |
| 0 and 1 | 50% each without correction | Uncorrected branch mixture. |
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 qubits (n)
- 1
- Secret string s
- 1
- Apply phase correction P_f
- On
- 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 c0 for the one-bit input. Selector/helper outcomes are not additional secret bits.
Compare corrected and uncorrected circuits with the same secret and enough shots.
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
- This circuit contains two function-dependent blocks, T_f and P_f. One final measurement is not evidence of one total oracle block.
- Do not confuse this single-secret variant with two-secret probabilistic BV.
8. Check your understanding
Why does disabling correction still return only 0 when the secret is 0?
Reveal the reasoning
Both decoded selector branches then contain the same input state |0⟩; they no longer form two different histogram labels.
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 one secret string. Turn phase correction off to compare the CCNOT oracle alone with the corrected circuit.
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 qubits (n)
- Default: 3 · Whole number from 1 to 5.
- Secret string s
- Default: 110 · 3 bits (0 or 1); leftmost character is the highest-numbered qubit.
- Apply phase correction P_f
- Default: true · On or off.
Turn off to see the CCNOT oracle alone: zero and a nonzero secret each occur in about half the shots.
Implementation notes
Standard BV uses n+1 qubits and a CX parity oracle to read one secret with certainty. This paper variant uses n+2 qubits: a selector-controlled CCNOT block T_f puts the parity phase on one branch, then a CZ-based block P_f puts it on the other. With P_f, the input always reads s; without it, a nonzero s reads either all-zero or s with equal probability. The separate probabilistic BV card instead holds two different secrets and returns either one per run. T_f and P_f both depend on f, so one final measurement does not mean one oracle call.
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.
- Function-dependent blocks
- T_f + P_f
- Ideal input result
- 110 (100%)
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.