{'fraction_non_alphanumeric': 0.042840360266283774, 'fraction_numerical': 0.010573032241221773, 'mean_word_length': 4.287962451684153, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Verification of Quantum Programs

This paper develops verification methodology for quantum programs, and the contribution of the paper is two-fold: 1. Sharir, Pnueli and Hart [SIAM J. Comput. 13(1984)292-314] presented a general method for proving properties of probabilistic programs, in which a probabilistic program is modeled by a Markov chain and an assertion on the output distribution is extended into an invariant assertion on all intermediate distributions. Their method is essentially a probabilistic generalization of the classical Floyd inductive assertion method. In this paper, we consider quantum programs modeled by quantum Markov chains which are defined by super-operators. It is shown that the Sharir-Pnueli-Hart method can be elegantly generalized to quantum programs by exploiting the Schr\"odinger-Heisenberg duality between quantum states and observables. In particular, a completeness theorem for the Sharir-Pnueli-Hart verification method of quantum programs is established. 2. As indicated by the completeness theorem, the Sharir-Pnueli-Hart method is in principle effective for verifying all properties of quantum programs that can be expressed in terms of Hermitian operators (observables). But it is not feasible for many practical applications because of the complicated calculation involved in the verification. For the case of finite-dimensional state spaces, we find a method for verification of quantum programs much simpler than the Sharir-Pnueli-Hart method by employing the matrix representation of super-operators and Jordan decomposition of matrices. In particular, this method enables us to compute easily the average running time and even to analyze some interesting long-run behaviors of quantum programs in a finite-dimensional state space.


Introduction
The need of techniques for verification of quantum programs comes from two areas: • Since the early 1980s, various quantum communication protocols have been proposed, and now quantum cryptographic systems are already commercially available from Id Quantique, MagiQ Technologies, SmartQuantum and NEC. A salient advantage of quantum communication over classical communication is that its security is provable based on the principles of quantum mechanics. However, it is very difficult to guarantee the correctness of protocols at the stage of design. Some simple classical protocols were finally found to have fundamental flaws. The case of quantum protocols is even worse because of the combined weirdness of cryptographic protocols and the quantum world. Indeed, an attack on Id Quantique's commercial quantum cryptographic system was recently reported [24]. Since quantum communication protocols can be expressed as quantum programs, the need in this area is urgent.
• Steady progress in the techniques of quantum devices has made people widely believe that large-scalable and functional quantum computers will be eventually built. Once quantum computers come into truth, quantum programming techniques will play a key role in exploiting the power of quantum computers. It is likely that programmers will commit faults more often in designing programs for quantum computers than programming classical computers, since human intuition is much better adapted to the classical world than the quantum world. Therefore, verification techniques and tools will be indispensable to warrant correctness of quantum programs. The need in this area is not urgent because quantum hardware is still in its infancy, but it will be huge when quantum computers are commercialized.
Several techniques for verifying quantum programs have already been developed in the last 10 years [15,22]. Various formal semantics have been defined for the existing quantum programming languages, and they can be used to reason about the correctness of quantum programs written in these languages; for example, an operational semantics was given to Sanders and Zuliani's language qGCL [20,29], a denotational semantics was defined for Selinger's QPL [21] by representing quantum programs as super-operators, and a denotational semantics of Altenkirch and Grattage's language QML [1] was described in category-theoretic terms. Another research line is language-independent approach; for example, D'Hondt and Panangaden [11] proposed the Hermitian operator representation of quantum predicates and thus introduced an intrinsic notion of quantum weakest preconditions, and quantum predicate transformer semantics was further developed by Ying et al. [25,26]. Also, a few program logics have been introduced into the quantum setting; for example, Baltag and Smets [3] proposed a dynamic logic formalism of information flows in quantum systems, Brunet and Jorrand [7] found a way of applying Birkhoff and von Neumann's quantum logic to reason about quantum programs, Chadha, Mateus and Sernadas [8] presented a Floyd-Hoare logic for quantum programs with bounded iterations, and Feng et al. [14] introduced some useful proof rules for reasoning about quantum loops.
Quantum mechanics is an intrinsically probabilistic theory. So, it is natural to see whether the successful methods for verifying probabilistic programs can be generalized to the quantum case. Sharir, Pnueli and Hart [23] introduced a general method for verifying probabilistic programs. The method is language-independent, and it models a probabilistic program as a Markov chain defined on the program states. An initial distribution of the program state is given, and a set of terminal states is assumed. At each step of the execution, the distribution of the next state is determined by the distribution of the current state and the matrix of transition probabilities of the Markov chain, and the terminal states remain unchanged. The Markov chain model is very popular in the current studies of probabilistic programs [9,10,6]. The property of the program to be verified is an assertion on the distribution of the terminal states, and it is represented by a linear functional of the state distribution. The key idea of this method is to extend it into an invariant assertion on all intermediate distributions of the program states, including the initial one. Thus, the problem of verifying the program is reduced to checking whether the initial distribution satisfies the invariant assertion without computing the distribution of the terminal states, which is usually formidable. This method is essentially a probabilistic generalization of the classical Floyd inductive assertion method for deterministic programs. The Sharir-Pnueli-Hart method can be used to infer statistical properties of a deterministic program, such as its average running time, the expected value of certain output variable, the probability of program termination, etc., when the inputs of the programs are drawn with a known probability distribution. Also, it can be used to analyze random algorithms in which the decision at nondeterministic branching is made according to certain known probability distribution.
Our Contribution: The first aim of this paper is to develop a verification method for quantum programs in the Sharir-Pnueli-Hart style. According to the Hilbert space formalism of quantum mechanics, the state space of a quantum program is supposed to be a separable Hilbert space. A state of the program is described by a density operator. Then program is modeled by the quantum counterpart of a Markov chain, namely, a quantum Markov chain. The transitions in the quantum Markov chain is depicted by a super-operator, which transforms density operators to themselves. The reasonableness of this model can be argued from the following three aspects: • First, super-operators are one of the most popular mathematical formalisms of physically realizable operations allowed by quantum mechanics [18], including of course all the operations that quantum computers can perform.
• Second, this model coincides with Selinger's insight of representing quantum programs as super-operators [21].
• Third, super-operators are widely used as the mathematical model of quantum communication channels so that the technique developed in this paper can be conveniently applied in verifying quantum communication protocols.
By exploiting the Schrödinger-Heisenberg duality between quantum states and observables, we are able to generalize the Sharir-Pnueli-Hart method to reason about quantum programs within the quantum Markov chain framework. In particular, a completeness theorem for the Sharir-Pnueli-Hart verification method of quantum programs is established, which indicates that the method is in principle effective for verifying all properties of quantum programs that can be expressed in terms of Hermitian operators (observables).
Although the completeness theorem guarantees its universal effectiveness, the quantum Sharir-Pnueli-Hart method is often not feasible in practice since usually a very complicated calculation involving iterations of superoperators is required in its applications. For the case of finite-dimensional state spaces, each super-operator enjoys a matrix representation which is easier to manipulate than the super-operator itself. By using this powerful mathematical tool, we find a method for verification of quantum programs in finite-dimensional state spaces much simpler than the Sharir-Pnueli-Hart method. The effectiveness of this simplified verification method depends upon the condition that the modules of all eigenvalues of a certain matrix are strictly smaller than 1. Fortunately, a delicate matrix analysis allows us to vanish the Jordan blocks of the matrix corresponding to those eigenvalues with module 1, and thus warrants the effectiveness of the simplified method.
Another difficulty in the practical applications of the Sharir-Pnueli-Hart method often arises in checking termination condition. We are able to provide some alternate termination conditions much easier to check than the original one in the case of finite-dimensional state spaces also by employing the matrix representation of superoperators and Jordan decomposition of matrices.
The paper is organized as follows: Some preliminaries are presented in Sec. 2. In Sec. 3, the Quantum Sharir-Pnueli-Hart method is introduced, and a simple example is provided to illustrate how to use this method . Also, correctness and completeness of the method are proved. A simplified verification method only suited to quantum programs in finite-dimensional state spaces is proposed in Sec. 4 Sec. 5 is devoted to examine termination of quantum programs in finite-dimensional state spaces. For readability, the proofs of two technical lemmas used in Sec. 4 and 5 are postponed to the appendix.

Sharir-Pnueli-Hart Method
For convenience of the reader, we briefly review the Sharir-Pnueli-Hart method. A comparison of this method and its quantum generalization presented in Sec. 3 is very helpful for the understanding of the latter.
Let S be the set of program states, which is finite or countably infinite. We assume that T ⊆ S is the set of terminal (absorbing) states, and write I = S \ T . A program is understood as a probabilistic transition on S. A single step of the program is represented by a matrix P = (P ij ) i,j∈S of transition probabilities, where P ij is the probability of moving from state i to state j for each i, j ∈ S. It is reasonable to assume that P ij = δ ij for all j ∈ S if i ∈ T is a terminal state. We also assume an initial distribution µ 0 = (µ 0 i ) i∈S of the program state, where µ 0 i is the probability that the program is initially in state i for each i ∈ S. So, a program can be modeled by a Markov chain with transition probability matrix P and initial distribution µ 0 . An execution of the program is then a path in the Markov chain; that is, a sequence of states in S. For any n ≥ 0, we define µ (n) to be the distribution of the program state after n steps; that is, for each i ∈ S, where P n = (P n ij ) i,j∈S is the nth power of P . For any i, j ∈ S and n ≥ 1, we also define: where i 0 = i and i n = j. We write: for each i, j ∈ S. Intuitively, f * ij is the probability of ever getting to state j from state i. Furthermore, for each terminal state j ∈ T , we define µ * j to be the probability that the program ever gets to state j: and it is obvious that µ * = (µ * j ) j∈T is the (partial) distribution of the program's terminal state. Thus, the program can be seen as a distribution transformer, which sends the initial distribution µ 0 to the distribution µ * of terminal states, and this transformer can be considered as the denotational (input-output) semantics of the program.
As one can imagine, in the general case, the distribution µ * of the program's terminal state is very difficult to compute explicitly. However, Sharir, Pnueli and Hart [23] discovered an effective method to verify a class of properties of the program. They first observed that a large class of important properties of probabilistic programs, e.g. the expected running time, the probability of termination, the expected value of some program variable, can be represented by a linear functional of µ * of the form: where β j ≥ 0 for all j ∈ T . Their method for computing ψ(µ * ) is indeed a probabilistic generalization of the Floyd inductive assertion method. The main idea is to find an invariant of the distribution transformer so that one can trace back to the initial distribution µ 0 through all immediate distributions. More precisely, what we need to do is to find a completion β = (β i ) i∈S of the partial vector (β j ) j∈T on the whole set of program states, with β j = β j for all j ∈ T and β i ≥ 0 for all i ∈ I. If β satisfies the following conditions: then we conclude: Thus, computing the functional ψ(µ * ) of the terminal distribution µ * can be done by computing a linear functional ϕ(µ 0 ) of the initial distribution µ 0 . This method can be understood better if we compare it with the Floyd method in the following way: Condition (V1) is a probabilistic version of saying that ϕ is true in the initial state; (V2) means that β is an invariant of the program (a fixed point of P ), and thus it is analogous to the local verification condition; (V3) means that the program terminates. The implication from (V1), (V2) and (V3) to (C) is thus the analogue of partial correctness.
The Sharir-Pnueli-Hart method was shown to be complete in the sense that any partial vector (β j ) j∈T can be extended to β required by the method: (Sharir,Pnueli and Hart [23]) There always exists a completion β = (β i ) i∈S of (β j ) j∈T , which satisfies (V2) and either satisfies (V1), (V3) and thus (C), or else ψ(µ * ) = ∞. More explicitly, the least fixed-point β of equation P β = β, β ≥ 0 is such a completion, with

Quantum Domains
We assume that the reader is familiar with the Hilbert space formalism of quantum theory. Let H be a separable Hilbert space, which is the state space of the quantum systems considered in this paper. We adopt the Dirac notation, using |ϕ , |ψ , ... to denote vectors in H. The inner product of vectors |ϕ , |ψ is written ϕ|ψ . The Löwner order of operators is defined as follows: A ⊑ B if and only if B − A is a positive operator. Recall that a partial density operator is a positive operator ρ with its trace tr(ρ) ≤ 1. In particular, if tr(ρ) = 1, then ρ is called a density operator. A (mixed) state of a quantum system is represented by a density operator. An operator M is said to be Hermitian if its conjugate operator M † = M . An observable on a quantum system is described by a Hermitian operator. A quantum predicate was defined by D'Hondt and Panangaden [11] to be an observable ⊑ I, where I is the identity operator on H.
A main result in this paper depends on the convergence of a certain sequence of observables, which is guaranteed by the following: ([21, 17, 26]) Both the set of partial density operators and the set of quantum predicates, equipped with the Löwner order, are a CPO (complete partial order).
One of the mathematical formalisms of physically realizable operations allowed by quantum mechanics is the notion of super-operator. A super-operator on H is a linear operator E from the space of linear operators on H into itself, which satisfies the following two conditions: 1. tr[E(ρ)] ≤ tr(ρ) for each partial density operator ρ; If condition 1 is strengthened to tr[E(ρ)] = tr(ρ) for all partial density operators ρ, then E is said to be tracepreserving. The following theorem gives an elegant representations of super-operators.

Theorem 2.2 ([18], Theorem 8.1) Kraus Operator-Sum Representation: E is a super-operator on H if and only if there exists a set of operators {E
The Löwner order induces a partial order between super-operators in a natural way: E ⊑ F if and only if E(ρ) ⊑ F(ρ) for all partial density operators ρ. The convergence of a certain sequence of super-operators is required in the proof of a key lemma in this paper. It is guaranteed by the following: 21,26]) The set of (not necessarily trace-preserving) super-operators equipped with ⊑ is a CPO (complete partial order).

Schrödinger-Heisenberg Duality
Now we can introduce a duality between states described as density operators and observables described as Hermitian operators. This duality will be our main tool in developing the Sharir-Pnueli-Hart method for verifying quantum programs.

Definition 2.1 Let E be a super-operator mapping (partial) density operators to (partial) density operators, and let E * be a super-operator mapping Hermitian operators to Hermitian operators. If we have
for any (partial) density operator ρ, and for any Hermitian operator M , then we say that E and E * are (Schrödinger-Heisenberg) dual.
The mapping ρ → E(ρ) is the Schrödinger picture, and the mapping M → E * (M ) is the Heisenberg picture.

Figure 1. Schrödinger-Heisenberg Duality
The following proposition gives an operator-sum representation of the dual of a super-operator, which will be frequently used in the sequent sections.

Proposition 2.3 If E has the operator-sum representation
for all density operators ρ, then we have: for all Hermitian operators M .
Proof: It suffices to see that for any density operator ρ, by definition we have: The duality considered in this subsection was also exploited by D'Hondt and Panangaden [11] to establish an elegant connection between the state transformer (forward) semantics and the predicate transformer (backward) semantics of quantum programs.

Matrix Representation of Super-Operators
The matrix representation of a super-operator is usually easier to manipulate than the super-operator itself. This technique will be extensively used in Sec. 4 and 5.

Definition 2.2 Suppose super-operator E on a finite-dimensional Hilbert space H has the operator-sum representation:
for all partial density operators ρ, and dim H = d. Then the matrix representation of E is the following where A * stands for the conjugate of matrix A, i.e. A * = (a * ij ) with a * ij being the conjugate of complex number a ij , whenever A = (a ij ).
The next is a key lemma for the proofs of the main results in Sec. 4 and 5. Also, it is easy to see from the next lemma that the matrix representation of a super-operator is well-defined: if super-operator E has another operator-sum representation: Proof: We first observe the following matrix equality: for any matrices A, B and C, where B T stands for the transpose of matrix B. Now it follows that

Quantum Generalization of Sharir-Pnueli-Hart Method
We first define the model of quantum programs. Let H be a separable Hilbert space. It will be regarded as the state space of quantum programs. A quantum program is considered as a quantum operation on H, which transforms a (mixed) state in H to another. Following Selinger [21], a single step of the program may be depicted by a trace-preserving super-operator E on H. Suppose that ρ 0 is the initial state. An execution of the program starts in ρ 0 and repeatedly implements the quantum operation represented by E. Formally, we introduce: 2. E is a trace-preserving super-operator; and 3. ρ 0 is a density operator.
In this paper, since the state space H is fixed, we simply say that the pair (E, ρ 0 ) is a quantum Markov chain. We assume that the program has a terminal (absorbing) space. At the end of each execution step, we check whether the program reaches a terminal state or not. This is modeled by a yes-no measurement {M 0 , M 1 }: if the outcome of the measurement is 0, then the program terminates, and we can imagine the program state falls into a terminal space and it remains there forever; otherwise, the program will enter the next step and continues to perform the quantum operation E. So, the execution can be seen as a quantum Markov chain (E, ρ 0 ) together with a termination test {M 0 , M 1 }. The program is essentially a generalization of the quantum loop considered in [27] so that the loop body is allowed to be a super-operator.
To simplify the presentation, we define super-operator: for any partial density operator ρ, and i = 0, 1. Then the execution of the program can be more precisely described as follows. At the first step, we perform the termination measurement {M 0 , M 1 } on the initial state ρ 0 . The probability that the program terminates; that is, the measurement outcome is 0, is p 1 = tr[E 0 (ρ 0 )], and the program state after termination is ρ 1 = E 0 (ρ 0 )/p 1 . We adopt Selinger's normalization convention [21] to encode probability p 1 and density operator ρ 1 into a partial density operator p 1 ρ 1 = E 0 (ρ 0 ). So, E 0 (ρ 0 ) is the partial terminal state obtained at the first step. On the other hand, the probability that the program does not terminate; that is, the measurement outcome is 1, is p N 1 = tr[E 1 (ρ 0 )], and the program state after the outcome 1 is obtained is Then they are combined to get a partial density operator p N 1 ρ N 1 = E 1 (ρ 0 ), and it is transformed by the defining super-operator of the quantum Markov chain to (E • E 1 )(ρ 0 ), upon which the second step will be executed. In general, the (n + 1)th step is executed upon the partial density operator where p N n is the probability that the program does not terminate at the nth step, and ρ N n is the program state when the program does not terminate at the nth step. The probability that the program terminates in the (n + 1)th step is then and the probability that the program does not terminate in the (n + 1)th step is then The program state after the termination is and combining them yields the partial terminal state of the program at the (n + 1)th step: Thus, the (total) terminal state of the program is obtained by summing up the partial computing results at all steps. Formally, it is given by Furthermore, we can understand that a super-operator E together with a termination measurement {M 0 , M 1 } defines a quantum program scheme. Whenever an initial state ρ 0 is fed into the program scheme, we get a program and it computes the terminal state ρ * . Thus, the program scheme transforms initial state ρ 0 to terminal state ρ * , and it defines a super-operator F : ρ 0 → ρ * .
The following proposition gives a recursive characterization of quantum program.
for all density operators ρ.
2. The dual F * of F is defined by the following equation: for all Hermitian operators M .
Verification Problem for Quantum Programs: Now we consider a positive observable modeled by Hermitian operator P ⊒ 0, where 0 is the zero operator on H. As will be shown in the examples below, a class of interesting properties of the quantum program can be expressed as the average value (or expectation) of observable P in the terminal state ρ * of the program. Our question is then: how to compute it?
The main aim of this paper is to develop a verification method in the Sharir-Pnueli-Hart style to solve this problem.
Solving the Problem: Recall that in the probabilistic case, a nonnegative vector β = (β j ) j∈T is given over the set T of terminal states, and the task is to compute its expectation with respect to the terminal distribution of the program. The Sharir-Pnueli-Hart method requires to find a completing β = (β i ) i∈S over the whole set S of program states satisfying conditions (V1), (V2) and (V3).
A unexpected difficulty comes out when we try to generalize this method to the quantum case: The notion that a vector β is a completion of another vector β is ready and simple. The quantum analogue of vector β is the positive operator P . What is the quantum analogue of the completion β of β? Note that β is defined merely over a subset T of S, and β can be obtained by adding its values in the remaining states in S \ T . However, P is defined already on the whole space H of program states but not one of its subspaces. So, at the first glance it seems hopeless to define a completion of P which must also be an operator on H. After a careful analysis, however, we understand that M † 0 P M 0 + M † 1 QM 1 with a positive operator Q on H can be seen as a completion of P with respect to the termination measurement {M 0 , M 1 }. Once a suitable completion of P is discovered, it is relatively easy to conceive the quantum counterparts of conditions (V1), (V2) and (V3). They are displayed as follows: It is interesting to compare (QV2) with (V2). Note that in (QV2) the dual E * but not E itself is used. This shows that the Schrödinger-Heisenberg duality must be taken seriously for quantum programs. But it is not the case in condition (V2) for probabilistic programs.
Recall that the Sharir-Pnueli-Hart method is based on the implication from (V1), (V2) and (V3) to (C). Similarly, if (QV1), (QV2) and (QV3) imply then its quantum generalization can be stated as follows: • Quantum Sharir-Pnueli-Hart method: To compute the average value P ρ * of positive observable P in the terminal state ρ * of the program, one only needs to find a positive operator Q satisfying conditions (QV1), (QV2) and (QV3). Then the problem of computing P ρ * is reduced to computing the average value It is worth noting that P is assumed to be positive in the above presentation of quantum Sharir-Pnueli-Hart method. The positivity of P is essential in the proofs of the correctness and completeness theorems below, where the monotonicity of certain sequences of (super-)operators is crucial. In practical applications, however, the positivity of P is not essential. In fact, for any observable (Hermitian operator) O, it holds that O = P 1 − P 2 for some positive operators P 1 and P 2 . Thus, we can use the above quantum Sharir-Pnueli-Hart method to compute P 1 ρ * and P 2 ρ * , respectively, and we obtain: We postpone the proof of the correctness of the quantum Sharir-Pnueli-Hart method to a separate subsection, but now present a simple example to show how to use it.

Example 3.1 We consider the bit flip channel, which is widely used in quantum communication. This channel
flips the state of a qubit from |0 to |1 and vice versa, with probability 1 − p, 0 ≤ p ≤ 1 (see [18], Sec. 8 Let us compute the termination probability of the program defined by super-operator E, initial state ρ 0 and termination measurement M . Then we take P = |0 0|, and the termination probability is P ρ * , where ρ * is the terminal state of the program. To use the quantum Sharir-Pnueli-Hart method, we need to find a positive operator Q satisfying condition (QV2). It is reasonable to assume that Q = λ|ϕ ϕ| + µ|ψ ψ| such that {|ϕ , |ψ } is an orthonormal basis of H 2 , and λ, µ ≥ 0. We write:

.3.3). It is described by the super-operator E on the 2−dimensional Hilbert space H 2 , defined as follows:
A routine calculation leads to N = |0 0| + K|1 1|, and where and in the sequel Then condition (QV2) becomes E * (N ) = Q, and it yields that On the other hand, by a routine calculation we obtain: We consider the following three cases: • Case 1. p < 1. We always have (QV3). It follows from Eq. (6) that K = 1. So, N = I, and the assertion (QC) implies the termination probability P ρ * = N ρ 0 = ψ 0 |N |ψ 0 = 1.

Correctness Theorem
This subsection is devoted to prove the correctness of the quantum Sharir-Pnueli-Hart method:

Theorem 3.1 (Correctness) The quantum Sharir-Pnueli-Hart method is correct; that is, (QV1), (QV2) and (QV3) imply (QC).
A key intermediate step in the proof of the above theorem is the calculation of the expectation in the right-hand side of (QC). It can be stated as the following: Lemma 3.1 If Q satisfies (QV2), then for any n ≥ 0, we have: Proof. The key of this proof is repeated applications of the Schrödinger-Heisenberg duality between states and observables defined in Subsec. 2.3. We proceed by induction on n. For the case of n = 0, it holds that We now consider the case of n + 1. First, by (QV2) and the duality between E and E * , we have: Then it follows from the induction hypothesis for the case of n that The above lemma will also be needed in the proof of the completeness theorem below. Now we are ready to prove the correctness theorem.
Proof of Theorem 3.1. Combining Lemma 3.1 and conditions (QV1), (QV2) and (QV3), we obtain: Note that the existence of the limits in the above equation is guaranteed by the fact that the set of partial density operators equipped with the Löwner order is a CPO (see Proposition 2.1), and the equalities labeled by (a) and (b) are derived by the continuity of trace and the continuity of multiplication of operators, respectively.

Completeness Theorem
The quantum Sharir-Pnueli-Hart method was used in the last section to compute the termination probability of a simple quantum program used in quantum communication. It is natural to ask the question: Can it be used to more complicated quantum programs? Furthermore, one may ask: Is the quantum Sharir-Pnueli-Hart method complete? More precisely, for any positive observable P , can we always find a positive observable Q such that we only need to compute the average value of observable M † 0 P M 0 + M † 1 QM 1 in the initial state ρ 0 in order to compute the average value of P in the terminal state ρ * ? The following theorem gives a positive answer to this question:

Indeed, Q can be chosen to be the least fixed-point of the following equation:
Proof. We put: Q 0 = 0, and It can be easily shown by induction on n that {Q n } is an increasing sequence according to the Löwner order. Thus, we can define: (1) We first show that Q is well-defined. It suffices to prove the existence of supremum ∞ n=0 Q n . With its monotonicity, we only need to demonstrate that sequence {Q n } is bounded from up. Indeed, we have: Q n ⊑ F * (P ) for every n ≥ 0. We prove this claim by induction on n. The case of n = 0 is obvious. Assuming the claim is correct for the case n, we obtain: for any density operator ρ, Here, equalities labeled by (a) and (c) are derived by the Schrödinger-Heisenberg duality, (b) by the induction hypothesis, and (d) by Eq. (4). So, Q n+1 ⊑ F * (P ), and the claim is proved.
(2) Second, we prove that Q satisfies (QV2). It suffices to show that for any density operator ρ. The key is also repeated applications of the Schrödinger-Heisenberg duality. It follows from continuity of trace operator tr(·) that (3) Third, we show that Q is the least fixed-point of Eq. (8). Suppose that Q satisfies (QV2). First, we show that tr[Q n E(ρ)] ≤ tr(Qρ) for any density operator ρ and for all n ≥ 0 by induction on n. The case of n = 0 is trivial. If the conclusion is correct for the case of n, then we have: and the conclusion also holds for the case of n + 1. Now, we obtain: for all density operator ρ. Consequently, Q ≤ Q, and Q is the least fixed-point of Eq. (8).
(4) We claim that for all density operators ρ and for all n ≥ 0. To prove Eq. (9), we proceed by induction on n. The case of n = 0 is obvious. If Eq. (9) is valid for the case of n, then we have:

Verification in Finite-Dimensional State Spaces
The Sharir-Pnueli-Hart method developed in the last section can be used to verify properties of quantum programs both in finite-dimensional state spaces and in infinite-dimensional state spaces. In this section, we present a much simpler verification method for the case of finite-dimensional state spaces.
We consider the program defined by quantum Markov chain (E, ρ 0 ) with termination test {M 0 , M 1 } in a finitedimensional state Hilbert space H. Suppose that super-operator E has the operator-sum representation: i for all partial density operators ρ. Recall that super-operators E i (i = 0, 1) are defined by Eq. (1). For simplicity of presentation, we write G for the composition of E and E 1 : G = E • E 1 . Then G has the following operator-sum representation: for all partial density operators ρ. Let the matrix representations of super-operators E 0 and G are with J ks (λ s ) being a k s × k s -Jordan block of eigenvalue λ s (1 ≤ s ≤ l) (see [16], Sec. 3.1). The next lemma describes the structure of the matrix representation M of super-operator F.
for each 1 ≤ s ≤ l. (Note that J ks (λ s ) and J ′ s are both 1 × 1 matrices when λ s | = 1; see Lemma 4.1.) The following technical lemma is crucial for the proofs of the main results in this and next section.
By first applying Eq. (12) and then repeatedly applying Eq. (13), we obtain: The equality labeled by (a) follows from Lemma 4.2. Finally, we have: The case of p = 1 is trivial. For the case of p < 1, we have: To compute the termination probability of the program, we consider the observable P = |0 0| and write |Φ = |00 + |11 . Then by Theorem 4.1 and some routine matrix multiplications we obtain the termination probability: To further illustrate the power of the verification method introduced above, we compute the average running time: In particular, if the initial state ρ 0 = |ψ ψ| with |ψ = α|0 + β|1 , then the average running time is 1 + |β| 2 1−p .
The techniques developed in this section can be further generalized to analyze the long-run behaviors defined by de Alfaro [10] and Brázdil, Esparza and Kučera [6] for quantum programs in finite-dimensional state spaces.

Termination of Quantum Programs
It is usually not easy to check the termination condition (QV3) when applying the quantum Sharir-Pnueli-Hart method. The purpose of this section is to find some alternate conditions for termination of quantum programs in finite-dimension state spaces employing the ideas used in the last section.
As in the last section, we assume that the state space H of quantum programs considered in this section is finite-dimensional.

We say that the program terminates if the nontermination probability in the nth step
for some positive integer n, where E i (i = 0, 1) are defined by Eq.(1).
2. We say that the program almost terminates if lim n→∞ p N n = 0, where p N n is as in item 1 for every n ≥ 1 (also see Eq. (3)).
It is obvious that almost termination is equivalent to (QV3) with Q = the identity operator I on H. On the other hand, almost termination implies (QV3) for every Q.
The above definition is a generalization of Definition 3.1 in [27], where only the case that E is a unitary operator, i.e. for some unitary operator U , E(ρ) = U ρU † for all density operators ρ, is considered.
The following lemma gives a simple termination condition in terms of the matrix representation of superoperators. We now turn to consider the terminating problem of quantum programs. Recall that a super-operator E together with a termination test {M 0 , M 1 } can be understood as a program scheme.

Definition 5.2
The program scheme is terminating (resp. almost terminating) if for every density operator ρ, the program generated from the program scheme with initial state ρ, i.e. the program defined by Markov chain (E, ρ) and termination test {M 0 , M 1 }, terminates (resp. almost terminates). Proof: Notice that a program scheme is terminating if and only if it terminates when the initial state is ρ 0 = I/ dim H. Then this lemma follows immediately from Lemma 5.1.

Conclusion
This paper develops a methodology for verifying quantum programs in which quantum programs are modeled by quantum Markov chains and verified properties are described in terms of Hermitian operators. The Sharir-Pnueli-Hart method for verifying probabilistic programs is generalized into the quantum setting. For quantum programs with finite-dimensional state spaces, a simpler verification method is found, which is especially useful for analysis of long-run behavior like the average running time. The methodology developed in this paper mainly targets verification of programs for future quantum computers, but it also has potential applications in other areas such as verifications of quantum communication protocols and engineered quantum systems ??. Further studies will naturally go along two lines: • More Complex Programs: An interesting topic in this direction is verification of quantum programs with recursive procedures. A possible model of these programs is a quantum generalization of recursive state machines introduced by Alur et al. [2] and recursive Markov chains introduced by Etessami and Yannakakis [13]. It is similar to prove that trB i 2 ≤ tr(A † A) for i = 2, 3, 4.
The second part can also be proved by refutation. Without any loss of generality, we assume that |λ 1 | = 1 with k 1 > 1 in the Jordan decomposition of M . Suppose that {|i } d 2 i=1 is the orthonormal basis of H ⊗ H compatible with the numbering of the columns and rows of M . Take an unnormalized vector |y = S|k 1 . Since S is nonsingular, there are real numbers R, r > 0 such that r · |x ≤ S|x ≤ R · |x for any vector |x in H ⊗ H. By definition, it holds that |y ≤ R. We can choose integer n such that nr > R · 4 √ d because r > 0. Then a routine calculation yields: Consequently, we have: This contradicts to Lemma A.3 again.
Moreover, we have: The convergence of ∞ n=0 (E 0 • G n ) follows immediately from Proposition 2.2, and it in turn implies the convergence of ∞ n=0 N 0 M n . It is clear that Since S is nonsingular, we see that ∞ n=0 N 0 SJ(M ) n converges. This implies that lim and it follows that lim n→∞ QU n = 0 and lim n→∞ SU n = 0. So, we have: tr(Q † Q) = lim n→∞ tr(QU n ) † QU n = 0, and tr(S † S) = lim n→∞ tr(SU n ) † SU n = 0. This yields Q = 0 and S = 0, and it follows immediately that N 0 M n = N 0 N n .