Weakest Precondition Reasoning for Expected Run–Times of

Weakest Precondition Reasoning for Expected
Run–Times of Probabilistic Programs
Benjamin Kaminski
Christoph Matheja
Joost-Pieter Katoen
Federico Olmedo
25th European Symposium on Programming
19th edition of the European Joint Conferences on Theory & Practice of Software
April 4, 2016, Eindhoven, Netherlands
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
1
Motivation
Probabilistic Programs
Probabilistic Programs
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
2
Motivation
Probabilistic Programs
Probabilistic Programs
Introduce randomization into computation
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
2
Motivation
Probabilistic Programs
Probabilistic Programs
Introduce randomization into computation
Significant speed–up in solving difficult problems at cost of
tolerating incorrect results with low probability
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
2
Motivation
Probabilistic Programs
Probabilistic Programs
Introduce randomization into computation
Significant speed–up in solving difficult problems at cost of
tolerating incorrect results with low probability
Solution to problems where deterministic techniques fail:
E.g. symmetry breaking in Dining Philosophers, Leader
Election, Ethernet’s randomized exponential backoff
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
2
Motivation
Probabilistic Programs
Probabilistic Programs
Introduce randomization into computation
Significant speed–up in solving difficult problems at cost of
tolerating incorrect results with low probability
Solution to problems where deterministic techniques fail:
E.g. symmetry breaking in Dining Philosophers, Leader
Election, Ethernet’s randomized exponential backoff
Randomization of some sort occurs almost in any technique
related used in cryptography and security
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
2
Motivation
Probabilistic Programs
Probabilistic Programs
Introduce randomization into computation
Significant speed–up in solving difficult problems at cost of
tolerating incorrect results with low probability
Solution to problems where deterministic techniques fail:
E.g. symmetry breaking in Dining Philosophers, Leader
Election, Ethernet’s randomized exponential backoff
Randomization of some sort occurs almost in any technique
related used in cryptography and security
Model probability distributions in machine learning
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
2
Motivation
Probabilistic Programs
Syntax of Probabilistic Programs
C
−→
Kaminski, Katoen, Matheja, Olmedo
skip x := E C; C
if (ξ) {C} else {C}
{C} 2 {C}
while (ξ) {C}
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
3
Motivation
Probabilistic Programs
Syntax of Probabilistic Programs
C
−→
Kaminski, Katoen, Matheja, Olmedo
skip x := E C; C
if (ξ) {C} else {C}
{C} 2 {C}
while (ξ) {C}
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
3
Motivation
Probabilistic Programs
Syntax of Probabilistic Programs
C
−→
Kaminski, Katoen, Matheja, Olmedo
skip x := E C; C
if (ξ) {C} else {C}
{C} 2 {C}
while (ξ) {C}
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
3
Motivation
Probabilistic Programs
Syntax of Probabilistic Programs
C
−→
Kaminski, Katoen, Matheja, Olmedo
skip x := E C; C
if (ξ) {C} else {C}
{C} 2 {C}
while (ξ) {C}
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
3
Motivation
Probabilistic Programs
Syntax of Probabilistic Programs
C
−→
Kaminski, Katoen, Matheja, Olmedo
skip x := E C; C
if (ξ) {C} else {C}
{C} 2 {C}
while (ξ) {C}
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
3
Motivation
Probabilistic Programs
Syntax of Probabilistic Programs
C
−→
Kaminski, Katoen, Matheja, Olmedo
skip x := E C; C
if (ξ) {C} else {C}
{C} 2 {C}
while (ξ) {C}
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
3
Motivation
Probabilistic Programs
Syntax of Probabilistic Programs
C
−→
Kaminski, Katoen, Matheja, Olmedo
skip x := E C; C
if (ξ) {C} else {C}
{C} 2 {C}
while (ξ) {C}
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
3
Motivation
Probabilistic Programs
Syntax of Probabilistic Programs
C
−→
skip x := E C; C
if (ξ) {C} else {C}
{C} 2 {C}
while (ξ) {C}
What is probabilistic about that language?
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
3
Motivation
Probabilistic Programs
Syntax of Probabilistic Programs
C
−→
skip x := E C; C
if (ξ) {C} else {C}
{C} 2 {C}
while (ξ) {C}
What is probabilistic about that language?
Probabilistic guards ξ : Σ → D({true, false}):
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
3
Motivation
Probabilistic Programs
Syntax of Probabilistic Programs
C
−→
skip x := E C; C
if (ξ) {C} else {C}
{C} 2 {C}
while (ξ) {C}
What is probabilistic about that language?
Probabilistic guards ξ : Σ → D({true, false}):
Jξ : trueK(σ) = 1 − Jξ : falseK(σ) is the probability of ξ
evaluating to true
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
3
Motivation
Probabilistic Programs
Syntax of Probabilistic Programs
C
−→
skip x := E C; C
if (ξ) {C} else {C}
{C} 2 {C}
while (ξ) {C}
What is probabilistic about that language?
Probabilistic guards ξ : Σ → D({true, false}):
Jξ : trueK(σ) = 1 − Jξ : falseK(σ) is the probability of ξ
evaluating to true
E.g.
Kaminski, Katoen, Matheja, Olmedo
2
3 htruei
+ 13 hfalsei
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
3
Motivation
Probabilistic Programs
Syntax of Probabilistic Programs
C
−→
skip x := E C; C
if (ξ) {C} else {C}
{C} 2 {C}
while (ξ) {C}
What is probabilistic about that language?
Probabilistic guards ξ : Σ → D({true, false}):
Jξ : trueK(σ) = 1 − Jξ : falseK(σ) is the probability of ξ
evaluating to true
E.g.
Kaminski, Katoen, Matheja, Olmedo
2
3 htruei
+ 13 hfalsei,
1
2 hx
> yi + 12 hx ≥ yi
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
3
Motivation
Probabilistic Programs
Probabilistic Programs
What does a probabilistic program C do?
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
4
Motivation
Probabilistic Programs
Probabilistic Programs
What does a probabilistic program C do?
Run program C on initial state σ
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
4
Motivation
Probabilistic Programs
Probabilistic Programs
What does a probabilistic program C do?
Run program C on initial state σ
Obtain final set of
Kaminski, Katoen, Matheja, Olmedo
distributions µ over terminal states
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
4
Motivation
Probabilistic Programs
Probabilistic Programs
What does a probabilistic program C do?
Run program C on initial state σ
Obtain final set of (sub–)distributions µ over terminal states
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
4
Motivation
Probabilistic Programs
Probabilistic Programs
What does a probabilistic program C do?
Run program C on initial state σ
Obtain final set of (sub–)distributions µ over terminal states
What is the run–time of C on input σ?
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
4
Motivation
Probabilistic Programs
Probabilistic Programs
What does a probabilistic program C do?
Run program C on initial state σ
Obtain final set of (sub–)distributions µ over terminal states
What is the run–time of C on input σ?
Behavior of C not entirely determined by σ
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
4
Motivation
Probabilistic Programs
Probabilistic Programs
What does a probabilistic program C do?
Run program C on initial state σ
Obtain final set of (sub–)distributions µ over terminal states
What is the run–time of C on input σ?
Behavior of C not entirely determined by σ
Probabilistic nature of C influences its run–time
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
4
Motivation
Probabilistic Programs
Probabilistic Programs
What does a probabilistic program C do?
Run program C on initial state σ
Obtain final set of (sub–)distributions µ over terminal states
What is the run–time of C on input σ?
Behavior of C not entirely determined by σ
Probabilistic nature of C influences its run–time
Better Question:
What is the expected run–time (ERT) of C on input σ?
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
4
Motivation
Expected Run–Times
Expected Run–Time Phenomena
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
5
Motivation
Expected Run–Times
Expected Run–Time Phenomena
ERT of C can be finite even if C admits infinite computations
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
5
Motivation
Expected Run–Times
Expected Run–Time Phenomena
ERT of C can be finite even if C admits infinite computations
x := 1; while (1/2) {x := 2 · x}
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
5
c := coinExpected
flip(0.5)
Motivation
Run–Times
until (c=heads);
return n
Phenomena
ution
Expected Run–Time
ERT of C can be finite even if C admits infinite computations
utput
n
Program Runtime
Probability
1/2
1/4
1/8
1/16
1/32
2
Output
3
5
7
9
11
Run–Time
Average
x := 1; Runtime:
while (1/2) {x := 2 · x}
3·
1
2
+5·
1
4
+ · · · + (2n+1) ·
1
2n
+ ··· = 5
3
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
5
Motivation
Expected Run–Times
Expected Run–Time Phenomena
ERT of C can be finite even if C admits infinite computations
Positive almost–sure termination:
x := 1; while (1/2) {x := 2 · x}
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
5
Motivation
Expected Run–Times
Expected Run–Time Phenomena
ERT of C can be finite even if C admits infinite computations
Positive almost–sure termination:
ERT of C is finite
x := 1; while (1/2) {x := 2 · x}
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
5
Motivation
Expected Run–Times
Expected Run–Time Phenomena
ERT of C can be finite even if C admits infinite computations
Positive almost–sure termination:
ERT of C is finite
x := 1; while (1/2) {x := 2 · x};
while (x > 0) {x := x − 1}
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
5
Motivation
Expected Run–Times
Expected Run–Time Phenomena
ERT of C can be finite even if C admits infinite computations
Positive almost–sure termination:
ERT of C is finite
Positively almost–surely terminating programs are not closed
under sequential composition
x := 1; while (1/2) {x := 2 · x};
while (x > 0) {x := x − 1}
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
5
Motivation
Expected Run–Times
Expected Run–Time Phenomena
ERT of C can be finite even if C admits infinite computations
Positive almost–sure termination:
ERT of C is finite
Positively almost–surely terminating programs are not closed
under sequential composition
Reasoning about positive almost–sure termination is
computationally very difficult:
x := 1; while (1/2) {x := 2 · x};
while (x > 0) {x := x − 1}
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
5
Motivation
Expected Run–Times
Expected Run–Time Phenomena
ERT of C can be finite even if C admits infinite computations
Positive almost–sure termination:
ERT of C is finite
Positively almost–surely terminating programs are not closed
under sequential composition
Reasoning about positive almost–sure termination is
computationally very difficult:
Strictly more difficult than the termination problem for
non–probabilistic programs [MFCS 2015]
x := 1; while (1/2) {x := 2 · x};
while (x > 0) {x := x − 1}
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
5
Motivation
Expected Run–Times
Expected Run–Time Phenomena
ERT of C can be finite even if C admits infinite computations
Positive almost–sure termination:
ERT of C is finite
Positively almost–surely terminating programs are not closed
under sequential composition
Reasoning about positive almost–sure termination is
computationally very difficult:
Strictly more difficult than the termination problem for
non–probabilistic programs [MFCS 2015]
ERT of C can be infinite, even if C terminates almost–surely1
x := 1; while (1/2) {x := 2 · x};
while (x > 0) {x := x − 1}
1
i.e. with probability 1
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
5
Motivation
Expected Run–Times
Expected Run–Times
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
6
Motivation
Expected Run–Times
Expected Run–Times
ERT if C terminates almost–surely on σ:
∞
X
i=1
Kaminski, Katoen, Matheja, Olmedo
i · Pr
“C terminates after
i steps on input σ”
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
6
Motivation
Expected Run–Times
Expected Run–Times
ERT if C terminates almost–surely on σ:
∞
X
i=1
i · Pr
“C terminates after
i steps on input σ”
ERT if C does not terminate almost–surely on σ:
∞
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
6
Motivation
Expected Run–Times
Expected Run–Times
ERT if C terminates almost–surely on σ:
∞
X
i=1
i · Pr
“C terminates after
i steps on input σ”
ERT if C does not terminate almost–surely on σ:
∞
In general: ERT of C is a function
t : Σ → R∞
≥0
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
6
Motivation
Expected Run–Times
Expected Run–Times
ERT if C terminates almost–surely on σ:
∞
X
i=1
i · Pr
“C terminates after
i steps on input σ”
ERT if C does not terminate almost–surely on σ:
∞
In general: ERT of C is a function
t : Σ → R∞
≥0
Call such a t a run–time.
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
6
Motivation
Expected Run–Times
Expected Run–Times
ERT if C terminates almost–surely on σ:
∞
X
i=1
i · Pr
“C terminates after
i steps on input σ”
ERT if C does not terminate almost–surely on σ:
∞
In general: ERT of C is a function
t : Σ → R∞
≥0
Call such a t a run–time. Denote set of run–times by T.
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
6
Motivation
Expected Run–Times
Expected Run–Times
ERT if C terminates almost–surely on σ:
∞
X
i=1
i · Pr
“C terminates after
i steps on input σ”
ERT if C does not terminate almost–surely on σ:
∞
In general: ERT of C is a function
t : Σ → R∞
≥0
Call such a t a run–time. Denote set of run–times by T.
Complete partial order on T:
t1 t2
Kaminski, Katoen, Matheja, Olmedo
iff ∀ σ ∈ Σ : t1 (σ) ≤ t2 (σ)
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
6
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
7
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Use a continuation passing style ERT transformer ert[C] : T → T.
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
7
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Use a continuation passing style ERT transformer ert[C] : T → T.
C
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
7
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Use a continuation passing style ERT transformer ert[C] : T → T.
C
t
time needed
after executing C
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
7
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Use a continuation passing style ERT transformer ert[C] : T → T.
C
t
time needed
after executing C
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
7
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Use a continuation passing style ERT transformer ert[C] : T → T.
ert [C] (t)
expected time needed
before executing C
Kaminski, Katoen, Matheja, Olmedo
C
t
time needed
after executing C
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
7
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Use a continuation passing style ERT transformer ert[C] : T → T.
ert [C] (t)
expected time needed
before executing C
C
t
time needed
after executing C
ERT in Terms of ert
ert [C] (0) (σ) = “ERT of C on input σ”
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
7
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Rules for the ert Transformer
C
ert [C] (t)
skip
1+t
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
8
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Rules for the ert Transformer
C
ert [C] (t)
skip
1+t
x := E
1 + t [x/E]
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
8
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Rules for the ert Transformer
C
ert [C] (t)
skip
1+t
x := E
1 + t [x/E]
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
8
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Rules for the ert Transformer
C
ert [C] (t)
skip
1+t
x := E
1 + t [x/E]
C1 ; C2
ert [C1 ] (ert [C2 ] (t))
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
8
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Rules for the ert Transformer
C
ert [C] (t)
skip
1+t
x := E
1 + t [x/E]
C1 ; C2
ert [C1 ] (ert [C2 ] (t))
{C1 } 2 {C2 }
Kaminski, Katoen, Matheja, Olmedo
max{ert [C1 ] (t) , ert [C2 ] (t)}
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
8
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Rules for the ert Transformer
C
ert [C] (t)
skip
1+t
x := E
1 + t [x/E]
C1 ; C2
ert [C1 ] (ert [C2 ] (t))
{C1 } 2 {C2 }
max{ert [C1 ] (t) , ert [C2 ] (t)}
if (ξ) {C1 } else {C2 }
Kaminski, Katoen, Matheja, Olmedo
1 + Jξ : trueK · ert [C1 ] (t)
+ Jξ : falseK · ert [C2 ] (t)
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
8
Weakest Precondition Reasoning for Expected Run–Times
The ert Transformer
Rules for the ert Transformer
C
ert [C] (t)
skip
1+t
x := E
1 + t [x/E]
C1 ; C2
ert [C1 ] (ert [C2 ] (t))
{C1 } 2 {C2 }
max{ert [C1 ] (t) , ert [C2 ] (t)}
if (ξ) {C1 } else {C2 }
while (ξ) {C 0 }
Kaminski, Katoen, Matheja, Olmedo
1 + Jξ : trueK · ert [C1 ] (t)
+ Jξ : falseK · ert [C2 ] (t)
lfp X • 1 + Jξ : falseK · t
+ Jξ : trueK · ert [C 0 ] (X)
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
8
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Upper Bounds for ert of Loops
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
9
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Upper Bounds for ert of Loops
Recall the definition of ert [while (ξ) {C}] (t):
lfp X • 1 + Jξ : falseK · t + Jξ : trueK · ert [C] (X)
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
9
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Upper Bounds for ert of Loops
Recall the definition of ert [while (ξ) {C}] (t):
lfp X • 1 + Jξ : falseK · t + Jξ : trueK · ert [C] (X)
{z
}
|
=: F (X)
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
9
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Upper Bounds for ert of Loops
Recall the definition of ert [while (ξ) {C}] (t):
lfp X • 1 + Jξ : falseK · t + Jξ : trueK · ert [C] (X)
{z
}
|
=: F (X)
Theorem: Upper Bounds from Upper Invariants
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
9
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Upper Bounds for ert of Loops
Recall the definition of ert [while (ξ) {C}] (t):
lfp X • 1 + Jξ : falseK · t + Jξ : trueK · ert [C] (X)
{z
}
|
=: F (X)
Theorem: Upper Bounds from Upper Invariants
If I ∈ T is an upper invariant of while (ξ) {C}, i.e. if
F (I) I
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
9
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Upper Bounds for ert of Loops
Recall the definition of ert [while (ξ) {C}] (t):
lfp X • 1 + Jξ : falseK · t + Jξ : trueK · ert [C] (X)
{z
}
|
=: F (X)
Theorem: Upper Bounds from Upper Invariants
If I ∈ T is an upper invariant of while (ξ) {C}, i.e. if
then
F (I) I
ert [while (ξ) {C}] (t) I .
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
9
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Lower Bounds for ert of Loops
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
10
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Lower Bounds for ert of Loops
Reasoning on lower bounds is more involved:
Find an argument for being below a least fixed point
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
10
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Lower Bounds for ert of Loops
Reasoning on lower bounds is more involved:
Find an argument for being below a least fixed point
Theorem: Lower Bounds from Lower ω–Invariants
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
10
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Lower Bounds for ert of Loops
Reasoning on lower bounds is more involved:
Find an argument for being below a least fixed point
Theorem: Lower Bounds from Lower ω–Invariants
If {In }n∈N ⊆ T is a lower ω–invariant, i.e. if
I0 F (0),
and
In+1 F (In )
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
10
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Lower Bounds for ert of Loops
Reasoning on lower bounds is more involved:
Find an argument for being below a least fixed point
Theorem: Lower Bounds from Lower ω–Invariants
If {In }n∈N ⊆ T is a lower ω–invariant, i.e. if
I0 F (0),
and
In+1 F (In )
then
sup In ert [while (ξ) {C}] (t) .
n∈N
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
10
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Theorem: Completeness of Proof Rules
The presented proof rules are complete
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
11
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Theorem: Completeness of Proof Rules
The presented proof rules are complete, since I = lfp F is an upper
invariant
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
11
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Theorem: Completeness of Proof Rules
The presented proof rules are complete, since I = lfp F is an upper
invariant and a lower ω–invariant is given by
In = F
· · ◦ F}(0) .
| ◦ ·{z
n times
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
11
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Theorem: Completeness of Proof Rules
The presented proof rules are complete, since I = lfp F is an upper
invariant and a lower ω–invariant is given by
In = F
· · ◦ F}(0) .
| ◦ ·{z
n times
Theorem: Bound Refinement
If I is an upper bound and F (I) I, then F (I) is also an upper
bound.
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
11
Weakest Precondition Reasoning for Expected Run–Times
Reasoning about ert
Theorem: Completeness of Proof Rules
The presented proof rules are complete, since I = lfp F is an upper
invariant and a lower ω–invariant is given by
In = F
· · ◦ F}(0) .
| ◦ ·{z
n times
Theorem: Bound Refinement
If I is an upper bound and F (I) I, then F (I) is also an upper
bound. Dually for lower bounds.
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
11
Weakest Precondition Reasoning for Expected Run–Times
Correspondence to Other Run–Time Models
Is the ert Calculus a Reasonable Run–Time Model?
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
12
Weakest Precondition Reasoning for Expected Run–Times
Correspondence to Other Run–Time Models
Is the ert Calculus a Reasonable Run–Time Model?
Correspondence to an operational semantics:
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
12
Weakest Precondition Reasoning for Expected Run–Times
Correspondence to Other Run–Time Models
Is the ert Calculus a Reasonable Run–Time Model?
Correspondence to an operational semantics:
Operational model defined in terms of a reward MDP à la
[QEST 2012] and [MFPS 2015]
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
12
Weakest Precondition Reasoning for Expected Run–Times
Correspondence to Other Run–Time Models
Is the ert Calculus a Reasonable Run–Time Model?
Correspondence to an operational semantics:
Operational model defined in terms of a reward MDP à la
[QEST 2012] and [MFPS 2015]
ert coincides with expected reward in the operational MDP
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
12
Weakest Precondition Reasoning for Expected Run–Times
Correspondence to Other Run–Time Models
Is the ert Calculus a Reasonable Run–Time Model?
Correspondence to an operational semantics:
Operational model defined in terms of a reward MDP à la
[QEST 2012] and [MFPS 2015]
ert coincides with expected reward in the operational MDP
Enables bounded model checking of expected run–times
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
12
Weakest Precondition Reasoning for Expected Run–Times
Correspondence to Other Run–Time Models
Is the ert Calculus a Reasonable Run–Time Model?
Correspondence to an operational semantics:
Operational model defined in terms of a reward MDP à la
[QEST 2012] and [MFPS 2015]
ert coincides with expected reward in the operational MDP
Enables bounded model checking of expected run–times
Nielson’s Hoare–style logic for reasoning about run–time
orders of magnitude of deterministic programs:
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
12
Weakest Precondition Reasoning for Expected Run–Times
Correspondence to Other Run–Time Models
Is the ert Calculus a Reasonable Run–Time Model?
Correspondence to an operational semantics:
Operational model defined in terms of a reward MDP à la
[QEST 2012] and [MFPS 2015]
ert coincides with expected reward in the operational MDP
Enables bounded model checking of expected run–times
Nielson’s Hoare–style logic for reasoning about run–time
orders of magnitude of deterministic programs:
Nielson’s logic relies on introducing additional logical variables
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
12
Weakest Precondition Reasoning for Expected Run–Times
Correspondence to Other Run–Time Models
Is the ert Calculus a Reasonable Run–Time Model?
Correspondence to an operational semantics:
Operational model defined in terms of a reward MDP à la
[QEST 2012] and [MFPS 2015]
ert coincides with expected reward in the operational MDP
Enables bounded model checking of expected run–times
Nielson’s Hoare–style logic for reasoning about run–time
orders of magnitude of deterministic programs:
Nielson’s logic relies on introducing additional logical variables
ert is sound and complete with respect to Nielson’s logic
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
12
Weakest Precondition Reasoning for Expected Run–Times
Correspondence to Other Run–Time Models
Is the ert Calculus a Reasonable Run–Time Model?
Correspondence to an operational semantics:
Operational model defined in terms of a reward MDP à la
[QEST 2012] and [MFPS 2015]
ert coincides with expected reward in the operational MDP
Enables bounded model checking of expected run–times
Nielson’s Hoare–style logic for reasoning about run–time
orders of magnitude of deterministic programs:
Nielson’s logic relies on introducing additional logical variables
ert is sound and complete with respect to Nielson’s logic
ert calculus is arguably easier to apply — no additional
variables!
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
12
Weakest Precondition Reasoning for Expected Run–Times
Case Study
Case Study: The Coupon Collector’s Problem
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
13
Weakest Precondition Reasoning for Expected Run–Times
Case Study
Case Study: The Coupon Collector’s Problem
The coupon collector is a well–known problem
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
13
Weakest Precondition Reasoning for Expected Run–Times
Case Study
Case Study: The Coupon Collector’s Problem
The coupon collector is a well–known problem
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
13
Weakest Precondition Reasoning for Expected Run–Times
Case Study
Case Study: The Coupon Collector’s Problem
The coupon collector is a well–known problem
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
13
Weakest Precondition Reasoning for Expected Run–Times
Case Study
Case Study: The Coupon Collector’s Problem
The coupon collector is a well–known problem
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
13
Weakest Precondition Reasoning for Expected Run–Times
Case Study
Case Study: The Coupon Collector’s Problem
The coupon collector is a well–known problem
We model it by the following algorithm:
cp := [0, . . . , 0]; i := 1; x := N ;
while (x > 0) {
while (cp[i] 6= 0) { i :≈ Unif[1 . . . N ] };
cp[i] := 1; x := x − 1 }
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
13
Weakest Precondition Reasoning for Expected Run–Times
Case Study
Case Study: The Coupon Collector’s Problem
The coupon collector is a well–known problem
We model it by the following algorithm:
cp := [0, . . . , 0]; i := 1; x := N ;
while (x > 0) {
while (cp[i] 6= 0) { i :≈ Unif[1 . . . N ] };
cp[i] := 1; x := x − 1 }
Using ert, we can analyze the ERT of the above algorithm
directly on the source code given above:
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
13
Weakest Precondition Reasoning for Expected Run–Times
Case Study
Case Study: The Coupon Collector’s Problem
The coupon collector is a well–known problem
We model it by the following algorithm:
cp := [0, . . . , 0]; i := 1; x := N ;
while (x > 0) {
while (cp[i] 6= 0) { i :≈ Unif[1 . . . N ] };
cp[i] := 1; x := x − 1 }
Using ert, we can analyze the ERT of the above algorithm
directly on the source code given above:
ert [coup. coll .] (0) = 4 + [N > 0] · 2N · (2 + HN −1 )
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
13
Weakest Precondition Reasoning for Expected Run–Times
Case Study
Case Study: The Coupon Collector’s Problem
The coupon collector is a well–known problem
We model it by the following algorithm:
cp := [0, . . . , 0]; i := 1; x := N ;
while (x > 0) {
while (cp[i] 6= 0) { i :≈ Unif[1 . . . N ] };
cp[i] := 1; x := x − 1 }
Using ert, we can analyze the ERT of the above algorithm
directly on the source code given above:
ert [coup. coll .] (0) = 4 + [N > 0] · 2N · (2 + HN −1 )
Harmonic number HN −1 is in Θ(log N )
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
13
Weakest Precondition Reasoning for Expected Run–Times
Case Study
Case Study: The Coupon Collector’s Problem
The coupon collector is a well–known problem
We model it by the following algorithm:
cp := [0, . . . , 0]; i := 1; x := N ;
while (x > 0) {
while (cp[i] 6= 0) { i :≈ Unif[1 . . . N ] };
cp[i] := 1; x := x − 1 }
Using ert, we can analyze the ERT of the above algorithm
directly on the source code given above:
ert [coup. coll .] (0) = 4 + [N > 0] · 2N · (2 + HN −1 )
Harmonic number HN −1 is in Θ(log N )
Coupon collector program runs in Θ(N · log N ) for N > 0
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
13
Het Einde
Summary
Summary
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
14
Het Einde
Summary
Summary
ert is an easy to understand weakest–precondition–style
calculus for reasoning about ERT of probabilistic programs
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
14
Het Einde
Summary
Summary
ert is an easy to understand weakest–precondition–style
calculus for reasoning about ERT of probabilistic programs
ert is sound and complete for reasoning about expected
run–times and positive almost–sure termination
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
14
Het Einde
Summary
Summary
ert is an easy to understand weakest–precondition–style
calculus for reasoning about ERT of probabilistic programs
ert is sound and complete for reasoning about expected
run–times and positive almost–sure termination
ert comes with proof rules for reasoning about loops
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
14
Het Einde
Summary
Summary
ert is an easy to understand weakest–precondition–style
calculus for reasoning about ERT of probabilistic programs
ert is sound and complete for reasoning about expected
run–times and positive almost–sure termination
ert comes with proof rules for reasoning about loops
ert is a powerful alternative to ranking super–martingales
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
14
Het Einde
Summary
Summary
ert is an easy to understand weakest–precondition–style
calculus for reasoning about ERT of probabilistic programs
ert is sound and complete for reasoning about expected
run–times and positive almost–sure termination
ert comes with proof rules for reasoning about loops
ert is a powerful alternative to ranking super–martingales
ert is applicable to tricky real–world examples which are
difficult to reason about by formal verification techniques
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
14
Het Einde
Summary
Summary
ert is an easy to understand weakest–precondition–style
calculus for reasoning about ERT of probabilistic programs
ert is sound and complete for reasoning about expected
run–times and positive almost–sure termination
ert comes with proof rules for reasoning about loops
ert is a powerful alternative to ranking super–martingales
ert is applicable to tricky real–world examples which are
difficult to reason about by formal verification techniques
Tobias Nipkow
Markus Wenzel
Lawrence C. Paulson
le
el
ab = ∀
HO
L
Is
λ
β
α
→
ert is Isabelle/HOL certified (courtesy of Johannes Hölzl, TUM)
A Proof Assistant for
Higher-Order Logic
February 17, 2016
Springer-Verlag
Berlin Heidelberg NewYork
London Paris Tokyo
Hong Kong Barcelona
Budapest
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
14
Het Einde
Summary
Summary
ert is an easy to understand weakest–precondition–style
calculus for reasoning about ERT of probabilistic programs
ert is sound and complete for reasoning about expected
run–times and positive almost–sure termination
ert comes with proof rules for reasoning about loops
ert is a powerful alternative to ranking super–martingales
ert is applicable to tricky real–world examples which are
difficult to reason about by formal verification techniques
Tobias Nipkow
Markus Wenzel
Lawrence C. Paulson
le
el
ab = ∀
HO
L
Is
λ
β
α
→
ert is Isabelle/HOL certified (courtesy of Johannes Hölzl, TUM)
A Proof Assistant for
Higher-Order Logic
Future work: recursion, conditioning, run–time variance
February 17, 2016
Springer-Verlag
Berlin Heidelberg NewYork
London Paris Tokyo
Hong Kong Barcelona
Budapest
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
14
Het Einde
Summary
Summary
ert is an easy to understand weakest–precondition–style
calculus for reasoning about ERT of probabilistic programs
ert is sound and complete for reasoning about expected
run–times and positive almost–sure termination
ert comes with proof rules for reasoning about loops
ert is a powerful alternative to ranking super–martingales
ert is applicable to tricky real–world examples which are
difficult to reason about by formal verification techniques
Tobias Nipkow
Markus Wenzel
Lawrence C. Paulson
le
el
ab = ∀
HO
L
Is
λ
β
α
→
ert is Isabelle/HOL certified (courtesy of Johannes Hölzl, TUM)
A Proof Assistant for
Higher-Order Logic
Future work: recursion, conditioning, run–time variance
February 17, 2016
Springer-Verlag
Berlin Heidelberg NewYork
London Paris Tokyo
Hong Kong Barcelona
Budapest
Thank you for your kind attention!
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
14
Het Einde
Summary
Backup Slides: The Actual Rule for Assignments
C
ert [C] (t)
x :≈ µ
1 + λσ • EJµK(σ) (λv. t [x/v] (σ))
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
15
Het Einde
Summary
Backup Slides: ert Calculations and Proof Rule Application
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
16
Het Einde
Summary
Backup Slides: Operational RMDP
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
17
Het Einde
Summary
∞
Backup Slides: Park’s Lemma
gfp F
•
•
•
•
•
•
lfp F
0
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
18
Het Einde
Summary
∞
Backup Slides: Park’s Lemma
gfp F
•
•
•
•
•
•
lfp F
I
0
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
18
Het Einde
Summary
∞
Backup Slides: Park’s Lemma
gfp F
•
•
•
•
•
•
lfp F
≤
F (I)
I
0
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
18
Het Einde
Summary
∞
Backup Slides: Park’s Lemma
F (I) ≤ I
implies
lfp F ≤ I
gfp F
•
•
•
•
•
•
lfp F
≤
F (I)
I
0
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
18
Het Einde
Summary
∞
Backup Slides: Park’s Lemma
F (I) ≤ I
implies
lfp F ≤ I
gfp F
I
•
•
•
•
•
•
lfp F
≤
F (I)
I
0
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
18
Het Einde
Summary
∞
Backup Slides: Park’s Lemma
F (I) ≤ I
implies
lfp F ≤ I
gfp F
•
•
•
•
•
•
≤
I
F (I)
lfp F
≤
F (I)
I
0
Kaminski, Katoen, Matheja, Olmedo
Weakest Precondition Reasoning for Expected Run–Times
4.4.2016
18