QuantumCore

Hands-on lab · 1 step

Decompose the Toffoli gate

Build the Toffoli gate CCX∣a,b,c⟩=∣a,b,c⊕ab⟩\mathrm{CCX}\lvert a,b,c\rangle=\lvert a,b,c\oplus ab\rangle (controls 0,10,1, target 22) on three qubits from the Clifford+TT set {H,T,T†,CNOT}\{H,T,T^\dagger,\mathrm{CNOT}\} with at most six CNOTs and fifteen gates in total.

0/1 step passedBest score 0/100

Step 1: Toffoli from H, T, T† and CNOT

Build a three-qubit circuit whose unitary equals CCX\mathrm{CCX} (controls qubits 00 and 11, target qubit 22) up to a global phase, using only HH, T=diag(1,eiπ/4)T=\mathrm{diag}(1,e^{i\pi/4}), T†=diag(1,e−iπ/4)T^\dagger=\mathrm{diag}(1,e^{-i\pi/4}) and CNOT\mathrm{CNOT}, with at most 66 CNOTs and at most 1515 gates, and no measurements. The grader computes the 8×88\times8 unitary UU of your circuit and the process fidelity FU=∣Tr(CCX†U)∣/8F_U=\lvert\mathrm{Tr}(\mathrm{CCX}^\dagger U)\rvert/8, which equals 11 exactly when U=eiγ CCXU=e^{i\gamma}\,\mathrm{CCX}. Qubit 00 is the most significant bit, so ∣a,b,c⟩\lvert a,b,c\rangle has index 4a+2b+c4a+2b+c.

  • 3 qubits
  • allowed gates: H, T, Tdg, CNOT
  • at most 15 gates
  • at most 6 two-qubit gates
  • no measurements

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).

Circuit diagram of your answerEmpty circuitq0q1q2
Statevector amplitudes
BasisAmplitude α|α|Phase arg αProbability
|000⟩1
1.0000
0
100.00%
7 basis states with zero amplitude hidden