Quantum Hoare Logic
Quantum Hoare Logic
Effects, weakest preconditions, and measurement-loop rules for partial and total correctness in Chapter 6 quantum Hoare logic.
Quantum Hoare logic extends the classical triple {P} C {Q} to the quantum while-language. A predicate is an effect rather than a set of states: it is a Hermitian operator satisfying . For a (possibly subnormalized) state , is the predicate's average truth value or degree of satisfaction. Write for the denotation of a program. It is usually a completely positive trace-nonincreasing map; lost trace represents mass that has not terminated in the chosen semantics. If a model uses postselection, it must state explicitly whether postselection loss is being treated as nontermination.
The notation follows Chapter 6: , is the space of all quantum variables, is the set of positive operators of trace at most one, and is the set of effects.
§6.1 Quantum predicates, Löwner order, and weakest preconditions
Definition 6.1 (printed p. 92). A quantum predicate is a Hermitian operator whose eigenvalues all lie in , equivalently . The Löwner order means that is positive semidefinite. Lemma 6.1 also gives the equivalent condition for every density operator . Projections are therefore Boolean predicates, while general effects express quantitative properties. Lemma 6.2 (printed p. 93) states
is a CPO under this order (Lemma 6.3, printed p. 93), but it is generally not a lattice: two effects need not have a greatest lower bound or a least upper bound. Classical conjunction and disjunction therefore cannot be copied unconditionally onto one quantum system. Tensor products work for disjoint systems, and Kraus-weighted sums combine measurement branches.
§6.1.1 Semantic wp and Schrödinger–Heisenberg duality
For a quantum operation and predicate , Definition 6.2 (printed p. 95) defines the precondition relation by
Definition 6.3. is the effect satisfying this relation and such that every other precondition obeys . “Weakest” is therefore the greatest admissible effect in the Löwner order; it is not an unstated Boolean implication order.
If , Proposition 6.1 (printed pp. 95–96) gives
The adjoint (Definition 6.4, Eq. (6.9), printed p. 97) is characterized by
Thus the Schrödinger picture moves states forward, , while the Heisenberg picture moves observations backward, . Proposition 6.3 identifies this duality with the quantum weakest-precondition transformer. The adjoint preserves scalar multiplication, sums, reverse composition, and suprema of increasing sequences (Proposition 6.4, printed pp. 98–99).
§6.1.2 Commutativity: wp does not generally preserve it
Two predicates commute when . Joint reasoning about them depends on this commutativity. A general quantum operation does not guarantee that commuting produce commuting . Extra hypotheses are needed before taking separate weakest preconditions of a joint specification.
Proposition 6.5 (printed p. 100) gives two useful cases:
- If is unitary, then and commute exactly when and commute.
- If is a projective measurement whose result is discarded, they commute exactly when every compressed pair and commutes. For measurement in a complete orthonormal basis, the weakest preconditions commute for all .
A useful sufficient condition from Proposition 6.8 (printed p. 101) is that commute with each other and each commutes with every Kraus operator of ; then and commute. The bit-flip example (Example 6.2, printed p. 100) additionally requires besides , showing why postcondition commutativity alone is insufficient. Propositions 6.6, 6.9, and 6.10 provide more specialized sufficient conditions using spectral decompositions and system–environment models; their long matrix proofs are omitted here.
§6.2 Partial and total correctness
A quantum Hoare triple is
For every , Definition 6.8 (printed pp. 103–104) gives two semantics:
Total correctness:
Partial correctness:
The final two terms together compensate for nonterminating mass, so partial correctness permits an execution to fail to terminate. Total correctness requires the satisfaction promised by the precondition to appear in terminating output. If is trace-preserving, the two inequalities coincide.
Termination must be read relative to the precondition. If and is normalized, (6.12), together with , forces and requires the output to satisfy . If , the triple is trivial. An arbitrary constrains only the input effect weighted by ; it does not assert global termination on every input. Under partial correctness, always holds, while equates output satisfaction with termination mass.
In adjoint form,
§6.3 Structural wp/wlp rules and loop fixed points
Definition 6.9 (printed p. 108). The program transformer is the greatest input effect making true; is defined the same way for partial correctness. For the denotation, and
The main structural equations (Propositions 6.12 and 6.13, printed pp. 109–112) are
For Boolean initialization,
with the analogous sum over all basis values for an integer register. wlp has the same equations for skip, initialization, unitary, sequencing, and measurement branches, replacing each subprogram wp by wlp; it additionally credits nontermination mass.
Let the loop be while M[q] = 1 do S od, with measurement satisfying . For postcondition , define
The loop wp is the least fixed point of : with and ,
The loop wlp is the greatest fixed point of , obtained by the descending approximation from :
These are the least/greatest fixed-point statements of Proposition 6.14 (printed pp. 113–114). For every ,
§6.4 qPD: the partial-correctness proof system
qPD uses the Löwner order in place of classical implication. Let be a measurement with . The core axioms and rules (Figure 6.3, PDF p. 25, printed p. 115; soundness/completeness theorems on pp. 117–120) are:
- (Ax.Sk) .
- (Ax.In) (for a Boolean register, ).
- (Ax.UT) .
- (R.SC) From and , infer .
- (R.IF) From for every , infer
- (R.LP) From , infer
- (R.Or) If , , and , infer .
Theorem 6.1 (printed p. 117): qPD is sound: provability implies partial-correctness validity. Theorem 6.2 (printed p. 120): qPD is relatively complete for partial correctness of quantum while-programs: every semantically valid triple is derivable, relative to facts about the complex field and an assertion language expressive enough to state the required wlp. Relative completeness does not mean that a tool will automatically find invariants or proofs.
§6.5 qTD: total correctness, ranking functions, and termination obligations
qTD shares qPD's skip, initialization, unitary, sequencing, case, and consequence rules, replacing only its loop rule by (R.LT). For , Definition 6.10 (printed p. 121) calls a -ranking function for a loop when, for every ,
and, whenever ,
The measured state must appear here; the classical condition cannot simply be reused. Well-foundedness of rules out an infinite strictly descending chain.
The qTD loop rule (R.LT, Figure 6.5, PDF p. 33, printed p. 123) is
Lemma 6.6 (printed p. 122) characterizes the ranking obligation by the residual limit
This is the vanishing of residual mass still in the continuing branch as observed by ; it is not an automatic claim that global termination mass vanishes for every arbitrary precondition. Theorem 6.3 (printed p. 124) proves qTD sound, and Theorem 6.4 (printed p. 126) proves relative completeness. The relative qualification again concerns complex-field order facts and the expressibility of ranking functions.
§6.6 Grover example in outline
Printed pp. 127–130 use Grover search to demonstrate the combination of qPD and qTD. The search space has size and solutions. Registers form the search register, is the oracle ancilla, and is an integer counter. The program initializes the registers, prepares the uniform superposition and , and executes
while M[r] = 1 do D od; if (computational-basis measurement of the q-register) fi,
where consists of the oracle, Hadamards, phase transformation, Hadamards, and r := r+1. The threshold is chosen using the Grover angle (the textbook convention is and an integer in ).
The general specification (printed p. 128) is , where
Here and ; the near-optimal integer choice above gives . To simplify its proof, the textbook additionally assumes and that the midpoint is an admissible integer iteration count. This extra ideal case has , giving the target . A unique solution alone does not give probability one for an arbitrary integer iteration count.
The proof has three parts: use (Ax.UT) and (R.IF) to verify the loop body D; use the counter-based ranking function that decreases on each continuing iteration (pp. 129–130, Eq. (6.37)) and (R.LT) to prove loop termination; then combine initialization, gates, the loop, and final measurement with (Ax.In), (R.SC), and (R.Or). The example makes the qTD termination obligation explicit; it does not turn an arbitrary program precondition into a global termination guarantee.
§6.7 Auxiliary rules, scope, and side conditions
Auxiliary rules compress many qPD/qTD steps into readable structural proofs without changing the underlying semantics. For , the cylindric extension is ; for disjoint variables, is the partial trace. Weak operator convergence means for every pair of vectors.
Figure 6.9 (PDF p. 42, printed p. 132) gives:
- (Ax.Inv) If , , and , then .
- (R.TI) With , and , infer from .
- (R.CC) From for , infer , with and .
- (R.Inv) If and concerns variables unchanged by , infer , with and .
- (R.SO) For a quantum operation on variables unchanged by , infer from .
- (R.Lin) From infer for , with both scaled operators remaining effects. Figure 6.9 states scaling, not an affine shift by .
- (R.Lim) If , , and every is valid, infer .
Lemma 6.8 (printed pp. 131–132) supplies the scope conditions: Ax.Inv is sound only for partial correctness; R.TI, R.CC, R.Inv, and R.Lim are sound for both partial and total correctness; R.SO is sound for total correctness and for partial correctness only when is trace-preserving; R.Lin is sound for total correctness and for partial correctness only when . The following probability equivalences use normalized inputs; for partial density operators, replace 1 by . Figure 6.10 also introduces abortion and termination predicates. characterizes abortion of when , equivalently ; it characterizes termination when , equivalently . The strengthened (R.CC1)/(R.CC2) rules require respectively Abort/Term and coefficients or .
These rules support framing, mixing, noisy channels, and limit arguments; they do not automatically synthesize loop invariants, ranking functions, or numerical error bounds. Classical registers, retained measurement outcomes, postselection, and open-system models must be included explicitly in the state space and denotation.
References and page index
This entry was checked against Chapter 6 of Foundations of Quantum Programming (PDF pp. 1–44, printed pp. 91–134): Definitions/Lemmas 6.1–6.4 (PDF pp. 2–7), Proposition 6.4 (p. 8), Propositions 6.5–6.10 (pp. 10–12), Definitions 6.7–6.8 (pp. 13–14), Definition/Propositions 6.9 and 6.12–6.14 (pp. 18–24), Theorems 6.1–6.2 (pp. 27 and 30), Definition/Lemma 6.10/6.6 and Theorems 6.3–6.4 (pp. 31–36), Grover (pp. 37–40), and Lemmas 6.8–6.9 with Figures 6.9–6.10 (pp. 41–43). Long proofs, all exercises, the three quantum-relation compositions, and detailed system–environment commutativity matrices are not reproduced; definitions, rule conclusions, theorem statements, coefficients, and side conditions are retained.
- Mingsheng Ying, Foundations of Quantum Programming, Chapter 6, 2024.
- Mingsheng Ying, Floyd-Hoare Logic for Quantum Programs, ACM TOPLAS 33(6), 2011, DOI.
- Ellie D'Hondt and Prakash Panangaden, Quantum Weakest Preconditions, arXiv:quant-ph/0501157.
Further examples
Predicate connectives, auxiliary rules and Grover proof give worked details and the explicitly labelled apparent angle-formula typo.