The Deutsch-Jozsa algorithm can determine whether a function mapping all bitstrings to a single bit is constant or balanced, provided that it is one of the two. A constant function always maps to either 1 or 0, and a balanced function maps to 1 for half of the inputs and maps to 0 for the other half. Unlike any deterministic classical algorithm, the Deutsch-Jozsa Algorithm can solve this problem with a single iteration, regardless of the input size. It was one of the first known quantum algorithms that showed an exponential speedup, albeit against a deterministic (non-probabilistic) classical compuetwr, and with access to a blackbox function that can evaluate inputs to the chosen function.
This algorithm takes as input n qubits in state
In the case of the Deutsch-Jozsa algorithm, the function f is some function mapping from bitstrings to bits:
f : {0, 1}n → {0, 1}
and is assumed to either be textit{constant} or textit{balanced}. Constant means that on all inputs f takes on the same value, and balanced means that on half of the inputs f takes on one value, and on the other half f takes on a different value. (Here the value is restricted to {0, 1})
We can then describe the algorithm as follows:
- Input:
n + 1 qubits
- Algorithm:
- Prepare the textit{ancilla} (
$\ket{q}$ above) in the$\ket{1}$ state by performing an X gate. - Perform the n + 1-fold Hadamard gate H ⊗ n + 1 on the n + 1 qubits.
- Apply the circuit Uw.
- Apply the n-fold Hadamard gate H ⊗ n on the data qubits,
$\ket{x}$ . - Measure
$\ket{x}$ . If the result is all zeroes, then the function is constant. Otherwise, it is balanced.
- Prepare the textit{ancilla} (
The oracle in the Deutsch-Jozsa
module is not implemented in such a way that calling Deutsch_Jozsa.is_constant() will yield an exponential speedup over classical implementations. To construct the quantum algorithm that is executing on the QPU we use a Quil defgate, which specifies the circuit Uw as its action on the data qubits
Here you can find documentation for the different submodules in deutsch-jozsa.
grove.deutsch_jozsa.deutsch_jozsa