Automatic Probabilistic Program Verification through
Random Variable Abstraction
Damián Barsotti ∗

Nicolás Wolovick ∗

Fa.M.A.F., Universidad Nacional de Córdoba, Ciudad Universitaria, 5000 Córdoba, Argentina

The weakest pre-expectation calculus [20] has been proved to be a mature theory to analyze quantitative properties of probabilistic and nondeterministic programs. We present an automatic method
for proving quantitative linear properties on any denumerable state space using iterative backwards
fixed point calculation in the general framework of abstract interpretation. In order to accomplish
this task we present the technique of random variable abstraction (RVA) and we also postulate a sufficient condition to achieve exact fixed point computation in the abstract domain. The feasibility of
our approach is shown with two examples, one obtaining the expected running time of a probabilistic
program, and the other the expected gain of a gambling strategy.
Our method works on general guarded probabilistic and nondeterministic transition systems instead of plain pGCL programs, allowing us to easily model a wide range of systems including distributed ones and unstructured programs. We present the operational and wp semantics for this programs and prove its equivalence.

1

Introduction

Automatic probabilistic program verification has been a field of active research in the last two decades.
The two major approaches to tackle this problem have been model checking [22, 9, 2, 11], and theorem
proving [12, 3]. Traditionally model checking has been targeted to be a push-button technique, but in the
quest of full automation some restrictions apply. The most prominent one is finiteness of the state space,
that leads to finite-state Markov chains (MC) and Markov decision processes (MDP). These models are
usually verified against probabilistic extensions of temporal logics such as PCTL [9, 2]. Even with the
finiteness restriction, the state explosion problem have to be alleviated using, for example, partial order
reduction techniques [1]. Another approach is taken in the PASS tool [23, 10], where the authors profit
from the work on predicate abstraction [8, 4] in the general framework of abstract interpretation [5] in
order to aggregate states conveniently and prevent the state explosion problem or even handle infinite
state spaces. Theorem proving techniques can also overcome state explosion and infinite state space
problems but at a cost, the automation is up-to loop invariants, that is, once the correct loop invariants
are fixed, the theorem prover can automatically prove the desired property [12]. There are also mixed
approaches like [17] in the realm of refinement checking of pGCL programs.
Automatic probabilistic program verification cannot, to the author’s knowledge, tackle the problem
of performance measurement of possibly unbounded program variables. Typical examples of this quantitative measurements are expected number of rounds of a probabilistic algorithm, or the expected revenue
of a gambling strategy. In this kind of problems, the model checking approach discretize the variable
up to a bound, either statically or using counterexample-guided abstraction refinement (CEGAR) [10],
but since the values it can reach are unbounded, an approximation is needed at some point. In theorem
∗ Granted

by MinCyT PID2008, Gobierno de la Provincia de Córdoba.

A. Di Pierro & G. Norman (Eds): 8th Workshop on Quantitative
Aspects of Programming Languages (QAPL 2010)
EPTCS 28, 2010, pp. 34–47, doi:10.4204/EPTCS.28.3

D. Barsotti & N. Wolovick

35

proving this problem could be solved but the invariants have to devised, and anyone involved in this task
knows that this is far from trivial.
We propose the computation of parametric linear invariants on a set of predefined predicates, and we
call this random variable abstraction (RVA) as it generalizes predicate abstraction (PA) to a quantitative
logic based on expectations [20]. Our motivation is simple. If the underlying invariants of the program
can be captured as a sum of linear random variables in disjoint regions of the state space, a suitable fixed
point computation should be able to discover the coefficients of such a linear expressions. To compute the
coefficients we depart from the traditional forward semantics approach, and use weakest pre-expectation
(wp) backwards semantics [20]. This combination of predicate abstraction, linear random variables
and quantitative wp, renders a new technique that can compute, for example, expected running time of
probabilistic algorithms, even though this quantities are not a-priori bound by any constant. This allows
us to reason about efficiency of algorithms.
Parametric linear invariants for probabilistic and nondeterministic programs using expectation logic
are also generated in [14], but our work differs in two aspects. First, in [14] all random variables have
to be one-bounded or equivalently they should be bounded by a constant. Second, in the computation
technique for the coefficients, they cast the problem to one of constraint-solving and resort to off-theshelf constraint solvers, while we use a fixed point computation.
Outline. In Section 2 we first give a motivating example that briefly shows the type of problems we
address as well as the mechanics to obtain the result. Then in Section 3 the probabilistic and nondeterministic programs, its operational and wp semantics are presented, as well as the fixed point computation
in the concrete domain of (general) random variables. Section 4 covers the abstract domain of random
variables, its semantics, and the fixed point computation, as well as the general problems to face in this
process. A more involved example is given in Section 5. Section 6 concludes the paper and discusses
future work.

2

Motivating Example

In order to give some intuition on what we are going to develop throughout the paper, we present a purely
probabilistic program P0 that generates a geometric distribution. This program halts with probability 1
P0 , x, i := 1, 0
;do x 6= 0 →
x := 0 ⊕ 1 x := 1
2
;i := i + 1
od
Figure 1: Geometric distribution.
and variable i could reach any natural number with positive probability. The semantics of this program
can be regarded as a probability measure ∆ over the naturals with distribution ∆.{K < i} = 21K . The
expected running timeR of the algorithm is precisely the expectation of random variable i with respect to
the measure ∆, that is ∆ i. Informally we could do this quantitative analysis as follows: the first iteration
is certain, however the second one occurs with probability one half, the third one will occur with half
the probability of previous one, and so on. In [20, p.69] the same calculation is done by hand, using the

36

Automatic Probabilistic Program Verification through Random Variable Abstraction

invariant (i + K) if (x 6= 0) else i, the equations fix K = 2 and this implies that given the initialization, the
expected value of random variable i is 2.
Our approach establishes a recursive higher-order function f on the domain of random variables
using weakest pre-expectation semantics [20]. It computes the expectation of taking a loop cycle and
repeating, or ending.
f .X , [x 6= 0] × wp.(x := 0 ⊕ 1 x := 1; i := i + 1).X + [x = 0] × i
2

We are looking for a fixed point of this functional, namely f .ϕ = ϕ, but taking a specific subset of
random variables: two linear functions on the post-expectation i, one for each region defined by the
predicates that control the flow of the program. It is a parametric random variable with coefficients
((a1 , a0 ), (b1 , b0 )).
Inv , (a1 i + a0 )[x = 0] + (b1 i + b0 )[x 6= 0]
Calculating f in the random variable Inv:
a0 +a1 +b0 +b1
1
f .Inv = (1i + 0)[x = 0] + ( a1 +b
)[x 6= 0] .
2 i+
2

If we only look at the coefficients, f can be (exactly) captured by function f ] on the domain R(1+1)×2 .
1 a0 +a1 +b0 +b1
f ] .((a1 , a0 ), (b1 , b0 )) = ((1, 0), ( a1 +b
)) .
2 ,
2

The computation goes as follows, from the random variable that is constantly 0 represented by the tuple
((0, 0), (0, 0)) we apply the update rule iteratively until the floating point precision produces a fixed point
after a little less than half hundred iterations (Table 1).

Iter.
0
1
2
3
4
5
6
7
..
.

(a1 , a0 )
(0, 0)
(1, 0)
(1, 0)
(1, 0)
(1, 0)
(1, 0)
(1, 0)
(1, 0)
..
.

45

(1 ,0)

Coefficients
(b1 , b0 )
(0, 0)
(0, 0)
(0.5, 0.5)
(0.75, 1)
(0.875, 1.375)
(0.9375, 1.625)
(0.96875, 1.78125)
(0.984375, 1.875)
..
.
(1, 2)

Table 1: Iteration for the geometric distribution program.
These fixed point coefficients represent the random variable i × [x = 0] + (i + 2) × [x 6= 0] that is a
valid pre-expectation of the repeating construct with respect to post-expectation i. If we take the weakest
pre-expectation of initialization (syntactic substitution) we obtain the value 2. Note that invariant and
expectation of random variable i coincide with the calculations done by hand in [20].

D. Barsotti & N. Wolovick

3
3.1

37

Concrete Semantics
Probabilistic Programs

We fix a finite set of variables X. A state is a function from variables to the semantic domain s : X → Ω,
and the set of all states is denoted by S. An expression is a function from states to the semantic domain
β : S → Ω, while a boolean expression is a function G : S → {true, false}, and an assignment E : S → S
is a state transformer. We define substitution of expression β with assignment E, β hEi as function
composition β ◦ E.
A guarded command (G → E1 @p1 | · · · |Ek @pk ) consists of a boolean guard G and assignments
E1 , · · · , Ek weighted with probabilities p1 , · · · , pk where ∑ki=1 pi ≤ 1.
A program P = (S, I ,C) consists of a boolean expression I that defines the set of initial states and a
finite set of guarded commands C.
Note that using this guarded commands we can underspecify (in the sense of refinement) in two ways.
One way is using guard overlapping, so in the non-null intersection of G0 and G1 there is a nondeterministic choice between the two multi-way probabilistic assignments. The other is using subprobability
distributions, since the expression (E0 @ 41 |E1 @ 41 ) can be regarded as all the probability distributions that
assign at least 14 to each branch [7]. Later, in the operational model, we will see that the first one is
handled by convex combination closure, while the later is handled by up closure.

3.2

Operational model

We fix the semantic domain Ω as a denumerable set, for example the rationals. The power set is denoted
by P, and if the empty set is not included we denote it P+ .
The set of (discrete) sub-probability measures over S is S = {∆ : S → [0..1] | ∑ ∆ ≤ 1}. The partial
order ∆ v ∆0 on S is defined pointwise, and 0 denotes the least element everywhere defined 0. A set of
sub-probability measures ξ ⊆ S is up-closed if ∆ ∈ ξ and ∆ v ∆0 then ∆0 ∈ ξ . Similarly ξ is convex closed
if for all p ∈ [0..1] and ∆0 , ∆1 ∈ ξ implies p∆0 + (1 − p)∆1 ∈ ξ . Finally ξ is Cauchy-closed or simply
i→∞
closed if it contains its boundary, that is for every sequence {∆i } ⊆ ξ , such that ∆i −→ ∆, then ∆ ∈ ξ .
CS is the set of non-empty, up-closed, convex and Cauchy-closed subsets of S. The set of probabilistic
programs over S is defined HS , S → CS, and it is ordered pointwise with v .
The probabilistic and nondeterministic transition system M is a tuple (S, I , T ) where S is the set of
states, I ⊆ S is a set of initial states, and an T ∈ HS is called transition function.
The semantics of a program P = (S, I ,C) is the tuple M = (S, I , T ) with the same state space and
initial states, where T .s is defined by its generators.
Definition 3.1. Given the program P = (S, I ,C), where C = {i : [0..l) • (Gi → E1i @pi1 | · · · |Eki i @piki )}, the
set of generators of T .s is GT .s , {i : [0..l) | Gi .s • ∆i } if (∃i : [0..l) • Gi .s), otherwise GT .s = {0}, where
∆i .s0 = (∑ j : [1..ki ] | E ij .s = s0 • pij ) .
The set GT .s is nonempty and closed. Now T .s can be defined from above as the minimum set over
CS that includes GT .s. Note this set is well defined since GT .s ⊆ S ∈ CS, and CS is closed by arbitrary
intersections. We can also define T .s from below, taking the up and convex closure of the generator set
GT .s. There is no need to take the Cauchy closure since the generator set is closed and the operators that
form the up and convex closure preserve this property.

38

3.3

Automatic Probabilistic Program Verification through Random Variable Abstraction

Expectation-transformer semantics

In the previous section a probabilistic and nondeterministic program semantics was defined as a transition
function from states to a subset of subprobability distributions. This set was defined to be up and convex
closed.
Verification of this particular type of programs poses the question of what propositions are in this
context. We take the approach by Kozen [15], where propositions Q : S → {true, false} are generalized
as random variables, that is a measurable function β : S → R≥ from states to positive reals. The program
P is taken as a distribution function
∆, and the program verification problem, formerly a boolean value
R
P |= Q is cast into an integral ∆ β that is the expectation of random variable β given distribution ∆.
In a nutshell this is a quantitative logic based on expectations. Boolean operators are (no uniquely)
generalized. The arithmetic counterpart of the implication is α V β , that is pointwise inequality (∀s :
S • α.s ≤ β .s). Conjunction ∧ can be taken as multiplication × or minimum u , and disjunction ∨ over
non overlapping predicates is captured by addition + . The characteristic function operator [·] goes from
the boolean to the arithmetic domain with the usual interpretation [true] = 1, [false] = 0, and using it we
could define negation as subtracting the truth value from one [¬Q] = 1 − [Q].
R
This model generalizes the deterministic one since it is proven that [P |= Q] = P [Q] for predicate Q
and deterministic program P.
In [13] He et al. extend Kozen’s work to deal with nondeterminism as well as probabilism in the
programs. The program verification problem is again a real value, namely the least expected value of
the random variable with respect to the sub-probability distributions generated by the program (demonic
nondeterminism).
Probabilistic (and nondeterministic) program verification problem is usually defined in the program
text itself as Hoare triple semantics or the equivalent weakest precondition calculus of Dijkstra [15, 20].
The triple {Q}P{Q0 } ≡ Q ⇒ wp.P.Q0 is generalized to {α}P{β } ≡ α V wp.P.β , and the generalized wp
is called weakest pre-expectation calculus or probabilistic wp semantics.
In general, the program outcome depends on the input state s, therefore wp.P.β is a function that
given the initial state establish a lower bound on the expectation of random variable β (it is exact in
the case of a purely probabilistic program). Therefore, expectations as functions of the input are also
random variables, hence we define the expectation space as ES , hS → R≥ , Vi. It is worth noticing that
all functions in ES are measurable since S is taken
to be denumerable (all subsets of S are measurable).
R
This implies that is valid to write integrals like ∆ f with ∆ ∈ S and f ∈ ES. We define the expectation
transformer space as the functions from expectations to expectations TS , hES ← ES, vi.
The wp expectation calculus is defined structurally in the constructors of probabilistic and nondeterministic programs (Fig. 2). This function basically maps assignments to substitutions, choice and
probabilistic choice to convex combination and nondeterministic choice to minimum.
Inspired in this semantics, we are going to define a weakest pre-expectation of our program
P = (S, I ,C). We first transform the program C into a semantically equivalent set but with pairwise
disjoint guards. Let C = {i : [0..l) • (Gi → E1i @pi1 | · · · |Eki i @piki )}. We follow the standard approach of
taking the complete boolean algebra [6] over the finite set of assertions {Gi }. The new program P0 is:
P0 = {I : P+ [0..l), i : I • (AI → E1i @pi1 | · · · |Eki i @piki )}
where
AI = (∧i : I • Gi ) ∧ (∧i : [0..l)−I • ¬Gi ) .

(1)

This program can be regarded as a pGCL program that consists of an if-else ladder of the atoms AI . In
each branch I, there is a |I|-way nondeterministic choice of ki -way probabilistic choice with i ∈ I. The

D. Barsotti & N. Wolovick

39

wp.abort.β , 0
wp.skip.β , β
wp.E.β , β hEi
wp.(P0 ; P1 ).β , wp.P0 .(wp.P1 .β )
wp.(P0 ⊕ p P1 ).β , p × wp.P0 .β + (1 − p) × wp.P1 .β
wp.(if G then P0 else P1 fi).β , wp.(P0 ⊕[G] P1 ).β
wp.(P0 u P1 ).β , wp.P0 .β u wp.P1 .β
wp.(do G → P od).β , (µX • [G] × wp.P.X + [¬G] × β )

Figure 2: wp expectation calculus.
wp semantics is defined as follows:



l
i : I • ∑ j : [1..ki ] • pij × β hEij i
.
wp.P0 .β , ∑ I : P+ [0..l) • [AI ] ×

3.4

(2)

Relational to expectation-transformer embedding

We now define the notion of wp but in terms of the transition T . The injection wp ∈ HS → TS is defined
as the minimum expectation for random variable β over all nondeterministic choices of sub-probability
distributions.

Z 
d
wp.T .β .s ,
∆ : T .s • β .
(3)
∆

The next lemma shows that the syntactic definition (2) inspired in pGCL wp calculus coincides with the
semantic one (3). From now on we will use both definitions interchangeably.
Lemma 3.2. The syntactic and semantic notions of weakest pre-expectation coincide, that is wp.P0 .β .s =
wp.T .β .s .
Proof. FirstR suppose there is a valid Gi .s. We begin by the rhs of the equality, that by (3) is
(u∆ : T .s • ∆ β ). The equality will be first proved for the generators GT .s ⊆ T .s, where GT .s =
{i : [0..l) | Gi .s • ∆i } and ∆i .s0 = (∑ j : [1..ki ] | E ij .s = s0 • pij ). Let
I = {i : [0..l) | Gi .s} the index set
R
of valid guards, then the minimum over all expectations is (ui : I • ∆i β ). Now we develop the inner term
using the fact that ∆i .s0 6= 0 on a finite set of points.
R

∆i β

= (∑s0 : S • β .s0 × ∆i .s0 )
= (∑s0 : S • β .s0 × (∑ j : [1..ki ] | E ij .s = s0 • pij ))

{ definition ∆i }

= (∑s0 : S, j : [1..ki ] | E ij .s = s0 • β .s0 × pij )
= (∑ j : [1..ki ] •
= (∑ j : [1..ki ] •

{ distributivity }

pij × β .(E ij .s))
pij × (β hE ij i).s)

{

s0

is a function of j }

{ definition of substitution }

Summing up we have
wp.T .β .s = ui : I •

∑ j : [1..ki ]

•

 
pij × (β hE ij i .s .

40

Automatic Probabilistic Program Verification through Random Variable Abstraction

Taking the expression wp.P0 .β in (2) and evaluating in s we get the same expression since only AI is
valid.
The other case is given when all guards are invalid in s. The rhs of the equation is 0 as 0 ∈ T .s, and
the lhs is a finite sum of 0’s.
For the rest of subprobability measures generated by the up and convex closure in GT .s we show the
minimum is maintained. Let ∆0 be the measure achieving the minimum expectation. If forR up-closure
R
it was added ∆ w ∆0 , by monotonicity of the integral we would get a greater expectation ∆ β ≥ ∆0 β .
For and added convex combination p∆0 + (1 − p)∆1 , it is easy to show that ∆0 = p∆0 + (1 − p)∆0 ≤
p∆0 + (1 − p)∆1 , and the minimum is not changed.

3.5

Fixed points

The theory of fixed points is frequently used to give meaning to iterative programs like the ones we
outlined in Section 3.3. In this section we present a fixed point theory in accordance with our particular
domain.
A poset is a meet-semilattice if each pair of elements has a greatest lower bound (it has meet). An
almost complete meet-semilattice is a meet-semilattice where every non-empty subset has a greatest
lower bound (it has infimum). The poset hR≥ , ≤i agrees this property by completeness of the real
numbers. Given a poset hX, vi, a function f : X → X is monotone if x v y ⇒ f .x v f .y. An element
x ∈ X is a pre-fixed point if f .x v x, and if f .x = x then is a fixed point. The least fixed point is denoted
as µ. f if it exists.
It’s easy to see that ES is an almost complete meet-semilattice because it is the pointwise extension
of hR≥ , ≤i from the set of states S, then it inherits the property. Therefore, we will develop the basic
fixed point theory focused on these domains. The next result (proved in [6, Lemma 2.15]) establishes the
existence of the supremum of a subset of an almost complete meet-semilattice:
Lemma 3.3. Let P be an almost complete meet-semilattice. Then the supremum tS exists in P for every
subset S of P which has an upper bound in P.
In general, an almost complete meet-semilattice is not necessarily a complete partial order (CPO).
For example, the poset hR≥ , ≤i does not form a CPO (it lacks a top element) but it is an almost complete
meet-semilattice. Hence, we cannot prove the general existence of fixed points in this domain. Although,
under certain conditions, existence of fixed points is guaranteed as stated in [18, Theorem 1.4]:
Theorem 3.4. Let a poset hX, vi and a monotone function f : X → X. Suppose X is an almost complete
meet-semilattice which has a least element ⊥ and f has a pre-fixed point in X. Then f has a least fixed
point as the infimum of the set of the pre-fixed points of f : µ. f = (u x | f .x v x • x) .
The next section shows a suitable notion of correctness for our programs, using this theorem.

3.6

Correctness

The wp semantics allows us to express quantitative properties as expectations. In order to verify this
properties, we present a notion of correctness based on the fact that any program P = (S, I ,C) can
be written as a pGCL program. Such programs can be constructed as a while loop with body made
as a nested if-else ladder statement as we mentioned in Section 3.3. The guards of these conditional
statements are the predicates AI in (1) and its bodies are the non-deterministics probabilistic assignments
corresponding to each guard as defined in (2). The loop guard G is the disjunction of the atoms, so it

D. Barsotti & N. Wolovick

41

exits the loop if there is no valid guard in the if-else ladder. The weakest pre-expectation semantics of
this program is defined in [20] as the least fixed point:
wp.do G → P0 od.β = (µX • [G] × wp.P0 .X + [¬G] × β )
where G = (∨ I : P+ [0..l) • AI ) and P0 is the if-else ladder statement. Therefore, we can characterize the
following idea of correctness:
Definition 3.5. Let a program P = (S, I ,C) with G0 , · · · , Gl−1 the guards of the commands in C, and
two expectations α, β ∈ ES. Let also G , (∨ i : [0..l) • Gi ) and f : ES → ES the expectation transformer
defined as:
f .X , [G] × wp.P.X + [¬G] × β .

(4)

Then, we said that [¬G] × β is a valid post-expectation of P with respect to the pre-expectation α if
α V µ. f .

(5)

Based on this definition, if we can find the fixed point ϕ = µ. f defined from (4) then we can show
that
[G] × ϕ V wp.P.ϕ
and [¬G] × ϕ V β ,
and these equations denote ϕ as an invariant of the system verifying the post-expectation β . Also, if it
satisfies (5), the initialization of the loop is also fulfilled.
Moreover, our definition of correctness requires the existence of a least fixed point µ. f . Although the
poset hES, Vi is an almost complete meet-semilattice, it is not a CPO because R≥ itself is not (it lacks an
adjoined ∞ element). Therefore, we must remark the existence of the least fixed point µ. f is guaranteed
only if f has a pre-fixed point as we require in Theorem 3.4. There are many cases where pre-fixed
point do not exist, even for plain pGCL programs. An example of this kind of program is P00 where it is
obtained from Fig. 1 simply replacing i := i + 1 by the (also linear) i := 2 ∗ i. With this modification, it
can be calculated that wp.P00 .i = ∞.

4
4.1

Abstract Semantics
Preliminaries

Following [19], we review the framework of abstract interpretation applied to our problem. Let us consider two posets Γ = hX, vi and Γ] = hX ] , ⊆i, and a monotone function γ : X ] → X called concretization
function. An element x] ∈ X ] is said to be a backward abstraction (b-abstraction) of x ∈ X if γ.x] v x.
The triple hΓ, Γ] , γi is called abstraction, where Γ is the concrete domain and Γ] the abstract domain.
Definition 4.1. Let f : X → X be a monotone function, f ] : X ] → X ] is a b-abstraction of f if
(∀x : X, x] : X ] | γ.x] v x

•

γ.( f ] .x] ) v f .x) .

The next theorem, relevant to our work, shows that fixed points can be calculated accurately and uniformly in an abstract domain.

42

Automatic Probabilistic Program Verification through Random Variable Abstraction

Theorem 4.2. Let hΓ, Γ] , γi be an abstraction where Γ is an almost complete meet-semilattice with a
least element ⊥ and Γ] has a least element ⊥] with γ.⊥] = ⊥. Let also f : X → X be a monotone
function and f ] : X ] → X ] a b-abstraction of f . Then, if f has a pre-fixed point in X
1. the supremum of {i : N • γ.( f ](i) .⊥] )} exists and is a lower bound of the least fixed point; that is
(t i : N • γ.( f ](i) .⊥] )) v µ. f ,
2. if (t i : N • γ.( f ](i) .⊥] )) is a pre-fixed point of f then both definitions coincide; that is
(t i : N • γ.( f ](i) .⊥] )) = µ. f .
Proof.
1. First, we prove µ. f is an upper bound of the set {i : N • γ.( f ](i) .⊥] )}. By induction: If γ.⊥] = ⊥,
then γ.⊥] v µ. f . Suppose γ.( f ](i) .⊥] ) v µ. f then
γ.( f ](i+1) .⊥] ) = γ.( f ] .( f ](i) .⊥] ))
v f .(µ. f )

{ inductive hypothesis, Definition 4.1 }
{ µ. f is fixed point of f }

= µ. f

Hence, µ. f is an upper bound of that set. By Lemma 3.3, the supremum (t i : N • γ.( f ](i) .⊥] ))
exists and is lower than µ. f .
2. If (t i : N • γ.( f ](i) .⊥] )) is a pre-fixed point of f , by Theorem 3.4 µ. f v (t i : N • γ.( f ](i) .⊥] )) and
by (1) these are equal.

The first part of this theorem shows that we can obtain a lower bound of the least fixed point over an
abstract domain. Then, given a program P and an abstract domain, this lower bound can be used to prove
the correctness of the program (5). The second part gives us a sufficient condition to achieve exact fix
point calculation in the abstract domain. We will go into these points in the next section.

4.2

Random Variable Abstraction

By Theorem 4.2 if we choose an appropriate abstract domain then we could calculate or
under-approximate the fixed point µ. f (defined in Section 3.6) in order to prove the validity of (5). We
begin by defining a suitable abstraction hΓ, Γ] , γi. The basic idea consists in generalizing predicate-based
abstraction theory (PA) [8, 4] to expectations. In PA the abstraction is determined by a set of N linear
predicates {p1 , · · · , pN }. The abstract state space is just the lattice generated by the set of all bit-vectors
(b1 , · · · , bN ) of length N whose concretization is defined as γ.(b1 , · · · , bN ) = (∧i : [1..N] • bi ≡ pi ). Then,
any predicate in the concrete domain can be represented as a series of truth values over each of these
atoms. Our RVA generalize these values by linear functions on the program variables.
Given a program P = (S, I ,C) over the set of variables X = {x1 , · · · , xn } and a set of disjoint convex
linear predicates φ1 , · · · , φm the abstract domain will be Γ] = hR(n+1)×m , V] i. It can be thought as the set
of parameters of linear expectations over the program variables for each linear predicate φi . Hence, the
concretization function is defined as:
m
γ.((q10 , · · · , q1n ), · · · , (qm
0 , · · · , qn )) , (∑ i : [1..m]

•

(qi0 + (∑ j : [1..n] • qij × x j ) × [φi ]))

(6)

and the order relation as x] V] y] , γ.x] V γ.y] . The predicates φ1 , · · · , φm can be constructed from the
guards of the program [8, 4] and taking the complete boolean algebra [6] over this finite set of assertions.

D. Barsotti & N. Wolovick

43

The next step is to define a b-abstraction of the transformer (4). First note, as we want to approximate
µ. f by (t i : N • γ.( f ](i) .⊥] )) (Theorem 4.2), we only need to obtain the set {i : N • f ](i) .⊥] } such that
expectations in {i : N • γ.( f ](i) .⊥] )} form an ascending chain in ES. Thus, using Theorem 4.2, we can
approximate by calculation the least fixed point of the transformer as the limit of this chain. Moreover, the
function f ] : R(n+1)×m → R(n+1)×m over the elements of the defined set must agree with Definition 4.1,
that is
(∀x : ES, i : N | γ.( f ](i) .⊥] ) V x • γ.( f ](i+1) .⊥] ) V f .x) .
If we suppose
γ.( f ](i+1) .⊥] ) V f .(γ.( f ](i) .⊥] ))

(7)

then f ] agrees the above definition:
γ.( f ](i) .⊥] ) V x ⇒ f .(γ.( f ](i) .⊥] )) V f .x

{ f monotone }

≡ γ.( f ](i+1) .⊥] ) V f .(γ.( f ](i) .⊥] ))
∧ f .(γ.( f ](i) .⊥] )) V f .x
⇒ γ.( f ](i+1) .⊥] ) V f .x

{ by supposition (7) }
{ by transitivity of V }

Taking into account (7) we construct the set {i : N • f ](i) .⊥] }, where the bottom element ⊥] is clearly
the null matrix in R(n+1)×m . Also, if we have defined f ](i) .⊥] we obtain f ](i+1) .⊥] as follows: first
we calculate f .(γ.( f ](i) .⊥] )) and then we choose an expectation in the lhs of (7) that can be accurately
m
]
represented in Γ] . Let f ](i) .⊥] = ((q10 , · · · , q1n ), · · · , (qm
0 , · · · , qn )) and β a b-abstraction of β . The former
can be obtained:
f .(γ.( f ](i) .⊥] )) = [G] × wp.P.(∑ i : [1..m] • (qi0 + (∑ j : [1..n] • qij × x j ) × [φi ]))
+ [¬G] × γ.β ]

{ by (6) and (4) }

d
= [G] × (∑ I : P+ [0..l) • [AI ] × ( r : I • (∑ s : [1..kr ] • psr × ηrs )))
+ [¬G] × γ.β ]

{ by (2) }

where
ηrs = (∑ i : [1..m] • (qi0 + (∑ j : [1..n] • qij × x j )hErs i × [φi hErs i])) .
Then, we restrict the above result within each domain defined by predicates φi obtaining a set of expectations. Although, these expectations are not necessarily linear, if the program is linear (we have only
linear assignments Ers ), each of them can be lower bounded by linear functions gi agreeing (7). Also, we
choose each function gi such that they are greater or equal than [φi ] × γ.( f ](i) .⊥] ) ensuring monotonicity
of the constructed chain. So, each gi must be bounded above and below:
[φi ] × γ.( f ](i) .⊥] ) V [φi ] × gi V [φi ] × f .(γ.( f ](i) .⊥] )) .
Note that it is always possible to find these bounded expectations gi because f is monotone
(then γ.( f ](i) .⊥] ) V f .(γ.( f ](i) .⊥] ))) and the lower bound [φi ] × γ.( f ](i) .⊥] ) defines an hyperplane
over the set of states φi . Also, as g1 , · · · , gm are linear functions, we can find the parameters
0m
(n+1)×m such that each g .(x , · · · , x ) , q0 i +( j : [1..n] • q0 i ×x ).
((q0 10 , · · · , q0 1n ), · · · , (q0 m
∑
i
1
n
j
0 , · · · , q n )) ∈ R
0
j
1
1
m
m
](i+1)
0
0
0
0
](i)
Then we define f
.⊥] , ((q 0 , · · · , q n ), · · · , (q 0 , · · · , q n )). Thus, we abstract f .(γ.( f .⊥] )) by
choosing a lower expectation that could be accurately represented in Γ] .

44

Automatic Probabilistic Program Verification through Random Variable Abstraction

Henceforth, by applying this method we can reach a fixed point ϕ ] in the abstract domain provided that
exists a pre-fixed point of transformer f (condition from Theorem 4.2). By Theorem 4.2(1), expectation γ.ϕ ] is a lower bound of µ. f and can be used to prove the correctness of the program regarding
post-expectation β . Also, if we can check γ.ϕ ] is a pre-fixed point of f then, by Theorem 4.2(2), it is the
least fixed point of f and our abstraction works accurately.
The following section shows an example using this method.

5

Martingale Example

In this section we give a more detailed example of our probabilistic program verification through random
variable abstraction, computing the average capital a gambler would expect from a typical martingale
betting system (Fig. 3). The gambler starts with a capital C and bets initially one unit. While the bet b is
lower than the remaining capital c, a fair coin is tossed and if it is a win, the player obtain one hundred
percent gain and stops gambling, otherwise it doubles the bet and continues. The expected gain of this
P1 , c, b := C, 1
;do 0 < b ≤ c →
c := c − b
;c, b := c + 2b, 0 ⊕ 1 b := 2b
2
od
Figure 3: Martingale.
strategy is given by wp.P1 .c .
Following Section 4.2 we first define the set of variables X and the set of disjoint convex linear
predicates φi . For the variables we take the whole set {b, c} since both participate in the control flow. The
predicates involved should, in principle, include the guard 0 < b ≤ c and its negation as it is customary in
PA. However the update operations in the program produce movements in the bidimensional state space
that cannot be accurately captured by this two regions. We propose an abstraction that divides the two
dimensional space (b, c) into six different regions (predicates). The regions are defined by the four atoms
given by the inequalities 0 < b, b ≤ c, plus two other inequalities that define the six total orders between
0, b and c. The concretization function γ of the abstract domain R(2+1)×6 is the sum of a linear function
on b, c in each region.
φ1 = 0 ≤ c < b

φ4 = b ≤ c < 0

φ2 = 0 < b ≤ c

φ5 = c < b ≤ 0

φ3 = b ≤ 0 ≤ c

φ6 = c < 0 < b

γ , ∑6i=1 (ci c + bi b + ai )[φi ]

If we disregard the initialization and coalesce the two assignments, the program can be transformed into
an equivalent P10 , but following the syntax of Section 3. It consists of just one guard:
P10 , 0 < b ≤ c → (c, b := c + b, 0)@ 12 | (c, b := c − b, 2b)@ 12 .
The fixed point computation is f .X , [G] × wp.P10 .X + [¬G] × β with post-expectation β = c. The
term wp.P10 .X is given by (2) and the other summand is given by the final state condition on the
post-expectation.
f .X = [0 < b ≤ c] × ( 21 Xhc, b := c + b, 0i + 12 Xhc, b := c − b, 2bi) + [¬(0 < b ≤ c)] × c .

D. Barsotti & N. Wolovick

45

The function f ] is b-abstraction of f that we are going to calculate now. We apply f to the concretization
function γ over generic coefficients, and obtain three blocks of summands given by the left assignment,
the right assignment and the post-expectation.
f .γ = 12 (c3 c + c3 b + a3 )[0 < c + b]
+ 21 ((c1 c + (2b1 − c1 )b + a1 )[b ≤ c < 3b] + (c2 c + (2b2 − c2 )b + a2 )[0 < 2b ∧ 3b ≤ c])
+ (∑i : [1..6] | i 6= 2 • (1c + 0b + 0)[φi ]) .
Clearly the first three summands do not fit into the abstraction given by predicates φi , however we can
give linear lower bounds on each of them that can be accurately represented in the abstract domain Γ] as
stated in Section 4.2. The region 0 ≤ c + b includes φ2 or in terms of random variables [0 < b ≤ c] V [0 ≤
c + b], so we keep the linear function in the smaller region. The other two regions Ψ1 , b ≤ c < 3b, Ψ2 ,
0 < 3b ≤ c form a partition of φ2 . It is needed to find a plane that in Ψ1 is below (c1 c + (2b1 − c1 )b + a1 )
and in Ψ2 is below (c2 c+(2b2 −c2 )b+a2 ). The two planes form a wedge (Fig. 4), so our lower bounding
plane would put a base on it. In the region Ψ1 the function simplifies to c − b and the minimum in the
region is 0 when c = b. For Ψ2 the minimum is c2 achieved in b = 0. Putting it all together we obtain
c
10

5

0

6

4
f.ΓÈ0<b£c
2

0
0

5

10

b

Figure 4: Piecewise linear function to be minimized by a plane.
the final linear expression that bounds f .γ from below and it is in terms of the original predicates:
2
•
f .γ ≥ ( c22+1 c + 1−c
2 b)[φ2 ] + (∑i : [1..6] | i 6= 2 (1c + 0b + 0)[φi ]) .

Note that doing this we comply with Eq. 7, and this in turn implies that f ] is a b-abstraction. We
explicitly write down f ] and iterate it up-to fixed point convergence in Table 2. As expected, φ4 , φ5 , φ6
do not contribute in the fixed point computation since 0 ≤ c is a program invariant, so we do not include
them:
2
f ] .((c1 , b1 , a1 ), (c2 , b2 , a2 ), (c3 , b3 , a3 )) , ((1, 0, 0), ( c22+1 , 1−c
2 , 0), (1, 0, 0)) .
We can see f ](i) .⊥] V] f ](i+1) .⊥] , so the under approximation γ.( f ](i+1) .⊥] ) tends from below to
(∑i : [1..6] • (1c + 0b + 0)[φi ]) = c.
The initialization c, b := C, 1 does the rest obtaining a lower bound on the expected remaining capital,
that is precisely C. It can be proven that c is a prefix point of f (in fact it is a fixed point), and using
Theorem 4.2 (2), we establish µ. f = c, therefore our approximation is exact. Moreover, as the program
is purely probabilistic, C is the expectation of c with respect to P.

46

Automatic Probabilistic Program Verification through Random Variable Abstraction

Iter.
0
1
2
3
4
5
6
7
..
.

(c1 , b1 , a1 )
(0, 0, 0)
(1, 0, 0)
(1, 0, 0)
(1, 0, 0)
(1, 0, 0)
(1, 0, 0)
(1, 0, 0)
(1, 0, 0)
..
.

55

(1, 0, 0)

Coefficients
(c2 , b2 , a2 )
(0, 0, 0)
(0.5, 0.5, 0)
(0.75, 0.25, 0)
(0.875, 0.125, 0)
(0.9375, 0.0625, 0)
(0.96875, 0.03125, 0)
(0.984375, 0.015625, 0)
(0.9921875, 0.0078125, 0)
..
.
(1, 0, 0)

(c3 , b3 , a3 )
(0, 0, 0)
(1, 0, 0)
(1, 0, 0)
(1, 0, 0)
(1, 0, 0)
(1, 0, 0)
(1, 0, 0)
(1, 0, 0)
..
.
(1, 0, 0)

Table 2: Iteration for the martingale.

6

Aims and conclusions

This paper presents a technique for computing the expectation of unbounded random variables tailored
to performance measures, like expected number of rounds of a probabilistic algorithm or expected number of detections in anonymity protocols. Our method can check quantitative linear properties on any
denumerable state space using iterative backwards fixed point calculation.
Perhaps the main drawback of the method is that it is semi-computable but it covers cases where
previous work cannot be applied (geometric distribution, martingales). Besides, it seems hard to bound
expectations of programs syntactically since a minor (linear) modification in the geometric distribution
algorithm leads to a unbounded expectation for a program that halts with probability 1.
In future work we would like to build tool support for our approach. This would involve, among
other tasks, the mechanization of the weakest pre-expectation calculus in the abstract domain, as well
as the maximization problem that involves computing a lower linear function in each iteration. As our
technique works on linear domains, this later task would be easily solved by known linear programming
techniques.
We also plan to analyze more complex programs. The Crowds anonymity protocol modeled as in [21]
is a good candidate for our automatic quantitative program analysis, since its essential anonymity properties are expressed as the expected number of times the message initiator is observed by the adversary
with respect to the observations obtained for the rest of the crowd. It is also planned to reproduce the
results of Rabin and Lehmann’s probabilistic dining-philosophers algorithm [16].
Acknowledgements. We would like to thank Pedro D’Argenio for his support in this project, as well
as Joost-Pieter Katoen for handing us an early draft of [14].

References
[1] C. Baier, P.R. D’Argenio & M. Größer (2006): Partial Order Reduction for Probabilistic Branching Time.
Electr. Notes Theor. Comput. Sci 153(2), pp. 97–116.
[2] A. Bianco & L. De Alfaro (1995): Model Checking of Probabilistic and Nondeterministic Systems. Lecture
Notes in Computer Science 1026, pp. 499–513.

D. Barsotti & N. Wolovick

47

[3] O. Celiku (2006): Mechanized Reasoning for Dually-Nondeterministic and Probabilistic Programs. Ph.D.
thesis, TUCS.
[4] M.A. Colon & T.E. Uribe (1998): Generating Finite-State Abstractions of Reactive Systems Using Decision
Procedures. In: Proc. 10 Int. Conf. on Computer Aided Verification, Lecture Notes in Computer Science
1427, Springer-Verlag, pp. 293–304.
[5] P. Cousot & R. Cousot (1977): Abstract Interpretation: A Unified Lattice Model for Static Analysis of Programs by Construction or Approximation of Fixpoints. In: 4th POPL, Los Angeles, CA, pp. 238–252.
[6] B.A. Davey & H.A. Priestley (1990): Introduction to Lattices and Order. Cambridge University Press.
[7] J. Desharnais, F. Laviolette & A. Turgeon (2009): A Demonic Approach to Information in Probabilistic
Systems. In: CONCUR 2009: Proceedings of the 20th International Conference on Concurrency Theory,
Springer-Verlag, Berlin, Heidelberg, pp. 289–304.
[8] S. Graf & H. Saı̈di (1997): Construction of Abstract State Graphs with PVS. In: O. Grumberg, editor: Proc.
9th International Conference on Computer Aided Verification (CAV’97), Lecture Notes in Computer Science
1254, Springer-Verlag, pp. 72–83.
[9] H. Hansson & B. Jonsson (1994): A logic for reasoning about time and probability. Formal Aspects of
Computing 5(6), pp. 512–535.
[10] H. Hermanns, B. Wachter & L. Zhang (2008): Probabilistic CEGAR. In: A. Gupta & S. Malik, editors:
Computer Aided Verification, 20th International Conference, CAV 2008, Princeton, NJ, USA, July 7-14,
2008, Proceedings, Lecture Notes in Computer Science 5123, Springer, pp. 162–175.
[11] A. Hinton, M.Z. Kwiatkowska, G. Norman & D. Parker (2006): PRISM: A Tool for Automatic Verification
of Probabilistic Systems. In: H. Hermanns & J. Palsberg, editors: Tools and Algorithms for the Construction
and Analysis of Systems, 12th International Conference, TACAS 2006, Lecture Notes in Computer Science
3920, Springer, pp. 441–444.
[12] J. Hurd, A.K. McIver & C.C. Morgan (2005): Probabilistic guarded commands mechanized in HOL. Theor.
Comput. Sci 346(1), pp. 96–112.
[13] H. Jifeng, K. Seidel & A.K. McIver (1997): Probabilistic models for the guarded command language. Science of Computer Programming 28(2–3), pp. 171–192.
[14] J.P. Katoen, A.K. McIver, L.A. Meinicke & C.C. Morgan (2009): Linear-invariant generation for probabilistic programs. Journal of Symbolic Computation Submitted.
[15] D. Kozen (1983): A probabilistic PDL. In: STOC ’83: Proceedings of the fifteenth annual ACM symposium
on Theory of computing, ACM, New York, NY, USA, pp. 291–297.
[16] A.K. McIver (2002): Quantitative Program Logic and Expected Time Bounds in Probabilistic Distributed
Algorithms. TCS: Theoretical Computer Science 282.
[17] A.K. McIver, C.C. Morgan & C. Gonzalia (2009): Probabilistic Affirmation and Refutation: Case Studies.
In APV 09: Symposium on Automatic Program Verification, Rı́o Cuarto, Argentina.
[18] M.W. Mislove, A.W. Roscoe & S.A. Schneider (1993): Fixed Points Without Completeness. Theoretical
Computer Science 138, pp. 138–2.
[19] D. Monniaux (2000): Abstract Interpretation of Probabilistic Semantics. In: J. Palsberg, editor: SAS, Lecture
Notes in Computer Science 1824, Springer, pp. 322–339.
[20] C.C. Morgan & A.K. McIver (2004): Abstraction, Refinement and Proofs for Probabilistic Programs. Monographs in Computer Science. Springer.
[21] V. Shmatikov (2004): Probabilistic analysis of an anonymity system. Journal of Computer Security 12(3-4),
pp. 355–377.
[22] M. Vardi (1985): Automatic Verification of Probabilistic Concurrent Finite-State Programs. In: focs85, pp.
327–338.
[23] B. Wachter, L. Zhang & H. Hermanns (2007): Probabilistic Model Checking Modulo Theories. In: QEST,
IEEE Computer Society, pp. 129–140.

