Introduction
Quantum programs can contain loops that execute arbitrarily many iterations [3 , 51 ] . Understanding their termination and runtime behavior involves more than deciding whether they terminate: we would like to know how often a loop terminates, how long its terminating runs take on average, and how common very long terminating runs are [5 , 8 ] . These questions describe different aspects of completing a computation. Termination probability measures the likelihood of completion, conditional expected runtime describes its average duration [30 ] , and higher moments—averages of higher powers of runtime, such as its square—give greater weight to long executions [33 , 48 ] . This information helps us both understand a program in isolation and assess the behavior of a larger program that invokes it as a subroutine [4 ] . It is therefore desirable for a verification framework to establish these properties in a form that supports compositional reasoning, whether the relevant runtime moments are finite or infinite.
Quantum walks, a standard tool in quantum algorithm design, illustrate this difficulty [3 , 5 , 30 ] . Consider a particle moving along an infinite line whose positions are labeled by integers, with a quantum coin controlling whether each move is to the left or right. Before each move, the program uses a quantum measurement to check whether the particle is at the origin (position 0). If so, the walk stops; otherwise, the program tosses the coin (using a Hadamard operation) and moves the particle one position left or right according to the coin state. The quantum walk can evolve into a superposition of positions and coin states, allowing interference between different paths and thereby producing termination and runtime behavior different from that of a classical random
Authors’ Contact Information: Tianshi Yu, Institute of Software, Chinese Academy of Sciences, Beijing, China, yuts@ios.ac.cn; Minbo Gao, Institute of Software, Chinese Academy of Sciences, Beijing, China and University of Chinese Academy of Sciences, Beijing, China, gmb17@tsinghua.org.cn; Li Zhou, Institute of Software, Chinese Academy of Sciences, Beijing, China, zhouli@iscas.ac.cn. walk. Suppose the walk starts at position 1 with its coin in the rightward state. Then the runtime τ \tau τ , measured in loop iterations, satisfies
P ( τ < ∞ ) = 2 π , E [ τ ] = ∞ , E [ τ ∣ τ < ∞ ] = π 2 , E [ min ( τ , N ) 2 ∣ τ < ∞ ] = log N + O ( 1 ) . \mathbb{P}(\tau< \infty) = \frac{2}{\pi}, \qquad\mathbb{E}[\tau] = \infty, \qquad\mathbb{E}[\tau\mid\tau< \infty] = \frac{\pi}{2}, \qquad\mathbb{E}[\min(\tau,N)^2 \mid\tau< \infty] = \log N + O(1). P ( τ < ∞ ) = π 2 , E [ τ ] = ∞ , E [ τ ∣ τ < ∞ ] = 2 π , E [ min ( τ , N ) 2 ∣ τ < ∞ ] = log N + O ( 1 ) .
Therefore, the walk fails to terminate with probability greater than one third, yet takes fewer than two iterations on average conditional on termination. Moreover, when each terminating run’s duration is capped at N N N , the resulting conditional second moment grows logarithmically with N N N , which implies the conditional second moment E [ τ 2 ∣ τ < ∞ ] \mathbb{E}[\tau^2 \mid\tau< \infty] E [ τ 2 ∣ τ < ∞ ] is infinite.
The example above exhibits two distinct sources of infinite moments. On the one hand, the unconditional mean E [ τ ] \mathbb{E}[\tau] E [ τ ] is infinite because nontermination has positive probability. On the other hand, the conditional second moment E [ τ 2 ∣ τ < ∞ ] \mathbb{E}[\tau^2 \mid\tau< \infty] E [ τ 2 ∣ τ < ∞ ] remains infinite even after restricting attention to terminating runs, because long executions make a sufficiently large contribution. Both facts matter, and the value + ∞ +\infty + ∞ alone leaves verifying their quantitative structure unresolved. Moreover, the walk explores an infinite-dimensional state space, so directly representing its unbounded runtime quantities requires a theory of unbounded quantum observables. Thus the challenge is to encode these finer aspects of unbounded behavior in a structure suitable for program reasoning.
Existing approaches to representing unbounded information. There are two approaches to representing such unbounded information [12 , 16 , 47 ] . One approach is to admit infinite values directly into the domain of reasoning. For example, interval analyses use infinite endpoints to describe program values with no finite upper or lower bound [16 ] , and probabilistic runtime calculi reason with cost functions taking values in the extended nonnegative reals [27 ] . Another approach is to represent an infinite collection of quantitative information through a parameterized object. A famous example is the generating function, which encodes an infinite sequence as the coefficients of a formal power series and allows asymptotic properties of the sequence to be recovered from the series’ analytic behavior. This approach supports average-case analysis of sorting, searching, and hashing algorithms [47 ] , as well as reasoning about the output distributions of probabilistic programs [12 , 28 ] . Similarly, in finite-state Markov decision processes, rewards over an infinite horizon are encoded in normalized discounted values, whose limits recover optimal long-run average rewards [22 ] .
Existing works in quantum runtime analysis either do not cover infinite expected costs or follow the first approach, admitting infinite values directly into their reasoning domains. Expected runtime calculi provide compositional methods with finite-dimensional quantum registers or finite-dimensional computational techniques [4 , 37 ] ; these techniques do not cover the coherent walk on the infinite line. Yu [56 ] reduces flowchart programs to a single loop while preserving runtime moments and gives algorithms for termination and exact expected runtime; the computation of this work assumes a finite-dimensional state space and almost-sure termination, conditions under which all runtime moments are finite. Unbounded pre-expectations [21 ] and closed positive quadratic forms [59 ] follow the direct approach, extending expectation-transformer reasoning to infinite-dimensional systems through unbounded predicates. These calculi can establish that an expected cost is infinite, but that conclusion alone leaves the finer properties above unresolved. Thus we want to seek a representation that retains this finer information and supports quantum program composition.
Design choice. We take the second approach: encoding the unbounded information into a parameterized object. Its central design problem is to choose how execution times are weighted at each parameter value. The weights are designed to meet three requirements. First, they are bounded , so that the resulting observations remain finite even when runtime moments are infinite. Second, they support composition , so that verified specifications for individual commands can be combined according to the program structure. For quantum programs, this involves preserving the dependence between execution time and the state on which the next command acts. Third, they retain enough runtime information to recover termination probabilities, conditional moments, and the divergence rates of infinite moments. Meeting these requirements together allows the parameterized representation to support both quantitative analysis and compositional verification.
To meet the above requirements, we use an auxiliary observation scale s > 0 s > 0 s > 0 and assign a finite runtime n n n the weight
r s ( n ) ≜ s s + n , r s ( ∞ ) ≜ 0. r_s(n) \triangleq\frac{s}{s+n}, \qquad r_s(\infty) \triangleq0. r s ( n ) ≜ s + n s , r s ( ∞ ) ≜ 0.
At each scale, these weights give bounded observations of execution time. Changing the scale changes how strongly long executions contribute to the observation. The weights also allow time consumed by a command to be accounted for by shifting the scale, which supports sequential calls and nested loops. Their large-scale behavior retains the information used to recover the runtime properties above. Thus the scale provides a common means of organizing both program composition and quantitative analysis.
Contributions. Building on the above choice of weights, we develop a weakest-precondition calculus for reasoning about fine-grained properties of quantum loops. The concrete contributions are as follows:
Runtime-graded semantics and parameterized predicates. To express specifications in this calculus, we introduce parameterized predicates : families of bounded quantum effects indexed by the observation scale. We support them with a runtime-graded semantics that records, for each finite runtime n n n , the output state of executions that terminate after exactly n n n loop iterations. We also show how to translate a valid cost Hoare triple in [59 ] into a valid triple over parameterized predicates.
A compositional weakest-precondition calculus. Our weakest-precondition calculus propagates these parameterized predicates backward through the program syntax using the runtime weights and scale shifts. Moreover, for loops, we prove that the weakest-precondition equation has a unique solution in the predicate domain and show how to certify an approximation by checking it against the weakest-precondition equation.
Rules for extracting runtime properties. Since our parameterized weight has a clear probabilistic interpretation, the asymptotic behavior of a precondition yields termination probabilities and conditional moments. We provide rules for recovering these properties from a runtime family verified on the program’s full state space. When a conditional moment is infinite, the same family gives its rate of divergence, which is measured by how quickly the corresponding capped moment grows as the cap on runtime increases.
Applications. Using this calculus, we verify the termination and runtime properties of the quantum walk mentioned above. To the best of our knowledge, this is the first direct verification of all these properties for the quantum walk on the one-dimensional infinite line using a weakest-precondition calculus.
For the one-dimensional absorbing walk with a Hadamard coin, we verify the termination probability and conditional mean runtime from the program and show that the conditional second moment diverges. When the durations of terminating runs are capped, we establish that the resulting second moment grows logarithmically with the cap. We also extend the analysis to biased walks with arbitrary initial coin states.
Furthermore, to demonstrate the composability of our framework, we verify the termination and runtime properties of a nested loop: an outer loop that repeatedly invokes the Hadamard walk as a subprogram. At each loop test, a fair coin measurement decides whether to exit or to reinitialize the state and run the walk again. By reusing the verified runtime family of the inner walk, we obtain the outer loop’s termination probability and its expected runtime conditional on termination.
Organization. Section 2 presents the motivating example. Sections 3–5 develop the runtime-graded semantics, weakest-precondition calculus, and rules for extracting runtime properties. Section 6 presents the case studies, followed by related work in Section 7 and the conclusion in Section 8. The supplemental text provides full proofs and detailed calculations.
Motivating Example
We use the one-dimensional absorbing quantum walk [5 , 30 ] to illustrate what runtime information a verification framework should retain and what it takes to reuse that information in a larger program. Quantum walks are important algorithmic primitives and universal for quantum computation [14 , 15 ] . As a classic model, the absorbing walk is a concrete and useful setting in which termination probability, finite moments, and infinite moments all matter, both for a single invocation and for a program that calls it repeatedly.
Finite and infinite runtime properties
Figure 1 presents the absorbing Hadamard walk as a quantum loop over a coin register and an integer position register. The coin states ∣ L ⟩ |L\rangle ∣ L ⟩ and ∣ R ⟩ |R\rangle ∣ R ⟩ control the direction of movement along the integer lattice. At each loop test, the guard M M M measures whether the particle is at the origin, grouping all nonzero positions into a single continuation outcome. If the position is zero, the loop terminates; otherwise, the body applies a Hadamard gate C 1 / 2 C_{1/2} C 1/2 to the coin and shifts the position left or right accordingly. The guard preserves superpositions among nonzero positions. We measure runtime by the number of entries into the loop body.
Figure 1. The program and its first iteration. The guard distinguishes the origin (outcome zero) from all nonzero sites together (outcome one). Here τ \tau τ is the total runtime and t t t is the remaining runtime from ∣ R , 2 ⟩ |R,2\rangle ∣ R , 2 ⟩ .
Starting from ∣ R , 1 ⟩ |R,1\rangle ∣ R , 1 ⟩ , the first iteration produces the superposition shown in Figure 1 . At the next guard measurement, half of the probability mass terminates at the origin with total runtime τ = 1 \tau= 1 τ = 1 . The other half continues from ∣ R , 2 ⟩ |R,2\rangle ∣ R , 2 ⟩ with one iteration already spent.
To characterize the whole execution, we want to answer three questions:
How often does the walk terminate? Its termination probability on this input is 2 / π 2/\pi 2/ π .
How long do terminating executions take on average? Their expected runtime is π / 2 \pi/2 π /2 , fewer than two iterations.
(3) How strongly do long terminating executions affect the runtime? The conditional second moment is infinite. To describe its divergence, we ask how the conditional second moment grows when each terminating run’s duration is capped at N N N before squaring.
The probability, conditional mean, and infinite conditional second moment are known properties of this walk [30 Section 4] . The capped second moment grows logarithmically with N N N ; establishing this rate is a further verification target, treated in Section E.2 of the supplemental text.
The expected-cost calculus of [59 ] (or equivalently [21 ] ) allows us to prove that the unconditional expected runtime is infinite (Theorem A.2 of the supplemental text). This follows from the positive probability of nontermination. The infinite conditional second moment has a different source: long executions still make an unbounded contribution after nonterminating runs have been excluded. Thus a verification framework should establish both the finite quantities and the quantitative behavior of the infinite ones.
These questions place two requirements on the parameterized approach outlined in the introduction. Each observation should remain bounded when a runtime moment is infinite. At the same time, the observations taken across parameter values must retain enough information to recover the termination probability, conditional moments, and the growth of capped moments. For this walk, all three questions should be answered from the same verified representation.
Reusing a verified loop in a caller
Figure 2 places Walk inside an outer loop that draws a fresh fair bit at each guard. Outcome one exits the outer loop; outcome one initializes the registers to ∣ R , 1 ⟩ \lvert R, 1\rangle ∣ R , 1 ⟩ and executes Walk. When the inner walk terminates, execution continues at the outer guard. Each continuing pass contributes one unit of runtime for entering the outer body plus the runtime t i t_i t i of that call to Walk.
The caller
while randomBit() = 1 do
coin := |R⟩;
position := |1⟩;
Walk
odFigure 2. An outer loop calling Walk. Each t i t_i t i is the runtime of a terminating call. Total runtime counts entries into both the outer and inner loop bodies.
We now ask for the outer loop’s termination probability and conditional expected runtime. As the table in Figure 2 shows, the caller can terminate before making a call or after several calls have finished. If any call fails to terminate, the caller also fails to terminate. A compositional analysis should obtain the caller’s properties by reusing a verified specification of the initialized walk.
In backward reasoning, we must account for the execution that follows the call. Suppose the first call takes either one or three iterations. Including the step spent entering the outer body, these executions reach the outer guard after two or four iterations. If the remaining execution takes t t t further iterations, their total runtimes are 2 + t 2+t 2 + t and 4 + t 4+t 4 + t . Although both executions continue with the same code, an observation of their total runtime must account for the different amounts of time already spent.
This gives the third design requirement: the representation must support composition. Propagating a postcondition backward through a call must account for its possible runtimes and yield a precondition of the same form, allowing the same rules to be reused through further commands and enclosing loops. In a general quantum program, the remaining execution also depends on the quantum state produced by the call. Reasoning about the continuation must therefore retain the dependence between runtime and output state. We seek parameterized predicates that carry this information through program composition and support the quantitative questions raised by the walk.
Runtime Semantics and Parameterized Predicates
To reason compositionally about both runtime and quantum state transformations, we refine the standard denotational semantics ⟦ S ⟧ \llbracket S \rrbracket [ [ S ] ] of a quantum program S S S into runtime-graded completely positive maps ⟦ S ⟧ r t = ( ⟦ S ⟧ n ) n ≥ 0 \llbracket S \rrbracket_{\mathrm{rt}} = (\llbracket S \rrbracket_n)_{n \ge0} [ [ S ] ] rt = ( [ [ S ] ] n ) n ≥ 0 and test them against scale-indexed families of bounded effects F = ( F s ) s > 0 F = (F_s)_{s > 0} F = ( F s ) s > 0 .
Programs and Their Runtime-Graded Semantics
Fix a finite set V a r \mathrm{Var} Var of quantum variables. Each variable q q q has a separable Hilbert space H q \mathcal{H}_q H q , possibly infinite-dimensional, and a distinguished unit vector ∣ 0 ⟩ q \lvert0 \rangle_q ∣ 0 ⟩ q . The joint space and its partial density operators are
H ≜ ⨂ q ∈ V a r H q , D ( H ) ≜ { ρ ∈ T ( H ) : ρ ≥ 0 , tr ( ρ ) ≤ 1 } . \mathcal{H} \triangleq\bigotimes_{q \in\mathrm{Var}} \mathcal{H}_q,\qquad\mathcal{D}(\mathcal{H}) \triangleq\{ \rho\in\mathcal{T}(\mathcal{H}) : \rho\ge0,\ \operatorname{tr}(\rho) \le1 \}. H ≜ q ∈ Var ⨂ H q , D ( H ) ≜ { ρ ∈ T ( H ) : ρ ≥ 0 , tr ( ρ ) ≤ 1 } .
Here T ( H ) \mathcal{T}(\mathcal{H}) T ( H ) is the space of trace-class operators. Following standard quantum while-language conventions [50 , 59 ] , programs are generated by
S : : = skip ∣ abort ∣ q : = ∣ 0 ⟩ ∣ q ˉ : = U [ q ˉ ] ∣ S 1 ; S 2 ∣ if ( □ i ∈ J M [ q ˉ ] = i → S i ) fi ∣ while M [ q ˉ ] = 1 do B od . S ::= \operatorname{skip} \mid\operatorname{abort} \mid q := \lvert0 \rangle\mid\bar{q} := U[\bar{q}] \mid S_1; S_2
\mid\operatorname{if}\left(\Box_{i \in J} M[\bar{q}] = i \to S_i\right)\operatorname{fi} \mid\operatorname{while}\ M[\bar{q}] = 1\ \operatorname{do}\ B\ \operatorname{od}. S ::= skip ∣ abort ∣ q := ∣ 0 ⟩ ∣ q ˉ := U [ q ˉ ] ∣ S 1 ; S 2 ∣ if ( □ i ∈ J M [ q ˉ ] = i → S i ) fi ∣ while M [ q ˉ ] = 1 do B od .
Here U U U is unitary, and operators on a subsystem are extended by the identity on the remaining variables. Initialization resets q q q to ∣ 0 ⟩ q \lvert0 \rangle_q ∣ 0 ⟩ q . A conditional measurement has a finite outcome set J J J and satisfies ∑ i ∈ J M i † M i = I \sum_{i \in J} M_i^\dagger M_i = I ∑ i ∈ J M i † M i = I . A loop uses a binary measurement: outcome zero exits, and outcome one enters the body.
M i ( ρ ) ≜ M i ρ M i † , R q ( ρ ) ≜ ∣ 0 ⟩ ⟨ 0 ∣ q ⊗ tr q ( ρ ) , U q ˉ ( ρ ) ≜ U ρ U † . \mathcal{M}_i(\rho) \triangleq M_i \rho M_i^\dagger,\qquad\mathcal{R}_q(\rho) \triangleq\lvert0 \rangle\langle0 \rvert_q \otimes\operatorname{tr}_q(\rho),\qquad\mathcal{U}_{\bar{q}}(\rho) \triangleq U \rho U^\dagger. M i ( ρ ) ≜ M i ρ M i † , R q ( ρ ) ≜ ∣ 0 ⟩ ⟨ 0 ∣ q ⊗ tr q ( ρ ) , U q ˉ ( ρ ) ≜ U ρ U † .
Definition 3.1 (Runtime-graded denotational semantics). The runtime-graded denotational semantics of a program S S S is the sequence
⟦ S ⟧ r t ≜ ( ⟦ S ⟧ n ) n ≥ 0 , ⟦ S ⟧ n : T ( H ) → T ( H ) , \llbracket S \rrbracket_{\mathrm{rt}} \triangleq(\llbracket S \rrbracket_n)_{n \ge0},\qquad\llbracket S \rrbracket_n : \mathcal{T}(\mathcal{H}) \to\mathcal{T}(\mathcal{H}), [ [ S ] ] rt ≜ ( [ [ S ] ] n ) n ≥ 0 , [ [ S ] ] n : T ( H ) → T ( H ) , where the grade-n n n map ⟦ S ⟧ n \llbracket S \rrbracket_n [ [ S ] ] n produces the subnormalized output state of executions terminating after exactly n n n total loop-body entries (accumulating iterations across nested loops, while loop exits and loop-free commands contribute zero). For n ≥ 0 n \ge0 n ≥ 0 , the grades are defined by
⟦ skip ⟧ n = 1 { n = 0 } id , ⟦ abort ⟧ n = 0 , \llbracket\operatorname{skip} \rrbracket_n = 1_{\{n=0\}}\operatorname{id},\qquad\llbracket\operatorname{abort} \rrbracket_n = 0, [ [ skip ] ] n = 1 { n = 0 } id , [ [ abort ] ] n = 0 , ⟦ q : = ∣ 0 ⟩ ⟧ n = 1 { n = 0 } R q , ⟦ q ˉ : = U [ q ˉ ] ⟧ n = 1 { n = 0 } U q ˉ , \llbracket q := \lvert0 \rangle\rrbracket_n = 1_{\{n=0\}}\mathcal{R}_q,\qquad\llbracket\bar{q} := U[\bar{q}] \rrbracket_n = 1_{\{n=0\}}\mathcal{U}_{\bar{q}}, [ [ q := ∣ 0 ⟩ ] ] n = 1 { n = 0 } R q , [ [ q ˉ := U [ q ˉ ] ] ] n = 1 { n = 0 } U q ˉ , ⟦ S 1 ; S 2 ⟧ n = ∑ a + b = n ⟦ S 2 ⟧ b ∘ ⟦ S 1 ⟧ a , \llbracket S_1; S_2 \rrbracket_n = \sum_{a+b=n} \llbracket S_2 \rrbracket_b \circ\llbracket S_1 \rrbracket_a, [ [ S 1 ; S 2 ] ] n = a + b = n ∑ [ [ S 2 ] ] b ∘ [ [ S 1 ] ] a , ⟦ if ( □ i M [ q ˉ ] = i → S i ) fi ⟧ n = ∑ i ⟦ S i ⟧ n ∘ M i , \llbracket\operatorname{if}\left(\Box_i M[\bar{q}] = i \to S_i\right)\operatorname{fi} \rrbracket_n = \sum_i \llbracket S_i \rrbracket_n \circ\mathcal{M}_i, [ [ if ( □ i M [ q ˉ ] = i → S i ) fi ] ] n = i ∑ [ [ S i ] ] n ∘ M i , ⟦ while M [ q ˉ ] = 1 do B od ⟧ n = ∑ j = 0 n ∑ k 1 , … , k j ∈ N + k 1 + ⋯ + k j = n M 0 ∘ C k j ∘ ⋯ ∘ C k 1 . (1) \llbracket\operatorname{while}\ M[\bar{q}] = 1\ \operatorname{do}\ B\ \operatorname{od} \rrbracket_n =
\sum_{j=0}^{n}\ \sum_{\substack{k_1,\ldots,k_j \in\mathbb{N}_+\\ k_1+\cdots+k_j=n}}
\mathcal{M}_0 \circ\mathcal{C}_{k_j} \circ\cdots\circ\mathcal{C}_{k_1}. \tag*{(1)} [ [ while M [ q ˉ ] = 1 do B od ] ] n = j = 0 ∑ n k 1 , … , k j ∈ N + k 1 + ⋯ + k j = n ∑ M 0 ∘ C k j ∘ ⋯ ∘ C k 1 . (1)
Here C k ≜ ⟦ B ⟧ k − 1 ∘ M 1 C_k \triangleq\llbracket B\rrbracket_{k-1} \circ\mathcal{M}_1 C k ≜ [ [ B ] ] k − 1 ∘ M 1 for k ≥ 1 k \ge1 k ≥ 1 : entering the body contributes one iteration, and executing B B B contributes the remaining k − 1 k-1 k − 1 . The j = 0 j=0 j = 0 term is 1 { n = 0 } M 0 \mathbf{1}_{\{n=0\}}\mathcal{M}_0 1 { n = 0 } M 0 .
Proposition 3.2 (Well-definedness and compatibility). For every program S S S , the grades ( ⟦ S ⟧ n ) n ≥ 0 (\llbracket S\rrbracket_n)_{n\ge0} ( [ [ S ] ] n ) n ≥ 0 are well-defined completely positive, trace-nonincreasing maps, and ∑ n ≥ 0 ⟦ S ⟧ n ( ρ ) = ⟦ S ⟧ ( ρ ) \sum_{n\ge0}\llbracket S\rrbracket_n(\rho)=\llbracket S\rrbracket(\rho) ∑ n ≥ 0 [ [ S ] ] n ( ρ ) = [ [ S ] ] ( ρ ) in trace norm for every ρ ∈ D ( H ) \rho\in\mathcal{D}(\mathcal{H}) ρ ∈ D ( H ) .
The proof in Section B of the supplemental text proceeds by structural induction, using the trace-nonincreasingness of finite partial sums to justify trace-norm convergence and series regrouping.
From Costs to Bounded Runtime Tests
From the grades of S S S , define the exact-runtime termination effects, the total termination effect, and the divergence effect:
E n S ≜ ⟦ S ⟧ n † ( I ) , Q S ≜ ∑ n ≥ 0 E n S = ⟦ S ⟧ † ( I ) , D S ≜ I − Q S . (2) E_n^S \triangleq\llbracket S\rrbracket_n^\dagger(I), \qquad Q_S \triangleq\sum_{n\ge0} E_n^S=\llbracket S\rrbracket^\dagger(I), \qquad D_S\triangleq I-Q_S. \tag*{(2)} E n S ≜ [ [ S ] ] n † ( I ) , Q S ≜ n ≥ 0 ∑ E n S = [ [ S ] ] † ( I ) , D S ≜ I − Q S . (2)
Here the adjoint is defined by trace duality. For a normalized input ρ \rho ρ , let τ S \tau_S τ S denote the runtime of S S S , with τ S = ∞ \tau_S=\infty τ S = ∞ on nontermination. Then tr ( E n S ρ ) = P ρ ( τ S = n ) \operatorname{tr}(E_n^S\rho)=\mathbb{P}_{\rho}(\tau_S=n) tr ( E n S ρ ) = P ρ ( τ S = n ) and tr ( D S ρ ) = P ρ ( τ S = ∞ ) \operatorname{tr}(D_S\rho)=\mathbb{P}_{\rho}(\tau_S=\infty) tr ( D S ρ ) = P ρ ( τ S = ∞ ) . Because runtime moments and expected costs can diverge to + ∞ +\infty + ∞ on infinite-dimensional spaces, they cannot in general be represented by bounded operators. Following [59 ] , we represent the unnormalized k k k -th runtime moment (k > 0 k>0 k > 0 ) on terminating runs and the total expected runtime as closed positive quadratic forms (which extend positive operators by allowing the value + ∞ +\infty + ∞ ):
M k S ≜ ∑ n ≥ 0 n k E n S (3) M_k^S \triangleq\sum_{n\ge0} n^k E_n^S \tag*{(3)} M k S ≜ n ≥ 0 ∑ n k E n S (3)
C S ≜ sup N ≥ 1 ( ∑ n ≥ 0 min ( n , N ) E n S + N D S ) = M 1 S + ∞ D S . (4) C_S \triangleq\sup_{N\ge1}\left(\sum_{n\ge0}\min(n,N)E_n^S+ND_S\right)=M_1^S+\infty D_S. \tag*{(4)} C S ≜ N ≥ 1 sup ( n ≥ 0 ∑ min ( n , N ) E n S + N D S ) = M 1 S + ∞ D S . (4)
Positive series and suprema are taken in the order of quadratic forms, allowing the value + ∞ +\infty + ∞ . For a closed positive form P P P , we write tr ( P ρ ) \operatorname{tr}(P\rho) tr ( P ρ ) for its extended expectation, obtained by increasing bounded approximations to P P P . In particular, tr ( C S ρ ) = E ρ [ τ S ] \operatorname{tr}(C_S\rho)=\mathbb{E}_{\rho}[\tau_S] tr ( C S ρ ) = E ρ [ τ S ] by monotone convergence of the truncated expectations E ρ [ min ( τ S , N ) ] \mathbb{E}_{\rho}[\min(\tau_S,N)] E ρ [ min ( τ S , N )] .
Motivating the predicate domain and calculus. We evaluate individual execution costs via a bounded test before taking expectations, using the scalar normalized resolvent at scale s > 0 s>0 s > 0 :
r s ( t ) ≜ s s + t ( t ≥ 0 ) , r s ( ∞ ) ≜ 0. r_s(t)\triangleq\frac{s}{s+t}\quad(t\ge0),\qquad r_s(\infty)\triangleq0. r s ( t ) ≜ s + t s ( t ≥ 0 ) , r s ( ∞ ) ≜ 0.
Because r s r_s r s is bounded and vanishes at ∞ \infty ∞ , its expectation remains finite and retains information about terminating executions even when E ρ [ τ S ] = ∞ \mathbb{E}_{\rho}[\tau_S]=\infty E ρ [ τ S ] = ∞ . Its large-scale behavior determines the runtime properties studied in § 5 .
Lifting r s r_s r s to a bounded positive terminal-cost operator G G G yields the normalized resolvent R s ( G ) ≜ s ( s I + G ) − 1 R_s(G)\triangleq s(sI+G)^{-1} R s ( G ) ≜ s ( s I + G ) − 1 , which is a quantum effect (an operator between 0 0 0 and I I I ). Because R s R_s R s reverses the operator order (0 ≤ G ≤ P 0\le G\le P 0 ≤ G ≤ P implies R s ( P ) ≤ R s ( G ) R_s(P)\le R_s(G) R s ( P ) ≤ R s ( G ) ), it turns an upper bound on terminal cost into a lower bound on the bounded runtime test. Since runtime n n n adds n I nI n I to the terminal cost,
R s ( n I + G ) = s s + n R s + n ( G ) , ∑ n ≥ 0 ⟦ S ⟧ n † ( R s ( n I + G ) ) = ∑ n ≥ 0 s s + n ⟦ S ⟧ n † ( R s + n ( G ) ) . (5) R_s(nI+G)=\frac{s}{s+n}R_{s+n}(G), \qquad\sum_{n\ge0}\llbracket S\rrbracket_n^\dagger(R_s(nI+G))=\sum_{n\ge0}\frac{s}{s+n}\llbracket S\rrbracket_n^\dagger(R_{s+n}(G)). \tag*{(5)} R s ( n I + G ) = s + n s R s + n ( G ) , n ≥ 0 ∑ [ [ S ] ] n † ( R s ( n I + G )) = n ≥ 0 ∑ s + n s [ [ S ] ] n † ( R s + n ( G )) . (5)
The terminal test is therefore evaluated at scale s + n s+n s + n and weighted by s / ( s + n ) s/(s+n) s / ( s + n ) . However, because a program may terminate after different runtimes n n n across branches, averaging s s + n R s + n ( G ) \frac{s}{s+n}R_{s+n}(G) s + n s R s + n ( G ) over n n n produces a convex combination of shifted resolvents that cannot be written as R s ( P ) R_s(P) R s ( P ) for any single cost operator P P P in general. To keep the assertion domain closed under branching and sequential pullbacks, we therefore generalize from resolvents of single costs to arbitrary scale-indexed effect families F = ( F s ) s > 0 F=(F_s)_{s>0} F = ( F s ) s > 0 , on which accumulating n n n steps of runtime acts by F s ↦ s s + n F s + n F_s \mapsto\frac{s}{s+n}F_{s+n} F s ↦ s + n s F s + n .
This transformation respects sequential execution because
s s + c + t = s s + c s + c s + c + t ( s > 0 , c , t ≥ 0 ) . (6) \frac{s}{s+c+t}=\frac{s}{s+c}\frac{s+c}{s+c+t}\qquad(s>0,\ c,t\geq0). \tag*{(6)} s + c + t s = s + c s s + c + t s + c ( s > 0 , c , t ≥ 0 ) . (6)
This scale-shift law also admits an operational interpretation via a random deadline. Let T s ≥ 0 T_s\geq0 T s ≥ 0 be a deadline independent of the execution, with density s / ( s + t ) 2 s/(s+t)^2 s / ( s + t ) 2 on [ 0 , ∞ ) [0,\infty) [ 0 , ∞ ) , so that its median is s s s and the probability of surviving at least t t t steps is
P ( T s ≥ t ) = s s + t . \mathbb{P}(T_s\geq t)=\frac{s}{s+t}. P ( T s ≥ t ) = s + t s .
Then conditioning on survival past c c c steps simply shifts the scale of the remaining deadline to s + c s+c s + c :
P ( T s − c ≥ t ∣ T s ≥ c ) = s + c s + c + t . \mathbb{P}(T_s-c\geq t\mid T_s\geq c)=\frac{s+c}{s+c+t}. P ( T s − c ≥ t ∣ T s ≥ c ) = s + c + t s + c .
Thus, after c c c iterations, the remaining duration follows the same law at scale s + c s+c s + c .
Running example: runtime semantics of Hadamard walk. For Walk from § 2 , write
Π 0 ≜ I 2 ⊗ ∣ 0 ⟩ ⟨ 0 ∣ , U ≜ V ( C 1 / 2 ⊗ I ) , W ≜ U ( I − Π 0 ) . \Pi_0\triangleq I_2\otimes\lvert0\rangle\langle0\rvert,\qquad U\triangleq V(C_{1/2}\otimes I),\qquad W\triangleq U(I-\Pi_0). Π 0 ≜ I 2 ⊗ ∣ 0 ⟩ ⟨ 0 ∣ , U ≜ V ( C 1/2 ⊗ I ) , W ≜ U ( I − Π 0 ) .
Definition 3.1 gives every component of ⟦ W a l k ⟧ r t \llbracket\mathrm{Walk}\rrbracket_{\mathrm{rt}} [ [ Walk ] ] rt :
⟦ W a l k ⟧ n ( ρ ) = Π 0 W n ρ ( W † ) n Π 0 ( n ≥ 0 ) . \llbracket\mathrm{Walk}\rrbracket_n(\rho)=\Pi_0W^n\rho(W^\dagger)^n\Pi_0\qquad(n\geq0). [ [ Walk ] ] n ( ρ ) = Π 0 W n ρ ( W † ) n Π 0 ( n ≥ 0 ) .
The corresponding runtime observables are
E n W a l k = ( W † ) n Π 0 W n , E_n^{\mathrm{Walk}}=(W^\dagger)^n\Pi_0W^n, E n Walk = ( W † ) n Π 0 W n ,
Q W a l k = ∑ n ≥ 0 ( W † ) n Π 0 W n , Q_{\mathrm{Walk}}=\sum_{n\geq0}(W^\dagger)^n\Pi_0W^n, Q Walk = n ≥ 0 ∑ ( W † ) n Π 0 W n ,
D W a l k = I − Q W a l k = lim N → ∞ ( W † ) N W N , D_{\mathrm{Walk}}=I-Q_{\mathrm{Walk}}=\lim_{N\to\infty}(W^\dagger)^NW^N, D Walk = I − Q Walk = N → ∞ lim ( W † ) N W N ,
M k W a l k = ∑ n ≥ 1 n k ( W † ) n Π 0 W n ( k > 0 ) , M_k^{\mathrm{Walk}}=\sum_{n\geq1}n^k(W^\dagger)^n\Pi_0W^n\qquad(k>0), M k Walk = n ≥ 1 ∑ n k ( W † ) n Π 0 W n ( k > 0 ) ,
C W a l k = ∑ n ≥ 1 ( W † ) n W n . C_{\mathrm{Walk}}=\sum_{n\geq1}(W^\dagger)^nW^n. C Walk = n ≥ 1 ∑ ( W † ) n W n .
Here the limit for D W a l k D_{\mathrm{Walk}} D Walk is taken in the strong operator topology. The expressions for D W a l k D_{\mathrm{Walk}} D Walk and C W a l k C_{\mathrm{Walk}} C Walk follow from W † W = I − Π 0 W^\dagger W=I-\Pi_0 W † W = I − Π 0 : since ( W † ) n W n = ∑ m ≥ n E m W a l k + D W a l k (W^\dagger)^nW^n=\sum_{m\geq n}E_m^{\mathrm{Walk}}+D_{\mathrm{Walk}} ( W † ) n W n = ∑ m ≥ n E m Walk + D Walk is the effect of entering the loop body at least n n n times, summing these tail effects over n ≥ 1 n\geq1 n ≥ 1 yields C W a l k C_{\mathrm{Walk}} C Walk .
Parameterized Predicates and Semantic Validity
We now formalize the space of scale-indexed effect families and define the semantic validity of Hoare triples.
Definition 3.3 (Parameterized predicates and semantic validity). Write [ 0 , I ] H ≜ { E ∈ B ( H ) : 0 ≤ E ≤ I } [0,I]_{\mathcal{H}}\triangleq\{E\in\mathcal{B}(\mathcal{H}):0\leq E\leq I\} [ 0 , I ] H ≜ { E ∈ B ( H ) : 0 ≤ E ≤ I } for the effects. The predicate space is
Pred ( H ) ≜ ∏ s > 0 [ 0 , I ] H , A ≤ F ⟺ A s ≤ F s for all s > 0 , \operatorname{Pred}(\mathcal{H})\triangleq\prod_{s>0}[0,I]_{\mathcal{H}},\qquad A\leq F\Longleftrightarrow A_s\leq F_s\text{ for all }s>0, Pred ( H ) ≜ s > 0 ∏ [ 0 , I ] H , A ≤ F ⟺ A s ≤ F s for all s > 0 , which forms an ω \omega ω -CPO under the pointwise Löwner order. Suprema of increasing sequences are taken pointwise in the strong operator topology; 0 0 0 and I I I denote the constant zero and identity
families. For A , F ∈ Pred ( H ) A,F \in\operatorname{Pred}(\mathcal{H}) A , F ∈ Pred ( H ) , the Hoare triple { A } S { F } \{A\}\,S\,\{F\} { A } S { F } is valid for total correctness, written ⊨ t o t { A } S { F } \vDash_{\mathrm{tot}}\{A\}\,S\,\{F\} ⊨ tot { A } S { F } , if for every s > 0 s>0 s > 0 and ρ ∈ D ( H ) \rho\in\mathcal{D}(\mathcal{H}) ρ ∈ D ( H ) ,
tr ( A s ρ ) ≤ ∑ n ≥ 0 s s + n tr ( F s + n ⟦ S ⟧ n ( ρ ) ) . (7) \operatorname{tr}(A_s\rho)\leq\sum_{n\geq0}\frac{s}{s+n}\operatorname{tr}\left(F_{s+n}\llbracket S\rrbracket_n(\rho)\right). \tag*{(7)} tr ( A s ρ ) ≤ n ≥ 0 ∑ s + n s tr ( F s + n [ [ S ] ] n ( ρ ) ) . (7)
It is valid for partial correctness, written ⊨ p a r { A } S { F } \vDash_{\mathrm{par}}\{A\}\,S\,\{F\} ⊨ par { A } S { F } , if for every such s , ρ s,\rho s , ρ ,
tr ( A s ρ ) ≤ ∑ n ≥ 0 s s + n tr ( F s + n ⟦ S ⟧ n ( ρ ) ) + tr ( ρ ) − tr ( ⟦ S ⟧ ( ρ ) ) . (8) \operatorname{tr}(A_s\rho)\leq\sum_{n\geq0}\frac{s}{s+n}\operatorname{tr}\left(F_{s+n}\llbracket S\rrbracket_n(\rho)\right)+\operatorname{tr}(\rho)-\operatorname{tr}\left(\llbracket S\rrbracket(\rho)\right). \tag*{(8)} tr ( A s ρ ) ≤ n ≥ 0 ∑ s + n s tr ( F s + n [ [ S ] ] n ( ρ ) ) + tr ( ρ ) − tr ( [ [ S ] ] ( ρ ) ) . (8)
Both notions evaluate the same discounted postcondition on terminating executions. Total correctness assigns nonterminating runs weight zero, whereas partial correctness credits them with weight one (contributing the divergence probability tr ( D S ρ ) = tr ( ρ ) − tr ( ⟦ S ⟧ ( ρ ) ) \operatorname{tr}(D_S\rho)=\operatorname{tr}(\rho)-\operatorname{tr}(\llbracket S\rrbracket(\rho)) tr ( D S ρ ) = tr ( ρ ) − tr ( [ [ S ] ] ( ρ )) ). Because the precondition is a quantitative lower bound, ⊨ t o t \vDash_{\mathrm{tot}} ⊨ tot can also describe programs that terminate with probability less than one.
Reusing total-cost proofs. When a subprogram already has a verified expected-cost bound in the calculus of [59 ] , we do not need to re-verify it from scratch: the normalized resolvent R ( P ) ≜ ( R s ( P ) ) s > 0 ∈ Pred ( H ) R(P)\triangleq(R_s(P))_{s>0}\in\operatorname{Pred}(\mathcal{H}) R ( P ) ≜ ( R s ( P ) ) s > 0 ∈ Pred ( H ) translates any valid total-cost contract directly into a parameterized specification (proved via the Choi-Davis-Jensen inequality in Section G of the supplemental text).
Theorem 3.4 (Translation of total-cost contracts). For closed positive quadratic forms P , G P,G P , G , if tr ( P ρ ) ≥ tr ( G ⟦ S ⟧ ( ρ ) ) + tr ( C S ρ ) \operatorname{tr}(P\rho)\geq\operatorname{tr}(G\llbracket S\rrbracket(\rho))+\operatorname{tr}(C_S\rho) tr ( P ρ ) ≥ tr ( G [ [ S ] ] ( ρ )) + tr ( C S ρ ) for every ρ ∈ D ( H ) \rho\in\mathcal{D}(\mathcal{H}) ρ ∈ D ( H ) , then ⊨ t o t { R ( P ) } S { R ( G ) } \vDash_{\mathrm{tot}}\{R(P)\}\,S\,\{R(G)\} ⊨ tot { R ( P )} S { R ( G )} .
Thus a total-cost Hoare triple from [59 ] supplies a valid specification in the parameterized predicate domain.
A Compositional Resolvent Calculus and Loop Solutions
In this section, we develop a compositional calculus for the weakest preconditions wp ( S , F ) \operatorname{wp}(S,F) wp ( S , F ) and wlp ( S , F ) \operatorname{wlp}(S,F) wlp ( S , F ) . The structural rules propagate postcondition families through the program and reduce loops to fixed-point equations on Pred ( H ) \operatorname{Pred}(\mathcal{H}) Pred ( H ) . We then prove uniqueness of the loop solution and give certificates for exact and approximate specifications. The proofs appear in Section C of the supplemental text.
Weakest Preconditions and Structural Rules
Definition 4.1 (Weakest preconditions). For a program S S S and postcondition F ∈ Pred ( H ) F\in\operatorname{Pred}(\mathcal{H}) F ∈ Pred ( H ) , the weakest precondition wp ( S , F ) \operatorname{wp}(S,F) wp ( S , F ) and weakest liberal precondition wlp ( S , F ) \operatorname{wlp}(S,F) wlp ( S , F ) are the largest valid preconditions for total and partial correctness, respectively. Equivalently, they satisfy
⊨ t o t { A } S { F } ⟺ A ≤ wp ( S , F ) , \vDash_{\mathrm{tot}}\{A\}\,S\,\{F\}\Longleftrightarrow A\leq\operatorname{wp}(S,F), ⊨ tot { A } S { F } ⟺ A ≤ wp ( S , F ) , ⊨ p a r { A } S { F } ⟺ A ≤ wlp ( S , F ) . \vDash_{\mathrm{par}}\{A\}\,S\,\{F\}\Longleftrightarrow A\leq\operatorname{wlp}(S,F). ⊨ par { A } S { F } ⟺ A ≤ wlp ( S , F ) .
Theorem 4.2 (Weakest preconditions and structural rules). For every program S S S and postcondition F ∈ Pred ( H ) F\in\operatorname{Pred}(\mathcal{H}) F ∈ Pred ( H ) , the weakest precondition exists and is given at each scale s > 0 s>0 s > 0 by
wp ( S , F ) s = ∑ n ≥ 0 s s + n ⟦ S ⟧ n † ( F s + n ) . (9) \operatorname{wp}(S,F)_s=\sum_{n\geq0}\frac{s}{s+n}\llbracket S\rrbracket_n^\dagger(F_{s+n}). \tag*{(9)} wp ( S , F ) s = n ≥ 0 ∑ s + n s [ [ S ] ] n † ( F s + n ) . (9) The transformer wp ( S , ⋅ ) \operatorname{wp}(S,\mathord{\cdot}) wp ( S , ⋅ ) is monotone, preserves increasing sequential suprema, and satisfies the structural rules in Figure 3 .
Figure 3. Weakest-precondition rules for parameterized predicates. The initialization rule uses an orthonormal basis { ∣ j ⟩ q } j \{\lvert j\rangle_q\}_j {∣ j ⟩ q } j . The loop’s continuation branch charges one iteration and applies the body’s transformer at scale s + 1 s+1 s + 1 .
Proposition 4.3 (Weakest liberal preconditions). For every program S S S and postcondition F F F ,
wlp ( S , F ) = wp ( S , F ) + D S , D S ≜ ( D s ) s > 0 . (10) \operatorname{wlp}(S,F)=\operatorname{wp}(S,F)+D_S,\qquad D_S\triangleq(D_s)_{s>0}. \tag*{(10)} wlp ( S , F ) = wp ( S , F ) + D S , D S ≜ ( D s ) s > 0 . (10)
For L = while M [ q ˉ ] = 1 do B od L = \operatorname{while}\;M[\bar{q}] = 1\;\operatorname{do}\;B\;\operatorname{od} L = while M [ q ˉ ] = 1 do B od , lfp T F \operatorname{lfp} T_F lfp T F denotes the least fixed point of
( T F X ) s = M 0 † F s M 0 + s s + 1 M 1 † wp ( B , X ) s + 1 M 1 . (11) (T_FX)_s = M_0^\dagger F_sM_0 + \frac{s}{s+1}M_1^\dagger\operatorname{wp}(B,X)_{s+1}M_1. \tag*{(11)} ( T F X ) s = M 0 † F s M 0 + s + 1 s M 1 † wp ( B , X ) s + 1 M 1 . (11)
This follows directly from the nontermination term in partial validity.
Choosing the terminal postcondition I I I defines the runtime family and its liberal counterpart:
H s S ≜ wp ( S , I ) s = ∑ n ≥ 0 s s + n E n S , L s S ≜ wlp ( S , I ) s = H s S + D s . (12) H_s^S \triangleq\operatorname{wp}(S,I)_s = \sum_{n\geq0}\frac{s}{s+n}E_n^S,\qquad L_s^S \triangleq\operatorname{wlp}(S,I)_s = H_s^S + D_s. \tag*{(12)} H s S ≜ wp ( S , I ) s = n ≥ 0 ∑ s + n s E n S , L s S ≜ wlp ( S , I ) s = H s S + D s . (12)
For a normalized input ρ \rho ρ , tr ( ρ H s S ) \operatorname{tr}(\rho H_s^S) tr ( ρ H s S ) is the probability of termination before the independent deadline T s T_s T s from § 3.2 .
Certifying Loop Specifications
We verify a loop specification by substituting it into the loop equation. The check uses the body’s transformer wp ( B , ⋅ ) \operatorname{wp}(B,\cdot) wp ( B , ⋅ ) , allowing a verified subprogram to serve as the loop body.
Theorem 4.4 (Exact loop specifications and bounds). For every loop L L L as in (11) and every F ∈ Pred ( H ) F \in\operatorname{Pred}(\mathcal{H}) F ∈ Pred ( H ) , the equation X = T F X X = T_FX X = T F X has exactly one solution in Pred ( H ) \operatorname{Pred}(\mathcal{H}) Pred ( H ) , namely wp ( L , F ) \operatorname{wp}(L,F) wp ( L , F ) . Moreover, for all X , Y ∈ Pred ( H ) X,Y \in\operatorname{Pred}(\mathcal{H}) X , Y ∈ Pred ( H ) ,
X ≤ T F X ⟹ X ≤ wp ( L , F ) , T F Y ≤ Y ⟹ wp ( L , F ) ≤ Y . (13) X \leq T_FX \Longrightarrow X \leq\operatorname{wp}(L,F),\qquad T_FY \leq Y \Longrightarrow\operatorname{wp}(L,F) \leq Y. \tag*{(13)} X ≤ T F X ⟹ X ≤ wp ( L , F ) , T F Y ≤ Y ⟹ wp ( L , F ) ≤ Y . (13)
The uniqueness conclusion is notable. In general, loop equations may admit multiple fixed points, so finding a solution alone does not identify the program semantics: one must establish that it is the least fixed point. Here, any solution in Pred ( H ) \operatorname{Pred}(\mathcal{H}) Pred ( H ) is already the weakest precondition, with no separate minimality argument needed.
For example, consider while true do skip od , with guard operators M 0 = 0 M_0 = 0 M 0 = 0 and M 1 = I M_1 = I M 1 = I . Its ordinary weakest-precondition equation is simply X = X X = X X = X , which admits every effect as a solution. In our calculus, a fixed point X ∈ Pred ( H ) X \in\operatorname{Pred}(\mathcal{H}) X ∈ Pred ( H ) must instead satisfy
X s = s s + 1 X s + 1 = s s + N X s + N ( s > 0 , N ≥ 1 ) . X_s = \frac{s}{s+1}X_{s+1} = \frac{s}{s+N}X_{s+N}\qquad(s > 0,\;N \geq1). X s = s + 1 s X s + 1 = s + N s X s + N ( s > 0 , N ≥ 1 ) .
Since 0 ≤ X s + N ≤ I 0 \leq X_{s+N} \leq I 0 ≤ X s + N ≤ I , we obtain 0 ≤ X s ≤ s s + N I 0 \leq X_s \leq\frac{s}{s+N}I 0 ≤ X s ≤ s + N s I for every N N N . Letting N → ∞ N \to\infty N → ∞ shows that the unique solution is 0 0 0 , representing the absence of terminating executions.
For an asymptotic specification, the residual A − T F A A-\mathcal{T}_{F}A A − T F A measures how closely a candidate A A A satisfies the equation for one loop step. The next result turns its decay rate into an approximation guarantee for the whole loop.
Theorem 4.5 (Certification of an asymptotic loop solution). Let L L L be a loop as in (11) , F ∈ Pred ( H ) F \in\operatorname{Pred}(\mathcal{H}) F ∈ Pred ( H ) , and A = ( A s ) s > 0 A=(A_s)_{s>0} A = ( A s ) s > 0 a uniformly bounded self-adjoint family ( sup s > 0 ∥ A s ∥ < ∞ (\sup_{s>0}\lVert A_s\rVert<\infty ( sup s > 0 ∥ A s ∥ < ∞ , allowing truncated asymptotic expansions that need not lie in [ 0 , I ] H ) [0,I]_{\mathcal{H}}) [ 0 , I ] H ) . Applying T F \mathcal{T}_{F} T F to A A A via (11) and writing d s ≜ A s − ( T F A ) s d_s \triangleq A_s-(\mathcal{T}_{F}A)_s d s ≜ A s − ( T F A ) s for the one-step residual, we have for every r > 0 r>0 r > 0 as s → ∞ s\to\infty s → ∞ :
∥ d s ∥ = O ( s − r − 1 ) ⟹ ∥ A s − wp ( L , F ) s ∥ = O ( s − r ) . (14) \lVert d_s\rVert=O(s^{-r-1})\quad\Longrightarrow\quad\lVert A_s-\operatorname{wp}(L,F)_s\rVert=O(s^{-r}). \tag*{(14)} ∥ d s ∥ = O ( s − r − 1 ) ⟹ ∥ A s − wp ( L , F ) s ∥ = O ( s − r ) . (14) If there is 0 ≤ κ < 1 0\le\kappa<1 0 ≤ κ < 1 such that
u u + 1 M 1 † wp ( B , I ) u + 1 M 1 ≤ κ I ( u > 0 ) , \frac{u}{u+1}M_1^{\dagger}\operatorname{wp}(B,I)_{u+1}M_1\le\kappa I\qquad(u>0), u + 1 u M 1 † wp ( B , I ) u + 1 M 1 ≤ κ I ( u > 0 ) , then
∥ d s ∥ = O ( s − r ) ⟹ ∥ A s − wp ( L , F ) s ∥ = O ( s − r ) . (15) \lVert d_s\rVert=O(s^{-r})\quad\Longrightarrow\quad\lVert A_s-\operatorname{wp}(L,F)_s\rVert=O(s^{-r}). \tag*{(15)} ∥ d s ∥ = O ( s − r ) ⟹ ∥ A s − wp ( L , F ) s ∥ = O ( s − r ) . (15) Both implications also hold with o o o in place of O O O .
Running example: backward derivation of wp and the runtime family. Retain Π 0 = I 2 ⊗ ∣ 0 ⟩ ⟨ 0 ∣ \Pi_0=I_2\otimes\lvert0\rangle\langle0\rvert Π 0 = I 2 ⊗ ∣ 0 ⟩ ⟨ 0 ∣ , U = V ( C 1 / 2 ⊗ I ) U=V(C_{1/2}\otimes I) U = V ( C 1/2 ⊗ I ) , and W = U ( I − Π 0 ) W=U(I-\Pi_0) W = U ( I − Π 0 ) from § 3.2 , and set Π ≠ 0 ≜ I − Π 0 \Pi_{\ne0}\triangleq I-\Pi_0 Π = 0 ≜ I − Π 0 . With coin basis ∣ L ⟩ , ∣ R ⟩ \lvert L\rangle,\lvert R\rangle ∣ L ⟩ , ∣ R ⟩ , let B W a l k B_{\mathrm{Walk}} B Walk denote the loop body of Walk (Figure 1 ), which applies the Hadamard coin and conditional shift
C 1 / 2 = 1 2 ( 1 1 1 − 1 ) , V ∣ L , x ⟩ = ∣ L , x − 1 ⟩ , V ∣ R , x ⟩ = ∣ R , x + 1 ⟩ . C_{1/2}=\frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\1&-1\end{pmatrix},\qquad V\lvert L,x\rangle=\lvert L,x-1\rangle,\qquad V\lvert R,x\rangle=\lvert R,x+1\rangle. C 1/2 = 2 1 ( 1 1 1 − 1 ) , V ∣ L , x ⟩ = ∣ L , x − 1 ⟩ , V ∣ R , x ⟩ = ∣ R , x + 1 ⟩ .
We apply the structural rules of Theorem 4.2 (Figure 3 ) to derive wp ( W a l k , F ) \operatorname{wp}(\mathrm{Walk},F) wp ( Walk , F ) and H W a l k H^{\mathrm{Walk}} H Walk backward from the program syntax, reducing the program verification task to a concrete operator series. First, for any postcondition family X ∈ Pred ( H ) X\in\operatorname{Pred}(\mathcal{H}) X ∈ Pred ( H ) at the end of B W a l k B_{\mathrm{Walk}} B Walk , the unitary and sequencing rules propagate X s X_s X s backward through the two body commands (read from bottom to top):
{ ( C 1 / 2 † ⊗ I ) V † X s V ( C 1 / 2 ⊗ I ) } coin : = C 1 / 2 [ coin ] ; { V † X s V } ( coin , position ) : = V [ coin , position ] { X s } . \begin{aligned}
&\{(C_{1/2}^{\dagger}\otimes I)V^{\dagger}X_sV(C_{1/2}\otimes I)\}\\
&\quad\text{coin}:=C_{1/2}\ [\text{coin}];\\
&\{V^{\dagger}X_sV\}\\
&\quad(\text{coin},\text{position}):=V\ [\text{coin},\text{position}]\\
&\{X_s\}.
\end{aligned} {( C 1/2 † ⊗ I ) V † X s V ( C 1/2 ⊗ I )} coin := C 1/2 [ coin ] ; { V † X s V } ( coin , position ) := V [ coin , position ] { X s } .
The shift command pulls X s X_s X s back to the intermediate assertion V † X s V V^{\dagger}X_sV V † X s V , which the sequencing rule passes as the postcondition to the coin update, yielding the body transformer wp ( B W a l k , X ) s = U † X s U \operatorname{wp}(B_{\mathrm{Walk}},X)_s=U^{\dagger}X_sU wp ( B Walk , X ) s = U † X s U .
Now let Y ∈ Pred ( H ) Y\in\operatorname{Pred}(\mathcal{H}) Y ∈ Pred ( H ) be a candidate precondition family at the loop guard M = { M 0 , M 1 } M=\{M_0,M_1\} M = { M 0 , M 1 } , where M 0 = Π 0 M_0=\Pi_0 M 0 = Π 0 and M 1 = Π ≠ 0 M_1=\Pi_{\ne0} M 1 = Π = 0 . Substituting the body transformer wp ( B W a l k , Y ) s + 1 = U † Y s + 1 U \operatorname{wp}(B_{\mathrm{Walk}},Y)_{s+1}=U^{\dagger}Y_{s+1}U wp ( B Walk , Y ) s + 1 = U † Y s + 1 U into the loop functional (11) gives the fixed-point equation
Y s = Π 0 F s Π 0 + s s + 1 Π ≠ 0 U † Y s + 1 U Π ≠ 0 = Π 0 F s Π 0 + s s + 1 W † Y s + 1 W . (16) Y_s=\Pi_0F_s\Pi_0+\frac{s}{s+1}\Pi_{\ne0}U^{\dagger}Y_{s+1}U\Pi_{\ne0}=\Pi_0F_s\Pi_0+\frac{s}{s+1}W^{\dagger}Y_{s+1}W. \tag*{(16)} Y s = Π 0 F s Π 0 + s + 1 s Π = 0 U † Y s + 1 U Π = 0 = Π 0 F s Π 0 + s + 1 s W † Y s + 1 W . (16)
By Theorem 4.4, (16) has a unique solution in Pred ( H ) \operatorname{Pred}(\mathcal{H}) Pred ( H ) , namely Y = wp ( W a l k , F ) Y=\operatorname{wp}(\mathrm{Walk},F) Y = wp ( Walk , F ) .
Because the walk starts at x = 1 x=1 x = 1 and terminates as soon as it reaches x = 0 x=0 x = 0 , no continuing execution ever visits x ≤ 0 x\le0 x ≤ 0 . All surviving states therefore remain supported on the positive half-line H + ≜ C 2 ⊗ ℓ 2 ( N + ) \mathcal{H}_+\triangleq\mathbb{C}^2\otimes\ell^2(\mathbb{N}_+) H + ≜ C 2 ⊗ ℓ 2 ( N + ) , and one unitary step U U U maps H + \mathcal{H}_+ H + into ran Π 0 ⊕ H + \operatorname{ran}\Pi_0\oplus\mathcal{H}_+ ran Π 0 ⊕ H + . This invariance allows us to compress the full-space equation (16) to H + \mathcal{H}_+ H + . Let Π + \Pi_+ Π + project onto H + \mathcal{H}_+ H + and split U ∣ H + U\vert_{\mathcal{H}_+} U ∣ H + into the one-step absorbing and continuing operators
B ≜ Π 0 U ∣ H + , K ≜ Π + U ∣ H + . B\triangleq\Pi_0U\vert_{\mathcal{H}_+},\qquad K\triangleq\Pi_+U\vert_{\mathcal{H}_+}. B ≜ Π 0 U ∣ H + , K ≜ Π + U ∣ H + .
e n d s m i d = 1 {ends_mid=1} e n d s m i d = 1
On the basis { ∣ L , x ⟩ , ∣ R , x ⟩ : x ∈ N + } \{\lvert L,x\rangle,\lvert R,x\rangle:x\in\mathbb{N}_{+}\} {∣ L , x ⟩ , ∣ R , x ⟩ : x ∈ N + } of H + \mathcal{H}_{+} H + , the absorbing operator acts by
B ∣ L , 1 ⟩ = 1 2 ∣ L , 0 ⟩ , B ∣ R , 1 ⟩ = 1 2 ∣ L , 0 ⟩ , B\lvert L,1\rangle=\frac{1}{\sqrt{2}}\lvert L,0\rangle,\qquad B\lvert R,1\rangle=\frac{1}{\sqrt{2}}\lvert L,0\rangle, B ∣ L , 1 ⟩ = 2 1 ∣ L , 0 ⟩ , B ∣ R , 1 ⟩ = 2 1 ∣ L , 0 ⟩ ,
B ∣ c , x ⟩ = 0 ( c ∈ { L , R } , x ≥ 2 ) . B\lvert c,x\rangle=0\qquad(c\in\{L,R\},\ x\ge2). B ∣ c , x ⟩ = 0 ( c ∈ { L , R } , x ≥ 2 ) .
The continuing operator acts by
K ∣ L , 1 ⟩ = 1 2 ∣ R , 2 ⟩ , K ∣ L , x ⟩ = 1 2 ( ∣ L , x − 1 ⟩ + ∣ R , x + 1 ⟩ ) ( x ≥ 2 ) , K\lvert L,1\rangle=\frac{1}{\sqrt{2}}\lvert R,2\rangle,\qquad K\lvert L,x\rangle=\frac{1}{\sqrt{2}}\left(\lvert L,x-1\rangle+\lvert R,x+1\rangle\right)\qquad(x\ge2), K ∣ L , 1 ⟩ = 2 1 ∣ R , 2 ⟩ , K ∣ L , x ⟩ = 2 1 ( ∣ L , x − 1 ⟩ + ∣ R , x + 1 ⟩ ) ( x ≥ 2 ) ,
K ∣ R , 1 ⟩ = − 1 2 ∣ R , 2 ⟩ , K ∣ R , x ⟩ = 1 2 ( ∣ L , x − 1 ⟩ − ∣ R , x + 1 ⟩ ) ( x ≥ 2 ) . K\lvert R,1\rangle=-\frac{1}{\sqrt{2}}\lvert R,2\rangle,\qquad K\lvert R,x\rangle=\frac{1}{\sqrt{2}}\left(\lvert L,x-1\rangle-\lvert R,x+1\rangle\right)\qquad(x\ge2). K ∣ R , 1 ⟩ = − 2 1 ∣ R , 2 ⟩ , K ∣ R , x ⟩ = 2 1 ( ∣ L , x − 1 ⟩ − ∣ R , x + 1 ⟩ ) ( x ≥ 2 ) .
In particular, every terminating run from H + \mathcal{H}_{+} H + exits at the origin in state ∣ L , 0 ⟩ \lvert L,0\rangle ∣ L , 0 ⟩ . Compressing (16) to H + \mathcal{H}_{+} H + and unfolding the resulting recurrence yields the restricted precondition family Y s + Y_s^{+} Y s + (Proposition E.1 of the supplemental text):
Y s + ≔ Π + Y s ∣ H + = Π + wp ( W a l k , F s ) ∣ H + = ∑ n ≥ 1 s s + n ⟨ L , 0 ∣ F s + n ∣ L , 0 ⟩ ( K † ) n − 1 B † B K n − 1 . (17) Y_s^{+}\mathrel{\mathop{\coloneqq}}\left.\Pi_{+}Y_s\right|_{\mathcal{H}_{+}}=\left.\Pi_{+}\operatorname{wp}(\mathrm{Walk},F_s)\right|_{\mathcal{H}_{+}}
=\sum_{n\ge1}\frac{s}{s+n}\langle L,0\lvert F_{s+n}\rvert L,0\rangle(K^\dagger)^{n-1}B^\dagger B K^{n-1}. \tag*{(17)} Y s + : = Π + Y s ∣ H + = Π + wp ( Walk , F s ) ∣ H + = n ≥ 1 ∑ s + n s ⟨ L , 0 ∣ F s + n ∣ L , 0 ⟩ ( K † ) n − 1 B † B K n − 1 . (17)
Here the n n n -th term evaluates F s + n F_{s+n} F s + n on the returned state ∣ L , 0 ⟩ \lvert L,0\rangle ∣ L , 0 ⟩ and weights it by s / ( s + n ) s/(s+n) s / ( s + n ) and the n n n -step termination effect ( K † ) n − 1 B † B K n − 1 (K^\dagger)^{n-1}B^\dagger B K^{n-1} ( K † ) n − 1 B † B K n − 1 .
Finally, taking F = I F=I F = I in (17) as in (12) gives the restricted runtime resolvent family H s H_s H s on H + \mathcal{H}_{+} H + and its expectation h s h_s h s on the initial state ρ 0 = ∣ R , 1 ⟩ ⟨ R , 1 ∣ \rho_0=\lvert R,1\rangle\langle R,1\rvert ρ 0 = ∣ R , 1 ⟩ ⟨ R , 1 ∣ :
H s ≔ Π + H s W a l k ∣ H + = ∑ n ≥ 1 s s + n ( K † ) n − 1 B † B K n − 1 , H_s\mathrel{\mathop{\coloneqq}}\left.\Pi_{+}H_s^{\mathrm{Walk}}\right|_{\mathcal{H}_{+}}
=\sum_{n\ge1}\frac{s}{s+n}(K^\dagger)^{n-1}B^\dagger B K^{n-1}, H s : = Π + H s Walk H + = n ≥ 1 ∑ s + n s ( K † ) n − 1 B † B K n − 1 ,
h s ≔ tr ( ρ 0 H s ) = ∑ n ≥ 1 s s + n ∥ B K n − 1 ∣ R , 1 ⟩ ∥ 2 . (18) h_s\mathrel{\mathop{\coloneqq}}\operatorname{tr}(\rho_0H_s)
=\sum_{n\ge1}\frac{s}{s+n}\left\lVert BK^{n-1}\lvert R,1\rangle\right\rVert^2. \tag*{(18)} h s : = tr ( ρ 0 H s ) = n ≥ 1 ∑ s + n s B K n − 1 ∣ R , 1 ⟩ 2 . (18)
Section E.2 of the supplemental text derives the asymptotic expansion of h s h_s h s , from which § 5 extracts the walk’s runtime properties.
Extracting Termination Probabilities, Moments, and Divergence Rates
Once the calculus has verified the runtime family H S = wp ( S , I ) H^S=\operatorname{wp}(S,I) H S = wp ( S , I ) , this parameterized predicate serves two roles. Within a larger program T ; S T;S T ; S , it can be reused compositionally as the postcondition for the preceding command T T T via the sequencing rule
H T ; S = wp ( T , H S ) . H^{T;S}=\operatorname{wp}(T,H^S). H T ; S = wp ( T , H S ) .
For the top-level program of interest, we use H S H^S H S to answer three operational runtime questions: how likely the program is to terminate, which runtime moments are finite, and how quickly an infinite moment diverges.
To see how H S H^S H S encodes these observables, recall from (12) that
H s S = ∑ n ≥ 0 s s + n E n S . H_s^S=\sum_{n\ge0}\frac{s}{s+n}E_n^S. H s S = n ≥ 0 ∑ s + n s E n S .
In H s S H_s^S H s S , the discount factor s / ( s + n ) s/(s+n) s / ( s + n ) weights each terminating run of duration n n n against the scale s s s while assigning nonterminating runs weight zero. As s → ∞ s\to\infty s → ∞ , each weight s / ( s + n ) s/(s+n) s / ( s + n ) increases to 1 1 1 , so the limit of H s S H_s^S H s S recovers the termination effect Q S Q_S Q S , while its large-s s s behavior encodes the moments and tail behavior of terminating runs. The moment forms M k S = ∑ n ≥ 0 n k E n S M_k^S=\sum_{n\ge0}n^kE_n^S M k S = ∑ n ≥ 0 n k E n S count only terminating runs. To measure the divergence of an infinite moment, we cap the duration counted on each terminating run at N N N and let N N N grow, defining the bounded capped-moment operators
M ~ k S ( N ) ≔ ∑ n ≥ 0 min ( n , N ) k E n S ( k > 0 , N > 0 ) . (19) \widetilde{M}_{k}^{S}(N) \coloneqq\sum_{n \ge0} \min(n,N)^{k} E_{n}^{S} \qquad(k > 0,\ N > 0). \tag*{(19)} M k S ( N ) : = n ≥ 0 ∑ min ( n , N ) k E n S ( k > 0 , N > 0 ) . (19)
For a normalized input state ρ \rho ρ , taking expectations of these operators gives the termination probability and capped moments:
q ≔ tr ( ρ Q S ) = P ρ ( τ S < ∞ ) , c k ( N ) ≔ tr ( ρ M ~ k S ( N ) ) . q \coloneqq\operatorname{tr}(\rho Q_{S}) = \mathbb{P}_{\rho}(\tau_{S} < \infty), \qquad c_{k}(N) \coloneqq\operatorname{tr}\left(\rho\widetilde{M}_{k}^{S}(N)\right). q : = tr ( ρ Q S ) = P ρ ( τ S < ∞ ) , c k ( N ) : = tr ( ρ M k S ( N ) ) .
For q > 0 q > 0 q > 0 , dividing tr ( ρ M k S ) \operatorname{tr}(\rho M_{k}^{S}) tr ( ρ M k S ) or c k ( N ) c_{k}(N) c k ( N ) by q q q gives the corresponding moment conditional on termination. For unconditional properties, nonterminating runs contribute ( 1 − q ) N k (1-q)N^{k} ( 1 − q ) N k to the capped moment, giving E ρ [ min ( τ S , N ) k ] = ( 1 − q ) N k + c k ( N ) \mathbb{E}_{\rho}[\min(\tau_{S},N)^{k}] = (1-q)N^{k} + c_{k}(N) E ρ [ min ( τ S , N ) k ] = ( 1 − q ) N k + c k ( N ) . In particular, q < 1 q < 1 q < 1 implies an infinite unconditional expected runtime; when q = 1 q = 1 q = 1 , that expectation is tr ( ρ M 1 S ) \operatorname{tr}(\rho M_{1}^{S}) tr ( ρ M 1 S ) .
There are two routes to extract these quantities, depending on the available specification (with proofs in Section D of the supplemental text): Table 1 recovers the termination effect Q S Q_{S} Q S and moment forms M k S M_{k}^{S} M k S , and bounds the capped-moment operators M ~ k S ( N ) \widetilde{M}_{k}^{S}(N) M k S ( N ) directly from the exact runtime family H s S H_{s}^{S} H s S , whereas Table 2 reads out the scalar quantities q q q , tr ( ρ M k S ) \operatorname{tr}(\rho M_{k}^{S}) tr ( ρ M k S ) , and c k ( N ) c_{k}(N) c k ( N ) from a certified large-s s s expansion of the expectation tr ( ρ H s S ) \operatorname{tr}(\rho H_{s}^{S}) tr ( ρ H s S ) on an input state.
Table 2.
From the Exact Runtime Family
When an exact expression for the operator family H s S H_{s}^{S} H s S is available, it supports all three checks in Table 1. While the s → ∞ s \to\infty s → ∞ limit in the first row directly recovers Q S Q_{S} Q S , extracting higher moments requires isolating powers of n n n from the rational weights s / ( s + n ) s/(s+n) s / ( s + n ) . To do so, the second and third rows combine Q S Q_{S} Q S with H s S H_{s}^{S} H s S at the rescaled parameters s , s / 2 , … , s / k s,s/2,\ldots,s/k s , s /2 , … , s / k to form a k k k -th order finite-difference operator B k S ( s ) B_{k}^{S}(s) B k S ( s ) , which recovers M k S M_{k}^{S} M k S as s → ∞ s \to\infty s → ∞ and bounds the capped-moment operator M ~ k S ( N ) \widetilde{M}_{k}^{S}(N) M k S ( N ) up to constant factors when evaluated at s = N s=N s = N .
Table 1. Three runtime properties from an exact verified family. Here ρ \rho ρ is a normalized input, q = tr ( ρ Q S ) q = \operatorname{tr}(\rho Q_{S}) q = tr ( ρ Q S ) , and k ≥ 1 k \ge1 k ≥ 1 is an integer. Conditional quantities require q > 0 q > 0 q > 0 .
The mechanism unifying the second and third rows of Table 1 comes from expanding H s / j S H^{S}_{s/j} H s / j S in the definition of B k S ( s ) B^{S}_{k}(s) B k S ( s ) : partial-fraction cancellation turns this alternating linear combination into a positive series with a smooth cutoff weight:
B k S ( s ) = ∑ n ≥ 0 n k ( ∏ j = 1 k s s + j n ) E n S . B^{S}_{k}(s)=\sum_{n\ge0}n^{k}\left(\prod_{j=1}^{k}\frac{s}{s+jn}\right)E^{S}_{n}. B k S ( s ) = n ≥ 0 ∑ n k ( j = 1 ∏ k s + j n s ) E n S .
For short runs (n ≪ s n\ll s n ≪ s ), the product weight is close to 1, so the runtime weight behaves like n k n^{k} n k ; for long runs (n ≫ s n\gg s n ≫ s ), the k k k denominators damp n k n^{k} n k and cap the weight at ≈ s k / k ! \approx s^{k}/k! ≈ s k / k ! . Consequently, B k S ( s ) B^{S}_{k}(s) B k S ( s ) acts as a smooth counterpart to the hard cutoff min ( n , s ) k \min(n,s)^{k} min ( n , s ) k : as s → ∞ s\to\infty s → ∞ , it increases monotonically to the k k k -th moment form M k S M^{S}_{k} M k S , while setting s = N s=N s = N directly approximates the capped-moment operator M ~ k S ( N ) \widetilde{M}^{S}_{k}(N) M k S ( N ) . For any input ρ \rho ρ , the moment tr ( ρ M k S ) = lim s → ∞ tr ( ρ B k S ( s ) ) \operatorname{tr}(\rho M^{S}_{k})=\lim_{s\to\infty}\operatorname{tr}(\rho B^{S}_{k}(s)) tr ( ρ M k S ) = lim s → ∞ tr ( ρ B k S ( s )) is finite if and only if tr ( ρ B k S ( s ) ) \operatorname{tr}(\rho B^{S}_{k}(s)) tr ( ρ B k S ( s )) remains bounded.
From an Asymptotic Expansion
In practice, extracting properties on a fixed normalized input state ρ \rho ρ does not require closed-form operator limits: it suffices to expand the scalar expectation h s ≔ tr ( ρ H s S ) h_{s}\coloneqq\operatorname{tr}(\rho H^{S}_{s}) h s : = tr ( ρ H s S ) as s → ∞ s\to\infty s → ∞ . Moreover, when a candidate loop specification with a known large-s s s expansion is certified in operator norm via § 4.2 , it transfers the same error bound to h s h_{s} h s on every input. Table 2 shows how successive terms in the expansion of h s h_{s} h s recover the three runtime properties, with the target property dictating the remainder accuracy required from the certificate: the leading constant gives q q q , the coefficients of ( − s ) − j (-s)^{-j} ( − s ) − j give the finite moments, and logarithmic or fractional-power remainders determine the divergence rate of the next moment.
Table 2 . Three runtime properties from a verified asymptotic expansion. Here k ≥ 1 k\ge1 k ≥ 1 is an integer, and all expansions are as s → ∞ s\to\infty s → ∞ . Conditional quantities require q > 0 q>0 q > 0 .
Table 1 (PDF p. 15).
The mechanism behind Table 2 comes from the finite geometric expansion of the discount weight: for every integer k ≥ 1 k\ge1 k ≥ 1 and all n ≥ 0 n\ge0 n ≥ 0 ,
s s + n = ∑ j = 0 k − 1 ( − 1 ) j n j s j + ( − 1 ) k s k s n k s + n . \frac{s}{s+n}=\sum_{j=0}^{k-1}\frac{(-1)^j n^j}{s^j}+\frac{(-1)^k}{s^k}\frac{sn^k}{s+n}. s + n s = j = 0 ∑ k − 1 s j ( − 1 ) j n j + s k ( − 1 ) k s + n s n k .
Summing this identity against tr ( ρ E n S ) \operatorname{tr}(\rho E_n^S) tr ( ρ E n S ) accounts for all three rows in turn. Whenever the first k − 1 k-1 k − 1 moments are finite, a 0 = q a_0=q a 0 = q and a j = tr ( ρ M j S ) a_j=\operatorname{tr}(\rho M_j^S) a j = tr ( ρ M j S ) appear as the polynomial coefficients of ( − s ) − j (-s)^{-j} ( − s ) − j up to order s − ( k − 1 ) s^{-(k-1)} s − ( k − 1 ) , leaving the order-s − k s^{-k} s − k remainder factor in the third row:
f ( s ) = ∑ n ≥ 0 s n k s + n tr ( ρ E n S ) . f(s)=\sum_{n\ge0}\frac{sn^k}{s+n}\operatorname{tr}(\rho E_n^S). f ( s ) = n ≥ 0 ∑ s + n s n k tr ( ρ E n S ) .
Here the weight s n k / ( s + n ) sn^k/(s+n) s n k / ( s + n ) behaves like n k n^k n k for n ≤ s n\le s n ≤ s and is damped to ≤ s n k − 1 \le sn^{k-1} ≤ s n k − 1 for n > s n>s n > s . As s → ∞ s\to\infty s → ∞ , f ( s ) f(s) f ( s ) increases monotonically to tr ( ρ M k S ) \operatorname{tr}(\rho M_k^S) tr ( ρ M k S ) , so the k k k -th moment is finite if and only if f ( s ) f(s) f ( s ) remains bounded. When the k k k -th moment is infinite, f ( s ) f(s) f ( s ) diverges as s → ∞ s\to\infty s → ∞ ; in the logarithmic and fractional-power regimes of Table 2 , its growth rate at scale s = N s=N s = N directly determines the divergence rate of the capped moment c k ( N ) c_k(N) c k ( N ) .
In the logarithmic and fractional-power cases, the parameter α \alpha α in the third row is called the critical moment order because it governs the power-law tail of terminating runs: P ρ ( N < τ S < ∞ ) = Θ ( N − α ) P_{\rho}(N < \tau_S < \infty) = \Theta(N^{-\alpha}) P ρ ( N < τ S < ∞ ) = Θ ( N − α ) . Consequently, α \alpha α marks the exact threshold for moment finiteness: for every real moment order k > 0 k > 0 k > 0 , runtime moments tr ( ρ M k S ) \operatorname{tr}(\rho M_k^S) tr ( ρ M k S ) are finite if and only if 0 < k < α 0 < k < \alpha 0 < k < α , whereas the capped moment c k ( N ) c_k(N) c k ( N ) grows as Θ ( log N ) \Theta(\log N) Θ ( log N ) at the boundary k = α k = \alpha k = α and as Θ ( N k − α ) \Theta(N^{k-\alpha}) Θ ( N k − α ) for k > α k > \alpha k > α .
Running example: extracting the Hadamard walk’s runtime properties. For the Hadamard walk on input ρ = ∣ R , 1 ⟩ ⟨ R , 1 ∣ \rho= \lvert R,1\rangle\langle R,1\rvert ρ = ∣ R , 1 ⟩ ⟨ R , 1 ∣ , § 4 derived the runtime family H W a l k H^{\mathrm{Walk}} H Walk by the program rules. Starting from the explicit actions of B B B and K K K on the basis states given there, Section E.2 of the supplemental text evaluates the trace in (18) using elementary linear algebra, combinatorial identities, and calculus, obtaining
h s = tr ( ρ H s W a l k ) = 2 π − 1 s + 2 log s π s 2 + O ( s − 2 ) . (20) h_s = \operatorname{tr}(\rho H_s^{\mathrm{Walk}}) = \frac{2}{\pi} - \frac{1}{s} + \frac{2\log s}{\pi s^2} + O(s^{-2}). \tag*{(20)} h s = tr ( ρ H s Walk ) = π 2 − s 1 + π s 2 2 log s + O ( s − 2 ) . (20)
Combined with the compositional calculus, these explicit calculations suggest a route to automated runtime reasoning using computer algebra systems such as Mathematica or Maple. Applying the three rows of Table 2 recovers the runtime properties from § 2.1 :
Termination probability. The constant term gives q = 2 / π q = 2/\pi q = 2/ π and divergence probability 1 − 2 / π 1 - 2/\pi 1 − 2/ π .
Conditional mean runtime. The coefficient of − s − 1 -s^{-1} − s − 1 gives tr ( ρ M 1 W a l k ) = 1 \operatorname{tr}(\rho M_1^{\mathrm{Walk}}) = 1 tr ( ρ M 1 Walk ) = 1 , so E ρ [ τ ∣ τ < ∞ ] = 1 / q = π / 2 \mathbb{E}_{\rho}[\tau\mid\tau< \infty] = 1/q = \pi/2 E ρ [ τ ∣ τ < ∞ ] = 1/ q = π /2 . Since q < 1 q < 1 q < 1 , the unconditional expected runtime is infinite.
Divergence rate. At order k = 2 k = 2 k = 2 , the remainder is f ( s ) = ( 2 / π ) log s + O ( 1 ) f(s) = (2/\pi)\log s + O(1) f ( s ) = ( 2/ π ) log s + O ( 1 ) . Hence
c 2 ( N ) = 2 π log N + O ( 1 ) , E ρ [ min ( τ , N ) 2 ∣ τ < ∞ ] = log N + O ( 1 ) . c_2(N) = \frac{2}{\pi}\log N + O(1), \qquad\mathbb{E}_{\rho}[\min(\tau,N)^2 \mid\tau< \infty] = \log N + O(1). c 2 ( N ) = π 2 log N + O ( 1 ) , E ρ [ min ( τ , N ) 2 ∣ τ < ∞ ] = log N + O ( 1 ) .
The critical moment order is α = 2 \alpha= 2 α = 2 : conditional moments are finite exactly for 0 < k < 2 0 < k < 2 0 < k < 2 , and the terminating tail is P ρ ( N < τ < ∞ ) = Θ ( N − 2 ) P_{\rho}(N < \tau< \infty) = \Theta(N^{-2}) P ρ ( N < τ < ∞ ) = Θ ( N − 2 ) .
Case Studies
Up to this point, our running example has focused on a single program instance: the Hadamard walk started in a fixed state. In practice, however, analyzing one fixed configuration of a quantum loop is rarely an end in itself. Once we can establish a loop’s runtime behavior, we want to use that analysis in two further ways: to understand how the behavior changes when we adjust the program’s parameters or inputs, and to reason about larger programs that invoke the loop as a subroutine. This section demonstrates both uses and shows how they fit together, using the scalar evaluations in Section E of the supplemental text as mathematical oracles.
First, § 6.1 examines how the absorbing walk behaves when we replace the symmetric Hadamard coin with a biased coin and allow an arbitrary initial coin state. Moving from a single instance to this parameterized family shows which aspects of the runtime behavior are structural to the loop and which depend on the configuration, clarifying how the coin bias and initial state govern the resulting runtime properties. Second, § 6.2 turns to the nested program from Figure 2 , where an outer loop repeatedly resets the registers and invokes the walk. Here the verified specification of the inner walk becomes a building block for analyzing its caller, allowing us to determine the outer loop’s termination probability and conditional expected runtime without re-examining the inner walk’s lattice operators. Finally, these two studies connect directly: when the inner Hadamard walk is replaced by the biased walk, the results of § 6.1 plug straight into the outer proof of § 6.2 to establish the runtime properties of the modified caller.
Changing the Coin
Let L p L_p L p be the program obtained from Walk by replacing its Hadamard coin with
C p = ( p 1 − p 1 − p − p ) , 0 < p < 1. C_p = \begin{pmatrix} \sqrt{p} & \sqrt{1-p} \\ \sqrt{1-p} & -\sqrt{p} \end{pmatrix}, \qquad0 < p < 1. C p = ( p 1 − p 1 − p − p ) , 0 < p < 1.
The guard and conditional shift remain the same. We verify the termination probability, conditional mean, and growth of the capped second moment for an arbitrary normalized coin state ρ \rho ρ at position 1.
Program reduction. The backward derivation in § 4 applies with U p = V ( C p ⊗ I ) U_p = V(C_p \otimes I) U p = V ( C p ⊗ I ) , B p = Π 0 U p ∣ H + B_p = \Pi_0 U_p|_{\mathcal{H}_+} B p = Π 0 U p ∣ H + , and K p = Π + U p ∣ H + K_p = \Pi_+ U_p|_{\mathcal{H}_+} K p = Π + U p ∣ H + . In particular, the unitary and sequencing rules give the body transformer X s ↦ U p † X s U p X_s \mapsto U_p^\dagger X_s U_p X s ↦ U p † X s U p , and the loop rule gives the same recurrence with these operators. Writing H p , s H_{p,s} H p , s for the compression of wp ( L p , I ) s \operatorname{wp}(L_p,I)_s wp ( L p , I ) s to H + \mathcal{H}_+ H + , we obtain the scalar calculation target
h ρ ( s ) ≜ tr ( ( ρ ⊗ ∣ 1 ⟩ ⟨ 1 ∣ ) H p , s ) = ∑ n ≥ 1 s s + n tr ( ( ρ ⊗ ∣ 1 ⟩ ⟨ 1 ∣ ) ( K p † ) n − 1 B p † B p K p n − 1 ) . (21) h_\rho(s) \triangleq\operatorname{tr}\bigl((\rho\otimes|1\rangle\langle1|)H_{p,s}\bigr) = \sum_{n \ge1} \frac{s}{s+n}\operatorname{tr}\bigl((\rho\otimes|1\rangle\langle1|)(K_p^\dagger)^{n-1}B_p^\dagger B_pK_p^{n-1}\bigr). \tag*{(21)} h ρ ( s ) ≜ tr ( ( ρ ⊗ ∣1 ⟩ ⟨ 1∣ ) H p , s ) = n ≥ 1 ∑ s + n s tr ( ( ρ ⊗ ∣1 ⟩ ⟨ 1∣ ) ( K p † ) n − 1 B p † B p K p n − 1 ) . (21)
Mathematical oracle. At this point, program reasoning hands off a pure scalar analysis problem: given the explicit operators B p , K p B_p,K_p B p , K p and initial coin state ρ \rho ρ , evaluate the series (21) as s → ∞ s \to\infty s → ∞ . Section E.3 of the supplemental text discharges this obligation using Legendre polynomial identities (Theorem E.5 of the supplemental text), yielding
h ρ ( s ) = q ρ − 1 s + λ ρ log s s 2 + O ( s − 2 ) , (22) h_\rho(s) = q_\rho- \frac{1}{s} + \frac{\lambda_\rho\log s}{s^2} + O(s^{-2}), \tag*{(22)} h ρ ( s ) = q ρ − s 1 + s 2 λ ρ log s + O ( s − 2 ) , (22)
where, with v − = 1 − p ∣ L ⟩ − p ∣ R ⟩ v_- = \sqrt{1-p}|L\rangle- \sqrt{p}|R\rangle v − = 1 − p ∣ L ⟩ − p ∣ R ⟩ ,
β ρ ≜ ⟨ v − ∣ ρ ∣ v − ⟩ , q ρ ≜ 1 − ( 1 − κ p ) β ρ , λ ρ ≜ 4 β ρ π δ , \beta_\rho\triangleq\langle v_-|\rho|v_-\rangle, \qquad q_\rho\triangleq1-(1-\kappa_p)\beta_\rho, \qquad\lambda_\rho\triangleq\frac{4\beta_\rho}{\pi\delta}, β ρ ≜ ⟨ v − ∣ ρ ∣ v − ⟩ , q ρ ≜ 1 − ( 1 − κ p ) β ρ , λ ρ ≜ π δ 4 β ρ ,
χ ≜ 1 − 2 p , δ ≜ 2 p ( 1 − p ) , κ p ≜ 4 π ( δ + χ arcsin χ ) − 1 − χ 2 δ 2 . \chi\triangleq1-2p, \qquad\delta\triangleq2\sqrt{p(1-p)}, \qquad\kappa_p \triangleq\frac{\frac{4}{\pi}(\delta+\chi\arcsin\chi)-1-\chi^2}{\delta^2}. χ ≜ 1 − 2 p , δ ≜ 2 p ( 1 − p ) , κ p ≜ δ 2 π 4 ( δ + χ arcsin χ ) − 1 − χ 2 .
Here 0 < κ p < 1 0 < \kappa_p < 1 0 < κ p < 1 .
Verified runtime properties. Applying Table 2 to (22) , with τ \tau τ the runtime on ρ ⊗ ∣ 1 ⟩ ⟨ 1 ∣ \rho\otimes|1\rangle\langle1| ρ ⊗ ∣1 ⟩ ⟨ 1∣ , yields
P ( τ < ∞ ) = q ρ , E [ τ ∣ τ < ∞ ] = 1 q ρ , \mathbb{P}(\tau< \infty) = q_\rho, \qquad\mathbb{E}[\tau\mid\tau< \infty] = \frac{1}{q_\rho}, P ( τ < ∞ ) = q ρ , E [ τ ∣ τ < ∞ ] = q ρ 1 ,
E [ min ( τ , N ) 2 ∣ τ < ∞ ] = λ ρ q ρ log N + O ( 1 ) ( β ρ > 0 ) . (23) \mathbb{E}[\min(\tau,N)^2 \mid\tau< \infty] = \frac{\lambda_\rho}{q_\rho}\log N + O(1) \qquad(\beta_\rho> 0). \tag*{(23)} E [ min ( τ , N ) 2 ∣ τ < ∞ ] = q ρ λ ρ log N + O ( 1 ) ( β ρ > 0 ) . (23)
For β ρ > 0 \beta_\rho> 0 β ρ > 0 , the unconditional mean is infinite and the conditional moments are finite exactly for orders 0 < r < 2 0 < r < 2 0 < r < 2 . If β ρ = 0 \beta_\rho= 0 β ρ = 0 , the coin sends the input directly toward the origin and τ = 1 \tau= 1 τ = 1 almost surely. For the original input ρ = ∣ R ⟩ ⟨ R ∣ \rho= |R\rangle\langle R| ρ = ∣ R ⟩ ⟨ R ∣ , we have β ρ = p \beta_\rho= p β ρ = p ; setting p = 1 / 2 p = 1/2 p = 1/2 recovers q ρ = 2 / π q_\rho= 2/\pi q ρ = 2/ π and λ ρ = 2 / π \lambda_\rho= 2/\pi λ ρ = 2/ π .
Reusing the Walk Inside an Outer Loop
We now verify the caller from Figure 2 . Each continuing outer iteration resets the registers and invokes Walk; the next outer test is reached only if that invocation terminates. The verification targets are the caller’s termination probability and conditional expected runtime, counting entries into both loop bodies. We derive both quantities modularly from the inner walk’s verified specification (20) , without unfolding Walk or re-analyzing its lattice operators (full details in Section F of the supplemental text).
Reuse the initialized walk’s specification. Let Init denote the two reset commands in Figure 4 and put σ = ∣ R , 1 ⟩ ⟨ R , 1 ∣ \sigma= \lvert R,1\rangle\langle R,1\rvert σ = ∣ R , 1 ⟩ ⟨ R , 1 ∣ . Each reset is implemented by initialization followed by a fixed unitary. Together they prepare σ \sigma σ from every normalized input, so its backward action on any parameterized predicate G G G is wp ( I n i t , G ) s = tr ( σ G s ) I \operatorname{wp}(\mathrm{Init},G)_s = \operatorname{tr}(\sigma G_s)I wp ( Init , G ) s = tr ( σ G s ) I . The sequencing rule therefore gives, for every postcondition F F F ,
Figure 4. The nested program. The measurement M o u t M^{\mathrm{out}} M out implements randomBit() in Figure 2 : each test exits or continues with probability 1 / 2 1/2 1/2 , leaving the registers unchanged. A terminating call of duration n n n contributes 1 + n 1+n 1 + n to the total runtime, including entry into the outer body.
wp ( S , F ) s = wp ( I n i t , wp ( W a l k , F ) ) s = tr ( σ wp ( W a l k , F ) s ) I . (24) \operatorname{wp}(S,F)_s=\operatorname{wp}(\mathrm{Init},\operatorname{wp}(\mathrm{Walk},F))_s=\operatorname{tr}\left(\sigma\operatorname{wp}(\mathrm{Walk},F)_s\right)I. \tag*{(24)} wp ( S , F ) s = wp ( Init , wp ( Walk , F ) ) s = tr ( σ wp ( Walk , F ) s ) I . (24)
In particular, taking F = I F=I F = I reuses the Hadamard runtime family:
H s S = h s I , h s = q − 1 s + o ( s − 1 ) , q = 2 π . (25) H^S_s=h_sI,\qquad h_s=q-\frac{1}{s}+o(s^{-1}),\qquad q=\frac{2}{\pi}. \tag*{(25)} H s S = h s I , h s = q − s 1 + o ( s − 1 ) , q = π 2 . (25)
The scalar expansion is the mathematical oracle result (20) , used here only through first order. Equation (24) turns that input-specific calculation into a specification for S S S on its full state space.
Derive the outer loop equation. Let X X X describe the remaining execution from the outer guard. The exit branch contributes I / 2 I/2 I /2 . The continuing branch charges one iteration, propagates X X X backward through S S S at scale s + 1 s+1 s + 1 , and has weight 1 / 2 1/2 1/2 . Substitution into the loop rule gives
( T X ) s = 1 2 I ⏟ exit + s 2 ( s + 1 ) wp ( S , X ) s + 1 ⏟ continue , H L = lfp T . (26) (\mathcal{T}X)_s=\underbrace{\frac{1}{2}I}_{\text{exit}}+\underbrace{\frac{s}{2(s+1)}\operatorname{wp}(S,X)_{s+1}}_{\text{continue}},\qquad H^L=\operatorname{lfp}\mathcal{T}. \tag*{(26)} ( T X ) s = exit 2 1 I + continue 2 ( s + 1 ) s wp ( S , X ) s + 1 , H L = lfp T . (26)
The subprogram’s transformer accounts for all inner iterations; the factor s / ( s + 1 ) s/(s+1) s / ( s + 1 ) accounts for the additional outer iteration.
Set the approximation goal. Computing an exact solution of (26) directly is not easy. However, for termination probability and conditional mean, Table 2 only needs the constant and first-order coefficients of tr ( ρ H s L ) \operatorname{tr}(\rho H^L_s) tr ( ρ H s L ) . We therefore seek a parameterized predicate A A A that approximates H L H^L H L in operator norm with error o ( s − 1 ) o(s^{-1}) o ( s − 1 ) .
Theorem 4.5 reduces this approximation goal to a check of one outer iteration. Its same-order error bound applies because the fair outer guard supplies a uniform contraction: since H u + 1 S ≤ I H^S_{u+1}\leq I H u + 1 S ≤ I ,
u u + 1 ( M 1 o u t ) † H u + 1 S M 1 o u t = u 2 ( u + 1 ) H u + 1 S ≤ 1 2 I ( u > 0 ) . \frac{u}{u+1}(M^{\mathrm{out}}_1)^\dagger H^S_{u+1}M^{\mathrm{out}}_1=\frac{u}{2(u+1)}H^S_{u+1}\leq\frac{1}{2}I\qquad(u>0). u + 1 u ( M 1 out ) † H u + 1 S M 1 out = 2 ( u + 1 ) u H u + 1 S ≤ 2 1 I ( u > 0 ) .
Thus, with κ = 1 / 2 \kappa=1/2 κ = 1/2 , it suffices to find A A A satisfying
∥ A s − ( T A ) s ∥ = o ( s − 1 ) . (27) \lVert A_s-(\mathcal{T}A)_s\rVert=o(s^{-1}). \tag*{(27)} ∥ A s − ( T A ) s ∥ = o ( s − 1 ) . (27)
The theorem then controls the accumulated error over the whole outer loop.
Construct and certify the approximation. To meet this goal, we look for a parameterized predicate with adjustable constant and first-order coefficients whose precondition through S S S can be computed from the verified inner family H S H^{S} H S . We use the rational template
A s ≔ s s + b I = ( a − a b s + O ( s − 2 ) ) I , 0 < a ≤ 1 , b > 0. (28) A_s \coloneqq\frac{s}{s+b}I = \left(a-\frac{ab}{s}+O(s^{-2})\right)I,\qquad0<a\leq1,\quad b>0. \tag*{(28)} A s : = s + b s I = ( a − s ab + O ( s − 2 ) ) I , 0 < a ≤ 1 , b > 0. (28)
It provides these two coefficients and stays in the predicate domain at every scale. Its backward propagation reuses H S H^{S} H S at a shifted scale: by the graded weakest-precondition rule,
wp ( S , A ) s = ∑ n ≥ 0 s s + n ⟦ S ⟧ n ( s + n s + n + b I ) = a s s + b H s + b S = a s s + b h s + b I . (29) \begin{aligned}
\operatorname{wp}(S,A)_s=\sum_{n\geq0}\frac{s}{s+n}\llbracket S\rrbracket_n\left(\frac{s+n}{s+n+b}I\right) \\
&=a\frac{s}{s+b}H^{S}_{s+b}=a\frac{s}{s+b}h_{s+b}I. \tag*{(29)}
\end{aligned} wp ( S , A ) s = n ≥ 0 ∑ s + n s [ [ S ] ] n ( s + n + b s + n I ) = a s + b s H s + b S = a s + b s h s + b I . (29)
Each inner duration n n n selects the continuation at scale s + n s+n s + n ; the rational template collects all these shifted continuations into one evaluation of H S H^{S} H S at s + b s+b s + b . The identity in terms of H S H^{S} H S applies to any subprogram with a known runtime family.
Substituting this call precondition at scale s + 1 s+1 s + 1 into (26) gives
( T A ) s = [ 1 2 + a 2 s s + 1 + b h s + 1 + b ] I . (30) (\mathcal{T}A)_s=\left[\frac{1}{2}+\frac{a}{2}\frac{s}{s+1+b}h_{s+1+b}\right]I. \tag*{(30)} ( T A ) s = [ 2 1 + 2 a s + 1 + b s h s + 1 + b ] I . (30)
The program rules have now reduced the residual check to a scalar calculation using the inner expansion (25) . Matching the constant and s − 1 s^{-1} s − 1 coefficients of (30) with those of A s A_s A s gives
a = 1 2 − q , b = 1 + q 2 − q . (31) a=\frac{1}{2-q},\qquad b=\frac{1+q}{2-q}. \tag*{(31)} a = 2 − q 1 , b = 2 − q 1 + q . (31)
These values satisfy 0 < a < 1 0<a<1 0 < a < 1 and b > 0 b>0 b > 0 , and make the residual meet (27) . Theorem 4.5 therefore certifies
∥ H s L − A s ∥ = o ( s − 1 ) , H s L = ( a − a b s ) I + o ( s − 1 ) . (32) \lVert H^{L}_s-A_s\rVert=o(s^{-1}),\qquad H^{L}_s=\left(a-\frac{ab}{s}\right)I+o(s^{-1}). \tag*{(32)} ∥ H s L − A s ∥ = o ( s − 1 ) , H s L = ( a − s ab ) I + o ( s − 1 ) . (32)
Extract the caller’s runtime properties. For every normalized input state ρ \rho ρ , taking the expectation of (32) gives tr ( ρ H s L ) = a − a b / s + o ( s − 1 ) \operatorname{tr}(\rho H^{L}_s)=a-ab/s+o(s^{-1}) tr ( ρ H s L ) = a − ab / s + o ( s − 1 ) . The first two rows of Table 2 give the termination probability a a a and conditional mean a b / a = b ab/a=b ab / a = b :
P ρ ( τ L < ∞ ) = a = 1 2 − q = π 2 ( π − 1 ) , \mathbb{P}_{\rho}(\tau_L<\infty)=a=\frac{1}{2-q}=\frac{\pi}{2(\pi-1)}, P ρ ( τ L < ∞ ) = a = 2 − q 1 = 2 ( π − 1 ) π ,
E ρ [ τ L ∣ τ L < ∞ ] = b = 1 + q 2 − q = π + 2 2 ( π − 1 ) . (33) \mathbb{E}_{\rho}[\tau_L\mid\tau_L<\infty]=b=\frac{1+q}{2-q}=\frac{\pi+2}{2(\pi-1)}. \tag*{(33)} E ρ [ τ L ∣ τ L < ∞ ] = b = 2 − q 1 + q = 2 ( π − 1 ) π + 2 . (33)
The caller may terminate before invoking S S S , which increases its termination probability from q q q to a a a . It still has positive divergence probability, so its unconditional expected runtime is infinite.
Because the outer proof depends on Walk only through the first-order expansion (25) , replacing Walk with the biased walk L p L_p L p (reset to ∣ R , 1 ⟩ \lvert R,1\rangle ∣ R , 1 ⟩ ) simply updates the inner termination probability in (25) to q = 1 − p + p κ p q=1-p+p\kappa_p q = 1 − p + p κ p . Substituting this q q q into (31) immediately yields the new caller’s termination probability a a a and conditional mean b b b , reusing the entire outer derivation and certificate unchanged.
Related Work
Quantum program verification. Quantum weakest preconditions, Hoare logics, and operator-based verification provide the foundations for reasoning about quantum programs [17 , 50 , 53 ] . Termination analyses cover quantum loops, concurrent and nondeterministic programs, ranking-supermartingale synthesis, and scheduler construction [35 , 36 , 49 , 51 , 58 ] . Related work on quantum Markov chains and decision processes studies reachability probabilities, recursion, and long-run behavior [19 , 20 , 23 , 54 , 55 ] , while quantum automata and temporal logics support verification of linear-time properties [52 , 57 ] . Our calculus connects termination probability and runtime information in specifications that compose through sequential calls and nested loops.
Quantum runtime analysis. Avanzini et al. [4 ] and Liu et al. [37 ] develop compositional expectation transformers for quantum costs and expected runtimes. The former uses finite-dimensional quantum registers with potentially unbounded classical variables; the latter includes quantum integers in its state-based semantics, while its observable-based computational methods specialize to finite dimensions. Yu [56 ] reduces flowchart programs to a single loop while preserving expected runtime, variance, and general moments, and gives algorithms for termination and exact expected runtime. Unbounded pre-expectations [21 ] and closed positive quadratic forms [59 ] extend cost reasoning to infinite-dimensional systems. Our bounded parameterized predicates retain information when the expected cost is infinite and yield termination probabilities, conditional moments, and capped-moment divergence rates. The resolvent translation Theorem 3.4 also lets existing total-cost proofs supply specifications in this domain.
Probabilistic termination and runtime distributions. Classical expectation transformers support compositional reasoning about probabilities and expected runtimes [27 , 40 ] . Martingale and lexicographic methods establish almost-sure termination and support automated certificate synthesis [1 , 7 , 10 , 41 ] . Quantitative analyses derive expected-time and tail bounds [8 ] , termination-probability bounds [9 , 11 ] , and inductive lower bounds on expectations and runtimes [26 ] . Higher-moment methods bound runtime moments, variances, and central moments [33 , 48 ] . Generating-function approaches retain distributions and support symbolic verification, conditioning, and invariant synthesis [12 , 24 , 28 , 29 ] . These approaches provide precedents for combining program rules with symbolic mathematical calculations. Our calculus propagates quantum postconditions and elapsed time together through scale-shifted predicate families. Its loop uniqueness and residual bounds certify asymptotic specifications from which conditional moments and their divergence rates can be extracted, including for programs with positive nontermination probability.
Quantum walks and absorption. Quantum walks have been studied as dynamical processes and computational primitives [2 , 3 , 14 , 15 ] . Analyses of absorbing boundaries and measured hitting times establish hitting probabilities, conditional timing properties, and examples with infinite hitting times [5 , 30 , 31 , 32 ] . These results supply the mathematical setting and verification targets for our examples. Our program rules derive the trace series whose scalar asymptotics establish reusable runtime specifications; the nested-loop example then applies such a specification in a caller’s proof.
Quantum-walk circuits and formal verification. Circuit constructions analyze the resources needed to implement walk evolution on various graphs, including Fourier-transform and Szegedy implementations [18 , 38 , 39 , 42 , 44 ] . Their resource measures concern a prescribed evolution, whereas our runtime counts iterations until a measurement causes the loop to terminate. Formal-verification work establishes relational properties of absorbing walks on finite intervals [6 ] and verifies walk algorithms in Qafny and QafnyC [13 , 34 ] . Our case studies verify absorption on the unbounded integer lattice, including arbitrarily long terminating runs, and reuse the resulting specifications through program composition.
Conclusion
This paper shows that bounded parameterized predicates can retain detailed information about runtime, even when runtime moments are infinite. The observation scale serves as the parameter that stores this information: finite moments appear as coefficients in an asymptotic expansion, and infinite moments reveal themselves through the rate at which capped moments grow. The weakest-precondition rules propagate these parameterized predicates through program syntax, so a verified specification of a loop can be reused when that loop is called by a larger program. We demonstrated this on the absorbing Hadamard walk and on an outer loop that repeatedly invokes it.
A natural next step is to automate the construction of these specifications. Predicate templates and symbolic calculations could generate candidate families, and the uniqueness and residual theorems provide the checks needed to certify them.
AI Use
During this work, the authors used GPT-6 Astra as an interactive assistant. It was used to assist with proof review and to draft and revise English prose and LaTeX presentation. No generated proof or text was adopted without author verification. The authors retain full responsibility for all content of the paper.
Data-Availability Statement
The appendices have been submitted as Supplementary text but are not yet publicly available to preserve anonymity during the review process. They will be released publicly after the review is completed.
References
Guide to the Supplemental Text
This supplemental text is designed as an extended version of the main paper and can be read independently. It includes the full definitions, proofs, and calculations underlying the main results. Section A introduces the absorbing quantum walk and establishes its infinite expected runtime using an existing cost logic. Section B defines the runtime-graded semantics, parameterized predicates, and semantic validity. Section C develops the compositional weakest-precondition calculus and proves the uniqueness and residual bounds used to certify loop specifications. Section D shows how to extract termination probabilities, runtime moments, and divergence rates from these specifications. Section E applies the framework to Hadamard and biased quantum walks, and Section F reuses the walk’s specification to verify an outer loop that repeatedly invokes it. Finally, Section G shows how total-cost proofs can be translated into proofs over parameterized predicates.
The core development in Sections B–F has been formalized in Lean with assistance from GPT-6 Astra. Sections A and G provide complementary connections to the cost logic of [59 ] and lie outside the paper’s central development. They are not included in the formalization, as formalizing them would require a full formalization of the extensive framework developed in that work.
Furthermore, we provide an illustrative Mathematica script, developed with assistance from GPT-6 Astra, for semi-automatic symbolic evaluation of the scalar sums arising in the absorbing quantum walk example.
Conventions
We write N = { 0 , 1 , 2 , … } \mathbb{N} = \{0, 1, 2, \ldots\} N = { 0 , 1 , 2 , … } and N + = { 1 , 2 , … } \mathbb{N}_{+} = \{1, 2, \ldots\} N + = { 1 , 2 , … } . All Hilbert spaces are complex, and program state spaces are separable. Inner products ⟨ ⋅ , ⋅ ⟩ \langle\cdot, \cdot\rangle ⟨ ⋅ , ⋅ ⟩ are conjugate-linear in the first argument. We write B ( H ) \mathcal{B}(\mathcal{H}) B ( H ) for the algebra of bounded linear operators, T ( H ) \mathcal{T}(\mathcal{H}) T ( H ) for trace-class operators, and [ 0 , I ] H = { A ∈ B ( H ) : 0 ≤ A ≤ I } [0, I]_{\mathcal{H}} = \{A \in\mathcal{B}(\mathcal{H}) : 0 \le A \le I\} [ 0 , I ] H = { A ∈ B ( H ) : 0 ≤ A ≤ I } for the space of quantum effects. Quantum states (partial density operators) are positive trace-class operators ρ ∈ T ( H ) \rho\in\mathcal{T}(\mathcal{H}) ρ ∈ T ( H ) with tr ( ρ ) ≤ 1 \operatorname{tr}(\rho) \le1 tr ( ρ ) ≤ 1 ; conditional probabilities and conditional moments are stated for normalized states (tr ( ρ ) = 1 \operatorname{tr}(\rho) = 1 tr ( ρ ) = 1 ). The Heisenberg adjoint Φ † : B ( K ) → B ( H ) \Phi^{\dagger} : \mathcal{B}(\mathcal{K}) \to\mathcal{B}(\mathcal{H}) Φ † : B ( K ) → B ( H ) of a bounded linear map Φ : T ( H ) → T ( K ) \Phi: \mathcal{T}(\mathcal{H}) \to\mathcal{T}(\mathcal{K}) Φ : T ( H ) → T ( K ) is defined by trace duality tr ( Φ † ( A ) ρ ) = tr ( A Φ ( ρ ) ) \operatorname{tr}(\Phi^{\dagger}(A)\rho) = \operatorname{tr}(A\Phi(\rho)) tr ( Φ † ( A ) ρ ) = tr ( A Φ ( ρ )) .
Positive quadratic forms P : H → [ 0 , ∞ ] P : \mathcal{H} \to[0,\infty] P : H → [ 0 , ∞ ] take the value + ∞ +\infty + ∞ outside their finite domain Dom ( P ) \operatorname{Dom}(P) Dom ( P ) , with the convention 0 ⋅ ∞ = 0 0 \cdot\infty= 0 0 ⋅ ∞ = 0 . For a closed positive form P P P and a positive trace-class operator with spectral decomposition ρ = ∑ j λ j ∣ u j ⟩ ⟨ u j ∣ \rho= \sum_j \lambda_j |u_j\rangle\langle u_j| ρ = ∑ j λ j ∣ u j ⟩ ⟨ u j ∣ , the extended trace is
tr ( P ρ ) = tr ( ρ P ) ≔ ∑ j λ j P [ u j ] ∈ [ 0 , ∞ ] . \operatorname{tr}(P\rho) = \operatorname{tr}(\rho P) \coloneqq\sum_j \lambda_j P[u_j] \in[0,\infty]. tr ( P ρ ) = tr ( ρP ) : = j ∑ λ j P [ u j ] ∈ [ 0 , ∞ ] .
For a bounded positive operator D ≥ 0 D \ge0 D ≥ 0 , ω D \omega_D ω D denotes the closed positive form that vanishes on ker ( D ) \operatorname{ker}(D) ker ( D ) and equals + ∞ +\infty + ∞ on H ∖ ker ( D ) \mathcal{H} \setminus\operatorname{ker}(D) H ∖ ker ( D ) . Uniformly bounded monotone sequences of self-adjoint operators converge in the strong operator topology. Positive operator series are interpreted as monotone suprema of their partial sums in the order of quadratic forms; when the partial sums are uniformly bounded, they also converge strongly. Nonnegative numerical series and integrals are evaluated by monotone convergence, with interchanges justified by Tonelli’s theorem. Runtime is measured by the total number of loop iterations: each time a while guard selects its continuing branch, the count increases by one, with iterations of nested loops added to the same total. Loop exits and all other commands contribute zero. Terminating runtimes lie in N \mathbb{N} N , and nonterminating executions have runtime + ∞ +\infty + ∞ . In moment formulas, n 0 = 1 n^0 = 1 n 0 = 1 for all n ≥ 0 n \ge0 n ≥ 0 . Big-O O O and little-o o o estimates for operator families use the operator norm on the stated space: for g ( s ) > 0 g(s) > 0 g ( s ) > 0 , A s = O ( g ( s ) ) A_s = O(g(s)) A s = O ( g ( s )) means that ∥ A s ∥ / g ( s ) \lVert A_s\rVert/g(s) ∥ A s ∥ / g ( s ) remains bounded as s → ∞ s \to\infty s → ∞ , and A s = o ( g ( s ) ) A_s = o(g(s)) A s = o ( g ( s )) means that this ratio tends to zero. For scalar functions, the norm is replaced by absolute value. Implicit constants in quantum-walk estimates may depend on the fixed coin parameter p ∈ ( 0 , 1 ) p \in(0,1) p ∈ ( 0 , 1 ) .
A Coherent Quantum Walk and Its Infinite Expected Cost
The one-dimensional discrete-time Hadamard walk with an absorbing boundary at x = 0 x = 0 x = 0 is a standard benchmark in quantum computing [5 , 30 ] . Its coherent evolution over an infinite lattice exhibits a rich runtime profile: starting at x = 1 x = 1 x = 1 with coin state ∣ R ⟩ \lvert R\rangle ∣ R ⟩ , it terminates with probability 2 / π ≈ 0.637 2/\pi\approx0.637 2/ π ≈ 0.637 and has infinite unconditional expected runtime, yet its conditional expected runtime given termination is only π / 2 \pi/2 π /2 [30 Section 4] . Its absorption-time tail also gives logarithmic growth of the capped conditional second moment. These properties provide a concrete target for compositional runtime verification of programs that are not almost surely terminating (AST).
Existing quantum runtime analyses provide compositional methods for expected costs, but are restricted to finite-dimensional state spaces [4 , 37 ] and therefore do not cover this coherent infinite-lattice walk. The closed-positive-quadratic-form calculus of [59 ] extends expected-cost reasoning to infinite-dimensional systems and allows us to prove that this walk has infinite expected runtime (Theorem A.2). However, because the expected-cost predicate collapses to + ∞ +\infty + ∞ , it leaves the termination probability, the conditional mean, and the divergence rate of higher moments unresolved. Recovering these quantities compositionally requires moving beyond a single unbounded cost to a parameterized family of bounded runtime predicates, which we introduce at the end of this section and develop systematically in the following sections.
Registers, Commands, and the Runtime Convention
We begin by formulating the absorbing Hadamard walk as a qwhile program over a coin register and an infinite-lattice position register. Restricting each loop iteration to the positive half-line then allows us to express the walk’s runtime distribution directly in terms of its continuing and absorbing operators.
The walk operates on a coin register with state space C 2 = span { ∣ L ⟩ , ∣ R ⟩ } \mathbb{C}^2 = \operatorname{span}\{\lvert L\rangle,\lvert R\rangle\} C 2 = span {∣ L ⟩ , ∣ R ⟩} and a position register with state space ℓ 2 ( Z ) = span { ∣ x ⟩ : x ∈ Z } \ell^2(\mathbb{Z}) = \operatorname{span}\{\lvert x\rangle: x \in\mathbb{Z}\} ℓ 2 ( Z ) = span {∣ x ⟩ : x ∈ Z } ; we write ∣ c , x ⟩ ≡ ∣ c ⟩ ⊗ ∣ x ⟩ \lvert c,x\rangle\equiv\lvert c\rangle\otimes\lvert x\rangle ∣ c , x ⟩ ≡ ∣ c ⟩ ⊗ ∣ x ⟩ for product basis states. As a quantum loop program, the walk is written as
coin := |R⟩; position := |1⟩;
while M[position] = 1 do
coin := C_{1/2}[coin]; (coin,position) := V[coin,position]
od
Here the loop guard M = { M 0 , M 1 } M = \{M_0,M_1\} M = { M 0 , M 1 } tests whether the particle has reached the absorbing boundary at x = 0 x = 0 x = 0 , with termination projector M 0 = Π 0 ≜ I 2 ⊗ ∣ 0 ⟩ ⟨ 0 ∣ M_0 = \Pi_0 \triangleq I_2 \otimes\lvert0\rangle\langle0\rvert M 0 = Π 0 ≜ I 2 ⊗ ∣ 0 ⟩ ⟨ 0 ∣ and continuation projector M 1 = Π ≠ 0 ≜ I − Π 0 M_1 = \Pi_{\ne0} \triangleq I - \Pi_0 M 1 = Π = 0 ≜ I − Π 0 . Each iteration of the loop body applies the Hadamard coin C 1 / 2 C_{1/2} C 1/2 followed by the conditional shift V V V :
C 1 / 2 = 1 2 ( 1 1 1 − 1 ) , V ∣ L , x ⟩ = ∣ L , x − 1 ⟩ , V ∣ R , x ⟩ = ∣ R , x + 1 ⟩ , (34) C_{1/2} = \frac{1}{\sqrt{2}}
\begin{pmatrix}
1 & 1 \\
1 & -1
\end{pmatrix},
\qquad
V\lvert L,x\rangle= \lvert L,x-1\rangle,
\qquad
V\lvert R,x\rangle= \lvert R,x+1\rangle, \tag*{(34)} C 1/2 = 2 1 ( 1 1 1 − 1 ) , V ∣ L , x ⟩ = ∣ L , x − 1 ⟩ , V ∣ R , x ⟩ = ∣ R , x + 1 ⟩ , (34)
so a single unitary step on the full line is U = V ( C 1 / 2 ⊗ I ) U = V(C_{1/2} \otimes I) U = V ( C 1/2 ⊗ I ) .
Because the walk starts at x = 1 x = 1 x = 1 and moves by ± 1 \pm1 ± 1 per step, any state surviving the guard measurement remains supported on the positive half-line H + ≜ C 2 ⊗ ℓ 2 ( N + ) \mathcal{H}_+ \triangleq\mathbb{C}^2 \otimes\ell^2(\mathbb{N}_+) H + ≜ C 2 ⊗ ℓ 2 ( N + ) . Moreover, boundary x = 0 x = 0 x = 0 can only be entered from H + \mathcal{H}_{+} H + by stepping left from x = 1 x = 1 x = 1 , which always lands in the one-dimensional subspace C ∣ L , 0 ⟩ \mathbb{C}|L,0\rangle C ∣ L , 0 ⟩ . Let Π + \Pi_{+} Π + denote the orthogonal projection onto H + \mathcal{H}_{+} H + . Restricted to H + \mathcal{H}_{+} H + , one iteration of the loop is completely characterized by the continuing operator K K K and the absorbing operator B B B :
K = Π + U ∣ H + : H + ⟶ H + , B = Π 0 U ∣ H + : H + ⟶ C ∣ L , 0 ⟩ . (35) K = \left.\Pi_{+}U\right|_{\mathcal{H}_{+}}:\mathcal{H}_{+}\longrightarrow\mathcal{H}_{+}, \qquad B = \left.\Pi_{0}U\right|_{\mathcal{H}_{+}}:\mathcal{H}_{+}\longrightarrow\mathbb{C}|L,0\rangle. \tag*{(35)} K = Π + U ∣ H + : H + ⟶ H + , B = Π 0 U ∣ H + : H + ⟶ C ∣ L , 0 ⟩ . (35)
Since U U U is unitary and maps H + \mathcal{H}_{+} H + into H + ⊕ C ∣ L , 0 ⟩ \mathcal{H}_{+}\oplus\mathbb{C}|L,0\rangle H + ⊕ C ∣ L , 0 ⟩ , these operators satisfy the conservation identity K † K + B † B = I H + K^{\dagger}K+B^{\dagger}B=I_{\mathcal{H}_{+}} K † K + B † B = I H + .
Under our runtime convention, each execution of the loop body incurs one unit of time, so the runtime τ \tau τ counts the number of iterations until absorption at x = 0 x=0 x = 0 . For any initial unit vector u ∈ H + u\in\mathcal{H}_{+} u ∈ H + , the unnormalized surviving state after n n n iterations is K n u K^{n}u K n u , yielding the runtime distribution
P u ( τ > n ) = ∥ K n u ∥ 2 , P u ( τ = n ) = ∥ B K n − 1 u ∥ 2 ( n ≥ 1 ) . (36) \mathbb{P}_{u}(\tau>n)=\lVert K^{n}u\rVert^{2},\qquad\mathbb{P}_{u}(\tau=n)=\lVert BK^{n-1}u\rVert^{2}\qquad(n\geq1). \tag*{(36)} P u ( τ > n ) = ∥ K n u ∥ 2 , P u ( τ = n ) = ∥ B K n − 1 u ∥ 2 ( n ≥ 1 ) . (36)
Expected-Runtime Analysis
We derive the walk’s expected-runtime predicate from its commands, counting one unit per loop iteration. For a post-cost X X X , the unitary rule gives the following exact backward annotations of the loop body, read from bottom to top:
{ ( C 1 2 † ⊗ I ) ( V † X V ) ( C 1 2 ⊗ I ) } \left\{\left(C_{\frac{1}{2}}^{\dagger}\otimes I\right)\left(V^{\dagger}XV\right)\left(C_{\frac{1}{2}}\otimes I\right)\right\} { ( C 2 1 † ⊗ I ) ( V † X V ) ( C 2 1 ⊗ I ) }
coin := C 1 / 2 C_{1/2} C 1/2 [coin];
{ V † X V } \left\{V^{\dagger}XV\right\} { V † X V }
(coin, position) := V V V [coin, position]
{ X } \{X\} { X } .
The shift pulls X X X back to V † X V V^{\dagger}XV V † X V , which becomes the post-cost for the coin command. The sequencing rule joins the two unitary-rule instances at this intermediate predicate, giving the body precondition U † X U U^{\dagger}XU U † X U .
At the loop guard, the exit branch has post-cost 0 0 0 . On the continuing branch, I I I pays for the current iteration and U † X U U^{\dagger}XU U † X U pulls the continuation cost X X X at the next guard back through the loop body. Pulling these two branch costs back through the measurement gives
X ⟼ M 0 † 0 M 0 + M 1 † ( I + U † X U ) M 1 . X\longmapsto M_{0}^{\dagger}0M_{0}+M_{1}^{\dagger}(I+U^{\dagger}XU)M_{1}. X ⟼ M 0 † 0 M 0 + M 1 † ( I + U † X U ) M 1 .
The while rule takes the least fixed point of this transformer, obtained by iteration from 0 0 0 . Thus the expected-runtime predicate C C C satisfies
C = M 1 † ( I + U † C U ) M 1 . (37) C=M_{1}^{\dagger}(I+U^{\dagger}CU)M_{1}. \tag*{(37)} C = M 1 † ( I + U † C U ) M 1 . (37)
where ( U † C U ) [ w ] = C [ U w ] (U^{\dagger}CU)[w]=C[Uw] ( U † C U ) [ w ] = C [ U w ] . This adapts the positive-form construction of [59 Section 5.4 and Appendix C.5] to our iteration cost: the bounded predicates obtained by finite unfolding from 0 0 0 increase, so their supremum C C C is a closed positive quadratic form. For a unit input u ∈ H + u\in\mathcal{H}_{+} u ∈ H + , the N N N th unfolding has value E u [ min ( τ , N ) ] \mathbb{E}_{u}[\min(\tau,N)] E u [ min ( τ , N )] ; hence C [ u ] = E u [ τ ] C[u]=\mathbb{E}_{u}[\tau] C [ u ] = E u [ τ ] .
Equation (A.4) makes C C C vanish on the absorbing branch and gives C [ b + w ] = C [ w ] C[b+w]=C[w] C [ b + w ] = C [ w ] for b ∈ ran Π 0 b\in\operatorname{ran}\Pi_{0} b ∈ ran Π 0 and w ∈ H + w\in\mathcal{H}_{+} w ∈ H + . Since U u = B u + K u Uu=Bu+Ku U u = B u + K u , the loop equation reduces to
C [ u ] = ∥ u ∥ 2 + C [ K u ] ( u ∈ H + ) . (38) C[u]=\lVert u\rVert^{2}+C[Ku]\qquad(u\in\mathcal{H}_{+}). \tag*{(38)} C [ u ] = ∥ u ∥ 2 + C [ K u ] ( u ∈ H + ) . (38)
The cost rules thus reduce our verification task to ruling out a finite value at ψ = ∣ R , 1 ⟩ \psi=|R,1\rangle ψ = ∣ R , 1 ⟩ for a nonnegative solution of the one-step inequality below. The following lemma resolves this operator-theoretic question using the boundary defects of K K K .
Lemma A.1 (A rank-one obstruction to finite cost). For the continuing operator K K K in (A.2), every nonnegative quadratic form C C C on H + \mathcal{H}_{+} H + satisfying
C [ u ] ≥ ∥ u ∥ 2 + C [ K u ] ( u ∈ H + ) (39) C[u] \ge\lVert u\rVert^{2} + C[Ku] \qquad(u \in\mathcal{H}_{+}) \tag*{(39)} C [ u ] ≥ ∥ u ∥ 2 + C [ K u ] ( u ∈ H + ) (39) has C [ ψ ] = ∞ C[\psi] = \infty C [ ψ ] = ∞ at ψ = ∣ R , 1 ⟩ \psi= \lvert R,1\rangle ψ = ∣ R , 1 ⟩ .
Proof. Suppose toward a contradiction that C [ ψ ] < ∞ C[\psi] < \infty C [ ψ ] < ∞ . Iterating (A.6) gives
∑ n = 0 N − 1 ∥ K n ψ ∥ 2 + C [ K N ψ ] ≤ C [ ψ ] , \sum_{n=0}^{N-1} \lVert K^{n}\psi\rVert^{2} + C[K^{N}\psi] \le C[\psi], n = 0 ∑ N − 1 ∥ K n ψ ∥ 2 + C [ K N ψ ] ≤ C [ ψ ] ,
so nonnegativity of C C C implies ∑ n ≥ 0 ∥ K n ψ ∥ 2 < ∞ \sum_{n\ge0}\lVert K^{n}\psi\rVert^{2} < \infty ∑ n ≥ 0 ∥ K n ψ ∥ 2 < ∞ . Our strategy is to assemble the surviving states K n ψ K^{n}\psi K n ψ into the cumulative occupation operator G G G : finiteness of the sum makes G G G trace-class, whereas the boundary defects of K K K will force G G G to act as the identity on an infinite-dimensional backward-reachable subspace.
Write ∣ ± ⟩ ≜ ( ∣ L ⟩ ± ∣ R ⟩ ) / 2 \lvert\pm\rangle\triangleq(\lvert L\rangle\pm\lvert R\rangle)/\sqrt{2} ∣ ± ⟩ ≜ (∣ L ⟩ ± ∣ R ⟩) / 2 . From (A.1)–(A.2), the forward action of K K K on H + \mathcal{H}_{+} H + is
K ∣ L , x ⟩ = { 2 − 1 / 2 ∣ R , 2 ⟩ , x = 1 , 2 − 1 / 2 ( ∣ L , x − 1 ⟩ + ∣ R , x + 1 ⟩ ) , x ≥ 2 , (40) K\lvert L,x\rangle=
\begin{cases}
2^{-1/2}\lvert R,2\rangle, & x=1,\\
2^{-1/2}(\lvert L,x-1\rangle+\lvert R,x+1\rangle), & x\ge2,
\end{cases} \tag*{(40)} K ∣ L , x ⟩ = { 2 − 1/2 ∣ R , 2 ⟩ , 2 − 1/2 (∣ L , x − 1 ⟩ + ∣ R , x + 1 ⟩) , x = 1 , x ≥ 2 , (40)
K ∣ R , x ⟩ = { − 2 − 1 / 2 ∣ R , 2 ⟩ , x = 1 , 2 − 1 / 2 ( ∣ L , x − 1 ⟩ − ∣ R , x + 1 ⟩ ) , x ≥ 2 , (41) K\lvert R,x\rangle=
\begin{cases}
-2^{-1/2}\lvert R,2\rangle, & x=1,\\
2^{-1/2}(\lvert L,x-1\rangle-\lvert R,x+1\rangle), & x\ge2,
\end{cases} \tag*{(41)} K ∣ R , x ⟩ = { − 2 − 1/2 ∣ R , 2 ⟩ , 2 − 1/2 (∣ L , x − 1 ⟩ − ∣ R , x + 1 ⟩) , x = 1 , x ≥ 2 , (41)
and its adjoint action is
K † ∣ L , x ⟩ = ∣ + , x + 1 ⟩ ( x ≥ 1 ) , K † ∣ R , x ⟩ = ∣ − , x − 1 ⟩ ( x ≥ 2 ) , K † ψ = 0. K^{\dagger}\lvert L,x\rangle=\lvert+,x+1\rangle\qquad(x\ge1), \qquad K^{\dagger}\lvert R,x\rangle=\lvert-,x-1\rangle\qquad(x\ge2), \qquad K^{\dagger}\psi=0. K † ∣ L , x ⟩ = ∣ + , x + 1 ⟩ ( x ≥ 1 ) , K † ∣ R , x ⟩ = ∣ − , x − 1 ⟩ ( x ≥ 2 ) , K † ψ = 0.
These formulas reveal two rank-one boundary defects at x = 1 x=1 x = 1 . In the forward direction, only the ∣ + , 1 ⟩ \lvert+,1\rangle ∣ + , 1 ⟩ component steps left into ∣ L , 0 ⟩ \lvert L,0\rangle ∣ L , 0 ⟩ , so B = ∣ L , 0 ⟩ ⟨ + , 1 ∣ B=\lvert L,0\rangle\langle+,1\rvert B = ∣ L , 0 ⟩ ⟨ + , 1 ∣ and the conservation identity K † K + B † B = I H + K^{\dagger}K+B^{\dagger}B=I_{\mathcal{H}_{+}} K † K + B † B = I H + gives K † K = I − ∣ + , 1 ⟩ ⟨ + , 1 ∣ K^{\dagger}K=I-\lvert+,1\rangle\langle+,1\rvert K † K = I − ∣ + , 1 ⟩ ⟨ + , 1 ∣ . In the backward direction, no step inside H + \mathcal{H}_{+} H + can land in ψ = ∣ R , 1 ⟩ \psi=\lvert R,1\rangle ψ = ∣ R , 1 ⟩ (reaching x = 1 x=1 x = 1 from x = 2 x=2 x = 2 requires coin state ∣ L ⟩ \lvert L\rangle ∣ L ⟩ ), while K K K maps { ∣ + , 1 ⟩ } ⊥ \{\lvert+,1\rangle\}^{\perp} {∣ + , 1 ⟩ } ⊥ isometrically onto { ψ } ⊥ \{\psi\}^{\perp} { ψ } ⊥ . Thus K K K is a partial isometry satisfying
K † K = I − ∣ + , 1 ⟩ ⟨ + , 1 ∣ , K K † = I − ∣ ψ ⟩ ⟨ ψ ∣ . (42) K^{\dagger}K=I-\lvert+,1\rangle\langle+,1\rvert, \qquad KK^{\dagger}=I-\lvert\psi\rangle\langle\psi\rvert. \tag*{(42)} K † K = I − ∣ + , 1 ⟩ ⟨ + , 1 ∣ , K K † = I − ∣ ψ ⟩ ⟨ ψ ∣ . (42)
Now define the cumulative occupation operator
G ≜ ∑ n = 0 ∞ K n ∣ ψ ⟩ ⟨ ψ ∣ ( K † ) n , (43) G \triangleq\sum_{n=0}^{\infty} K^{n}\lvert\psi\rangle\langle\psi\rvert(K^{\dagger})^{n}, \tag*{(43)} G ≜ n = 0 ∑ ∞ K n ∣ ψ ⟩ ⟨ ψ ∣ ( K † ) n , (43)
which converges in trace norm to a positive trace-class operator with tr ( G ) = ∑ n = 0 ∞ ∥ K n ψ ∥ 2 < ∞ \operatorname{tr}(G)=\sum_{n=0}^{\infty}\lVert K^{n}\psi\rVert^{2}<\infty tr ( G ) = ∑ n = 0 ∞ ∥ K n ψ ∥ 2 < ∞ . Shifting the summation index gives the fixed-point equation
G = ∣ ψ ⟩ ⟨ ψ ∣ + K G K † . (44) G=\lvert\psi\rangle\langle\psi\rvert+KGK^{\dagger}. \tag*{(44)} G = ∣ ψ ⟩ ⟨ ψ ∣ + K G K † . (44)
Substituting ∣ ψ ⟩ ⟨ ψ ∣ = I − K K † \lvert\psi\rangle\langle\psi\rvert=I-KK^{\dagger} ∣ ψ ⟩ ⟨ ψ ∣ = I − K K † from (A.9) telescopes the first N N N terms of (A.10) to I − K N ( K † ) N ≤ I I-K^{N}(K^{\dagger})^{N}\le I I − K N ( K † ) N ≤ I , so 0 ≤ G ≤ I 0\le G\le I 0 ≤ G ≤ I . Taking the trace in (A.11) and using the first identity in (A.9) yields
tr ( G ) = 1 + tr ( G K † K ) = 1 + tr ( G ) − ⟨ + , 1 ∣ G ∣ + , 1 ⟩ . \operatorname{tr}(G)=1+\operatorname{tr}(GK^{\dagger}K)=1+\operatorname{tr}(G)-\langle+,1\vert G\vert+,1\rangle. tr ( G ) = 1 + tr ( G K † K ) = 1 + tr ( G ) − ⟨ + , 1∣ G ∣ + , 1 ⟩ .
Canceling the finite quantity tr ( G ) \operatorname{tr}(G) tr ( G ) forces ⟨ + , 1 ∣ G ∣ + , 1 ⟩ = 1 \langle+,1\vert G\vert+,1\rangle=1 ⟨ + , 1∣ G ∣ + , 1 ⟩ = 1 . Since I − G ≥ 0 I-G\ge0 I − G ≥ 0 , we have ∥ ( I − G ) 1 / 2 ∣ + , 1 ⟩ ∥ 2 = ⟨ + , 1 ∣ ( I − G ) ∣ + , 1 ⟩ = 0 \lVert(I-G)^{1/2}\lvert+,1\rangle\rVert^{2}=\langle+,1\vert(I-G)\vert+,1\rangle=0 ∥( I − G ) 1/2 ∣ + , 1 ⟩ ∥ 2 = ⟨ + , 1∣ ( I − G ) ∣ + , 1 ⟩ = 0 , so ( I − G ) ∣ + , 1 ⟩ = 0 (I-G)\lvert+,1\rangle=0 ( I − G ) ∣ + , 1 ⟩ = 0 .
Finally, subtracting (A.11) from I = ∣ ψ ⟩ ⟨ ψ ∣ + K K † I=\lvert\psi\rangle\langle\psi\rvert+KK^{\dagger} I = ∣ ψ ⟩ ⟨ ψ ∣ + K K † gives the invariance relation
I − G = K ( I − G ) K † . I-G=K(I-G)K^{\dagger}. I − G = K ( I − G ) K † .
For any u ∈ ker ( I − G ) u \in\ker(I-G) u ∈ ker ( I − G ) , this relation implies ∥ ( I − G ) 1 / 2 K † u ∥ 2 2 = ⟨ u , K ( I − G ) K † u ⟩ = 0 \lVert(I-G)^{1/2}K^\dagger u\rVert_2^2 = \langle u,K(I-G)K^\dagger u\rangle= 0 ∥( I − G ) 1/2 K † u ∥ 2 2 = ⟨ u , K ( I − G ) K † u ⟩ = 0 , so ker ( I − G ) \ker(I-G) ker ( I − G ) is invariant under the backward step K † K^\dagger K † . By induction from ∣ + , 1 ⟩ ∈ ker ( I − G ) |+,1\rangle\in\ker(I-G) ∣ + , 1 ⟩ ∈ ker ( I − G ) , the entire backward orbit satisfies
( I − G ) ( K † ) n ∣ + , 1 ⟩ = 0 ( n ≥ 0 ) . (45) (I-G)(K^\dagger)^n|+,1\rangle=0 \qquad(n\ge0). \tag*{(45)} ( I − G ) ( K † ) n ∣ + , 1 ⟩ = 0 ( n ≥ 0 ) . (45)
The adjoint formulas show inductively that ( K † ) n ∣ + , 1 ⟩ (K^\dagger)^n|+,1\rangle ( K † ) n ∣ + , 1 ⟩ is supported on sites { 1 , … , n + 1 } \{1,\ldots,n+1\} { 1 , … , n + 1 } with highest-site component 2 − n / 2 ∣ + , n + 1 ⟩ ≠ 0 2^{-n/2}|+,n+1\rangle\ne0 2 − n /2 ∣ + , n + 1 ⟩ = 0 . These vectors are therefore linearly independent, and (A.12) implies that G G G acts as the identity on their infinite-dimensional span, contradicting tr ( G ) < ∞ \operatorname{tr}(G)<\infty tr ( G ) < ∞ .
Theorem A.2 (Infinite expected runtime at the entrance site). Write ∣ + ⟩ ≜ ( ∣ L ⟩ + ∣ R ⟩ ) / 2 |+\rangle\triangleq(|L\rangle+|R\rangle)/\sqrt{2} ∣ + ⟩ ≜ ( ∣ L ⟩ + ∣ R ⟩) / 2 . For every unit coin vector v ∈ C 2 v \in\mathbb{C}^2 v ∈ C 2 , the coherent Hadamard walk started at v ⊗ ∣ 1 ⟩ v\otimes|1\rangle v ⊗ ∣1 ⟩ satisfies
E v ⊗ ∣ 1 ⟩ [ τ ] = { 1 , v ∈ C ∣ + ⟩ , ∞ , v ∉ C ∣ + ⟩ . (46) \mathbb{E}_{v\otimes|1\rangle}[\tau]=
\begin{cases}
1, & v\in\mathbb{C}|+\rangle,\\
\infty, & v\notin\mathbb{C}|+\rangle.
\end{cases} \tag*{(46)} E v ⊗ ∣1 ⟩ [ τ ] = { 1 , ∞ , v ∈ C ∣ + ⟩ , v ∈ / C ∣ + ⟩ . (46) In particular, E ψ [ τ ] = ∞ \mathbb{E}_{\psi}[\tau]=\infty E ψ [ τ ] = ∞ for ψ = ∣ R , 1 ⟩ \psi=|R,1\rangle ψ = ∣ R , 1 ⟩ .
Proof. By (A.5), the expected-runtime predicate C C C satisfies (A.6), so Lemma A.1 gives C [ ψ ] = ∞ C[\psi]=\infty C [ ψ ] = ∞ . For ∣ + , 1 ⟩ |+,1\rangle ∣ + , 1 ⟩ , the coin operation produces ∣ L , 1 ⟩ |L,1\rangle ∣ L , 1 ⟩ and the shift steps into the absorbing state ∣ L , 0 ⟩ |L,0\rangle ∣ L , 0 ⟩ ; hence K ∣ + , 1 ⟩ = 0 K|+,1\rangle=0 K ∣ + , 1 ⟩ = 0 and (A.5) gives C [ ∣ + , 1 ⟩ ] = 1 C[|+,1\rangle]=1 C [ ∣ + , 1 ⟩] = 1 . Because the finite domain Dom ( C ) \operatorname{Dom}(C) Dom ( C ) of the positive quadratic form C C C is a linear subspace, if it contained v ⊗ ∣ 1 ⟩ v\otimes|1\rangle v ⊗ ∣1 ⟩ for any v ∉ C ∣ + ⟩ v\notin\mathbb{C}|+\rangle v ∈ / C ∣ + ⟩ , it would contain the entire two-dimensional entrance space C 2 ⊗ ∣ 1 ⟩ \mathbb{C}^2\otimes|1\rangle C 2 ⊗ ∣1 ⟩ , including ψ \psi ψ . Thus C [ v ⊗ ∣ 1 ⟩ ] = ∞ C[v\otimes|1\rangle]=\infty C [ v ⊗ ∣1 ⟩] = ∞ for every v ∉ C ∣ + ⟩ v\notin\mathbb{C}|+\rangle v ∈ / C ∣ + ⟩ . Since C [ u ] = E u [ τ ] C[u]=\mathbb{E}_u[\tau] C [ u ] = E u [ τ ] for unit inputs u ∈ H + u\in\mathcal{H}_+ u ∈ H + , the two runtime cases in (A.13) follow.
To recover finer runtime information, we introduce a parameterized family of bounded runtime expectations. For the input ψ = ∣ R , 1 ⟩ \psi=|R,1\rangle ψ = ∣ R , 1 ⟩ , define
h s ≜ E ψ [ s s + τ ; τ < ∞ ] ( s > 0 ) . (47) h_s \triangleq\mathbb{E}_{\psi}\left[\frac{s}{s+\tau};\ \tau<\infty\right] \qquad(s>0). \tag*{(47)} h s ≜ E ψ [ s + τ s ; τ < ∞ ] ( s > 0 ) . (47)
which remains in [ 0 , 1 ] [0,1] [ 0 , 1 ] for every scale s > 0 s>0 s > 0 . Its large-scale behaviour determines the termination probability, conditional runtime moments, and growth rates of capped moments through the results of Section D. In the notation of Section B.2, this quantity is h s = E ψ [ r s ( τ ) ] h_s=\mathbb{E}_{\psi}[r_s(\tau)] h s = E ψ [ r s ( τ )] , where r s ( t ) = s / ( s + t ) r_s(t)=s/(s+t) r s ( t ) = s / ( s + t ) for finite t t t and r s ( ∞ ) = 0 r_s(\infty)=0 r s ( ∞ ) = 0 . Section C constructs the corresponding bounded operator family compositionally; Section E evaluates its scalar readout h s h_s h s on the input ψ \psi ψ .
Runtime Semantics and Parameterized Predicates
To reason compositionally about both runtime and quantum state transformations, we refine the standard denotational semantics ⟦ S ⟧ \llbracket S\rrbracket [ [ S ] ] of a quantum program S S S into runtime-graded completely positive maps ⟦ S ⟧ r t = ( ⟦ S ⟧ n ) n ≥ 0 \llbracket S\rrbracket_{\mathrm{rt}}=(\llbracket S\rrbracket_n)_{n\ge0} [ [ S ] ] rt = ( [ [ S ] ] n ) n ≥ 0 and test them against scale-indexed families of bounded effects F = ( F s ) s > 0 F=(F_s)_{s>0} F = ( F s ) s > 0 .
Programs and Their Runtime-Graded Semantics
Fix a finite set Var \operatorname{Var} Var of quantum variables (registers). Each variable q ∈ Var q\in\operatorname{Var} q ∈ Var is associated with a separable Hilbert space H q \mathcal{H}_q H q (possibly infinite-dimensional, such as ℓ 2 ( Z ) \ell^2(\mathbb{Z}) ℓ 2 ( Z ) ) and a distinguished unit vector ∣ 0 ⟩ q ∈ H q |0\rangle_q\in\mathcal{H}_q ∣0 ⟩ q ∈ H q . The joint Hilbert space and the corresponding set of partial density operators are
H ≜ ⨂ q ∈ Var H q , D ( H ) ≜ { ρ ∈ T ( H ) : ρ ≥ 0 , tr ( ρ ) ≤ 1 } . \mathcal{H}\triangleq\bigotimes_{q\in\operatorname{Var}}\mathcal{H}_q,\qquad
\mathcal{D}(\mathcal{H})\triangleq\{\rho\in\mathcal{T}(\mathcal{H}):\rho\ge0,\ \operatorname{tr}(\rho)\le1\}. H ≜ q ∈ Var ⨂ H q , D ( H ) ≜ { ρ ∈ T ( H ) : ρ ≥ 0 , tr ( ρ ) ≤ 1 } .
Following standard quantum while-language conventions [50 , 59 ] , programs are generated by the syntax
S : : = s k i p ∣ a b o r t ∣ q : = ∣ 0 ⟩ ∣ q ˉ : = U [ q ˉ ] ∣ S 1 ; S 2 ∣ i f ( □ i ∈ J M [ q ˉ ] = i → S i ) f i ∣ w h i l e M [ q ˉ ] = 1 d o B o d . S ::= \mathop{\mathrm{skip}} \mid\mathop{\mathrm{abort}} \mid q := \lvert0\rangle\mid\bar{q} := U[\bar{q}] \mid S_1;S_2
\\
\mid\mathop{\mathrm{if}}\ (\Box_{i\in J}\ M[\bar{q}]=i\to S_i)\ \mathop{\mathrm{fi}}\mid\mathop{\mathrm{while}}\ M[\bar{q}]=1\ \mathop{\mathrm{do}}\ B\ \mathop{\mathrm{od}}. S ::= skip ∣ abort ∣ q := ∣ 0 ⟩ ∣ q ˉ := U [ q ˉ ] ∣ S 1 ; S 2 ∣ if ( □ i ∈ J M [ q ˉ ] = i → S i ) fi ∣ while M [ q ˉ ] = 1 do B od .
Here q ˉ \bar{q} q ˉ is a tuple of distinct variables, U U U is a unitary operator on their joint space H q ˉ \mathcal{H}_{\bar{q}} H q ˉ , and any operator acting on a subsystem is implicitly extended by the identity on the remaining variables. Initialization q : = ∣ 0 ⟩ q := \lvert0\rangle q := ∣ 0 ⟩ resets register q q q to ∣ 0 ⟩ q \lvert0\rangle_q ∣ 0 ⟩ q , and we write q : = ∣ ϕ ⟩ q := \lvert\phi\rangle q := ∣ ϕ ⟩ as shorthand for q : = ∣ 0 ⟩ ; q : = U ϕ [ q ] q := \lvert0\rangle; q := U_\phi[q] q := ∣ 0 ⟩ ; q := U ϕ [ q ] with U ϕ ∣ 0 ⟩ q = ∣ ϕ ⟩ q U_\phi\lvert0\rangle_q=\lvert\phi\rangle_q U ϕ ∣ 0 ⟩ q = ∣ ϕ ⟩ q . In the conditional if, M = { M i } i ∈ J M=\{M_i\}_{i\in J} M = { M i } i ∈ J is a measurement on H q ˉ \mathcal{H}_{\bar{q}} H q ˉ with finite outcome set J J J satisfying ∑ i ∈ J M i † M i = I \sum_{i\in J}M_i^\dagger M_i=I ∑ i ∈ J M i † M i = I , selecting branch S i S_i S i upon outcome i i i . In while, M = { M 0 , M 1 } M=\{M_0,M_1\} M = { M 0 , M 1 } is a binary measurement (M 0 † M 0 + M 1 † M 1 = I M_0^\dagger M_0+M_1^\dagger M_1=I M 0 † M 0 + M 1 † M 1 = I ), where outcome 0 exits the loop and outcome 1 enters the loop body B B B .
Write M i ( ρ ) ≜ M i ρ M i † \mathcal{M}_i(\rho)\triangleq M_i\rho M_i^\dagger M i ( ρ ) ≜ M i ρ M i † for the measurement branch maps, and
R q ( ρ ) ≜ ∣ 0 ⟩ ⟨ 0 ∣ q ⊗ tr q ( ρ ) , U q ˉ ( ρ ) ≜ U ρ U † \mathcal{R}_q(\rho)\triangleq\lvert0\rangle\langle0\rvert_q\otimes\operatorname{tr}_q(\rho),\qquad\mathcal{U}_{\bar{q}}(\rho)\triangleq U\rho U^\dagger R q ( ρ ) ≜ ∣ 0 ⟩ ⟨ 0 ∣ q ⊗ tr q ( ρ ) , U q ˉ ( ρ ) ≜ U ρ U †
for the initialization and unitary-update channels (identifying H \mathcal{H} H with H q ⊗ H r e s t \mathcal{H}_q\otimes\mathcal{H}_{\mathrm{rest}} H q ⊗ H rest ). Recall that the standard denotational semantics [50 ] interprets each program S S S as a completely positive, trace-nonincreasing (CPTNI) map ⟦ S ⟧ : T ( H ) → T ( H ) \llbracket S\rrbracket:\mathcal{T}(\mathcal{H})\to\mathcal{T}(\mathcal{H}) [ [ S ] ] : T ( H ) → T ( H ) defined structurally by
⟦ s k i p ⟧ = id , ⟦ a b o r t ⟧ = 0 , ⟦ q : = ∣ 0 ⟩ ⟧ = R q , ⟦ q ˉ : = U [ q ˉ ] ⟧ = U q ˉ , \llbracket\mathop{\mathrm{skip}}\rrbracket=\operatorname{id},\qquad\llbracket\mathop{\mathrm{abort}}\rrbracket=0,\qquad\llbracket q:=\lvert0\rangle\rrbracket=\mathcal{R}_q,\qquad\llbracket\bar{q}:=U[\bar{q}]\rrbracket=\mathcal{U}_{\bar{q}}, [ [ skip ] ] = id , [ [ abort ] ] = 0 , [ [ q := ∣ 0 ⟩ ] ] = R q , [ [ q ˉ := U [ q ˉ ] ] ] = U q ˉ ,
⟦ S 1 ; S 2 ⟧ = ⟦ S 2 ⟧ ∘ ⟦ S 1 ⟧ , ⟦ i f ( □ i ∈ J M [ q ˉ ] = i → S i ) f i ⟧ = ∑ i ∈ J ⟦ S i ⟧ ∘ M i , (48) \llbracket S_1;S_2\rrbracket=\llbracket S_2\rrbracket\circ\llbracket S_1\rrbracket,\qquad
\llbracket\mathop{\mathrm{if}}\ (\Box_{i\in J}M[\bar{q}]=i\to S_i)\ \mathop{\mathrm{fi}}\rrbracket=\sum_{i\in J}\llbracket S_i\rrbracket\circ\mathcal{M}_i, \tag*{(48)} [ [ S 1 ; S 2 ] ] = [ [ S 2 ] ] ∘ [ [ S 1 ] ] , [ [ if ( □ i ∈ J M [ q ˉ ] = i → S i ) fi ] ] = i ∈ J ∑ [ [ S i ] ] ∘ M i , (48)
⟦ w h i l e M [ q ˉ ] = 1 d o B o d ⟧ = ∑ j = 0 ∞ M 0 ∘ ( ⟦ B ⟧ ∘ M 1 ) j . \llbracket\mathop{\mathrm{while}}\ M[\bar{q}]=1\ \mathop{\mathrm{do}}\ B\ \mathop{\mathrm{od}}\rrbracket
=\sum_{j=0}^{\infty}\mathcal{M}_0\circ(\llbracket B\rrbracket\circ\mathcal{M}_1)^j. [ [ while M [ q ˉ ] = 1 do B od ] ] = j = 0 ∑ ∞ M 0 ∘ ( [ [ B ] ] ∘ M 1 ) j .
To track runtime alongside state transformations, we refine ⟦ S ⟧ \llbracket S\rrbracket [ [ S ] ] by recording the total number of loop iterations. Each entry into a loop body increments the count by one, with iterations of nested loops accumulated into the same total, while loop exits and loop-free commands contribute zero.
Definition B.1 (Runtime-graded denotational semantics). The runtime-graded denotational semantics of a program S S S is the sequence ⟦ S ⟧ r t ≜ ( ⟦ S ⟧ n ) n ≥ 0 \llbracket S\rrbracket_{\mathrm{rt}}\triangleq(\llbracket S\rrbracket_n)_{n\ge0} [ [ S ] ] rt ≜ ( [ [ S ] ] n ) n ≥ 0 , where for each n ∈ Z n\in\mathbb{Z} n ∈ Z , the grade-n n n map ⟦ S ⟧ n : T ( H ) → T ( H ) \llbracket S\rrbracket_n:\mathcal{T}(\mathcal{H})\to\mathcal{T}(\mathcal{H}) [ [ S ] ] n : T ( H ) → T ( H ) is the CP map producing the subnormalized output state of executions that terminate after exactly n n n total loop-body entries (with ⟦ S ⟧ n = 0 \llbracket S\rrbracket_n=0 [ [ S ] ] n = 0 for n < 0 n<0 n < 0 ):
⟦ s k i p ⟧ n = 1 { n = 0 } id , ⟦ a b o r t ⟧ n = 0 , (49) \llbracket\mathop{\mathrm{skip}}\rrbracket_n=1_{\{n=0\}}\operatorname{id},\qquad\llbracket\mathop{\mathrm{abort}}\rrbracket_n=0, \tag*{(49)} [ [ skip ] ] n = 1 { n = 0 } id , [ [ abort ] ] n = 0 , (49)
⟦ q : = ∣ 0 ⟩ ⟧ n = 1 { n = 0 } R q , ⟦ q ˉ : = U [ q ˉ ] ⟧ n = 1 { n = 0 } U q ˉ , (50) \llbracket q:=\lvert0\rangle\rrbracket_n=1_{\{n=0\}}\mathcal{R}_q,\qquad
\llbracket\bar{q}:=U[\bar{q}]\rrbracket_n=1_{\{n=0\}}\mathcal{U}_{\bar{q}}, \tag*{(50)} [ [ q := ∣ 0 ⟩ ] ] n = 1 { n = 0 } R q , [ [ q ˉ := U [ q ˉ ] ] ] n = 1 { n = 0 } U q ˉ , (50)
⟦ S 1 ; S 2 ⟧ n = ∑ a + b = n ⟦ S 2 ⟧ b ∘ ⟦ S 1 ⟧ a , (51) \llbracket S_1;S_2\rrbracket_n=\sum_{a+b=n}\llbracket S_2\rrbracket_b\circ\llbracket S_1\rrbracket_a, \tag*{(51)} [ [ S 1 ; S 2 ] ] n = a + b = n ∑ [ [ S 2 ] ] b ∘ [ [ S 1 ] ] a , (51)
⟦ i f ( □ i ∈ J M [ q ˉ ] = i → S i ) f i ⟧ n = ∑ i ∈ J ⟦ S i ⟧ n ∘ M i . (52) \llbracket\mathop{\mathrm{if}}\ (\Box_{i\in J}M[\bar{q}]=i\to S_i)\ \mathop{\mathrm{fi}}\rrbracket_n
=\sum_{i\in J}\llbracket S_i\rrbracket_n\circ\mathcal{M}_i. \tag*{(52)} [ [ if ( □ i ∈ J M [ q ˉ ] = i → S i ) fi ] ] n = i ∈ J ∑ [ [ S i ] ] n ∘ M i . (52)
For a loop L = w h i l e M [ q ˉ ] = 1 d o B o d L=\mathop{\mathrm{while}}\ M[\bar{q}]=1\ \mathop{\mathrm{do}}\ B\ \mathop{\mathrm{od}} L = while M [ q ˉ ] = 1 do B od and each integer k ≥ 1 k\ge1 k ≥ 1 , let C k ≜ ⟦ B ⟧ k − 1 ∘ M 1 C_k\triangleq\llbracket B\rrbracket_{k-1}\circ\mathcal{M}_1 C k ≜ [ [ B ] ] k − 1 ∘ M 1 denote the grade-k k k map of one guarded continuation step (with C 0 ≜ 0 C_0\triangleq0 C 0 ≜ 0 ): entering the body contributes one iteration and executing B B B contributes the remaining k − 1 k-1 k − 1 . The grade-n n n map of L L L sums over 0 ≤ j ≤ n 0\le j\le n 0 ≤ j ≤ n completed outer iterations:
⟦ L ⟧ n = ∑ j = 0 n ∑ k 1 , … , k j ∈ N + k 1 + ⋯ + k j = n M 0 ∘ C k j ∘ ⋯ ∘ C k 1 . (53) \llbracket L\rrbracket_n
=\sum_{j=0}^{n}\ \sum_{\substack{k_1,\ldots,k_j\in\mathbb{N}_+\\k_1+\cdots+k_j=n}}
\mathcal{M}_0\circ C_{k_j}\circ\cdots\circ C_{k_1}. \tag*{(53)} [ [ L ] ] n = j = 0 ∑ n k 1 , … , k j ∈ N + k 1 + ⋯ + k j = n ∑ M 0 ∘ C k j ∘ ⋯ ∘ C k 1 . (53)
where n ≥ 0 n \ge0 n ≥ 0 and the j = 0 j = 0 j = 0 term is 1 { n = 0 } M 0 \mathbf{1}_{\{n=0\}}\mathcal{M}_0 1 { n = 0 } M 0 .
Recall that the trace class is complete in the trace norm [43 Theorem VI.20] . If ( Φ n ) n ≥ 0 (\Phi_n)_{n\ge0} ( Φ n ) n ≥ 0 is a sequence of CP maps whose finite partial sums are trace-nonincreasing, then for every positive trace-class operator ρ \rho ρ ,
∑ n ≥ 0 ∥ Φ n ( ρ ) ∥ 1 = ∑ n ≥ 0 tr ( Φ n ( ρ ) ) ≤ tr ( ρ ) . \sum_{n\ge0}\lVert\Phi_n(\rho)\rVert_1 = \sum_{n\ge0}\operatorname{tr}(\Phi_n(\rho)) \le\operatorname{tr}(\rho). n ≥ 0 ∑ ∥ Φ n ( ρ ) ∥ 1 = n ≥ 0 ∑ tr ( Φ n ( ρ )) ≤ tr ( ρ ) .
Thus ∑ n ≥ 0 Φ n ( ρ ) \sum_{n\ge0}\Phi_n(\rho) ∑ n ≥ 0 Φ n ( ρ ) converges absolutely in trace norm (allowing arbitrary regrouping), and by linearity this convergence extends to all ρ ∈ T ( H ) \rho\in\mathcal{T}(\mathcal{H}) ρ ∈ T ( H ) . Since complete positivity and the trace bound pass to the limit, the sum defines a CPTNI map. Forgetting the runtime index then recovers the standard denotational semantics ⟦ S ⟧ \llbracket S\rrbracket [ [ S ] ] :
Proposition B.2 (Well-definedness and compatibility with ⟦ S ⟧ \llbracket S\rrbracket [ [ S ] ] ). For every program S S S , the runtime grades ( ⟦ S ⟧ n ) n ≥ 0 (\llbracket S\rrbracket_n)_{n\ge0} ( [ [ S ] ] n ) n ≥ 0 are well-defined CPTNI maps. Their sum is also CPTNI and coincides with the standard denotational semantics (B.1): for every ρ ∈ D ( H ) \rho\in\mathcal{D}(\mathcal{H}) ρ ∈ D ( H ) ,
∑ n ≥ 0 ⟦ S ⟧ n ( ρ ) = ⟦ S ⟧ ( ρ ) \sum_{n\ge0}\llbracket S\rrbracket_n(\rho)=\llbracket S\rrbracket(\rho) n ≥ 0 ∑ [ [ S ] ] n ( ρ ) = [ [ S ] ] ( ρ ) in trace norm.
Proof. We proceed by structural induction on S S S . In each case, every grade ⟦ S ⟧ n \llbracket S\rrbracket_n [ [ S ] ] n is a finite sum of compositions of CP maps; fixing ρ ∈ D ( H ) \rho\in\mathcal{D}(\mathcal{H}) ρ ∈ D ( H ) , it suffices to show that the finite partial sums are trace-nonincreasing and converge in trace norm to ⟦ S ⟧ ( ρ ) \llbracket S\rrbracket(\rho) [ [ S ] ] ( ρ ) .
Basic commands. For skip, initialization, and unitary updates, only grade zero is nonzero and equals the corresponding trace-preserving CP map, whereas all grades of abort are zero. The claims follow immediately.
∑ a , b ≥ 0 tr ( ⟦ S 2 ⟧ b ( ⟦ S 1 ⟧ a ( ρ ) ) ) ≤ ∑ a ≥ 0 tr ( ⟦ S 1 ⟧ a ( ρ ) ) ≤ tr ( ρ ) . \sum_{a,b\ge0}\operatorname{tr}\left(\llbracket S_2\rrbracket_b(\llbracket S_1\rrbracket_a(\rho))\right) \le\sum_{a\ge0}\operatorname{tr}\left(\llbracket S_1\rrbracket_a(\rho)\right) \le\operatorname{tr}(\rho). a , b ≥ 0 ∑ tr ( [ [ S 2 ] ] b ( [ [ S 1 ] ] a ( ρ )) ) ≤ a ≥ 0 ∑ tr ( [ [ S 1 ] ] a ( ρ ) ) ≤ tr ( ρ ) .
Thus absolute convergence in trace norm and trace-norm continuity give
∑ n ≥ 0 ⟦ S 1 ; S 2 ⟧ n ( ρ ) = ∑ a , b ≥ 0 ⟦ S 2 ⟧ b ( ⟦ S 1 ⟧ a ( ρ ) ) = ⟦ S 2 ⟧ ( ⟦ S 1 ⟧ ( ρ ) ) = ⟦ S 1 ; S 2 ⟧ ( ρ ) . \begin{aligned}
\sum_{n\ge0}\llbracket S_1;S_2\rrbracket_n(\rho) = \sum_{a,b\ge0}\llbracket S_2\rrbracket_b(\llbracket S_1\rrbracket_a(\rho)) \\
&= \llbracket S_2\rrbracket(\llbracket S_1\rrbracket(\rho)) = \llbracket S_1;S_2\rrbracket(\rho).
\end{aligned} n ≥ 0 ∑ [ [ S 1 ; S 2 ] ] n ( ρ ) = a , b ≥ 0 ∑ [ [ S 2 ] ] b ( [ [ S 1 ] ] a ( ρ )) = [ [ S 2 ] ] ( [ [ S 1 ] ] ( ρ )) = [ [ S 1 ; S 2 ] ] ( ρ ) .
∑ n ≥ 0 ⟦ S i f ⟧ n ( ρ ) = ∑ i ∈ J ⟦ S i ⟧ ( M i ( ρ ) ) = ⟦ S i f ⟧ ( ρ ) \sum_{n\ge0}\llbracket S_{\mathrm{if}}\rrbracket_n(\rho) = \sum_{i\in J}\llbracket S_i\rrbracket(\mathcal{M}_i(\rho)) = \llbracket S_{\mathrm{if}}\rrbracket(\rho) n ≥ 0 ∑ [ [ S if ] ] n ( ρ ) = i ∈ J ∑ [ [ S i ] ] ( M i ( ρ )) = [ [ S if ] ] ( ρ )
in trace norm, with trace at most ∑ i ∈ J tr ( M i ( ρ ) ) = tr ( ρ ) \sum_{i\in J}\operatorname{tr}(\mathcal{M}_i(\rho)) = \operatorname{tr}(\rho) ∑ i ∈ J tr ( M i ( ρ )) = tr ( ρ ) .
C ( σ ) = ∑ k ≥ 1 C k ( σ ) , σ ∈ D ( H ) , C(\sigma) = \sum_{k\ge1} C_k(\sigma), \qquad\sigma\in\mathcal{D}(\mathcal{H}), C ( σ ) = k ≥ 1 ∑ C k ( σ ) , σ ∈ D ( H ) ,
in trace norm. Since ⟦ B ⟧ \llbracket B\rrbracket [ [ B ] ] is trace-nonincreasing and ∑ i = 0 1 M i † M i = I \sum_{i=0}^{1}M_i^\dagger M_i = I ∑ i = 0 1 M i † M i = I ,
tr ( M 0 ( σ ) ) + tr ( C ( σ ) ) ≤ tr ( σ ) . \operatorname{tr}(\mathcal{M}_0(\sigma)) + \operatorname{tr}(C(\sigma)) \le\operatorname{tr}(\sigma). tr ( M 0 ( σ )) + tr ( C ( σ )) ≤ tr ( σ ) .
Applying this inequality to σ = C j ( ρ ) \sigma= C^{j}(\rho) σ = C j ( ρ ) and summing gives
∑ j = 0 N − 1 tr ( M 0 ( C j ( ρ ) ) ) ≤ ∑ j = 0 N − 1 [ tr ( C j ( ρ ) ) − tr ( C j + 1 ( ρ ) ) ] = tr ( ρ ) − tr ( C N ( ρ ) ) ≤ tr ( ρ ) . \sum_{j=0}^{N-1} \operatorname{tr}(\mathcal{M}_0(C^{j}(\rho))) \le\sum_{j=0}^{N-1} \left[\operatorname{tr}(C^{j}(\rho))-\operatorname{tr}(C^{j+1}(\rho))\right]
= \operatorname{tr}(\rho)-\operatorname{tr}(C^{N}(\rho)) \le\operatorname{tr}(\rho). j = 0 ∑ N − 1 tr ( M 0 ( C j ( ρ ))) ≤ j = 0 ∑ N − 1 [ tr ( C j ( ρ )) − tr ( C j + 1 ( ρ )) ] = tr ( ρ ) − tr ( C N ( ρ )) ≤ tr ( ρ ) .
Expanding each C j C^{j} C j using the induction hypothesis gives, for every integer N ≥ 1 N \ge1 N ≥ 1 ,
∑ n = 0 N − 1 ⟦ L ⟧ n ( ρ ) ≤ ∑ j = 0 N − 1 M 0 ( C j ( ρ ) ) . \sum_{n=0}^{N-1} \llbracket L \rrbracket_n(\rho) \le\sum_{j=0}^{N-1} \mathcal{M}_0(C^{j}(\rho)). n = 0 ∑ N − 1 [ [ L ] ] n ( ρ ) ≤ j = 0 ∑ N − 1 M 0 ( C j ( ρ )) .
The preceding trace bound therefore applies to every partial sum of ∑ n ≥ 0 ⟦ L ⟧ n ( ρ ) \sum_{n\ge0}\llbracket L \rrbracket_n(\rho) ∑ n ≥ 0 [ [ L ] ] n ( ρ ) , ensuring absolute convergence in trace norm. We can therefore regroup terms either by total runtime n n n or by outer iteration count j j j to obtain
∑ n ≥ 0 ⟦ L ⟧ n ( ρ ) = ∑ j ≥ 0 M 0 ( C j ( ρ ) ) = ⟦ L ⟧ ( ρ ) \sum_{n\ge0}\llbracket L \rrbracket_n(\rho) = \sum_{j\ge0}\mathcal{M}_0(C^{j}(\rho)) = \llbracket L \rrbracket(\rho) n ≥ 0 ∑ [ [ L ] ] n ( ρ ) = j ≥ 0 ∑ M 0 ( C j ( ρ )) = [ [ L ] ] ( ρ )
in trace norm, with trace at most tr ( ρ ) \operatorname{tr}(\rho) tr ( ρ ) .
Hence each grade and the runtime-erased sum are CPTNI, as claimed. □
From Costs to Bounded Runtime Tests
From the runtime grades of S S S , we define the exact-runtime termination effects E n S E_n^S E n S , the total termination effect Q S Q_S Q S , and the divergence effect D S D_S D S :
E n S ≜ ⟦ S ⟧ n † ( I ) , Q S ≜ ∑ n ≥ 0 E n S = ⟦ S ⟧ † ( I ) , D S ≜ I − Q S . (54) E_n^S \triangleq\llbracket S \rrbracket_n^\dagger(I), \qquad Q_S \triangleq\sum_{n\ge0} E_n^S = \llbracket S \rrbracket^\dagger(I), \qquad D_S \triangleq I-Q_S. \tag*{(54)} E n S ≜ [ [ S ] ] n † ( I ) , Q S ≜ n ≥ 0 ∑ E n S = [ [ S ] ] † ( I ) , D S ≜ I − Q S . (54)
For a normalized state ρ \rho ρ , p n = tr ( E n S ρ ) p_n = \operatorname{tr}(E_n^S\rho) p n = tr ( E n S ρ ) and p ∞ = tr ( D S ρ ) p_\infty= \operatorname{tr}(D_S\rho) p ∞ = tr ( D S ρ ) give the distribution of the runtime τ S ∈ N ∪ { ∞ } \tau_S \in\mathbb{N}\cup\{\infty\} τ S ∈ N ∪ { ∞ } , with τ S = ∞ \tau_S=\infty τ S = ∞ on nonterminating executions. The successful k k k -th runtime moment (k > 0 k>0 k > 0 ) and the total expected runtime are the closed positive quadratic forms
M k S ≜ ∑ n ≥ 0 n k E n S (55) M_k^S \triangleq\sum_{n\ge0} n^k E_n^S \tag*{(55)} M k S ≜ n ≥ 0 ∑ n k E n S (55)
C S ≜ sup N ≥ 1 ( ∑ n ≥ 0 min ( n , N ) E n S + N D S ) = M 1 S + ∞ D S . (56) C_S \triangleq\sup_{N\ge1}\left(\sum_{n\ge0}\min(n,N)E_n^S+ND_S\right)=M_1^S+\infty D_S. \tag*{(56)} C S ≜ N ≥ 1 sup ( n ≥ 0 ∑ min ( n , N ) E n S + N D S ) = M 1 S + ∞ D S . (56)
Each capped operator in (B.9) lies in [ 0 , N I ] [0,NI] [ 0 , N I ] , and these operators increase with N N N . Their supremum is therefore a closed positive form, and scalar monotone convergence on each vector gives M 1 S + ∞ D S M_1^S+\infty D_S M 1 S + ∞ D S . For a normalized input ρ \rho ρ , their expectations are E ρ [ min ( τ S , N ) ] \mathbb{E}_{\rho}[\min(\tau_S,N)] E ρ [ min ( τ S , N )] ; monotone convergence then gives tr ( C S ρ ) = E ρ [ τ S ] \operatorname{tr}(C_S\rho)=\mathbb{E}_{\rho}[\tau_S] tr ( C S ρ ) = E ρ [ τ S ] .
Building on the expected-cost analysis of Section A, we evaluate individual execution costs via a bounded test before taking expectations, using the scalar normalized resolvent at scale s > 0 s>0 s > 0 :
r s ( t ) ≜ s s + t ( t ≥ 0 ) , r s ( ∞ ) ≜ 0. r_s(t) \triangleq\frac{s}{s+t}\quad(t\ge0), \qquad r_s(\infty)\triangleq0. r s ( t ) ≜ s + t s ( t ≥ 0 ) , r s ( ∞ ) ≜ 0.
Because r s r_s r s is bounded and vanishes at ∞ \infty ∞ , the expectation E ρ [ r s ( τ S ) ] \mathbb{E}_{\rho}[r_s(\tau_S)] E ρ [ r s ( τ S )] remains finite and retains information about terminating executions even when E ρ [ τ S ] = ∞ \mathbb{E}_{\rho}[\tau_S]=\infty E ρ [ τ S ] = ∞ . As s s s varies, this yields a family of bounded observations whose large-scale behaviour determines termination probabilities, moments, and divergence rates (Section D).
The same construction extends to a bounded positive terminal-cost operator G G G through its normalized resolvent R s ( G ) ≜ s ( s I + G ) − 1 ∈ [ 0 , I ] H R_s(G)\triangleq s(sI+G)^{-1}\in[0,I]_{\mathcal{H}} R s ( G ) ≜ s ( s I + G ) − 1 ∈ [ 0 , I ] H . These resolvents reverse operator cost bounds into ordered effects: 0 ≤ G ≤ P 0\le G\le P 0 ≤ G ≤ P implies R s ( P ) ≤ R s ( G ) R_s(P)\le R_s(G) R s ( P ) ≤ R s ( G ) for bounded P P P , turning an upper bound on the cost into a lower bound on its test across all input states. Since an execution of runtime n n n adds n I nI n I to the terminal cost, we have
R s ( n I + G ) = s s + n R s + n ( G ) , (57) R_s(nI+G)=\frac{s}{s+n}R_{s+n}(G), \tag*{(57)} R s ( n I + G ) = s + n s R s + n ( G ) , (57)
so at runtime n n n the terminal test is evaluated at the shifted scale s + n s+n s + n and weighted by s / ( s + n ) s/(s+n) s / ( s + n ) . Pulling this test back through each runtime grade and summing gives
∑ n ≥ 0 [ [ S ] ] n ( R s ( n I + G ) ) = ∑ n ≥ 0 s s + n [ [ S ] ] n ( R s + n ( G ) ) . \sum_{n\geq0}[\![S]\!]_n(R_s(nI+G))=\sum_{n\geq0}\frac{s}{s+n}[\![S]\!]_n(R_{s+n}(G)). n ≥ 0 ∑ [ [ S ] ] n ( R s ( n I + G )) = n ≥ 0 ∑ s + n s [ [ S ] ] n ( R s + n ( G )) .
Once averaged over executions, however, such tests need not be the resolvent of any single cost. For instance, a scalar runtime taking the values 1 and 3 with equal probability has the s → ∞ s\to\infty s → ∞ expansion
1 2 s s + 1 + 1 2 s s + 3 = 1 − 2 s + 5 s 2 + O ( s − 3 ) , \frac{1}{2}\frac{s}{s+1}+\frac{1}{2}\frac{s}{s+3}=1-\frac{2}{s}+\frac{5}{s^2}+O(s^{-3}), 2 1 s + 1 s + 2 1 s + 3 s = 1 − s 2 + s 2 5 + O ( s − 3 ) ,
which cannot equal s / ( s + c ) s/(s+c) s / ( s + c ) for any fixed scalar c ≥ 0 c\geq0 c ≥ 0 : matching the s − 1 s^{-1} s − 1 coefficient forces c = 2 c=2 c = 2 , whereas s / ( s + 2 ) s/(s+2) s / ( s + 2 ) has coefficient 4 rather than 5 at order s − 2 s^{-2} s − 2 . To keep predicates closed under branch sums and program pullbacks, we therefore work with general effect families F = ( F s ) s > 0 F=(F_s)_{s>0} F = ( F s ) s > 0 , for which accumulating runtime n n n transforms the terminal test into s s + n F s + n \frac{s}{s+n}F_{s+n} s + n s F s + n . Section G later shows how existing cost-logic proofs yield contracts in this domain.
Under sequential execution, accumulating runtime c c c followed by t t t applies this transformation twice, yielding s s + c ( s + c s + c + t F s + c + t ) = s s + c + t F s + c + t \frac{s}{s+c}\left(\frac{s+c}{s+c+t}F_{s+c+t}\right)=\frac{s}{s+c+t}F_{s+c+t} s + c s ( s + c + t s + c F s + c + t ) = s + c + t s F s + c + t . This consistency rests on a simple multiplicative identity that also gives the discount factor a random-deadline interpretation:
Lemma B.3 (Scale-shift identity and random deadlines). For all s > 0 s>0 s > 0 and c , t ≥ 0 c,t\geq0 c , t ≥ 0 ,
s s + c + t = s s + c ⋅ s + c ( s + c ) + t . (58) \frac{s}{s+c+t}=\frac{s}{s+c}\cdot\frac{s+c}{(s+c)+t}. \tag*{(58)} s + c + t s = s + c s ⋅ ( s + c ) + t s + c . (58) Probabilistically, if T s ≥ 0 T_s\geq0 T s ≥ 0 is a random deadline independent of the execution of S S S with density s ( s + t ) 2 \frac{s}{(s+t)^2} ( s + t ) 2 s on [ 0 , ∞ ) [0,\infty) [ 0 , ∞ ) (so T s T_s T s has median s s s ), then its survival function obeys the scale-shifting memory law
P ( T s ≥ t ) = s s + t , P ( T s − c ≥ t ∣ T s ≥ c ) = s + c s + c + t . \mathbb{P}(T_s\geq t)=\frac{s}{s+t},\qquad\mathbb{P}(T_s-c\geq t\mid T_s\geq c)=\frac{s+c}{s+c+t}. P ( T s ≥ t ) = s + t s , P ( T s − c ≥ t ∣ T s ≥ c ) = s + c + t s + c . Proof. Identity (B.11) is immediate by canceling s + c s+c s + c . Integrating ∫ t ∞ s ( s + u ) 2 d u = s s + t \int_t^\infty\frac{s}{(s+u)^2}\,\mathrm{d}u=\frac{s}{s+t} ∫ t ∞ ( s + u ) 2 s d u = s + t s gives P ( T s ≥ t ) \mathbb{P}(T_s\geq t) P ( T s ≥ t ) (which equals 1 / 2 1/2 1/2 at t = s t=s t = s ), and dividing P ( T s ≥ c + t ) \mathbb{P}(T_s\geq c+t) P ( T s ≥ c + t ) by P ( T s ≥ c ) \mathbb{P}(T_s\geq c) P ( T s ≥ c ) yields the conditional survival probability.
Parameterized Predicates and Semantic Validity
We now formalize the space of scale-indexed effect families and define the semantic validity of Hoare triples.
Definition B.4 (Parameterized predicates and semantic validity). The predicate space on H \mathcal{H} H is the pointwise ordered ω \omega ω -CPO of scale-indexed effect families:
Pred ( H ) ≔ ∏ s > 0 [ 0 , I ] H , A ≤ F ⟺ A s ≤ F s for all s > 0. \operatorname{Pred}(\mathcal{H})\coloneqq\prod_{s>0}[0,I]_{\mathcal{H}},\qquad A\leq F\Longleftrightarrow A_s\leq F_s\text{ for all }s>0. Pred ( H ) : = s > 0 ∏ [ 0 , I ] H , A ≤ F ⟺ A s ≤ F s for all s > 0. Increasing sequential suprema are computed pointwise in the strong operator topology, and 0 \mathbf{0} 0 and I \mathbf{I} I denote the constant zero and identity families. For A , F ∈ Pred ( H ) A,F\in\operatorname{Pred}(\mathcal{H}) A , F ∈ Pred ( H ) , the Hoare triple { A } S { F } \{A\}\,S\,\{F\} { A } S { F } is valid in the sense of total correctness, written ⊨ t o t { A } S { F } \models_{\mathrm{tot}}\{A\}\,S\,\{F\} ⊨ tot { A } S { F } , if, for every s > 0 s>0 s > 0 and ρ ∈ D ( H ) \rho\in\mathcal{D}(\mathcal{H}) ρ ∈ D ( H ) ,
tr ( A s ρ ) ≤ ∑ n ≥ 0 s s + n tr ( F s + n [ [ S ] ] n ( ρ ) ) . (59) \operatorname{tr}(A_s\rho)\leq\sum_{n\geq0}\frac{s}{s+n}\operatorname{tr}(F_{s+n}[\![S]\!]_n(\rho)). \tag*{(59)} tr ( A s ρ ) ≤ n ≥ 0 ∑ s + n s tr ( F s + n [ [ S ] ] n ( ρ )) . (59)
The triple is valid in the sense of partial correctness, written ⊨ p a r { A } S { F } \vDash_{\mathrm{par}}\{A\}\,S\,\{F\} ⊨ par { A } S { F } , if, for every s > 0 s>0 s > 0 and ρ ∈ D ( H ) \rho\in\mathcal{D}(\mathcal{H}) ρ ∈ D ( H ) ,
tr ( A s ρ ) ≤ ∑ n ≥ 0 s s + n tr ( F s + n ⟦ S ⟧ n ( ρ ) ) + tr ( ρ ) − tr ( ⟦ S ⟧ ( ρ ) ) . (60) \operatorname{tr}(A_s\rho)\leq\sum_{n\geq0}\frac{s}{s+n}\operatorname{tr}(F_{s+n}\llbracket S\rrbracket_n(\rho))+\operatorname{tr}(\rho)-\operatorname{tr}(\llbracket S\rrbracket(\rho)). \tag*{(60)} tr ( A s ρ ) ≤ n ≥ 0 ∑ s + n s tr ( F s + n [ [ S ] ] n ( ρ )) + tr ( ρ ) − tr ( [ [ S ] ] ( ρ )) . (60)
Both notions of validity evaluate the same discounted postcondition on terminating executions, differing only on nontermination: total correctness assigns nonterminating runs zero weight, whereas partial correctness credits the full nontermination mass tr ( ρ ) − tr ( ⟦ S ⟧ ( ρ ) ) \operatorname{tr}(\rho)-\operatorname{tr}(\llbracket S\rrbracket(\rho)) tr ( ρ ) − tr ( [ [ S ] ] ( ρ )) . Rather than evaluating these grade sums directly, we next characterize both notions of validity compositionally via weakest-precondition transformers.
A Compositional Resolvent Calculus and Loop Solutions
In this section, we develop a compositional calculus for the weakest preconditions wp ( S , F ) \operatorname{wp}(S,F) wp ( S , F ) and wlp ( S , F ) \operatorname{wlp}(S,F) wlp ( S , F ) . Section Section C.1 establishes their explicit grade-sum representations and syntax-directed rules, which reduce while loops to fixed-point equations on Pred ( H ) \operatorname{Pred}(\mathcal{H}) Pred ( H ) . Because closed-form loop solutions are rarely available, Section Section C.2 proves uniqueness of the loop fixed point and derives residual bounds that certify asymptotic approximations, preparing for the extraction of termination probabilities and moments in Section Section D.
Weakest Preconditions and Structural Rules
Definition C.1 (Weakest preconditions). For a program S S S and postcondition F ∈ Pred ( H ) F\in\operatorname{Pred}(\mathcal{H}) F ∈ Pred ( H ) , the weakest precondition wp ( S , F ) \operatorname{wp}(S,F) wp ( S , F ) and weakest liberal precondition wlp ( S , F ) \operatorname{wlp}(S,F) wlp ( S , F ) are defined, when they exist, as the largest valid preconditions in Pred ( H ) \operatorname{Pred}(\mathcal{H}) Pred ( H ) for total and partial correctness, respectively. That is, they satisfy:
Validity: ⊨ t o t { wp ( S , F ) } S { F } \vDash_{\mathrm{tot}}\{\operatorname{wp}(S,F)\}\,S\,\{F\} ⊨ tot { wp ( S , F )} S { F } and ⊨ p a r { wlp ( S , F ) } S { F } \vDash_{\mathrm{par}}\{\operatorname{wlp}(S,F)\}\,S\,\{F\} ⊨ par { wlp ( S , F )} S { F } .
Maximality: For any A ∈ Pred ( H ) A\in\operatorname{Pred}(\mathcal{H}) A ∈ Pred ( H ) , if ⊨ t o t { A } S { F } \vDash_{\mathrm{tot}}\{A\}\,S\,\{F\} ⊨ tot { A } S { F } , then A ≤ wp ( S , F ) A\leq\operatorname{wp}(S,F) A ≤ wp ( S , F ) ; if ⊨ p a r { A } S { F } \vDash_{\mathrm{par}}\{A\}\,S\,\{F\} ⊨ par { A } S { F } , then A ≤ wlp ( S , F ) A\leq\operatorname{wlp}(S,F) A ≤ wlp ( S , F ) .
Theorem C.2 (Weakest preconditions and structural rules). For every program S S S and postcondition F ∈ Pred ( H ) F\in\operatorname{Pred}(\mathcal{H}) F ∈ Pred ( H ) , the weakest precondition wp ( S , F ) \operatorname{wp}(S,F) wp ( S , F ) exists and is given at each scale s > 0 s>0 s > 0 by
wp ( S , F ) s = ∑ n ≥ 0 s s + n ⟦ S ⟧ n † ( F s + n ) . (61) \operatorname{wp}(S,F)_s=\sum_{n\geq0}\frac{s}{s+n}\llbracket S\rrbracket_n^{\dagger}(F_{s+n}). \tag*{(61)} wp ( S , F ) s = n ≥ 0 ∑ s + n s [ [ S ] ] n † ( F s + n ) . (61)
The transformer wp ( S , ⋅ ) : Pred ( H ) → Pred ( H ) \operatorname{wp}(S,\cdot):\operatorname{Pred}(\mathcal{H})\to\operatorname{Pred}(\mathcal{H}) wp ( S , ⋅ ) : Pred ( H ) → Pred ( H ) is monotone, preserves increasing sequential suprema, and satisfies the structural rules
wp ( s k i p , F ) s = F s , wp ( a b o r t , F ) s = 0 , (62) \operatorname{wp}(\mathop{\mathrm{skip}},F)_s=F_s,\qquad\operatorname{wp}(\mathop{\mathrm{abort}},F)_s=0, \tag*{(62)} wp ( skip , F ) s = F s , wp ( abort , F ) s = 0 , (62)
wp ( q : = ∣ 0 ⟩ , F ) s = ∑ j ∣ j ⟩ q ⟨ 0 ∣ q F s ∣ 0 ⟩ q ⟨ j ∣ q , (63) \operatorname{wp}(q:=\lvert0\rangle,F)_s=\sum_j\lvert j\rangle_q\langle0\rvert_qF_s\lvert0\rangle_q\langle j\rvert_q, \tag*{(63)} wp ( q := ∣ 0 ⟩ , F ) s = j ∑ ∣ j ⟩ q ⟨ 0 ∣ q F s ∣ 0 ⟩ q ⟨ j ∣ q , (63)
wp ( q ˉ : = U [ q ˉ ] , F ) s = U † F s U , (64) \operatorname{wp}(\bar{q}:=U[\bar{q}],F)_s=U^\dagger F_sU, \tag*{(64)} wp ( q ˉ := U [ q ˉ ] , F ) s = U † F s U , (64)
wp ( if ( □ i ∈ J M [ q ˉ ] = i → S i ) fi , F ) s = ∑ i ∈ J M i † wp ( S i , F ) s M i , (65) \operatorname{wp}\left(\operatorname{if}\left(\mathop{\Box}_{i\in J}M[\bar{q}]=i\to S_i\right)\operatorname{fi},F\right)_s=\sum_{i\in J}M_i^\dagger\operatorname{wp}(S_i,F)_sM_i, \tag*{(65)} wp ( if ( □ i ∈ J M [ q ˉ ] = i → S i ) fi , F ) s = i ∈ J ∑ M i † wp ( S i , F ) s M i , (65)
wp ( S 1 ; S 2 , F ) = wp ( S 1 , wp ( S 2 , F ) ) , (66) \operatorname{wp}(S_1;S_2,F)=\operatorname{wp}(S_1,\operatorname{wp}(S_2,F)), \tag*{(66)} wp ( S 1 ; S 2 , F ) = wp ( S 1 , wp ( S 2 , F )) , (66)
where { ∣ j ⟩ q } j \{\lvert j\rangle_q\}_j {∣ j ⟩ q } j in (C.3) is an orthonormal basis of H q \mathcal{H}_q H q . Moreover, for a loop L = while M [ q ˉ ] = 1 do B od L=\operatorname{while}\ M[\bar{q}]=1\ \operatorname{do}\ B\ \operatorname{od} L = while M [ q ˉ ] = 1 do B od , wp ( L , F ) \operatorname{wp}(L,F) wp ( L , F ) is the least fixed point in Pred ( H ) \operatorname{Pred}(\mathcal{H}) Pred ( H ) of the characteristic functional T F : Pred ( H ) → Pred ( H ) \mathcal{T}_F:\operatorname{Pred}(\mathcal{H})\to\operatorname{Pred}(\mathcal{H}) T F : Pred ( H ) → Pred ( H ) defined by
( T F X ) s = M 0 † F s M 0 + s s + 1 M 1 † wp ( B , X ) s + 1 M 1 . (67) (\mathcal{T}_F X)_s=M_0^\dagger F_sM_0+\frac{s}{s+1}M_1^\dagger\operatorname{wp}(B,X)_{s+1}M_1. \tag*{(67)} ( T F X ) s = M 0 † F s M 0 + s + 1 s M 1 † wp ( B , X ) s + 1 M 1 . (67)
Proof. For each s > 0 s > 0 s > 0 and n ≥ 0 n \ge0 n ≥ 0 , positivity of ⟦ S ⟧ n † \llbracket S\rrbracket_n^\dagger [ [ S ] ] n † and 0 ≤ F s + n ≤ I 0 \le F_{s+n} \le I 0 ≤ F s + n ≤ I give 0 ≤ s s + n ⟦ S ⟧ n † ( F s + n ) ≤ ⟦ S ⟧ n † ( I ) = E n S 0 \le\frac{s}{s+n}\llbracket S\rrbracket_n^\dagger(F_{s+n}) \le\llbracket S\rrbracket_n^\dagger(I) = E_n^S 0 ≤ s + n s [ [ S ] ] n † ( F s + n ) ≤ [ [ S ] ] n † ( I ) = E n S . By (B.7), ∑ n ≥ 0 E n S = Q S ≤ I \sum_{n\ge0} E_n^S = Q_S \le I ∑ n ≥ 0 E n S = Q S ≤ I , so the series in (C.1) converges strongly to an effect in [ 0 , I ] H [0,I]_{\mathcal{H}} [ 0 , I ] H and wp ( S , F ) ∈ Pred ( H ) \operatorname{wp}(S,F) \in\operatorname{Pred}(\mathcal{H}) wp ( S , F ) ∈ Pred ( H ) is well defined. By trace duality and monotone convergence, the right-hand side of (B.12) equals
∑ n ≥ 0 s s + n tr ( F s + n ⟦ S ⟧ n ( ρ ) ) = ∑ n ≥ 0 s s + n tr ( ⟦ S ⟧ n † ( F s + n ) ρ ) = tr ( wp ( S , F ) s ρ ) . \sum_{n\ge0}\frac{s}{s+n}\operatorname{tr}(F_{s+n}\llbracket S\rrbracket_n(\rho))
=\sum_{n\ge0}\frac{s}{s+n}\operatorname{tr}(\llbracket S\rrbracket_n^\dagger(F_{s+n})\rho)
=\operatorname{tr}(\operatorname{wp}(S,F)_s\rho). n ≥ 0 ∑ s + n s tr ( F s + n [ [ S ] ] n ( ρ )) = n ≥ 0 ∑ s + n s tr ( [ [ S ] ] n † ( F s + n ) ρ ) = tr ( wp ( S , F ) s ρ ) .
Hence ⊨ t o t { A } S { F } \models_{\mathrm{tot}}\{A\}\ S\ \{F\} ⊨ tot { A } S { F } holds if and only if tr ( A s ρ ) ≤ tr ( wp ( S , F ) s ρ ) \operatorname{tr}(A_s\rho) \le\operatorname{tr}(\operatorname{wp}(S,F)_s\rho) tr ( A s ρ ) ≤ tr ( wp ( S , F ) s ρ ) for all ρ ∈ D ( H ) \rho\in\mathcal{D}(\mathcal{H}) ρ ∈ D ( H ) and s > 0 s > 0 s > 0 , which is equivalent to A ≤ wp ( S , F ) A \le\operatorname{wp}(S,F) A ≤ wp ( S , F ) . This establishes both validity and maximality. Monotonicity and preservation of increasing sequential suprema follow immediately from the normality of each adjoint map ⟦ S ⟧ n † \llbracket S\rrbracket_n^\dagger [ [ S ] ] n † .
We now verify the structural rules (C.2)–(C.7) using Definition B.1:
Basic commands. By (B.2)–(B.3), all runtime grades of abort vanish, while skip, initialization, and unitary updates are concentrated at grade n = 0 n=0 n = 0 with weight s s + 0 = 1 \frac{s}{s+0}=1 s + 0 s = 1 . This gives (C.2) and (C.4). For q : = ∣ 0 ⟩ q := \lvert0\rangle q := ∣ 0 ⟩ , writing R q ( ρ ) = ∣ 0 ⟩ ⟨ 0 ∣ q ⊗ tr q ( ρ ) = ∑ j ∣ 0 ⟩ ⟨ j ∣ q ρ ∣ j ⟩ ⟨ 0 ∣ q R_q(\rho)=\lvert0\rangle\langle0\rvert_q\otimes\operatorname{tr}_q(\rho)=\sum_j\lvert0\rangle\langle j\rvert_q\rho\lvert j\rangle\langle0\rvert_q R q ( ρ ) = ∣ 0 ⟩ ⟨ 0 ∣ q ⊗ tr q ( ρ ) = ∑ j ∣ 0 ⟩ ⟨ j ∣ q ρ ∣ j ⟩ ⟨ 0 ∣ q yields R q † ( F s ) = ∑ j ∣ j ⟩ ⟨ 0 ∣ q F s ∣ 0 ⟩ ⟨ j ∣ q R_q^\dagger(F_s)=\sum_j\lvert j\rangle\langle0\rvert_qF_s\lvert0\rangle\langle j\rvert_q R q † ( F s ) = ∑ j ∣ j ⟩ ⟨ 0 ∣ q F s ∣ 0 ⟩ ⟨ j ∣ q , proving (C.3).
Conditionals. Let S i f ≜ if ( □ i ∈ J M [ q ˉ ] = i → S i ) fi S_{\mathrm{if}}\mathrel{\triangleq}\operatorname{if}\left(\mathop{\square}_{i\in J}M[\bar q]=i\mathbin{\to}S_i\right)\operatorname{fi} S if ≜ if ( □ i ∈ J M [ q ˉ ] = i → S i ) fi . By (B.5), ⟦ S i f ⟧ n † = ∑ i ∈ J M i † ∘ ⟦ S i ⟧ n † \llbracket S_{\mathrm{if}}\rrbracket_n^\dagger=\sum_{i\in J}M_i^\dagger\circ\llbracket S_i\rrbracket_n^\dagger [ [ S if ] ] n † = ∑ i ∈ J M i † ∘ [ [ S i ] ] n † . Substituting this into (C.1) and interchanging the finite sum over i ∈ J i\in J i ∈ J with the strong sum over n ≥ 0 n\ge0 n ≥ 0 gives
wp ( S i f , F ) s = ∑ n ≥ 0 s s + n ∑ i ∈ J M i † ⟦ S i ⟧ n † ( F s + n ) M i = ∑ i ∈ J M i † wp ( S i , F ) s M i . \operatorname{wp}(S_{\mathrm{if}},F)_s
=\sum_{n\ge0}\frac{s}{s+n}\sum_{i\in J}M_i^\dagger\llbracket S_i\rrbracket_n^\dagger(F_{s+n})M_i
=\sum_{i\in J}M_i^\dagger\operatorname{wp}(S_i,F)_sM_i. wp ( S if , F ) s = n ≥ 0 ∑ s + n s i ∈ J ∑ M i † [ [ S i ] ] n † ( F s + n ) M i = i ∈ J ∑ M i † wp ( S i , F ) s M i .
Sequential composition. By (B.4), ⟦ S 1 ; S 2 ⟧ n † = ∑ a + b = n ⟦ S 1 ⟧ a † ∘ ⟦ S 2 ⟧ b † \llbracket S_1;S_2\rrbracket_n^\dagger=\sum_{a+b=n}\llbracket S_1\rrbracket_a^\dagger\circ\llbracket S_2\rrbracket_b^\dagger [ [ S 1 ; S 2 ] ] n † = ∑ a + b = n [ [ S 1 ] ] a † ∘ [ [ S 2 ] ] b † . Re-indexing the sum over n ≥ 0 n\ge0 n ≥ 0 as a double sum over a , b ≥ 0 a,b\ge0 a , b ≥ 0 with n = a + b n=a+b n = a + b and applying the scale-shift identity (B.11) with c = a c=a c = a and t = b t=b t = b , we obtain
wp ( S 1 ; S 2 , F ) s = ∑ a , b ≥ 0 s s + a s + a s + a + b ⟦ S 1 ⟧ a † ( ⟦ S 2 ⟧ b † ( F s + a + b ) ) . \operatorname{wp}(S_1;S_2,F)_s
=\sum_{a,b\ge0}\frac{s}{s+a}\frac{s+a}{s+a+b}\llbracket S_1\rrbracket_a^\dagger\left(\llbracket S_2\rrbracket_b^\dagger(F_{s+a+b})\right). wp ( S 1 ; S 2 , F ) s = a , b ≥ 0 ∑ s + a s s + a + b s + a [ [ S 1 ] ] a † ( [ [ S 2 ] ] b † ( F s + a + b ) ) .
Using the normality of ⟦ S 1 ⟧ a † \llbracket S_1\rrbracket_a^\dagger [ [ S 1 ] ] a † to bring it outside the positive strong sum over b ≥ 0 b\ge0 b ≥ 0 yields
wp ( S 1 ; S 2 , F ) s = ∑ a ≥ 0 s s + a ⟦ S 1 ⟧ a † ( wp ( S 2 , F ) s + a ) = wp ( S 1 , wp ( S 2 , F ) ) s . \operatorname{wp}(S_1;S_2,F)_s
=\sum_{a\ge0}\frac{s}{s+a}\llbracket S_1\rrbracket_a^\dagger(\operatorname{wp}(S_2,F)_{s+a})
=\operatorname{wp}(S_1,\operatorname{wp}(S_2,F))_s. wp ( S 1 ; S 2 , F ) s = a ≥ 0 ∑ s + a s [ [ S 1 ] ] a † ( wp ( S 2 , F ) s + a ) = wp ( S 1 , wp ( S 2 , F ) ) s .
While loops. Since wp ( B , ⋅ ) \operatorname{wp}(B,\mathord\cdot) wp ( B , ⋅ ) is monotone and preserves increasing sequential suprema, so does T F \mathcal{T}_F T F ; by Kleene’s fixed-point theorem on the ω \omega ω -CPO Pred ( H ) \operatorname{Pred}(\mathcal{H}) Pred ( H ) , the least fixed point of T F \mathcal{T}_F T F is sup N ≥ 0 T F N 0 \sup_{N\ge0}\mathcal{T}_F^N0 sup N ≥ 0 T F N 0 . Recall from (B.6) that C k = ⟦ B ⟧ k − 1 † ∘ M 1 C_k=\llbracket B\rrbracket_{k-1}^\dagger\circ M_1 C k = [ [ B ] ] k − 1 † ∘ M 1 for k ≥ 1 k\ge1 k ≥ 1 . Expanding wp ( B , X ) s + 1 \operatorname{wp}(B,X)_{s+1} wp ( B , X ) s + 1 via (C.1), setting k = m + 1 k=m+1 k = m + 1 , and applying (B.11) with c = 1 c=1 c = 1 and t = m t=m t = m , we can rewrite the continuation term of (C.7) as
s s + 1 M 1 † wp ( B , X ) s + 1 M 1 = ∑ m ≥ 0 s s + 1 + m M 1 † ⟦ B ⟧ m † ( X s + 1 + m ) M 1 = ∑ k ≥ 1 s s + k C k † ( X s + k ) . \frac{s}{s+1}M_1^\dagger\operatorname{wp}(B,X)_{s+1}M_1
=\sum_{m\ge0}\frac{s}{s+1+m}M_1^\dagger\llbracket B\rrbracket_m^\dagger(X_{s+1+m})M_1
=\sum_{k\ge1}\frac{s}{s+k}C_k^\dagger(X_{s+k}). s + 1 s M 1 † wp ( B , X ) s + 1 M 1 = m ≥ 0 ∑ s + 1 + m s M 1 † [ [ B ] ] m † ( X s + 1 + m ) M 1 = k ≥ 1 ∑ s + k s C k † ( X s + k ) .
An induction on N ≥ 0 N\ge0 N ≥ 0 , again using (B.11) and the normality of C k † C_k^\dagger C k † , shows that ( T F N 0 ) s (\mathcal{T}_F^N0)_s ( T F N 0 ) s sums all terminating unfoldings with fewer than N N N outer iterations:
( T F N 0 ) s = ∑ j = 0 N − 1 ∑ k 1 , … , k j ≥ 1 s s + k 1 + ⋯ + k j ( C k 1 † ∘ ⋯ ∘ C k j † ∘ M 1 † ) ( F s + k 1 + ⋯ + k j ) . (\mathcal{T}_F^N0)_s
=\sum_{j=0}^{N-1}\sum_{k_1,\ldots,k_j\ge1}
\frac{s}{s+k_1+\cdots+k_j}
\left(C_{k_1}^\dagger\circ\cdots\circ C_{k_j}^\dagger\circ M_1^\dagger\right)
(F_{s+k_1+\cdots+k_j}). ( T F N 0 ) s = j = 0 ∑ N − 1 k 1 , … , k j ≥ 1 ∑ s + k 1 + ⋯ + k j s ( C k 1 † ∘ ⋯ ∘ C k j † ∘ M 1 † ) ( F s + k 1 + ⋯ + k j ) .
Taking the strong supremum as N → ∞ N \to\infty N → ∞ and regrouping the positive terms by total runtime n = k 1 + ⋯ + k j n=k_1+\cdots+k_j n = k 1 + ⋯ + k j (so that 0 ≤ j ≤ n 0\le j\le n 0 ≤ j ≤ n ) recovers ∑ n ≥ 0 s s + n ⟦ L ⟧ n † ( F s + n ) = wp ( L , F ) s \sum_{n\ge0}\frac{s}{s+n}\llbracket L\rrbracket_n^\dagger(F_{s+n})=\operatorname{wp}(L,F)_s ∑ n ≥ 0 s + n s [ [ L ] ] n † ( F s + n ) = wp ( L , F ) s by (B.6). Thus wp ( L , F ) \operatorname{wp}(L,F) wp ( L , F ) is the least fixed point of T F T_F T F . □
Proposition C.3 (Weakest liberal preconditions). For every program S S S , let D S ≜ ( D S ) s > 0 ∈ Pred ( H ) D_S\triangleq(D_S)_{s>0}\in\operatorname{Pred}(\mathcal{H}) D S ≜ ( D S ) s > 0 ∈ Pred ( H ) denote the constant family given by the divergence effect D S = I − Q S D_S=I-Q_S D S = I − Q S in (B.7). Then for every F ∈ Pred ( H ) F\in\operatorname{Pred}(\mathcal{H}) F ∈ Pred ( H ) ,
wlp ( S , F ) = wp ( S , F ) + D S . (68) \operatorname{wlp}(S,F)=\operatorname{wp}(S,F)+D_S. \tag*{(68)} wlp ( S , F ) = wp ( S , F ) + D S . (68) The transformer wlp ( S , ⋅ ) : Pred ( H ) → Pred ( H ) \operatorname{wlp}(S,\mathord\cdot):\operatorname{Pred}(\mathcal{H})\to\operatorname{Pred}(\mathcal{H}) wlp ( S , ⋅ ) : Pred ( H ) → Pred ( H ) is monotone, preserves increasing sequential suprema, and satisfies
wlp ( skip , F ) s = F s , wlp ( abort , F ) s = I , (69) \operatorname{wlp}(\operatorname{skip},F)_s=F_s,\qquad\operatorname{wlp}(\operatorname{abort},F)_s=I, \tag*{(69)} wlp ( skip , F ) s = F s , wlp ( abort , F ) s = I , (69) wlp ( q : = ∣ 0 ⟩ , F ) s = ∑ j ∣ j ⟩ ⟨ 0 ∣ q F s ∣ 0 ⟩ ⟨ j ∣ q , wlp ( q ˉ : = U [ q ˉ ] , F ) s = U † F s U , (70) \operatorname{wlp}(q:=|0\rangle,F)_s=\sum_j |j\rangle\langle0|_qF_s|0\rangle\langle j|_q,\qquad\operatorname{wlp}(\bar q:=U[\bar q],F)_s=U^\dagger F_sU, \tag*{(70)} wlp ( q := ∣0 ⟩ , F ) s = j ∑ ∣ j ⟩ ⟨ 0 ∣ q F s ∣0 ⟩ ⟨ j ∣ q , wlp ( q ˉ := U [ q ˉ ] , F ) s = U † F s U , (70) wlp ( S i f , F ) s = ∑ i ∈ J M i † wlp ( S i , F ) s M i , (71) \operatorname{wlp}(S_{\mathrm{if}},F)_s=\sum_{i\in J}M_i^\dagger\operatorname{wlp}(S_i,F)_sM_i, \tag*{(71)} wlp ( S if , F ) s = i ∈ J ∑ M i † wlp ( S i , F ) s M i , (71) wlp ( S 1 ; S 2 , F ) s = wlp ( S 1 , wlp ( S 2 , F ) ) s + ⟦ S 1 ⟧ † ( D S 2 ) − wp ( S 1 , D S 2 ) s , (72) \operatorname{wlp}(S_1;S_2,F)_s=\operatorname{wlp}(S_1,\operatorname{wlp}(S_2,F))_s+\llbracket S_1\rrbracket^\dagger(D_{S_2})-\operatorname{wp}(S_1,D_{S_2})_s, \tag*{(72)} wlp ( S 1 ; S 2 , F ) s = wlp ( S 1 , wlp ( S 2 , F ) ) s + [ [ S 1 ] ] † ( D S 2 ) − wp ( S 1 , D S 2 ) s , (72) where S i f S_{\mathrm{if}} S if is the conditional in (C.5). Moreover, the correction term in (C.12) is positive:
⟦ S 1 ⟧ † ( D S 2 ) − wp ( S 1 , D S 2 ) s = ∑ n ≥ 0 n s + n ⟦ S 1 ⟧ n † ( D S 2 ) ≥ 0. (73) \llbracket S_1\rrbracket^\dagger(D_{S_2})-\operatorname{wp}(S_1,D_{S_2})_s=\sum_{n\ge0}\frac{n}{s+n}\llbracket S_1\rrbracket_n^\dagger(D_{S_2})\ge0. \tag*{(73)} [ [ S 1 ] ] † ( D S 2 ) − wp ( S 1 , D S 2 ) s = n ≥ 0 ∑ s + n n [ [ S 1 ] ] n † ( D S 2 ) ≥ 0. (73)
Proof. In (B.13), the nontermination term equals tr ( ρ ) − tr ( ⟦ S ⟧ ( ρ ) ) = tr ( D S ρ ) \operatorname{tr}(\rho)-\operatorname{tr}(\llbracket S\rrbracket(\rho))=\operatorname{tr}(D_S\rho) tr ( ρ ) − tr ( [ [ S ] ] ( ρ )) = tr ( D S ρ ) by (B.7), so trace duality gives wlp ( S , F ) = wp ( S , F ) + D S \operatorname{wlp}(S,F)=\operatorname{wp}(S,F)+D_S wlp ( S , F ) = wp ( S , F ) + D S . Since 0 ≤ wp ( S , F ) s ≤ Q S = I − D S 0\le\operatorname{wp}(S,F)_s\le Q_S=I-D_S 0 ≤ wp ( S , F ) s ≤ Q S = I − D S , this sum defines a valid effect family in Pred ( H ) \operatorname{Pred}(\mathcal{H}) Pred ( H ) , inheriting monotonicity and preservation of increasing suprema from wp ( S , ⋅ ) \operatorname{wp}(S,\mathord\cdot) wp ( S , ⋅ ) . Rules (C.9)–(C.10) follow from (C.2)–(C.4) because D abort = I D_{\operatorname{abort}}=I D abort = I whereas skip, initialization, and unitary updates have D S = 0 D_S=0 D S = 0 ; (C.11) follows from D S i f = ∑ i ∈ J M i † D S i M i D_{S_{\mathrm{if}}}=\sum_{i\in J}M_i^\dagger D_{S_i}M_i D S if = ∑ i ∈ J M i † D S i M i . For sequential composition, substituting D S 1 ; S 2 = D S 1 + ⟦ S 1 ⟧ † ( D S 2 ) D_{S_1;S_2}=D_{S_1}+\llbracket S_1\rrbracket^\dagger(D_{S_2}) D S 1 ; S 2 = D S 1 + [ [ S 1 ] ] † ( D S 2 ) and (C.6) into (C.8) at scale s s s gives
wlp ( S 1 ; S 2 , F ) s = wp ( S 1 , wp ( S 2 , F ) ) s + D S 1 + ⟦ S 1 ⟧ † ( D S 2 ) = wlp ( S 1 , wlp ( S 2 , F ) ) s + ⟦ S 1 ⟧ † ( D S 2 ) − wp ( S 1 , D S 2 ) s , \begin{aligned}
\operatorname{wlp}(S_1;S_2,F)_s=\operatorname{wp}(S_1,\operatorname{wp}(S_2,F))_s+D_{S_1}+\llbracket S_1\rrbracket^\dagger(D_{S_2}) \\
&=\operatorname{wlp}(S_1,\operatorname{wlp}(S_2,F))_s+\llbracket S_1\rrbracket^\dagger(D_{S_2})-\operatorname{wp}(S_1,D_{S_2})_s,
\end{aligned} wlp ( S 1 ; S 2 , F ) s = wp ( S 1 , wp ( S 2 , F ) ) s + D S 1 + [ [ S 1 ] ] † ( D S 2 ) = wlp ( S 1 , wlp ( S 2 , F ) ) s + [ [ S 1 ] ] † ( D S 2 ) − wp ( S 1 , D S 2 ) s ,
where the second equality uses the additivity of wp ( S 1 , ⋅ ) \operatorname{wp}(S_1,\mathord\cdot) wp ( S 1 , ⋅ ) in (C.1) together with wlp ( S 2 , F ) = wp ( S 2 , F ) + D S 2 \operatorname{wlp}(S_2,F)=\operatorname{wp}(S_2,F)+D_{S_2} wlp ( S 2 , F ) = wp ( S 2 , F ) + D S 2 and (C.8) for S 1 S_1 S 1 . Finally, expanding ⟦ S 1 ⟧ † ( D S 2 ) = ∑ n ≥ 0 ⟦ S 1 ⟧ n † ( D S 2 ) \llbracket S_1\rrbracket^\dagger(D_{S_2})=\sum_{n\ge0}\llbracket S_1\rrbracket_n^\dagger(D_{S_2}) [ [ S 1 ] ] † ( D S 2 ) = ∑ n ≥ 0 [ [ S 1 ] ] n † ( D S 2 ) and subtracting wp ( S 1 , D S 2 ) s \operatorname{wp}(S_1,D_{S_2})_s wp ( S 1 , D S 2 ) s gives (C.13). □
Combining the initialization and unitary rules with sequential composition also gives the derived rule for the state-preparation shorthand q : = ∣ ϕ ⟩ q:=|\phi\rangle q := ∣ ϕ ⟩ :
wp ( q : = ∣ ϕ ⟩ , F ) s = wlp ( q : = ∣ ϕ ⟩ , F ) s = ∑ j ∣ j ⟩ ⟨ ϕ ∣ q F s ∣ ϕ ⟩ ⟨ j ∣ q . \operatorname{wp}(q:=|\phi\rangle,F)_s=\operatorname{wlp}(q:=|\phi\rangle,F)_s=\sum_j|j\rangle\langle\phi|_qF_s|\phi\rangle\langle j|_q. wp ( q := ∣ ϕ ⟩ , F ) s = wlp ( q := ∣ ϕ ⟩ , F ) s = j ∑ ∣ j ⟩ ⟨ ϕ ∣ q F s ∣ ϕ ⟩ ⟨ j ∣ q .
In particular, resetting all registers to a pure state σ \sigma σ yields tr ( F s σ ) I \operatorname{tr}(F_s\sigma)I tr ( F s σ ) I , as used in Section F.
Specializing Theorem C.2 and Proposition C.3 to the terminal postcondition F = I F=I F = I defines the runtime resolvent family H S ≜ wp ( S , I ) ∈ Pred ( H ) H^S\triangleq\operatorname{wp}(S,I)\in\operatorname{Pred}(\mathcal{H}) H S ≜ wp ( S , I ) ∈ Pred ( H ) and its liberal counterpart L S ≜ wlp ( S , I ) ∈ Pred ( H ) L^S\triangleq\operatorname{wlp}(S,I)\in\operatorname{Pred}(\mathcal{H}) L S ≜ wlp ( S , I ) ∈ Pred ( H ) , given at each scale s > 0 s>0 s > 0 by
H s S ≜ wp ( S , I ) s = ∑ n ≥ 0 s s + n E n S . (74) H_s^S\triangleq\operatorname{wp}(S,I)_s=\sum_{n\ge0}\frac{s}{s+n}E_n^S. \tag*{(74)} H s S ≜ wp ( S , I ) s = n ≥ 0 ∑ s + n s E n S . (74)
L s S ≜ wlp ( S , I ) s = H s S + D S . (75) L_s^S\triangleq\operatorname{wlp}(S,I)_s=H_s^S+D_S. \tag*{(75)} L s S ≜ wlp ( S , I ) s = H s S + D S . (75)
By Lemma B.3, for a normalized input state ρ \rho ρ , tr ( H ρ S ) = P ρ ( τ S ≤ T S ) \operatorname{tr}(H^S_\rho)=\mathbb{P}_\rho(\tau_S\leq T_S) tr ( H ρ S ) = P ρ ( τ S ≤ T S ) is the probability that S S S terminates before the independent random deadline T S T_S T S , whereas tr ( L ρ S ) = P ρ ( τ S ≤ T S or τ S = ∞ ) \operatorname{tr}(L^S_\rho)=\mathbb{P}_\rho(\tau_S\leq T_S\text{ or }\tau_S=\infty) tr ( L ρ S ) = P ρ ( τ S ≤ T S or τ S = ∞ ) additionally includes nonterminating runs. Later Theorem D.1 will show that H S H^S H S increases strongly to Q S = I − D S Q_S=I-D_S Q S = I − D S as s → ∞ s\to\infty s → ∞ . Thus H S H^S H S determines D S D_S D S and L S L^S L S ; together with wp ( S , F ) \operatorname{wp}(S,F) wp ( S , F ) , it also determines wlp ( S , F ) \operatorname{wlp}(S,F) wlp ( S , F ) . The subsequent analysis therefore focuses on wp \operatorname{wp} wp and H S H^S H S .
Loop Unfolding and Residual Bounds
Theorem C.2 characterizes wp ( L , F ) \operatorname{wp}(L,F) wp ( L , F ) as the least fixed point of T F \mathcal{T}_F T F , but in applications one often works with finite unfoldings or asymptotic candidates rather than closed-form solutions. Both tasks require controlling how errors propagate under T F \mathcal{T}_F T F . In this subsection, we show that T F \mathcal{T}_F T F contracts boundary differences at each scale, ensuring uniqueness of the fixed point, and use this decay to bound the approximation error of a candidate family by its one-step residual.
Theorem C.4 (Loop unfolding and uniqueness). For every loop L L L as in (C.7), every F ∈ Pred ( H ) F\in\operatorname{Pred}(\mathcal{H}) F ∈ Pred ( H ) , and all X , Y ∈ Pred ( H ) X,Y\in\operatorname{Pred}(\mathcal{H}) X , Y ∈ Pred ( H ) ,
∥ ( T F N X ) s − ( T F N Y ) s ∥ ≤ s s + N ( s > 0 , N ∈ N ) . (76) \left\|(\mathcal{T}_F^N X)_s-(\mathcal{T}_F^N Y)_s\right\|\leq\frac{s}{s+N}\qquad(s>0,\ N\in\mathbb{N}). \tag*{(76)} ( T F N X ) s − ( T F N Y ) s ≤ s + N s ( s > 0 , N ∈ N ) . (76) For every X ∈ Pred ( H ) X\in\operatorname{Pred}(\mathcal{H}) X ∈ Pred ( H ) , ( T F N X ) s (\mathcal{T}_F^N X)_s ( T F N X ) s converges in operator norm to wp ( L , F ) s \operatorname{wp}(L,F)_s wp ( L , F ) s at each fixed s > 0 s>0 s > 0 . Consequently, X = T F X X=\mathcal{T}_F X X = T F X has exactly one solution in Pred ( H ) \operatorname{Pred}(\mathcal{H}) Pred ( H ) , namely wp ( L , F ) \operatorname{wp}(L,F) wp ( L , F ) .
Proof. For X , Y ∈ Pred ( H ) X,Y\in\operatorname{Pred}(\mathcal{H}) X , Y ∈ Pred ( H ) , subtracting (C.7) for X X X and Y Y Y cancels the exit term M 0 † F s M 0 M_0^{\dagger}F_sM_0 M 0 † F s M 0 ; expanding wp ( B , ⋅ ) s + 1 \operatorname{wp}(B,\cdot)_{s+1} wp ( B , ⋅ ) s + 1 via (C.1) and applying (B.11) gives the one-step difference formula
( T F X ) s − ( T F Y ) s = s s + 1 M 1 † ( wp ( B , X ) s + 1 − wp ( B , Y ) s + 1 ) M 1 = ∑ m ≥ 0 s s + 1 + m M 1 † ⟦ B ⟧ m † ( X s + 1 + m − Y s + 1 + m ) M 1 . (77) \begin{aligned}
(\mathcal{T}_F X)_s-(\mathcal{T}_F Y)_s
&=\frac{s}{s+1}M_1^{\dagger}\bigl(\operatorname{wp}(B,X)_{s+1}-\operatorname{wp}(B,Y)_{s+1}\bigr)M_1\\
&=\sum_{m\geq0}\frac{s}{s+1+m}M_1^{\dagger}\llbracket B\rrbracket_m^{\dagger}(X_{s+1+m}-Y_{s+1+m})M_1. \tag*{(77)}
\end{aligned} ( T F X ) s − ( T F Y ) s = s + 1 s M 1 † ( wp ( B , X ) s + 1 − wp ( B , Y ) s + 1 ) M 1 = m ≥ 0 ∑ s + 1 + m s M 1 † [ [ B ] ] m † ( X s + 1 + m − Y s + 1 + m ) M 1 . (77)
We prove (C.16) by induction on N N N . For N = 0 N=0 N = 0 , 0 ≤ X s , Y s ≤ I 0\leq X_s,Y_s\leq I 0 ≤ X s , Y s ≤ I implies − I ≤ X s − Y s ≤ I -I\leq X_s-Y_s\leq I − I ≤ X s − Y s ≤ I , so ∥ X s − Y s ∥ ≤ 1 = s s + 0 \left\|X_s-Y_s\right\|\leq1=\frac{s}{s+0} ∥ X s − Y s ∥ ≤ 1 = s + 0 s . Assume (C.16) holds for N N N , and set Δ u ( N ) ≔ ( T F N X ) u − ( T F N Y ) u \Delta_u^{(N)}\coloneqq(\mathcal{T}_F^N X)_u-(\mathcal{T}_F^N Y)_u Δ u ( N ) : = ( T F N X ) u − ( T F N Y ) u . At each shifted scale u = s + 1 + m u=s+1+m u = s + 1 + m , the induction hypothesis reads
− s + 1 + m s + 1 + m + N I ≤ Δ s + 1 + m ( N ) ≤ s + 1 + m s + 1 + m + N I . -\frac{s+1+m}{s+1+m+N}I\leq\Delta_{s+1+m}^{(N)}\leq\frac{s+1+m}{s+1+m+N}I. − s + 1 + m + N s + 1 + m I ≤ Δ s + 1 + m ( N ) ≤ s + 1 + m + N s + 1 + m I .
Since each map M 1 † ⟦ B ⟧ m † ( ⋅ ) M 1 M_1^{\dagger}\llbracket B\rrbracket_m^{\dagger}(\cdot)M_1 M 1 † [ [ B ] ] m † ( ⋅ ) M 1 is positive and
s s + 1 + m ⋅ s + 1 + m s + 1 + m + N = s s + 1 + m + N ≤ s s + N + 1 , \frac{s}{s+1+m}\cdot\frac{s+1+m}{s+1+m+N}=\frac{s}{s+1+m+N}\leq\frac{s}{s+N+1}, s + 1 + m s ⋅ s + 1 + m + N s + 1 + m = s + 1 + m + N s ≤ s + N + 1 s ,
∑ m ≥ 0 M 1 † ⟦ B ⟧ m † ( I ) M 1 = M 1 † Q B M 1 ≤ M 1 † M 1 ≤ I , \sum_{m\geq0}M_1^{\dagger}\llbracket B\rrbracket_m^{\dagger}(I)M_1=M_1^{\dagger}Q_BM_1\leq M_1^{\dagger}M_1\leq I, m ≥ 0 ∑ M 1 † [ [ B ] ] m † ( I ) M 1 = M 1 † Q B M 1 ≤ M 1 † M 1 ≤ I ,
applying (C.17) to T F N X \mathcal{T}_F^N X T F N X and T F N Y \mathcal{T}_F^N Y T F N Y yields − s s + N + 1 I ≤ Δ s ( N + 1 ) ≤ s s + N + 1 I -\frac{s}{s+N+1}I\leq\Delta_s^{(N+1)}\leq\frac{s}{s+N+1}I − s + N + 1 s I ≤ Δ s ( N + 1 ) ≤ s + N + 1 s I , which completes the induction.
By Theorem C.2, wp ( L , F ) \operatorname{wp}(L,F) wp ( L , F ) is a fixed point of T F \mathcal{T}_F T F . Taking Y = wp ( L , F ) Y=\operatorname{wp}(L,F) Y = wp ( L , F ) in (C.16) gives ∥ ( T F N X ) s − wp ( L , F ) s ∥ ≤ s s + N → 0 \left\|(\mathcal{T}_F^N X)_s-\operatorname{wp}(L,F)_s\right\|\leq\frac{s}{s+N}\to0 ( T F N X ) s − wp ( L , F ) s ≤ s + N s → 0 as N → ∞ N\to\infty N → ∞ . In particular, if X ∈ Pred ( H ) X\in\operatorname{Pred}(\mathcal{H}) X ∈ Pred ( H ) satisfies X = T F X X=\mathcal{T}_F X X = T F X , then X s = ( T F N X ) s → wp ( L , F ) s X_s=(\mathcal{T}_F^N X)_s\to\operatorname{wp}(L,F)_s X s = ( T F N X ) s → wp ( L , F ) s , so X = wp ( L , F ) X=\operatorname{wp}(L,F) X = wp ( L , F ) . □
To certify an approximate solution, we substitute a candidate family A A A into the loop equation and estimate its one-step residual A − T F A A-\mathcal{T}_F A A − T F A . Because truncated asymptotic expansions need not lie in [ 0 , I ] H [0,I]_{\mathcal{H}} [ 0 , I ] H , we evaluate (C.1) and (C.7) on uniformly bounded self-adjoint families by the same formulas. Note that if a candidate is uniformly bounded for s ≥ s 0 > 0 s\geq s_0>0 s ≥ s 0 > 0 , extending it boundedly to ( 0 , s 0 ) (0,s_0) ( 0 , s 0 ) does not affect its residual at scales s ≥ s 0 s\geq s_0 s ≥ s 0 , since (C.7) only queries larger scales.
Theorem C.5 (Certification of an asymptotic loop solution). For a loop L L L as in (C.7), a postcondition F ∈ Pred ( H ) F \in\operatorname{Pred}(\mathcal{H}) F ∈ Pred ( H ) , and a self-adjoint family A A A with sup s > 0 ∥ A s ∥ < ∞ \sup_{s>0}\lVert A_s\rVert< \infty sup s > 0 ∥ A s ∥ < ∞ , the approximation error satisfies
∥ A s − wp ( L , F ) s ∥ ≤ ∑ j ≥ 0 sup u ≥ s + j s u ∥ A u − ( T F A ) u ∥ ( s > 0 ) . (78) \lVert A_s-\operatorname{wp}(L,F)_s\rVert\le\sum_{j\ge0}\sup_{u\ge s+j}\frac{s}{u}\lVert A_u-(\mathcal{T}_F A)_u\rVert\qquad(s>0). \tag*{(78)} ∥ A s − wp ( L , F ) s ∥ ≤ j ≥ 0 ∑ u ≥ s + j sup u s ∥ A u − ( T F A ) u ∥ ( s > 0 ) . (78) Consequently, a residual ∥ A s − ( T F A ) s ∥ = O ( s − r − 1 ) \lVert A_s-(\mathcal{T}_F A)_s\rVert=O(s^{-r-1}) ∥ A s − ( T F A ) s ∥ = O ( s − r − 1 ) gives an error ∥ A s − wp ( L , F ) s ∥ = O ( s − r ) \lVert A_s-\operatorname{wp}(L,F)_s\rVert=O(s^{-r}) ∥ A s − wp ( L , F ) s ∥ = O ( s − r ) for every r > 0. I f , i n a d d i t i o n , t h e r e i s $ 0 ≤ κ < 1 r>0. If, in addition, there is \$0\le\kappa<1 r > 0. I f , ina dd i t i o n , t h er e i s $0 ≤ κ < 1 such that
u u + 1 M 1 † wp ( B , I ) u + 1 M 1 ≤ κ I ( u > 0 ) , \frac{u}{u+1}M_1^\dagger\operatorname{wp}(B,I)_{u+1}M_1\le\kappa I \qquad(u>0), u + 1 u M 1 † wp ( B , I ) u + 1 M 1 ≤ κ I ( u > 0 ) , then
sup u ≥ s ∥ A u − wp ( L , F ) u ∥ ≤ 1 1 − κ sup u ≥ s ∥ A u − ( T F A ) u ∥ . (79) \sup_{u\ge s}\lVert A_u-\operatorname{wp}(L,F)_u\rVert\le\frac{1}{1-\kappa}\sup_{u\ge s}\lVert A_u-(\mathcal{T}_F A)_u\rVert. \tag*{(79)} u ≥ s sup ∥ A u − wp ( L , F ) u ∥ ≤ 1 − κ 1 u ≥ s sup ∥ A u − ( T F A ) u ∥ . (79) In this case a residual O ( s − r ) O(s^{-r}) O ( s − r ) gives an error of the same order. Both rate statements also hold with o o o in place of O O O .
Proof. The proof combines a bound on the propagation of differences with a telescoping sum of one-step residuals. Firstly, for any uniformly bounded self-adjoint families X X X , Y Y Y , we prove by induction on j ≥ 0 j\ge0 j ≥ 0 that
∥ ( T F j X ) s − ( T F j Y ) s ∥ ≤ sup u ≥ s + j s u ∥ X u − Y u ∥ ( s > 0 ) . (80) \lVert(\mathcal{T}_F^jX)_s-(\mathcal{T}_F^jY)_s\rVert\le\sup_{u\ge s+j}\frac{s}{u}\lVert X_u-Y_u\rVert\qquad(s>0). \tag*{(80)} ∥( T F j X ) s − ( T F j Y ) s ∥ ≤ u ≥ s + j sup u s ∥ X u − Y u ∥ ( s > 0 ) . (80)
The case j = 0 j=0 j = 0 holds trivially since the supremum includes u = s u=s u = s , where s u = 1 \frac{s}{u}=1 u s = 1 . Assuming (C.20) for j j j , its bound at the shifted scale s + 1 + m s+1+m s + 1 + m gives
s s + 1 + m ∥ ( T F j X ) s + 1 + m − ( T F j Y ) s + 1 + m ∥ ≤ s s + 1 + m sup u ≥ s + 1 + m + j s + 1 + m u ∥ X u − Y u ∥ ≤ sup u ≥ s + j + 1 s u ∥ X u − Y u ∥ . \begin{aligned}
\frac{s}{s+1+m}\lVert(\mathcal{T}_F^jX)_{s+1+m}-(\mathcal{T}_F^jY)_{s+1+m}\rVert
\le\frac{s}{s+1+m}\sup_{u\ge s+1+m+j}\frac{s+1+m}{u}\lVert X_u-Y_u\rVert\\
&\le\sup_{u\ge s+j+1}\frac{s}{u}\lVert X_u-Y_u\rVert.
\end{aligned} s + 1 + m s ∥( T F j X ) s + 1 + m − ( T F j Y ) s + 1 + m ∥ ≤ s + 1 + m s u ≥ s + 1 + m + j sup u s + 1 + m ∥ X u − Y u ∥ ≤ u ≥ s + j + 1 sup u s ∥ X u − Y u ∥ .
Substituting this operator-norm bound into (C.17) and using ∑ m ≥ 0 M 1 † m ( I ) M 1 ≤ I \sum_{m\ge0}M_1^{\dagger m}(I)M_1\le I ∑ m ≥ 0 M 1 † m ( I ) M 1 ≤ I proves (C.20) for j + 1 j+1 j + 1 .
Taking X = A X=A X = A and Y = wp ( L , F ) Y=\operatorname{wp}(L,F) Y = wp ( L , F ) in (C.20) gives ∥ ( T F N A ) s − wp ( L , F ) s ∥ ≤ s s + N sup u ≥ s + N ∥ A u − wp ( L , F ) u ∥ → 0 \lVert(\mathcal{T}_F^N A)_s-\operatorname{wp}(L,F)_s\rVert\le\frac{s}{s+N}\sup_{u\ge s+N}\lVert A_u-\operatorname{wp}(L,F)_u\rVert\to0 ∥( T F N A ) s − wp ( L , F ) s ∥ ≤ s + N s sup u ≥ s + N ∥ A u − wp ( L , F ) u ∥ → 0 as N → ∞ N\to\infty N → ∞ . Applying (C.20) with X = A X=A X = A and Y = T F A Y=\mathcal{T}_F A Y = T F A to each term of the telescoping sum
A s − ( T F N A ) s = ∑ j = 0 N − 1 ( ( T F j A ) s − ( T F j ( T F A ) ) s ) A_s-(\mathcal{T}_F^N A)_s=\sum_{j=0}^{N-1}\left((\mathcal{T}_F^j A)_s-(\mathcal{T}_F^j(\mathcal{T}_F A))_s\right) A s − ( T F N A ) s = j = 0 ∑ N − 1 ( ( T F j A ) s − ( T F j ( T F A ) ) s )
and letting N → ∞ e s t a b l i s h e s x r e f ‘ ( C .18 ) ‘ . I f N\to\infty establishes {xref}`(C.18)`. If N → ∞ es t ab l i s h es x r e f ‘ ( C .18 ) ‘. I f \lVert A_u-(\mathcal{T}_F A)_u\rVert\le Cu^{-r-1}$ for large u u u , then sup u ≥ s + j ∥ A u − ( T F A ) u ∥ ≤ C s − r − 2 ( s + j ) − r − 2 \sup_{u\ge s+j}\lVert A_u-(\mathcal{T}_F A)_u\rVert\le Cs^{-r-2}(s+j)^{-r-2} sup u ≥ s + j ∥ A u − ( T F A ) u ∥ ≤ C s − r − 2 ( s + j ) − r − 2 , and summing over j ≥ 0 j\ge0 j ≥ 0 yields C ∑ j ≥ 0 s ( s + j ) − r − 2 = O ( s − r ) C\sum_{j\ge0}s(s+j)^{-r-2}=O(s^{-r}) C ∑ j ≥ 0 s ( s + j ) − r − 2 = O ( s − r ) .
Now assume the contraction condition with κ < 1 \kappa<1 κ < 1 . Fix s > 0 s>0 s > 0 and set e s ≔ sup v ≥ s ∥ A v − wp ( L , F ) v ∥ < ∞ e_s\coloneqq\sup_{v\ge s}\lVert A_v-\operatorname{wp}(L,F)_v\rVert<\infty e s : = sup v ≥ s ∥ A v − wp ( L , F ) v ∥ < ∞ . For every u ≥ s u\ge s u ≥ s and m ≥ 0 m\ge0 m ≥ 0 , we have u + 1 + m ≥ s u+1+m\ge s u + 1 + m ≥ s and hence − e s I ≤ A u + 1 + m − wp ( L , F ) u + 1 + m ≤ e s I -e_sI\le A_{u+1+m}-\operatorname{wp}(L,F)_{u+1+m}\le e_sI − e s I ≤ A u + 1 + m − wp ( L , F ) u + 1 + m ≤ e s I . Applying the positive map wp ( B , ⋅ ) u + 1 \operatorname{wp}(B,\cdot)_{u+1} wp ( B , ⋅ ) u + 1 in (C.1) gives
− e s wp ( B , I ) u + 1 ≤ wp ( B , A ) u + 1 − wp ( B , wp ( L , F ) ) u + 1 ≤ e s wp ( B , I ) u + 1 . -e_s\operatorname{wp}(B,I)_{u+1}\le\operatorname{wp}(B,A)_{u+1}-\operatorname{wp}(B,\operatorname{wp}(L,F))_{u+1}\le e_s\operatorname{wp}(B,I)_{u+1}. − e s wp ( B , I ) u + 1 ≤ wp ( B , A ) u + 1 − wp ( B , wp ( L , F ) ) u + 1 ≤ e s wp ( B , I ) u + 1 .
By (C.17) and T F ( wp ( L , F ) ) = wp ( L , F ) \mathcal{T}_{F}(\operatorname{wp}(L,F))=\operatorname{wp}(L,F) T F ( wp ( L , F )) = wp ( L , F ) , conjugating by M 1 M_{1} M 1 and multiplying by u u + 1 \frac{u}{u+1} u + 1 u yields
∥ ( T F A ) u − wp ( L , F ) u ∥ = ∥ u u + 1 M 1 † ( wp ( B , A ) u + 1 − wp ( B , wp ( L , F ) ) u + 1 ) M 1 ∥ ≤ e s ∥ u u + 1 M 1 † wp ( B , I ) u + 1 M 1 ∥ ≤ κ e s . \begin{aligned}
\left\lVert(\mathcal{T}_{F}A)_{u}-\operatorname{wp}(L,F)_{u}\right\rVert
&=\left\lVert\frac{u}{u+1}M_{1}^{\dagger}\left(\operatorname{wp}(B,A)_{u+1}-\operatorname{wp}(B,\operatorname{wp}(L,F))_{u+1}\right)M_{1}\right\rVert\\
&\leq e_{s}\left\lVert\frac{u}{u+1}M_{1}^{\dagger}\operatorname{wp}(B,I)_{u+1}M_{1}\right\rVert\\
&\leq\kappa e_{s}.
\end{aligned} ∥ ( T F A ) u − wp ( L , F ) u ∥ = u + 1 u M 1 † ( wp ( B , A ) u + 1 − wp ( B , wp ( L , F ) ) u + 1 ) M 1 ≤ e s u + 1 u M 1 † wp ( B , I ) u + 1 M 1 ≤ κ e s .
Taking the supremum over u ≥ s u\geq s u ≥ s and using the triangle inequality A u − wp ( L , F ) u = ( A u − ( T F A ) u ) + ( ( T F A ) u − wp ( L , F ) u ) A_{u}-\operatorname{wp}(L,F)_{u}=(A_{u}-(\mathcal{T}_{F}A)_{u})+((\mathcal{T}_{F}A)_{u}-\operatorname{wp}(L,F)_{u}) A u − wp ( L , F ) u = ( A u − ( T F A ) u ) + (( T F A ) u − wp ( L , F ) u ) gives e s ≤ sup u ≥ s ∥ A u − ( T F A ) u ∥ + κ e s e_{s}\leq\sup_{u\geq s}\lVert A_{u}-(\mathcal{T}_{F}A)_{u}\rVert+\kappa e_{s} e s ≤ sup u ≥ s ∥ A u − ( T F A ) u ∥ + κ e s , which rearranges to (C.19). Finally, the little-o o o statements follow by applying the same bounds with arbitrarily small tail constants as s → ∞ s\to\infty s → ∞ . □
Extracting Termination Probabilities, Moments, and Divergence Rates
The compositional calculus and loop rules of Section C do not compute the runtime observables of Section B.2 directly; instead, for a program S S S , they characterize the runtime operator family H s S = wp ( S , I ) s H^{S}_{s}=\operatorname{wp}(S,I)_{s} H s S = wp ( S , I ) s either exactly or through operator-norm approximations (Theorem C.5 ). Because the operator norm directly bounds the error in expectation for any normalized input state ρ \rho ρ , an operator-norm approximation whose error decays sufficiently fast as s → ∞ s\to\infty s → ∞ yields the asymptotic expansion of tr ( ρ H s S ) \operatorname{tr}(\rho H^{S}_{s}) tr ( ρ H s S ) to the desired order. This section shows how to recover the operational runtime properties of S S S from the large-s s s behavior of H s S H^{S}_{s} H s S . Specifically, we recover termination probabilities in Section D.1, finite runtime moments on terminating runs in Section D.2, and divergence rates of truncated moments in Section D.3. In each subsection, we show how to obtain the target quantities both directly from the operator family H s S H^{S}_{s} H s S and from the asymptotic expansion of tr ( ρ H s S ) \operatorname{tr}(\rho H^{S}_{s}) tr ( ρ H s S ) as s → ∞ s\to\infty s → ∞ .
Termination Probabilities
As the parameter s s s tends to infinity, the rational weights s s + n \frac{s}{s+n} s + n s approach 1 1 1 for every runtime n n n . Consequently, the large-s s s limit of H s S H^{S}_{s} H s S recovers the total weight of all terminating executions, which appears as the leading constant term in the asymptotic expansion of tr ( ρ H s S ) \operatorname{tr}(\rho H^{S}_{s}) tr ( ρ H s S ) .
Theorem D.1 (Termination probability from the exact family). For every program S S S , as s → ∞ s\to\infty s → ∞ , the family H s S H^{S}_{s} H s S increases monotonically with respect to the Löwner order and converges in the strong operator topology to Q S Q_{S} Q S :
lim s → ∞ H s S = Q S , D S = I − lim s → ∞ H s S . (81) \lim_{s\to\infty}H^{S}_{s}=Q_{S},\qquad D_{S}=I-\lim_{s\to\infty}H^{S}_{s}. \tag*{(81)} s → ∞ lim H s S = Q S , D S = I − s → ∞ lim H s S . (81) Consequently, for any normalized input state ρ \rho ρ , the termination probability is tr ( ρ Q S ) = lim s → ∞ tr ( ρ H s S ) \operatorname{tr}(\rho Q_{S})=\lim_{s\to\infty}\operatorname{tr}(\rho H^{S}_{s}) tr ( ρ Q S ) = lim s → ∞ tr ( ρ H s S ) , and the divergence probability is tr ( ρ D S ) = 1 − lim s → ∞ tr ( ρ H s S ) \operatorname{tr}(\rho D_{S})=1-\lim_{s\to\infty}\operatorname{tr}(\rho H^{S}_{s}) tr ( ρ D S ) = 1 − lim s → ∞ tr ( ρ H s S ) .
Proof. For each n ≥ 0 n\geq0 n ≥ 0 , the weight s s + n \frac{s}{s+n} s + n s increases monotonically to 1 1 1 as s → ∞ s\to\infty s → ∞ . Since H s S = ∑ n = 0 ∞ s s + n E n S H^{S}_{s}=\sum_{n=0}^{\infty}\frac{s}{s+n}E^{S}_{n} H s S = ∑ n = 0 ∞ s + n s E n S and ∑ n = 0 ∞ E n S = Q S ≤ I \sum_{n=0}^{\infty}E^{S}_{n}=Q_{S}\leq I ∑ n = 0 ∞ E n S = Q S ≤ I , monotone convergence for bounded positive operators yields the strong operator limits in (D.1), and the trace identities follow immediately. □
Theorem D.2 (Termination probability from the leading asymptotic constant). If a normalized input state ρ \rho ρ satisfies tr ( ρ H s S ) = a 0 + o ( 1 ) \operatorname{tr}(\rho H^{S}_{s})=a_{0}+o(1) tr ( ρ H s S ) = a 0 + o ( 1 ) as s → ∞ s\to\infty s → ∞ , then the termination and divergence probabilities of S S S on ρ \rho ρ are tr ( ρ Q S ) = a 0 \operatorname{tr}(\rho Q_{S})=a_{0} tr ( ρ Q S ) = a 0 and tr ( ρ D S ) = 1 − a 0 \operatorname{tr}(\rho D_{S})=1-a_{0} tr ( ρ D S ) = 1 − a 0 , respectively.
Runtime Moments on Terminating Runs
Beyond termination probabilities, the exact family H s S H^{S}_{s} H s S determines every successful runtime moment M k S M^{S}_{k} M k S of integer order through a positive k k k -th order finite difference across rescaled parameters s / j s/j s / j , whereas in the asymptotic expansion of tr ( ρ H s S ) \operatorname{tr}(\rho H^S_s) tr ( ρ H s S ) as s → ∞ s \to\infty s → ∞ , the finite moments tr ( ρ M j S ) \operatorname{tr}(\rho M^S_j) tr ( ρ M j S ) appear as the coefficients of ( − s ) − j (-s)^{-j} ( − s ) − j .
Theorem D.3 (Moments from finite differences of the exact family). For every integer k ≥ 1 k \ge1 k ≥ 1 and parameter s > 0 s > 0 s > 0 , the finite-difference operator
B k S ( s ) ≔ s k k ! [ Q S + ∑ j = 1 k ( − 1 ) j ( k j ) H s / j S ] (82) B^S_k(s) \coloneqq\frac{s^k}{k!}\left[Q_S+\sum_{j=1}^{k}(-1)^j\binom{k}{j}H^S_{s/j}\right] \tag*{(82)} B k S ( s ) : = k ! s k [ Q S + j = 1 ∑ k ( − 1 ) j ( j k ) H s / j S ] (82) is a bounded positive operator admitting the series representation
B k S ( s ) = ∑ n = 0 ∞ n k [ ∏ j = 1 k s s + j n ] E n S . (83) B^S_k(s)=\sum_{n=0}^{\infty}n^k\left[\prod_{j=1}^{k}\frac{s}{s+jn}\right]E^S_n. \tag*{(83)} B k S ( s ) = n = 0 ∑ ∞ n k [ j = 1 ∏ k s + j n s ] E n S . (83) As s → ∞ s \to\infty s → ∞ , the quadratic forms of B k S ( s ) B^S_k(s) B k S ( s ) increase monotonically to the quadratic form of M k S M^S_k M k S . Consequently, for every normalized input state ρ \rho ρ ,
tr ( ρ M k S ) = lim s → ∞ tr ( ρ B k S ( s ) ) ∈ [ 0 , ∞ ] , (84) \operatorname{tr}(\rho M^S_k)=\lim_{s\to\infty}\operatorname{tr}(\rho B^S_k(s))\in[0,\infty], \tag*{(84)} tr ( ρ M k S ) = s → ∞ lim tr ( ρ B k S ( s )) ∈ [ 0 , ∞ ] , (84) and tr ( ρ M k S ) \operatorname{tr}(\rho M^S_k) tr ( ρ M k S ) is finite if and only if tr ( ρ B k S ( s ) ) \operatorname{tr}(\rho B^S_k(s)) tr ( ρ B k S ( s )) remains bounded as s → ∞ s \to\infty s → ∞ .
Proof. Expanding the rational function ∏ j = 1 k ( u + j ) − 1 \prod_{j=1}^{k}(u+j)^{-1} ∏ j = 1 k ( u + j ) − 1 into partial fractions in u u u and substituting u = 1 / x u=1/x u = 1/ x yields the identity
1 k ! [ 1 + ∑ j = 1 k ( − 1 ) j ( k j ) 1 1 + j x ] = x k ∏ j = 1 k ( 1 + j x ) \frac{1}{k!}\left[1+\sum_{j=1}^{k}(-1)^j\binom{k}{j}\frac{1}{1+jx}\right]=\frac{x^k}{\prod_{j=1}^{k}(1+jx)} k ! 1 [ 1 + j = 1 ∑ k ( − 1 ) j ( j k ) 1 + j x 1 ] = ∏ j = 1 k ( 1 + j x ) x k ( x ≥ 0 ) (x \ge0) ( x ≥ 0 ) .
Setting x = n / s x=n/s x = n / s , multiplying by s k E n S s^kE^S_n s k E n S , and summing over n ≥ 0 n \ge0 n ≥ 0 gives (D.3). For each n ≥ 0 n \ge0 n ≥ 0 , the weight n k ∏ j = 1 k s s + j n n^k\prod_{j=1}^{k}\frac{s}{s+jn} n k ∏ j = 1 k s + j n s is bounded above by s k k ! \frac{s^k}{k!} k ! s k and increases monotonically to n k n^k n k as s → ∞ s \to\infty s → ∞ . Monotone convergence therefore yields the form limit M k S M^S_k M k S and the trace identity (D.4). □
Theorem D.4 (Moments from asymptotic coefficients). Let M 0 S ≔ Q S M^S_0 \coloneqq Q_S M 0 S : = Q S . For any integer k ≥ 1 k \ge1 k ≥ 1 and normalized input state ρ \rho ρ , the moment tr ( ρ M k S ) \operatorname{tr}(\rho M^S_k) tr ( ρ M k S ) is finite if and only if there exist real coefficients a 0 , … , a k a_0,\ldots,a_k a 0 , … , a k such that, as s → ∞ s \to\infty s → ∞ ,
tr ( ρ H s S ) = ∑ j = 0 k ( − 1 ) j a j s j + o ( s − k ) . (85) \operatorname{tr}(\rho H^S_s)=\sum_{j=0}^{k}\frac{(-1)^j a_j}{s^j}+o(s^{-k}). \tag*{(85)} tr ( ρ H s S ) = j = 0 ∑ k s j ( − 1 ) j a j + o ( s − k ) . (85) Whenever this expansion holds, the coefficients are given by a j = tr ( ρ M j S ) a_j=\operatorname{tr}(\rho M^S_j) a j = tr ( ρ M j S ) for all 0 ≤ j ≤ k 0 \le j \le k 0 ≤ j ≤ k .
Proof. Write p n ≔ tr ( ρ E n S ) p_n\coloneqq\operatorname{tr}(\rho E^S_n) p n : = tr ( ρ E n S ) . Applying the finite geometric series identity
1 1 + x = ∑ j = 0 m − 1 ( − x ) j + ( − x ) m 1 + x \frac{1}{1+x}=\sum_{j=0}^{m-1}(-x)^j+\frac{(-x)^m}{1+x} 1 + x 1 = j = 0 ∑ m − 1 ( − x ) j + 1 + x ( − x ) m at x = n / s x=n/s x = n / s and summing against p n p_n p n shows that for any integer m ≥ 1 m \ge1 m ≥ 1 with tr ( ρ M m − 1 S ) < ∞ \operatorname{tr}(\rho M^S_{m-1})<\infty tr ( ρ M m − 1 S ) < ∞ ,
tr ( ρ H s S ) = ∑ j = 0 m − 1 ( − 1 ) j tr ( ρ M j S ) s j + ( − 1 ) m s m ∑ n = 0 ∞ s n m s + n p n . (86) \operatorname{tr}(\rho H^S_s)=\sum_{j=0}^{m-1}\frac{(-1)^j\operatorname{tr}(\rho M^S_j)}{s^j}+\frac{(-1)^m}{s^m}\sum_{n=0}^{\infty}\frac{s n^m}{s+n}p_n. \tag*{(86)} tr ( ρ H s S ) = j = 0 ∑ m − 1 s j ( − 1 ) j tr ( ρ M j S ) + s m ( − 1 ) m n = 0 ∑ ∞ s + n s n m p n . (86) The remainder sum ∑ n = 0 ∞ s n m s + n p n \sum_{n=0}^{\infty}\frac{s n^m}{s+n}p_n ∑ n = 0 ∞ s + n s n m p n is bounded by s tr ( ρ M m − 1 S ) < ∞ s\operatorname{tr}(\rho M^S_{m-1})<\infty s tr ( ρ M m − 1 S ) < ∞ and increases monotonically to tr ( ρ M m S ) \operatorname{tr}(\rho M^S_m) tr ( ρ M m S ) as s → ∞ s \to\infty s → ∞ . If tr ( ρ M k S ) < ∞ \operatorname{tr}(\rho M^S_k)<\infty tr ( ρ M k S ) < ∞ , taking m = k m=k m = k in (D.6) and applying dominated convergence to the k k k -th term yields (D.5) with a j = tr ( ρ M j S ) a_j=\operatorname{tr}(\rho M^S_j) a j = tr ( ρ M j S ) .
Conversely, suppose (D.5) holds. Theorem D.2 gives a 0 = tr ( ρ Q S ) = tr ( ρ M 0 S ) a_0 = \operatorname{tr}(\rho Q_S) = \operatorname{tr}(\rho M^S_0) a 0 = tr ( ρ Q S ) = tr ( ρ M 0 S ) . Proceeding by induction on m ∈ { 1 , … , k } m \in\{1,\ldots,k\} m ∈ { 1 , … , k } , once a j = tr ( ρ M j S ) < ∞ a_j = \operatorname{tr}(\rho M^S_j) < \infty a j = tr ( ρ M j S ) < ∞ has been established for all j < m j < m j < m , comparing (D.5) with (D.6) shows that
∑ n = 0 ∞ s n m s + n p n = a m + o ( 1 ) ( s → ∞ ) . \sum_{n=0}^{\infty} \frac{s n^m}{s+n}p_n = a_m + o(1) \qquad(s \to\infty). n = 0 ∑ ∞ s + n s n m p n = a m + o ( 1 ) ( s → ∞ ) .
By monotone convergence as s → ∞ s \to\infty s → ∞ , the left-hand side converges to tr ( ρ M m S ) \operatorname{tr}(\rho M^S_m) tr ( ρ M m S ) , whence tr ( ρ M m S ) = a m < ∞ \operatorname{tr}(\rho M^S_m) = a_m < \infty tr ( ρ M m S ) = a m < ∞ . □
Because M r S = ∑ n = 0 ∞ n r E n S M^S_r = \sum_{n=0}^{\infty} n^r E^S_n M r S = ∑ n = 0 ∞ n r E n S sums only over finite runtimes, its expectation tr ( ρ M r S ) = ∑ n = 0 ∞ n r tr ( ρ E n S ) = E ρ [ τ S r 1 { τ S < ∞ } ] \operatorname{tr}(\rho M^S_r) = \sum_{n=0}^{\infty} n^r\operatorname{tr}(\rho E^S_n) = \mathbb{E}_{\rho}[\tau_S^r 1_{\{\tau_S<\infty\}}] tr ( ρ M r S ) = ∑ n = 0 ∞ n r tr ( ρ E n S ) = E ρ [ τ S r 1 { τ S < ∞ } ] is the r r r -th runtime moment restricted to terminating runs. When the termination probability tr ( ρ Q S ) \operatorname{tr}(\rho Q_S) tr ( ρ Q S ) is strictly positive, conditioning on the event { τ S < ∞ } \{\tau_S < \infty\} { τ S < ∞ } normalizes the runtime distribution to P ρ ( τ S = n ∣ τ S < ∞ ) = tr ( ρ E n S ) tr ( ρ Q S ) \mathbb{P}_{\rho}(\tau_S = n \mid\tau_S < \infty) = \frac{\operatorname{tr}(\rho E^S_n)}{\operatorname{tr}(\rho Q_S)} P ρ ( τ S = n ∣ τ S < ∞ ) = tr ( ρ Q S ) tr ( ρ E n S ) , so the conditional r r r -th moment given termination is
E ρ [ τ S r ∣ τ S < ∞ ] = tr ( ρ M r S ) tr ( ρ Q S ) . \mathbb{E}_{\rho}[\tau_S^r \mid\tau_S < \infty] = \frac{\operatorname{tr}(\rho M^S_r)}{\operatorname{tr}(\rho Q_S)}. E ρ [ τ S r ∣ τ S < ∞ ] = tr ( ρ Q S ) tr ( ρ M r S ) .
By contrast, the total runtime form C S = M 1 S + ∞ D S C_S = M^S_1 + \infty D_S C S = M 1 S + ∞ D S assigns infinite cost to nonterminating runs; it is recovered as the s → ∞ s \to\infty s → ∞ monotone form limit of the bounded positive operators s ( I − H s S ) s(I-H^S_s) s ( I − H s S ) , yielding the unconditional expected runtime
s ( I − H s S ) = s D S + B 1 S ( s ) , E ρ [ τ S ] = tr ( ρ C S ) = lim s → ∞ s ( 1 − tr ( ρ H s S ) ) . (87) s(I-H^S_s) = sD_S + B^S_1(s), \qquad\mathbb{E}_{\rho}[\tau_S] = \operatorname{tr}(\rho C_S) = \lim_{s\to\infty}s(1-\operatorname{tr}(\rho H^S_s)). \tag*{(87)} s ( I − H s S ) = s D S + B 1 S ( s ) , E ρ [ τ S ] = tr ( ρ C S ) = s → ∞ lim s ( 1 − tr ( ρ H s S )) . (87)
Divergence Rates of Truncated Moments
When tr ( ρ M r S ) = ∞ \operatorname{tr}(\rho M^S_r) = \infty tr ( ρ M r S ) = ∞ for a given input state ρ \rho ρ , taking the limit s → ∞ s \to\infty s → ∞ only indicates divergence. To quantify the rate of divergence as the truncation threshold N > 0 N > 0 N > 0 grows, we consider the bounded truncated (or capped) moment operators
M ~ r S ( N ) ≜ ∑ n = 0 ∞ min ( n , N ) r E n S ( r > 0 , N > 0 ) . (88) \widetilde{M}^S_r(N) \triangleq\sum_{n=0}^{\infty} \min(n,N)^r E^S_n \qquad(r > 0,\ N > 0). \tag*{(88)} M r S ( N ) ≜ n = 0 ∑ ∞ min ( n , N ) r E n S ( r > 0 , N > 0 ) . (88)
As N → ∞ N \to\infty N → ∞ , the expectation tr ( ρ M ~ r S ( N ) ) \operatorname{tr}(\rho\widetilde{M}^S_r(N)) tr ( ρ M r S ( N )) either converges to tr ( ρ M r S ) \operatorname{tr}(\rho M^S_r) tr ( ρ M r S ) when the r r r -th moment on ρ \rho ρ is finite, or diverges at a rate governed by the tail of the terminating runtime distribution when the moment is infinite.
For the exact family H s S H^S_s H s S , evaluating the finite-difference operator B k S ( s ) B^S_k(s) B k S ( s ) directly at s = N s = N s = N already captures the asymptotic growth order of M ~ k S ( N ) \widetilde{M}^S_k(N) M k S ( N ) up to constant factors.
Theorem D.5 (Divergence rates from the exact family). For every integer k ≥ 1 k \ge1 k ≥ 1 and truncation threshold N > 0 N > 0 N > 0 , the finite-difference operator B k S ( N ) B^S_k(N) B k S ( N ) in (D.2) satisfies the two-sided operator inequality
1 ( k + 1 ) ! M ~ k S ( N ) ≤ B k S ( N ) ≤ M ~ k S ( N ) . (89) \frac{1}{(k+1)!}\widetilde{M}^S_k(N) \le B^S_k(N) \le\widetilde{M}^S_k(N). \tag*{(89)} ( k + 1 )! 1 M k S ( N ) ≤ B k S ( N ) ≤ M k S ( N ) . (89) Consequently, tr ( ρ M ~ k S ( N ) ) \operatorname{tr}(\rho\widetilde{M}^S_k(N)) tr ( ρ M k S ( N )) and tr ( ρ B k S ( N ) ) \operatorname{tr}(\rho B^S_k(N)) tr ( ρ B k S ( N )) have the same asymptotic order of growth as N → ∞ N \to\infty N → ∞ up to constant factors.
Proof. In the series representation (D.3) at s = N s = N s = N , the n n n -th weight is w n ( N ) ≜ n k ∏ j = 1 k N N + j n w_n(N) \triangleq n^k \prod_{j=1}^{k}\frac{N}{N+jn} w n ( N ) ≜ n k ∏ j = 1 k N + j n N . For n ≤ N n \le N n ≤ N , each factor N N + j n \frac{N}{N+jn} N + j n N lies in [ 1 j + 1 , 1 ] \left[\frac{1}{j+1},1\right] [ j + 1 1 , 1 ] , so n k ( k + 1 ) ! ≤ w n ( N ) ≤ n k \frac{n^k}{(k+1)!} \le w_n(N) \le n^k ( k + 1 )! n k ≤ w n ( N ) ≤ n k . For n > N n > N n > N , rewriting w n ( N ) = N k ∏ j = 1 k n N + j n w_n(N) = N^k \prod_{j=1}^{k}\frac{n}{N+jn} w n ( N ) = N k ∏ j = 1 k N + j n n shows that each factor lies in [ 1 j + 1 , 1 j ] \left[\frac{1}{j+1},\frac{1}{j}\right] [ j + 1 1 , j 1 ] , whence N k ( k + 1 ) ! ≤ w n ( N ) ≤ N k \frac{N^k}{(k+1)!} \le w_n(N) \le N^k ( k + 1 )! N k ≤ w n ( N ) ≤ N k . Combining both ranges gives 1 ( k + 1 ) ! min ( n , N ) k ≤ w n ( N ) ≤ min ( n , N ) k \frac{1}{(k+1)!}\min(n,N)^k \le w_n(N) \le\min(n,N)^k ( k + 1 )! 1 min ( n , N ) k ≤ w n ( N ) ≤ min ( n , N ) k for all n ≥ 0 n \ge0 n ≥ 0 , and summing against E n S ≥ 0 E_n^S \ge0 E n S ≥ 0 yields (D.9).
When an asymptotic expansion of tr ( ρ H s S ) \operatorname{tr}(\rho H_s^S) tr ( ρ H s S ) is available and the first k − 1 k-1 k − 1 moments on ρ \rho ρ are finite, subtracting the polynomial terms up to s − ( k − 1 ) s^{-(k-1)} s − ( k − 1 ) leaves a k k k -th order remainder ( − 1 ) k f ( s ) / s k (-1)^k f(s)/s^k ( − 1 ) k f ( s ) / s k . The next theorem shows how the large-s s s behavior of f ( s ) f(s) f ( s ) governs the truncated moments: a bounded remainder yields a finite k k k -th moment with an explicit truncation bound, whereas logarithmic or fractional-power growth determines the tail exponent α \alpha α on terminating runs and the resulting divergence and convergence rates across all orders r > 0 r>0 r > 0 .
Theorem D.6 (Divergence and convergence rates from the asymptotic remainder). For an integer k ≥ 1 k \ge1 k ≥ 1 , a normalized input state ρ \rho ρ , and real coefficients a 0 , … , a k − 1 a_0,\ldots,a_{k-1} a 0 , … , a k − 1 , define the remainder f ( s ) f(s) f ( s ) for every s > 0 s>0 s > 0 by
tr ( ρ H s S ) = ∑ j = 0 k − 1 ( − 1 ) j a j s j + ( − 1 ) k f ( s ) s k . (90) \operatorname{tr}(\rho H_s^S)=\sum_{j=0}^{k-1}\frac{(-1)^j a_j}{s^j}+\frac{(-1)^k f(s)}{s^k}. \tag*{(90)} tr ( ρ H s S ) = j = 0 ∑ k − 1 s j ( − 1 ) j a j + s k ( − 1 ) k f ( s ) . (90) Suppose that f ( s ) = o ( s ) f(s)=o(s) f ( s ) = o ( s ) as s → ∞ s\to\infty s → ∞ . Then a j = tr ( ρ M j S ) < ∞ a_j=\operatorname{tr}(\rho M_j^S)<\infty a j = tr ( ρ M j S ) < ∞ for all 0 ≤ j < k 0\le j<k 0 ≤ j < k (with M 0 S ≔ Q S M_0^S\coloneqq Q_S M 0 S : = Q S ), and the remainder f ( s ) f(s) f ( s ) determines the asymptotic behavior of the truncated moments as follows:
(1) Bounded case: If f ( s ) f(s) f ( s ) is bounded, then tr ( ρ M k S ) = lim s → ∞ f ( s ) ≕ a k < ∞ \operatorname{tr}(\rho M_k^S)=\lim_{s\to\infty}f(s)\eqqcolon a_k<\infty tr ( ρ M k S ) = lim s → ∞ f ( s ) = : a k < ∞ , and the truncation error at threshold N N N satisfies
0 ≤ tr ( ρ M k S ) − tr ( ρ M ~ k S ( N ) ) ≤ 2 ( a k − f ( N ) ) . (91) 0\le\operatorname{tr}(\rho M_k^S)-\operatorname{tr}(\rho\widetilde{M}_k^S(N))\le2(a_k-f(N)). \tag*{(91)} 0 ≤ tr ( ρ M k S ) − tr ( ρ M k S ( N )) ≤ 2 ( a k − f ( N )) . (91) (2) Logarithmic case: If f ( s ) = λ log s + O ( 1 ) f(s)=\lambda\log s+O(1) f ( s ) = λ log s + O ( 1 ) with λ > 0 \lambda>0 λ > 0 , then
tr ( ρ M ~ k S ( N ) ) = λ log N + O ( 1 ) , (92) \operatorname{tr}(\rho\widetilde{M}_k^S(N))=\lambda\log N+O(1), \tag*{(92)} tr ( ρ M k S ( N )) = λ log N + O ( 1 ) , (92) and the tail exponent is α = k \alpha=k α = k .
(3) Fractional-power case: If f ( s ) = Θ ( s β ) f(s)=\Theta(s^\beta) f ( s ) = Θ ( s β ) with 0 < β < 1 0<\beta<1 0 < β < 1 , then tr ( ρ M ~ k S ( N ) ) = Θ ( N β ) \operatorname{tr}(\rho\widetilde{M}_k^S(N))=\Theta(N^\beta) tr ( ρ M k S ( N )) = Θ ( N β ) , and the tail exponent is α = k − β \alpha=k-\beta α = k − β .
Moreover, in both the logarithmic and fractional-power cases, the tail probability on terminating runs decays as ∑ n > N tr ( ρ E n S ) = Θ ( N − α ) \sum_{n>N}\operatorname{tr}(\rho E_n^S)=\Theta(N^{-\alpha}) ∑ n > N tr ( ρ E n S ) = Θ ( N − α ) . Consequently, α \alpha α is the critical moment threshold: tr ( ρ M r S ) \operatorname{tr}(\rho M_r^S) tr ( ρ M r S ) is finite if and only if 0 < r < α 0<r<\alpha 0 < r < α , and for all r > 0 r>0 r > 0 ,
tr ( ρ M r S ) − tr ( ρ M ~ r S ( N ) ) = Θ ( N r − α ) ( 0 < r < α ) , \operatorname{tr}(\rho M_r^S)-\operatorname{tr}(\rho\widetilde{M}_r^S(N))=\Theta(N^{r-\alpha}) \qquad(0<r<\alpha), tr ( ρ M r S ) − tr ( ρ M r S ( N )) = Θ ( N r − α ) ( 0 < r < α ) , tr ( ρ M ~ r S ( N ) ) = Θ ( log N ) , \operatorname{tr}(\rho\widetilde{M}_r^S(N))=\Theta(\log N), tr ( ρ M r S ( N )) = Θ ( log N ) , tr ( ρ M ~ r S ( N ) ) = Θ ( N r − α ) ( r > α ) . (93) \operatorname{tr}(\rho\widetilde{M}_r^S(N))=\Theta(N^{r-\alpha}) \qquad(r>\alpha). \tag*{(93)} tr ( ρ M r S ( N )) = Θ ( N r − α ) ( r > α ) . (93)
Proof. Write p n ≔ tr ( ρ E n S ) p_n\coloneqq\operatorname{tr}(\rho E_n^S) p n : = tr ( ρ E n S ) . Since f ( s ) / s k = o ( s − ( k − 1 ) ) f(s)/s^k=o(s^{-(k-1)}) f ( s ) / s k = o ( s − ( k − 1 ) ) , Theorems D.2 and D.4 give a j = tr ( ρ M j S ) < ∞ a_j=\operatorname{tr}(\rho M_j^S)<\infty a j = tr ( ρ M j S ) < ∞ for 0 ≤ j < k 0\le j<k 0 ≤ j < k . Comparing (D.10) with the geometric remainder identity (D.6) at m = k m=k m = k shows that
f ( s ) = ∑ n = 0 ∞ s n k s + n p n , f ( 2 s ) − f ( s ) = ∑ n = 0 ∞ s n k + 1 ( s + n ) ( 2 s + n ) p n . f(s)=\sum_{n=0}^{\infty}\frac{s n^k}{s+n}p_n,\qquad f(2s)-f(s)=\sum_{n=0}^{\infty}\frac{s n^{k+1}}{(s+n)(2s+n)}p_n. f ( s ) = n = 0 ∑ ∞ s + n s n k p n , f ( 2 s ) − f ( s ) = n = 0 ∑ ∞ ( s + n ) ( 2 s + n ) s n k + 1 p n .
As s → ∞ s\to\infty s → ∞ , f ( s ) f(s) f ( s ) increases monotonically to tr ( ρ M k S ) \operatorname{tr}(\rho M_k^S) tr ( ρ M k S ) . If f f f is bounded, this limit a k = tr ( ρ M k S ) a_k=\operatorname{tr}(\rho M_k^S) a k = tr ( ρ M k S ) is finite; since n k − N k ≤ n k ≤ 2 n k + 1 N + n n^k-N^k\le n^k\le\frac{2n^{k+1}}{N+n} n k − N k ≤ n k ≤ N + n 2 n k + 1 for n > N n>N n > N , comparing tr ( ρ M k S ) − tr ( ρ M ~ k S ( N ) ) = ∑ n > N ( n k − N k ) p n \operatorname{tr}(\rho M_k^S)-\operatorname{tr}(\rho\widetilde{M}_k^S(N))=\sum_{n>N}(n^k-N^k)p_n tr ( ρ M k S ) − tr ( ρ M k S ( N )) = ∑ n > N ( n k − N k ) p n with a k − f ( N ) = ∑ n = 0 ∞ n k + 1 N + n p n a_k-f(N)=\sum_{n=0}^{\infty}\frac{n^{k+1}}{N+n}p_n a k − f ( N ) = ∑ n = 0 ∞ N + n n k + 1 p n yields (D.11). Next, we relate f ( s ) f(s) f ( s ) to the truncated moment tr ( ρ M ~ k S ( s ) ) = ∑ n = 0 ∞ min ( n , s ) k p n \operatorname{tr}(\rho\widetilde{M}^{S}_{k}(s))=\sum_{n=0}^{\infty}\min(n,s)^{k}p_n tr ( ρ M k S ( s )) = ∑ n = 0 ∞ min ( n , s ) k p n and bound the tail ∑ n > N p n \sum_{n>N}p_n ∑ n > N p n from above. In the logarithmic case, comparing the rational weight s n k s + n \frac{sn^{k}}{s+n} s + n s n k with the truncated weight min ( n , s ) k \min(n,s)^{k} min ( n , s ) k separately on n ≤ s n\le s n ≤ s and n > s n>s n > s gives the pointwise bounds
∣ s n k s + n − min ( n , s ) k ∣ ≤ 6 s n k + 1 ( s + n ) ( 2 s + n ) ( n ≥ 0 ) , s n k + 1 ( s + n ) ( 2 s + n ) ≥ s k 6 ( n > s ) . \left|\frac{sn^{k}}{s+n}-\min(n,s)^{k}\right|\le\frac{6sn^{k+1}}{(s+n)(2s+n)}\qquad(n\ge0),
\qquad
\frac{sn^{k+1}}{(s+n)(2s+n)}\ge\frac{s^{k}}{6}\qquad(n>s). s + n s n k − min ( n , s ) k ≤ ( s + n ) ( 2 s + n ) 6 s n k + 1 ( n ≥ 0 ) , ( s + n ) ( 2 s + n ) s n k + 1 ≥ 6 s k ( n > s ) .
Summing against p n p_n p n bounds both the difference ∣ tr ( ρ M ~ k S ( s ) ) − f ( s ) ∣ |\operatorname{tr}(\rho\widetilde{M}^{S}_{k}(s))-f(s)| ∣ tr ( ρ M k S ( s )) − f ( s ) ∣ and the tail by f ( 2 s ) − f ( s ) f(2s)-f(s) f ( 2 s ) − f ( s ) :
∣ tr ( ρ M ~ k S ( s ) ) − f ( s ) ∣ ≤ 6 ( f ( 2 s ) − f ( s ) ) , s k ∑ n > s p n ≤ 6 ( f ( 2 s ) − f ( s ) ) . \left|\operatorname{tr}(\rho\widetilde{M}^{S}_{k}(s))-f(s)\right|\le6\bigl(f(2s)-f(s)\bigr),
\qquad
s^{k}\sum_{n>s}p_n\le6\bigl(f(2s)-f(s)\bigr). tr ( ρ M k S ( s )) − f ( s ) ≤ 6 ( f ( 2 s ) − f ( s ) ) , s k n > s ∑ p n ≤ 6 ( f ( 2 s ) − f ( s ) ) .
Because f ( s ) = λ log s + O ( 1 ) f(s)=\lambda\log s+O(1) f ( s ) = λ log s + O ( 1 ) implies f ( 2 s ) − f ( s ) = O ( 1 ) f(2s)-f(s)=O(1) f ( 2 s ) − f ( s ) = O ( 1 ) , setting s = N s=N s = N proves (D.12) and ∑ n > N p n = O ( N − k ) \sum_{n>N}p_n=O(N^{-k}) ∑ n > N p n = O ( N − k ) . In the fractional-power case, min ( n , s ) k ≤ 2 s n k s + n \min(n,s)^{k}\le\frac{2sn^{k}}{s+n} min ( n , s ) k ≤ s + n 2 s n k immediately gives tr ( ρ M ~ k S ( s ) ) ≤ 2 f ( s ) \operatorname{tr}(\rho\widetilde{M}^{S}_{k}(s))\le2f(s) tr ( ρ M k S ( s )) ≤ 2 f ( s ) . For a lower bound, splitting the sum for f ( s ) f(s) f ( s ) at n = b s n=bs n = b s with b ≥ 1 b\ge1 b ≥ 1 and noting that s n k s + n ≤ 2 b ( b s ) n k b s + n \frac{sn^{k}}{s+n}\le\frac{2}{b}\frac{(bs)n^{k}}{bs+n} s + n s n k ≤ b 2 b s + n ( b s ) n k for n > b s n>bs n > b s yields
tr ( ρ M ~ k S ( b s ) ) ≥ f ( s ) − 2 b f ( b s ) . \operatorname{tr}(\rho\widetilde{M}^{S}_{k}(bs))\ge f(s)-\frac{2}{b}f(bs). tr ( ρ M k S ( b s )) ≥ f ( s ) − b 2 f ( b s ) .
Since f ( s ) = Θ ( s β ) f(s)=\Theta(s^{\beta}) f ( s ) = Θ ( s β ) with β < 1 \beta<1 β < 1 , choosing b b b sufficiently large ensures 2 b f ( b s ) ≤ 1 2 f ( s ) \frac{2}{b}f(bs)\le\frac{1}{2}f(s) b 2 f ( b s ) ≤ 2 1 f ( s ) for large s s s , so tr ( ρ M ~ k S ( N ) ) = Θ ( N β ) \operatorname{tr}(\rho\widetilde{M}^{S}_{k}(N))=\Theta(N^{\beta}) tr ( ρ M k S ( N )) = Θ ( N β ) . Moreover, N k ∑ n > N p n ≤ tr ( ρ M ~ k S ( N ) ) N^{k}\sum_{n>N}p_n\le\operatorname{tr}(\rho\widetilde{M}^{S}_{k}(N)) N k ∑ n > N p n ≤ tr ( ρ M k S ( N )) gives ∑ n > N p n = O ( N β − k ) \sum_{n>N}p_n=O(N^{\beta-k}) ∑ n > N p n = O ( N β − k ) .
To obtain matching tail lower bounds, observe that raising the truncation threshold from N N N to b N bN b N (b > 1 b>1 b > 1 ) only increases terms with n > N n>N n > N , each by at most ( b k − 1 ) N k (b^{k}-1)N^{k} ( b k − 1 ) N k :
tr ( ρ M ~ k S ( b N ) ) − tr ( ρ M ~ k S ( N ) ) ≤ ( b k − 1 ) N k ∑ n > N p n ( b > 1 ) . \operatorname{tr}(\rho\widetilde{M}^{S}_{k}(bN))-\operatorname{tr}(\rho\widetilde{M}^{S}_{k}(N))
\le(b^{k}-1)N^{k}\sum_{n>N}p_n
\qquad(b>1). tr ( ρ M k S ( b N )) − tr ( ρ M k S ( N )) ≤ ( b k − 1 ) N k n > N ∑ p n ( b > 1 ) .
In the logarithmic case, (D.12) makes the left-hand side λ log b + O ( 1 ) \lambda\log b+O(1) λ log b + O ( 1 ) , which is strictly positive for a sufficiently large fixed b b b , yielding ∑ n > N p n = Ω ( N − k ) \sum_{n>N}p_n=\Omega(N^{-k}) ∑ n > N p n = Ω ( N − k ) . In the fractional-power case, tr ( ρ M ~ k S ( N ) ) = Θ ( N β ) \operatorname{tr}(\rho\widetilde{M}^{S}_{k}(N))=\Theta(N^{\beta}) tr ( ρ M k S ( N )) = Θ ( N β ) makes the left-hand side Ω ( N β ) \Omega(N^{\beta}) Ω ( N β ) for a sufficiently large fixed b b b , yielding ∑ n > N p n = Ω ( N β − k ) \sum_{n>N}p_n=\Omega(N^{\beta-k}) ∑ n > N p n = Ω ( N β − k ) . Thus ∑ n > N p n = Θ ( N − α ) \sum_{n>N}p_n=\Theta(N^{-\alpha}) ∑ n > N p n = Θ ( N − α ) in both cases.
Finally, for any r > 0 r>0 r > 0 , substituting min ( n , N ) r = r ∫ 0 N x r − 1 1 { n > x } d x \min(n,N)^{r}=r\int_{0}^{N}x^{r-1}\mathbf{1}_{\{n>x\}}\,dx min ( n , N ) r = r ∫ 0 N x r − 1 1 { n > x } d x and applying Fubini’s theorem expresses the truncated moments in terms of the tail sum:
tr ( ρ M ~ r S ( N ) ) = r ∫ 0 N x r − 1 ∑ n > x p n d x , tr ( ρ M r S ) − tr ( ρ M ~ r S ( N ) ) = r ∫ N ∞ x r − 1 ∑ n > x p n d x , \operatorname{tr}(\rho\widetilde{M}^{S}_{r}(N))
=r\int_{0}^{N}x^{r-1}\sum_{n>x}p_n\,dx,
\qquad
\operatorname{tr}(\rho M^{S}_{r})-\operatorname{tr}(\rho\widetilde{M}^{S}_{r}(N))
=r\int_{N}^{\infty}x^{r-1}\sum_{n>x}p_n\,dx, tr ( ρ M r S ( N )) = r ∫ 0 N x r − 1 n > x ∑ p n d x , tr ( ρ M r S ) − tr ( ρ M r S ( N )) = r ∫ N ∞ x r − 1 n > x ∑ p n d x ,
where the second identity holds whenever tr ( ρ M r S ) < ∞ \operatorname{tr}(\rho M^{S}_{r})<\infty tr ( ρ M r S ) < ∞ . Substituting ∑ n > x p n = Θ ( x − α ) \sum_{n>x}p_n=\Theta(x^{-\alpha}) ∑ n > x p n = Θ ( x − α ) into both integrals immediately gives the finiteness range 0 < r < α 0<r<\alpha 0 < r < α and all three asymptotic rates in (D.13). □
As in Section D.2, tr ( ρ M ~ r S ( N ) ) = E ρ [ min ( τ S , N ) r 1 { τ S < ∞ } ] \operatorname{tr}(\rho\widetilde{M}^{S}_{r}(N))=\mathbb{E}_{\rho}[\min(\tau_S,N)^r\mathbf{1}_{\{\tau_S<\infty\}}] tr ( ρ M r S ( N )) = E ρ [ min ( τ S , N ) r 1 { τ S < ∞ } ] sums only over terminating executions. When tr ( ρ Q S ) > 0 \operatorname{tr}(\rho Q_S)>0 tr ( ρ Q S ) > 0 , dividing by the termination probability gives the conditional truncated moment given termination, whereas including the divergence probability tr ( ρ D S ) = 1 − tr ( ρ Q S ) \operatorname{tr}(\rho D_S)=1-\operatorname{tr}(\rho Q_S) tr ( ρ D S ) = 1 − tr ( ρ Q S ) (on which min ( τ S , N ) r = N r \min(\tau_S,N)^r=N^r min ( τ S , N ) r = N r ) gives the unconditional truncated moment:
E ρ [ min ( τ S , N ) r ∣ τ S < ∞ ] = tr ( ρ M ~ r S ( N ) ) tr ( ρ Q S ) , \mathbb{E}_{\rho}[\min(\tau_S,N)^r\mid\tau_S<\infty]
=\frac{\operatorname{tr}(\rho\widetilde{M}^{S}_{r}(N))}{\operatorname{tr}(\rho Q_S)}, E ρ [ min ( τ S , N ) r ∣ τ S < ∞ ] = tr ( ρ Q S ) tr ( ρ M r S ( N )) ,
E ρ [ min ( τ S , N ) r ] = tr ( ρ D S ) N r + tr ( ρ M ~ r S ( N ) ) . (94) \mathbb{E}_{\rho}[\min(\tau_S,N)^r]
=\operatorname{tr}(\rho D_S)N^r+\operatorname{tr}(\rho\widetilde{M}^{S}_{r}(N)). \tag*{(94)} E ρ [ min ( τ S , N ) r ] = tr ( ρ D S ) N r + tr ( ρ M r S ( N )) . (94)
Certified First-Passage Analysis of Coherent Quantum Walks
We now apply the parameterized weakest-precondition calculus and asymptotic extraction theorems of Sections B–D to the absorbing quantum walk [5 , 30 ] of Section A, recovering the quantitative runtime properties that were lost when the single expected-cost predicate collapsed to + ∞ +\infty + ∞ (Theorem A.2 ). We first carry out this analysis for the Hadamard walk started at ∣ R , 1 ⟩ |R,1\rangle ∣ R , 1 ⟩ and then extend it to biased coins and arbitrary entrance states.
Deriving the Runtime Family
Let Walk be the while command of Section A, with guard projectors M 0 = Π 0 M_0=\Pi_0 M 0 = Π 0 and M 1 = Π ≠ 0 M_1=\Pi_{\ne0} M 1 = Π = 0 , and retain U U U , B B B , and K K K from (A.1)–(A.2). For a postcondition family F ∈ Pred ( H ) F\in\operatorname{Pred}(\mathcal{H}) F ∈ Pred ( H ) , we derive wp ( W a l k , F ) \operatorname{wp}(\mathrm{Walk},F) wp ( Walk , F ) by propagating predicates backwards through the body and then combining the two guard branches.
For an intermediate family X X X , the unitary rule of Theorem C.2 gives the following exact annotations at scale s s s , read from bottom to top:
{ ( C 1 / 2 † ⊗ I ) V † X s V ( C 1 / 2 ⊗ I ) } \left\{\left(C_{1/2}^{\dagger}\otimes I\right)V^{\dagger}X_sV\left(C_{1/2}\otimes I\right)\right\} { ( C 1/2 † ⊗ I ) V † X s V ( C 1/2 ⊗ I ) }
coin := C_{1/2}[coin];
{ V † X s V } \left\{V^{\dagger}X_sV\right\} { V † X s V }
(coin, position) := V[coin, position]
{ X s } \{X_s\} { X s } .
The sequencing rule joins these annotations, giving the body precondition U † X s U U^{\dagger}X_sU U † X s U . At the guard, the exit branch returns F s F_s F s , while the continuing branch contributes the factor s / ( s + 1 ) s/(s+1) s / ( s + 1 ) and uses the body precondition at scale s + 1 s+1 s + 1 . The loop rule therefore gives Y ≔ wp ( W a l k , F ) Y\coloneqq\operatorname{wp}(\mathrm{Walk},F) Y : = wp ( Walk , F ) satisfying
Y s = Π 0 F s Π 0 + s s + 1 Π ≠ 0 U † Y s + 1 U Π ≠ 0 . (95) Y_s=\Pi_0F_s\Pi_0+\frac{s}{s+1}\Pi_{\ne0}U^{\dagger}Y_{s+1}U\Pi_{\ne0}. \tag*{(95)} Y s = Π 0 F s Π 0 + s + 1 s Π = 0 U † Y s + 1 U Π = 0 . (95)
Theorem C.4 makes this the unique solution in Pred ( H ) \operatorname{Pred}(\mathcal{H}) Pred ( H ) .
Equation (E.1) gives Π 0 Y s Π 0 = Π 0 F s Π 0 \Pi_0Y_s\Pi_0=\Pi_0F_s\Pi_0 Π 0 Y s Π 0 = Π 0 F s Π 0 and zero cross terms between the boundary and its complement. Since U u = B u + K u Uu=Bu+Ku U u = B u + K u for u ∈ H + u\in\mathcal{H}_+ u ∈ H + , the compression Y s + ≔ Π + Y s ∣ H + Y_s^+\coloneqq\Pi_+Y_s|_{\mathcal{H}_+} Y s + : = Π + Y s ∣ H + satisfies
Y s + = s s + 1 ( B † F s + 1 B + K † Y s + 1 + K ) = s s + 1 ( tr ( ∣ L , 0 ⟩ ⟨ L , 0 ∣ F s + 1 ) B † B + K † Y s + 1 + K ) . (96) \begin{aligned}
Y_s^+=\frac{s}{s+1}\left(B^{\dagger}F_{s+1}B+K^{\dagger}Y_{s+1}^+K\right) \\
&=\frac{s}{s+1}\left(\operatorname{tr}\left(|L,0\rangle\langle L,0|F_{s+1}\right)B^{\dagger}B+K^{\dagger}Y_{s+1}^+K\right). \tag*{(96)}
\end{aligned} Y s + = s + 1 s ( B † F s + 1 B + K † Y s + 1 + K ) = s + 1 s ( tr ( ∣ L , 0 ⟩ ⟨ L , 0∣ F s + 1 ) B † B + K † Y s + 1 + K ) . (96)
where the second equality uses ran B = C ∣ L , 0 ⟩ \operatorname{ran}B=\mathbb{C}|L,0\rangle ran B = C ∣ L , 0 ⟩ . For F = I F=I F = I , write H s ≔ Π + wp ( W a l k , I ) s ∣ H + H_s\coloneqq\Pi_+\operatorname{wp}(\mathrm{Walk},I)_s|_{\mathcal{H}_+} H s : = Π + wp ( Walk , I ) s ∣ H + . The recurrence becomes
H s = s s + 1 ( B † B + K † H s + 1 K ) . (97) H_s=\frac{s}{s+1}\left(B^{\dagger}B+K^{\dagger}H_{s+1}K\right). \tag*{(97)} H s = s + 1 s ( B † B + K † H s + 1 K ) . (97)
Unfolding these equations gives the operator series used in the scalar calculations below.
Proposition E.1 (Runtime family from loop unfolding). The runtime family on H + \mathcal{H}_+ H + is
H s = ∑ n ≥ 1 s s + n ( K † ) n − 1 B † B K n − 1 . (98) H_s=\sum_{n\ge1}\frac{s}{s+n}(K^{\dagger})^{n-1}B^{\dagger}BK^{n-1}. \tag*{(98)} H s = n ≥ 1 ∑ s + n s ( K † ) n − 1 B † B K n − 1 . (98) More generally, for any postcondition F ∈ Pred ( H ) F\in\operatorname{Pred}(\mathcal{H}) F ∈ Pred ( H ) ,
Π + wp ( W a l k , F ) s ∣ H + = ∑ n ≥ 1 s s + n tr ( ∣ L , 0 ⟩ ⟨ L , 0 ∣ F s + n ) ( K † ) n − 1 B † B K n − 1 . (99) \Pi_+\operatorname{wp}(\mathrm{Walk},F)_s|_{\mathcal{H}_+}
=\sum_{n\ge1}\frac{s}{s+n}\operatorname{tr}\left(|L,0\rangle\langle L,0|F_{s+n}\right)(K^{\dagger})^{n-1}B^{\dagger}BK^{n-1}. \tag*{(99)} Π + wp ( Walk , F ) s ∣ H + = n ≥ 1 ∑ s + n s tr ( ∣ L , 0 ⟩ ⟨ L , 0∣ F s + n ) ( K † ) n − 1 B † B K n − 1 . (99) Both series converge in operator norm at each fixed s > 0 s>0 s > 0 .
Proof. Unfolding (E.2) N N N times and canceling successive scale factors gives
Y s + = ∑ n = 1 N s s + n tr ( ∣ L , 0 ⟩ ⟨ L , 0 ∣ F s + n ) ( K † ) n − 1 B † B K n − 1 + s s + N ( K † ) N Y s + N + K N . Y_s^+ = \sum_{n=1}^{N} \frac{s}{s+n}\operatorname{tr}(\lvert L,0\rangle\langle L,0\rvert F_{s+n})(K^\dagger)^{n-1}B^\dagger B K^{n-1}
+ \frac{s}{s+N}(K^\dagger)^N Y_{s+N}^+ K^N. Y s + = n = 1 ∑ N s + n s tr (∣ L , 0 ⟩ ⟨ L , 0 ∣ F s + n ) ( K † ) n − 1 B † B K n − 1 + s + N s ( K † ) N Y s + N + K N .
Since 0 ≤ Y s + N + ≤ I 0 \leq Y_{s+N}^+ \leq I 0 ≤ Y s + N + ≤ I and K K K is a contraction, the remainder satisfies
0 ≤ s s + N ( K † ) N Y s + N + K N ≤ s s + N I . 0 \leq\frac{s}{s+N}(K^\dagger)^N Y_{s+N}^+ K^N \leq\frac{s}{s+N}I. 0 ≤ s + N s ( K † ) N Y s + N + K N ≤ s + N s I .
At each fixed s > 0 s>0 s > 0 , letting N → ∞ N\to\infty N → ∞ proves (E.5) in operator norm. Taking F = I F=I F = I gives (E.4). The same derivation applies to the biased walks in Section E.3.
The Hadamard Walk
For the input ρ = ∣ R , 1 ⟩ ⟨ R , 1 ∣ \rho=\lvert R,1\rangle\langle R,1\rvert ρ = ∣ R , 1 ⟩ ⟨ R , 1 ∣ , Proposition E.1 reduces the runtime test (A.14) to
h s = tr ( H s ρ ) = ∑ n ≥ 1 s s + n ∥ B K n − 1 ∣ R , 1 ⟩ ∥ 2 . (100) h_s=\operatorname{tr}(H_s\rho)=\sum_{n\geq1}\frac{s}{s+n}\lVert BK^{n-1}\lvert R,1\rangle\rVert^2. \tag*{(100)} h s = tr ( H s ρ ) = n ≥ 1 ∑ s + n s ∥ B K n − 1 ∣ R , 1 ⟩ ∥ 2 . (100)
We evaluate this expression from the matrix entries of B B B and K K K , then apply the extraction theorems of Section D to the resulting asymptotic expansion.
Lemma E.2 (Matrix coefficients of B K n − 1 BK^{n-1} B K n − 1 ). Let K K K have the matrix entries in (A.7)–(A.8), and let
B = 1 2 ∣ L , 0 ⟩ ( ⟨ L , 1 ∣ + ⟨ R , 1 ∣ ) . B=\frac{1}{\sqrt{2}}\lvert L,0\rangle(\langle L,1\rvert+\langle R,1\rvert). B = 2 1 ∣ L , 0 ⟩ (⟨ L , 1 ∣ + ⟨ R , 1 ∣) . For n ≥ 1 n\geq1 n ≥ 1 , write
B K n − 1 ∣ R , 1 ⟩ = a n ∣ L , 0 ⟩ , ∥ B K n − 1 ∣ R , 1 ⟩ ∥ 2 = ∣ a n ∣ 2 . BK^{n-1}\lvert R,1\rangle=a_n\lvert L,0\rangle,\qquad\lVert BK^{n-1}\lvert R,1\rangle\rVert^2=\lvert a_n\rvert^2. B K n − 1 ∣ R , 1 ⟩ = a n ∣ L , 0 ⟩ , ∥ B K n − 1 ∣ R , 1 ⟩ ∥ 2 = ∣ a n ∣ 2 . The coefficients a n a_n a n are given by
a 1 = 1 2 , a 4 j − 1 = − 1 2 ( 1 / 2 j ) ( j ≥ 1 ) , a n = 0 otherwise . a_1=\frac{1}{\sqrt{2}},\qquad a_{4j-1}=-\frac{1}{\sqrt{2}}\binom{1/2}{j}\quad(j\geq1),\qquad a_n=0\quad\text{otherwise}. a 1 = 2 1 , a 4 j − 1 = − 2 1 ( j 1/2 ) ( j ≥ 1 ) , a n = 0 otherwise . Proof. Expand the matrix product B K n − 1 BK^{n-1} B K n − 1 in the standard basis. Its nonzero terms are indexed by integer sequences x 0 = 1 x_0=1 x 0 = 1 , x n = 0 x_n=0 x n = 0 , with x i ≥ 1 x_i\geq1 x i ≥ 1 for 0 < i < n 0<i<n 0 < i < n and x i − x i − 1 ∈ { − 1 , 1 } x_i-x_{i-1}\in\{-1,1\} x i − x i − 1 ∈ { − 1 , 1 } . Each difference determines the next basis label: − 1 -1 − 1 gives L L L and + 1 +1 + 1 gives R R R . Thus even n n n give zero, and a 1 = 2 − 1 / 2 a_1=2^{-1/2} a 1 = 2 − 1/2 . For n = 2 m + 1 ≥ 3 n=2m+1\geq3 n = 2 m + 1 ≥ 3 , deleting the final difference − 1 -1 − 1 leaves a word with m m m entries + 1 +1 + 1 and m m m entries − 1 -1 − 1 , all of whose partial sums are nonnegative.
Group these words by their number r r r of positive runs, writing each as
( + 1 ) α 1 ( − 1 ) β 1 ⋯ ( + 1 ) α r ( − 1 ) β r , ∑ i = 1 r α i = ∑ i = 1 r β i = m , (+1)^{\alpha_1}(-1)^{\beta_1}\cdots(+1)^{\alpha_r}(-1)^{\beta_r},\qquad\sum_{i=1}^{r}\alpha_i=\sum_{i=1}^{r}\beta_i=m, ( + 1 ) α 1 ( − 1 ) β 1 ⋯ ( + 1 ) α r ( − 1 ) β r , i = 1 ∑ r α i = i = 1 ∑ r β i = m , where all run lengths are positive integers. Set p i ≔ ∑ ℓ = 1 i α ℓ p_i\coloneqq\sum_{\ell=1}^{i}\alpha_\ell p i : = ∑ ℓ = 1 i α ℓ and q i ≔ ∑ ℓ = 1 i β ℓ q_i\coloneqq\sum_{\ell=1}^{i}\beta_\ell q i : = ∑ ℓ = 1 i β ℓ for 1 ≤ i < r 1\leq i<r 1 ≤ i < r . These define ( r − 1 ) (r-1) ( r − 1 ) -element subsets P = { p i } P=\{p_i\} P = { p i } and Q = { q i } Q=\{q_i\} Q = { q i } of { 1 , … , m − 1 } \{1,\ldots,m-1\} { 1 , … , m − 1 } . Nonnegativity of the word is equivalent to p i ≥ q i p_i\geq q_i p i ≥ q i for every i i i , or, equivalently, ∣ P ∩ { 1 , … , t } ∣ ≤ ∣ Q ∩ { 1 , … , t } ∣ \lvert P\cap\{1,\ldots,t\}\rvert\leq\lvert Q\cap\{1,\ldots,t\}\rvert ∣ P ∩ { 1 , … , t }∣ ≤ ∣ Q ∩ { 1 , … , t }∣ for every t t t . There are ( m − 1 r − 1 ) 2 \binom{m-1}{r-1}^2 ( r − 1 m − 1 ) 2 unrestricted pairs. For a violating pair, exchange the two prefixes at the first t t t where the first count exceeds the second by one. The resulting subsets have sizes r − 2 r-2 r − 2 and r r r . Conversely, exchanging prefixes at the first excess of the second count over the first recovers the violating pair. Hence the number of words with r r r positive runs is
N ( m , r ) = ( m − 1 r − 1 ) 2 − ( m − 1 r − 2 ) ( m − 1 r ) = 1 m ( m r ) ( m r − 1 ) . N(m,r)=\binom{m-1}{r-1}^2-\binom{m-1}{r-2}\binom{m-1}{r}=\frac{1}{m}\binom{m}{r}\binom{m}{r-1}. N ( m , r ) = ( r − 1 m − 1 ) 2 − ( r − 2 m − 1 ) ( r m − 1 ) = m 1 ( r m ) ( r − 1 m ) .
with out-of-range binomial coefficients interpreted as zero.
Every nonzero matrix entry has modulus 2 − 1 / 2 2^{-1/2} 2 − 1/2 . Negative entries occur exactly when an R R R label is followed by another R R R label. A word with r r r positive runs therefore contributes m − r m-r m − r negative entries within those runs and one from the initial label R R R , giving sign ( − 1 ) m − r + 1 (-1)^{m-r+1} ( − 1 ) m − r + 1 . Consequently,
a 2 m + 1 = 2 − ( 2 m + 1 ) / 2 m ∑ r = 1 m ( − 1 ) m − r + 1 ( m r ) ( m r − 1 ) = 2 − ( 2 m + 1 ) / 2 m [ z m + 1 ] ( 1 + z ) m ( 1 − z ) m = 2 − ( 2 m + 1 ) / 2 m [ z m + 1 ] ( 1 − z 2 ) m . \begin{aligned}
a_{2m+1}=\frac{2^{-(2m+1)/2}}{m}\sum_{r=1}^{m}(-1)^{m-r+1}\binom{m}{r}\binom{m}{r-1} \\
&=\frac{2^{-(2m+1)/2}}{m}[z^{m+1}](1+z)^m(1-z)^m
=\frac{2^{-(2m+1)/2}}{m}[z^{m+1}](1-z^2)^m.
\end{aligned} a 2 m + 1 = m 2 − ( 2 m + 1 ) /2 r = 1 ∑ m ( − 1 ) m − r + 1 ( r m ) ( r − 1 m ) = m 2 − ( 2 m + 1 ) /2 [ z m + 1 ] ( 1 + z ) m ( 1 − z ) m = m 2 − ( 2 m + 1 ) /2 [ z m + 1 ] ( 1 − z 2 ) m .
Here [ z ℓ ] [z^\ell] [ z ℓ ] denotes coefficient extraction. This coefficient vanishes for even m m m . For m = 2 j − 1 m=2j-1 m = 2 j − 1 , its value divided by m m m is
( − 1 ) j 2 j − 1 ( 2 j − 1 j ) = ( − 1 ) j j ( 2 j − 2 j − 1 ) . \frac{(-1)^j}{2j-1}\binom{2j-1}{j}
=\frac{(-1)^j}{j}\binom{2j-2}{j-1}. 2 j − 1 ( − 1 ) j ( j 2 j − 1 ) = j ( − 1 ) j ( j − 1 2 j − 2 ) .
Together with
( 1 / 2 j ) = ( − 1 ) j − 1 2 2 j − 1 j ( 2 j − 2 j − 1 ) , \binom{1/2}{j}=\frac{(-1)^{j-1}}{2^{2j-1}j}\binom{2j-2}{j-1}, ( j 1/2 ) = 2 2 j − 1 j ( − 1 ) j − 1 ( j − 1 2 j − 2 ) ,
this proves the stated coefficients. □
Since B K n − 1 ∣ R , 1 ⟩ = a n ∣ L , 0 ⟩ BK^{n-1}|R,1\rangle=a_n|L,0\rangle B K n − 1 ∣ R , 1 ⟩ = a n ∣ L , 0 ⟩ , the scalar series is now explicit:
h s = ∑ n ≥ 1 s s + n ∣ a n ∣ 2 = 1 2 s 2 s + 1 + 1 2 ∑ j ≥ 1 ( 1 / 2 j ) 2 s s + 4 j − 1 . (101) h_s=\sum_{n\geq1}\frac{s}{s+n}|a_n|^2
=\frac{1}{2}\frac{s}{2s+1}+\frac{1}{2}\sum_{j\geq1}\binom{1/2}{j}^{2}\frac{s}{s+4j-1}. \tag*{(101)} h s = n ≥ 1 ∑ s + n s ∣ a n ∣ 2 = 2 1 2 s + 1 s + 2 1 j ≥ 1 ∑ ( j 1/2 ) 2 s + 4 j − 1 s . (101)
Two finite summation identities determine its constant and s − 1 s^{-1} s − 1 terms. The coefficient asymptotics determine the logarithmic remainder.
Theorem E.3 (Asymptotic expansion of the rational series). The function h s h_s h s in (E.7) satisfies, as s → ∞ s\to\infty s → ∞ ,
h s = 2 π − 1 s + 2 log s π s 2 + O ( s − 2 ) . (102) h_s=\frac{2}{\pi}-\frac{1}{s}+\frac{2\log s}{\pi s^2}+O(s^{-2}). \tag*{(102)} h s = π 2 − s 1 + π s 2 2 log s + O ( s − 2 ) . (102)
Proof. Put c j = ( 1 / 2 j ) 2 c_j=\binom{1/2}{j}^{2} c j = ( j 1/2 ) 2 and u m = 4 − m ( 2 m m ) u_m=4^{-m}\binom{2m}{m} u m = 4 − m ( m 2 m ) . For m ≥ 1 m\geq1 m ≥ 1 , the identities c m = u m 2 / ( 2 m − 1 ) 2 c_m=u_m^2/(2m-1)^2 c m = u m 2 / ( 2 m − 1 ) 2 and u m / u m − 1 = ( 2 m − 1 ) / ( 2 m ) u_m/u_{m-1}=(2m-1)/(2m) u m / u m − 1 = ( 2 m − 1 ) / ( 2 m ) give
( 4 m + 1 ) u m 2 − ( 4 m − 3 ) u m − 1 2 = c m , (4m+1)u_m^2-(4m-3)u_{m-1}^2=c_m, ( 4 m + 1 ) u m 2 − ( 4 m − 3 ) u m − 1 2 = c m ,
m u m 2 − ( m − 1 ) u m − 1 2 = m c m . mu_m^2-(m-1)u_{m-1}^2=mc_m. m u m 2 − ( m − 1 ) u m − 1 2 = m c m .
Summing these differences and using c 0 = u 0 = 1 c_0=u_0=1 c 0 = u 0 = 1 yields
∑ j = 0 m c j = ( 4 m + 1 ) u m 2 , ∑ j = 1 m j c j = m u m 2 . \sum_{j=0}^{m}c_j=(4m+1)u_m^2,\qquad
\sum_{j=1}^{m}jc_j=mu_m^2. j = 0 ∑ m c j = ( 4 m + 1 ) u m 2 , j = 1 ∑ m j c j = m u m 2 .
Since Stirling’s formula gives u m 2 ∼ 1 / ( π m ) u_m^2\sim1/(\pi m) u m 2 ∼ 1/ ( π m ) , we obtain ∑ j ≥ 0 c j = 4 / π \sum_{j\geq0}c_j=4/\pi ∑ j ≥ 0 c j = 4/ π and ∑ j ≥ 1 j c j = 1 / π \sum_{j\geq1}jc_j=1/\pi ∑ j ≥ 1 j c j = 1/ π . Thus
∑ n ≥ 1 ∣ a n ∣ 2 = 1 2 + 1 2 ( 4 π − 1 ) = 2 π , \sum_{n\geq1}|a_n|^2=\frac{1}{2}+\frac{1}{2}\left(\frac{4}{\pi}-1\right)=\frac{2}{\pi}, n ≥ 1 ∑ ∣ a n ∣ 2 = 2 1 + 2 1 ( π 4 − 1 ) = π 2 ,
∑ n ≥ 1 n ∣ a n ∣ 2 = 1 2 + 1 2 [ 4 π − ( 4 π − 1 ) ] = 1. \sum_{n\geq1}n|a_n|^2=\frac{1}{2}+\frac{1}{2}\left[\frac{4}{\pi}-\left(\frac{4}{\pi}-1\right)\right]=1. n ≥ 1 ∑ n ∣ a n ∣ 2 = 2 1 + 2 1 [ π 4 − ( π 4 − 1 ) ] = 1.
The geometric remainder identity used in (D.6) now gives
s 2 ( h s − 2 π + 1 s ) = ∑ n ≥ 1 s n 2 s + n ∣ a n ∣ 2 = 1 2 s 2 s + 1 + 1 2 ∑ j ≥ 1 s ( 4 j − 1 ) 2 s + 4 j − 1 c j . s^{2}\left(h_s-\frac{2}{\pi}+\frac{1}{s}\right)=\sum_{n\ge1}\frac{sn^{2}}{s+n}|a_n|^{2}
=\frac{1}{2}\frac{s}{2s+1}+\frac{1}{2}\sum_{j\ge1}\frac{s(4j-1)^{2}}{s+4j-1}c_j. s 2 ( h s − π 2 + s 1 ) = n ≥ 1 ∑ s + n s n 2 ∣ a n ∣ 2 = 2 1 2 s + 1 s + 2 1 j ≥ 1 ∑ s + 4 j − 1 s ( 4 j − 1 ) 2 c j .
Stirling’s formula also gives
c j = 1 4 π j 3 + O ( j − 4 ) , 1 2 ( 4 j − 1 ) 2 c j = 2 π j + O ( j − 2 ) . c_j=\frac{1}{4\pi j^{3}}+O(j^{-4}),\qquad\frac{1}{2}(4j-1)^{2}c_j=\frac{2}{\pi j}+O(j^{-2}). c j = 4 π j 3 1 + O ( j − 4 ) , 2 1 ( 4 j − 1 ) 2 c j = π j 2 + O ( j − 2 ) .
The O ( j − 2 ) O(j^{-2}) O ( j − 2 ) error is summable uniformly after multiplication by s / ( s + 4 j − 1 ) ≤ 1 s/(s+4j-1)\le1 s / ( s + 4 j − 1 ) ≤ 1 , so
s 2 ( h s − 2 π + 1 s ) = 2 π ∑ j ≥ 1 s j ( s + 4 j − 1 ) + O ( 1 ) . s^{2}\left(h_s-\frac{2}{\pi}+\frac{1}{s}\right)=\frac{2}{\pi}\sum_{j\ge1}\frac{s}{j(s+4j-1)}+O(1). s 2 ( h s − π 2 + s 1 ) = π 2 j ≥ 1 ∑ j ( s + 4 j − 1 ) s + O ( 1 ) .
To estimate the last sum, split it at J = ⌊ s ⌋ J=\lfloor s\rfloor J = ⌊ s ⌋ . For j ≤ J j\le J j ≤ J ,
0 ≤ 1 j − s j ( s + 4 j − 1 ) = 4 j − 1 j ( s + 4 j − 1 ) ≤ 4 s , 0\le\frac{1}{j}-\frac{s}{j(s+4j-1)}=\frac{4j-1}{j(s+4j-1)}\le\frac{4}{s}, 0 ≤ j 1 − j ( s + 4 j − 1 ) s = j ( s + 4 j − 1 ) 4 j − 1 ≤ s 4 ,
so this part equals ∑ j = 1 J j − 1 + O ( 1 ) = log s + O ( 1 ) \sum_{j=1}^{J}j^{-1}+O(1)=\log s+O(1) ∑ j = 1 J j − 1 + O ( 1 ) = log s + O ( 1 ) . For j > J j>J j > J , the bound s / [ j ( s + 4 j − 1 ) ] ≤ s / ( 3 j 2 ) s/[j(s+4j-1)]\le s/(3j^{2}) s / [ j ( s + 4 j − 1 )] ≤ s / ( 3 j 2 ) makes the remaining sum O ( 1 ) O(1) O ( 1 ) . This proves the expansion. □
Extracting runtime properties. The constant term in (E.8) gives the termination probability by Theorem D.2:
P ( τ < ∞ ) = 2 π . \mathbb{P}(\tau<\infty)=\frac{2}{\pi}. P ( τ < ∞ ) = π 2 .
Since h s = 2 / π − s − 1 + o ( s − 1 ) h_s=2/\pi-s^{-1}+o(s^{-1}) h s = 2/ π − s − 1 + o ( s − 1 ) , Theorem D.4 with k = 1 k=1 k = 1 reads the successful first moment from the coefficient of − s − 1 -s^{-1} − s − 1 :
E [ τ ; τ < ∞ ] = 1. \mathbb{E}[\tau;\tau<\infty]=1. E [ τ ; τ < ∞ ] = 1.
For the second moment, subtracting these two terms leaves
s 2 ( h s − 2 π + 1 s ) = 2 π log s + O ( 1 ) . s^{2}\left(h_s-\frac{2}{\pi}+\frac{1}{s}\right)=\frac{2}{\pi}\log s+O(1). s 2 ( h s − π 2 + s 1 ) = π 2 log s + O ( 1 ) .
The logarithmic case of Theorem D.6 , with k = 2 k=2 k = 2 , therefore gives
E [ min ( τ , N ) 2 ; τ < ∞ ] = 2 π log N + O ( 1 ) . (103) \mathbb{E}[\min(\tau,N)^{2};\tau<\infty]=\frac{2}{\pi}\log N+O(1). \tag*{(103)} E [ min ( τ , N ) 2 ; τ < ∞ ] = π 2 log N + O ( 1 ) . (103)
It also gives P ( N < τ < ∞ ) = Θ ( N − 2 ) \mathbb{P}(N<\tau<\infty)=\Theta(N^{-2}) P ( N < τ < ∞ ) = Θ ( N − 2 ) and critical moment order 2 2 2 . By the conditioning formula (D.14), the conditional moments are finite exactly for 0 < r < 2 0<r<2 0 < r < 2 , and their capped versions grow as Θ ( N r − 2 ) \Theta(N^{r-2}) Θ ( N r − 2 ) for r > 2 r>2 r > 2 .
Dividing the successful first moment and the capped second moment by 2 / π 2/\pi 2/ π gives the conditional mean π / 2 \pi/2 π /2 and conditional capped second moment log N + O ( 1 ) \log N+O(1) log N + O ( 1 ) . Since the conditional capped mean is at most π / 2 \pi/2 π /2 , its squared contribution to the variance is bounded. Hence
E [ τ ∣ τ < ∞ ] = π 2 , Var ( min ( τ , N ) ∣ τ < ∞ ) = log N + O ( 1 ) . (104) \mathbb{E}[\tau\mid\tau<\infty]=\frac{\pi}{2},\qquad\operatorname{Var}(\min(\tau,N)\mid\tau<\infty)=\log N+O(1). \tag*{(104)} E [ τ ∣ τ < ∞ ] = 2 π , Var ( min ( τ , N ) ∣ τ < ∞ ) = log N + O ( 1 ) . (104)
The positive divergence probability 1 − 2 / π 1-2/\pi 1 − 2/ π gives E [ τ ] = ∞ \mathbb{E}[\tau]=\infty E [ τ ] = ∞ .
Extension to Biased Coins
Replace the Hadamard coin by
C p = ( a b b − a ) , a = p , b = 1 − p , p ∈ ( 0 , 1 ) . (105) C_p=\begin{pmatrix}a&b\\b&-a\end{pmatrix},\qquad a=\sqrt{p},\quad b=\sqrt{1-p},\quad p\in(0,1). \tag*{(105)} C p = ( a b b − a ) , a = p , b = 1 − p , p ∈ ( 0 , 1 ) . (105)
Let L p L_p L p be the resulting loop, and put
U p ≜ V ( C p ⊗ I ) , B p ≜ Π 0 U p ∣ H + , K p ≜ Π + U p ∣ H + . U_p\triangleq V(C_p\otimes I),\qquad B_p\triangleq\Pi_0U_p\big|_{\mathcal{H}_+},\qquad K_p\triangleq\Pi_+U_p\big|_{\mathcal{H}_+}. U p ≜ V ( C p ⊗ I ) , B p ≜ Π 0 U p H + , K p ≜ Π + U p H + .
The derivation in Section E.1 applies with U , B , K U,B,K U , B , K replaced by U p , B p , K p U_p,B_p,K_p U p , B p , K p . Thus the compression H p , s H_{p,s} H p , s of wp ( L p , I ) s \operatorname{wp}(L_p,I)_s wp ( L p , I ) s to H + \mathcal{H}_+ H + satisfies
H p , s = s s + 1 ( B p † B p + K p † H p , s + 1 K p ) , H_{p,s}=\frac{s}{s+1}\left(B_p^\dagger B_p+K_p^\dagger H_{p,s+1}K_p\right), H p , s = s + 1 s ( B p † B p + K p † H p , s + 1 K p ) ,
and Proposition E.1 gives its operator series. For a normalized coin state ρ \rho ρ at position 1, the scalar calculation target is
h ρ ( s ) ≜ tr ( ( ρ ⊗ ∣ 1 ⟩ ⟨ 1 ∣ ) H p , s ) = ∑ n ≥ 1 s s + n tr ( ( ρ ⊗ ∣ 1 ⟩ ⟨ 1 ∣ ) ( K p † ) n − 1 B p † B p K p n − 1 ) . (106) h_\rho(s)\triangleq\operatorname{tr}\left((\rho\otimes|1\rangle\langle1|)H_{p,s}\right)
=\sum_{n\geq1}\frac{s}{s+n}\operatorname{tr}\left((\rho\otimes|1\rangle\langle1|)(K_p^\dagger)^{n-1}B_p^\dagger B_pK_p^{n-1}\right). \tag*{(106)} h ρ ( s ) ≜ tr ( ( ρ ⊗ ∣1 ⟩ ⟨ 1∣ ) H p , s ) = n ≥ 1 ∑ s + n s tr ( ( ρ ⊗ ∣1 ⟩ ⟨ 1∣ ) ( K p † ) n − 1 B p † B p K p n − 1 ) . (106)
We evaluate this trace using the same matrix expansion as in Section E.2. For the calculation, write
v + = a ∣ L ⟩ + b ∣ R ⟩ , v − = b ∣ L ⟩ − a ∣ R ⟩ , χ = 1 − 2 p , δ = 2 p ( 1 − p ) , v_+=a|L\rangle+b|R\rangle,\qquad v_-=b|L\rangle-a|R\rangle,\qquad\chi=1-2p,\qquad\delta=2\sqrt{p(1-p)}, v + = a ∣ L ⟩ + b ∣ R ⟩ , v − = b ∣ L ⟩ − a ∣ R ⟩ , χ = 1 − 2 p , δ = 2 p ( 1 − p ) ,
so that v + , v − v_+,v_- v + , v − are orthonormal and δ 2 = 1 − χ 2 \delta^2=1-\chi^2 δ 2 = 1 − χ 2 .
Lemma E.4 (Matrix coefficients of powers of K p K_p K p ). For every ψ ∈ C 2 \psi\in\mathbb{C}^2 ψ ∈ C 2 and n ≥ 1 n\geq1 n ≥ 1 ,
⟨ L , 0 ∣ B p K p n − 1 ∣ ψ , 1 ⟩ = { ⟨ v + , ψ ⟩ , n = 1 , t k ⟨ v − , ψ ⟩ , n = 2 k + 1 , k ≥ 1 , 0 , n even , \langle L,0|B_pK_p^{n-1}|\psi,1\rangle=
\begin{cases}
\langle v_+,\psi\rangle,&n=1,\\
t_k\langle v_-,\psi\rangle,&n=2k+1,\ k\geq1,\\
0,&n\ \text{even},
\end{cases} ⟨ L , 0∣ B p K p n − 1 ∣ ψ , 1 ⟩ = ⎩ ⎨ ⎧ ⟨ v + , ψ ⟩ , t k ⟨ v − , ψ ⟩ , 0 , n = 1 , n = 2 k + 1 , k ≥ 1 , n even , where, for the Legendre polynomials P k P_k P k ,
t k = δ P k ′ ( χ ) k ( k + 1 ) = P k − 1 ( χ ) − P k + 1 ( χ ) δ ( 2 k + 1 ) . (107) t_k=\frac{\delta P_k'(\chi)}{k(k+1)}
=\frac{P_{k-1}(\chi)-P_{k+1}(\chi)}{\delta(2k+1)}. \tag*{(107)} t k = k ( k + 1 ) δ P k ′ ( χ ) = δ ( 2 k + 1 ) P k − 1 ( χ ) − P k + 1 ( χ ) . (107) Proof. The identities C p v + = ∣ L ⟩ C_pv_+=|L\rangle C p v + = ∣ L ⟩ and C p v − = ∣ R ⟩ C_pv_-=|R\rangle C p v − = ∣ R ⟩ give
B p ∣ v + , 1 ⟩ = ∣ L , 0 ⟩ , K p ∣ v + , 1 ⟩ = 0 , B_p|v_+,1\rangle=|L,0\rangle,\qquad K_p|v_+,1\rangle=0, B p ∣ v + , 1 ⟩ = ∣ L , 0 ⟩ , K p ∣ v + , 1 ⟩ = 0 , B p ∣ v − , 1 ⟩ = 0 , K p ∣ v − , 1 ⟩ = ∣ R , 2 ⟩ . B_p|v_-,1\rangle=0,\qquad K_p|v_-,1\rangle=|R,2\rangle. B p ∣ v − , 1 ⟩ = 0 , K p ∣ v − , 1 ⟩ = ∣ R , 2 ⟩ . By linearity, it remains to compute the coefficients with initial vector ∣ v − , 1 ⟩ |v_-,1\rangle ∣ v − , 1 ⟩ . Parity again excludes even n n n . For n = 2 k + 1 n=2k+1 n = 2 k + 1 with k ≥ 1 k\geq1 k ≥ 1 , use the words counted by N ( k , r ) N(k,r) N ( k , r ) in the proof of Lemma E.2 . The first + 1 +1 + 1 has coefficient 1. For a word with r r r positive runs, the remaining factors contain k − r k-r k − r transitions R → R R\to R R → R , k + 1 − r k+1-r k + 1 − r transitions L → L L\to L L → L (including the final B p B_p B p factor), and 2 r − 1 2r-1 2 r − 1 changes of label. Their entries are respectively − a , a , b -a,a,b − a , a , b , giving the product ( − a ) k − r a k + 1 − r b 2 r − 1 (-a)^{k-r}a^{k+1-r}b^{2r-1} ( − a ) k − r a k + 1 − r b 2 r − 1 . Summing over r r r therefore gives
t k = a b k ∑ r = 1 k ( k r ) ( k r − 1 ) ( − p ) k − r ( 1 − p ) r − 1 . t_k=\frac{ab}{k}\sum_{r=1}^{k}\binom{k}{r}\binom{k}{r-1}(-p)^{k-r}(1-p)^{r-1}. t k = k ab r = 1 ∑ k ( r k ) ( r − 1 k ) ( − p ) k − r ( 1 − p ) r − 1 . Rodrigues’ formula identifies this finite sum with δ P k ′ ( χ ) / ( k ( k + 1 ) ) \delta P_k'(\chi)/(k(k+1)) δ P k ′ ( χ ) / ( k ( k + 1 )) . The identity ( 1 − χ 2 ) P k ′ ( χ ) = k ( k + 1 ) ( P k − 1 ( χ ) − P k + 1 ( χ ) ) / ( 2 k + 1 ) (1-\chi^2)P_k'(\chi)=k(k+1)(P_{k-1}(\chi)-P_{k+1}(\chi))/(2k+1) ( 1 − χ 2 ) P k ′ ( χ ) = k ( k + 1 ) ( P k − 1 ( χ ) − P k + 1 ( χ )) / ( 2 k + 1 ) gives the second expression in (E.13). □
For a positive 2 × 2 2 \times2 2 × 2 matrix ρ \rho ρ of trace one, put
β ρ ≔ ⟨ v − ∣ ρ ∣ v − ⟩ ∈ [ 0 , 1 ] . \beta_\rho\coloneqq\langle v_-|\rho|v_-\rangle\in[0,1]. β ρ : = ⟨ v − ∣ ρ ∣ v − ⟩ ∈ [ 0 , 1 ] .
The lemma gives quadratic forms proportional to ∣ v + ⟩ ⟨ v + ∣ |v_+\rangle\langle v_+| ∣ v + ⟩ ⟨ v + ∣ at n = 1 n=1 n = 1 and to ∣ v − ⟩ ⟨ v − ∣ |v_-\rangle\langle v_-| ∣ v − ⟩ ⟨ v − ∣ at n = 2 k + 1 n=2k+1 n = 2 k + 1 . Taking their traces against ρ \rho ρ evaluates (E.12) as
h ρ ( s ) = ( 1 − β ρ ) s s + 1 + β ρ ∑ k ≥ 1 s s + 2 k + 1 t k 2 . (108) h_\rho(s)=(1-\beta_\rho)\frac{s}{s+1}+\beta_\rho\sum_{k\geq1}\frac{s}{s+2k+1}t_k^2. \tag*{(108)} h ρ ( s ) = ( 1 − β ρ ) s + 1 s + β ρ k ≥ 1 ∑ s + 2 k + 1 s t k 2 . (108)
As in Section E.2, the expansion follows from two coefficient sums and a tail estimate. Here the Legendre representation makes the two sums accessible through Parseval’s identity.
Theorem E.5 (Asymptotic expansion of the parameterized series). For fixed p ∈ ( 0 , 1 ) p\in(0,1) p ∈ ( 0 , 1 ) and every positive 2 × 2 2 \times2 2 × 2 matrix ρ \rho ρ of trace one, the scalar series (E.14) satisfies
h ρ ( s ) = q ρ − 1 s + λ ρ log s s 2 + O ( s − 2 ) ( s → ∞ ) , (109) h_\rho(s)=q_\rho-\frac{1}{s}+\frac{\lambda_\rho\log s}{s^2}+O(s^{-2})\qquad(s\to\infty), \tag*{(109)} h ρ ( s ) = q ρ − s 1 + s 2 λ ρ log s + O ( s − 2 ) ( s → ∞ ) , (109) where q ρ ≔ 1 − ( 1 − κ p ) β ρ q_\rho\coloneqq1-(1-\kappa_p)\beta_\rho q ρ : = 1 − ( 1 − κ p ) β ρ , λ ρ ≔ 4 β ρ / ( π δ ) \lambda_\rho\coloneqq4\beta_\rho/(\pi\delta) λ ρ : = 4 β ρ / ( π δ ) , and
κ p = 4 π ( δ + χ arcsin χ ) − 1 − χ 2 δ 2 ∈ ( 0 , 1 ) . (110) \kappa_p=\frac{\frac{4}{\pi}(\delta+\chi\arcsin\chi)-1-\chi^2}{\delta^2}\in(0,1). \tag*{(110)} κ p = δ 2 π 4 ( δ + χ arcsin χ ) − 1 − χ 2 ∈ ( 0 , 1 ) . (110)
Proof. To compute the coefficient sums, set u k ≔ ∫ χ 1 P k ( x ) d x u_k\coloneqq\int_\chi^1P_k(x)\,\mathrm{d}x u k : = ∫ χ 1 P k ( x ) d x . Then u 0 = 1 − χ u_0=1-\chi u 0 = 1 − χ and u k = δ t k u_k=\delta t_k u k = δ t k for k ≥ 1 k\geq1 k ≥ 1 . The squared norm of P k P_k P k in L 2 ( − 1 , 1 ) L^2(-1,1) L 2 ( − 1 , 1 ) is 2 / ( 2 k + 1 ) 2/(2k+1) 2/ ( 2 k + 1 ) , so Parseval’s identity for 1 [ χ , 1 ] 1_{[\chi,1]} 1 [ χ , 1 ] gives
∑ k ≥ 0 ( 2 k + 1 ) u k 2 = 2 ( 1 − χ ) . \sum_{k\geq0}(2k+1)u_k^2=2(1-\chi). k ≥ 0 ∑ ( 2 k + 1 ) u k 2 = 2 ( 1 − χ ) .
Subtracting the k = 0 k=0 k = 0 term yields
∑ k ≥ 1 ( 2 k + 1 ) t k 2 = 2 ( 1 − χ ) − ( 1 − χ ) 2 δ 2 = 1. \sum_{k\geq1}(2k+1)t_k^2=\frac{2(1-\chi)-(1-\chi)^2}{\delta^2}=1. k ≥ 1 ∑ ( 2 k + 1 ) t k 2 = δ 2 2 ( 1 − χ ) − ( 1 − χ ) 2 = 1.
For the unweighted sum, put ϕ ≔ arccos χ ∈ ( 0 , π ) \phi\coloneqq\arccos\chi\in(0,\pi) ϕ : = arccos χ ∈ ( 0 , π ) , so sin ϕ = δ \sin\phi=\delta sin ϕ = δ . Integrating the Mehler–Dirichlet formula [46 Eq. (4.8.6)] over x ∈ [ χ , 1 ] x\in[\chi,1] x ∈ [ χ , 1 ] and interchanging the absolutely integrable terms gives
u k = 2 2 π ∫ 0 ϕ cos θ − χ cos ( ( k + 1 2 ) θ ) d θ . u_k=\frac{2\sqrt{2}}{\pi}\int_0^\phi\sqrt{\cos\theta-\chi}\cos\left(\left(k+\frac{1}{2}\right)\theta\right)\,\mathrm{d}\theta. u k = π 2 2 ∫ 0 ϕ cos θ − χ cos ( ( k + 2 1 ) θ ) d θ .
The functions cos ( ( k + 1 2 ) θ ) \cos((k+\frac{1}{2})\theta) cos (( k + 2 1 ) θ ) form a complete orthogonal system in L 2 ( 0 , π ) L^2(0,\pi) L 2 ( 0 , π ) with squared norm π / 2 \pi/2 π /2 . Applying Parseval to cos θ − χ \sqrt{\cos\theta-\chi} cos θ − χ on [ 0 , ϕ ] [0,\phi] [ 0 , ϕ ] , extended by zero, gives
∑ k ≥ 0 u k 2 = 4 π ∫ 0 ϕ ( cos θ − χ ) d θ = 4 π ( δ − χ ϕ ) . \sum_{k\geq0}u_k^2=\frac{4}{\pi}\int_0^\phi(\cos\theta-\chi)\,\mathrm{d}\theta=\frac{4}{\pi}(\delta-\chi\phi). k ≥ 0 ∑ u k 2 = π 4 ∫ 0 ϕ ( cos θ − χ ) d θ = π 4 ( δ − χ ϕ ) .
Subtracting u 0 2 u_0^2 u 0 2 and using ϕ = π / 2 − arcsin χ \phi=\pi/2-\arcsin\chi ϕ = π /2 − arcsin χ yields ∑ k ≥ 1 t k 2 = κ p \sum_{k\geq1}t_k^2=\kappa_p ∑ k ≥ 1 t k 2 = κ p . Since t 1 = a b > 0 t_1=ab>0 t 1 = ab > 0 and 3 ∑ k ≥ 1 t k 2 ≤ ∑ k ≥ 1 ( 2 k + 1 ) t k 2 = 1 3\sum_{k\geq1}t_k^2\leq\sum_{k\geq1}(2k+1)t_k^2=1 3 ∑ k ≥ 1 t k 2 ≤ ∑ k ≥ 1 ( 2 k + 1 ) t k 2 = 1 , we have 0 < κ p < 1 0<\kappa_p<1 0 < κ p < 1 . The two sums determine the constant and s − 1 s^{-1} s − 1 coefficients in (E.14). Applying the geometric remainder identity from (D.6), as in the proof of Theorem E.3, gives
s 2 ( h ρ ( s ) − q ρ + s − 1 ) = ( 1 − β ρ ) s s + 1 + β ρ ∑ k ≥ 1 s ( 2 k + 1 ) 2 s + 2 k + 1 t k 2 . s^2\left(h_\rho(s)-q_\rho+s^{-1}\right)=(1-\beta_\rho)\frac{s}{s+1}+\beta_\rho\sum_{k\geq1}\frac{s(2k+1)^2}{s+2k+1}t_k^2. s 2 ( h ρ ( s ) − q ρ + s − 1 ) = ( 1 − β ρ ) s + 1 s + β ρ k ≥ 1 ∑ s + 2 k + 1 s ( 2 k + 1 ) 2 t k 2 .
To estimate this remainder, apply Darboux’s formula [46 Theorem 8.21.8] to P k − 1 ( χ ) − P k + 1 ( χ ) P_{k-1}(\chi)-P_{k+1}(\chi) P k − 1 ( χ ) − P k + 1 ( χ ) in (E.13). Squaring the resulting leading term gives
t k 2 = 1 − sin ( ( 2 k + 1 ) ϕ ) π δ k 3 + O ( k − 4 ) . t_k^2=\frac{1-\sin((2k+1)\phi)}{\pi\delta k^3}+O(k^{-4}). t k 2 = π δ k 3 1 − sin (( 2 k + 1 ) ϕ ) + O ( k − 4 ) .
Consequently,
∑ k ≥ 1 s ( 2 k + 1 ) 2 s + 2 k + 1 t k 2 = 4 π δ ∑ k ≥ 1 s ( 1 − sin ( ( 2 k + 1 ) ϕ ) ) k ( s + 2 k + 1 ) + O ( 1 ) . \sum_{k\ge1}\frac{s(2k+1)^2}{s+2k+1}t_k^2=\frac{4}{\pi\delta}\sum_{k\ge1}\frac{s(1-\sin((2k+1)\phi))}{k(s+2k+1)}+O(1). k ≥ 1 ∑ s + 2 k + 1 s ( 2 k + 1 ) 2 t k 2 = π δ 4 k ≥ 1 ∑ k ( s + 2 k + 1 ) s ( 1 − sin (( 2 k + 1 ) ϕ )) + O ( 1 ) .
The nonoscillating sum is log s + O ( 1 ) \log s+O(1) log s + O ( 1 ) by the same split at ⌊ s ⌋ \lfloor s\rfloor ⌊ s ⌋ used in Theorem E.3. For the oscillating sum, the partial sums of sin ( ( 2 k + 1 ) ϕ ) \sin((2k+1)\phi) sin (( 2 k + 1 ) ϕ ) are bounded, while s / [ k ( s + 2 k + 1 ) ] s/[k(s+2k+1)] s / [ k ( s + 2 k + 1 )] decreases to zero and has first term at most 1. Summation by parts therefore bounds it uniformly in s s s . The remainder is thus λ ρ log s + O ( 1 ) \lambda_\rho\log s+O(1) λ ρ log s + O ( 1 ) , proving (E.15). □
Extracting runtime properties. Let τ \tau τ be the runtime of L ρ L_\rho L ρ on input ρ ⊗ ∣ 1 ⟩ ⟨ 1 ∣ \rho\otimes|1\rangle\langle1| ρ ⊗ ∣1 ⟩ ⟨ 1∣ . Theorem D.2 reads the termination probability q ρ q_\rho q ρ from the constant term in (E.15). Since h ρ ( s ) = q ρ − s − 1 + o ( s − 1 ) h_\rho(s)=q_\rho-s^{-1}+o(s^{-1}) h ρ ( s ) = q ρ − s − 1 + o ( s − 1 ) , Theorem D.4 with k = 1 k=1 k = 1 gives E ρ [ τ ; τ < ∞ ] = 1 \mathbb{E}_\rho[\tau;\tau<\infty]=1 E ρ [ τ ; τ < ∞ ] = 1 . As q ρ ≥ κ p > 0 q_\rho\ge\kappa_p>0 q ρ ≥ κ p > 0 , conditioning gives
P ρ ( τ < ∞ ) = q ρ , E ρ [ τ ∣ τ < ∞ ] = 1 q ρ . (111) \mathbb{P}_\rho(\tau<\infty)=q_\rho,\qquad\mathbb{E}_\rho[\tau\mid\tau<\infty]=\frac{1}{q_\rho}. \tag*{(111)} P ρ ( τ < ∞ ) = q ρ , E ρ [ τ ∣ τ < ∞ ] = q ρ 1 . (111)
If β ρ > 0 \beta_\rho>0 β ρ > 0 , then λ ρ > 0 \lambda_\rho>0 λ ρ > 0 , so the logarithmic case of Theorem D.6 with k = 2 k=2 k = 2 applies to the remainder in (E.15). It gives
E ρ [ min ( τ , N ) 2 ; τ < ∞ ] = λ ρ log N + O ( 1 ) , (112) \mathbb{E}_\rho[\min(\tau,N)^2;\tau<\infty]=\lambda_\rho\log N+O(1), \tag*{(112)} E ρ [ min ( τ , N ) 2 ; τ < ∞ ] = λ ρ log N + O ( 1 ) , (112)
and the conditional r r r -th moment is finite exactly for 0 < r < 2 0<r<2 0 < r < 2 . By (D.14), the conditional capped second moment has leading term ( λ ρ / q ρ ) log N (\lambda_\rho/q_\rho)\log N ( λ ρ / q ρ ) log N . As in Section E.2, the conditional capped mean is bounded by 1 / q ρ 1/q_\rho 1/ q ρ , so its square contributes only O ( 1 ) O(1) O ( 1 ) to the variance. Hence
Var ρ ( min ( τ , N ) ∣ τ < ∞ ) = 4 β ρ π δ q ρ log N + O ( 1 ) . (113) \operatorname{Var}_\rho(\min(\tau,N)\mid\tau<\infty)=\frac{4\beta_\rho}{\pi\delta q_\rho}\log N+O(1). \tag*{(113)} Var ρ ( min ( τ , N ) ∣ τ < ∞ ) = π δ q ρ 4 β ρ log N + O ( 1 ) . (113)
The divergence probability ( 1 − κ p ) β ρ (1-\kappa_p)\beta_\rho ( 1 − κ p ) β ρ is positive, giving E ρ [ τ ] = ∞ \mathbb{E}_\rho[\tau]=\infty E ρ [ τ ] = ∞ . If β ρ = 0 \beta_\rho=0 β ρ = 0 , Lemma E.4 gives probability one at runtime 1, so τ = 1 \tau=1 τ = 1 almost surely.
Compositional Verification of a Nested Loop
To illustrate how our calculus composes across nested loops without re-analyzing inner loop operators, we verify the termination probability and conditional expected runtime of a probabilistic outer loop L L L that repeatedly invokes the absorbing Hadamard walk of Section A.
Use the coin and position registers of Section A, with identities I c I_c I c , I x I_x I x , and I = I c ⊗ I x I=I_c\otimes I_x I = I c ⊗ I x . The inner subprogram S S S resets the registers to ∣ R , 1 ⟩ |R,1\rangle ∣ R , 1 ⟩ and runs the Hadamard walk loop Walk of Section E.1, while the outer loop L L L guards each invocation of S S S with a fair coin measurement M 0 o u t = M 1 o u t = I / 2 M^{\mathrm{out}}_0=M^{\mathrm{out}}_1=I/\sqrt{2} M 0 out = M 1 out = I / 2 :
S ≡ coin : = ∣ R ⟩ ; position : = ∣ 1 ⟩ ; W a l k , L ≡ while M o u t [ coin , position ] = 1 do S od . \begin{aligned}
S&\equiv\text{coin}:=|R\rangle;\ \text{position}:=|1\rangle;\ \mathrm{Walk},\\
L&\equiv\text{while }M^{\mathrm{out}}[\text{coin},\text{position}]=1\text{ do }S\text{ od}.
\end{aligned} S L ≡ coin := ∣ R ⟩ ; position := ∣1 ⟩ ; Walk , ≡ while M out [ coin , position ] = 1 do S od .
At each outer guard, outcome 0 exits and outcome 1 executes S S S , each with probability 1 / 2 1/2 1/2 . One continuing outer test adds one unit of runtime to that of S S S ; if an invocation of S S S does not terminate, L L L also diverges.
Reusing the inner runtime family. Set σ ≜ ∣ R , 1 ⟩ ⟨ R , 1 ∣ \sigma\triangleq\lvert R,1\rangle\langle R,1\rvert σ ≜ ∣ R , 1 ⟩ ⟨ R , 1 ∣ . By the sequencing rule (C.6) and the state-preparation rule of Section C.1, pulling any postcondition F ∈ Pred ( H ) F \in\operatorname{Pred}(\mathcal{H}) F ∈ Pred ( H ) back through S S S gives
wp ( S , F ) s = wp ( coin : = ∣ R ⟩ ; position : = ∣ 1 ⟩ , wp ( Walk , F ) s ) = tr ( σ wp ( Walk , F ) s ) I . (114) \operatorname{wp}(S,F)_s=\operatorname{wp}(\text{coin}:=\lvert R\rangle;\ \text{position}:=\lvert1\rangle,\operatorname{wp}(\operatorname{Walk},F)_s)=\operatorname{tr}(\sigma\operatorname{wp}(\operatorname{Walk},F)_s)I. \tag*{(114)} wp ( S , F ) s = wp ( coin := ∣ R ⟩ ; position := ∣ 1 ⟩ , wp ( Walk , F ) s ) = tr ( σ wp ( Walk , F ) s ) I . (114)
Specializing (F.1) to F = I F=I F = I directly reuses the scalar runtime test h s = tr ( σ wp ( Walk , I ) s ) h_s=\operatorname{tr}(\sigma\operatorname{wp}(\operatorname{Walk},I)_s) h s = tr ( σ wp ( Walk , I ) s ) expanded in Theorem E.3:
H s S = wp ( S , I ) s = h s I , h s = q − 1 s + o ( s − 1 ) ( s → ∞ ) , q = 2 π . (115) H^S_s=\operatorname{wp}(S,I)_s=h_sI,\qquad h_s=q-\frac{1}{s}+o(s^{-1})\quad(s\to\infty),\qquad q=\frac{2}{\pi}. \tag*{(115)} H s S = wp ( S , I ) s = h s I , h s = q − s 1 + o ( s − 1 ) ( s → ∞ ) , q = π 2 . (115)
Outer loop equation and rational candidate. Applying the loop rule (C.7) of Theorem C.2 to L L L characterizes H L ≜ wp ( L , I ) = lfp ( T I ) H^L\triangleq\operatorname{wp}(L,I)=\operatorname{lfp}(\mathcal{T}_I) H L ≜ wp ( L , I ) = lfp ( T I ) via
( T I X ) s = ( M 0 out ) † I M 0 out + s s + 1 ( M 1 out ) † wp ( S , X ) s + 1 M 1 out = 1 2 I + s 2 ( s + 1 ) wp ( S , X ) s + 1 . (116) (\mathcal{T}_I X)_s=(M_0^{\operatorname{out}})^\dagger I M_0^{\operatorname{out}}+\frac{s}{s+1}(M_1^{\operatorname{out}})^\dagger\operatorname{wp}(S,X)_{s+1}M_1^{\operatorname{out}}=\frac{1}{2}I+\frac{s}{2(s+1)}\operatorname{wp}(S,X)_{s+1}. \tag*{(116)} ( T I X ) s = ( M 0 out ) † I M 0 out + s + 1 s ( M 1 out ) † wp ( S , X ) s + 1 M 1 out = 2 1 I + 2 ( s + 1 ) s wp ( S , X ) s + 1 . (116)
To capture the first-order asymptotics of H s L H^L_s H s L while shifting cleanly under wp ( S , ⋅ ) \operatorname{wp}(S,\cdot) wp ( S , ⋅ ) , we test T I \mathcal{T}_I T I on a bounded rational candidate A ∈ Pred ( H ) A\in\operatorname{Pred}(\mathcal{H}) A ∈ Pred ( H ) of the form
A s ≜ a s s + b I = ( a − a b s + O ( s − 2 ) ) I ( a ∈ ( 0 , 1 ] , b > 0 ) . (117) A_s\triangleq a\frac{s}{s+b}I=\left(a-\frac{ab}{s}+O(s^{-2})\right)I\qquad(a\in(0,1],\ b>0). \tag*{(117)} A s ≜ a s + b s I = ( a − s ab + O ( s − 2 ) ) I ( a ∈ ( 0 , 1 ] , b > 0 ) . (117)
By the grade representation (C.1) and the scale-shift identity (B.11), wp ( S , A ) s \operatorname{wp}(S,A)_s wp ( S , A ) s reduces to H S H^S H S at the shifted scale s + b s+b s + b :
wp ( S , A ) s = ∑ n ≥ 0 s s + n ⟦ S ⟧ n ( a s + n s + b + n I ) = a s s + b ∑ n ≥ 0 s + b s + b + n E n S = a s s + b H s + b S = a s s + b h s + b I . \begin{aligned}
\operatorname{wp}(S,A)_s=\sum_{n\geq0}\frac{s}{s+n}\llbracket S\rrbracket_n\left(a\frac{s+n}{s+b+n}I\right) \\
&=a\frac{s}{s+b}\sum_{n\geq0}\frac{s+b}{s+b+n}E^S_n \\
&=a\frac{s}{s+b}H^S_{s+b}=a\frac{s}{s+b}h_{s+b}I.
\end{aligned} wp ( S , A ) s = n ≥ 0 ∑ s + n s [ [ S ] ] n ( a s + b + n s + n I ) = a s + b s n ≥ 0 ∑ s + b + n s + b E n S = a s + b s H s + b S = a s + b s h s + b I .
Substituting wp ( S , A ) s + 1 \operatorname{wp}(S,A)_{s+1} wp ( S , A ) s + 1 into (F.3) and canceling s + 1 s+1 s + 1 via (B.11) yields
( T I A ) s = [ 1 2 + a 2 s s + 1 + b h s + 1 + b ] I . (118) (\mathcal{T}_I A)_s=\left[\frac{1}{2}+\frac{a}{2}\frac{s}{s+1+b}h_{s+1+b}\right]I. \tag*{(118)} ( T I A ) s = [ 2 1 + 2 a s + 1 + b s h s + 1 + b ] I . (118)
Theorem F.1 (Termination probability and conditional mean runtime of L L L ). Let q = 2 / π q=2/\pi q = 2/ π , and set
a ≜ 1 2 − q = π 2 ( π − 1 ) , b ≜ 1 + q 2 − q = π + 2 2 ( π − 1 ) . a\triangleq\frac{1}{2-q}=\frac{\pi}{2(\pi-1)},\qquad b\triangleq\frac{1+q}{2-q}=\frac{\pi+2}{2(\pi-1)}. a ≜ 2 − q 1 = 2 ( π − 1 ) π , b ≜ 2 − q 1 + q = 2 ( π − 1 ) π + 2 . Then the outer runtime family H s L = wp ( L , I ) s H^L_s=\operatorname{wp}(L,I)_s H s L = wp ( L , I ) s satisfies
∥ H s L − A s ∥ = o ( s − 1 ) ( s → ∞ ) , (119) \lVert H^L_s-A_s\rVert=o(s^{-1})\qquad(s\to\infty), \tag*{(119)} ∥ H s L − A s ∥ = o ( s − 1 ) ( s → ∞ ) , (119) and for every normalized input state ρ \rho ρ ,
P ρ ( τ L < ∞ ) = a = 1 2 − q , \mathbb{P}_{\rho}(\tau_L<\infty)=a=\frac{1}{2-q}, P ρ ( τ L < ∞ ) = a = 2 − q 1 , E ρ [ τ L ; τ L < ∞ ] = a b = 1 + q ( 2 − q ) 2 , E ρ [ τ L ∣ τ L < ∞ ] = b = 1 + q 2 − q . (120) \mathbb{E}_{\rho}[\tau_L;\tau_L<\infty]=ab=\frac{1+q}{(2-q)^2},\qquad\mathbb{E}_{\rho}[\tau_L\mid\tau_L<\infty]=b=\frac{1+q}{2-q}. \tag*{(120)} E ρ [ τ L ; τ L < ∞ ] = ab = ( 2 − q ) 2 1 + q , E ρ [ τ L ∣ τ L < ∞ ] = b = 2 − q 1 + q . (120)
Proof. Inserting h s + 1 + b = q − s − 1 + o ( s − 1 ) h_{s+1+b}=q-s^{-1}+o(s^{-1}) h s + 1 + b = q − s − 1 + o ( s − 1 ) from (F.2) and s s + 1 + b = 1 − 1 + b s + O ( s − 2 ) \frac{s}{s+1+b}=1-\frac{1+b}{s}+O(s^{-2}) s + 1 + b s = 1 − s 1 + b + O ( s − 2 ) into (F.5) gives
( T I A ) s = [ 1 2 + a q 2 − a ( q ( 1 + b ) + 1 ) 2 s + o ( s − 1 ) ] I . (\mathcal{T}_I A)_s=\left[\frac{1}{2}+\frac{aq}{2}-\frac{a(q(1+b)+1)}{2s}+o(s^{-1})\right]I. ( T I A ) s = [ 2 1 + 2 a q − 2 s a ( q ( 1 + b ) + 1 ) + o ( s − 1 ) ] I .
e n d s m i d = 1 {ends_mid=1} e n d s m i d = 1
The choices a = ( 2 − q ) − 1 a=(2-q)^{-1} a = ( 2 − q ) − 1 and b = ( 1 + q ) ( 2 − q ) − 1 b=(1+q)(2-q)^{-1} b = ( 1 + q ) ( 2 − q ) − 1 satisfy 1 2 + a q 2 = a \frac{1}{2}+\frac{aq}{2}=a 2 1 + 2 a q = a and 1 2 ( q ( 1 + b ) + 1 ) = b \frac{1}{2}(q(1+b)+1)=b 2 1 ( q ( 1 + b ) + 1 ) = b , matching (F.4) to order s − 1 s^{-1} s − 1 and leaving
∥ A s − ( T A ) s ∥ = o ( s − 1 ) ( s → ∞ ) . \lVert A_s-(\mathcal{T}A)_s\rVert=o(s^{-1}) \qquad(s\to\infty). ∥ A s − ( T A ) s ∥ = o ( s − 1 ) ( s → ∞ ) .
Since H u + 1 S ≤ I H^S_{u+1}\le I H u + 1 S ≤ I , we have
u u + 1 ( M 1 o u t ) † H u + 1 S M 1 o u t = u 2 ( u + 1 ) H u + 1 S ≤ 1 2 I ( u > 0 ) , \frac{u}{u+1}(M^{\mathrm{out}}_1)^\dagger H^S_{u+1}M^{\mathrm{out}}_1=\frac{u}{2(u+1)}H^S_{u+1}\le\frac{1}{2}I \qquad(u>0), u + 1 u ( M 1 out ) † H u + 1 S M 1 out = 2 ( u + 1 ) u H u + 1 S ≤ 2 1 I ( u > 0 ) ,
so Theorem C.5 with κ = 1 / 2 < 1 \kappa=1/2<1 κ = 1/2 < 1 gives (F.6). Consequently, for any normalized input ρ \rho ρ , (F.4) and (F.6) yield
tr ( ρ H s L ) = tr ( ρ A s ) + o ( s − 1 ) = a − a b s + o ( s − 1 ) ( s → ∞ ) . \operatorname{tr}(\rho H^L_s)=\operatorname{tr}(\rho A_s)+o(s^{-1})=a-\frac{ab}{s}+o(s^{-1}) \qquad(s\to\infty). tr ( ρ H s L ) = tr ( ρ A s ) + o ( s − 1 ) = a − s ab + o ( s − 1 ) ( s → ∞ ) .
Theorems D.2 and D.4 (k = 1 k=1 k = 1 ) extract P ρ ( τ L < ∞ ) = a \mathbb{P}_{\rho}(\tau_L<\infty)=a P ρ ( τ L < ∞ ) = a and E ρ [ τ L ; τ L < ∞ ] = a b \mathbb{E}_{\rho}[\tau_L;\tau_L<\infty]=ab E ρ [ τ L ; τ L < ∞ ] = ab , and dividing by a a a gives E ρ [ τ L ∣ τ L < ∞ ] = b \mathbb{E}_{\rho}[\tau_L\mid\tau_L<\infty]=b E ρ [ τ L ∣ τ L < ∞ ] = b . □
Reusing Total-Cost Proofs
The cost logic of [59 ] proves upper bounds on expected execution costs and terminal observables using closed positive quadratic forms. Such proofs can also supply contracts for the parameterized calculus developed here. We first recall total-cost Hoare triples and their proof rules under our loop-iteration cost convention, then show how normalized resolvents translate these contracts into valid total-correctness Hoare triples on bounded effect families.
Total-Cost Logic with Closed Positive Forms
A cost predicate is a closed positive quadratic form P : H → [ 0 , ∞ ] P:\mathcal{H}\to[0,\infty] P : H → [ 0 , ∞ ] , with finite domain Dom ( P ) = { u : P [ u ] < ∞ } \operatorname{Dom}(P)=\{u:P[u]<\infty\} Dom ( P ) = { u : P [ u ] < ∞ } . The domain may be non-dense, allowing the predicate to impose an infinite penalty outside a prescribed subspace. Cost predicates are ordered pointwise:
P ≤ G ⟺ P [ u ] ≤ G [ u ] ( u ∈ H ) . P\le G\quad\Longleftrightarrow\quad P[u]\le G[u]\quad(u\in\mathcal{H}). P ≤ G ⟺ P [ u ] ≤ G [ u ] ( u ∈ H ) .
Increasing sequences have pointwise suprema that are again closed positive forms. This order structure supports the loop constructions in the cost logic [59 Sections 4–5] .
To define expectations, let H P ≔ Dom ( P ) \mathcal{H}_P\coloneqq\operatorname{Dom}(P) H P : = Dom ( P ) and let T P T_P T P be the positive self-adjoint operator on H P \mathcal{H}_P H P representing P P P , so that P [ u ] = ∥ T P 1 / 2 u ∥ 2 P[u]=\lVert T_P^{1/2}u\rVert^2 P [ u ] = ∥ T P 1/2 u ∥ 2 on Dom ( P ) = Dom ( T P 1 / 2 ) \operatorname{Dom}(P)=\operatorname{Dom}(T_P^{1/2}) Dom ( P ) = Dom ( T P 1/2 ) . Its bounded spectral truncations are
P [ N ] ≔ min ( T P , N I H P ) ⊕ N I H P ⊥ ( N ≥ 1 ) , P^{[N]}\coloneqq\min(T_P,NI_{\mathcal{H}_P})\oplus NI_{\mathcal{H}_P^\perp}\qquad(N\ge1), P [ N ] : = min ( T P , N I H P ) ⊕ N I H P ⊥ ( N ≥ 1 ) ,
where the first term is defined by spectral calculus. They increase to P P P as quadratic forms, and the extended trace is
tr ( P ρ ) ≔ sup N ≥ 1 tr ( P [ N ] ρ ) ∈ [ 0 , ∞ ] . \operatorname{tr}(P\rho)\coloneqq\sup_{N\ge1}\operatorname{tr}(P^{[N]}\rho)\in[0,\infty]. tr ( P ρ ) : = N ≥ 1 sup tr ( P [ N ] ρ ) ∈ [ 0 , ∞ ] .
For a CPTNI map E \mathcal{E} E , its Heisenberg adjoint extends to cost forms by
E c † ( G ) ≔ sup N ≥ 1 E † ( G [ N ] ) , tr ( E c † ( G ) ρ ) = tr ( G E ( ρ ) ) . (121) \mathcal{E}_c^\dagger(G)\coloneqq\sup_{N\ge1}\mathcal{E}^\dagger(G^{[N]}),\qquad\operatorname{tr}(\mathcal{E}_c^\dagger(G)\rho)=\operatorname{tr}(G\mathcal{E}(\rho)). \tag*{(121)} E c † ( G ) : = N ≥ 1 sup E † ( G [ N ] ) , tr ( E c † ( G ) ρ ) = tr ( G E ( ρ )) . (121)
The supremum is taken in the order of closed positive forms; the trace identity follows by monotone convergence [59 Theorem 4.1] . In particular, K † G K K^\dagger G K K † G K denotes the form u ↦ G [ K u ] u\mapsto G[Ku] u ↦ G [ K u ] for a bounded operator K K K .
We use the cost convention of Section B: each entry into a loop body costs one, terminating loop-free commands and loop exits cost zero, and a nonterminating execution has infinite cost.
Thus the cost predicate is C S = M 1 S + ∞ D S C_S = M_1^S + \infty D_S C S = M 1 S + ∞ D S from (B.9). For cost predicates P , G P,G P , G , the validity of the total-cost Hoare triple { P } S { G } \{P\}\ S\ \{G\} { P } S { G } is defined by
⊨ C , t o t { P } S { G } ⟺ tr ( P ρ ) ≥ tr ( G ⟦ S ⟧ ( ρ ) ) + tr ( C S ρ ) for every state ρ . (122) \models_{C,\mathrm{tot}}\ \{P\}\ S\ \{G\}\quad\Longleftrightarrow\quad\operatorname{tr}(P\rho) \ge\operatorname{tr}\bigl(G\llbracket S\rrbracket(\rho)\bigr) + \operatorname{tr}(C_S\rho)\quad\text{for every state }\rho. \tag*{(122)} ⊨ C , tot { P } S { G } ⟺ tr ( P ρ ) ≥ tr ( G [ [ S ] ] ( ρ ) ) + tr ( C S ρ ) for every state ρ . (122)
The precondition P P P therefore bounds the sum of the execution cost and the terminal cost G G G . Its least valid value is the cost weakest precondition
wp C ( S , G ) ≜ ⟦ S ⟧ † ( G ) + C S , ⊨ C , t o t { P } S { G } ⟺ P ≥ wp C ( S , G ) . (123) \operatorname{wp}_C(S,G) \triangleq\llbracket S\rrbracket^\dagger(G) + C_S,\qquad\models_{C,\mathrm{tot}}\ \{P\}\ S\ \{G\}\quad\Longleftrightarrow\quad P \ge\operatorname{wp}_C(S,G). \tag*{(123)} wp C ( S , G ) ≜ [ [ S ] ] † ( G ) + C S , ⊨ C , tot { P } S { G } ⟺ P ≥ wp C ( S , G ) . (123)
This is the cost-transformer construction of [59 Proposition 5.2] , with its command costs replaced by the loop-iteration costs above.
The structural rules pull terminal costs backwards and add the cost of each command. For the basic commands they give
wp C ( skip , G ) = G , wp C ( abort , G ) = ∞ I , \operatorname{wp}_C(\operatorname{skip},G) = G,\qquad\operatorname{wp}_C(\operatorname{abort},G) = \infty I, wp C ( skip , G ) = G , wp C ( abort , G ) = ∞ I ,
wp C ( q : = ∣ 0 ⟩ , G ) = ∑ j ∣ j ⟩ ⟨ 0 ∣ q G ∣ 0 ⟩ ⟨ j ∣ q , wp C ( q ˉ : = U [ q ˉ ] , G ) = U † G U . \operatorname{wp}_C(q := |0\rangle,G) = \sum_j |j\rangle\langle0|_qG|0\rangle\langle j|_q,\qquad\operatorname{wp}_C(\bar{q} := U[\bar{q}],G) = U^\dagger G U. wp C ( q := ∣0 ⟩ , G ) = j ∑ ∣ j ⟩ ⟨ 0 ∣ q G ∣0 ⟩ ⟨ j ∣ q , wp C ( q ˉ := U [ q ˉ ] , G ) = U † G U .
Sequential composition uses the precondition of the second program as the postcondition of the first:
wp C ( S 1 ; S 2 , G ) = wp C ( S 1 , wp C ( S 2 , G ) ) . \operatorname{wp}_C(S_1;S_2,G) = \operatorname{wp}_C\bigl(S_1,\operatorname{wp}_C(S_2,G)\bigr). wp C ( S 1 ; S 2 , G ) = wp C ( S 1 , wp C ( S 2 , G ) ) .
For a conditional S i f = if ( □ i ∈ J M i [ q ˉ ] = i → S i ) fi S_{\mathrm{if}} = \operatorname{if}\bigl(\Box_{i\in J}\ M_i[\bar{q}] = i \mathbin{\to} S_i\bigr)\operatorname{fi} S if = if ( □ i ∈ J M i [ q ˉ ] = i → S i ) fi , the branch costs combine as
wp C ( S i f , G ) = ∑ i ∈ J M i † wp C ( S i , G ) M i . \operatorname{wp}_C(S_{\mathrm{if}},G) = \sum_{i\in J} M_i^\dagger\operatorname{wp}_C(S_i,G)M_i. wp C ( S if , G ) = i ∈ J ∑ M i † wp C ( S i , G ) M i .
All sums and pullbacks here are interpreted as quadratic forms. For a loop L = while M [ q ˉ ] = 1 do B od L = \operatorname{while}\ M[\bar{q}] = 1\ \operatorname{do}\ B\ \operatorname{od} L = while M [ q ˉ ] = 1 do B od , define
K G ( X ) ≜ M 0 † G M 0 + M 1 † ( I + wp C ( B , X ) ) M 1 . (124) \mathcal{K}_G(X) \triangleq M_0^\dagger G M_0 + M_1^\dagger\bigl(I+\operatorname{wp}_C(B,X)\bigr)M_1. \tag*{(124)} K G ( X ) ≜ M 0 † G M 0 + M 1 † ( I + wp C ( B , X ) ) M 1 . (124)
The exit branch returns G G G , while the continuing branch pays one unit before executing the body. Starting from X 0 = 0 X_0 = 0 X 0 = 0 and setting X m + 1 = K G ( X m ) X_{m+1} = \mathcal{K}_G(X_m) X m + 1 = K G ( X m ) gives
wp C ( L , G ) = sup m ≥ 0 X m . \operatorname{wp}_C(L,G) = \sup_{m\ge0} X_m. wp C ( L , G ) = m ≥ 0 sup X m .
These rules agree with (G.3) by structural induction using Definition B.1: sequencing adds runtimes, and conditionals sum branch costs. For a loop, X m X_m X m records the costs of up to m m m outer iterations, including each reached body’s full cost, and G G G on exits after fewer than m m m outer iterations. Monotone convergence recovers the terminal expectation plus total expected runtime; a divergent run either enters infinitely many outer iterations or incurs infinite cost inside a reached body.
Consequently, a cost predicate P P P satisfying P ≥ K G ( P ) P \ge\mathcal{K}_G(P) P ≥ K G ( P ) proves ⊨ C , t o t { P } L { G } \models_{C,\mathrm{tot}}\ \{P\}\ L\ \{G\} ⊨ C , tot { P } L { G } . Indeed, monotonicity gives X m ≤ P X_m \le P X m ≤ P by induction. This is the invariant-and-potential rule underlying the expected-runtime analysis in Section A.
Resolvent Translation of Total Correctness
To turn a cost bound into a bounded guarantee, we apply the normalized resolvent to its pre- and postconditions. The proof uses two order properties: the resolvent reverses cost inequalities, and the operator Jensen inequality compares a resolvent of an expected cost with the expectation of its resolvent. We establish these properties first for bounded operators and then extend them to closed positive forms.
Definition G.1 (Normalized resolvents of cost forms). For a closed positive form P P P and s > 0 s>0 s > 0 , define
R s ( P ) ≔ s ( s I H P + T P ) − 1 ⊕ 0 H P ⊥ , R ( P ) ≔ ( R s ( P ) ) s > 0 . R_s(P) \coloneqq s(sI_{\mathcal H_P}+T_P)^{-1}\oplus0_{\mathcal H_P^\perp}, \qquad R(P)\coloneqq(R_s(P))_{s>0}. R s ( P ) : = s ( s I H P + T P ) − 1 ⊕ 0 H P ⊥ , R ( P ) : = ( R s ( P ) ) s > 0 . Thus R s ( P ) R_s(P) R s ( P ) is an effect on H \mathcal H H , and R ( P ) ∈ Pred ( H ) R(P)\in\operatorname{Pred}(\mathcal H) R ( P ) ∈ Pred ( H ) . For bounded P P P it equals ( I + P / s ) − 1 (I+P/s)^{-1} ( I + P / s ) − 1 ; in particular, R s ( 0 ) = I R_s(0)=I R s ( 0 ) = I and R s ( ∞ I ) = 0 R_s(\infty I)=0 R s ( ∞ I ) = 0 .
The resolvent has the variational characterization
⟨ u , R s ( P ) u ⟩ = sup v ∈ Dom ( P ) { 2 Re ⟨ u , v ⟩ − ∥ v ∥ 2 − P [ v ] s } . (125) \langle u,R_s(P)u\rangle=\sup_{v\in\operatorname{Dom}(P)}\left\{2\operatorname{Re}\langle u,v\rangle-\lVert v\rVert^2-\frac{P[v]}{s}\right\}. \tag*{(125)} ⟨ u , R s ( P ) u ⟩ = v ∈ Dom ( P ) sup { 2 Re ⟨ u , v ⟩ − ∥ v ∥ 2 − s P [ v ] } . (125) To see this, write u = u 0 + u ⊥ u=u_0+u_\perp u = u 0 + u ⊥ according to H = H P ⊕ H P ⊥ \mathcal H=\mathcal H_P\oplus\mathcal H_P^\perp H = H P ⊕ H P ⊥ and complete the square with ( I + T P / s ) 1 / 2 v (I+T_P/s)^{1/2}v ( I + T P / s ) 1/2 v . The supremum is attained at v = ( I + T P / s ) − 1 u 0 v=(I+T_P/s)^{-1}u_0 v = ( I + T P / s ) − 1 u 0 and equals ⟨ u 0 , ( I + T P / s ) − 1 u 0 ⟩ \langle u_0,(I+T_P/s)^{-1}u_0\rangle ⟨ u 0 , ( I + T P / s ) − 1 u 0 ⟩ . If P ≥ G P\ge G P ≥ G , then Dom ( P ) ⊆ Dom ( G ) \operatorname{Dom}(P)\subseteq\operatorname{Dom}(G) Dom ( P ) ⊆ Dom ( G ) and the expression being maximized for P P P is no larger than that for G G G . Hence
P ≥ G ⟹ R s ( P ) ≤ R s ( G ) ( s > 0 ) . (126) P\ge G\quad\Longrightarrow\quad R_s(P)\le R_s(G)\qquad(s>0). \tag*{(126)} P ≥ G ⟹ R s ( P ) ≤ R s ( G ) ( s > 0 ) . (126)
Definition G.2 (Operator convexity). A continuous function f : [ 0 , ∞ ) → R f:[0,\infty)\to\mathbb R f : [ 0 , ∞ ) → R is operator convex if, for all bounded positive operators A , B A,B A , B on any Hilbert space and every λ ∈ [ 0 , 1 ] \lambda\in[0,1] λ ∈ [ 0 , 1 ] ,
f ( λ A + ( 1 − λ ) B ) ≤ λ f ( A ) + ( 1 − λ ) f ( B ) . f(\lambda A+(1-\lambda)B)\le\lambda f(A)+(1-\lambda)f(B). f ( λ A + ( 1 − λ ) B ) ≤ λ f ( A ) + ( 1 − λ ) f ( B ) .
Lemma G.3 (Choi–Davis–Jensen inequality). Let A \mathcal A A be a unital C ∗ C^* C ∗ -algebra and let Φ : A → B ( H ) \Phi:\mathcal A\to\mathcal B(\mathcal H) Φ : A → B ( H ) be a unital completely positive map. If f : [ 0 , ∞ ) → R f:[0,\infty)\to\mathbb R f : [ 0 , ∞ ) → R is operator convex, then for every positive X ∈ A X\in\mathcal A X ∈ A ,
f ( Φ ( X ) ) ≤ Φ ( f ( X ) ) . f(\Phi(X))\le\Phi(f(X)). f ( Φ ( X )) ≤ Φ ( f ( X )) . Proof. We give the compression argument for the operator Jensen inequality [25 ] . By Stinespring’s theorem, Φ ( X ) = V † π ( X ) V \Phi(X)=V^\dagger\pi(X)V Φ ( X ) = V † π ( X ) V , where π : A → B ( K ) \pi:\mathcal A\to\mathcal B(\mathcal K) π : A → B ( K ) is a unital ∗ * ∗ -representation and V : H → K V:\mathcal H\to\mathcal K V : H → K is an isometry. Put E = V V † E=VV^\dagger E = V V † and U = 2 E − I K U=2E-I_{\mathcal K} U = 2 E − I K . Then U U U is a self-adjoint unitary. For Y = π ( X ) Y=\pi(X) Y = π ( X ) , averaging with its conjugate by U U U removes the off-diagonal blocks relative to E E E :
Z ≔ 1 2 ( Y + U Y U † ) = E Y E + ( I − E ) Y ( I − E ) . Z\coloneqq\frac{1}{2}(Y+UYU^\dagger)=EYE+(I-E)Y(I-E). Z : = 2 1 ( Y + U Y U † ) = E Y E + ( I − E ) Y ( I − E ) . Operator convexity and unitary invariance of functional calculus give
f ( Z ) ≤ 1 2 ( f ( Y ) + U f ( Y ) U † ) = E f ( Y ) E + ( I − E ) f ( Y ) ( I − E ) . f(Z)\le\frac{1}{2}(f(Y)+Uf(Y)U^\dagger)
=Ef(Y)E+(I-E)f(Y)(I-E). f ( Z ) ≤ 2 1 ( f ( Y ) + U f ( Y ) U † ) = E f ( Y ) E + ( I − E ) f ( Y ) ( I − E ) . Compressing by V V V therefore yields V † f ( Z ) V ≤ V † f ( Y ) V V^\dagger f(Z)V\le V^\dagger f(Y)V V † f ( Z ) V ≤ V † f ( Y ) V . Since Z Z Z commutes with E E E and V † E V = I V^\dagger EV=I V † E V = I , its restriction to E K E\mathcal K E K is unitarily identified with V † Z V = V † Y V V^\dagger ZV=V^\dagger YV V † Z V = V † Y V . More explicitly, ( V † Z V ) m = V † Z m V (V^\dagger ZV)^m=V^\dagger Z^mV ( V † Z V ) m = V † Z m V for every nonnegative integer m m m , so polynomial approximation gives
V † f ( Z ) V = f ( V † Z V ) = f ( V † Y V ) . V^\dagger f(Z)V=f(V^\dagger ZV)=f(V^\dagger YV). V † f ( Z ) V = f ( V † Z V ) = f ( V † Y V ) . Combining the two identities and using f ( π ( X ) ) = π ( f ( X ) ) f(\pi(X))=\pi(f(X)) f ( π ( X )) = π ( f ( X )) , we obtain
f ( Φ ( X ) ) = f ( V † Y V ) ≤ V † f ( Y ) V = V † π ( f ( X ) ) V = Φ ( f ( X ) ) . f(\Phi(X))=f(V^\dagger YV)\le V^\dagger f(Y)V=V^\dagger\pi(f(X))V=\Phi(f(X)). f ( Φ ( X )) = f ( V † Y V ) ≤ V † f ( Y ) V = V † π ( f ( X )) V = Φ ( f ( X )) .
Proposition G.4 (Operator convexity of the normalized resolvent). For every s > 0 s>0 s > 0 , the function r s ( t ) = s / ( s + t ) r_s(t)=s/(s+t) r s ( t ) = s / ( s + t ) is operator convex on [ 0 , ∞ ) [0,\infty) [ 0 , ∞ ) .
Proof. We prove convexity of inversion on bounded positive invertible operators. For such an operator Z Z Z , the block matrix
( Z I I Z − 1 ) \begin{pmatrix} Z & I \\ I & Z^{-1} \end{pmatrix} ( Z I I Z − 1 )
is positive, because its quadratic form at ( u , v ) (u,v) ( u , v ) is ∥ Z 1 / 2 u + Z − 1 / 2 v ∥ 2 \lVert Z^{1/2}u+Z^{-1/2}v\rVert^2 ∥ Z 1/2 u + Z − 1/2 v ∥ 2 . Thus, for positive invertible X X X , Y Y Y and λ ∈ [ 0 , 1 ] \lambda\in[0,1] λ ∈ [ 0 , 1 ] ,
( λ X + ( 1 − λ ) Y I I λ X − 1 + ( 1 − λ ) Y − 1 ) ≥ 0. \begin{pmatrix}
\lambda X+(1-\lambda)Y & I \\
I & \lambda X^{-1}+(1-\lambda)Y^{-1}
\end{pmatrix}\geq0. ( λ X + ( 1 − λ ) Y I I λ X − 1 + ( 1 − λ ) Y − 1 ) ≥ 0.
Taking the Schur complement of the positive invertible upper-left block gives
( λ X + ( 1 − λ ) Y ) − 1 ≤ λ X − 1 + ( 1 − λ ) Y − 1 . \left(\lambda X+(1-\lambda)Y\right)^{-1}\leq\lambda X^{-1}+(1-\lambda)Y^{-1}. ( λ X + ( 1 − λ ) Y ) − 1 ≤ λ X − 1 + ( 1 − λ ) Y − 1 .
For bounded A , B ≥ 0 A,B\geq0 A , B ≥ 0 , substitute X = s I + A X=sI+A X = s I + A and Y = s I + B Y=sI+B Y = s I + B , then multiply by s s s . This gives
R s ( λ A + ( 1 − λ ) B ) ≤ λ R s ( A ) + ( 1 − λ ) R s ( B ) , R_s\left(\lambda A+(1-\lambda)B\right)\leq\lambda R_s(A)+(1-\lambda)R_s(B), R s ( λ A + ( 1 − λ ) B ) ≤ λ R s ( A ) + ( 1 − λ ) R s ( B ) ,
as required. □
Corollary G.5 (Resolvent Jensen inequality for closed positive forms). Let P P P be a closed positive form on K K K , and let Φ : B ( K ) → B ( H ) \Phi:\mathcal{B}(K)\to\mathcal{B}(H) Φ : B ( K ) → B ( H ) be a normal unital completely positive map. Define its extension to P P P by
Φ ^ ( P ) ≔ sup N ≥ 1 Φ ( P [ N ] ) . \widehat{\Phi}(P)\coloneqq\sup_{N\geq1}\Phi\left(P^{[N]}\right). Φ ( P ) : = N ≥ 1 sup Φ ( P [ N ] ) . Then, for every s > 0 s>0 s > 0 ,
R s ( Φ ^ ( P ) ) ≤ Φ ( R s ( P ) ) . (127) R_s\left(\widehat{\Phi}(P)\right)\leq\Phi\left(R_s(P)\right). \tag*{(127)} R s ( Φ ( P ) ) ≤ Φ ( R s ( P ) ) . (127)
Proof. Each P [ N ] P^{[N]} P [ N ] is bounded and positive, so Lemma G.3 and Proposition G.4 give
R s ( Φ ( P [ N ] ) ) ≤ Φ ( R s ( P [ N ] ) ) . R_s\left(\Phi\left(P^{[N]}\right)\right)\leq\Phi\left(R_s\left(P^{[N]}\right)\right). R s ( Φ ( P [ N ] ) ) ≤ Φ ( R s ( P [ N ] ) ) .
As N → ∞ N\to\infty N → ∞ , the quadratic forms of Φ ( P [ N ] ) \Phi(P^{[N]}) Φ ( P [ N ] ) increase monotonically to Φ ^ ( P ) \widehat{\Phi}(P) Φ ( P ) . Monotone convergence for closed positive forms implies that the operators R s ( Φ ( P [ N ] ) ) R_s(\Phi(P^{[N]})) R s ( Φ ( P [ N ] )) decrease monotonically and converge strongly to R s ( Φ ^ ( P ) ) R_s(\widehat{\Phi}(P)) R s ( Φ ( P )) [45 , 59 ] . Spectral calculus likewise shows that R s ( P [ N ] ) R_s(P^{[N]}) R s ( P [ N ] ) decreases monotonically and converges strongly to R s ( P ) R_s(P) R s ( P ) . Normality of Φ \Phi Φ preserves this bounded decreasing limit, as follows by applying it to the increasing sequence I − R s ( P [ N ] ) I-R_s(P^{[N]}) I − R s ( P [ N ] ) . Taking matrix elements and passing to the limit proves (G.7). □
Total-cost validity accounts for divergence through C S C_S C S . The next lemma isolates the bound that makes the divergent contribution disappear after applying the resolvent.
Lemma G.6 (Divergence bound). For every program S S S and every integer N ≥ 1 N\geq1 N ≥ 1 ,
C S ≥ ∑ n ≥ 0 min ( n , N ) E n S + N D S ≥ N D S . (128) C_S\geq\sum_{n\geq0}\min(n,N)E_n^S+ND_S\geq ND_S. \tag*{(128)} C S ≥ n ≥ 0 ∑ min ( n , N ) E n S + N D S ≥ N D S . (128) Consequently, if ⊨ C , t o t { P } S { G } \models_{C,\mathrm{tot}}\{P\}\ S\ \{G\} ⊨ C , tot { P } S { G } and tr ( P ρ ) < ∞ \operatorname{tr}(P\rho)<\infty tr ( P ρ ) < ∞ for a normalized state ρ \rho ρ , then S S S has finite expected runtime and terminates almost surely on ρ \rho ρ .
Proof. The first inequality follows from (B.9), which defines C S C_S C S as the supremum of these capped costs; the second follows from positivity of the sum. Validity of the assumed total-cost Hoare triple gives tr ( C S ρ ) ≤ tr ( P ρ ) < ∞ \operatorname{tr}(C_S\rho)\leq\operatorname{tr}(P\rho)<\infty tr ( C S ρ ) ≤ tr ( P ρ ) < ∞ . Since N tr ( D S ρ ) ≤ tr ( C S ρ ) N\operatorname{tr}(D_S\rho)\leq\operatorname{tr}(C_S\rho) N tr ( D S ρ ) ≤ tr ( C S ρ ) for every N N N , we obtain tr ( D S ρ ) = 0 \operatorname{tr}(D_S\rho)=0 tr ( D S ρ ) = 0 . □
Theorem G.7 (Translation of total-cost contracts). For closed positive cost forms P , G P,G P , G and a program S S S ,
⊨ C , t o t { P } S { G } ⟹ ⊨ t o t { R ( P ) } S { R ( G ) } . (129) \models_{C,\mathrm{tot}}\{P\}\ S\ \{G\}\quad\Longrightarrow\quad\models_{\mathrm{tot}}\{R(P)\}\ S\ \{R(G)\}. \tag*{(129)} ⊨ C , tot { P } S { G } ⟹ ⊨ tot { R ( P )} S { R ( G )} . (129) Equivalently, a valid total-cost contract gives
R s ( P ) ≤ wp ( S , R ( G ) ) s = ∑ n ≥ 0 s s + n ⟦ S ⟧ n † ( R s + n ( G ) ) ( s > 0 ) . R_s(P)\leq\operatorname{wp}(S,R(G))_s=\sum_{n\geq0}\frac{s}{s+n}\llbracket S\rrbracket_n^{\dagger}(R_{s+n}(G))\qquad(s>0). R s ( P ) ≤ wp ( S , R ( G ) ) s = n ≥ 0 ∑ s + n s [ [ S ] ] n † ( R s + n ( G )) ( s > 0 ) . Proof. Fix s > 0 s>0 s > 0 . We record each terminating runtime in a separate output block and add one block for divergence. Let
K ≜ ( ⨁ n ∈ N H ) ⊕ C . \mathcal{K}\triangleq\left(\bigoplus_{n\in\mathbb{N}}\mathcal{H}\right)\oplus\mathbb{C}. K ≜ ( n ∈ N ⨁ H ) ⊕ C . For a positive trace-class operator ρ \rho ρ , define
Ψ ∗ ( ρ ) ≜ ( ⨁ n ≥ 0 ⟦ S ⟧ n ( ρ ) ) ⊕ tr ( D S ρ ) . (130) \Psi_*(\rho)\triangleq\left(\bigoplus_{n\geq0}\llbracket S\rrbracket_n(\rho)\right)\oplus\operatorname{tr}(D_S\rho). \tag*{(130)} Ψ ∗ ( ρ ) ≜ ( n ≥ 0 ⨁ [ [ S ] ] n ( ρ ) ) ⊕ tr ( D S ρ ) . (130) The direct sum converges in trace norm, and
tr ( Ψ ∗ ( ρ ) ) = ∑ n ≥ 0 tr ( ⟦ S ⟧ n ( ρ ) ) + tr ( D S ρ ) = tr ( ( Q S + D S ) ρ ) = tr ( ρ ) . \operatorname{tr}(\Psi_*(\rho))=\sum_{n\geq0}\operatorname{tr}(\llbracket S\rrbracket_n(\rho))+\operatorname{tr}(D_S\rho)=\operatorname{tr}((Q_S+D_S)\rho)=\operatorname{tr}(\rho). tr ( Ψ ∗ ( ρ )) = n ≥ 0 ∑ tr ( [ [ S ] ] n ( ρ )) + tr ( D S ρ ) = tr (( Q S + D S ) ρ ) = tr ( ρ ) . Complete positivity holds blockwise, so linear extension gives a trace-preserving CP map Ψ ∗ : T ( H ) → T ( K ) \Psi_*:\mathcal{T}(\mathcal{H})\to\mathcal{T}(\mathcal{K}) Ψ ∗ : T ( H ) → T ( K ) . Its Heisenberg adjoint Ψ : B ( K ) → B ( H ) \Psi:\mathcal{B}(\mathcal{K})\to\mathcal{B}(\mathcal{H}) Ψ : B ( K ) → B ( H ) is therefore normal and unital.
For N ∈ N + N\in\mathbb{N}_+ N ∈ N + , define the closed positive form on K \mathcal{K} K
X N ≜ ( ⨁ n ≥ 0 ( G + min ( n , N ) I ) ) ⊕ N I C . X_N\triangleq\left(\bigoplus_{n\geq0}(G+\min(n,N)I)\right)\oplus NI_{\mathbb{C}}. X N ≜ ( n ≥ 0 ⨁ ( G + min ( n , N ) I ) ) ⊕ N I C . Extended trace duality gives
Ψ ^ ( X N ) = ⟦ S ⟧ ^ † ( G ) + ∑ n ≥ 0 min ( n , N ) E n S + N D S . \widehat{\Psi}(X_N)=\widehat{\llbracket S\rrbracket}^{\dagger}(G)+\sum_{n\geq0}\min(n,N)E_n^S+ND_S. Ψ ( X N ) = [ [ S ] ] † ( G ) + n ≥ 0 ∑ min ( n , N ) E n S + N D S . Here the terminal-cost terms combine by monotone convergence:
∑ n ≥ 0 tr ( G ⟦ S ⟧ n ( ρ ) ) = tr ( G ⟦ S ⟧ ( ρ ) ) ( ρ ≥ 0 ) . \sum_{n\geq0}\operatorname{tr}(G\llbracket S\rrbracket_n(\rho))=\operatorname{tr}(G\llbracket S\rrbracket(\rho))\qquad(\rho\geq0). n ≥ 0 ∑ tr ( G [ [ S ] ] n ( ρ )) = tr ( G [ [ S ] ] ( ρ )) ( ρ ≥ 0 ) . Thus total-cost validity, (G.3), and Lemma G.6 imply
P ≥ ⟦ S ⟧ ^ † ( G ) + C S ≥ Ψ ^ ( X N ) . P\geq\widehat{\llbracket S\rrbracket}^{\dagger}(G)+C_S\geq\widehat{\Psi}(X_N). P ≥ [ [ S ] ] † ( G ) + C S ≥ Ψ ( X N ) . Applying antitonicity (G.6) and Corollary G.5 yields
R s ( P ) ≤ R s ( Ψ ^ ( X N ) ) ≤ Ψ ( R s ( X N ) ) R_s(P)\leq R_s(\widehat{\Psi}(X_N))\leq\Psi(R_s(X_N)) R s ( P ) ≤ R s ( Ψ ( X N )) ≤ Ψ ( R s ( X N )) = ∑ n ≥ 0 ⟦ S ⟧ n † ( R s ( G + min ( n , N ) I ) ) + s s + N D S . (131) =\sum_{n\geq0}\llbracket S\rrbracket_n^{\dagger}(R_s(G+\min(n,N)I))+\frac{s}{s+N}D_S. \tag*{(131)} = n ≥ 0 ∑ [ [ S ] ] n † ( R s ( G + min ( n , N ) I )) + s + N s D S . (131) For each fixed n n n , the corresponding block of R s ( X N ) R_s(X_N) R s ( X N ) equals R s ( G + n I ) R_s(G+nI) R s ( G + n I ) once N ≥ n N\geq n N ≥ n , while its final scalar block tends to zero. Together with the bound 0 ≤ R s ( X N ) ≤ I K 0\leq R_s(X_N)\leq I_{\mathcal{K}} 0 ≤ R s ( X N ) ≤ I K , these blockwise limits show that, as N → ∞ N\to\infty N → ∞ , the operators R s ( X N ) R_s(X_N) R s ( X N ) decrease monotonically and converge in the strong operator topology to
( ⨁ n ≥ 0 R s ( G + n I ) ) ⊕ 0. \left(\bigoplus_{n\geq0}R_s(G+nI)\right)\oplus0. ( n ≥ 0 ⨁ R s ( G + n I ) ) ⊕ 0.
Normality of Ψ \Psi Ψ preserves this bounded decreasing limit. Letting N → ∞ N \to\infty N → ∞ in (G.11) therefore gives
R s ( P ) ≤ ∑ n ≥ 0 [ S ] n R s ( G + n I ) . R_s(P) \le\sum_{n \ge0} [S]^n R_s(G+nI). R s ( P ) ≤ n ≥ 0 ∑ [ S ] n R s ( G + n I ) .
The scale-shift identity extends to closed positive forms by spectral calculus on H G \mathcal{H}_G H G , with both sides zero on H G ⊥ \mathcal{H}_G^\perp H G ⊥ :
R s ( G + n I ) = s s + n R s + n ( G ) . R_s(G+nI) = \frac{s}{s+n}R_{s+n}(G). R s ( G + n I ) = s + n s R s + n ( G ) .
Substituting this identity and invoking (C.1) gives R s ( P ) ≤ wp ( S , R ( G ) ) s R_s(P) \le\operatorname{wp}(S,R(G))_s R s ( P ) ≤ wp ( S , R ( G ) ) s . Since this holds for every s > 0 s>0 s > 0 , Definition B.4 establishes the validity of the total-correctness Hoare triple in (G.9). □