In this section we describe how to map quantum programs to superoperators over density matrices.
We identify every type σ with a dimensionJσK.
JLUnitK≡0 JQubitK≡1
Jσ1⊗σ2K≡Jσ1K+Jσ2K
JLower αK≡ ∣α∣
Because we restricted the constructor forLowerαto finite types, the size∣α∣is well-defined. For each typeα, we also pick a canonical ordering on its elements, so that valuesa∶α can be mapped to distinct vectorsδa of dimension 2∣α∣.
Each typing context is also associated with a dimension.
J∅K≡0 J∆, x∶σK≡J∆K+JσK
We write Density σ for the type of 2JσK ×2JσK density matrices and similarly for
Density ∆. Our goal is to map expressions ∆ ⊢QNQ e ∶ σ to functions Density ∆ →
Density σ.
The category of density matrices is symmetric monoidal, which tells us how to interpret the multiplicative unit and product.
Every unitary U ∶ U(σ, τ) will be associated with a unitary matrix JUK of dimension 2JσK×2JτK. We can lift this to a superoperator
JUK∗∶Density σ→Density τ; recall that U∗(ρ) =U†ρU.
JU #eK≡JUK
∗○
JeK
For qubits, initialization and measurement are defined as follows:
Jinit bK≡ ⟨b∣
∗
The semantics of Lower is a generalization of the semantics of qubits. Notice that the typesQubit andLower Bool have the same representation as density matrices.
Jput aK≡ (δ † a)∗ Je>!fK≡ ∑ a∶αJ f aK○ (δaδ†a)∗○JeK
Finally, the interpretation of a quantum functionf ∶Boxσ τis a superoperatorDensityσ→ Density τ, and applyingf to an argument composes their denotations together.
Jbox x⇒eK≡JeK Jf $eK≡JfK○JeK
6.4.1 Soundness
Theorem 6.4.1 (Soundness ofβ-reduction). If ∆⊢QNQe∶τ ande↝βe′, then Je′K=JeK.
Proof. The only interesting cases are those for qubits and theLower type. For qubits, we have meas(init b) ↝β putb. Unfolding definitions, we have
Jmeas(init b)K≡ ((∣0⟩ ⟨0∣)
∗+ (∣1⟩ ⟨1∣)∗) ○ ⟨b∣∗. (6.1)
Because M∗○N∗ is exactly(N M)∗, Equation (6.1) is equal to (⟨b∣ ∣0⟩ ⟨0∣)∗+ (⟨b∣ ∣1⟩ ⟨1∣)∗.
Notice that ∣b⟩ ⟨b′∣ is equal to the constant 1 if b=b′, or 0 if b≠ b′. Thus Equation (6.1) reduces to⟨b∣∗.
For Lower, we have puta>!f ↝β f a. Then: Jput a>!fK= ∑ b∶α Jf bK○ (δbδ † b)∗JputaK = ∑ b∶α Jf bK○ (δbδ † b)∗(δ†a)∗ = ∑ b∶α Jf bK○ (δ † aδbδ†b)∗
As for qubits, it is the case that δ†aδb is 1 if a = b, and 0 otherwise. Therefore, the sum reduces to the single clauseJf aK.
CHAPTER 7
Quantum equational theories in HoTT
The β- and η-equivalences of the QNQ calculus described in the previous section cover only a few of the equivalences we expect to hold from a quantum system. The operational semantics of unitary transformations cannot be expressed as equivalences—there is no sim- pler representation of the expression H #init 0, for example. Even so, there are several properties of unitary transformations that can be expressed equationally. Consider, for example the X unitary transformation, which maps ∣0⟩ to ∣1⟩ and ∣1⟩ to ∣0⟩. We expect X#initbto be equivalent toinit(¬b), and we also expectmeas(X#e)to be equivalent tomeas e>!λb.put(¬b).
Staton (2015) describes an equational theory for a small quantum programming lan- guage, given as an algebraic theory with quantum data and classical control. Staton’s algebraic theory includes measurement-based branching, but it does not contain explicit classical data or features we would expect from a QRAM-style language, let alone access to an entire classical host language. In this chapter we adapt Staton’s equational theory to the QNQ calculus, continuing to reason about the meta-theory of an embedded language inside its host language.
Other works propose axiomatizations of particular sets of unitary transformations (Amy et al., 2018; Matsumoto and Amano, 2008; Namet al., 2018), but, like Staton, we focus on the relationships between quantum and classical features.
What features should our host language have in order to perform this meta-theory? To reason about program equivalences, we choose to work in a host language that specializes in equality—homotopy type theory (HoTT). In HoTT, proofs of equality, also calledpaths,
can contain extra computational content. In the past few years a variety of applications have used these paths as a data structure for groupoids, such as containers (Abbott et al., 2004), version control patches (Angiuli et al., 2014), and SQL queries (Chu et al., 2017).
The key contribution of this chapter is the observation thatunitary transformations form a groupoid. We exploit this structure to encode unitaries in the paths between quantum types. With this structure, we can derive many of the structural rules from Staton’s theory. We group the remaining axioms into two families of axioms describing the behavior of unitaries with respect to initialization and measurement, respectively.
The rest of this chapter is devoted to establishing the equational theory of QNQ in homotopy type theory. Section 7.1 gives some background of HoTT. Section 7.2 describes a slight variation of QNQ with additive sums and gives an overview of the equational principles we expect to hold. Section 7.3 shows how to derive many of the structural rules by encoding unitary transformations as higher inductive types. Section 7.4 establishes the remaining two axioms that cannot be derived from the HoTT meta-theory. Section 7.5 proves that these additional axioms are sound with respect to the denotational semantics of Section 6.4. Finally, Section 7.6 discusses some of the design decisions that went into this theory.