• No results found

In developing the equational theory, we make three changes to the QNQ calculus described in Chapter 7.

Qubits asLower Bool. First, instead of takingQubitto be a primitive type of qubits, we instead defineQubit to be Lower Bool, since qubits are represented by a two-dimensional vector space. We can define initialization and measurement as follows:

init∶Bool→LExp∅ Qubit init≡λb.put b

meas∶Box Qubit(Lower Bool) meas≡boxx⇒let !b∶=x in put b

On first glance, these definitions appear to do nothing—meas in particular is just the η expansion of e. But the encoding of Qubit as Lower Bool highlights a critical semantic fact of our system: case analysis performs quantum measurement. This has a number of consequences for the theory of the language, including the fact thatηexpansion is not sound in general: a measured qubit isnot equivalent to an unmeasured one.

By choosing to encode measurement as case analysis, we open the door to a very ex- pressive quantum theory. For example, the type Lower(Bool×Bool) is equivalent to the two-qubit system Qubit⊗Qubit≡Lower Bool⊗Lower Bool. We can also easily encode a qutrit (a base-3 quantum system) as Lower(() + () + ()).

We write σ τ for an equivalence betweenσ and τ that arises from an isomorphism on basis sets. For example, swap ∶ σ ⊗τ τ ⊗σ arises from symmetry and distr ∶ σ⊗ (τ1⊕τ2) σ⊗τ1⊕σ⊗τ2 reflects the distributivity of ⊗ over ⊗. We formalize the

Strengthened η equivalence for LUnit. As discussed in Section 6.2, we do allow the usual η equivalences for the tensor product and linear unit type, as follows:

∆⊢QNQe∶LUnit ∆′, x∶LUnit⊢QNQe′∶τ

e′{e/x} ∼ηlet() ∶=eine′{()/x}

∆⊢QNQe∶σ1⊗σ2 ∆′, x∶σ1⊗σ2⊢QNQe′∶τ

e′{e/x} ∼η let(x1, x2) ∶=ein e′{(x1, x2)/x}

However, for units we actually expect a stronger η equivalence: LUnit is a terminal object in the category of density matrices. That is, every two terms of type LUnit are equivalent.

∆⊢QNQe1∶LUnit ∆⊢QNQe2∶LUnit

e1∼η e2

This is not a consequence of the usual linear η rule above, but is a consequence of the cartesianηequivalence, which states that every term of type unit is equal to the unit value.

Additive sums. Staton’s equational theory relies on the fact that unitaries can be com- bined via the direct sum, which corresponds to the additive sum in the type theory. There- fore we extend QNQ with additive sums, written σ1⊕σ2. Although sums do not arise

naturally in the context of quantum circuits, they do occur in several quantum program- ming languages.

∆⊢QNQei ∶σi

∆⊢QNQιiei∶σ1⊕σ2

∆⊢QNQe∶σ1⊕σ2 ∆′, x1∶σ1⊢QNQe1∶τ ∆′, x2∶σ2⊢QNQe2 ∶τ

∆,∆′⊢QNQcase eof(ι1x1→e1 ∣ι2x2 →e2) ∶τ

We allow β equivalences but not general η-equivalence for sums; like for the Lower type, case analysis for sums corresponds to measuring a quantum state. However, we do allow

the commuting conversion rule.

case ιieof(ι1x1→e1∣ι2x2→e2) ∼β ei{e/xi}

∆⊢QNQe∶σ1⊕σ2 ∆0, x1∶σ1⊢QNQe1∶σ ∆0, x2∶σ2⊢QNQe2∶σ ∆′, x∶σ⊢QNQe′∶τ

e′{(case eof(ι1x1→e1 ∣ι2x2 →e2))/x}∼cccase eof(ι1x1→e′{e1/x} ∣ι2x2→e′{e1/x})

7.2.1 Unitary transformations.

Following Staton (2015), we focus on two main ways to combine unitaries: if U ∶ U(q, r) and V ∶ U(q′, r′), then U ⊗V ∶ U(q⊗q′, r⊗r′) is the tensor product of U by V, and U⊕V ∶ U(q⊕q′, r⊕r′) is the direct sum.

Staton proves that all unitary matrices can be constructed from 1-qubit unitaries with the direct sum and tensor product. In our formulation, where unitaries are indexed by linear types, we must also account for equivalences between these types, such as associativity and distributivity. For example, the controlled-not unitary CNOT ∶ U(Qubit⊗Qubit,Qubit⊗ Qubit), is exactly equal to I⊕X∶ U(Qubit⊕Qubit,Qubit⊕Qubit) when we account for the equivalence between Qubit⊗Qubitand Qubit⊕Qubit.

The equational theory of unitaries is divided into three classes. First, the “structural” axioms, shown in Figure 7.1, characterize the how unitaries interact with syntactic forms of the language. For example, Equation (U-⊗-intro) describes how the tensor product U1⊗U2 distributes over pairs of expressions.

Second, the “groupoid” axioms in Figure 7.2 characterize that unitaries form a groupoid. The third set of axioms describe how unitary equivalences—isomorphisms between the basis sets of linear types—interact with initialization and measurement. Every equivalence f ∶σ τ can be lifted to a unitaryf̃∶ U(σ, τ). For example, for the equivalenceswap, it should be the case that swap̃#(e1, e2) ≈ (e2, e1). We call (e1, e2) the partial initialization

of the quantum system σ1⊗σ2, reflected in the fact thatswap quantifies over all types σ1

(U1⊗U2)#(e1, e2) ≈ (U1#e1, U2 #e2) (U-⊗-intro)

let (x1, x2) ∶= (U1⊗U2)#e ine′

≈let(y1, y2) ∶=eine′{U1#y1/x1, U2#y2/x2} (U-⊗-elim)

U #(let(x1, x2) ∶=ein e′) ≈let (x1, x2) ∶=einU #e′ (U-⊗-comm) (U0⊕U1)#(ι0e) ≈U0#e (U-⊕-intro0) (U0⊕U1)#(ι1e) ≈U1#e (U-⊕-intro1) case (U0⊕U1)#eof (ι0x0→e0∣ι1x1→e1) ≈case eof(ι0y0 →e0{U0#y0/x0} ∣ι1y1→e1{U1#y1/x1}) (U-⊕-elim) U #(case eof(ι0x0→e0∣ι1x1→e1)) ≈case eof (ι0x0 →U #e0∣ι1x1→U #e1) (U-⊕-comm) U #(e>!f) ≈e>!λx→U #(f x) (U-Lower-comm) U #e>!λ .e′≈e>!λ .e′ (U-Lower-elim) Figure 7.1: Structural axioms

U #(V #e) ≈ (U ○V)#e (U-compose)

I #e≈e (U-I)

U†#U #e≈e (U-†)

X#putb≈put ¬b (X-intro) let!x∶=meas X#e ine′≈let !y∶=meas ein e′{¬y/x} (X-elim) SWAP#(e1, e2) ≈ (e2, e1) (SWAP-intro) let(x, y) ∶=SWAP#e ine′≈let (y, x) ∶=eine′ (SWAP-elim) DISTR#(e, ιie′) ≈ιi(e, e′) (DISTR-intro) case(DISTR#e)of (ι0z0→e0∣ι1z1→e1) ≈case eof⎧⎪⎪⎨⎪⎪

(x, ι0y0) →e0{(x, y0)/z0} (x, ι1y1) →e1{(x, y1)/z1}

(DISTR-elim)

Figure 7.3: Unitary equivalence axioms forX∶ U(Qubit,Qubit),SWAP∶ U(σ⊗τ, τ⊗σ), and DISTR∶ U(σ⊗ (τ1⊕τ2),(σ⊗τ1) ⊕ (σ⊗τ2)).

The idea of partial initialization and its counterpart, partial measurement, provide a concise encapsulation of the behavior of unitary equivalences. Given an equivalence f ∶ σ τ, we have

̃

f #initσ b≈initτ(f b) (U-intro)

matchτ ( ̃f #e) with g≈matchσ ewith g○f (U-elim)