A Quantum Interpretation of Bunched Logic for Quantum Separation Logic
Li Zhou Gilles Barthe Max Planck Institute for Security and Privacy Max Planck Institute for Security and Privacy; IMDEA Software Institute
Justin Hsu Mingsheng Ying University of Wisconsin–Madison University of Technology Sydney; Institute of Software, Chinese Academy of Sciences; Tsinghua University
Nengkun Yu University of Technology Sydney
Abstract—We propose a model of the substructural logic of Quantum computation is another domain where the ideas Bunched Implications (BI) that is suitable for reasoning about of separation logic seem relevant. Recent work [10], [11] quantum states. In our model, the separating conjunction of suggests that reasoning about resources (in particular, entan- BI describes separable quantum states. We develop a program glement – a resource unique in the quantum world) can bring logic where pre- and post-conditions are BI formulas describing similar benefits to quantum computing and communications. quantum states—the program logic can be seen as a counter- Motivated by this broad perspective, we propose a quan- part of separation logic for imperative quantum programs. We tum model of BI and develop a novel separation logic for exercise the logic for proving the security of quantum one-time quantum programs. Our development is guided by concrete pad and secret sharing, and we show how the program logic examples of quantum algorithms and security protocols. can be used to discover a flaw in Google Cirq’s tutorial on the Motivating Local Reasoning for Quantum Programs: Variational Quantum Algorithm (VQA). Quantum Machine Learning [12], [13] and VQAs (Vari- ational Quantum Algorithms) [14], [15] are new classes 1. Introduction of quantum algorithms that emerged in recent years as a leading application of quantum computing. These algo- The logic of Bunched Implications (BI) of O’Hearn rithms solve problems by training parameterized quantum and Pym [1], [2], [3] is a substructural logic that fea- circuits. The trained circuits are usually very large in terms tures resource-aware connectives. One such connective is ∗, of both their size and the required quantum resources, known as separating conjunction: informally, an assertion i.e., the number of involved quantum bits (qubits). This φ ∗ ψ holds with respect to a resource R if the resource makes them particularly challenging to verify with exist- R can be split into resources R0 and R00 such that φ ing techniques such as quantum Hoare logic [16], [17] holds with respect to R0 and ψ holds with respect to R00. and verification based on operational semantics [18], since This interpretation is particularly well suited for reasoning the dimension of the matrices used to represent assertions about programs in settings where computations can have increases exponentially w.r.t. the number of qubits. Fortu- arXiv:2102.00329v1 [cs.LO] 30 Jan 2021 interfering effects. In particular, BI has found success as an nately, these algorithms can benefit from local reasoning, assertion language for Separation Logic [4], [5], [6], a pro- since each of their operations is performed locally on a gram logic for reasoning about programs with mutable state, small number of qubits. Consider for instance the quantum and Concurrent Separation Logic [7], [8], a program logic circuit shown in Figure 1, that implements a VQA circuit for reasoning about shared-memory concurrent processes. with 2 × 2 grid qubits. Instead of reasoning about the Recent works seek to extend the separation logic frame- circuit as a whole, we would like to reason about sub- work beyond memory-manipulating programs by consider- circuits ProcC(1), ProcC(2), Proc(R)(1), ProcR(2) sepa- ing other notions of resources and other models of com- rately, and then combine the results to establish the correct- putation. Broadly speaking, separation logics are a good fit ness of the whole program. This is precisely the kind of whenever programs manipulate resources in a local fashion: reasoning enabled by Quantum Separation Logic (QSL for that is, there is a natural notion of two resources being short). separate, and a program can operate on the first resource without affecting the second. This idea underlies recent sep- Technical Challenges and Contributions: QSL will be aration logics for probabilistic programs, where separation developed by first developing a model of BI, where formulas is probabilistic independence [9]. describe quantum states and then building a separation logic
1 Reynolds [19] in the context of standard separation logic. This extra bit of freedom seems to be particular to the quantum setting, and we crucially use this feature when using the frame rule to establish uniformity. The soundness proof of our quantum frame rule requires a nontrivial calculation based on purification, a fun- damental technique used in quantum information for transforming mixed states to pure states by introducing reference systems [20]. Figure 1: VQA(2) with parameters taken in Sec. 5.3. 3) Reasoning about entangled predicates:1 The structural rules FRAME and CONST enable us to lift local rea- soning to global correctness of quantum algorithms using these assertions as pre- and post-conditions, introduc- only when no entanglement occur in the pre- and ing proof rules to reason about quantum programs. post-conditions. However, entangled predicates play an BI and Its Quantum Interpretation: To characterize the essential role in revealing the non-local (global) proper- properties of quantum systems, we first identify a quantum ties of a composite quantum system; for instance, some interpretation of BI appropriate for our target applications. entangled predicates are used when reasoning about the We choose to interpret our separating conjunction ∗ as (in)correctness of VQA (see Sec. 5.3). With the help separability of quantum states. Roughly speaking, φ1 ∗ φ2 of auxiliary variables, we set up a new rule UNCR holds in a quantum state ρ if ρ can be factored into two which enables us to prove the correctness of large quantum states ρ1 and ρ2 over disjoint registers satisfying quantum algorithms with respect to entangled pre- and φ1 and φ2, respectively. post-conditions. Intuitively, when the program (as the Proof System for Program Logic: next, we define principal system) combined with auxiliary variables (as a program logic for a quantum while-language [16] (for ancillary systems), modification can be used to create simplicity, we do not consider classical variables). Our (mathematically rather than physically) entanglement language follows the “classical control and quantum data” and rule UNCR is used to preserve correctness under paradigm. We develop a set of proof rules that are effective the modification on the auxiliary variables in the pre- for verifying quantum programs over a large set of qubits. and post-conditions (but not in the program). The key Our proof system has several novel ingredients: idea behind was first proposed in [21] for reasoning 1) Modification on BI formulas. The basic rule for assign- about parallel quantum programs; UNCR is its gener- ments in classical program logics is defined using the alization tailored for our purpose. syntactic notion of substitution. Due to the non-cloning Applications: To demonstrate the breadth of the applica- law of quantum information, the role of assignments tion range of our logic QSL, we present several case studies has to be played by initialization q := |0i and unitary from two very different areas: transformations q := U[q], and inference rules for these operations involve a quantum operation (e.g., • Our first example given in Section 5 is formal verifi- [16], [17]). Unfortunately, the rules for initialization cation of Variational Quantum Algorithm (VQA) [14], and unitary transformations are not simple adaptations [15] for finding the ground state of a quantum system, of the rule for assignment, because a quantum gen- which has potential applications in quantum chemistry eralization of substitution is not straightforward. For for designing new materials and drugs. A typical VQA atomic predicates, substitutions are not always defined. can be split into different subprograms that are suited For composite formulas, a straightforward definition of to locally reasoning. Then the frame rules together substitution is too weak for applications. We overcome with UNCR are used to derive global correctness with this hurdle by introducing a modification operation for entangled pre- and post-conditions. In particular, an atomic formulas (see Definition 3.4), which is essen- analysis based on QSL reveals that the VQA presented tially a quantum version of substitution. Extending this in the tutorial of Google’s Cirq [22] is incorrect. operation to composite formulas requires some care • In Section 6, we use QSL to verify the security of (see Definition 3.5). quantum one-time pad (QOTP) [23], [24] and quantum 2) Frame rule: The frame rule is one of the most char- secret sharing (QSS) [25], [26]. Unlike previous work, acteristic structural rules in separation logic. QSL also the QSL verification of QOTP and QSS is scalable: in- enjoys a frame rule FRAME that is similar in spirit creasing the number of registers that algorithms employ to frame rules from standard separation logics, but does not complicate the verification. In particular, rule our new interpretation of separating conjunction means FRAME with the supported assertion (SP) enables us to that the meaning of the rule is different. Furthermore, avoid the very complicated mathematical calculations the frame rule can be generalized slightly: even if used in earlier verifications of QOTP [27]. the standard side condition for frame rules does not hold, the frame rule still applies if the post-condition 1. Here, entangled predicates refer to the projections that cannot be is a supported assertion—a concept first proposed by factored as a product of projections of its local constituents.
2 2. Preliminaries subsystem p is in state |0i and subsystem q is in state |1i. Due to the superposition principle, there exist states like For the convenience of the reader, we briefly review 1 |Φipq = √ (|0ip|0iq + |1ip|1iq) basic notions of quantum information and programming as 2 well as the logic of bunched implication. that cannot be written in the simple tensor form |φip|ψiq, which are called entangled states. These states play a crucial 2.1. Basics of Quantum Information role in applications of quantum computation and quantum communication. The state space of a quantum system is a Hilbert The state of a composite system fully determines the space H, which is essentially a vector space in the finite- state of each subsystem. Formally, given composite system dimensional case. A pure state of the system is a unit column pq in state ρ, subsystem q is then in state trp(ρ), where the vector |ψi ∈ H. For example, the state space of a quantum partial trace trp(·) over p is a mapping from operators on bit (aka qubit) is a two-dimensional Hilbert space with basis Hp ⊗ Hq to operators on Hq defined by: 1 0 states |0i = and |1i = , and any pure state of 0 1 trp(|φpiphψp| ⊗ |φqiqhψq|) = hψp|φpi · · · |φqiqhψq| α a qubit can be described in the form α|0i + β|1i = for all |φpi, |ψpi ∈ Hp and |φqi, |ψqi ∈ Hq together with β linearity. The state trq(ρ) of subsystem q can be defined satisfying normalization condition |α|2 + |β|2 = 1. When symmetrically. We often use the notations ρ|p , trp(ρ) and the state is not completely known but could be in one of ρ|q , trq(ρ) in order to explicitly indicate that ρ|p and ρ|q some pure states |ψii with respective probabilities pi, we are states of p, q, respectively. call {(pi, |ψii)} an ensemble of pure states or a mixed state, and the system is fully described by the density operator Summary of Notations. Let V be the set of all quantum P variables. A quantum register is a list of distinct variables ρ = i pi|ψiihψi|. For example, the completely mixed state of a qubit can be seen as ensemble {(0.5, |0i), (0.5, |1i)} q = q1, . . . , qn. Each quantum variable q has a type Hq, (i.e. the state is either |0i or |1i with the same probability which is the state Hilbert space of quantum system denoted 0.5 0 by q. For a set of quantum variables S = {q1, . . . , qn} ⊆ V 0.5) or density matrix 1 (|0ih0| + |1ih1|) = . 2 0 0.5 (or a quantum register q = q1, . . . , qn), we fix following The evolution of a quantum system is modelled by a notations: † † n • N unitary operator U; i.e. a complex matrix with UU = U U HS = i=1 Hqi : the Hilbert space of S. being the identity operator, where † is conjugate transpose. • dim(S): the dimension of HS. In quantum computing, operators are often called quantum • D(S): the set of all (mixed) quantum states (i.e. density 1 1 matrices) of S. In particular, for any ρ ∈ D(S), gates. For example, the Hadamard gate H = √1 2 1 −1 its domain is defined as dom(ρ) , S; we write maps |0i, |1i to their superpositions |±i = √1 (|0i ± |1i). D S D(S) for the set of all states. 2 , S⊆V Unlike a classical system which can be observed directly • P(S): the set of projections on HS. In particular, for without changing its state, we need to perform a quan- any P ∈ P(S), its domain is defined as free (P ) , tum measurement to extract information from a quantum S. Since there is a one-to-one correspondence between state which inevitably leads to state collapse. Formally, a projections and closed subspaces, we sometimes called projective quantum measurement consists of a set of pro- closed subspaces of HS projections. We write P , 2 S jections, i.e., self-adjoint and idempotent linear operators, S⊆V P(S) for the set of all projections. M ,M ,...,M . When such a measurement is applied to 0 1 n • ρ|S , trdom(ρ)\S(ρ): the restriction of state ρ on S, a quantum state ρ, we obtain one of the classical outcome defined as a reduced density operator over S ∩dom(ρ). i ∈ {0, 1, . . . , n} with probability pi = tr(Miρ), and the post-measurement state of the system is then MiρMi . pi 2.2. Quantum Programs: Syntax and Semantics We use variables p, q, r, ... to denote quantum systems. Operations in quantum computing are often performed on a For simplicity of presentation, we consider a purely composite system consisting of multiple qubits. To indicate quantum extension of while-language, namely the quantum which system a state describes or an operation acts on, we while-language [16]—that is, we do not allow classical use subscripts; for example, Hp is the state space of system variables. p, |0ip is the pure state |0i of the system p and |1iqh1| is the density matrix of the system q. The composite system Definition 2.1 (Syntax [16]). The quantum while-programs is described by the tensor product of its subsystems; for are defined by the grammar: example, a composite system pq has the state space Hp⊗Hq, C ::= skip | C1; C2 | q := |0i | q := U[q] and |0ip⊗|1iq (or, |0ip|1iq for short) is a pure state in which | if (m · M[q] = m → Cm) fi 2. That is, P : H → H is a projection over H iff P = P † = P 2. | while M[q] = 1 do C od
3 The program constructs defined above are explained as Proposition 2.1 (Proposition 3.3.5 in [29]). For any pro- follows. First, q := |0i initializes the quantum variable gram C and any set V ⊇ var(C) of variables, the semantic q in a basis state |0i, and q := U[q] applies a unitary function of domain V is a cylindric extension of the se- transformation U to a sequence q of quantum variables. The mantic function of domain var(C): C V = C var(C) ⊗ case statement if ··· fi performs the projective measurement IV\var(C), where IV\var(C) is the identityJ K quantumJ K opera- M = {Mm} on q, and then chooses a subprogram Cm to tion in HV\var(C). execute according to measurement outcome m. In the loop while ··· od, the projective measurement M = {M0,M1} 2.3. Brief review of BI-Logic in the guard has only two possible outcomes 0, 1: if the outcome is 0 the loop terminates, and if the outcome is Next, we briefly review the logic of Bunched Impli- 1 it executes the loop body C and enters the loop again. cations (BI) [1], [2]. BI is a sub-structural logic with the For simplicity of presentation, we will use the following following syntax: abbreviation: for i = 1, ··· ,N do Ci od , C1; ··· ; CN . For each program C, we write var(C) for the set of φ, ψ ::= p ∈ AP | > | ⊥ | φ∧ψ | φ∨ψ | φ → ψ | φ∗ψ| φ −∗ ψ all quantum variables in C. If V ⊇ var(C) is a set of where p ranges over a set AP of atomic propositions. quantum variables, and ρ ∈ D(V), then hC, ρi is called Besides standard propositional logic, BI contains a substruc- a configuration (of domain V). tural fragment – the separating conjunction ∗ and separating Definition 2.2 (Operational Semantics [16]). The oper- implication −∗ (“magic wand”). A distinction between ∗ and ational semantics of quantum programs is defined as a ∧ is that ∗ is not idempotent, i.e., P ∗P 6= P . For example, in transition relation → by the following transition rules: the standard heap model of separation logic, the separating conjunction P ∗ Q is true of a heap if it can be split into (Sk) hskip, ρi → hE, ρi (In) hq := |0i, ρi → hE, ρqi 0 two heaplets, one of which makes P true and the other of (UT) hq := U[q], ρi → hE, UρU †i which makes Q true. The implication −∗ is adjoint to ∗. For 0 0 hC1, ρi → hC1, ρ i example, P −∗ Q holds in some heap if adding a separate (SC) 0 0 heap satisfying P leads to a combined heap satisfying Q. hC1; C2, ρi → hC1; C2, ρ i † The most general semantics of BI is given in terms of (IF) hif (m · M[q] = m → Cm) fi, ρi → hCm,MmρMmi a kind of Kripke structures, called BI frames. Standard BI † (L0) hwhile M[q] = 1 do C od, ρi → hE,M0ρM0 i frame is based on a pre-ordered commutative monoid: (L1) hwhile M[q] = 1 do C od, ρi Definition 2.4 (BI frame [1]). A BI frame is a tuple X = † (X, ◦, , e), where X is a set equipped with a preorder , → hC; while M[q] = 1 do C od,M1ρM1 i and ◦ : X × X → X is a partial binary operation with an q P E is the empty program. In (In), ρ0 = n |0iqhn|ρ|niqh0|. unit element e and satisfying the following conditions: In (SC), we use the convention E; C2 = C2. In (IF), m 1) (Unit Existence) for all x, x = x ◦ e = e ◦ x; ranges over every possible outcome of measurement M = 2) (Commutativity) x ◦ y = y ◦ x; {Mm}. 3) (Associativity) x ◦ (y ◦ z) = (x ◦ y) ◦ z; Transitions in rules (IF), (L0) and (L1) are essentially 4) (Compatible with ) x x0 and y y0 and both x◦x0 probabilistic; but we adopt a convention from [28] to and y ◦ y0 are defined, then x ◦ x0 y ◦ y0. present them as non-probabilistic transitions. For example, Above, equalities state that either both sides are defined and for each m, the transition in (IF) happens with probability equal, or both sides are undefined. † pm = tr(MmMmρ) and the program state ρ is changed to ρ = M ρM † /p . We can combine probability p Intuitively, if we choose the collections of resources as m m m m m possible worlds, then ◦ can be interpreted as a commutative and density operator ρm into a partial density operator † combination of resources. The identity e is an empty re- MmρMm = pmρm. This convention significantly simplifies the presentation. source or lack of resource, and combine any resource x and empty resource e yields x itself. Based on the combination, Definition 2.3 (Denotational Semantics [16]). Let V be a a preorder is defined: if x is a combination of resources y set of variables. Then for any quantum program C with and z, it should be “larger” than y since it contains y. var(C) ⊆ V, its semantic function of domain V is the The semantics of formulas depends on the semantics mapping C V : D(V) → D(V) defined by C V(ρ) = of atomic propositions. A valuation is a mapping V : P{|ρ0 : hJC,K ρi →∗ hE, ρ0i|} for every ρ ∈ DJ(VK), where AP → ℘(X), and it is monotonic if x ∈ V(p) and y x →∗ is the reflexive and transitive closure of →, and {|· |} implies y ∈ V(p). A BI frame X together with a monotonic denotes a multi-set. valuation V gives a BI model M. Note that auxiliary variables in V \ var(C) are allowed Definition 2.5 (Satisfaction in BI models [1]). Given a BI in the above definition of semantic function C V. The formula φ and a BI model M = (X, ◦, , e, V). For each following proposition shows that the denotationalJ semanticsK x ∈ X, the relation x |= φ is defined by induction on φ: of a program C is independent of these auxiliary variables. x |=M p iff x ∈ V(p)
4 x |=M > : always x |=M ⊥ : never 3.2. Atomic Propositions about Quantum States x |=M φ1 ∧ φ2 iff x |=M φ1 and x |=M φ2 To complete our description of the quantum BI logic, x |= φ ∨ φ x |= φ or x |= φ M 1 2 iff M 1 M 2 we introduce three atomic propositions and interpret them in 0 0 0 x |=M φ1 → φ2 iff ∀x x, x |=M φ1 implies x |=M φ2 quantum states. In general, we have a great deal of freedom x |=M φ1 ∗ φ2 iff ∃y, z s.t. y ◦ z is defined and x y ◦ z, in selecting these atomic propositions; the only requirement is that their interpretation must be monotone with respect to y |=M φ1 and z |=M φ2 the pre-order . Our atomic propositions are fairly general, x |=M φ1 −∗ φ2 iff ∀y s.t. x ◦ y is defined, but motivated by applications of our separation logic. y |= φ implies x ◦ y |= φ . M 1 M 2 Propositions denoting free variables. We first introduce a set of atomic propositions D[S] for each variable set S ∈ V Following [2] (see also [11]), a sound and complete with domain defined by free (D[S]) , S, and interpret it as Hilbert-style proof system of BI is presented in Supplemen- the state with domain at least S: tary Material B.1. D[S] , {ρ ∈ D : S ⊆ dom(ρ)} . (1) J K 3. Quantum Interpretation of BI Logic Propositions for qualitative analysis. For qualitative anal- ysis of quantum programs, we often use projection operators Now, we are ready to present our quantum model of as atomic propositions. For a projection P ∈ P as an atomic BI, using the resource semantics of BI. After defining the proposition, its semantics P is defined as the following set J K model, we introduce some atomic propositions. To lay the of quantum states: groundwork for the separation logic, we explore a technical n o P , ρ ∈ D : free (P ) ⊆ dom(ρ) & supp ρ|free(P ) ⊆ P . property called restriction—which will be important for the J K frame rule—and we define a modification operation, an (2) analog of substitution that we will use for reasoning about where the support of a state ρ ∈ D is the (topological) initialization and unitary transformations. closure of the subspace spanned by its eigenvectors with nonzero eigenvalues, or equivalently, supp(ρ) = {|φi ∈ ⊥ 3 3.1. BI Frame of Quantum States Hdom(ρ) : hφ|ρ|φi = 0} . Let us carefully explain the definition of P . In the case that ρ has the same domain of P , it is naturalJ toK define ρ ∈ P if its support supp(ρ) lies The basic idea of our model is to consider quantum states in P , or equivalently, ρ is invariantJ K under projection operator over specific registers as resources. Then, the separating con- P . In the case where dom(ρ) and free (P ) are not the junction is introduced to model independent combinations same, in order to make P upward-closed (i.e., monotonic): of spatially separate quantum resources (quantum states over ρ ∈ P and ρ ρ0 implyJ K ρ0 ∈ P , it is appropriate to disjoint registers). Formally, we define: requireJ K that ρ ∈ P iff (i) dom(ρ)J⊇Kfree (P ); and (ii) the J K Definition 3.1. The partial binary functions ◦ : D×D → D restricted state of ρ on free (P ) is in P . J K on quantum states is defined by: Atomic propositions expressing uniformity in quantum security. As is well-known, probabilistic uniformity is a ( basic property in verification of security protocols. To de- ρ1 ⊗ ρ2 : if dom(ρ1) ∩ dom(ρ2) = ∅ ρ1 ◦ ρ2 scribe uniformity in quantum protocols, we introduce an , undefined : otherwise. atomic proposition U[S] for each S ⊆ V denoting finite- dimensional quantum systems. Its domain is free (U[S]) , Essentially, ◦ takes the tensor product of two quantum S. The semantics of U[S] is defined as the following set of states with disjoint domains. Note that in our setting, the quantum states: tensor product ⊗ is commutative since every quantum state ρ ∈ D is tagged with its domain. For example, |1iph1| ⊗ IS U[S] , ρ ∈ D : S ⊆ dom(ρ) & ρ|S = , |0iqh0| = |0iqh0| ⊗ |1iph1| denote the same state in pq. For J K dim(S) the partial order over quantum states, we take the following: (3) where IS is the identity density on the quantum system over Definition 3.2. Let be the partial order over D: ρ registers S. The intuition behind defining equation (3) is 0 0 0 ρ iff dom(ρ) ⊆ dom(ρ ) and ρ = ρ |dom(ρ). quite simple: for a state ρ in U[S] such that S ⊆ dom(ρ), S J K Intuitively, ρ ρ0 means that ρ describes a subsys- its restriction on should be the completely mixed state, IS , which means “uniformly distributed” over all or- tem of ρ0; more precisely, if we discard the subsystem dim(S) dom(ρ0)\dom(ρ) of ρ0, then the remaining subsystem is in thonormal bases of the system denoted by S. state ρ. Combining all of the ingredients defined, we have: Axiom schema for atomic formulas. With the interpreta- tion of atomic propositions, we have: Proposition 3.1. (D, ◦, , 1) forms a BI frame, where scalar number 1 is understood as the state over the empty register. 3. ⊥ stands for ortho-complement.
5 Proposition 3.2. 3.4. Quantum Modification of BI Formulas 1) For all S ⊆ V and identity operator IS over HS, we have: |= D[S] ↔ IS. In classical program logic, substitution is used in the 2) For all P,Q ∈ P with disjoint domains, we have: |= inference rule about assignment statements. In the quan- P ∧ Q ↔ (P ⊗ Q); tum setting, due to no-cloning of quantum data, the role 3) If S1 ⊆ S2, then |= U[S2] → U[S1]. of assignment is played by two basic constructs: unitary 4) If S1,S2 are disjoint, then: transformation and initialization. We conclude this section by defining a technique of modifying BI formulas, which |= (U[S1] ∗ U[S2]) ↔ U[S1 ∪ S2]. we will need reasoning about these operations. Note that ⊗ is not a connective in BI: instead, it stands for Definition 3.4 (Modification of atomic propositions). Let C the mathematical tensor product. Thus, P ⊗Q is a projection be a unitary transformation q := U[q] or an initialisation and can be considered as atomic formula. q := |0i. For any p ∈ AP, we write p[C] for the C- modification of p. For the three classes of atomic propo- 3.3. Restriction Property sitions defined in Sec. 3.2, p[C] is defined as follows: 1) For an atomic proposition D[S] defined in Eq. (1), After choosing (the interpretation of) atomic proposi- D[S][C] , D[S]; tions in the quantum frame (D, ◦, , 1), the semantics of 2) For an atomic proposition P ∈ P as a projection all BI formulas can be defined using Definitions 2.5. As is defined in Eq. (2), well-known, the frame rule plays an essential role in sepa- ration logic, and in turn it heavily relies on the restriction PU[q] if q ⊆ free (P ); property that satisfaction only depends on the free variables P [q := U[q]] , P q ∩ free (P ) = ∅; appearing in a BI formula φ. The restriction property was undefined otherwise; also identified and generalized in prior work on probabilistic D[q] ∧ dP e if q ∈ free (P ); P [q := |0i] q separation logic [9]. However, the restriction property: , P otherwise; ρ |= φ ⇒ ρ| |= φ free(φ) where projections PU[q] and dP eq are given as follows: where free (φ) stands for the free variables occurring in P = (U q† ⊗ I )P (U q ⊗ I ), φ, does not hold for our quantum setting, even for the U[q] free(P )\q free(P )\q F ordinary implication φ = φ1 → φ2 (see Definition 2.5 and dP eq = { closed subspaces T : |0iqh0| ⊗ T ⊆ for its semantics). Essentially, the validity of the restriction P } ∈ P(free (P )\q). Here, t is the disjunction of property in the probabilistic setting can be attributed to projections in quantum logic, that is, for projections a fundamental fact in probability theory—the existence of P,Q with the same domain, P t Q = span(P ∪ Q) extensions.4 Unfortunately, this does not always hold for with “ · ” standing for (topological) closure. quantum systems. Indeed, it is violated by the well-known 3) For any atomic proposition U[S] ∈ U for uniformity phenomenon of “Monogamy” – one of the most fundamental defined in Eq.(3), 5 properties of entanglement. a) If q ⊆ S or q∩S = ∅, then U[S][q := U[q]] , U[S]; Since we wish to have a frame rule in QSL, we need to otherwise, U[S][q := U[q]] is undefined; recover the restriction property to a certain extent. While not b) If q∈ / S, then U[S][q := |0i] , U[S]; all formulas satisfy this property, we can identify a subset otherwise, U[S][q := |0i] is undefined. of them that do satisfy it. The modification of some atomic propositions/BI formu- Definition 3.3. The formulas generated by following gram- las may not exist; we write φ[C]↓ whenever φ[C] is defined. mar are denoted by Res. The notion of modification can be easily extended to all BI φ, ψ ::= p ∈ AP | > | ⊥ | φ ∧ ψ | φ ∨ ψ | φ ∗ ψ formulae: Proposition 3.3. Any formula φ ∈ Res is restrictive; that Definition 3.5 (Modification of BI formulas). Let C be uni- is, for any ρ |= φ, ρ| |= φ. tary transformation q := U[q] or initialisation q := |0i. The free(φ) modification φ[C] of BI formula φ is defined by induction The above simple treatment of restriction property is on the structure of φ: sufficient for the purpose of this paper. A more intrinsic 1) if φ ≡ > or ⊥, then φ[C] , φ; way for recovering this property in the quantum setting will 2) if φ ≡ p ∈ AP, then φ[C] is defined according to be discussed in Section 7. Definition 3.4; 3) if φ ≡ φ1 4 φ2 where 4 ∈ {∧, ∨} and φ1[C]↓ and 4. For two joint-distributions µAB and µBC over sets A, B and B,C respectively, if they are consistent on B (with the same marginal on B) φ2[C]↓, then φ[C] , φ1[C] 4 φ2[C]; then there exists joint-distribution µABC over A, B, C which takes µAB 4) if φ ≡ φ1 ∗ φ2, φi[C]↓ and q ⊆ free (φi) or and µ as marginals. BC q ∩ free (φi) = ∅ for i = 1, 2, then 5. If two qubits A and B is maximally correlated, then they cannot be correlated at all with a third qubit C; more precisely, if A and B are in a a) if C ≡ q := U[q], then φ[C] , φ1[C] ∗ φ2[C]; maximally entangled state, then A and C cannot be in any entangled state. b) if C ≡ q := |0i, then
6 • if q∈ / free (φ )∪free (φ ), φ[C] φ [C]∗φ [C]; 1 2 , 1 2 φ[q := |0i]↓ • if only one of q ∈ free (φ1), q ∈ free (φ2) SKIP INIT {φ}skip{φ} {φ[q := |0i]} q := |0i{φ} is satisfied, then φ[C] , (φ1[C] ∧ φ2[C]) ∧ (D[free (φ1)\q] ∗ D[free (φ2)\q]); φ[q := U[q]]↓ UNIT The reason for the complexity of this case will be {φ[q := U[q]]}q := U [q] {φ} seen in the program logic; roughly speaking, initial- {φ}C1{ψ}{ψ}C2{µ} ization on q is special because it can introduce inde- SEQ pendence: it makes q independent from all variables. {φ}C1; C2{µ} 5) otherwise, φ[C] is undefined. {φ ∗ Mm} Cm{ψ} for all m ψ ∈ CM RIF A close connection between the semantics of a BI for- {φ ∗ D(q)}if ··· fi{ψ} mula φ and its modification φ[C] is shown in the following: {φ ∗ M1}C{φ ∗ D(q)} φ ∈ CM RLOOP Proposition 3.4. Let C be unitary transformation q := U[q] {φ ∗ D(q)}while{φ ∧ M0} or initialisation q := |0i, and φ be any BI formula. If its modification φ[C] is defined, then: Figure 2: Inference Rules for Program Constructs. In INIT and UNIT, ↓ means the existence of modification. In RIF and 1) φ and φ[C] have the same domain: free (φ) = RLOOP, if ··· fi and while are abbreviations of if ( m · free (φ[C]); M[q] = m → C ) fi and while M[q] = 1 do C od 2) for all ρ ∈ D(free (φ) ∪ var(C)), if ρ |= φ[C], then m respectively, and M ,M ,M in assertions are regarded as C (ρ) |= φ. 0 1 m J K projective predicates acting on q. In PERM, Perm(q 7→ q0)[q] stands for the unitary transformation which permutes 4. Separation Logic for Quantum Programs the variables from q to q0 (see Section 2.1 for details).
Now we are ready to present our separation logic for quantum programs, using quantum BI formulas as the as- 4.2. Inference Rules for Program Constructs sertion language. The first set of our inference rules are designed for 4.1. Judgments and Validity reasoning about basic quantum program constructs and dis- played in Fig. 2. Some of them deserve careful explanations: Let us first define judgments (correctness formulas) in quantum separation logic. A judgment is a Hoare triple of • Rules INIT and UNIT: With the definition of modification the form {φ}C{ψ} with both precondition φ and postcon- of BI formulas and Proposition 3.4 in mind, the rules INIT dition ψ being restrictive BI formulas (cf. Definition 3.3). and UNIT are similar to the (backwards) inference rule {φ[e/x]}x := e{φ} for assignment in classical program Definition 4.1 (Validity). Let V be a set of quantum logics. variables with free (φ), free (ψ), var(C) ⊆ V. Then a cor- rectness formula {φ}C{ψ} is true in the sense of partial • Rules RIF and RLOOP: These two rules use the sep- correctness with respect to V, written V |= {φ}C{ψ}, if arating conjunction to perform reasoning about different we have: execution paths. Note that condition φ ∈ CM is imposed in the premises of the rules RIF and RLOOP. ∀ρ ∈ D(V), ρ |= φ ⇒ C V(ρ) |= ψ. The set CM of assertions is formally defined as follows: J K Here, satisfaction relation ρ |= φ and C V(ρ) |= ψ are Definition 4.2. A formula φ is closed under mixtures (CM), defined according to the quantum interpretationJ K of BI logic written φ ∈ CM, if for any ρ, ρ0, whenever dom(ρ) = given in Section 3. dom(ρ0), ρ |= φ and ρ0 |= φ, we have: ∀ λ ∈ [0, 1], λρ + 0 The following theorem indicates that satisfaction does (1 − λ)ρ |= φ. not depends on auxiliary variables. Example 4.1. For two projections P0 = |0ih0| and P1 = Theorem 4.1. For any two sets V and V0 containing all |1ih1|, P0 ∧ P1 is CM, but P0 ∨ P1 is not CM (both free variables of φ, ψ and C, states |0ih0| and |1ih1| satisfies P0 ∨ P1, but their affine I |0ih0|+|1ih1| combination = does not satisfy P0 nor P1 0 2 2 V |= {φ}C{ψ} if and only if V |= {φ}C{ψ}. and thus does not satisfy P0 ∨ P1). As a consequence, we can drop V from V |= {φ}C{ψ} To see why the condition φ ∈ CM necessary, we and simply write |= {φ}C{ψ}. note that a quantum program can be executed in different In the remainder of this section, we gradually develop paths with non-zero probabilities, and its semantic function the proof system for our quantum separation logic. For better maps the input to a weighted summation of the outputs readability, this proof system is organised as several sets of from different execution paths. The condition φ ∈ CM is inference rules. introduced so that satisfaction relation is preserved under
7 • Rules WEAK: This rule is also similar to its counterpart φ →G φ0 {φ0}C{ψ0} ψ0 →G ψ WEAK in classical program logics, but there is a subtle difference {φ}C{ψ} between them. Since only global states (i.e. the states whose {φ1}C{ψ1}{φ2}C{ψ2} domain contains all free variables appearing in the assertions CONJ {φ1 ∧ φ2}C{ψ1 ∧ ψ2} and programs) are considered in defining the validity of the Hoare triple, we use →G in the premise of the WEAK rule {φ1}C{ψ1}{φ2}C{ψ2} DISJ for comparing assertions. It is easy to see that the rule is {φ1 ∨ φ2}C{ψ1 ∨ ψ2} also sound when using →, but the WEAK rule with →G is {φ}C{ψ} free (µ) ∩ var(C) = ∅ stronger. CONST {φ ∧ µ}C{ψ ∧ µ} • Rules CONST: This rule states that if any variable appear- {φ}C{ψ} free (µ) ∩ var(C) = ∅ ing in program C is not free in µ, then µ is preserved and free (ψ) ∪ var(C) ⊆ free (φ) or ψ ∈ SP thus can be conjoined to the pre- and post-conditions. The FRAME principle behind is that µ is restrictive, i.e., the satisfaction {φ ∗ µ}C{ψ ∗ µ} of µ depends only on the reduced state over subsystem free (µ), which trivially remains unchanged after executing →G Figure 3: Structural Rules. Since is strictly weaker than C. An interesting application of this rule is proving product → EAK ,W is stronger than ordinary weak rule. predicates from local reasoning using Proposition 3.2. • Rules FRAME: The condition free (µ)∩var(C) = ∅ in the affine combination. The following proposition identifies a premise ensures that µ can be conjoined with the pre- and class of formulas closed under mixture. post-conditions. The condition free (ψ) ∪ var(C) ⊆ free (φ) guarantees that, if the input satisfies φ∗µ, which asserts that The formulas generated by following Proposition 4.1. subsystems free (φ) and free (µ) are uncorrelated, then after grammar are CM: executing C, these two subsystems are still independent φ, ψ ::= p ∈ AP | > | ⊥ | φ ∧ ψ | U[S] ∗ φ since var(C) ⊆ free (φ), and furthermore, by the downward closed property of independence, subsystems free (ψ) and We need to pay special attention on the application of free (µ) are uncorrelated as free (ψ) ⊆ free (φ). It is par- separating conjunctions ∗ in RIF and RLOOP. Since the ticularly interesting to note that the latter condition can be quantum measurement in the guards of if-statements and altered by ψ ∈ SP defined in the following: while loops may change the quantum state, we hereby Definition 4.4 (Supported Assertion, c.f. [19]). A formula consider a special kind of inputs that satisfying φ ∗ Iq. ψ is called supported, written ψ ∈ SP, if ψ is nonempty Thus the subsystem being measured is uncorrelated to the then it has a least element, or equivalently,J K there exists a part of the state described by φ, which ensures that the S ⊆ V such that 1. at most one ρ ∈ D(S) satisfies ψ and post-measurement state still satisfies φ. In RLOOP, although 2. if σ |= ψ, σ ρ. φ∗M0 is satisfied for each path, it does not belong to CM in Trivially, any uniformity proposition U[S] and any general. Thus, only a weaker postcondition φ ∧ M0 ∈ CM can be achieved. atomic proposition defined by a projection of rank 1 are in SP; more examples of SP are given in the Supplementary Material C.4. The frame rule with SP condition is non- 4.3. Structural rules trivial and it will be very useful in our later case studies on verification of quantum information-theoretic security; The second set of rules consists of the structural rules, indeed, this application uncovered the condition ψ ∈ SP. presented in Fig. 3. The rules CONJ and DISJ are similar Note that under this condition, the frame rule is sound even to their counterparts in classical program logics. To explain without any restriction on free (ψ), free (φ) and var(C). This the other rules, let us fist define the global implication: seems counter-intuitive; but in fact, the premise {φ}C{ψ} Definition 4.3 (Global implication). For any BI formulas is much stronger than it looks at first sight, given that the φ, ψ, the global implication φ →G ψ is defined as the abbre- postcondition ψ ∈ SP. If the input satisfies precondition viation of D[free (φ) ∪ free (ψ)] → (φ → ψ). φ, then an execution of C is almost equivalent to first erasing any information on subsystem free (ψ) (of course, Trivially, →G is strictly weaker than →. The difference it is now uncorrelated with the rest part of the whole is that, φ →G ψ is already enough to ensure that for any state system), and then regenerating the singleton that satisfies ρ with dom(ρ) ⊇ free (φ) ∪ free (ψ), ρ |= φ implies ρ |= ψ. the postcondition ψ. For example, we have following proposition: Proposition 4.2. For all φ ∈ Res and S ⊆ V, it holds that 4.4. Reasoning about Entangled Predicates |= φ ↔G φ ∧ D[S]. Many quantum algorithms are designed following the Now we are ready to carefully examine the remaining same pattern: start from a large entangled state, and then rules in Fig. 3. operate on various subsystems. Inevitably, entanglements
8 often appear in the preconditions and/or postconditions of {φ}C{ψ} q ∩ var(C) = ∅ φ[E[q]]↓ ψ[E[q]]↓ Hoare triples appropriate for specifying the correctness of UNCR these algorithms. But the frame rule itself is not strong {φ[E[q]]}C{ψ[E[q]]} enough to verify them. To see this more clearly, let us consider the following simple example: Figure 4: Proof rule for dealing with entangled predicates. ↓ means the existence of modification. Example 4.2. Let |Φ±i = √1 (|00i±|11i) be two Bell states 2 ± ± ± (entanglement).√ Define√ projections Φ = |Φ ihΦ |. The program C ≡ Z[q1]; Z[q2] transforms one Bell states We divide VQA into several pieces and reason locally, but to the other; that is, both {Φ+}C{Φ−} and {Φ−}C{Φ+} the global predicate we desired is an entangled predicate that are true. However, they cannot be proved√ by using F√RAME cannot be constructed using FRAME.UNCR is the bridge or CONST to lift local correctness of Z[q1] and Z[q2] for structural reasoning from local to global predicates. In to global predicates Φ±, since Φ± cannot be written in the addition, a formal verification of Example 4.2 using UNCR ± ± form of Φ 6≡ φq1 ∗ ψq2 or Φ 6≡ φq1 ∧ ψq2 . can be found in Supplementary Material C.9. Fortunately, our frame rule can be combined with a technique for reasoning about entangled predicates proposed 4.5. Soundness in [21] to handle this problem. Originally, this technique was introduced for parallel quantum programs. Here, we need to To conclude this section, we show that quantum sepa- reformulate it in a way convenient for our purpose. A combi- ration logic QSL consisting of all the proof rules listed in nation of this technique with the frame rule can significantly Figure 2–4 are sound. The detailed proof can be found in broaden the range of applications of our quantum separation the Supplementary Material C.6. logic. To this end, we need to generalise Definition 3.4 from Theorem 4.2 (Soundness of QSL). A program C is al- modification by a unitary transformation, and initialisation 6 most surely terminating if for all inputs ρ, tr( C (ρ)) = to modification by a general quantum operation. tr(ρ). If C is a most surely terminating program,J K then Definition 4.5 (E-Modification). Let E be quantum opera- ` {φ}C{ψ} implies |= {φ}C{ψ}. tion on q. The E-Modification φ[E[q]] acting on register q of a BI formula φ is defined inductively: 5. Local Reasoning: Analysis of Variational 1) (Atomic Proposition) For any P ∈ P, we have:7 Quantum Algorithms a) if q ⊆ free (P ),