QuantumCore

Hands-on lab · 1 step

Deutsch–Jozsa with one oracle query

Surround a black-box oracle Uf∣x0x1⟩∣y⟩=∣x0x1⟩∣y⊕f(x0x1)⟩U_f\lvert x_0x_1\rangle\lvert y\rangle=\lvert x_0x_1\rangle\lvert y\oplus f(x_0x_1)\rangle with gates from {H,X,Z}\{H,X,Z\} so that a single query decides whether f:{0,1}2→{0,1}f:\{0,1\}^2\to\{0,1\} is constant or balanced. The grader runs your circuit four times, once for each of the oracles f≡0f\equiv0, f≡1f\equiv1, f=x0⊕x1f=x_0\oplus x_1 and f=x0f=x_0, and inspects the measurement distribution of the two input qubits.

0/1 step passedBest score 0/100

Step 1: Constant or balanced in one query

The register has three qubits, all starting in ∣0⟩\lvert0\rangle: qubits 00 and 11 hold the input x=x0x1x=x_0x_1 and qubit 22 is the ancilla yy. Qubit 00 is the most significant bit, so the basis state ∣x0,x1,y⟩\lvert x_0,x_1,y\rangle has index 4x0+2x1+y4x_0+2x_1+y.

The circuit already contains the oracle placeholder UfU_f. In the circuit editor it is the statement Uf on its own line; keep it exactly once and type gates before and after it. You may use HH, XX and ZZ, at most 88 operations in total including Uf, and no measurements.

The grader substitutes four oracles into Uf and computes the Born probabilities (p00,p01,p10,p11)(p_{00},p_{01},p_{10},p_{11}) of the input qubits (x0,x1)(x_0,x_1), summed over the ancilla:

  • constant-cases: for f≡0f\equiv0 (Uf=I8U_f=I_8) and for f≡1f\equiv1 (Uf=I⊗I⊗XU_f=I\otimes I\otimes X) you must obtain (1,0,0,0)(1,0,0,0), i.e. the outcome 0000 with certainty;
  • balanced-cases: for f=x0⊕x1f=x_0\oplus x_1 (Uf=CNOT1→2 CNOT0→2U_f=\mathrm{CNOT}_{1\to2}\,\mathrm{CNOT}_{0\to2}) you must obtain (0,0,0,1)(0,0,0,1), and for f=x0f=x_0 (Uf=CNOT0→2U_f=\mathrm{CNOT}_{0\to2}) you must obtain (0,0,1,0)(0,0,1,0).

Every probability is compared within 10−610^{-6}. In general the Deutsch–Jozsa circuit returns the string zz with probability ∣2−n∑x(−1)f(x)+x⋅z∣2\big\lvert2^{-n}\sum_x(-1)^{f(x)+x\cdot z}\big\rvert^2, which for a linear f(x)=s⋅xf(x)=s\cdot x is 11 exactly at z=sz=s.

  • 3 qubits
  • allowed gates: H, X, Z
  • at most 8 gates
  • no measurements
  • use Uf at least 1×

One gate per line or separated by ;, e.g. H(0); CNOT(0,1); RY(1, pi/3); measure(1 -> 0). Qubit 0 is the top wire (most significant bit); controls come first. # starts a comment.

Measure into a classical bit with measure(q -> c); apply a gate only when a bit is set with X(2) if c1==1 (several bits, first = most significant: if c[0,1]==3). Placeholders: Uf — write the name on its own (e.g. Uf); it acts on the qubits fixed by the step.

Circuit diagram of your answerUf on q0, q1, q2q0q1q2Uf
Statevector amplitudes
BasisAmplitude α|α|Phase arg αProbability
|000⟩1
1.0000
0
100.00%
7 basis states with zero amplitude hidden