QuantumCore

Lesson 19 · 70 min · core

Hadamard, S and T Gates

Loading progress…

The Hadamard gate H=12(X+Z)H=\tfrac1{\sqrt2}(X+Z) exchanges the computational basis with the XX eigenbasis, squares to the identity, and conjugates X↔ZX\leftrightarrow Z and Y↦−YY\mapsto-Y; geometrically it is a rotation by π\pi about the axis (x^+z^)/2(\hat x+\hat z)/\sqrt2, and H=eiπ/2RY(π2)RZ(π)H=e^{i\pi/2}R_Y(\tfrac\pi2)R_Z(\pi). The phase gates S=ZS=\sqrt Z and T=ST=\sqrt S are rotations about zz by π2\tfrac\pi2 and π4\tfrac\pi4 up to global phase. Applied to every qubit, H⊗nH^{\otimes n} turns ∣0n⟩\lvert0^n\rangle into the uniform superposition and ∣x⟩\lvert x\rangle into 2−n/2∑y(−1)x⋅y∣y⟩2^{-n/2}\sum_y(-1)^{x\cdot y}\lvert y\rangle.

Prerequisites: Pauli Gates & the Pauli Algebra

Objectives and key results
  • Write H=12(X+Z)H=\tfrac1{\sqrt2}(X+Z), prove H2=IH^2=I and H=H†H=H^\dagger from {X,Z}=0\{X,Z\}=0, and use HH to change between the ZZ and XX eigenbases.

  • Derive HXH=ZHXH=Z, HZH=XHZH=X and HYH=−YHYH=-Y by explicit algebra with the Pauli product formula σjσk=δjkI+iϵjklσl\sigma_j\sigma_k=\delta_{jk}I+i\epsilon_{jkl}\sigma_l.

  • Identify HH as a rotation by π\pi about n^=(x^+z^)/2\hat n=(\hat x+\hat z)/\sqrt2 and verify H=eiπ/2RY(π2)RZ(π)H=e^{i\pi/2}R_Y(\tfrac\pi2)R_Z(\pi) entry by entry.

  • Prove S2=ZS^2=Z, T2=ST^2=S, T=eiπ/8RZ(π4)T=e^{i\pi/8}R_Z(\tfrac\pi4) and SXS†=YSXS^\dagger=Y, and describe SS and TT as rotations about the zz axis.

  • Prove H⊗n∣x⟩=2−n/2∑y(−1)x⋅y∣y⟩H^{\otimes n}\lvert x\rangle=2^{-n/2}\sum_{y}(-1)^{x\cdot y}\lvert y\rangle and compute every amplitude for n=2n=2.

identity · Hadamard from Paulis
H=12(X+Z)=12(111−1),H2=I,H=H†H=\tfrac1{\sqrt2}(X+Z)=\tfrac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix},\qquad H^2=I,\qquad H=H^\dagger
identity · Hadamard conjugation
HXH=Z,HZH=X,HYH=−YHXH=Z,\qquad HZH=X,\qquad HYH=-Y
formula · Hadamard as a rotation
H=i e−iπ2n^⋅σ⃗,n^=12(1,0,1),H=eiπ/2RY(π2)RZ(π)H=i\,e^{-i\frac\pi2\hat n\cdot\vec\sigma},\quad\hat n=\tfrac1{\sqrt2}(1,0,1),\qquad H=e^{i\pi/2}R_Y(\tfrac\pi2)R_Z(\pi)
identity · Phase gates
S2=Z,T2=S,T=eiπ/8RZ(π4),SXS†=YS^2=Z,\qquad T^2=S,\qquad T=e^{i\pi/8}R_Z(\tfrac\pi4),\qquad SXS^\dagger=Y
theorem · Walsh–Hadamard transform
H⊗n∣x⟩=12n/2∑y∈{0,1}n(−1)x⋅y∣y⟩,H⊗n∣0n⟩=12n/2∑y∈{0,1}n∣y⟩H^{\otimes n}\lvert x\rangle=\frac1{2^{n/2}}\sum_{y\in\{0,1\}^n}(-1)^{x\cdot y}\lvert y\rangle,\qquad H^{\otimes n}\lvert0^n\rangle=\frac1{2^{n/2}}\sum_{y\in\{0,1\}^n}\lvert y\rangle

The Hadamard gate#

Definition

Hadamard gate

The Hadamard gate is the single-qubit operator H=12(111−1)H=\tfrac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}, i.e. H∣0⟩=12(∣0⟩+∣1⟩)=∣+⟩H\lvert0\rangle=\tfrac1{\sqrt2}(\lvert0\rangle+\lvert1\rangle)=\lvert+\rangle and H∣1⟩=12(∣0⟩−∣1⟩)=∣−⟩H\lvert1\rangle=\tfrac1{\sqrt2}(\lvert0\rangle-\lvert1\rangle)=\lvert-\rangle. In outer-product form H=∣+⟩⟨0∣+∣−⟩⟨1∣H=\lvert+\rangle\langle0\rvert+\lvert-\rangle\langle1\rvert.

H=12(111−1)H=\frac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}
Hadamard H2×2

Unitary verified: U†U=IU^\dagger U = I (max deviation 2.2e-16)

Derivation

H=12(X+Z)H=\tfrac1{\sqrt2}(X+Z) and H2=IH^2=I

  1. Step 1:
    X+Z=(0110)+(100−1)=(111−1)X+Z=\begin{pmatrix}0&1\\1&0\end{pmatrix}+\begin{pmatrix}1&0\\0&-1\end{pmatrix}=\begin{pmatrix}1&1\\1&-1\end{pmatrix}
    Add the two Pauli matrices entry by entry.
  2. Step 2:
    H=12(X+Z)H=\tfrac1{\sqrt2}(X+Z)
    Compare with the definition of HH: the matrices agree entry by entry.
  3. Step 3:
    XZ=(0110)(100−1)=(0−110),ZX=(100−1)(0110)=(01−10)XZ=\begin{pmatrix}0&1\\1&0\end{pmatrix}\begin{pmatrix}1&0\\0&-1\end{pmatrix}=\begin{pmatrix}0&-1\\1&0\end{pmatrix},\qquad ZX=\begin{pmatrix}1&0\\0&-1\end{pmatrix}\begin{pmatrix}0&1\\1&0\end{pmatrix}=\begin{pmatrix}0&1\\-1&0\end{pmatrix}
    Row-by-column products; for instance (XZ)01=0⋅0+1⋅(−1)=−1(XZ)_{01}=0\cdot0+1\cdot(-1)=-1 and (ZX)01=1⋅1+0⋅0=1(ZX)_{01}=1\cdot1+0\cdot0=1.
  4. Step 4:
    {X,Z}=XZ+ZX=(0000),XZ=−iY\{X,Z\}=XZ+ZX=\begin{pmatrix}0&0\\0&0\end{pmatrix},\qquad XZ=-iY
    Adding the two products gives zero: XX and ZZ anticommute. Also −iY=−i(0−ii0)=(0−110)=XZ-iY=-i\begin{pmatrix}0&-i\\i&0\end{pmatrix}=\begin{pmatrix}0&-1\\1&0\end{pmatrix}=XZ, consistent with σjσk=δjkI+iϵjklσl\sigma_j\sigma_k=\delta_{jk}I+i\epsilon_{jkl}\sigma_l for (j,k)=(x,z)(j,k)=(x,z), where ϵxzy=−1\epsilon_{xzy}=-1.
  5. Step 5:
    H2=12(X+Z)(X+Z)=12(X2+XZ+ZX+Z2)H^2=\tfrac12(X+Z)(X+Z)=\tfrac12\big(X^2+XZ+ZX+Z^2\big)
    Expand the product; matrix multiplication is distributive but not commutative, so XZXZ and ZXZX are kept separate.
  6. Step 6:
    =12(I+{X,Z}+I)=12(2I+0)=I=\tfrac12\big(I+\{X,Z\}+I\big)=\tfrac12(2I+0)=I
    Every Pauli matrix squares to the identity, X2=Z2=IX^2=Z^2=I, and {X,Z}=0\{X,Z\}=0 from the previous step.
  7. Step 7:
    H†=12(X†+Z†)=12(X+Z)=H ⇒ H†H=H2=IH^\dagger=\tfrac1{\sqrt2}(X^\dagger+Z^\dagger)=\tfrac1{\sqrt2}(X+Z)=H\ \Rightarrow\ H^\dagger H=H^2=I
    XX and ZZ are Hermitian, so HH is Hermitian (it is real and symmetric); together with H2=IH^2=I this shows that HH is unitary and is its own inverse.

Result

H=12(X+Z),H=H†=H−1,H2=I\boxed{H=\tfrac1{\sqrt2}(X+Z),\qquad H=H^\dagger=H^{-1},\qquad H^2=I}
Derivation

Action on the ZZ and XX eigenbases

  1. Step 1:
    H∣0⟩=12(111−1)(10)=12(11)=∣+⟩H\lvert0\rangle=\tfrac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}\begin{pmatrix}1\\0\end{pmatrix}=\tfrac1{\sqrt2}\begin{pmatrix}1\\1\end{pmatrix}=\lvert+\rangle
    H∣0⟩H\lvert0\rangle is the first column of HH.
  2. Step 2:
    H∣1⟩=12(111−1)(01)=12(1−1)=∣−⟩H\lvert1\rangle=\tfrac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}\begin{pmatrix}0\\1\end{pmatrix}=\tfrac1{\sqrt2}\begin{pmatrix}1\\-1\end{pmatrix}=\lvert-\rangle
    H∣1⟩H\lvert1\rangle is the second column of HH.
  3. Step 3:
    H∣+⟩=H H∣0⟩=H2∣0⟩=∣0⟩,H∣−⟩=H2∣1⟩=∣1⟩H\lvert+\rangle=H\,H\lvert0\rangle=H^2\lvert0\rangle=\lvert0\rangle,\qquad H\lvert-\rangle=H^2\lvert1\rangle=\lvert1\rangle
    Substitute ∣±⟩=H∣0⟩,H∣1⟩\lvert\pm\rangle=H\lvert0\rangle,H\lvert1\rangle and use H2=IH^2=I. Directly: H∣+⟩=12(1+11−1)=(10)H\lvert+\rangle=\tfrac12\begin{pmatrix}1+1\\1-1\end{pmatrix}=\begin{pmatrix}1\\0\end{pmatrix}.
  4. Step 4:
    H=∣+⟩⟨0∣+∣−⟩⟨1∣=∣0⟩⟨+∣+∣1⟩⟨−∣H=\lvert+\rangle\langle0\rvert+\lvert-\rangle\langle1\rvert=\lvert0\rangle\langle+\rvert+\lvert1\rangle\langle-\rvert
    A linear map is fixed by its action on a basis; the first form maps ∣k⟩\lvert k\rangle to the kk-th XX eigenvector, and the second is its adjoint, which equals HH because H=H†H=H^\dagger.
  5. Step 5:
    ⟨+∣ψ⟩=⟨0∣H∣ψ⟩,⟨−∣ψ⟩=⟨1∣H∣ψ⟩ ⇒ P(+)=∣⟨0∣H∣ψ⟩∣2,P(−)=∣⟨1∣H∣ψ⟩∣2\langle+\vert\psi\rangle=\langle0\vert H\vert\psi\rangle,\quad\langle-\vert\psi\rangle=\langle1\vert H\vert\psi\rangle\ \Rightarrow\ P(+)=\big\lvert\langle0\vert H\vert\psi\rangle\big\rvert^2,\quad P(-)=\big\lvert\langle1\vert H\vert\psi\rangle\big\rvert^2
    ⟨+∣=(H∣0⟩)†=⟨0∣H†=⟨0∣H\langle+\rvert=(H\lvert0\rangle)^\dagger=\langle0\rvert H^\dagger=\langle0\rvert H, and likewise ⟨−∣=⟨1∣H\langle-\rvert=\langle1\rvert H. Hence measuring in the XX basis is the same as applying HH and then measuring in the computational basis.

Result

H∣0⟩=∣+⟩,H∣1⟩=∣−⟩,H∣+⟩=∣0⟩,H∣−⟩=∣1⟩\boxed{H\lvert0\rangle=\lvert+\rangle,\quad H\lvert1\rangle=\lvert-\rangle,\quad H\lvert+\rangle=\lvert0\rangle,\quad H\lvert-\rangle=\lvert1\rangle}

Quick check

Which state is H∣−⟩H\lvert-\rangle?

Select one answer

Conjugation identities#

Conjugation P↦UPU†P\mapsto UPU^\dagger describes how a gate UU transforms an observable or another gate. Because H=H†H=H^\dagger, conjugation by the Hadamard is simply P↦HPHP\mapsto HPH. The derivations below use only H=12(X+Z)H=\tfrac1{\sqrt2}(X+Z) and the Pauli product formula σjσk=δjkI+iϵjklσl\sigma_j\sigma_k=\delta_{jk}I+i\epsilon_{jkl}\sigma_l, which gives the six products XY=iZ,YZ=iX,ZX=iY,YX=−iZ,ZY=−iX,XZ=−iY,XY=iZ,\quad YZ=iX,\quad ZX=iY,\quad YX=-iZ,\quad ZY=-iX,\quad XZ=-iY, together with X2=Y2=Z2=IX^2=Y^2=Z^2=I. The prefactor is always 12⋅12=12\tfrac1{\sqrt2}\cdot\tfrac1{\sqrt2}=\tfrac12.

Proposition

Hadamard conjugation of the Pauli matrices

HXH=ZHXH=Z, HZH=XHZH=X and HYH=−YHYH=-Y. Consequently, for every real vector r⃗\vec r, H(rxX+ryY+rzZ)H=rzX−ryY+rxZH(r_xX+r_yY+r_zZ)H=r_zX-r_yY+r_xZ.

Proof (11 steps)
  1. Step 1:
    (X+Z)X=X2+ZX=I+iY(X+Z)X=X^2+ZX=I+iY
    Right-multiply X+ZX+Z by XX, then use X2=IX^2=I and ZX=iYZX=iY.
  2. Step 2:
    (I+iY)(X+Z)=X+Z+iYX+iYZ=X+Z+i(−iZ)+i(iX)=X+Z+Z−X=2Z(I+iY)(X+Z)=X+Z+iYX+iYZ=X+Z+i(-iZ)+i(iX)=X+Z+Z-X=2Z
    Expand, substitute YX=−iZYX=-iZ and YZ=iXYZ=iX, and use i⋅(−i)=1i\cdot(-i)=1, i⋅i=−1i\cdot i=-1.
  3. Step 3:
    HXH=12(X+Z)X(X+Z)=12⋅2Z=ZHXH=\tfrac12(X+Z)X(X+Z)=\tfrac12\cdot2Z=Z
    Combine the two previous lines with the prefactor 12\tfrac12.
  4. Step 4:
    (X+Z)Z=XZ+Z2=−iY+I(X+Z)Z=XZ+Z^2=-iY+I
    Right-multiply by ZZ, then use XZ=−iYXZ=-iY and Z2=IZ^2=I.
  5. Step 5:
    (I−iY)(X+Z)=X+Z−iYX−iYZ=X+Z−i(−iZ)−i(iX)=X+Z−Z+X=2X(I-iY)(X+Z)=X+Z-iYX-iYZ=X+Z-i(-iZ)-i(iX)=X+Z-Z+X=2X
    Expand and substitute the same two products; now −i⋅(−i)=−1-i\cdot(-i)=-1 and −i⋅i=1-i\cdot i=1.
  6. Step 6:
    HZH=12(X+Z)Z(X+Z)=12⋅2X=XHZH=\tfrac12(X+Z)Z(X+Z)=\tfrac12\cdot2X=X
    Combine with the prefactor 12\tfrac12.
  7. Step 7:
    (X+Z)Y=XY+ZY=iZ−iX(X+Z)Y=XY+ZY=iZ-iX
    Right-multiply by YY, then use XY=iZXY=iZ and ZY=−iXZY=-iX.
  8. Step 8:
    (iZ−iX)(X+Z)=iZX+iZ2−iX2−iXZ=i(iY)+iI−iI−i(−iY)=−Y−Y=−2Y(iZ-iX)(X+Z)=iZX+iZ^2-iX^2-iXZ=i(iY)+iI-iI-i(-iY)=-Y-Y=-2Y
    Expand, substitute ZX=iYZX=iY, XZ=−iYXZ=-iY, Z2=X2=IZ^2=X^2=I; the identity terms cancel and i⋅i=−1i\cdot i=-1, −i⋅(−i)=−1-i\cdot(-i)=-1.
  9. Step 9:
    HYH=12(X+Z)Y(X+Z)=12⋅(−2Y)=−YHYH=\tfrac12(X+Z)Y(X+Z)=\tfrac12\cdot(-2Y)=-Y
    Combine with the prefactor 12\tfrac12.
  10. Step 10:
    HYH=H(iXZ)H=i (HXH)(HZH)=i ZX=i⋅iY=−YHYH=H(iXZ)H=i\,(HXH)(HZH)=i\,ZX=i\cdot iY=-Y
    Independent check: Y=iXZY=iXZ (multiply XZ=−iYXZ=-iY by ii), and inserting H2=IH^2=I between XX and ZZ splits the conjugation into the two identities already proven.
  11. Step 11:
    H(rxX+ryY+rzZ)H=rxZ−ryY+rzXH(r_xX+r_yY+r_zZ)H=r_xZ-r_yY+r_zX
    Conjugation is linear, so apply the three identities term by term.

∎

Circuit · 1 qubit

Quantum circuit on 1 qubitH on q0; Z on q0; H on q0q0HZH

The sandwich H;Z;HH;Z;H implements exactly HZH=XHZH=X: the unitary panel shows (0110)\begin{pmatrix}0&1\\1&0\end{pmatrix}, and starting from ∣0⟩\lvert0\rangle the output is ∣1⟩\lvert1\rangle. The phase flip ZZ in the XX basis is a bit flip in the ZZ basis.

∣ψ⟩=1∣1⟩\lvert\psi\rangle = 1\lvert 1\rangle
U=(0110)U = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}

Circuit · 1 qubit

Quantum circuit on 1 qubitH on q0; Y on q0; H on q0q0HYH

The sandwich H;Y;HH;Y;H implements HYH=−Y=(0i−i0)HYH=-Y=\begin{pmatrix}0&i\\-i&0\end{pmatrix}, which differs from YY by the global phase −1-1 and therefore acts on the Bloch sphere exactly like YY.

U=(0i−i0)U = \begin{pmatrix} 0 & i \\ -i & 0 \end{pmatrix}

Comparing two circuits. The identity playground below draws two single-qubit circuits side by side, multiplies out their unitaries ULU_L and URU_R, and reports FU=∣Tr(UL†UR)∣/dF_U=\lvert\mathrm{Tr}(U_L^\dagger U_R)\rvert/d with d=2d=2. By the Cauchy–Schwarz inequality for the Hilbert–Schmidt inner product, FU=1F_U=1 exactly when UR=eiφULU_R=e^{i\varphi}U_L, and the playground then prints the verdict "equal" (φ=0\varphi=0) or "equal up to global phase eiφe^{i\varphi}" together with φ\varphi. The circuits here are fixed; the menu offers five identities, written as matrix products whose right-most factor acts first: HXH=ZHXH=Z, HYH=−YHYH=-Y, TT=STT=S, HH=IHH=I and XYZ=iIXYZ=iI. Predict each verdict with the derivation below before selecting it.

Derivation

What the playground reports for HXH=ZHXH=Z and HYH=−YHYH=-Y

  1. Step 1:
    HX=12(111−1)(0110)=12(11−11)HX=\tfrac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}\begin{pmatrix}0&1\\1&0\end{pmatrix}=\tfrac1{\sqrt2}\begin{pmatrix}1&1\\-1&1\end{pmatrix}
    Right multiplication by XX swaps the two columns of HH.
  2. Step 2:
    HXH=12(11−11)(111−1)=12(200−2)=ZHXH=\tfrac12\begin{pmatrix}1&1\\-1&1\end{pmatrix}\begin{pmatrix}1&1\\1&-1\end{pmatrix}=\tfrac12\begin{pmatrix}2&0\\0&-2\end{pmatrix}=Z
    Row by column: 1+1=21+1=2, 1−1=01-1=0, −1+1=0-1+1=0, −1−1=−2-1-1=-2.
  3. Step 3:
    Tr(Z†Z)=Tr I=2=2ei0 ⇒ FU=22=1, φ=0\mathrm{Tr}(Z^\dagger Z)=\mathrm{Tr}\,I=2=2e^{i0}\ \Rightarrow\ F_U=\tfrac22=1,\ \varphi=0
    The two unitaries coincide, so the verdict is "equal".
  4. Step 4:
    HY=12(111−1)(0−ii0)=12(i−i−i−i)HY=\tfrac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}\begin{pmatrix}0&-i\\i&0\end{pmatrix}=\tfrac1{\sqrt2}\begin{pmatrix}i&-i\\-i&-i\end{pmatrix}
    Entries 1⋅0+1⋅i1\cdot0+1\cdot i, 1⋅(−i)+1⋅01\cdot(-i)+1\cdot0, 1⋅0+(−1)⋅i1\cdot0+(-1)\cdot i and 1⋅(−i)+(−1)⋅01\cdot(-i)+(-1)\cdot0.
  5. Step 5:
    HYH=12(i−i−i−i)(111−1)=12(02i−2i0)=(0i−i0)=−YHYH=\tfrac12\begin{pmatrix}i&-i\\-i&-i\end{pmatrix}\begin{pmatrix}1&1\\1&-1\end{pmatrix}=\tfrac12\begin{pmatrix}0&2i\\-2i&0\end{pmatrix}=\begin{pmatrix}0&i\\-i&0\end{pmatrix}=-Y
    Row by column: i−i=0i-i=0, i+i=2ii+i=2i, −i−i=−2i-i-i=-2i, −i+i=0-i+i=0.
  6. Step 6:
    Tr((−Y)†Y)=−Tr(Y2)=−2=2eiπ ⇒ FU=1, φ=π\mathrm{Tr}\big((-Y)^\dagger Y\big)=-\mathrm{Tr}(Y^2)=-2=2e^{i\pi}\ \Rightarrow\ F_U=1,\ \varphi=\pi
    Y†=YY^\dagger=Y and Y2=IY^2=I. The verdict is "equal up to global phase eiπ=−1e^{i\pi}=-1": both circuits move every Bloch vector in the same way, although the matrices differ. Such a sign becomes observable once the gate is controlled (Module 2.3).

Result

HXH=Z  (FU=1, φ=0),HYH=eiπ Y  (FU=1, φ=π)\boxed{HXH=Z\ \ (F_U=1,\ \varphi=0),\qquad HYH=e^{i\pi}\,Y\ \ (F_U=1,\ \varphi=\pi)}

Then select the other three. TT=STT=S is an exact equality, since diag(1,eiπ/4)2=diag(1,eiπ/2)=S\mathrm{diag}(1,e^{i\pi/4})^2=\mathrm{diag}(1,e^{i\pi/2})=S (proved in the next section), and HH=IHH=I is exact by H2=IH^2=I. For XYZ=iIXYZ=iI the left circuit applies ZZ, then YY, then XX, so its unitary is the product XYZ=(XY)Z=iZ⋅Z=iIXYZ=(XY)Z=iZ\cdot Z=iI; it equals the empty circuit only up to the global phase eiπ/2e^{i\pi/2}. Applying the same three gates in the time order XX, YY, ZZ gives ZYX=−iIZYX=-iI instead, a reminder that the order of factors is reversed with respect to the wire.

Quick check

Which operator equals HZHHZH?

Select one answer

The Hadamard as a rotation#

Derivation

HH is a rotation by π\pi about (x^+z^)/2(\hat x+\hat z)/\sqrt2

  1. Step 1:
    n^=12(1,0,1),∥n^∥2=12+0+12=1\hat n=\tfrac1{\sqrt2}(1,0,1),\qquad\lVert\hat n\rVert^2=\tfrac12+0+\tfrac12=1
    The unit vector bisecting the +x+x and +z+z axes.
  2. Step 2:
    n^⋅σ⃗=12X+0⋅Y+12Z=12(X+Z)=H\hat n\cdot\vec\sigma=\tfrac1{\sqrt2}X+0\cdot Y+\tfrac1{\sqrt2}Z=\tfrac1{\sqrt2}(X+Z)=H
    Use H=12(X+Z)H=\tfrac1{\sqrt2}(X+Z) from the first section.
  3. Step 3:
    (n^⋅σ⃗)2=∑j,knjnkσjσk=∑j,knjnk(δjkI+iϵjklσl)=∥n^∥2I=I(\hat n\cdot\vec\sigma)^2=\textstyle\sum_{j,k}n_jn_k\sigma_j\sigma_k=\sum_{j,k}n_jn_k\big(\delta_{jk}I+i\epsilon_{jkl}\sigma_l\big)=\lVert\hat n\rVert^2I=I
    The ϵ\epsilon term is antisymmetric in (j,k)(j,k) while njnkn_jn_k is symmetric, so it sums to zero.
  4. Step 4:
    e−iα2n^⋅σ⃗=∑m≥0(−iα/2)mm!(n^⋅σ⃗)m=cos⁡α2 I−isin⁡α2 n^⋅σ⃗e^{-i\frac\alpha2\hat n\cdot\vec\sigma}=\sum_{m\ge0}\frac{(-i\alpha/2)^m}{m!}(\hat n\cdot\vec\sigma)^m=\cos\tfrac\alpha2\,I-i\sin\tfrac\alpha2\,\hat n\cdot\vec\sigma
    Even powers of n^⋅σ⃗\hat n\cdot\vec\sigma equal II and odd powers equal n^⋅σ⃗\hat n\cdot\vec\sigma; the even terms sum to cos⁡α2\cos\tfrac\alpha2 and the odd terms to −isin⁡α2-i\sin\tfrac\alpha2.
  5. Step 5:
    Rn^(π)=e−iπ2n^⋅σ⃗=cos⁡π2 I−isin⁡π2 n^⋅σ⃗=−i n^⋅σ⃗=−iHR_{\hat n}(\pi)=e^{-i\frac\pi2\hat n\cdot\vec\sigma}=\cos\tfrac\pi2\,I-i\sin\tfrac\pi2\,\hat n\cdot\vec\sigma=-i\,\hat n\cdot\vec\sigma=-iH
    Set α=π\alpha=\pi: cos⁡π2=0\cos\tfrac\pi2=0 and sin⁡π2=1\sin\tfrac\pi2=1.
  6. Step 6:
    H=i Rn^(π)=eiπ/2 e−iπ2n^⋅σ⃗H=i\,R_{\hat n}(\pi)=e^{i\pi/2}\,e^{-i\frac\pi2\hat n\cdot\vec\sigma}
    Multiply by ii and use i⋅(−i)=1i\cdot(-i)=1. The factor i=eiπ/2i=e^{i\pi/2} is a global phase, so on the Bloch sphere HH acts exactly as the rotation Rn^(π)R_{\hat n}(\pi).
  7. Step 7:
    r⃗ ↦ cos⁡π r⃗+sin⁡π (n^×r⃗)+(1−cos⁡π)(n^⋅r⃗) n^=2(n^⋅r⃗) n^−r⃗\vec r\ \mapsto\ \cos\pi\,\vec r+\sin\pi\,(\hat n\times\vec r)+(1-\cos\pi)(\hat n\cdot\vec r)\,\hat n=2(\hat n\cdot\vec r)\,\hat n-\vec r
    Rodrigues' rotation formula at angle π\pi, with cos⁡π=−1\cos\pi=-1 and sin⁡π=0\sin\pi=0.
  8. Step 8:
    2(n^⋅r⃗)n^−r⃗=(rx+rz)(1,0,1)−(rx,ry,rz)=(rz, −ry, rx)2(\hat n\cdot\vec r)\hat n-\vec r=(r_x+r_z)(1,0,1)-(r_x,r_y,r_z)=(r_z,\,-r_y,\,r_x)
    n^⋅r⃗=(rx+rz)/2\hat n\cdot\vec r=(r_x+r_z)/\sqrt2, so 2(n^⋅r⃗)n^=(rx+rz)(1,0,1)2(\hat n\cdot\vec r)\hat n=(r_x+r_z)(1,0,1). This is exactly the map H(r⃗⋅σ⃗)H=rzX−ryY+rxZH(\vec r\cdot\vec\sigma)H=r_zX-r_yY+r_xZ of the conjugation proposition: x↔zx\leftrightarrow z and y↦−yy\mapsto-y.

Result

H=eiπ/2Rn^(π),n^=12(x^+z^),(rx,ry,rz)↦(rz,−ry,rx)\boxed{H=e^{i\pi/2}R_{\hat n}(\pi),\quad\hat n=\tfrac1{\sqrt2}(\hat x+\hat z),\qquad(r_x,r_y,r_z)\mapsto(r_z,-r_y,r_x)}
Derivation

H=eiπ/2RY(π2)RZ(π)H=e^{i\pi/2}R_Y(\tfrac\pi2)R_Z(\pi) by matrix multiplication

  1. Step 1:
    RY(θ)=(cos⁡θ2−sin⁡θ2sin⁡θ2cos⁡θ2),RZ(θ)=(e−iθ/200eiθ/2)R_Y(\theta)=\begin{pmatrix}\cos\frac\theta2&-\sin\frac\theta2\\\sin\frac\theta2&\cos\frac\theta2\end{pmatrix},\qquad R_Z(\theta)=\begin{pmatrix}e^{-i\theta/2}&0\\0&e^{i\theta/2}\end{pmatrix}
    The platform conventions RP(θ)=e−iθP/2R_P(\theta)=e^{-i\theta P/2} for P=YP=Y and P=ZP=Z.
  2. Step 2:
    RY(π2)=(cos⁡π4−sin⁡π4sin⁡π4cos⁡π4)=12(1−111)R_Y(\tfrac\pi2)=\begin{pmatrix}\cos\frac\pi4&-\sin\frac\pi4\\\sin\frac\pi4&\cos\frac\pi4\end{pmatrix}=\frac1{\sqrt2}\begin{pmatrix}1&-1\\1&1\end{pmatrix}
    cos⁡π4=sin⁡π4=12\cos\tfrac\pi4=\sin\tfrac\pi4=\tfrac1{\sqrt2}.
  3. Step 3:
    RZ(π)=(e−iπ/200eiπ/2)=(−i00i)R_Z(\pi)=\begin{pmatrix}e^{-i\pi/2}&0\\0&e^{i\pi/2}\end{pmatrix}=\begin{pmatrix}-i&0\\0&i\end{pmatrix}
    Euler's formula: e±iπ/2=cos⁡π2±isin⁡π2=±ie^{\pm i\pi/2}=\cos\tfrac\pi2\pm i\sin\tfrac\pi2=\pm i.
  4. Step 4:
    RY(π2)RZ(π)=12(1⋅(−i)+(−1)⋅01⋅0+(−1)⋅i1⋅(−i)+1⋅01⋅0+1⋅i)=12(−i−i−ii)R_Y(\tfrac\pi2)R_Z(\pi)=\frac1{\sqrt2}\begin{pmatrix}1\cdot(-i)+(-1)\cdot0&1\cdot0+(-1)\cdot i\\1\cdot(-i)+1\cdot0&1\cdot0+1\cdot i\end{pmatrix}=\frac1{\sqrt2}\begin{pmatrix}-i&-i\\-i&i\end{pmatrix}
    Row-by-column products, every entry written out.
  5. Step 5:
    =−i2(111−1)=−iH=-\frac{i}{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}=-iH
    Factor −i-i out of every entry: −i⋅1=−i-i\cdot1=-i and −i⋅(−1)=i-i\cdot(-1)=i.
  6. Step 6:
    H=i RY(π2)RZ(π)=eiπ/2RY(π2)RZ(π)H=i\,R_Y(\tfrac\pi2)R_Z(\pi)=e^{i\pi/2}R_Y(\tfrac\pi2)R_Z(\pi)
    Multiply both sides by ii; on a circuit wire this is RZ(π)R_Z(\pi) first and RY(π2)R_Y(\tfrac\pi2) second.

Result

RY(π2)RZ(π)=−i2(111−1)=−iH,H=eiπ/2RY(π2)RZ(π)\boxed{R_Y(\tfrac\pi2)R_Z(\pi)=-\frac{i}{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}=-iH,\qquad H=e^{i\pi/2}R_Y(\tfrac\pi2)R_Z(\pi)}

Circuit · 1 qubit

Quantum circuit on 1 qubitRZ(π) on q0; RY(π/2) on q0q0RZ(π)RY(π/2)

RZ(π)R_Z(\pi) followed by RY(π2)R_Y(\tfrac\pi2). The unitary panel shows −i2(111−1)=−iH-\tfrac{i}{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}=-iH: the same gate as HH up to the unobservable global phase −i-i.

U=(−12 i−12 i−12 i12 i)U = \begin{pmatrix} -\tfrac{1}{\sqrt{2}}\,i & -\tfrac{1}{\sqrt{2}}\,i \\ -\tfrac{1}{\sqrt{2}}\,i & \tfrac{1}{\sqrt{2}}\,i \end{pmatrix}

The phase gates S and T#

Definition

Phase gates S and T

The phase gate S=(100i)S=\begin{pmatrix}1&0\\0&i\end{pmatrix} and the TT gate (also called the π/8\pi/8 gate) T=(100eiπ/4)T=\begin{pmatrix}1&0\\0&e^{i\pi/4}\end{pmatrix} leave ∣0⟩\lvert0\rangle unchanged and multiply the ∣1⟩\lvert1\rangle amplitude by i=eiπ/2i=e^{i\pi/2} and eiπ/4=1+i2e^{i\pi/4}=\tfrac{1+i}{\sqrt2} respectively. Their inverses are S†=diag(1,−i)S^\dagger=\mathrm{diag}(1,-i) and T†=diag(1,e−iπ/4)T^\dagger=\mathrm{diag}(1,e^{-i\pi/4}).

S=(100i)S=\begin{pmatrix}1&0\\0&i\end{pmatrix}
Phase gate S2×2

Unitary verified: U†U=IU^\dagger U = I (max deviation 0.0e+0)

T=(100eiπ/4)=(1001+i2)T=\begin{pmatrix}1&0\\0&e^{i\pi/4}\end{pmatrix}=\begin{pmatrix}1&0\\0&\frac{1+i}{\sqrt2}\end{pmatrix}
T gate2×2

Unitary verified: U†U=IU^\dagger U = I (max deviation 2.2e-16)

The matrix display below recognises the entry 1+i2≈0.707+0.707i\tfrac{1+i}{\sqrt2}\approx0.707+0.707i and prints it symbolically as eiπ/4e^{i\pi/4}. Its property list shows what distinguishes TT from the Pauli and Hadamard gates: TT is unitary and normal but not Hermitian, because eiπ/4‾=e−iπ/4≠eiπ/4\overline{e^{i\pi/4}}=e^{-i\pi/4}\neq e^{i\pi/4}, so TT is a gate but not an observable. Its trace is 1+eiπ/4≈1.707+0.707i1+e^{i\pi/4}\approx1.707+0.707i, with modulus ∣1+eiπ/4∣=2cos⁡π8≈1.848\lvert1+e^{i\pi/4}\rvert=2\cos\tfrac\pi8\approx1.848, and its determinant is det⁡T=1⋅eiπ/4=eiπ/4\det T=1\cdot e^{i\pi/4}=e^{i\pi/4}. As for every diagonal matrix, the eigenvalues are the diagonal entries 11 and eiπ/4e^{i\pi/4}, both on the unit circle.

Derivation

S2=ZS^2=Z, T2=ST^2=S and T=eiπ/8RZ(π4)T=e^{i\pi/8}R_Z(\tfrac\pi4)

  1. Step 1:
    S†S=(100−i)(100i)=(100(−i)i)=I,T†T=(100e−iπ/4eiπ/4)=IS^\dagger S=\begin{pmatrix}1&0\\0&-i\end{pmatrix}\begin{pmatrix}1&0\\0&i\end{pmatrix}=\begin{pmatrix}1&0\\0&(-i)i\end{pmatrix}=I,\qquad T^\dagger T=\begin{pmatrix}1&0\\0&e^{-i\pi/4}e^{i\pi/4}\end{pmatrix}=I
    Diagonal matrices multiply entry by entry, and ∣eiφ∣2=1\lvert e^{i\varphi}\rvert^2=1: both gates are unitary.
  2. Step 2:
    S2=(1200i2)=(100−1)=ZS^2=\begin{pmatrix}1^2&0\\0&i^2\end{pmatrix}=\begin{pmatrix}1&0\\0&-1\end{pmatrix}=Z
    Square the diagonal entries; i2=−1i^2=-1. So SS is a square root of ZZ.
  3. Step 3:
    T2=(100(eiπ/4)2)=(100eiπ/2)=(100i)=ST^2=\begin{pmatrix}1&0\\0&(e^{i\pi/4})^2\end{pmatrix}=\begin{pmatrix}1&0\\0&e^{i\pi/2}\end{pmatrix}=\begin{pmatrix}1&0\\0&i\end{pmatrix}=S
    (eiπ/4)2=eiπ/2=i(e^{i\pi/4})^2=e^{i\pi/2}=i. Hence TT is a square root of SS, and T4=S2=ZT^4=S^2=Z, T8=Z2=IT^8=Z^2=I.
  4. Step 4:
    RZ(π4)=(e−iπ/800eiπ/8)R_Z(\tfrac\pi4)=\begin{pmatrix}e^{-i\pi/8}&0\\0&e^{i\pi/8}\end{pmatrix}
    Put θ=π4\theta=\tfrac\pi4 in RZ(θ)=diag(e−iθ/2,eiθ/2)R_Z(\theta)=\mathrm{diag}(e^{-i\theta/2},e^{i\theta/2}).
  5. Step 5:
    eiπ/8RZ(π4)=(eiπ/8e−iπ/800eiπ/8eiπ/8)=(e000eiπ/4)=Te^{i\pi/8}R_Z(\tfrac\pi4)=\begin{pmatrix}e^{i\pi/8}e^{-i\pi/8}&0\\0&e^{i\pi/8}e^{i\pi/8}\end{pmatrix}=\begin{pmatrix}e^{0}&0\\0&e^{i\pi/4}\end{pmatrix}=T
    Multiply each diagonal entry by eiπ/8e^{i\pi/8} and add exponents: π8−π8=0\tfrac\pi8-\tfrac\pi8=0 and π8+π8=π4\tfrac\pi8+\tfrac\pi8=\tfrac\pi4. The off-diagonal entries stay 00.
  6. Step 6:
    eiπ/4RZ(π2)=(eiπ/4e−iπ/400eiπ/4eiπ/4)=(100i)=S,eiπ/2RZ(π)=i(−i00i)=Ze^{i\pi/4}R_Z(\tfrac\pi2)=\begin{pmatrix}e^{i\pi/4}e^{-i\pi/4}&0\\0&e^{i\pi/4}e^{i\pi/4}\end{pmatrix}=\begin{pmatrix}1&0\\0&i\end{pmatrix}=S,\qquad e^{i\pi/2}R_Z(\pi)=i\begin{pmatrix}-i&0\\0&i\end{pmatrix}=Z
    The same computation with θ=π2\theta=\tfrac\pi2 and θ=π\theta=\pi: in general diag(1,eiφ)=eiφ/2RZ(φ)\mathrm{diag}(1,e^{i\varphi})=e^{i\varphi/2}R_Z(\varphi).

Result

S2=Z,T2=S,T=eiπ/8RZ(π4),S=eiπ/4RZ(π2)\boxed{S^2=Z,\qquad T^2=S,\qquad T=e^{i\pi/8}R_Z(\tfrac\pi4),\qquad S=e^{i\pi/4}R_Z(\tfrac\pi2)}
Derivation

SXS†=YSXS^\dagger=Y and the Bloch picture of SS and TT

  1. Step 1:
    SX=(100i)(0110)=(1⋅0+0⋅11⋅1+0⋅00⋅0+i⋅10⋅1+i⋅0)=(01i0)SX=\begin{pmatrix}1&0\\0&i\end{pmatrix}\begin{pmatrix}0&1\\1&0\end{pmatrix}=\begin{pmatrix}1\cdot0+0\cdot1&1\cdot1+0\cdot0\\0\cdot0+i\cdot1&0\cdot1+i\cdot0\end{pmatrix}=\begin{pmatrix}0&1\\i&0\end{pmatrix}
    Row-by-column product; left multiplication by a diagonal matrix scales the rows.
  2. Step 2:
    (SX)S†=(01i0)(100−i)=(0⋅1+1⋅00⋅0+1⋅(−i)i⋅1+0⋅0i⋅0+0⋅(−i))=(0−ii0)=Y(SX)S^\dagger=\begin{pmatrix}0&1\\i&0\end{pmatrix}\begin{pmatrix}1&0\\0&-i\end{pmatrix}=\begin{pmatrix}0\cdot1+1\cdot0&0\cdot0+1\cdot(-i)\\i\cdot1+0\cdot0&i\cdot0+0\cdot(-i)\end{pmatrix}=\begin{pmatrix}0&-i\\i&0\end{pmatrix}=Y
    Right multiplication by the diagonal S†S^\dagger scales the columns.
  3. Step 3:
    SYS†=(0−ii⋅i0)(100−i)=(0(−i)(−i)−10)=(0−1−10)=−X,SZS†=ZSYS^\dagger=\begin{pmatrix}0&-i\\i\cdot i&0\end{pmatrix}\begin{pmatrix}1&0\\0&-i\end{pmatrix}=\begin{pmatrix}0&(-i)(-i)\\-1&0\end{pmatrix}=\begin{pmatrix}0&-1\\-1&0\end{pmatrix}=-X,\qquad SZS^\dagger=Z
    The same two steps for YY (SYSY multiplies the second row of YY by ii); ZZ is diagonal and commutes with SS, so SZS†=ZSS†=ZSZS^\dagger=ZSS^\dagger=Z.
  4. Step 4:
    P(φ)XP(φ)†=(0e−iφeiφ0)=cos⁡φ X+sin⁡φ Y,P(φ)=diag(1,eiφ)P(\varphi)XP(\varphi)^\dagger=\begin{pmatrix}0&e^{-i\varphi}\\e^{i\varphi}&0\end{pmatrix}=\cos\varphi\,X+\sin\varphi\,Y,\qquad P(\varphi)=\mathrm{diag}(1,e^{i\varphi})
    Scale row 11 of XX by eiφe^{i\varphi} and column 11 by e−iφe^{-i\varphi}; then cos⁡φX+sin⁡φY=(0cos⁡φ−isin⁡φcos⁡φ+isin⁡φ0)\cos\varphi X+\sin\varphi Y=\begin{pmatrix}0&\cos\varphi-i\sin\varphi\\\cos\varphi+i\sin\varphi&0\end{pmatrix} by Euler's formula. Likewise P(φ)YP(φ)†=−sin⁡φX+cos⁡φYP(\varphi)YP(\varphi)^\dagger=-\sin\varphi X+\cos\varphi Y.
  5. Step 5:
    (rx,ry,rz) ↦ P(φ)  (rxcos⁡φ−rysin⁡φ, rxsin⁡φ+rycos⁡φ, rz)(r_x,r_y,r_z)\ \xmapsto{\ P(\varphi)\ }\ (r_x\cos\varphi-r_y\sin\varphi,\ r_x\sin\varphi+r_y\cos\varphi,\ r_z)
    Apply the conjugation to 12(I+r⃗⋅σ⃗)\tfrac12(I+\vec r\cdot\vec\sigma) term by term: a rotation by φ\varphi about the zz axis. SS is the case φ=π2\varphi=\tfrac\pi2 (+x→+y+x\to+y, +y→−x+y\to-x) and TT the case φ=π4\varphi=\tfrac\pi4.

Result

SXS†=Y,SYS†=−X,TXT†=12(X+Y)\boxed{SXS^\dagger=Y,\qquad SYS^\dagger=-X,\qquad TXT^\dagger=\tfrac1{\sqrt2}(X+Y)}

Circuit · 1 qubit

Quantum circuit on 1 qubitH on q0; S on q0; H on q0q0HSH

The sandwich H;S;HH;S;H is half of the lab answer. Its unitary is HSH=12(1+i1−i1−i1+i)=XHSH=\tfrac12\begin{pmatrix}1+i&1-i\\1-i&1+i\end{pmatrix}=\sqrt X, a rotation by π2\tfrac\pi2 about xx up to global phase: one SS is a quarter turn about zz, and the Hadamards move that axis to xx.

∣ψ⟩=(12+12 i)∣0⟩+(12−12 i)∣1⟩\lvert\psi\rangle = \left(\tfrac{1}{2} + \tfrac{1}{2}\,i\right)\lvert 0\rangle + \left(\tfrac{1}{2} - \tfrac{1}{2}\,i\right)\lvert 1\rangle
U=(12+12 i12−12 i12−12 i12+12 i)U = \begin{pmatrix} \tfrac{1}{2} + \tfrac{1}{2}\,i & \tfrac{1}{2} - \tfrac{1}{2}\,i \\ \tfrac{1}{2} - \tfrac{1}{2}\,i & \tfrac{1}{2} + \tfrac{1}{2}\,i \end{pmatrix}

Quick check

Which gate equals TT up to a global phase?

Select one answer

Quick check

What is the smallest positive integer kk with Tk=ZT^k=Z?

tolerance ±1e-9

Hadamard on many qubits#

Theorem

Walsh–Hadamard transform

For every n≥1n\ge1 and every bit string x=x0x1⋯xn−1∈{0,1}nx=x_0x_1\cdots x_{n-1}\in\{0,1\}^n, H⊗n∣x⟩=2−n/2∑y∈{0,1}n(−1)x⋅y∣y⟩H^{\otimes n}\lvert x\rangle=2^{-n/2}\sum_{y\in\{0,1\}^n}(-1)^{x\cdot y}\lvert y\rangle with x⋅y=∑ixiyix\cdot y=\sum_ix_iy_i. In particular H⊗n∣0n⟩=2−n/2∑y∣y⟩H^{\otimes n}\lvert0^n\rangle=2^{-n/2}\sum_y\lvert y\rangle is the uniform superposition of all 2n2^n basis states.

Proof (6 steps)
  1. Step 1:
    H∣b⟩=12∑c∈{0,1}(−1)bc∣c⟩,b∈{0,1}H\lvert b\rangle=\tfrac1{\sqrt2}\textstyle\sum_{c\in\{0,1\}}(-1)^{bc}\lvert c\rangle,\qquad b\in\{0,1\}
    Base case n=1n=1: for b=0b=0 every sign is (−1)0=+1(-1)^0=+1, giving ∣+⟩\lvert+\rangle; for b=1b=1 the sign is (−1)c(-1)^c, giving 12(∣0⟩−∣1⟩)=∣−⟩\tfrac1{\sqrt2}(\lvert0\rangle-\lvert1\rangle)=\lvert-\rangle.
  2. Step 2:
    H⊗(n+1)∣x xn⟩=(H⊗n∣x⟩)⊗(H∣xn⟩)H^{\otimes(n+1)}\lvert x\,x_n\rangle=\big(H^{\otimes n}\lvert x\rangle\big)\otimes\big(H\lvert x_n\rangle\big)
    Induction step: ∣x xn⟩=∣x⟩⊗∣xn⟩\lvert x\,x_n\rangle=\lvert x\rangle\otimes\lvert x_n\rangle for x∈{0,1}nx\in\{0,1\}^n, and (A⊗B)(∣u⟩⊗∣v⟩)=A∣u⟩⊗B∣v⟩(A\otimes B)(\lvert u\rangle\otimes\lvert v\rangle)=A\lvert u\rangle\otimes B\lvert v\rangle.
  3. Step 3:
    =(2−n/2∑y(−1)x⋅y∣y⟩)⊗(2−1/2∑c(−1)xnc∣c⟩)=\Big(2^{-n/2}\textstyle\sum_{y}(-1)^{x\cdot y}\lvert y\rangle\Big)\otimes\Big(2^{-1/2}\sum_{c}(-1)^{x_nc}\lvert c\rangle\Big)
    Insert the induction hypothesis for nn qubits and the base case for the last qubit.
  4. Step 4:
    =2−(n+1)/2∑y∑c(−1)x⋅y+xnc∣y c⟩=2^{-(n+1)/2}\textstyle\sum_{y}\sum_{c}(-1)^{x\cdot y+x_nc}\lvert y\,c\rangle
    The tensor product is bilinear, so it distributes over both sums; the scalars multiply, 2−n/2⋅2−1/2=2−(n+1)/22^{-n/2}\cdot2^{-1/2}=2^{-(n+1)/2}, and the signs add in the exponent.
  5. Step 5:
    =2−(n+1)/2∑y′∈{0,1}n+1(−1)(x xn)⋅y′∣y′⟩=2^{-(n+1)/2}\textstyle\sum_{y'\in\{0,1\}^{n+1}}(-1)^{(x\,x_n)\cdot y'}\lvert y'\rangle
    Rename y′=y cy'=y\,c; then x⋅y+xnc=∑i=0nxiyi′=(x xn)⋅y′x\cdot y+x_nc=\sum_{i=0}^{n}x_iy'_i=(x\,x_n)\cdot y', which completes the induction.
  6. Step 6:
    H⊗n∣0n⟩=2−n/2∑y(−1)0∣y⟩=2−n/2∑y∣y⟩H^{\otimes n}\lvert0^n\rangle=2^{-n/2}\textstyle\sum_y(-1)^{0}\lvert y\rangle=2^{-n/2}\sum_y\lvert y\rangle
    For x=0nx=0^n every product x⋅yx\cdot y vanishes. The state is normalised: 2n2^n amplitudes each of squared modulus 2−n2^{-n}.

∎

Derivation

Worked example: n=2n=2

  1. Step 1:
    H⊗2∣00⟩=H∣0⟩⊗H∣0⟩=12(∣0⟩+∣1⟩)⊗12(∣0⟩+∣1⟩)H^{\otimes2}\lvert00\rangle=H\lvert0\rangle\otimes H\lvert0\rangle=\tfrac1{\sqrt2}(\lvert0\rangle+\lvert1\rangle)\otimes\tfrac1{\sqrt2}(\lvert0\rangle+\lvert1\rangle)
    Apply HH to each qubit separately.
  2. Step 2:
    =12(∣00⟩+∣01⟩+∣10⟩+∣11⟩) ↔ (12,12,12,12)T=\tfrac12\big(\lvert00\rangle+\lvert01\rangle+\lvert10\rangle+\lvert11\rangle\big)\ \leftrightarrow\ \big(\tfrac12,\tfrac12,\tfrac12,\tfrac12\big)^T
    Expand the tensor product; with qubit 0 as the most significant bit the amplitudes are listed in the order ∣00⟩,∣01⟩,∣10⟩,∣11⟩\lvert00\rangle,\lvert01\rangle,\lvert10\rangle,\lvert11\rangle, each with probability 14\tfrac14.
  3. Step 3:
    H⊗2∣01⟩=12(∣0⟩+∣1⟩)⊗12(∣0⟩−∣1⟩)=12(∣00⟩−∣01⟩+∣10⟩−∣11⟩)H^{\otimes2}\lvert01\rangle=\tfrac1{\sqrt2}(\lvert0\rangle+\lvert1\rangle)\otimes\tfrac1{\sqrt2}(\lvert0\rangle-\lvert1\rangle)=\tfrac12\big(\lvert00\rangle-\lvert01\rangle+\lvert10\rangle-\lvert11\rangle\big)
    Here x=01x=01, so x⋅y=y1x\cdot y=y_1: the sign is −1-1 exactly when the second bit of yy is 11.
  4. Step 4:
    H⊗2∣11⟩=12(∣0⟩−∣1⟩)⊗12(∣0⟩−∣1⟩)=12(∣00⟩−∣01⟩−∣10⟩+∣11⟩)H^{\otimes2}\lvert11\rangle=\tfrac1{\sqrt2}(\lvert0\rangle-\lvert1\rangle)\otimes\tfrac1{\sqrt2}(\lvert0\rangle-\lvert1\rangle)=\tfrac12\big(\lvert00\rangle-\lvert01\rangle-\lvert10\rangle+\lvert11\rangle\big)
    Here x⋅y=y0+y1x\cdot y=y_0+y_1, so the sign is −1-1 for y=01y=01 and y=10y=10 and +1+1 for y=11y=11, where (−1)2=1(-1)^2=1.
  5. Step 5:
    H⊗H=12(11111−11−111−1−11−1−11),(H⊗H)yx=12(−1)x⋅yH\otimes H=\frac12\begin{pmatrix}1&1&1&1\\1&-1&1&-1\\1&1&-1&-1\\1&-1&-1&1\end{pmatrix},\qquad(H\otimes H)_{yx}=\tfrac12(-1)^{x\cdot y}
    Column xx of the matrix is H⊗2∣x⟩H^{\otimes2}\lvert x\rangle; the four columns are the four expansions for x=00,01,10,11x=00,01,10,11 (the column for x=10x=10 is 12(1,1,−1,−1)T\tfrac12(1,1,-1,-1)^T by the same rule).

Result

H⊗2∣00⟩=12(∣00⟩+∣01⟩+∣10⟩+∣11⟩)\boxed{H^{\otimes2}\lvert00\rangle=\tfrac12\big(\lvert00\rangle+\lvert01\rangle+\lvert10\rangle+\lvert11\rangle\big)}

Circuit · 2 qubits

Quantum circuit on 2 qubitsH on q0; H on q1q0q1HH

HH on both qubits of ∣00⟩\lvert00\rangle produces the uniform superposition with amplitudes (12,12,12,12)(\tfrac12,\tfrac12,\tfrac12,\tfrac12); the unitary panel shows the 4×44\times4 Walsh–Hadamard matrix 12((−1)x⋅y)y,x\tfrac12\big((-1)^{x\cdot y}\big)_{y,x}.

∣ψ⟩=12∣00⟩+12∣01⟩+12∣10⟩+12∣11⟩\lvert\psi\rangle = \tfrac{1}{2}\lvert 00\rangle + \tfrac{1}{2}\lvert 01\rangle + \tfrac{1}{2}\lvert 10\rangle + \tfrac{1}{2}\lvert 11\rangle
U=(1212121212−1212−121212−12−1212−12−1212)U = \begin{pmatrix} \tfrac{1}{2} & \tfrac{1}{2} & \tfrac{1}{2} & \tfrac{1}{2} \\ \tfrac{1}{2} & -\tfrac{1}{2} & \tfrac{1}{2} & -\tfrac{1}{2} \\ \tfrac{1}{2} & \tfrac{1}{2} & -\tfrac{1}{2} & -\tfrac{1}{2} \\ \tfrac{1}{2} & -\tfrac{1}{2} & -\tfrac{1}{2} & \tfrac{1}{2} \end{pmatrix}

Circuit · 2 qubits

Quantum circuit on 2 qubitsX on q1; H on q0; H on q1q0q1XHH

Preparing ∣01⟩\lvert01\rangle with XX on qubit 1 and then applying H⊗HH\otimes H gives 12(∣00⟩−∣01⟩+∣10⟩−∣11⟩)\tfrac12(\lvert00\rangle-\lvert01\rangle+\lvert10\rangle-\lvert11\rangle): the signs follow (−1)x⋅y(-1)^{x\cdot y} with x=01x=01.

∣ψ⟩=12∣00⟩−12∣01⟩+12∣10⟩−12∣11⟩\lvert\psi\rangle = \tfrac{1}{2}\lvert 00\rangle - \tfrac{1}{2}\lvert 01\rangle + \tfrac{1}{2}\lvert 10\rangle - \tfrac{1}{2}\lvert 11\rangle
  • |00⟩0.25
  • |01⟩0.25
  • |10⟩0.25
  • |11⟩0.25

Quick check

What is the amplitude of ∣11⟩\lvert11\rangle in H⊗2∣01⟩H^{\otimes2}\lvert01\rangle? Give a decimal.

tolerance ±0.001

Numerical verification and lab#

The script below rebuilds every identity of this lesson from the simulator's gate matrices and checks it entry by entry to 10−1210^{-12}. It also evaluates the overlap ∣Tr(X†HSH)∣2/4=12\lvert\mathrm{Tr}(X^\dagger HSH)\rvert^2/4=\tfrac12 that appears as a diagnostic in the lab: one SS in the sandwich is not enough.

TypeScriptrunnable
import { HADAMARD, PAULI_X, PAULI_Y, PAULI_Z, S_GATE, SDG_GATE, T_GATE, cexpi, matrix, ryMatrix, rzMatrix } from '@/lib/quantum-simulator';

const tol = 1e-12;
const H = HADAMARD;

// Hadamard conjugation identities
console.log('HXH = Z  :', matrix.approxEqual(matrix.mulAll(H, PAULI_X, H), PAULI_Z, tol));
console.log('HZH = X  :', matrix.approxEqual(matrix.mulAll(H, PAULI_Z, H), PAULI_X, tol));
console.log('HYH = -Y :', matrix.approxEqual(matrix.mulAll(H, PAULI_Y, H), matrix.scale(PAULI_Y, -1), tol));

// Phase gates
console.log('S^2 = Z  :', matrix.approxEqual(matrix.mul(S_GATE, S_GATE), PAULI_Z, tol));
console.log('T^2 = S  :', matrix.approxEqual(matrix.mul(T_GATE, T_GATE), S_GATE, tol));
console.log('T = e^{i pi/8} RZ(pi/4) :', matrix.approxEqual(matrix.scale(rzMatrix(Math.PI / 4), cexpi(Math.PI / 8)), T_GATE, tol));
console.log('S X S^dag = Y :', matrix.approxEqual(matrix.mulAll(S_GATE, PAULI_X, SDG_GATE), PAULI_Y, tol));

// Euler factorisation H = i RY(pi/2) RZ(pi)
const ryrz = matrix.mul(ryMatrix(Math.PI / 2), rzMatrix(Math.PI));
console.log('H = i RY(pi/2) RZ(pi) :', matrix.approxEqual(matrix.scale(ryrz, cexpi(Math.PI / 2)), H, tol));

// Lab diagnostic: one S is only half of the answer
const hsh = matrix.mulAll(H, S_GATE, H);
const tr = matrix.trace(matrix.mul(matrix.adjoint(PAULI_X), hsh));
console.log('Tr(X^dag HSH) =', tr.re.toFixed(4), tr.im.toFixed(4));
console.log('|Tr(X^dag HSH)|^2 / 4 =', ((tr.re * tr.re + tr.im * tr.im) / 4).toFixed(4));

Expected output

HXH = Z  : true
HZH = X  : true
HYH = -Y : true
S^2 = Z  : true
T^2 = S  : true
T = e^{i pi/8} RZ(pi/4) : true
S X S^dag = Y : true
H = i RY(pi/2) RZ(pi) : true
Tr(X^dag HSH) = 1.0000 -1.0000
|Tr(X^dag HSH)|^2 / 4 = 0.5000

References

  1. M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, 10th anniversary ed., Cambridge University Press (2010), §4.2 (single qubit operations).doi:10.1017/CBO9780511976667
  2. P. O. Boykin, T. Mor, M. Pulver, V. Roychowdhury and F. Vatan, A new universal and fault-tolerant quantum basis, Information Processing Letters 75, 101–107 (2000); arXiv:quant-ph/9906054 (1999).doi:10.1016/S0020-0190(00)00084-3

Hands-on labs

  • Build X from H and S

    1 step · auto-graded

    Implement the bit flip X=(0110)X=\begin{pmatrix}0&1\\1&0\end{pmatrix} on one qubit, up to a global phase, using only the Hadamard gate HH and the phase gate S=diag(1,i)S=\mathrm{diag}(1,i), with at most four gates.

    Open lab