First construct a controlled unitary gate from the uncontrolled oracle. Keep the supplied in a reference register. Controlled on an extra qubit, swap the data and reference registers, query on the register that contains in one branch, and swap back. Because , that branch is unchanged, while the other branch acquires on the data. Reversing the control convention with Pauli X gates gives controlled-. The reference state is returned unchanged, and each use costs one query to and controlled-SWAP gates.
Expand in an eigenbasis of . Exact quantum phase estimation with an -qubit phase register produces
Apply the available phase gates, controlled by the corresponding bits of , to multiply branch by
Then reverse phase estimation. Although no oracle was supplied, every eigenvalue obeys , so . The inverse controlled powers can therefore be implemented with forward calls to . Since , phase estimation and its inverse use only queries. The phase register returns to , while the data register is
As a direct check, the same spectral promise implies .