- Related: Quantum Computing, Calcolabilità e Complessità
- Source: qiskit, Learn Quantum Computing with Python and Q [Ap.D]
- see Jupiter Notebook Extract
The first example of a quantum algorithm performing better than the best classical algorithm.
The algorithm can be applied to an oracle where is either constant or balanced and decide in whether it’s one or the other, in a single application.
Algorithm
- prepare two qubits,
controlandtarget, in the state - prepare the state $| + - ⟩$1
- apply the
oracleto input state - measure
controlin the- if 0 then is constant, otherwise is balanced
The algorithm can be extended to qubits with functions of form
and n-qubits oracles
Code
Algorithm
namespace DeutschJozsa {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Diagnostics;
operation CheckIfOracleIsBalanced(oracle : ((Qubit, Qubit) => Unit))
: Bool {
use control = Qubit();
use target = Qubit();
H(control);
X(target);
H(target);
oracle(control, target);
H(target);
X(target);
return MResetX(control) == One;
}
operation RunDeutschJozsaAlgorithm() : Unit {
Fact(not CheckIfOracleIsBalanced(ApplyZeroOracle),
"Test failed for zero oracle.");
Fact(not CheckIfOracleIsBalanced(ApplyOneOracle),
"Test failed for one oracle.");
Fact(CheckIfOracleIsBalanced(ApplyIdOracle),
"Test failed for id oracle.");
Fact(CheckIfOracleIsBalanced(ApplyNotOracle),
"Test failed for not oracle.");
Message("All tests passed!");
}
}
Oracles
namespace DeutschJozsa {
open Microsoft.Quantum.Intrinsic;
operation ApplyZeroOracle(control : Qubit, target : Qubit) : Unit {
}
operation ApplyOneOracle(control : Qubit, target : Qubit) : Unit {
X(target);
}
operation ApplyIdOracle(control : Qubit, target : Qubit) : Unit {
CNOT(control, target);
}
operation ApplyNotOracle(control : Qubit, target : Qubit) : Unit {
X(control);
CNOT(control, target);
X(control);
}
}
Footnotes
-
shortand for ↩