When ,
One Grover search algorithm iteration therefore gives
The selective sign change is implemented with one application of the Boolean quantum oracle: prepare its answer qubit in and use quantum phase kickback, obtaining on each . The remaining operations , , and the final computational-basis measurement are independent of . Measurement of returns some with probability one, so exactly one query to suffices.
Starting from , the first layer of Hadamard gates gives
The Boolean quantum oracle then gives
Using the Walsh-Hadamard transform identity
the final state is
Apply a Hadamard gate to every qubit. The amplitude of becomes
It equals in case (I) and in case (II). A computational-basis measurement therefore returns with certainty in case (I) and never returns it in case (II). This is the Deutsch-Jozsa algorithm.
For the distributed problem, Alice prepares
using one query to her quantum oracle, and sends these qubits to Bob. Bob applies his phase oracle, producing
The function is constant zero in case (1) and balanced in case (2). Bob applies and measures as above: outcome identifies case (1), while every other outcome identifies case (2), with certainty.
If some integer obeys , ordinary amplitude amplification already gives exactly. For a general known , use exact amplitude amplification. Choose so that
and put . Append an ancilla and coherently arrange that its designated good value has amplitude conditional on the original register being good. With the enlarged good subspace defined by
the starting state's total good amplitude is .
Apply the amplitude amplification theorem times to this enlarged problem. Its final good amplitude is
The Boolean quantum oracle implements the reflection by phase kickback, and the known state-preparation circuit implements the reflection about the starting state by prepare--reflect--unprepare. A final computational-basis measurement therefore yields an with with certainty.