Model-Checking SS 2012 | ||
News | Basic information | Content | Exercises | Slides | Links |
Note: This is an archvied version of our old webpage. Some links might be broken. The current one can be found here.
Exercise 1: April 18 (discussion on April 20)
- Recap of logic. Read Tom Henzinger's "How To Write a Proof" and Sections 1.1 - 1.6 in this book (PDF).
- Prove or give a counterexample: ((∀ y: P(y)) ∨ (∀ z: Q(z))) → (∀ x: P(x) ∨ Q(x)).
- Prove or give a counterexample: (∀ x: P(x) ∨ Q(x)) → ((∀ y: P(y)) ∨ (∀ z: Q(z))).
Exercise 2: April 24 (discussion on April 27)
-
Prove the following equivalence:
∀ V ∀ V' : H(V) ∧ R(V, V') → H(V')
if and only if
for all s and for all s' holds if s ⊧ H(V) and (s, s') ⊧ R(V, V') then s' ⊧ H(V) -
Prove that if a program is safe then there exists H(V) (in an
expressive assertion language) such that
∀ V: φinit(V) → H(V)
∀ V ∀ V' : H(V) ∧ R(V, V') → H(V')
∀ V: H(V) ∧ φerror(V) → ⊥ -
Prove that if a program terminates then there exists H(V), a well-founded
set (W, ≺), and a function r : States → W such that
∀ V: φinit(V) → H(V)
∀ V ∀ V' : H(V) ∧ R(V, V') → H(V') ∧ r(V) ≻ r(V')
Exercise 3: May 2 (discussion on May 4)
Basic Reachability Algorithm:- Study the termination proof for the Basic Reachability Algorithm (BRA) (see PDF).
- Prove that upon termination of BRA, if a node n is reachable from the initial node n0 via the set of edges E, i.e., (n0, n) ∈ E*, then n ∈ C.
-
Extend the BRA algorithm to detect the existence of cycles in a
given finite graph. The extended algorithm returns
true
iff there exists n ∈ N such that (n0, n) ∈ E* and (n, n) ∈ E+.
- Study the definition and examples of the post operator, see PDF.
- Give a program P that contains a single transition such that the reachability compuation using post diverges for P.
-
Install OCaml.
On Linux:
sudo apt-get install ocaml
. On OSX with ports:sudo port install ocaml
. -
Install git.
On Linux:
sudo apt-get install git
. On OSX with ports:sudo port install git
. -
Create a working directory:
cd mkdir mc2012
-
Install CIL from
github:
cd mc2012 git clone https://github.com/kerneis/cil.git cd cil ./configure make cd ..
Executepwd
and remember the output string. You will need this string in Step 6. -
Download the CFG bundle
and save it in the directory
mc2012
, e.g., by executingwget http://archive.model.in.tum.de/um/courses/mc/ss2012/cfg.tgz
Unpack the bundle using commandtar xzf cfg.tgz
. You should obtain a directorymc2012/cfg
. Change the working directory tomc2012/cfg
by executingcd cfg
. -
Edit
config.make
: i) uncommend a line with your OS, ii) adjust the variableCIL
such that it is assigned the directory obtained by runningpwd
in Step 3. -
Execute
make
-
Execute
src/main.native test/mytest.c > cfg.dot cat cfg.dot
-
Install a dot file viewer from Graphviz and use it
to visualize the content of
cfg.dot
. Discover a correspondance between the control-flow graph incfg.dot
and the source code oftest/mytest.c
.
Exercise 4: May 9 (discussion on May 11)
- Below we show a modified version of BRA together
with a cycle detection algortihm, which uses BRA.
Implement the presented cycle detection algorithm in Ocaml.
algorithm BRA input N : set of nodes n0 : start node, where n0 \in N E : set of edges, where E \subseteq N \times N var C : nodes reached so far done : Boolean flag D : auxiliary set of nodes begin C := {n0} done := false while \neg done do D := { d \in N | \exists c \in C: (c, d) \in E } if \neg (D \subseteq C) then C := C \cup D else done := true od return (C, D) end algorthm detect_cycle input N : set of nodes n0 : start node, where n0 \in N E : set of edges, where E \subseteq N \times N begin (C, D) := BRA (N, N0, Edges) foreach s in C (Cs,Ds) := BRA (N, s, Edges) if (s \in Ds) then return true return false end
- Let R be a transition relation over V and V'. We define post(φ) = ∃ V" : φ[V"/V] ∧ R[V"/V][V/V']. Prove (∨ i>= 0 post # i (φinit)) ⊧ (∨ j>= 0 post # j (α (φinit))).
- Prove:
- ∀ φ : φ ⊧ α (φ).
- α is monotonic, i.e., ∀ φ ∀ ψ : (φ ⊧ ψ) → (α (φ) ⊧ α (ψ)).
- ∀ φ ∀ R1 ∀ R2 : post(φ, R1 ∨ R2) iff ∀ φ ∀ R1 ∀ R2 : (post(φ, R1) ∨ post(φ, R2)).
- Give an inductive invariant that proves safety for each of the
following programs.
-
main(int x, int y) { assume(x == 0); if(y >= 0) y++; else y=1; assert(y > x); }
-
main(int n) { int i, j; assume(n >= 0); i = 0; j = n; while(i < j) { i++; j--; } assert(i+j == n); }
-
main(int n) { int i; int j; bool inc; i = 0; j = n; inc = false; while(i < n) { if(not inc) { j++; inc = true; } else { j--; inc = false; } i++; } assert(j =< n+1); }
-
- Install SICStus prolog, and implement the "hello world" program and a binary search program for ordered lists. A good reference can be the SICStus prolog user manual. Some of the main prolog constructs that will be used in the course will be discussed in the tutorial.
Exercise 5: May 16 (discussion on May 18)
- We define a constraint C1 over ϕ1,
ϕ2, and ϕ3 as follows.
C1(ϕ1, ϕ2, ϕ3) ≡
ϕ init ⊧ ϕ1 ∧
post(ϕ1, ρ1) ⊧ ϕ2 ∧
post(ϕ2, ρ2) ⊧ ϕ3 ∧
ϕ3 ∧ ϕerr ⊧ false
Prove that for each ϕ1, ϕ2, and ϕ3 if C1(ϕ1, ϕ2, ϕ3) then ϕ init ∧ (ρ1 o ρ2) ∧ ϕerr[V"/V] ⊧ false. -
We define a constraint C1 over ϕ1 and
ϕ2 as follows.
C2(ϕ1, ϕ1) ≡
ϕ init ⊧ ϕ1 ∧
post(ϕ1, ρ1) ⊧ ϕ2 ∧
post(ϕ2, ρ2) ∧ ϕerr ⊧ false
Prove that C1 is satisfiable if and only if C2 is satisfiable, where C1 is defined in the previous question. - Prove that post(post(ϕ, ρ1), ρ2) is equivalent to post(ϕ, ρ1 o ρ2)
Exercise 6: May 23 (discussion on May 25)
-
Compute interpolants for:
- x < 5, y ≤ x and y ≥ 10
- x < 5 and x ≥ y, y ≥ 10
- x+1 ≤ z and x ≥ y, y ≥ z
- Prove that our interpolation algorithm respects the condition imposed on the variables that occur in the computed interpolant.
- Prove that if Ax ≤ a ∧ Bx ≤ b ⊧ false then there exists ix ≤ i0 that is an interpolant.
- Represent inference rules describing summarization as entailments.
- Compute summaries for the following program:
f() { if (*) f(); } main() { assume(*); f(); assert(*); }
The prolog implementations of abstract and abstract_Reachability
Exercise 7: June 05 (discussion on June 08)
- For the program producer-consumer with semaphores, prove the stability of the inductive invariant given in class under transitions PW→PM and CI→CL.
- Consider the Dijkstra's two-threaded algorithm. Prove or refute that the inductive invariant given in class is the strongest one, i.e. that every invariant that implies the given one is already equivalent to the given one.
- The following mutual exclusion algorithm for 2 threads is suggested:
Initially turn∈{1,2}∧Q1=Q2=0
.// Thread 1 // Thread 2 while(true) {
// noncritical section
A: Q1:=true
B: turn:=1
C: await ¬Q2 ∨ turn=2
// critical section
D: Q1:=false
// nocritical section
}while(true) {
// noncritical section
A: Q2:=true
B: turn:=2
C: await ¬Q1 ∨ turn=1
// critical section
D: Q2:=false
// noncritical section
}D
. You may assume that the threads start at locationsA
and the transitions between each pair of labels is atomic.
Exercise 8: June 12 (discussion on June 15)
- In class a formula I for the Szymanski's mutual exclusion protocol was given.
- Prove that I is stable under each transition at locations l5 till l12 of each thread.
- Show that I implies the mutual exclusion property, namely, that ∀ i,j∈Tid: li=10=lj⇒i=j.
- Assume that the transition at location l11 is replaced by a no-operation (which changes just the program counter of the executing thread, while the remaining variables retain their values). Is the mutual exclusion property still satisfied?
- (An optional task with an increased difficulty level.) Let
(L, ≤) be a complete lattice (i.e. a partial order in which
for every set A ⊆ L, the least upper bound sup A and the greatest lower bound inf A exist). Let f:L→L.
- If f is monotone, then the least fixpoint of f, written lfp(f), exists and is equal to inf {x∈L | f(x)=x} = inf {x∈L | f(x)≤x }.
- If for all nonempty chains C ⊆ L we have sup f(C) = f (sup C), then lfp(f) = sup {fi(inf L)|i∈N0}.
Exercise 9: June 20 (discussion on June 22)
-
Infer the type in the empty typing environment:
let fun f x y = if x > y then true else false in f 0 end
-
Which typing environment is obtained by typing the following
declarations in the empty typing environment:
-
val t = 3
-
fun fib n = if n < 3 then 1 else fib (n-1) + fib(n-2)
-
fun square r = let fun exp y x = if y = 0 then 1 else if y < 0 then 0 else x * (exp (y-1) x) in exp 2 r end
-
-
Which sequence of value environments is obtained by evaluating the
following program?
fun f x = if x then 1 else 0; val x = 5*7; fun g z = f (z < x) < x; val x = g 5; val k = let fun h x = x * x in h end;
-
Evaluate the following expression:
let fun square r = let fun exp y x = if y = 0 then 1 else if y < 0 then 0 else x * (exp (y-1) x) in exp 2 r end in square 5 end
-
Formalize as a refinement type:
the value of
x
is a negative integer that is greater then the sum of values ofy
andz
. -
Formalize as a refinement type:
the value of
f
is a function that takes as input a positive integer and returns the doubled value.
Exercise 10: June 27 (discussion on June 29)
- Provide refinement type derivation for the following functions (as shown on Slides 16.4 and 16.5).
- The fibonacci sequence:
fun fib n = if n < 3 then 1 else let val m = fib (n - 1) in m + fib(n - 2)
- The maximum of two numbers:
fun max x y = if x > y then x else y
- Factorial of an integer n:
fun fact n = if n < 1 then 1 else let val m = fact (n - 1) in n * m
- The fibonacci sequence:
- LTL. If the webpage does not display properly in your browser, we have prepared a PDF file for you. Do not be intimidated by the number of tasks: with a single exception, each task is trivial.
- Let AP = {green, yellow, red} and σ = ({green}{green}{green}{yellow}{red}{red}{red}{yellow,red})ω. Does σ satisfy the following properties:
- green ∨ yellow ,
- ¬greenUred ,
- ¬(greenUred) ?
- Let AP = {green, yellow, red}. Write the following properties as LTL formulas (derived operators are allowed):
- Red and yellow occur together infinitely often.
- From some time point onward red and green never occur together.
- Whenever green turns on, green continues for at least two consecutive time units.
- Consider a program P with State={s0, s1, s2}, init={s0}, transitions s1→s0→s2→s1. Let AP={a,b}. Let a label just s1 and b label just s2. Which of the following formulas hold for P?
- a ∧ b ,
- (a∧b) ,
- a U ¬(a∧b) ,
- b .
- Let AP be a set of atomic propositions and φ,ψ be LTL formulas over AP. Show the following properties about distributivity, negation propagation, and expansion of temporal connectives:
- (φ∧ψ) ≡ φ∧ψ ,
- (φUψ) ≡ φUψ ,
- ¬φ ≡ ¬φ ,
- ¬(φUψ) ≡ ¬φR¬ψ ,
- ¬(φWψ) ≡ (φ∧¬ψ)U(¬φ∧¬ψ) ,
- ¬(φRψ) ≡ ¬φU¬ψ ,
- φUψ ≡ ψ∨(φ∧(φUψ)) ,
- φWψ ≡ ψ∨(φ∧(φWψ)) .
- Let AP={green, yellow, red}. Convert the following formulas into positive LTL:
- ¬((yellowUgreen)Ured) ,
- ¬(greenW(redUgreen)) ,
- ¬((yellowUgreen)R(redUgreen)) .
- (A task with an increased level of difficulty, **.) Show that weak until is "the greatest solution of the expansion law". More formally, show that for all LTL formulas φ,ψ over a set of atomic propositions AP,
- Words(φWψ) is a fixpoint of the map λ S∈℘(ℕ0→℘(AP)). Words(ψ) ∪ {σ∈Words(φ) | σ[1..]∈S}
- and that it is the greatest of all such fixpoints.
- Let AP = {green, yellow, red} and σ = ({green}{green}{green}{yellow}{red}{red}{red}{yellow,red})ω. Does σ satisfy the following properties:
Exercise 11: July 2 (discussion on July 6)
A monotone Galois connection (in program analysis shortened to just Galois connection) between posets (X,≤1), (Z,≤2) is a pair of maps (α,γ) where α: X→Z, γ: Z→X and
Show that the multithreaded Cartesian abstraction and the multithreaded Cartesian concretization (αmc,γmc) form a Galois connection between D, equipped with the inclusion order, and D#, equipped with the componentwise inclusion order.
∀ x∈X, z∈Z: α(x)≤2z ⇔ x≤1γ(z).
Consider a multithreaded program with the set of shared states Shared
and the sets of local states Localt (t∈Tid). Let D = ℘(State) and
D# = ∏t∈Tid
℘(Shared×Localt).
Show that the multithreaded Cartesian abstraction and the multithreaded Cartesian concretization (αmc,γmc) form a Galois connection between D, equipped with the inclusion order, and D#, equipped with the componentwise inclusion order.
Remark. One can show that for a monotone Galois connection (α,γ) the maps α and γ are indeed monotone. In
algebra and in lattice theory, the term
Galois connectionrefers to a pair of maps that satisfy a different property that ensures that the maps are antitone (a map f is antitone if whenever x is less than or equal to z, f(x)is greater than or equal to f(z)). Thus, when communicating to mathematicians, make sure you agree on terminology.