A quantum oracle is a unitary operation that implements a classical function so a quantum algorithm can use it without depending on the function’s internal implementation. For a search function f(x), it distinguishes inputs for which f(x)=1 from those for which f(x)=0, making the problem-specific predicate a reusable input to generic search logic. section 7.1 section 7.4
Two common encodings place the function result in different parts of the quantum state:
- A phase oracle acts on the n input qubits and applies Uₚ|x⟩ = (-1)^f(x)|x⟩. Marked basis states acquire a relative phase of -1; unmarked states remain unchanged. section 7.1.1
- A marking oracle acts on n input qubits plus a target qubit. It flips the target exactly when f(x)=1, leaving it unchanged when f(x)=0. section 7.1.1
- Phase kickback converts a marking oracle into a phase oracle by preparing an auxiliary qubit in |−⟩, applying the marking operation, and restoring the auxiliary state. section 7.1.2 section 7.1.3
Marking two three-bit inputs
For a function that marks 001 and 110, a phase oracle negates the amplitudes of |001⟩ and |110⟩ in a superposition. A marking oracle instead swaps the target-qubit amplitudes associated with each marked input, corresponding to a target flip. section 7.1 section 7.1.1
In Grover’s search, the oracle supplies the problem predicate while the rest of the algorithm is generic. The phase-oracle step reflects amplitudes associated with solutions; combined with reflection about the mean, it amplifies solution states. Measurements remain probabilistic, so a returned candidate must be checked classically with f(x). section 7.2.1 section 7.4
Build a marking oracle by choosing an input representation, computing the predicate reversibly into a target qubit, and uncomputing temporary constraint calculations. Search-space design can move guaranteed constraints into state preparation, leaving the oracle to test only the remaining constraints. section 8.0 section 8.2.2
N queens predicate
An N queens oracle can encode board cells or per-row column indices. With one queen per row enforced during state preparation, the marking oracle checks only column and diagonal conflicts, stores intermediate checks in extra qubits, flips the target for valid placements, and uncomputes the checks. section 8.2.2 section 8.3.2
Figure 8.1 Solving a search problem using Grover’s algorithm starts with deciding on the representation of the function input \(x\) and the way to calculate the function \(f(x)\) based on it. Then, we implement the marking oracle for this function and the operation that prepares the state \(\ket{\textrm{mean}}\) based on that decision. Finally, these building blocks are used in Grover’s search to get the end-to-end solution.
Use the workflow diagram to connect classical input representation and predicate design to reversible oracle construction, mean-state preparation, and Grover search. section 8.0

