Quantum While Programs: Syntax and Execution
Quantum While Programs: Syntax and Execution
Derive initialization, measurement branches, loops, and termination probabilities from formal syntax, partial density operators, and one-step execution rules.
This page uses a sequential language over finite-dimensional quantum registers. Measurement outcomes control execution; no additional classical store is returned. It presents a finite-dimensional account of the language discussed in Chapter 5; infinite-dimensional integer variables require additional operator and convergence conditions. Syntax, initialization, and small-step rules correspond to Definitions 5.1–5.4 and Figure 5.1; loop unfoldings correspond to Proposition 5.2.
States, registers, and program syntax
A register has Hilbert space ; spaces for several registers combine by tensor product. Inputs are partial density operators: and . The trace records the probability mass of an execution branch, without renormalizing after each measurement. A finite-dimensional core language is
is a unitary on the listed registers. A case command uses one measurement satisfying . It is not a sequence of Boolean guard tests, and its operators need not be mutually orthogonal projectors. A while command uses a two-outcome measurement : 0 exits and 1 continues. All local operators implicitly extend by the identity on other registers.
Initialization resets a register
The command discards the previous information in and prepares . For an orthonormal basis of , define . Then
The last expression uses tensor order with first. Initialization can destroy existing entanglement while preserving the reduced state of the other registers. It is a completely positive, trace-preserving map, and is generally not unitary.
One-step operational semantics
A configuration is written , and marks termination. Every measurement branch below carries an unnormalized state. Its weight is already included in its trace, so no additional probability factor is applied.
Sequential composition has two lifting rules:
In the first rule, is a residual command rather than the termination marker. A case command has one rule for each outcome :
Writing for the loop, its exit and continuation rules are
If distinct paths reach the same terminal configuration, their contributions must still be counted separately. Deduplicating them as a set would lose probability mass.
From the execution tree to a denotational map
Write and . The basic denotations satisfy
The contribution from exiting after exactly completed body executions is . Hence
The finite partial sums increase monotonically and have trace at most the input trace, so they converge in finite dimensions. Set and . Their limit is the least solution of . The zero map denotes a program that never terminates; it does not denote an immediate normal return.
For a normalized input, is the eventual termination probability. Missing mass is the probability of divergence, including possible divergence inside the body. Termination with probability one does not imply a uniform finite bound on the number of steps.
Example: measure, flip, and test again
Take computational-basis measurement and body . Outcome 0 exits immediately. Outcome 1 is flipped to the zero state by and exits at the next test. Thus
The loop terminates with probability one on every input. If the body is replaced by skip, input never exits and has zero output denotation, whereas input exits immediately.
Infinite-dimensional integer variables in the textbook
The type definitions appear on printed page 64, and initialization and transition rules in Figure 5.1 on page 67. The textbook allows both Boolean type and integer type . The latter has computational basis and can be represented as . A quantum register is a finite sequence of distinct variables, so even finitely many registers may have an infinite-dimensional state space.
The textbook's initialization rule for an integer variable is
Here the input is a positive trace-class operator. The finite partial sums are positive with bounded trace, and their convergence can be interpreted in trace norm. This is not a formal series of arbitrary unbounded matrices. Dual assertions are bounded effects, and local unitaries and measurement operators must be well-defined on the relevant Hilbert spaces. Unbounded position or momentum operators cannot directly serve as effects. Finite-dimensional matrix enumeration and numerical eigenvalue methods do not automatically extend to this setting.
Figure 5.1 defines a configuration as a pair consisting of a program and a partial density operator, without an additional general classical store; this page uses the same convention. Figure 5.2 on printed page 68 (PDF page 6) gives a separate pure-state probabilistic transition semantics: it normalizes the conditional state and labels the transition arrow with its probability. That differs from absorbing probabilities into partial density operators as above; the two conventions must not be combined in a way that counts a branch weight twice. Initialization can turn a globally pure entangled state into a mixed state, so Figure 5.2 has no general pure-state initialization rule.
Further reading and sources
Denotational Semantics explains compositionality; Weakest Preconditions applies these maps backward to assertions; Quantum Hoare Logic is used to prove program properties.
- Mingsheng Ying, Foundations of Quantum Programming, 2nd edition, Chapter 5, 2024. Chapter DOI. Relevant formulas appear in Definitions 5.1–5.6, Figures 5.1–5.2, and Propositions 5.1–5.2 (pp. 64–76). See Quantum Programming Languages and Denotational Semantics for classical recursion, variable access, and local blocks.