figure a

1 Introduction

Bounded model checking (BMC) [12, 17] is a successful method for analyzing models of hardware and software systems. For checking a finite-state transition system (TS) against a safety property (“bad states are unreachable”), BMC unrolls the transition relation until it either finds a counterexample and hence refutes the property, or reaches a pre-computed completeness threshold on the unrolling depth and accepts the property as verified. For infinite-state systems, however, such completeness thresholds need not exist (cf. [64]), rendering BMC a refutation-only technique. To verify infinite-state systems, BMC is typically combined with the search for an inductive invariant, i.e., a superset of the reachable states which is closed under the transition relation. Proving a—not necessarily inductive—safety property then amounts to synthesizing a sufficiently strong, often complicated, inductive invariant that excludes the bad states. A plethora of techniques target computing or approximating inductive invariants, including IC3 [14], induction [13, 20], interpolation [50, 51], and predicate abstraction [27, 36]. However, invariant synthesis may burden full automation, as it either relies on user-supplied annotations or confines push-button technologies to semi-decision or approximate procedures.

k-induction [65] generalizes the principle of simple induction (aka 1-induction) by considering k consecutive transition steps instead of only a single one. It is more powerful: an invariant can be k-inductive for some \(k >1\) but not 1-inductive. Following the seminal work of Sheeran et al. [65] which combines k-induction with SAT solving to check safety properties, k-induction has found a broad spectrum of applications in the realm of hardware [29, 37, 45, 65] and software verification [10, 21,22,23, 55, 63]. Its success is due to (1) being a foundational yet potent reasoning technique, and (2) integrating well with SAT/SMT solvers, as also pointed out in [45]: “the simplicity of applying k-induction made it the go-to technique for SMT-based infinite-state model checking”. This paper explores whether k-induction can have a similar impact on the fully automatic verification of infinite-state probabilistic programs. That is, we aim to verify that the expected value of a specified quantity—think: “quantitative postcondition”—after the execution of a probabilistic program is bounded by a specified threshold.

Example 1

(Bounded Retransmission Protocol [19, 32]). The loop

models a simplified version of the bounded retransmission protocol, which attempts to transmit \(\textit{toSend} \) packages via an unreliable channel (that fails with probability 0.1) allowing for at most \(\textit{maxFail} \) retransmissions per package.

Using our generalization of k-induction, we can fully automatically verify that the expected total number of failed transmissions is at most 1, if the number of packages we want to (successfully) send is at most 3. In terms of weakest preexpectations [38, 44, 49], this quantitative property reads

$$\begin{aligned}&\textsf {{wp}}\llbracket C\rrbracket \left( \textit{totalFail} \right) ~{}\preceq {}~\left[ {\textit{toSend} \le 3} \right] \cdot (\textit{totalFail} + 1) + \left[ {\textit{toSend} > 3} \right] \cdot \infty . \end{aligned}$$

The bound on the right-hand-side of the inequality is 4-inductive, but not 1-inductive; verifying the same bound using 1-induction requires finding a non-trivial—and far less perspicuous—inductive invariant. Moreover, if we consider an arbitrary number of packages to send, i.e., we drop \(\left[ {\textit{toSend} \le 3} \right] \), this bound becomes invalid. In this case, our BMC procedure produces a counterexample, i.e., values for \(\textit{toSend} \) and \(\textit{maxFail} \), proving that the bound does not hold.    

Lifting the classical formalization (and SAT encoding) of k-induction over TSs to the probabilistic setting is non-trivial. We encounter the following challenges:

(A) Quantitative reachability. In a TS, a state reachable within k steps remains reachable on increasing k. In contrast, reachability probabilities in Markov chains—a common operational model for probabilistic programs [28]—may increase on increasing k. Hence, proving that the probability of reaching a bad state remains below a given threshold is more intricate than reasoning about qualitative reachability.

(B) Counterexamples are subsystems. In a TS, an acyclic path from an initial to a bad state suffices as a witness for refuting safety, i.e., non-reachability. SAT encodings of k-induction rely on this by expressing the absence of witnesses up to a certain path-length. In the probabilistic setting, however, witnesses are no longer single paths [30]. Rather, a witness for the probability of reaching a bad state to exceed a threshold is a subsystem [15], i.e., a set of possibly cyclic paths.

(C) Symbolic encodings. To enable fully automated verification, we need a suitable encoding such that our lifting integrates well into SMT solvers. Verifying probabilistic programs involves reasoning about execution trees, where each (weighted) branch corresponds to a probabilistic choice. A suitable encoding needs to capture such trees which requires more involved theories than encoding paths in classical k-induction.

We address challenges (A) and (B) by developing latticed k-induction, which is a proof technique in the rather general setting of fixed point theory over complete lattices. Latticed k-induction generalizes classical k-induction in three aspects: (1) it works with any monotonic map on a complete lattice instead of being confined to the transition relation of a transition system, (2) it generalizes the Park induction principle for bounding fixed points of such monotonic maps, and (3) it extends from natural numbers k to (possibly transfinite) ordinals \(\kappa \), hence its short name: \(\kappa \)-induction.

It is this lattice-theoretic understanding that enables us to lift both k-induction and BMC to reasoning about quantitative properties of probabilistic programs. To enable automated reasoning, we address challenge (C) by an incremental SMT encoding based on the theory of quantifier-free mixed integer and real arithmetic with uninterpreted functions (\(\textsf {QF\_UFLIRA} \)). We show how to effectively compute all needed operations for \(\kappa \)-induction using the SMT encoding and, in particular, how to decide quantitative entailments.

A prototypical implementation of our method demonstrates that \(\kappa \)-induction for (linear) probabilistic programs manages to automatically verify non-trivial specifications for programs taken from the literature which—using existing techniques—cannot be verified without synthesizing a stronger inductive invariant.

Due to space restrictions, most proofs and details about individual benchmarks have been omitted; they are found in an extended version of this paper [8].

Related Work. Besides the aforementioned related work on k-induction, we briefly discuss other automated analysis techniques for probabilistic systems and other approaches for bounding fixed points. Symbolic engines exist for exact inference [26] and sensitivity analysis [33]. Other automated approaches focus on bounding expected costs [56], termination analysis [2, 16], and static analysis [3, 67]. BMC has been applied in a rather rudimentary form to the on-the-fly verification of finite unfoldings of probabilistic programs [35], and the enumerative generation of counterexamples in finite Markov chains [68]. (Semi-)automated invariant-synthesis techniques can be found in [6, 24, 41]. A recent variant of IC3 for probabilistic programs called PrIC3 [7] is restricted to finite-state systems. When applied to finite-state Markov chains, our \(\kappa \)-induction operator is related to other operators that have been employed for determining reachabilitiy probabilities through value iteration [4, 31, 61]. In particular, when iterated on the candidate upper bound, the \(\kappa \)-induction operator coincides with the (upper value iteration) operator in interval iteration [4]; the latter operator can be used together with the up-to techniques (cf. [53, 58, 59]) to prove our \(\kappa \)-induction rule sound (in contrast, we give an elementary proof). However, the \(\kappa \)-induction operator avoids comparing current and previous iterations. It is thus easier to implement and more amenable to SMT solvers. Finally, the proof rules for bounding fixed points recently developed in [5] are restricted to finite-state systems.

2 Verification as a Fixed Point Problem

We start by recapping some fundamentals on fixed points of monotonic operators on complete lattices before we state our target verification problem.

Fundamentals. For the next three sections, we fix a complete lattice \((E,\, \sqsubseteq )\), i.e. a carrier set E together with a partial order \(\sqsubseteq \), such that every subset \(S \subseteq E\) has a greatest lower bound \(\sqcap S\) (also called the meet of S) and a least upper bound \(\bigsqcup S\) (also called the join of S). For just two elements \(\{g, h\} \subseteq E\), we denote their meet by \(g\sqcap h\) and their join by \(g\sqcup h\). Every complete lattice has a least and a greatest element, which we denote by \(\bot \) and \(\top \), respectively.

In addition to \((E,\, \sqsubseteq )\), we also fix a monotonic operator \(\varPhi :E\rightarrow E\). By the Knaster-Tarski theorem [43, 47, 66], every monotonic operator \(\varPhi \) admits a complete lattice of (potentially infinitely many) fixed points. The least fixed point \({\textsf {{lfp}}}~\varPhi \) and the greatest fixed point \({\textsf {{gfp}}}~\varPhi \) are moreover constructible by (possibly transfinite) fixed point iteration from \(\bot \) and \(\top \), respectively: Cousot & Cousot [18] showed that there exist ordinals \(\alpha \) and \(\beta \), such thatFootnote 1

figure c

where denotes the upper \(\delta \)-fold iteration and \(\varPhi ^{\left\lfloor \delta \right\rfloor }\left( g\right) \) denotes the lower \(\delta \)-fold iteration of \(\varPhi \) on \(g\), respectively. Formally, is given byFootnote 2

Intuitively, if \(\delta \) is the successor of \(\gamma \), then we simply do another iteration of \(\varPhi \). If \(\delta \) is a limit ordinal, then can also be thought of as a limit, namely of iterating \(\varPhi \) on \(g\). However, simply iterating \(\varPhi \) on \(g\) need not always converge, especially if the iteration does not yield an ascending chain. To remedy this, we take as limit the join over the whole (possibly transfinite) iteration sequence, i.e., the least upper bound over all elements that occur along the iteration. The lower \(\delta \)-fold iteration \(\varPhi ^{\left\lfloor \delta \right\rfloor }\left( g\right) \) is defined analogously to , except that we take a meet instead of a join whenever \(\delta \) is a limit ordinal.

An important special case for fixed point iteration (see (\(\dagger \))) is when the operator \(\varPhi \) is Scott-continuous (or simply continuous), i.e., if . In this case, \(\alpha \) in (\(\dagger \)) coincides with the first infinite limit ordinal \(\omega \) (which can be identified with the set \(\mathbb {N} \) of natural numbers). This fact is also known as the Kleene fixed point theorem [1].

Problem Statement. Fixed points are ubiquitous in computer science. Prime examples of properties that can be conveniently characterized as least fixed points include both the set of reachable states in a transition system and the function mapping each state in a Markov chain to the probability of reaching some goal state (cf. [60]). However, least and greatest fixed points are often difficult or even impossible [39] to compute; it is thus desirable to bound them.

For example, it may be sufficient to prove that a system modeled as a Markov chain reaches a bad state from its initial state with probability at most \(10^{{-}6}\), instead of computing precise reachability probabilities for each state. Moreover, if said probability is not bounded by \(10^{{-}6}\), we would like to witness that as well.

In general lattice-theoretic terms, our problem statement reads as follows:

figure d

For proving, we will present latticed k-induction; for refuting, we will present latticed bounded model checking. Running both in parallel may (and under certain conditions: will) lead to a decision of the above problem.

Fig. 1.
figure 1

\(\kappa \)-induction and latticed BMC in case that \({\textsf {{lfp}}}~\varPhi \sqsubseteq f\). An arrow from \(g\) to \(h\) indicates \(g\sqsubseteq h\). The solid blue arrow from \(\varPhi (\varPsi _{f}^{\left\lfloor \kappa \right\rfloor }(f))\) to \(f\) is the premise of \(\kappa \)-induction, i.e., the LHS of Lemma 2, which implies the dash-dotted blue arrow from \(\varPhi (\varPsi _{f}^{\left\lfloor \kappa \right\rfloor }(f))\) to \(\varPsi _{f}^{\left\lfloor \kappa \right\rfloor }(f)\), i.e., the RHS of Lemma 2. The dashed blue arrow from \({\textsf {{lfp}}}~\varPhi \) to \(\varPhi (\varPsi _{f}^{\left\lfloor \kappa \right\rfloor }(f))\) is a consequence of the dash-dotted arrow (by Park induction, Theorem 1) and ultimately proves that \({\textsf {{lfp}}}~\varPhi \sqsubseteq f\).

3 Latticed k-Induction

In this section, we generalize the well-established k-induction verification technique [23, 29, 37, 45, 55, 65] to latticed k-induction (for short: \(\kappa \)-induction; reads: “kappa induction”). With \(\kappa \)-induction, our aim is to prove that \({\textsf {{lfp}}}~\varPhi \sqsubseteq f\). To this end, we attempt “ordinary” induction, also known as Park induction:

Theorem 1

(Park Induction [57]). Let \(f\in E\). Then

$$\begin{aligned} \varPhi \left( f \right) ~{}\sqsubseteq {}~f~\quad \text {implies}\quad ~{\textsf {{lfp}}}~\varPhi ~{}\sqsubseteq {}~f. \end{aligned}$$

Intuitively, this principle says: if pushing our candidate upper bound \(f\) through \(\varPhi \) takes us down in the partial order \(\sqsubseteq \), we have verified that \(f\) is indeed an upper bound on \({\textsf {{lfp}}}~\varPhi \). The true power of Park induction is that applying \(\varPhi \) once tells us something about iterating \(\varPhi \) possibly transfinitely often (see (\(\dagger \)) in Sect. 2).

Park induction, unfortunately, does not work in the reverse direction: If we are unlucky, \(f\sqsupset {\textsf {{lfp}}}~\varPhi \) is an upper bound on \({\textsf {{lfp}}}~\varPhi \), but nevertheless \(\varPhi \left( f \right) \not \sqsubseteq f\). In this case, we say that \(f\) is not inductive. But how can we verify that \(f\) is indeed an upper bound in such a non-inductive scenario? We search below \(f\) for a different, but inductive, upper bound on \({\textsf {{lfp}}}~\varPhi \), that is, we

$$\begin{aligned} \text {search for an } h\in E~\quad \text { such that } \quad ~ {\textsf {{lfp}}}~\varPhi ~{}\sqsubseteq {}~\varPhi (h) ~{}\sqsubseteq {}~h~{}\sqsubseteq {}~f. \end{aligned}$$

In order to perform a guided search for such an \(h\), we introduce the \(\kappa \)-induction operator—a modified version of \(\varPhi \) that is parameterized by our candidate \(f\):

Definition 1

(\(\boldsymbol{\kappa }\)-Induction Operator). For \(f\in E\), we call

$$ \varPsi _{f} :\quad E~{}\rightarrow {}~E, \qquad g~{}\mapsto {}~\varPhi \left( g \right) \sqcap f$$

the \(\kappa \) -induction operator (with respect to \(f\) and \(\varPhi \)).

What does \(\varPsi _{f}\) do? As illustrated in Fig. 1, if \(\varPhi \left( f \right) \not \sqsubseteq f\) (i.e. \(f\) is non-inductive) then “at least some part of \(\varPhi \left( f \right) \) is greater than \(f\)”. If the whole of \(\varPhi \left( f \right) \) is greater than \(f\), then \(f\sqsubset \varPhi \left( f \right) \); if only some part of \(\varPhi \left( f \right) \) is greater and some is smaller than \(f\), then \(f\) and \(\varPhi \left( f \right) \) are incomparable. The \(\kappa \)-induction operator \(\varPsi _{f}\) now rectifies \(\varPhi \left( f \right) \) being (partly) greater than \(f\) by pulling \(\varPhi \left( f \right) \) down via the meet with f (i.e., via ), so that the result is in no part greater than f. Applying \(\varPsi _{f}\) to \(f\) hence always yields something below or equal to f.

Together with the observation that \(\varPsi _{f}\) is monotonic, iterating \(\varPsi _{f}\) on \(f\) necessarily descends from \(f\) downwards in the direction of \({\textsf {{lfp}}}~\varPhi \) (and never below):

Lemma 1

(Properties of the \(\boldsymbol{\kappa }\)-Induction Operator). Let \(f\in E\) and let \(\varPsi _{f}\) be the \(\kappa \)-induction operator with respect to \(f\) and \(\varPhi \). Then

  1. (a)

    \(\varPsi _{f}\) is monotonic, i.e., \( \forall \, g_1,g_2 \in E:~ g_1 ~{}\sqsubseteq {}~g_2 ~~\text {implies}~~ \varPsi _{f}(g_1) ~{}\sqsubseteq {}~\varPsi _{f}(g_2) \).

  2. (b)

    Iterations of \(\varPsi _{f}\) starting from f are descending, i.e., for all ordinals \(\gamma \), \(\delta \),

    $$\begin{aligned} \gamma ~{}<{}~\delta ~\quad \text {implies}\quad ~\varPsi _{f}^{\left\lfloor \delta \right\rfloor }(f) ~{}\sqsubseteq {}~\varPsi _{f}^{\left\lfloor \gamma \right\rfloor }(f). \end{aligned}$$
  3. (c)

    \(\varPsi _{f}\) is dominated by \(\varPhi \), i.e., \(\forall \, g\in E:~ \varPsi _{f}(g) ~{}\sqsubseteq {}~\varPhi \left( g \right) . \)

  4. (d)

    If \({\textsf {{lfp}}}~\varPhi \sqsubseteq f\), then for any ordinal \(\delta \),

    $$\begin{aligned} {\textsf {{lfp}}}~\varPhi ~{}\sqsubseteq {}~{\ldots } ~{}\sqsubseteq {}~\varPsi _{f}^{\left\lfloor \delta \right\rfloor }(f) ~{}\sqsubseteq {}~{\ldots } ~{}\sqsubseteq {}~\varPsi _{f}^{\left\lfloor 2 \right\rfloor }(f) ~{}\sqsubseteq {}~\varPsi _{f}(f) ~{}\sqsubseteq {}~f. \end{aligned}$$

The descending sequence \(f\sqsupseteq \varPsi _{f}(f) \sqsupseteq \varPsi _{f}^{\left\lfloor 2 \right\rfloor }(f) \sqsupseteq {\ldots }\) constitutes our guided search for an inductive upper bound on \({\textsf {{lfp}}}~\varPhi \). For each ordinal \(\kappa \) (hence the short name: \(\kappa \)-induction), \({\varPsi _{f}^{\left\lfloor \kappa \right\rfloor }(f)}\) is a potential candidate for Park induction:

figure e

For efficiency reasons, e.g., when offloading the above inequality check to an SMT solver, we will not check the inequality (\(\ddagger \)) directly but a property equivalent to (\(\ddagger \)), namely whether \(\varPhi (\varPsi _{f}^{\left\lfloor \kappa \right\rfloor }(f))\) is below \(f\) instead of \(\varPsi _{f}^{\left\lfloor \kappa \right\rfloor }(f)\):

Lemma 2

(Park Induction from \(\boldsymbol{\kappa }\)-Induction). Let \(f\in E\). Then

$$ \varPhi \left( \varPsi _{f}^{\left\lfloor \kappa \right\rfloor } (f) \right) ~{}\sqsubseteq {}~f~\quad \text {iff}\quad ~\varPhi \left( \varPsi _{f}^{\left\lfloor \kappa \right\rfloor }(f) \right) ~{}\sqsubseteq {}~\varPsi _{f}^{\left\lfloor \kappa \right\rfloor }(f). $$

Proof

The if-direction is trivial, as \(\varPsi _{f}^{\left\lfloor \kappa \right\rfloor }(f) \sqsubseteq f\) (Lemma 1(d)). For only-if:

figure f

If \(\varPhi \bigl ( \varPsi _{f}^{\left\lfloor \kappa \right\rfloor } (f) \bigr ) \sqsubseteq f\), then Lemma 2 tells us that \(\varPsi _{f}^{\left\lfloor \kappa \right\rfloor } (f)\) is Park inductive and thereby an upper bound on \({\textsf {{lfp}}}~\varPhi \). Since iterating \(\varPsi _{f}\) on f yields a descending iteration sequence (see Lemma 1(b)), \(\varPsi _{f}^{\left\lfloor k \right\rfloor } (f)\) is below f and therefore f is also an upper bound on \({\textsf {{lfp}}}~\varPhi \). Put in more traditional terms, we have shown that \(\varPsi _{f}^{\left\lfloor \kappa \right\rfloor }(f)\) is an inductive invariant stronger than \(f\). Formulated as a proof rule, we obtain the following induction principle:

Theorem 2

(\(\boldsymbol{\kappa }\)-Induction). Let \(f\in E\) and let \(\kappa \) be an ordinal. Then

$$ \varPhi \left( \varPsi _{f}^{\left\lfloor \kappa \right\rfloor }(f) \right) ~{}\sqsubseteq {}~f~\quad \text {implies}\quad ~{\textsf {{lfp}}}~\varPhi ~{}\sqsubseteq {}~f. $$

Proof

Following the argument above, for details see [8, Appx. A.2].    \(\square \)

An illustration of \(\kappa \)-induction is shown in (the right frame of) Fig. 1. For every ordinal \(\kappa \), if \(\varPhi (\varPsi _{f}^{\left\lfloor \kappa \right\rfloor }(f))\sqsubseteq f\), then we call \(f\) \((\kappa {+}1)\)-inductive (for \(\varPhi \)). In particular, \(\kappa \)-induction generalizes Park induction, in the sense that 1-induction is Park induction and, \((\kappa > 1)\)-induction is a more general principle of induction.

figure g

Algorithm 1 depicts a (semi-)algorithm that performs latticed k-induction (for \(k < \omega \)) in order to prove \({\textsf {{lfp}}}~\varPhi \sqsubseteq f\) by iteratively increasing k. For implementing this algorithm, we require, of course, that both \(\varPhi \) and \(\varPsi _{f}\) are computable and that \(\sqsubseteq \) is decidable. Notice that the loop (lines 2–3) never terminates if \(f\sqsubset \varPhi \left( f \right) \)—a condition that can easily be checked before entering the loop. Even with this optimization, however, Algorithm 1 is a proper semi-algorithm: even if \({\textsf {{lfp}}}~\varPhi \sqsubseteq f\), then \(f\) is still not guaranteed to be k-inductive for some \(k < \omega \). And even if an algorithm could somehow perform transfinitely many iterations, then \(f\) is still not guaranteed to be \(\kappa \)-inductive for some ordinal \(\kappa \):

Counterexample 1

(Incompleteness of \(\boldsymbol{\kappa }\)-Induction). Consider the carrier set \(\{0, 1, 2\}\), partial order \(0 \sqsubset 1 \sqsubset 2\), and the monotonic operator \(\varPhi \) with \(\varPhi (0) = 0 = {\textsf {{lfp}}}~\varPhi \), and \(\varPhi (1) = 2\), and \(\varPhi (2) = 2 = {\textsf {{gfp}}}~\varPhi \). Then \({\textsf {{lfp}}}~\varPhi \sqsubseteq 1\), but for any ordinal \(\kappa \), \(\varPsi _{1}^{\left\lfloor \kappa \right\rfloor }(1) = 1\) and \(\varPhi (1) = 2 \not \sqsubseteq 1\). Hence 1 is not \(\kappa \)-inductive.    

Despite its incompleteness, we now provide a sufficient criterion which ensures that every upper bound on \({\textsf {{lfp}}}~\varPhi \) is \(\kappa \)-inductive for some ordinal \(\kappa \).

Theorem 3

(Completeness of \(\boldsymbol{\kappa }\)-Induction for Unique Fixed Point). If \({\textsf {{lfp}}}~\varPhi = {\textsf {{gfp}}}~\varPhi \) (i.e. \(\varPhi \) has exactly one fixed point), then, for every \(f\in E\),

$$\begin{aligned} {\textsf {{lfp}}}~\varPhi ~{}\sqsubseteq {}~f~\quad \text {implies}\quad ~f\text { is }\kappa \text {-inductive for some ordinal }\kappa . \end{aligned}$$

Proof

By the Knaster-Tarski theorem, we have \(\varPhi ^{\left\lfloor \beta \right\rfloor }(\top ) = {\textsf {{gfp}}}~\varPhi \) for some ordinal \(\beta \). We then show that \(f\) is \((\beta {+}1)\)-inductive; see [8, Appx A.3] for details.

   \(\square \)

The proof of the above theorem immediately yields that, if the unique fixed point can be reached through finite fixed point iterations starting at \(\top \), then \(f\) is k-inductive for some natural number k; Algorithm 1 thus eventually terminates.

Corollary 1

If \(\varPhi ^{\left\lfloor n \right\rfloor }\left( \top \right) = {\textsf {{lfp}}}~\varPhi \) for some \(n \in \mathbb {N} \), then, for every \(f\in E\),

$$\begin{aligned} {\textsf {{lfp}}}~\varPhi ~{}\sqsubseteq {}~f~\quad \text {implies}\quad ~f\text { is }n\text {-inductive for some }n \in \mathbb {N}. \end{aligned}$$

4 Latticed vs. Classical k-Induction

We show that our purely lattice-theoretic \(\kappa \)-induction from Sect. 3 generalizes classical k-induction for hardware- and software verification. To this end, we first recap how k-induction is typically formalized in the literature [10, 23, 29, 37]: Let \(\text {TS} = (S,\, I, T)\) be a transition system, where \(S \) is a (countable) set of states, \(I \subseteq S \) is a non-empty set of initial states, and \(T \subseteq S \times S \) is a transition relation. As in the seminal work on k-induction [65], we require that \(T \) is a total relation, i.e., every state has at least one successor. This requirement is sometimes overlooked in the literature, which renders the classical SAT-based formulation of k-induction ((1a) and (1b) below) unsound in general.

Our goal is to verify that a given invariant property \(P \subseteq S \) covers all states reachable in \(\text {TS} \) from some initial state. Suppose that \(I \), \(T \) and \(P \) are characterized by logical formulae \(I (s)\), \(T (s,s')\) and \(P (s)\) (over the free variables s and \(s'\)), respectively. Then, achieving the above goal with classical k-induction amounts to proving the validity of

$$\begin{aligned}&I (s_1) \wedge T (s_1,s_2) \wedge \ldots \wedge T (s_{k-1},s_k) \implies P (s_1) \wedge \ldots \wedge P (s_k),~\quad \text {and}\quad ~ \end{aligned}$$
(1a)
$$\begin{aligned}&P (s_1) \wedge T (s_1,s_2) \wedge \ldots \wedge P (s_k) \wedge T (s_k,s_{k+1}) \implies P (s_{k+1}). \end{aligned}$$
(1b)

Here, the base case (1a) asserts that \(P \) holds for all states reachable within k transition steps from some initial state; the induction step (1b) formalizes that \(P \) is closed under taking up to k transition steps, i.e., if we start in \(P \) and stay in \(P \) for up to k steps, then we also end up in \(P \) after taking the \((k{+}1)\)-st step. If both (1a) and (1b) are valid, then classical k-induction tells us that the property \(P \) holds for all reachable states of \(\text {TS} \). How is the above principle reflected in latticed k-induction (cf. Sect. 3)? For that, we choose the complete lattice \((2^S,\, \subseteq )\), where \(2^S\) denotes the powerset of \(S \); the least element is \(\bot = \emptyset \) and the meet operation is standard intersection \(\cap \).

Moreover, we define a monotonic operator \(\varPhi \) whose least fixed point precisely characterizes the set of reachable states of the transition system \(\text {TS} \):

$$\begin{aligned} \varPhi :\quad 2^S ~{}\rightarrow {}~2^S, \qquad F ~{}\mapsto {}~I \,\cup \, {\textsf {Succs}} (F), \end{aligned}$$

That is, \(\varPhi \) maps any given set of states \(F \subseteq S \) to the union of the initial states I and of those states \({\textsf {Succs}} (F)\) that are reachable from F using a single transition.Footnote 3

Using the \(\kappa \)-induction operator constructed from \(\varPhi \) and \(P \) according to Definition 1, the principle of \(\kappa \)-induction (cf. Theorem 2) then tells us that

For our above choices, the premise of \(\kappa \)-induction equals the classical formalization of k-induction—formulae (1a) and (1b)—because the set of initial states \(I \) is “baked into” the operator \(\varPhi \). More concretely, for the base case (1a), we have

In other words, formula (1a) captures those states that are reachable from \(I \) via at most k transitions. If we assume that (1a) is valid, then \(P \) contains all initial states and formula (1b) coincides with the premise of \(\kappa \)-induction:

$$\begin{aligned}&\underbrace{ \underbrace{ \underbrace{ \underbrace{ \underbrace{ P (s_1)\wedge T (s_1,s_2) }_{ \varPhi \left( P \right) } \wedge P (s_2) }_{ \varPsi _{P}(P) ~{}={}~\varPhi \left( P \right) \cap P} \wedge T (s_2,s_3) \wedge \ldots \wedge P (s_k) }_{ \varPsi _{P}^{\left\lfloor k-1 \right\rfloor }(P) } \wedge T (s_k,s_{k+1}) }_{ \varPhi \left( \varPsi _{P}^{\left\lfloor k-1 \right\rfloor }(P) \right) } \implies P (s_{k+1}) }_{ \qquad \qquad \qquad \qquad ~\text {meaning} \quad \varPhi \left( \varPsi _{P}^{\left\lfloor k-1 \right\rfloor }(P) \right) ~{}\subseteq {}~ P}. \end{aligned}$$

It follows that, when considering transition systems, our (latticed) \(\kappa \)-induction is equivalent to the classical notion of k-induction for \(\kappa < \omega \):

Theorem 4

For every natural number \(k \ge 1\),

$$\begin{aligned} \varPhi \left( \varPsi _{P}^{\left\lfloor k-1 \right\rfloor }(P) \right) ~{}\subseteq {}~ P ~\quad \text {iff}\quad ~\text {formulae (1a) and (1b) are valid}. \end{aligned}$$

5 Latticed Bounded Model Checking

We complement \(\kappa \)-induction with a latticed analog of bounded model checking [11, 12] for refuting that \({\textsf {{lfp}}}~\varPhi \sqsubseteq f\). In lattice-theoretic terms, bounded model checking amounts to a fixed point iteration of \(\varPhi \) on \(\bot \) while continually checking whether the iteration exceeds our candidate upper bound \(f\). If so, then we have indeed refuted \({\textsf {{lfp}}}~\varPhi \sqsubseteq f\):

Theorem 5

(Soundness of Latticed BMC). Let \(f\in E\). Then

Furthermore, if we were actually able to perform transfinite iterations of \(\varPhi \) on \(\bot \), then latticed bounded model checking is also complete: If \(f\) is in fact not an upper bound on \({\textsf {{lfp}}}~\varPhi \), this will be witnessed at some ordinal:

Theorem 6

(Completeness of Latticed BMC). Let \(f\in E\). Then

More practically relevant, if \(\varPhi \) is continuous (which is the case for Bellman operators characterizing reachability probabilities in Markov chains), then a simple finite fixed point iteration, see Algorithm 2, is sound and complete for refutation:

Corollary 2

(Latticed BMC for Continuous Operators). Let \(f\in E\) and let \(\varPhi \) be continuous. Then

$$\begin{aligned} \exists \, n \in \mathbb {N} :\quad \varPhi ^{n}(\bot ) ~{}\not \sqsubseteq {}~ f\qquad \text {iff}\qquad {\textsf {{lfp}}}~\varPhi ~{}\not \sqsubseteq {}~f. \end{aligned}$$
Fig. 2.
figure 2

Syntax of \({\textsf {{pGCL}}} \) programs, linear expressions, and guards, where x is a variable taken from a countable set \(\mathsf {Vars} \) of program variables (evaluating to natural numbers), \(p \in [0,1] \cap \mathbb {Q} \) is a rational probability, and \(n \in \mathbb {N} \) is a constant.

6 Probabilistic Programs

In the remainder of this article, we employ latticed k-induction and BMC to verify imperative programs with access to discrete probabilistic choices—branching on the outcomes of coin flips. In this section, we briefly recap the necessary background on formal reasoning about probabilistic programs (cf. [44, 49] for details).

6.1 The Probabilistic Guarded Command Language

Syntax. Programs in the probabilistic guarded command language \({\textsf {{pGCL}}} \) adhere to the grammar in Fig. 2a. The semantics of most statements is standard. In particular, the probabilistic choice \(\left\{ \, {C_1} \,\right\} \mathrel {\left[ \,p\,\right] }\left\{ \, {C_2} \,\right\} \) flips a coin with bias \(p \in [0,1] \cap \mathbb {Q} \). If the coin yields heads, it executes \(C_1\); otherwise, \(C_2\). In addition to the syntax in Fig. 2, we admit standard expressions that are definable as syntactic sugar, e.g., \(\mathsf {true}\), \(\mathsf {false}\), \(\varphi _1 \vee \varphi _2\), \(e_1 = e_2\), \(e_1 \le e_2\), etc.

Program States. A program state \(\sigma \) maps every variable in \(\mathsf {Vars} \) to its value, i.e., a natural number in \(\mathbb {N} \).Footnote 4 To ensure that the set of program states \(\varSigma \) remains countableFootnote 5, we restrict ourselves to states in which only finitely many variables—those that appear in a given program—evaluate to non-zero values. Formally,

The evaluation of expressions \(e\) and guards \(\varphi \) under a state \(\sigma \), denoted by \(e(\sigma )\) and \(\varphi (\sigma )\), is standard. For example, we define the evaluation of “monus” as

6.2 Weakest Preexpectations

Expectations. An expectation \(f:\varSigma \rightarrow \mathbb {R}_{\ge 0}^\infty \) is a map from program states to the non-negative reals extended by infinity. We denote by \(\mathbb {E}\) the set of all expectations. Moreover, \((\mathbb {E},\, \preceq )\) forms a complete lattice, where the partial order \(\preceq \) is given by the pointwise application of the canonical ordering \(\le \) on \(\mathbb {R}_{\ge 0}^\infty \), i.e.,

$$ f~{}\preceq {}~g\qquad \text {iff}\qquad \forall \, \sigma \in \varSigma :\quad f(\sigma ) ~{}\le {}~g(\sigma ). $$

To conveniently describe expectations evaluating to some \(r \in \mathbb {R}_{\ge 0}^\infty \) for every state, we slightly abuse notation and denote by \(r \) the constant expectation . Similarly, given an arithmetic expression \(e\), we denote by \(e\) the expectation . The least element of \((\mathbb {E},\, \preceq )\) is 0 and the greatest element is \(\infty \). We employ the Iverson bracket notation to cast Boolean expressions into expectations, i.e.,

The weakest preexpectation transformer \(\textsf {{wp}}:{\textsf {{pGCL}}} \rightarrow (\mathbb {E}\rightarrow \mathbb {E})\) is defined in Table 1, where denotes the substitution of variable x by expression \(e\), i.e.,

We call \(\textsf {{wp}}\llbracket C\rrbracket \left( g\right) \) the weakest preexpectation of program \(C\) w.r.t. postexpectation \(g\). The weakest preexpectation \(\textsf {{wp}}\llbracket C\rrbracket \left( g\right) \) is itself an expectation of type \(\mathbb {E}\), which maps each initial state \(\sigma \) to the expected value of \(g\) after running \(C\) on \(\sigma \). More formally, if \(\mu _C^\sigma \) is the distribution over final states obtained by executing \(C\) on initial state \(\sigma \), then for any postexpectation \(g\) [44],

$$\begin{aligned} \textsf {{wp}}\llbracket C\rrbracket \left( g\right) (\sigma ) ~{}={}~\sum \nolimits _{\tau \in \varSigma } \mu _C^\sigma (\tau ) \cdot g(\tau ). \end{aligned}$$

For a gentle introduction to weakest preexpectations, see [38, Chap. 2 and 4].

Table 1. Rules defining the weakest preexpectation transformer.

7 BMC and k-Induction for Probabilistic Programs

We now instantiate latticed \(\kappa \)-induction and BMC (as developed in Sects. 2 to 5) to enable verification of loops written in \({\textsf {{pGCL}}} \); we discuss practical aspects later in Sects. 7.1 to 7.3 and Sect. 8. For the next two sections, we fix a loop

For simplicity, we assume that the loop body \(C\) is loop-free (every probabilistic program can be rewritten as a single while loop with loop-free body [62]).

Given an expectation \(g\in \mathbb {E}\) and a candidate upper bound \(f\in \mathbb {E}\) on the expected value of \(g\) after executing \(C_{\text {loop}}\) (i.e. \(\textsf {{wp}}\llbracket C_{\text {loop}}\rrbracket \left( g\right) \)), we will apply latticed verification techniques to check whether \(f\) indeed upper-bounds \(\textsf {{wp}}\llbracket C_{\text {loop}}\rrbracket \left( g\right) \).

To this end, we denote by \(\varPhi \) the characteristic functional of \(C_{\text {loop}}\) and \(g\), i.e.,

$$ \varPhi :\quad \mathbb {E}~{}\rightarrow {}~\mathbb {E}, \qquad h~{}\mapsto {}~\left[ {\lnot \varphi } \right] \cdot g+ \left[ {\varphi } \right] \cdot \textsf {{wp}}\llbracket C\rrbracket \left( h\right) , $$

whose least fixed point defines \(\textsf {{wp}}\llbracket C_{\text {loop}}\rrbracket \left( g\right) \) (cf. Table 1). We remark that \(\varPhi \) is a monotonic—and in fact even continuous—operator over the complete lattice \((\mathbb {E}, \, \preceq )\) (cf. Sect. 6.2). In this lattice, the meet is a pointwise minimum, i.e.,

By Definition 1, \(\varPhi \) and \(g\) then induce the (continuous) \(\kappa \)-induction operator

$$\begin{aligned} \varPsi _{f}:\quad \mathbb {E}~{}\rightarrow {}~\mathbb {E}, \qquad h~{}\mapsto {}~\varPhi \left( h \right) \mathrel {\mathsf {min}} f. \end{aligned}$$

With this setup, we obtain the following proof rule for reasoning about probabilistic loops as an immediate consequence of Theorem 2:

Corollary 3

(\(\boldsymbol{k}\)-Induction for ). For every natural number \(k \in \mathbb {N} \),

$$ \varPhi \left( \varPsi _{f}^{\left\lfloor k \right\rfloor }(f) \right) ~{}\preceq {}~f~\quad \text {implies}\quad ~\textsf {{wp}}\llbracket C_{\text {loop}}\rrbracket \left( g\right) ~{}\preceq {}~f. $$

Analogously, refuting that \(f\) upper-bounds the expected value of \(g\) after execution of \(C_{\text {loop}}\) via bounded model checking is an instance of Corollary 2:

Corollary 4

(Bounded Model Checking for ).

$$ \exists \, n \in \mathbb {N} :\quad \varPhi ^{n}(0) ~{}\not \preceq {}~ f\qquad \text {iff}\qquad \textsf {{wp}}\llbracket C_{\text {loop}}\rrbracket \left( g\right) ~{}\not \preceq {}~ f. $$

Example 2 (Geometric Loop)

The \({\textsf {{pGCL}}} \) program

keeps flipping a fair coin x until it flips heads, sets x to 0, and terminates. Whenever it flips tails instead, it increments the counter c and continues. We refer to \(C_{\text {geo}}\) as the “geometric loop” because after its execution, the counter variable c is distributed according to a geometric distribution.

What is a (preferably small) upper bound on the expected value \(\textsf {{wp}}\llbracket C_{\text {geo}}\rrbracket \left( c\right) \) of c after execution of \(C_{\text {geo}}\)? Using 2-induction, we can (automatically) verify that \(c+1\) is indeed an upper bound: Since \(\varPhi \left( \varPsi _{c+1}(c+1) \right) \preceq c+1\), where \(\varPhi \) denotes the characteristic functional of \(C_{\text {geo}}\), Corollary 3 yields \(\textsf {{wp}}\llbracket C_{\text {geo}}\rrbracket \left( c\right) \preceq c + 1\).

However, \(c+1\) cannot be proven an upper bound using Park induction as it is not inductive. Moreover, it is indeed the least upper bound, i.e., any smaller bound is refutable using BMC (cf. Corollary 4). For example, we have \(\textsf {{wp}}\llbracket C_{\text {geo}}\rrbracket \left( c\right) \not \preceq c + 0.99\), since . Finally, we remark that some correct upper bounds only become \(\kappa \)-inductive for transfinite ordinals \(\kappa \). For instance, the innocuous-looking bound \(2 \cdot c + 1\) is not k-inductive for any natural number k, but it is \((\omega +1)\)-inductive, since \(\varPhi \bigl (\varPsi _{2\cdot c+1}^{\left\lfloor \omega \right\rfloor }(2 \cdot c+1) \bigr ) \preceq 2\cdot c+1\).    

In principle, we can semi-decide whether \(\textsf {{wp}}\llbracket C_{\text {loop}}\rrbracket \left( g\right) \not \preceq f\) holds or whether \(f\) is k-inductive for some k: it suffices to run Algorithms 1 and 2 in parallel. However, for these two algorithms to actually be semi-decision procedures, we cannot admit arbitrary expectations. Rather, we restrict ourselves to a suitable subset \(\mathsf {Exp} \) of expectations in \(\mathbb {E}\) satisfying all of the following requirements:

  1. 1.

    \(\mathsf {Exp} \) is closed under computing the characteristic functional \(\varPhi \), i.e.,

    $$\begin{aligned} \forall \, h\in \mathsf {Exp} :\quad \varPhi \left( h \right) ~\text {is computable and belongs to } \mathsf {Exp}. \end{aligned}$$
  2. 2.

    Quantitative entailments between expectations in \(\mathsf {Exp} \) are decidable, i.e.,

    $$\begin{aligned} \forall \, h, h' \in \mathsf {Exp} :\quad \text {it is decidable whether}~h~{}\preceq {}~h'. \end{aligned}$$
  3. 3.

    (For k-induction) \(\mathsf {Exp} \) is closed under computing meets, i.e.,

    $$\begin{aligned} \forall \, h, h' \in \mathsf {Exp} :\quad h\mathrel {\mathsf {min}} h'~\text {is computable and belongs to}~\mathsf {Exp}. \end{aligned}$$

Below, we show that linear expectations meet all of the above requirements.

7.1 Linear Expectations

Recall from Fig. 2b that we assume all expressions appearing in \({\textsf {{pGCL}}} \) programs to be linear. For our fragment of syntactic expectations, we consider extended linear expressions \(\tilde{e}\) that (1) are defined over rationals instead of natural numbers and (2) admit \(\infty \) as a constant (but not as a subexpression). Formally, the set of extended linear expressions is given by the following grammar:

figure l

Similarly, we admit extended linear expressions (without \(\infty \)) in linear guards \(\varphi \).Footnote 6 With these adjustments to expressions and guards in mind, the set \(\mathsf {LinExp} \) of linear expectations is defined by the grammar

$$\begin{aligned} h~\,::\,=~&\tilde{e}\quad {}|{}\quad \left[ {\varphi } \right] \cdot h\quad {}|{}\quad h+ h. \end{aligned}$$

We write \(h= h'\) if \(h\) and \(h'\) are ; and \(h\equiv h'\) if they are , i.e., if for all states \(\sigma \), we have \(h(\sigma ) = h'(\sigma )\).

Furthermore, the rescaling \(c \cdot h\) of a linear expectation \(h\) by a constant \(c \in \mathbb {Q}_{\ge 0}\) is syntactic sugar for rescaling suitableFootnote 7 arithmetic subexpressions of \(h\), e.g.,

A formal definition of the rescaling \(c \cdot h\) is found in [8, Appx A.5].

If we choose a linear expectation \(h\) as a postexpectation, then a quick inspection of Table 1 reveals that the weakest preexpectation \(\textsf {{wp}}\llbracket C\rrbracket \left( h\right) \) of any loop-free \({\textsf {{pGCL}}} \) program \(C\) and \(h\) yields a linear expectation again. Hence, linear expectations are closed under applying \(\varPhi \)— Requirement 1 above—because

$$\begin{aligned} \forall \, g,h\in \mathsf {LinExp} :\quad \varPhi \left( h \right) ~{}={}~\underbrace{ \underbrace{\left[ {\lnot \varphi } \right] \cdot g}_{~\in ~ \mathsf {LinExp}} \,+\, \left[ {\varphi } \right] \cdot \underbrace{\textsf {{wp}}\llbracket C\rrbracket \left( h\right) }_{~\in ~ \mathsf {LinExp}} }_{~\in ~ \mathsf {LinExp}}. \end{aligned}$$

7.2 Deciding Quantitative Entailments Between Linear Expectations

To prove that linear expectations meet Requirement 2—decidability of quantitative entailments—we effectively reduce the question of whether an entailment \(h\preceq h'\) holds to the decidable satisfiability problem for QF_LIRA—quantifier-free mixed linear integer and real arithmetic (cf. [42]).

As a first step, we show that every linear expectation can be represented as a sum of mutually exclusive extended arithmetic expressions—a representation we refer to as the guarded normal form (similar to [41, Lem. 1], [9, Lem. A.2]).

Definition 2 (Guarded Normal Form (GNF))

\(h\in \mathsf {LinExp} \) is in GNF if

$$\begin{aligned} h~{}={}~\sum \nolimits _{i = 1}^{n} \left[ {\varphi _i} \right] \cdot \tilde{e}_i, \end{aligned}$$

where \(\tilde{e}_1,\ldots ,\tilde{e}_n\) are extended linear expressions, \(n \in \mathbb {N} \) is some natural number, and \(\varphi _1, \ldots , \varphi _n\) are linear Boolean expressions that partition the set of states, i.e., for each \(\sigma \in \varSigma \) there exists exactly one \(i \in \{1,\ldots ,n\}\) such that \(\varphi _i (\sigma ) = \mathsf {true}\).

Lemma 3

Every linear expectation \(h\in \mathsf {LinExp} \) can effectively be transformed into an equivalent linear expectation \(\mathsf {GNF} \left( h\right) \equiv h\) in guarded normal form.

The number of summands \(|\mathsf {GNF} \left( h\right) |\) in \(\mathsf {GNF} \left( h\right) \) is, in general, exponential in the number of summands in \(h\). In practice, however, this exponential blow-up can often be mitigated by pruning summands with unsatisfiable guards. Throughout the remainder of this paper, we denote the components of \(\mathsf {GNF} \left( h\right) \) and \(\mathsf {GNF} \left( h'\right) \), where \(h\) and \(h'\) are arbitrary linear expectations, as follows:

$$\begin{aligned} \mathsf {GNF} \left( h\right) ~{}={}~\sum \nolimits _{i=1}^{n} \left[ {\varphi _i} \right] \cdot \tilde{e}_i ~\quad \text {and}\quad ~\mathsf {GNF} \left( h'\right) ~{}={}~&\sum \nolimits _{j=1}^{m} \left[ {\psi _j} \right] \cdot \tilde{a}_j. \end{aligned}$$

We now present a decision procedure for the quantitative entailment over \(\mathsf {LinExp} \).

Theorem 7

(Decidability of Quantitative Entailment over ). For \(h,h'\in \mathsf {LinExp} \), it is decidable whether \(h\preceq h'\) holds.

Proof

Let \(h,h'\in \mathsf {LinExp} \). By Lemma 3, we have \(h\preceq h'\) iff \(\mathsf {GNF} \left( h\right) \preceq \mathsf {GNF} \left( h'\right) \).

Let \(\sigma \) be some state. By definition of the GNF, \(\sigma \) satisfies exactly one guard \(\varphi _i\) and exactly one guard \(\psi _j\). Hence, the inequality \(\mathsf {GNF} \left( h\right) (\sigma ) \le \mathsf {GNF} \left( h'\right) (\sigma )\) does not hold iff \(\tilde{e}_i(\sigma ) > \tilde{a}_j(\sigma )\) holds for the expressions \(\tilde{e}_i\) and \(\tilde{a}_j\) guarded by \(\varphi _i\) and \(\psi _j\), respectively. Based on this observation, we construct a \(\textsf {QF\_LIRA} \) formula \(\textsf {cex}_{\preceq }\left( h , h' \right) \) that is unsatisfiable iff there is no counterexample to \(h\preceq h'\):

Here, we identify every program variable in \(h\) or \(h'\) with an \(\mathbb {N} \)-valued SMT variable. Moreover, to account for comparisons with \(\infty \), we rely on the fact that our (extended) arithmetic expressions either evaluate to \(\infty \) for every state or never evaluate to \(\infty \). To deal with the case \(\tilde{e}_i > \infty \), which is always false, we can thus safely exclude cases in which \(\tilde{a}_j = \infty \) holds. To deal with the case \(\infty > \tilde{a}_j\), we represent \(\infty \) by some unbounded number, i.e., we introduce a fresh, unconstrained \(\mathbb {N} \)-valued SMT variable \(\textsf {infty} \) and set \(\textsf {encodeInfty} \left( \tilde{e}\right) \) to \(\textsf {infty} \) if \(\tilde{e}= \infty \); otherwise, \(\textsf {encodeInfty} \left( \tilde{e}\right) = \tilde{e}\). Since \(\textsf {QF\_LIRA} \) is decidable (cf. [42]), we conclude that the quantitative entailment problem is decidable.    \(\square \)

Since quantitative entailments are decidable, we can already conclude that, for linear expectations, Algorithm 2 is a semi-decision procedure.

7.3 Computing Minima of Linear Expectations

To ensure that latticed k-induction on \({\textsf {{pGCL}}} \) programs (cf. Algorithm 1 and Sect. 7) is a semi-decision procedure when considering linear expectations, we have to consider Requirement 3—the expressability and computability of meets:

Theorem 8

\(\mathsf {LinExp} \) is effectively closed under taking minima.

Proof

For \(k\in \mathbb {N} \), let \(\mathbf {k} {}\triangleq {}\{1,\ldots ,k\}\). Then, for two linear expectations \(h, h'\), the linear expectation \(\mathsf {GNF} \left( h\right) \mathrel {\mathsf {min}} \mathsf {GNF} \left( h'\right) \in \mathsf {LinExp} \) is given by:

$$\begin{aligned} \sum _{(i,j)\, \in \, \mathbf {n} \times \mathbf {m}} {\left\{ \begin{array}{ll} \left[ {\varphi _i \wedge \psi _j} \right] \cdot \tilde{a}_j, &{}~\text {if }\tilde{e}_i = \infty , \\ \left[ {\varphi _i \wedge \psi _j} \right] \cdot \tilde{e}_i, &{}~\text {if }\tilde{a}_i = \infty , \\ \left[ {\varphi _i \wedge \psi _j \wedge \tilde{e}_i \le \tilde{a}_j} \right] \cdot \tilde{e}_i + \left[ {\varphi _i \wedge \psi _j \wedge \tilde{e}_i > \tilde{a}_j} \right] \cdot \tilde{a}_j &{}~\text {otherwise}, \end{array}\right. } \end{aligned}$$

where we exploit that, for every state, exactly one guard \(\varphi _i\) and exactly one guard \(\psi _j\) is satisfied (cf. Lemma 3). Notice that in the last case we indeed obtain a linear expectation since neither \(\tilde{e}\) nor \(\tilde{a}\) are equal to \(\infty \).    \(\square \)

8 Implementation

We have implemented a prototype called \(\textsc {kipro2}\)k-Induction for PRObabilistic PROgrams—in Python 3.7 using the SMT solver Z3 [54] and the solver-API PySMT [25]. Our tool, its source code, and our experiments are available online.Footnote 8 \(\textsc {kipro2}\) performs in parallel latticed k-induction and BMC to fully automatically verify upper bounds on expected values of \({\textsf {{pGCL}}} \) programs as described in Sect. 7. In addition to reasoning about expected values, \(\textsc {kipro2}\) supports verifying bounds on expected runtimes of \({\textsf {{pGCL}}} \) programs, which are characterized as least fixed points à la [40]. Rather than fixing a specific runtime model, we took inspiration from [56] and added a statement \({\texttt {tick}} \left( n \right) \) that does not affect the program state but consumes \(n \in \mathbb {N} \) time units.

To discharge quantitative entailments and compute the meet, we use the constructions in Theorems 7 and 8, respectively. As an additional optimization, we do not iteratively apply the k-induction operator \(\varPsi _{f}\) directly but use an incremental encoding. We briefly sketch our encoding for k-induction (Algorithm 2); the encoding for BMC is similar. In both cases, we employ uninterpreted functions on top of mixed integer and real arithmetic, i.e., \(\textsf {QF\_UFLIRA} \).

Recall Example 2, the geometric loop \(C_{\text {geo}}\), where we used k-induction to prove \(\textsf {{wp}}\llbracket C_{\text {geo}}\rrbracket \left( c\right) \preceq c + 1\). For every \(k \in \mathbb {N} \), \(\varPhi (\varPsi _{c+1}^{\left\lfloor k \right\rfloor }(c+1))\) is given by

To obtain an incremental encoding, we introduce an uninterpreted function \(P_k:\mathbb {N} \times \mathbb {N} \rightarrow \mathbb {R}_{\ge 0}\) and a formula \(\rho _{k}(c,x)\) specifying that \(P_k(c,x)\) characterizes \(\varPhi (\varPsi _{c+1}^{\left\lfloor k \right\rfloor }(c+1))\), i.e., for all \(\sigma \in \varSigma \) and \(r \in \mathbb {R}_{\ge 0}\) with \(\varPhi (\varPsi _{c+1}^{\left\lfloor k \right\rfloor }(c+1))(\sigma ) < \infty \),Footnote 9

$$\begin{aligned}&\rho _{k}(\sigma (c), \sigma (x)) \wedge P_k(\sigma (c), \sigma (x)) = r ~ \text {is satisfiable} ~\quad \text {iff}\quad ~r=\varPhi \Big (\varPsi _{c+1}^{\left\lfloor k \right\rfloor }(c+1)\Big )(\sigma ). \end{aligned}$$

If \(\varPhi (\varPsi _{c+1}^{\left\lfloor k \right\rfloor }(c+1))(\sigma ) = \infty \), our construction of \(\rho _{k}(x,c)\) ensures that the above conjunction is satisfiable for arbitrarily large r. Analogously, we introduce an uninterpreted function \(Q_k:\mathbb {N} \times \mathbb {N} \rightarrow \mathbb {R}_{\ge 0}\) that characterizes \(\varPsi _{c+1}^{\left\lfloor k \right\rfloor }(c+1)\).

In particular, may use all uninterpreted functions introduced for smaller or equal values of k—not just the function \(P_k(c,x)\) it needs to characterize. This enables an incremental encoding, i.e., \(\rho _{k}(c,x)\) can be computed on top of \(\rho _{k-1}(c,x)\) by reusing \(P_{k-1}(c,x)\), \(Q_k(c,x)\), and the construction in Theorem 8.

Moreover, we can reuse \(\rho _{k}(c,x)\) to avoid computing the (expensive) GNF for deciding certain quantitative entailments (cf. Theorem 7): For example, to check whether \(\varPhi (\varPsi _{c+1}^{\left\lfloor k \right\rfloor }(c+1)) \not \preceq h'\) holds, we only need to transform the right-hand side into GNF (cf. Sect. 7.2), i.e., if \(\mathsf {GNF} \left( h'\right) = \sum _{j=1}^{m} \left[ {\psi _j} \right] \cdot \tilde{a}_j\), then

$$\begin{aligned} \varPhi \Big (\varPsi _{c+1}^{\left\lfloor k \right\rfloor }(c+1)\Big ) \not \preceq g~\quad \text {iff}\quad ~\rho _{k} \wedge \bigvee \nolimits _{\begin{array}{c} j=1, \, \tilde{a}_j \ne \infty \end{array}}^m \psi _j \wedge P_k(c,x) > \tilde{a}_j~\text {is satisfiable}. \end{aligned}$$

9 Experiments

We evaluate \(\textsc {kipro2}\) on two sets of benchmarks. The first set, shown in Table 2, consists of four (infinite-state) probabilistic systems compiled from the literature; each benchmark is evaluated on multiple variants of candidate upper bounds:

  1. (1)

    brp is a \({\textsf {{pGCL}}} \) variant of the bounded retransmission protocol [19, 32]. The goal is to transmit \(\textit{toSend} \) many packages via an unreliable channel allowing for at most \(\textit{maxFail} \) many retransmissions per package (cf. Example 1). The variable \(\textit{totalFail} \) keeps track of the total number of failed attempts to send a package. We verified upper bounds on the expected outcome of \(\textit{totalFail} \) (variants 1–4). In doing so, we bound the number of packages to send by 4 (10, 20, 70) while keeping \(\textit{maxFail} \) unbounded, i.e., we still verify an infinite-state system. We notice that \(k > 1\) is required for proving any of the candidate bounds; for up to \(k = 11\), \(\textsc {kipro2}\) manages to prove non-trivial bounds within a few seconds. However, unsurprisingly, the complexity increases rapidly with larger k. While \(\textsc {kipro2}\) can prove variant 3, it needs to increase k to 23; we observe that the complexity grows rapidly both in terms of the size of formulae and in terms of runtime with increased k. Furthermore, variants 5–7 correspond to (increasing) incorrect candidate bounds (\(\textit{totalFail} +1\), \(\textit{totalFail} +1.5\), \(\textit{totalFail} +3\)) that are refuted (or time out) when not imposing any restriction on \(\textit{toSend} \).

  2. (2)

    geo corresponds to the geometric loop from Example 2. We verify that \(c+1\) upper-bounds the expected value of c for every initial state (variant 1); we refute the incorrect candidates \(c+0.99\) and \(c+0.999999999999\) (variants 2–3).

  3. (3)

    rabin is a variant of Rabin’s mutual exclusion algorithm [46] taken from [34]. We aim to verify that the probability of obtaining a unique winning process is at most \(\nicefrac {2}{3}\) for at most 2 (3, 4) participants (variants 1–3) and refute both \(\nicefrac {1}{3}\) (variant 4) and \(\nicefrac {3}{5}\) (variant 5) for an unbounded number of participants.

  4. (4)

    implements the algorithm in [48] for generating a discrete uniform distribution over some interval \(\{ \textit{l}, \ldots ,\textit{l}+\textit{n}-1 \}\) using only fair coin flips. We aim to verify that \(\nicefrac {1}{n}\) upper-bounds the probability of sampling a particular element from any such interval of size at most \(n=2\) (3, 4, 5, 6) (variants 1–5).

Our second set of benchmarks, shown in Table 3, confirms the correctness of (1-inductive) bounds on the expected runtime of \({\textsf {{pGCL}}} \) programs synthesized by the runtime analyzers Absynth [56] and (later) KoAT [52]; this gives a baseline for evaluating the performance of our implementation. Moreover, it demonstrates the flexibility of our approach as we effortlessly apply the expected runtime calculus [40] instead of the weakest preexpectation calculus for verification.

Setup. We ran Algorithms 1 and 2 in parallel using an AMD Ryzen 5 3600X processor with a shared memory limit of 8GB and a 15-minute timeout. For every benchmark finishing within the time limit, \(\textsc {kipro2}\) either finds the smallest k required to prove the candidate bound by k-induction or the smallest unrolling depth k to refute it. If \(\textsc {kipro2}\) refutes, the SMT solver provides a concrete initial state witnessing that violation. In Tables 2 and 3, column #formulae gives the maximal number of conjuncts on the solver stack; formulae_t, sat_t, and total_t give the amount of time spent on (1) computing formulae, (2) satisfiability checking, and (3) everything (including preprocessing), respectively. The input consists of a program, a candidate upper bound, and a postexpectation; in Table 3, the latter is fixed to “postruntime” 0 and thus omitted.

Table 2. Empirical results for the first benchmark set (time in seconds).

Evaluation of Benchmark Set 1. Table 2 empirically underlines that probabilistic program verification can benefit from k-induction to the same extent as classical software verification: \(\textsc {kipro2}\) fully automatically verifies relevant properties of infinite-state randomized algorithms and stochastic processes from the literature that require k to be strictly larger than 1. That is, proving these properties using (1-)inductive invariants requires either non-trivial invariant synthesis or additional user annotations. This indicates that k-induction mitigates the need for complicated specifications in probabilistic program verification (cf. [40]).

We observe that k-induction tends to succeed if some variable is bounded in the candidate upper bound under consideration (cf. brp, rabin, ). However, k-induction can also succeed without any bounds (cf. geo). The time and formulae required for checking k-inductivity increases rapidly for larger k; this is particularly striking for rabin and . When refuting candidate bounds with BMC, we obtain a similar picture. Both the time and formulae required for refutation increase if the candidate bound increases (cf. brp, geo, rabin).

For both k-induction and BMC, we observe a direct correlation between the complexity of the loop, i.e., the number of possible traces through the loop from some fixed initial state after some bounded number of iterations, and the required time and space (number of formulae). Whereas for geo and brp—which exhibit a rather simple structure—these checks tend to be fast, this is not the case for rabin and , which have more complex loop bodies. For such complex loops, k-induction and BMC quickly become infeasible as k increases.

Table 3. Empirical results for (a subset of) the ERTs [56] (time in milliseconds).

Evaluation of Benchmark Set 2. From Table 3, we observe that—in almost every case—verification is instantaneous and requires very few formulae. The programs we verify are equivalent to the programs provided in [56] up to interpreting minus as monus and using \(\mathbb {N} \)-typed (instead of \(\mathbb {Z} \)) variables. A manual inspection reveals that this matters for and rdwalk, which is the reason why the runtime bound for is 3-inductive rather than 1-inductive.

There are two timeouts (2drwalk, ) due to the GNF construction from Lemma 3, which exhibits a runtime exponential in the number of possible execution branches through the loop body. We conjecture that further preprocessing (by pruning infeasible branches upfront) can mitigate this, rendering 2drwalk and tractable as well. We consider a thorough investigation of suitable preprocessing strategies for GNF construction, which is outside the scope of this paper, a worthwhile direction for future research.

10 Conclusion

We presented \(\kappa \)-induction, a generalization of classical k-induction to arbitrary complete lattices, and—together with a complementary bounded model checking approach—obtained a fully automated technique for verifying infinite-state probabilistic programs. Experiments showed that this technique can prove non-trivial properties in an automated manner that using existing techniques cannot be proven—at least not without synthesizing a stronger inductive invariant. If a given candidate bound is k-inductive for some k, then our prototypical tool will find that k for linear programs and linear expectations. In theory, our tool is also applicable to non-linear programs at the expense of an undecidability quantitative entailment problem. It is left for future work to consider (positive) real-valued program variables for non-linear expectations.