ψQuantum PL WIKITHE LANGUAGE OF QUANTUM COMPUTATION中文
VOLUME IV · Logic & verification

Quantum Hoare Logic

Quantum Hoare Logic

Quantum Hoare logic uses operator-valued predicates to distinguish partial correctness from total correctness through precise trace inequalities.

Quantum Hoare logic generalizes the triple {P} C {Q}\{P\}\,C\,\{Q\} to programs manipulating quantum states. Predicates are effects: Hermitian operators satisfying 0⪯P⪯I0\preceq P\preceq I. For a normalized state ρ\rho, the quantity tr(Pρ)\mathrm{tr}(P\rho) is the probability of the effect's measurement outcome. It also serves as a quantitative satisfaction value.

Let E=⟦C⟧\mathcal E=\llbracket C\rrbracket be a completely positive, trace-nonincreasing map collecting terminating executions, as in denotational semantics. The meaning of a triple depends on whether nontermination is permitted.

Partial and total correctness

Partial correctness holds when, for every subnormalized input ρ\rho,

tr(Pρ)≤tr(QE(ρ))+tr(ρ)−tr(E(ρ)).\mathrm{tr}(P\rho)\leq \mathrm{tr}(Q\mathcal E(\rho)) +\mathrm{tr}(\rho)-\mathrm{tr}(\mathcal E(\rho)).

The final two terms give credit for probability mass lost through nontermination. Omitting this compensation changes the definition to total correctness:

tr(Pρ)≤tr(QE(ρ)).\mathrm{tr}(P\rho)\leq\mathrm{tr}(Q\mathcal E(\rho)).

For trace-preserving programs the two conditions coincide. A total-correctness triple does not impose termination on every input independently of its precondition: P=0P=0 gives a trivial triple. With P=IP=I, the total inequality forces termination with probability one and satisfaction of QQ with probability one on every normalized input.

A map describing postselection also loses trace, but interpreting that loss as nontermination requires an explicit program model. Normalizing a successful branch and silently applying these formulas would change their meaning.

Examples and predicate transformers

For the Pauli XX gate, take P=∣0⟩⟨0∣P=\lvert0\rangle\langle0\rvert and Q=∣1⟩⟨1∣Q=\lvert1\rangle\langle1\rvert. Since X†QX=PX^\dagger QX=P, both triples hold with equality for every input.

For a program that never terminates, E(ρ)=0\mathcal E(\rho)=0. Every partial-correctness triple holds because P⪯IP\preceq I. Total correctness can hold for all inputs only when P=0P=0. This example exposes why the compensation term matters.

Writing E∗\mathcal E^* for the trace adjoint, the equivalent operator conditions are

P⪯wlpC(Q)=E∗(Q)+I−E∗(I)P\preceq\mathrm{wlp}_C(Q)=\mathcal E^*(Q)+I-\mathcal E^*(I)

for partial correctness, and P⪯wpC(Q)=E∗(Q)P\preceq\mathrm{wp}_C(Q)=\mathcal E^*(Q) for total correctness. See weakest preconditions for backward calculation rules.

Limitations

Measurement branches must be combined using their quantum operations, with classical outcomes retained when the specification observes them. Loops require invariants and, for appropriate total specifications, termination arguments. These introductory examples illustrate semantic validity; they are not machine-checked proofs of a compiler or hardware implementation. A proof system's soundness and completeness require separate theorems.

References

  • Mingsheng Ying. Floyd-Hoare logic for quantum programs. ACM Transactions on Programming Languages and Systems 33(6), 1-49 (2011). DOI: 10.1145/2049706.2049708.
  • Ellie D'Hondt and Prakash Panangaden. Quantum Weakest Preconditions. Mathematical Structures in Computer Science (2006). arXiv:quant-ph/0501157.
An introductory guide. Consult the original references for technical details and formal citations.
READ NEXTWeakest Preconditions→

Search the collection