A Practical Quantum Hoare Logic with Classical Variables, I

Mingsheng YingarXiv 2024 · DOI

Introduction

As quantum computing moves from theoretical exploration to practical implementation, the need for robust formal verification becomes critical. In classical software engineering, Hoare Logic provides a foundational framework for proving program correctness using "triples" (precondition, program, and postcondition). However, applying this logic to quantum systems has historically been hindered by the hybrid nature of quantum programs, which combine classical control flow with quantum state manipulation.

In the paper "A Practical Quantum Hoare Logic with Classical Variables, I," Mingsheng Ying from the University of Technology Sydney introduces a refined Quantum Hoare Logic (QHL). This framework is designed to be "practical" by aligning more closely with classical programming intuitions and reducing the mathematical overhead typically associated with quantum verification.

The Barriers to Quantum Verification

Previous attempts to develop a QHL faced three primary obstacles that limited their utility for software engineers:

  1. Mathematical Complexity: Classical variables were often treated as complex mappings, making integration with standard logical tools difficult.
  2. The Measurement Problem: Quantum measurements are inherently probabilistic. Traditional logics required complex "probabilistic substitutions" to account for these outcomes, which are cumbersome for both human and automated reasoning.
  3. State Explosion: Representing quantum properties using $2^n \times 2^n$ matrices leads to exponential growth in complexity, rendering the verification of large-scale programs nearly impossible.

The $qWhile^+$ Language and Syntactic Assertions

To address these issues, Ying develops a new programming language, $qWhile^+$. This language extends previous quantum programming models by incorporating quantum arrays and parameterized gates—gates like the rotation gate $R_x(\theta)$ whose behavior depends on classical inputs.

The core innovation of this practical QHL lies in its shift from a "semantic" view to a "syntactic" one. Instead of using raw density matrices to describe quantum states, the logic employs assertions in the form of a pair $(\phi, A)$:

  • $\phi$: A standard classical first-order logic formula.
  • $A$: A symbolic quantum predicate formula.

By using symbolic formulas rather than numerical matrices, the framework allows for compact reasoning that can be more easily processed by symbolic logic solvers rather than heavy matrix calculators.

Simplifying Quantum Measurement

One of the most significant contributions of this work is the introduction of a simplified proof rule for quantum measurements. In earlier frameworks, researchers had to calculate probability distributions upfront to handle the non-deterministic nature of measurement.

Ying’s logic bypasses this by introducing a "fresh" classical variable to represent the measurement outcome in the postcondition. By asserting that a classical variable $x$ equals a new variable $y$ (representing the measurement result), the logic maintains a structure remarkably similar to classical Hoare logic. This approach allows verification engineers to reason about measurement outcomes without getting bogged down in the underlying probabilistic math.

Validation: Soundness and the QFT

The paper establishes the theoretical rigor of the logic through a Soundness Theorem (Theorem 6.1). This theorem guarantees that any program verified under these rules will behave correctly in practice, covering both partial correctness (correctness upon termination) and total correctness (guaranteed termination and correctness).

To demonstrate the framework's expressivity, the author provides a step-by-step verification of the Quantum Fourier Transform (QFT). As a cornerstone of many quantum algorithms, the successful verification of QFT using quantum arrays proves that the logic is capable of handling real-world quantum circuit implementations and scales effectively through symbolic representation.

Conclusion and Future Directions

Mingsheng Ying’s practical QHL significantly lowers the barrier to entry for classical verification engineers. By requiring only minimal modifications to traditional Hoare logic, it paves the way for integrating quantum verification into existing software engineering pipelines.

While this paper focuses on soundness and practical application, a companion "Part II" is expected to address the relative completeness of the logic—the proof that any true property of a program can, in principle, be proven within the system. Future work will also focus on implementing this framework into automated proof assistants like Coq, Isabelle/HOL, or Lean, and extending the logic to handle parallel quantum programs and error-correcting codes.

Summary updated

BibTeX
@misc{ying2024practical,
  author = {Mingsheng Ying},
  title = {{A Practical Quantum Hoare Logic with Classical Variables, I}},
  year = {2024},
  eprint = {2412.09869},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.09869},
}
Figure