Quantum Hoare Rules and Loop Proofs
Quantum Hoare Rules and Loop Proofs
Basic qPD and qTD rules, loop invariants, ranking functions, and side conditions for the quantum while language.
This page follows Quantum While Programs: Syntax and Execution and uses the notation of Quantum Hoare Logic and Weakest Preconditions. We use finite-dimensional registers, unnormalized execution branches, and denotational semantics that collects terminating paths. Let . Assertions are effects , and means that is positive semidefinite.
Assertions and two notions of correctness
For every partial density operator , total and partial correctness require respectively
Subscripts and below denote total and partial correctness. Total correctness imposes a termination obligation only over the effect promised by the precondition. An arbitrary total triple does not imply global termination on every input: forces termination on normalized inputs, while gives a trivial triple. A derivation must keep one correctness convention throughout.
Basic axioms
Initialization is defined by , where . Its rule is
The precondition therefore cannot be obtained by mechanically substituting 0 for in a matrix assertion. For the single-qubit postcondition , the calculated precondition is .
Sequencing and consequence
The directions follow from the trace inequalities: decreasing the precondition effect or increasing the postcondition effect preserves validity. Classical set implication cannot simply replace the Löwner order.
Measurement case rule
If holds for every outcome and , then
These are branches of one measurement, not successive tests of independent Boolean conditions. Measurement disturbance is represented by on both sides. An input entangled with untouched registers must still be interpreted on a common Hilbert space.
qPD: the partial-correctness loop rule
Let with measurement . Choose as the assertion before the body on the continuing branch and as the postcondition after exit, and set
The qPD loop rule is
is the assertion before the measurement, constrains only states entering the body on the continuing branch, and constrains exit states. They are generally different. The rule permits a divergent body or loop; the partial-correctness compensation term accounts for remaining mass. It is the same rule as (R.LP) on the main Quantum Hoare Logic page.
qPD also contains skip, initialization, unitary, sequencing, case, and Löwner consequence rules. Theorem 6.1 (printed p. 117) proves qPD sound, and Theorem 6.2 (printed p. 120) proves relative completeness, assuming facts about the complex field and an assertion language expressive enough for the required wlp. Relative completeness does not mean that a tool will synthesize an invariant automatically.
qTD: total correctness and ranking functions
Simply replacing by in the qPD loop rule is unsound: a nonterminating loop may still satisfy the body-preservation premise. Definition 6.10 (printed p. 121) calls
an -ranking function, for an effect and , exactly when, for every partial density operator ,
and
The measured continuing branch must be part of ; the classical comparison is not the quantum obligation. Well-foundedness of rules out an infinite strictly descending chain.
With this page's notation , the textbook (R.LT) rule (Figure 6.5, printed p. 123) is
The textbook figure uses for the final assertion and for the body assertion, exactly the opposite letter convention from this page; the rule has the same meaning. The ranking function concerns mass relevant to the precondition and does not require global termination for every input. Neither the body's total-correctness premise nor the condition for every positive threshold may be dropped.
Lemma 6.6 (printed p. 122) gives the equivalent residual-limit criterion. For any ranking-related effect , an -ranking function exists for every exactly when
for every . In this page's (R.LT), substitute , where is the body precondition. This is the vanishing of residual mass during continuing iterations as observed by , not a claim that a global termination mass automatically vanishes for an arbitrary precondition. Theorem 6.3 (printed p. 124) and Theorem 6.4 (printed p. 126) establish qTD soundness and relative completeness.
Weakest preconditions and fixed points
For the trace adjoint ,
and total and partial triples are equivalent to and respectively. A loop wp is obtained as the least fixed point by iterating
from the zero effect. Replacing the body wp by wlp and approximating downward from gives the greatest fixed point. See Weakest Preconditions for the transformer equations.
Example: a measurement loop that resets a qubit
For computational-basis measurement and body , choose exit postcondition and continuing-branch body precondition . Then and holds, so qPD yields . After , the continuing branch exits at the next measurement, so this particular loop terminates almost surely and the same triple is totally correct. That termination fact belongs to the example; it is not a consequence of the qPD loop rule alone.
References and audit page index
This page is aligned with the main Quantum Hoare Logic page and checked against Chapter 6 of Foundations of Quantum Programming: qPD Figure 6.3 is PDF p. 25 / printed p. 115; qPD soundness and completeness are PDF pp. 27 and 30 / printed pp. 117 and 120; Definition 6.10 is PDF p. 31 / printed p. 121; Lemma 6.6 is PDF p. 32 / printed p. 122; qTD Figure 6.5 and (R.LT) are PDF p. 33 / printed p. 123; qTD soundness and completeness are PDF pp. 34 and 36 / printed pp. 124 and 126. Definitions, structural wp/wlp equations, and auxiliary rules are summarized on the main page.