SLIDE 1 Efficient Analysis of Probabilistic Programs with an Unbounded Counter
CAV 2011 Tom´ aˇ s Br´ azdil1 Stefan Kiefer2 Anton´ ın Kuˇ cera1
1Masaryk University, Brno, Czech Republic 2University of Oxford, UK
SLIDE 2
Evaluation of And-Or Trees
∨ ∧ ∧ ∨ ∨ ∨ 1 ∧ ∧ ∨ ∨ 1 ∧ 1
procedure AND(node) if node is a leaf return node.value else for each successor s of node if OR(s) = 0 then return 0 return 1 procedure OR(node) ...
(evaluate only when necessary)
SLIDE 3
Evaluation of And-Or Trees
∨ ∧ ∧ ∨ ∨ ∨ 1 ∧ ∧ ∨ ∨ 1 ∧ 1
procedure AND(node) if node is a leaf return node.value else for each successor s of node if OR(s) = 0 then return 0 return 1 procedure OR(node) ...
(evaluate only when necessary) What is the average runtime? cannot tell: program may not even terminate
SLIDE 4
Evaluation of And-Or Trees
∨ ∧ ∧ ∨ ∨ ∨ 1 ∧ ∧ ∨ ∨ 1 ∧ 1
procedure AND(node) if node is a leaf return node.value else for each successor s of node if OR(s) = 0 then return 0 return 1 procedure OR(node) ...
(evaluate only when necessary) What is the average runtime? cannot tell: program may not even terminate probabilistic assumptions: AND node has 3 kids in average (geom. distribution) OR node has 2 kids in average a branch has length 4 in average Pr(leaf evaluates to 0) = Pr(leaf evaluates to 1) = 1
2
SLIDE 5
Evaluation of And-Or Trees
∨ ∧ ∧ ∨ ∨ ∨ 1 ∧ ∧ ∨ ∨ 1 ∧ 1
procedure AND(node) if node is a leaf return node.value else for each successor s of node if OR(s) = 0 then return 0 return 1 procedure OR(node) ...
(evaluate only when necessary) What is the average runtime? cannot tell: program may not even terminate probabilistic assumptions: AND node has 3 kids in average (geom. distribution) OR node has 2 kids in average a branch has length 4 in average Pr(leaf evaluates to 0) = Pr(leaf evaluates to 1) = 1
2
Under these probabilistic assumptions: Approximate efficiently the expected runtime
SLIDE 6
Probabilistic Counter Machines
Probabilistic Counter Machines induce infinite Markov chains: q
0.6
֒ − →r(+1) r
0.3
֒ − →q(±0) q
0.4
֒ − →q(−1) r
0.7
֒ − →r(−1) q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 0.3 0.3 0.3 0.4 0.4 0.4 0.7 0.7 0.7
SLIDE 7 Modeling a Program as Prob. Counter Machine
procedure AND(node) if node is a leaf return node.value else for each successor s of node if OR(s) = 0 then return 0 return 1
if leaf, return 0 or 1 : and
ℓ·z
֒ − → and0(−1) and
ℓ·(1−z)
֒ − − − − → and1(−1)
and
1−ℓ
֒ − − → or(+1) if OR returns 0, return 0 immediately :
1
֒ − → and0(−1)
- therwise, maybe call another OR :
- r1
x
֒ − → or(+1)
1−x
֒ − − → and1(−1)
SLIDE 8 Applications of Probabilistic Counter Machines
PCMs model infinite-state probabilistic programs recursion unbounded data structures PCMs = discrete-time Quasi-Birth-Death processes well established stochastic model studied since the late 60s queueing theory, performance evaluation, . . . Recently: Games over (Probabilistic) Counter Machines energy games [Chatterjee, Doyen et al.]
- ptimizing resource consumption in portable devices
SLIDE 9 Related Model: Probabilistic Pushdown System
Probabilistic Pushdown Systems modify a stack: q(X)
0.3
֒ − → r(YY ) q(X)
0.5
֒ − → r(X) q(Y ) ֒ − → . . . r(X) ֒ − → . . . r(Y ) ֒ − → . . . q(X)
0.2
֒ − → q(ε)
- Prob. Pushdown Systems (equivalently, Recursive Markov Chains)
are more general, but more expensive to analyze. PCMs are Prob. Pushdown Systems with a single stack symbol.
SLIDE 10
Probabilistic Counter Machines
q
0.6
֒ − →r(+1) r
0.3
֒ − →q(±0) q
0.4
֒ − →q(−1) r
0.7
֒ − →r(−1) q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 0.3 0.3 0.3 0.4 0.4 0.4 0.7 0.7 0.7
SLIDE 11
Trend
Runtime T := number of steps from (q, 1) to (∗, 0) We want to efficiently approximate ET. Trend t := “average increase of the counter per step” Assume t < 0. Intuition: The more negative the trend t, the smaller T.
SLIDE 12
Trend
Runtime T := number of steps from (q, 1) to (∗, 0) We want to efficiently approximate ET. Trend t := “average increase of the counter per step” Assume t < 0. Intuition: The more negative the trend t, the smaller T. Proposition (from martingale theory: Azuma’s inequality) Let m(0), m(1), m(2), . . . be random variables with m(0) = 1. Let t < 0. Assume E(m(k+1) | m(k)) = m(k) + t for all k. Then for all k: Pr(m(k) ≥ 1) ≤ ak, where a = e−t2/2 < 1. m(0) = 1 m(4)
SLIDE 13
Trend
Runtime T := number of steps from (q, 1) to (∗, 0) We want to efficiently approximate ET. Trend t := “average increase of the counter per step” Assume t < 0. Intuition: The more negative the trend t, the smaller T. Proposition (from martingale theory: Azuma’s inequality) Let m(0), m(1), m(2), . . . be random variables with m(0) = 1. Let t < 0. Assume E(m(k+1) | m(k)) = m(k) + t for all k. Then for all k: Pr(m(k) ≥ 1) ≤ ak, where a = e−t2/2 < 1. m(0) = 1 m(1) m(4)
SLIDE 14
Trend
Runtime T := number of steps from (q, 1) to (∗, 0) We want to efficiently approximate ET. Trend t := “average increase of the counter per step” Assume t < 0. Intuition: The more negative the trend t, the smaller T. Proposition (from martingale theory: Azuma’s inequality) Let m(0), m(1), m(2), . . . be random variables with m(0) = 1. Let t < 0. Assume E(m(k+1) | m(k)) = m(k) + t for all k. Then for all k: Pr(m(k) ≥ 1) ≤ ak, where a = e−t2/2 < 1. m(0) = 1 m(1) m(2) m(4)
SLIDE 15
Trend
Runtime T := number of steps from (q, 1) to (∗, 0) We want to efficiently approximate ET. Trend t := “average increase of the counter per step” Assume t < 0. Intuition: The more negative the trend t, the smaller T. Proposition (from martingale theory: Azuma’s inequality) Let m(0), m(1), m(2), . . . be random variables with m(0) = 1. Let t < 0. Assume E(m(k+1) | m(k)) = m(k) + t for all k. Then for all k: Pr(m(k) ≥ 1) ≤ ak, where a = e−t2/2 < 1. m(0) = 1 m(1) m(2) m(3) m(4)
SLIDE 16
Trend
Runtime T := number of steps from (q, 1) to (∗, 0) We want to efficiently approximate ET. Trend t := “average increase of the counter per step” Assume t < 0. Intuition: The more negative the trend t, the smaller T. Proposition (from martingale theory: Azuma’s inequality) Let m(0), m(1), m(2), . . . be random variables with m(0) = 1. Let t < 0. Assume E(m(k+1) | m(k)) = m(k) + t for all k. Then for all k: Pr(m(k) ≥ 1) ≤ ak, where a = e−t2/2 < 1. m(0) = 1 m(1) m(2) m(3) m(4) m(4)
SLIDE 17
Trend
Runtime T := number of steps from (q, 1) to (∗, 0) We want to efficiently approximate ET. Trend t := “average increase of the counter per step” Assume t < 0. Intuition: The more negative the trend t, the smaller T. Proposition (from martingale theory: Azuma’s inequality) Let m(0), m(1), m(2), . . . be random variables with m(0) = 1. Let t < 0. Assume E(m(k+1) | m(k)) = m(k) + t for all k. Then for all k: Pr(m(k) ≥ 1) ≤ ak, where a = e−t2/2 < 1. m(0) = 1 m(1) m(2) m(3) m(4) m(4) m(5)
SLIDE 18 Trend
Runtime T := number of steps from (q, 1) to (∗, 0) We want to efficiently approximate ET. Trend t := “average increase of the counter per step” Assume t < 0. Intuition: The more negative the trend t, the smaller T. Proposition (from martingale theory: Azuma’s inequality) Let m(0), m(1), m(2), . . . be random variables with m(0) = 1. Let t < 0. Assume E(m(k+1) | m(k)) = m(k) + t for all k. Then for all k: Pr(m(k) ≥ 1) ≤ ak, where a = e−t2/2 < 1. m(0) = 1 m(1) m(2) m(3) m(4) m(4) m(5) Pr(T > k) ≤ Pr(m(k) ≥ 1) ≤ ak ET =
∞
Pr(T > k) ≤ 1 1 − a
SLIDE 19 Trend
Runtime T := number of steps from (q, 1) to (∗, 0) We want to efficiently approximate ET. Trend t := “average increase of the counter per step” Assume t < 0. Intuition: The more negative the trend t, the smaller T. Proposition (from martingale theory: Azuma’s inequality) Let m(0), m(1), m(2), . . . be random variables with m(0) = 1. Let t < 0. But the trend must be independent of k :-( Assume E(m(k+1) | m(k)) = m(k) + t for all k. Then for all k: Pr(m(k) ≥ 1) ≤ ak, where a = e−t2/2 < 1. m(0) = 1 m(1) m(2) m(3) m(4) m(4) m(5) Pr(T > k) ≤ Pr(m(k) ≥ 1) ≤ ak ET =
∞
Pr(T > k) ≤ 1 1 − a
SLIDE 20 Trend
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 0.3 0.3 0.3 0.4 0.4 0.4 0.7 0.7 0.7 Average counter increase depends on state: 0.4 · (−1) + 0.6 · (+1) 0.3 · 0 + 0.7 · (−1)
0.2 −0.7
SLIDE 21 Trend
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 0.3 0.3 0.3 0.4 0.4 0.4 0.7 0.7 0.7 Average counter increase depends on state: 0.4 · (−1) + 0.6 · (+1) 0.3 · 0 + 0.7 · (−1)
0.2 −0.7
- Weight this by the stationary distribution
- f the counterless system:
q r 0.6 0.4 0.3 0.7 1/3 2/3
0.2 −0.7
1/3 2/3
SLIDE 22 Trend
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 . 6 . 6 0.3 0.3 0.3 0.4 0.4 0.4 0.7 0.7 0.7 Average counter increase depends on state: 0.4 · (−1) + 0.6 · (+1) 0.3 · 0 + 0.7 · (−1)
0.2 −0.7
- Weight this by the stationary distribution
- f the counterless system:
q r 0.6 0.4 0.3 0.7 1/3 2/3
0.2 −0.7
1/3 2/3
SLIDE 23 Trend
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 . 6 . 6 0.3 0.3 0.3 0.4 0.4 0.4 0.7 0.7 0.7 Average counter increase depends on state: 0.4 · (−1) + 0.6 · (+1) 0.3 · 0 + 0.7 · (−1)
0.2 −0.7
- Weight this by the stationary distribution
- f the counterless system:
q r 0.6 0.4 0.3 0.7 1/3 2/3
0.2 −0.7
1/3 2/3
SLIDE 24 Trend
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 0.3 0.3 0.3 0.4 0.4 0.4 0.7 0.7 0.7 Average counter increase depends on state: 0.4 · (−1) + 0.6 · (+1) 0.3 · 0 + 0.7 · (−1)
0.2 −0.7
- Weight this by the stationary distribution
- f the counterless system:
q r 0.6 0.4 0.3 0.7 1/3 2/3
0.2 −0.7
1/3 2/3
SLIDE 25 Trend
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 0.3 0.3 0.3 0.4 0.4 0.4 0.7 0.7 0.7 Average counter increase depends on state: 0.4 · (−1) + 0.6 · (+1) 0.3 · 0 + 0.7 · (−1)
0.2 −0.7
- Weight this by the stationary distribution
- f the counterless system:
q r 0.6 0.4 0.3 0.7 1/3 2/3
0.2 −0.7
1/3 2/3
SLIDE 26 Trend
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 0.3 0.3 0.3 0.4 0.4 0.4 0.7 0.7 0.7 Average counter increase depends on state: 0.4 · (−1) + 0.6 · (+1) 0.3 · 0 + 0.7 · (−1)
0.2 −0.7
- Weight this by the stationary distribution
- f the counterless system:
q r 0.6 0.4 0.3 0.7 1/3 2/3
0.2 −0.7
1/3 2/3
SLIDE 27 Trend
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 0.3 0.3 0.3 0.4 0.4 0.4 0.7 0.7 0.7 Average counter increase depends on state: 0.4 · (−1) + 0.6 · (+1) 0.3 · 0 + 0.7 · (−1)
0.2 −0.7
- Weight this by the stationary distribution
- f the counterless system:
q r 0.6 0.4 0.3 0.7 1/3 2/3
0.2 −0.7
1/3 2/3
SLIDE 28 Trend
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 0.3 0.3 0.3 0.4 0.4 0.4 0.7 0.7 0.7 Average counter increase depends on state: 0.4 · (−1) + 0.6 · (+1) 0.3 · 0 + 0.7 · (−1)
0.2 −0.7
- Weight this by the stationary distribution
- f the counterless system:
q r 0.6 0.4 0.3 0.7 1/3 2/3
0.2 −0.7
1/3 2/3
SLIDE 29 Trend
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 . 3 . 3 . 3 0.4 0.4 0.4 0.7 0.7 0.7 Average counter increase depends on state: 0.4 · (−1) + 0.6 · (+1) 0.3 · 0 + 0.7 · (−1)
0.2 −0.7
- Weight this by the stationary distribution
- f the counterless system:
q r 0.6 0.4 0.3 0.7 1/3 2/3
0.2 −0.7
1/3 2/3
SLIDE 30 Trend
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 . 3 . 3 . 3 0.4 0.4 0.4 0.7 0.7 0.7 Average counter increase depends on state: 0.4 · (−1) + 0.6 · (+1) 0.3 · 0 + 0.7 · (−1)
0.2 −0.7
- Weight this by the stationary distribution
- f the counterless system:
q r 0.6 0.4 0.3 0.7 1/3 2/3
0.2 −0.7
1/3 2/3
SLIDE 31 Trend
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 . 3 . 3 . 3 0.4 0.4 0.4 0.7 0.7 0.7 Average counter increase depends on state: 0.4 · (−1) + 0.6 · (+1) 0.3 · 0 + 0.7 · (−1)
0.2 −0.7
- Weight this by the stationary distribution
- f the counterless system:
q r 0.6 0.4 0.3 0.7 1/3 2/3
0.2 −0.7
1/3 2/3
SLIDE 32 Trend
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 . 3 . 3 . 3 0.4 0.4 0.4 0.7 0.7 0.7 Average counter increase depends on state: 0.4 · (−1) + 0.6 · (+1) 0.3 · 0 + 0.7 · (−1)
0.2 −0.7
- Weight this by the stationary distribution
- f the counterless system:
q r 0.6 0.4 0.3 0.7 1/3 2/3
0.2 −0.7
1/3 2/3
expected height increase: t = −0.4. independent of control state :-)
SLIDE 33
Positive Trend
m(0) = 1 m(1) m(2) m(3) m(4) m(5) If t > 0, then Pr(T = ∞) > 0. E(T | finite) can be bounded as before.
SLIDE 34
Zero Trend
k m(0) = 1 m(1) m(2) m(3) m(4) m(5) Proposition (from martingale theory: Optional stopping theorem) Let m(0), m(1), m(2), . . . be random variables with m(0) = 1. Assume E(m(i+1) | m(i)) = m(i) for all i. Let k ∈ N. Let τ be the first time with m(τ) ∈ (0, k). Then Em(τ) = 1.
SLIDE 35
Zero Trend
k m(0) = 1 m(1) m(2) m(3) m(4) m(5) Proposition (from martingale theory: Optional stopping theorem) Let m(0), m(1), m(2), . . . be random variables with m(0) = 1. Assume E(m(i+1) | m(i)) = m(i) for all i. Let k ∈ N. Let τ be the first time with m(τ) ∈ (0, k). Then Em(τ) = 1. Assuming all jumps are +1, ±0, −1, we must have m(τ) = k m(τ) = 0
SLIDE 36
Zero Trend
k m(0) = 1 m(1) m(2) m(3) m(4) m(5) Proposition (from martingale theory: Optional stopping theorem) Let m(0), m(1), m(2), . . . be random variables with m(0) = 1. Assume E(m(i+1) | m(i)) = m(i) for all i. Let k ∈ N. Let τ be the first time with m(τ) ∈ (0, k). Then Em(τ) = 1. Assuming all jumps are +1, ±0, −1, we must have Pr(m(τ) = k) = 1/k and Pr(m(τ) = 0) = 1 − 1/k
SLIDE 37
Zero Trend
k m(0) = 1 m(1) m(2) m(3) m(4) m(5) Proposition (from martingale theory: Optional stopping theorem) Let m(0), m(1), m(2), . . . be random variables with m(0) = 1. Assume E(m(i+1) | m(i)) = m(i) for all i. Let k ∈ N. Let τ be the first time with m(τ) ∈ (0, k). Then Em(τ) = 1. Assuming all jumps are +1, ±0, −1, we must have Pr(m(τ) = k) = 1/k and Pr(m(τ) = 0) = 1 − 1/k Pr(T ≥ k) ≥ Pr(m(τ) = k) = 1/k and hence ET = ∞
SLIDE 38
Finiteness of Expected Time
We condition on runs q↓r: from (q, 1) reach (r, 0) (e.g., consider [and↓and0], [and↓and1]) Theorem Either some easy case holds or one of the following: If trend t = 0, then E(T | q↓r) ≤ 85000 · |Q|6 x5|Q|+|Q|3
min
· t4 . If trend t = 0, then E(T | q↓r) is infinite. Corollary Whether E(T | q↓r) is finite can be decided in polynomial time.
SLIDE 39
Finiteness of Expected Time
We condition on runs q↓r: from (q, 1) reach (r, 0) (e.g., consider [and↓and0], [and↓and1]) Theorem Either some easy case holds or one of the following: If trend t = 0, then E(T | q↓r) ≤ 85000 · |Q|6 x5|Q|+|Q|3
min
· t4 . If trend t = 0, then E(T | q↓r) is infinite. Corollary Whether E(T | q↓r) is finite can be decided in polynomial time. But we want an approximation of E(T | q↓r).
SLIDE 40 Return Probabilities
“return probabilities” : [q↓r] := Pr
- from (q, 1) reach (r, 0)
- Proposition (from [EWY’08])
If [q↓r] > 0, then [q↓r] ≥ x|Q|3
min .
[q↓r] can be approximated within any error ε > 0 in time poly(|S|, log(1/ε)) in unit-cost arithmetic. (does not hold for pushdown systems)
SLIDE 41
Approximating Expected Runtime
Theorem The value E(T | q↓r) can be approximated within any error ε > 0 in time poly(|S|, log(1/ε)) in unit-cost arithmetic. Use the following procedure: Set up an equation system Ax = 1. (system already known) Solution vector contains E(T | q↓r) for all q, r ∈ Q. The matrix A contains return probabilities. Approximate A by approximating the return probabilities. Solve the approximated equation system.
SLIDE 42
Approximating Expected Runtime
Theorem The value E(T | q↓r) can be approximated within any error ε > 0 in time poly(|S|, log(1/ε)) in unit-cost arithmetic. Use the following procedure: Set up an equation system Ax = 1. (system already known) Solution vector contains E(T | q↓r) for all q, r ∈ Q. The matrix A contains return probabilities. Approximate A by approximating the return probabilities. Solve the approximated equation system. Precision of this method depends on the condition number of A. The condition number is good enough as: the return probabilities cannot be too small the solution cannot be too large (by our bound on ET)
SLIDE 43
Rules for Zero Counter
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 0.3 0.3 0.3 0.4 0.4 0.4 0.7 0.7 0.7 Now allow rules for zero counter (not −1) all runs are infinite
SLIDE 44
Rules for Zero Counter
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 0.3 0.3 0.3 0.4 0.4 0.4 0.7 0.7 0.7 Now allow rules for zero counter (not −1) all runs are infinite
SLIDE 45
Rules for Zero Counter
q, 0 q, 1 q, 2 q, 3 r, 0 r, 1 r, 2 r, 3 0.6 0.6 0.3 0.3 0.3 0.4 0.4 0.4 0.7 0.7 0.7 1.0 . 5 0.5 Now allow rules for zero counter (not −1) all runs are infinite
SLIDE 46
ω-regular Specifications
Theorem Given an ω-regular specification in terms of a Rabin automaton R, the probability of a run satisfying the specification can be approximated within any error ε > 0 in time poly(|S|, |R|, log(1/ε)) in unit-cost arithmetic. Proof uses again “trend”-based martingale arguments.
SLIDE 47
Summary
Probabilistic Counter Machines model infinite-state systems with a regular “counter-like” structure. Expected runtime and other quantities can be efficiently approximated (cf. prob. pushdown systems). Martingale techniques play a key role for the analysis.
SLIDE 48
Thank you!