343 Qubits and Circuits in Homotopy Type Theory

Thesis. In homotopy type theory the identity is a type. For terms \(a,b:A\) there is a type \(a=_Ab\) of identifications, and \(\mathsf {refl}_a:a=a\) is its canonical element. The constructions of Section 342 can be read in this language.

Bits and gates.

Geometry. The phase is the circle \(S^1\), whose loops form \(\mathbb Z\). The Bloch sphere is the base of the Hopf fibration \(S^1\to S^3\to S^2\), constructed in the type theory itself. The ground space of the toric code is read off from the torus.

Two limits.

343.1 Identity as a type

Formation and introduction. For \(A\) a type and \(a,b:A\) there is a type \(a=_Ab\), and

\begin{equation} \mathsf {refl}_a:\ a=_Aa . \tag{21295}\end{equation}
The identity \(A=A\) of the present work is this introduction rule.

Path induction. To prove \(C(x,y,p)\) for all \(x,y:A\) and \(p:x=y\), it suffices to prove \(C(x,x,\mathsf {refl}_x)\) for all \(x\). From this single rule follow:

Each type is an \(\infty \)-groupoid generated by \(\mathsf {refl}\), the type-theoretic form of Section 358.2.

Truncation levels. A type is a proposition if any two elements are equal, and a set if each \(x=y\) is a proposition. \(\mathbf 2\), \(\mathbb N\), \(\mathbb Z\), \(\mathbb R\) and \(\mathbb C\) are sets.

Declarations. The inductive type \(\mathbb N\), with \(0\) and \(\mathsf {succ}\), is a formation rule. As in Section 458, it is where the completed infinite is declared; the reals, and hence \(\mathbb C\), depend on it.

343.2 Bits and univalence

Univalence. For types \(A,B\) in a universe \(\mathcal U\),

\begin{equation} \mathsf {idtoeqv}:\ (A=_{\mathcal U}B)\xrightarrow {\ \simeq \ }(A\simeq B). \tag{21296}\end{equation}

The bit. For \(\mathbf 2\),

\begin{equation} (\mathbf 2=_{\mathcal U}\mathbf 2)\ \simeq \ (\mathbf 2\simeq \mathbf 2)\ \simeq \ \mathbf 2, \tag{21297}\end{equation}
with elements \(\mathsf {refl}\) and the path \(\mathsf {ua}(\neg )\), where \(\mathsf {ua}(\neg )\cdot \mathsf {ua}(\neg )=\mathsf {refl}\). Negation, the involution of the floor, is the nontrivial loop at \(\mathbf 2\) in the universe.

Two-element types. The type of two-element types,

\begin{equation} \mathrm {BAut}(\mathbf 2)=\sum _{X:\mathcal U}\|X\simeq \mathbf 2\|, \tag{21298}\end{equation}
is a connected \(1\)-type with
\begin{equation} \Omega \,\mathrm {BAut}(\mathbf 2)\simeq \mathbb Z/2 , \tag{21299}\end{equation}
the classifying type \(K(\mathbb Z/2,1)\).

343.3 The circle, the integers and phases

The circle. \(S^1\) is the higher inductive type with a point \(\mathsf {base}\) and a path \(\mathsf {loop}:\mathsf {base}=\mathsf {base}\).

Its loops. The encode–decode method gives

\begin{equation} (\mathsf {base}=_{S^1}\mathsf {base})\simeq \mathbb Z, \qquad \mathsf {loop}^n\mapsto n . \tag{21300}\end{equation}
The universal cover is the family \(S^1\to \mathcal U\) sending \(\mathsf {base}\) to \(\mathbb Z\) and \(\mathsf {loop}\) to \(\mathsf {ua}(\mathsf {succ})\). Integer winding numbers are loops of the circle (Section 333).

Phases and spin. A global phase \(e^{i\theta }\) is a point of \(S^1\), and phase windings are the integers above. A rotation \(R_Z(2\pi )=-1\) in \(SU(2)\) returns to the identity only after \(4\pi \): the loop of \(2\pi \) rotations generates \(\pi _1(SO(3))=\mathbb Z/2\), and \(SU(2)\to SO(3)\) is the double cover that unwinds it.

343.4 The Hopf fibration and the Bloch sphere

Suspension. \(S^2=\Sigma S^1\) has two poles \(N,S\) and a meridian \(\mathsf {merid}(x):N=S\) for each \(x:S^1\).

Construction. A family of types over \(S^2\) is given by its fibres over the two poles and an equivalence between them along each meridian:

Total space. The total space is the join \(S^1*S^1\simeq S^3\):

\begin{equation} S^1\ \hookrightarrow \ S^3\ \xrightarrow {\ \eta \ }\ S^2 . \tag{21301}\end{equation}

Consequences.

\begin{equation} \pi _2(S^2)=\mathbb Z, \qquad \pi _3(S^2)=\mathbb Z\ \text {generated by }\eta . \tag{21302}\end{equation}
The first classifies line bundles over the Bloch sphere: the Chern number \(1\) of the qubit’s Berry bundle is the generator. The second is the Hopf invariant (Section 362).

Relation to \(\mathbb CP^1\). The point-set space \(\mathbb CP^1\) of rank-one projectors, defined from \(\mathbb C\), is a set in book HoTT, carrying no homotopy of its own. In real-cohesive type theory the shape modality \(\int \) recovers its homotopy type:

\begin{equation} \int \mathbb CP^1\simeq S^2, \qquad \int (\mathbb R/\mathbb Z)\simeq S^1 . \tag{21303}\end{equation}

343.5 \(\mathbb C^2\), projectors and qubits

Projectors as a \(\Sigma \)-type. With \(\mathrm M_2(\mathbb C)\) a set, the rank-one projectors form the type

\begin{equation} \mathrm {Proj}_1=\sum _{P:\mathrm M_2(\mathbb C)}(P\cdot P=P)\times (P^\dagger =P)\times (\operatorname {tr}P=1). \tag{21304}\end{equation}
Idempotence is an element of an identity type, and because matrices form a set each condition is a proposition. A projector is a matrix together with a proof that it equals its own square.

The type of qubits.

\begin{equation} \mathrm {Qubit}=\sum _{V:\mathrm {Hilb}}\|V\simeq \mathbb C^2\|, \tag{21305}\end{equation}
two-dimensional Hilbert spaces, with \(\mathrm {Hilb}\) the type of complex inner-product spaces and \(\simeq \) meaning unitary equivalence.

Gates as loops. By the structure identity principle, univalence for structured types,

\begin{equation} \Omega (\mathrm {Qubit},\mathbb C^2) =(\mathbb C^2=\mathbb C^2) \simeq U(2). \tag{21306}\end{equation}

Circuits. A gate is a loop, and a circuit is a concatenation of loops:

\begin{equation} U_3U_2U_1=p_1\cdot p_2\cdot p_3, \qquad U^\dagger =p^{-1}, \qquad \mathrm {id}=\mathsf {refl}. \tag{21307}\end{equation}
A circuit identity such as \(\mathrm {CNOT}=(1\otimes H)\,\mathrm {CZ}\,(1\otimes H)\), or \(H^2=1\), is a path between paths. Since \(U(2)\) is a set here, any two proofs of such an identity are equal.

Global phase. States as projectors forget the global phase. The corresponding loop space is \(PU(2)=U(2)/U(1)\), acting on \(\mathrm {Proj}_1\).

Paulis. \(X\) is a loop with \(X\cdot X=\mathsf {refl}\). Restricted to the basis, \(\mathbf 2\to \mathbb C^2\), it is \(\mathsf {ua}(\neg )\), so the bit’s involution is the image of \(X\) on basis vectors:

\begin{equation} \Omega (\mathbf 2)\simeq \mathbb Z/2\ \hookrightarrow \ \Omega (\mathbb C^2)\simeq U(2). \tag{21308}\end{equation}

343.6 Controlled gates as elimination on \(\mathbf 2\)

Recursion on a bit. For \(U:\mathbb C^2\simeq \mathbb C^2\), recursion on \(\mathbf 2\) gives

\begin{equation} c_U:\ \mathbf 2\to (\mathbb C^2\simeq \mathbb C^2), \qquad c_U(0)=\mathrm {id}, \qquad c_U(1)=U . \tag{21309}\end{equation}

Linear extension. Extending linearly over the basis of the control qubit gives

\begin{equation} \mathrm C U=\sum _{b:\mathbf 2}\Pi _b\otimes c_U(b)=\Pi _0\otimes 1+\Pi _1\otimes U , \tag{21310}\end{equation}
with \(\mathrm {CNOT}=\mathrm CX\) and \(\mathrm {CZ}=\mathrm CZ\). Classical "if-then-else" is elimination on \(\mathbf 2\); the quantum controlled gate is its linear extension, the sum over the cut \(\Pi _0+\Pi _1=1\). Multi-controlled gates are elimination on \(\mathbf 2^k\).

343.7 The diagonal and no-cloning

The cartesian diagonal. Every type has

\begin{equation} \Delta _A:\ A\to A\times A, \qquad x\mapsto (x,x), \tag{21311}\end{equation}
so in HoTT any description of a state can be copied: \(\mathbb C^2\) and \(\mathrm {Proj}_1\) are sets of classical data.

No linear diagonal. No-cloning concerns the tensor product: there is no linear map \(\mathbb C^2\to \mathbb C^2\otimes \mathbb C^2\) with \(\psi \mapsto \psi \otimes \psi \) for all \(\psi \). Linearity gives \((\psi +\phi )\otimes (\psi +\phi )\neq \psi \otimes \psi +\phi \otimes \phi \). The diagonal exists for the copying of descriptions, the cartesian product, and fails for the copying of states, the tensor product.

Linear extensions. To make no-cloning a typing rule, the context must be monoidal rather than cartesian, as in linear and dependent linear type theories and quantum programming languages built on them. There the diagonal is available only on the classical part of a type.

343.8 The toric code from the torus

The torus. The torus \(T^2\) is the higher inductive type with a point, two loops \(a,b\), and a \(2\)-path \(a\cdot b=b\cdot a\). Its fundamental group is

\begin{equation} \pi _1(T^2)=\mathbb Z^2 . \tag{21312}\end{equation}

Cohomology. With \(\mathbb Z/2\) coefficients, as maps into \(K(\mathbb Z/2,1)\simeq \mathrm {BAut}(\mathbf 2)\),

\begin{equation} H^1(T^2;\mathbb Z/2)=\|T^2\to \mathrm {BAut}(\mathbf 2)\|_0\cong (\mathbb Z/2)^2 . \tag{21313}\end{equation}

Logical operators. On a lattice embedded in a torus, the toric code’s stabilizers are vertex and plaquette products, and its logical operators are \(X\) and \(Z\) strings along non-contractible cycles. These are classified by \(H_1(T^2;\mathbb Z/2)\) and its dual.

Ground space. The ground space has dimension

\begin{equation} \bigl |H^1(T^2;\mathbb Z/2)\bigr |=4, \tag{21314}\end{equation}
two logical qubits. On a surface of genus \(g\) it is \(2^{2g}\). The logical qubits are read off from the type \(T^2\) and the classifying type of the bit.

343.9 Summary

Statement HoTT form From
\(A=A\) \(\mathsf {refl}_a:a=a\) identity type
substitution transport along \(p:x=y\) path induction
bit symmetries \((\mathbf 2=\mathbf 2)\simeq \mathbf 2\) univalence
two-element types \(\mathrm {BAut}(\mathbf 2)=K(\mathbb Z/2,1)\) loops \(\mathbb Z/2\)
phase windings \((\mathsf {base}=\mathsf {base})\simeq \mathbb Z\) encode–decode
spin \(\pi _1(SO(3))=\mathbb Z/2\) double cover
Bloch sphere \(S^1\to S^3\to S^2\) Hopf construction
Chern number \(\pi _2(S^2)=\mathbb Z\) Freudenthal
\(\mathbb CP^1\) vs. \(S^2\) \(\int \mathbb CP^1\simeq S^2\) real cohesion
projectors \(\sum _P(P\cdot P=P)\times \cdots \) identity types
gates \(\Omega (\mathrm {Qubit})\simeq U(2)\) structure identity
circuits concatenation, inversion path algebra
circuit identities paths between paths higher identity
\(X\) on basis \(\mathsf {ua}(\neg )\) bit involution
controlled gates \(\sum _b\Pi _b\otimes c_U(b)\) elimination on \(\mathbf 2\)
copying descriptions \(\Delta _A\) cartesian
no-cloning no linear \(\psi \mapsto \psi \otimes \psi \) tensor product
toric code \(|H^1(T^2;\mathbb Z/2)|=4\) torus HIT