Quantum Computing Master Course — 068. Oracle Verification
Lesson 068: Oracle Verification
Smartyfy Quantum Computing Master Course
Prerequisites and objectives
A circuit can return the correct classical output labels and still implement the wrong quantum oracle. Relative phases, changed inputs, or correlated workspace can break the interference on which an algorithm relies. You will design layered verification checks, construct a phase-error counterexample, and distinguish small-model numerical verification from physical device certification.
Our target is a specified unitary Uf|x,y⟩=|x,y⊕f(x)⟩, possibly with clean ancillary workspace. Verification must compare the implemented operation with that full contract. Testing only whether a zero target produces f(x) checks a useful subset, but not the whole operation.
Start with register and interface checks
Write the input register order, target order, and ancilla positions explicitly. State whether array indices follow the displayed left-to-right bit string or a software package’s qubit significance convention. Many apparent mathematical failures are actually label mismatches.
For every small basis input, check that x is retained and y is XOR-updated for both zero and nonzero targets. If the function has multiple output bits, test all target strings when exhaustive testing is feasible.
Check workspace separately: clean ancillas must return to the stated clean state if that is the promised interface. Looking only at the useful output bits can miss residual information that changes a later algorithm.
Truth-table probabilities are necessary but insufficient
Suppose U is the intended oracle and another operation V maps each basis input |j⟩ to e^(iθj)U|j⟩. Measuring the output in the computational basis gives the same labels for both operations.
If all θj are the same, U and V differ by a single global phase as isolated operations. If they depend on j, superpositions generally acquire different relative phases. Computational-basis probability tests cannot distinguish those cases.
Even checking fidelity one separately for each basis output is insufficient: fidelity ignores a phase for each tested state. An operation comparison needs one common global phase across all inputs, not an independently chosen phase for every column.
Worked counterexample with a phase-corrupted CNOT
Let f(x)=x, so U is CNOT with data x on the left and target y on the right. Define V=U(Z⊗I), meaning apply Z to the data before the intended oracle. For x=0, the basis action is identical; for x=1, the output gains a minus sign.
Every computational-basis input still yields the correct output bits. But on |+⟩|0⟩, U produces Φ+=(|00⟩+|11⟩)/√2 while V produces Φ−=(|00⟩−|11⟩)/√2. Their inner product is zero.
Their Z histograms are identical, yet a Bell decoder distinguishes them: CNOT followed by H on the data produces 00 for Φ+ and 10 for Φ−. The error is therefore physically relevant relative phase, not merely a notation difference.

Check the algorithm-level consequence
Use the same two oracles inside Deutsch’s circuit with data |+⟩ and target |−⟩. The correct U contributes the phase pattern for f(x)=x, changing the data to |−⟩. The final H yields one, correctly reporting balanced.
The extra data Z in V contributes another identical sign pattern. The two relative sign changes cancel, leaving the data |+⟩ before the final H. The circuit now yields zero and falsely reports constant.
This example is especially useful for testing because no random statistics are needed in the ideal simulation. A basis truth-table test passes, while a known phase-sensitive application fails with certainty.
Compare full operators for small systems
For a small circuit, calculate the complete complex output vector for every computational-basis input. These output vectors are the columns of its matrix. Exact agreement of all columns proves equality of the finite-dimensional linear operators.
If global-phase equivalence is acceptable, align using one nonzero matrix entry and check that the same phase aligns every entry. Another equivalent criterion for unitary U,V is U†V=e^(iγ)I for one γ.
For the corrupted oracle above, U†V=Z⊗I, whose diagonal entries are 1,1,−1,−1. It is not a scalar multiple of identity. A routine that independently aligns each column would erase this evidence and incorrectly accept the operation.
For a controlled use of the oracle, even an otherwise global phase may become a relative phase on the controlling branch. The acceptable equivalence relation must therefore match how the operation is used in the larger circuit.
Workspace can hide another error
Imagine a circuit that returns the correct x and y labels but leaves an extra bit g(x) in workspace. On a coherent input, the joint output contains Σx αx|x,f(x),g(x)⟩. Distinct garbage states can distinguish branches that the intended algorithm needs to interfere.
Verify both that the workspace has returned to its expected state and that the useful-register amplitudes match the intended operation. A reset that clears the workspace’s visible bit after discarding its correlations is not equivalent to coherent uncomputation.
When the ancilla promise is only “starts at zero,” it is sufficient to test the full isometry on that allowed subspace rather than demanding an arbitrary action on inaccessible ancilla inputs. The tested contract should be neither weaker nor stronger than the specified use.
A layered test plan
| Check | Main issue detected |
|---|---|
| Basis labels for all targets | Wrong Boolean action or changed input |
| Complex column comparison | Input-dependent phase errors |
| Workspace state and coherence | Garbage or destructive cleanup |
| Known algorithm output | Integration and ordering mistakes |
Implement the expected Boolean specification independently from the gate construction when possible. Reusing the same mistaken index formula in both can make a test pass for the wrong reason. Include asymmetric inputs and complex superpositions rather than only highly symmetric cases.
Numerical tolerances handle floating-point rounding in a simulator. They do not represent hardware confidence intervals. Experimental verification uses finite measurement data and a noise model; an exact simulator assertion cannot substitute for those observations.
Four exercises with worked solutions
-
Why do U and U(Z⊗I) have identical computational-basis output labels?
Solution. Z only multiplies a basis input by +1 or −1. The later U sends that input to the same basis label, and squaring its amplitude removes the sign.
-
Calculate the fidelity between Φ+ and Φ−.
Solution. Their inner product is (1−1)/2=0, so squared-overlap fidelity is zero. Matching Z outcome probabilities therefore does not imply matching quantum states.
-
If V=e^(iπ/5)U on every input, are they equivalent as isolated unitaries?
Solution. Yes, they differ by one global phase. A controlled use needs separate analysis because only its active branch may receive that phase.
-
What is wrong with comparing each operator column after choosing a different phase for that column?
Solution. It treats input-dependent relative phases as if they were globally irrelevant. Those phases affect superpositions, so an operation-level equivalence test must use a single common phase.
Five explained multiple-choice questions
-
Correct basis output probabilities establish full oracle equivalence: A. Whenever probabilities sum to one. B. No, phase and workspace errors may remain. C. Always. D. Only when the target is zero.
Answer: B. Probability tests discard phase information.
-
A full operator’s columns are: A. Outputs on computational-basis inputs. B. Measurement counts only. C. Its eigenvalues only. D. The Boolean truth table without phases.
Answer: A. Linearity then determines its action on every superposition.
-
Acceptable global-phase alignment uses: A. A separate phase per input. B. No phase convention ever. C. One common phase for the whole operator. D. A separate phase per amplitude.
Answer: C. Relative phases between columns can affect coherent inputs.
-
The corrupted CNOT makes Deutsch’s balanced function appear: A. Constant. B. Random in the ideal example. C. Balanced with better confidence. D. Unnormalized.
Answer: A. The unwanted data Z cancels the function’s intended relative phase.
-
A simulator tolerance describes: A. Physical readout confidence automatically. B. An experimental error bar. C. A proof that noise is absent. D. Numerical comparison precision.
Answer: D. Hardware statistics require their own evidence and model.
Pitfalls and summary
Verify the full promised interface, use one global phase convention, and test coherent behavior and workspace. Basis truth tables are the beginning of oracle verification, while complete small-system matrices and phase-sensitive applications expose errors those tables cannot see.
Primary sources and further study
These sources support the definitions and context. The numerical examples, exercises, and explanations here were prepared for this lesson. Research papers are optional advanced reading.