CSE507
Emina Torlak
emina@cs.washington.educourses.cs.washington.edu/courses/cse507/14au/
Computer-Aided Reasoning for Software
Finite Model Finding
CSE507 Computer-Aided Reasoning for Software Finite Model Finding - - PowerPoint PPT Presentation
CSE507 Computer-Aided Reasoning for Software Finite Model Finding courses.cs.washington.edu/courses/cse507/14au/ Emina Torlak emina@cs.washington.edu Today 2 Today Last lecture The DPPL(T) framework for deciding quantifier-free SMT
Emina Torlak
emina@cs.washington.educourses.cs.washington.edu/courses/cse507/14au/
Computer-Aided Reasoning for Software
Finite Model Finding
Today
2Today
2Last lecture
Today
2Last lecture
Today
Today
2Last lecture
Today
Announcements
a finite universe U finite model finder
Finite model finding
3⋀ ¬ ∨ ∀ ∃ x f(a) p(y, z) a formula F in FOL
if one exists
core (or “unsat”)
a finite universe U finite model finder
Finite model finding
3⋀ ¬ ∨ ∀ ∃ x f(a) p(y, z) a formula F in FOL
if one exists
core (or “unsat”)
(SEM, CVC4)
(Paradox, Kodkod)
Some applications of finite model finding
4Proving theorems in finite algebras (Finder, SEM, MACE)
Some applications of finite model finding
4Proving theorems in finite algebras (Finder, SEM, MACE) Checking lightweight formal specifications (Alloy, ProB, ExUML)
Some applications of finite model finding
4Proving theorems in finite algebras (Finder, SEM, MACE) Checking lightweight formal specifications (Alloy, ProB, ExUML) Counterexamples to tentative theorems in interactive proof assistants (Nitpick/Isabelle)
Some applications of finite model finding
4Proving theorems in finite algebras (Finder, SEM, MACE) Checking lightweight formal specifications (Alloy, ProB, ExUML) Bounded verification of code and memory models (Forge, Miniatur, TACO, MemSAT) Counterexamples to tentative theorems in interactive proof assistants (Nitpick/Isabelle)
MemSAT
Some applications of finite model finding
4Proving theorems in finite algebras (Finder, SEM, MACE) Checking lightweight formal specifications (Alloy, ProB, ExUML) Bounded verification of code and memory models (Forge, Miniatur, TACO, MemSAT) Counterexamples to tentative theorems in interactive proof assistants (Nitpick/Isabelle) Declarative configuration and execution (ConfigAssure, Margrave, Squander, PBnJ)
MemSAT
SQUANDER
Some applications of finite model finding
4Checking lightweight formal specifications (Alloy, ProB, ExUML) Bounded verification of code and memory models (Forge, Miniatur, TACO, MemSAT) Counterexamples to tentative theorems in interactive proof assistants (Nitpick/Isabelle) Declarative configuration and execution (ConfigAssure, Margrave, Squander, PBnJ) KODKOD
Overview of Kodkod
5formula in relational logic (FOL, relations, bit vectors, transitive closure) bounds (partial model and types) translator symmetry breaker SAT solver core extractor finite universe model minimal unsat core
Overview of Kodkod
5formula in relational logic (FOL, relations, bit vectors, transitive closure) bounds (partial model and types) translator finite universe
Relational logic by example
6a minimalistic formal specification
Relational logic by example
6Root ⊆ Dir
hierarchy is a directory.
Relational logic by example
6Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir)
hierarchy is a directory.
files or directories.
Relational logic by example
6Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents
hierarchy is a directory.
files or directories.
reachable from the root.
Relational logic by example
6Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents)
hierarchy is a directory.
files or directories.
reachable from the root.
acyclic.
Bounded relational logic by example
7Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2}
Finite universe of interpretation.
Bounded relational logic by example
7Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2}
Finite universe of interpretation. Bounds for each relation:
(partial model).
Bounded relational logic by example
7Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2} R D1 F1 F2 contents Root File Dir
Translation by example
8Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2}
Translation by example
8Encode
matrices
matrix operations
matrix entries
Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2}
Relational constants as boolean matrices
9Relational constants as boolean matrices
91 {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} R D1 D2 F1 F2
Relational constants as boolean matrices
9d0 d1 d2 1 {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} R D1 D2 F1 F2
Relational constants as boolean matrices
9f0 f1 d0 d1 d2 1 {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} R D1 D2 F1 F2
Relational constants as boolean matrices
9f0 f1 d0 d1 d2 1 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2} R D1 D2 F1 F2 R D1 D2 F1 F2
Relational expressions as matrix operations
10f0 f1 d0 d1 d2 d0 d1 d2 f0 f1 File Dir File ∪ Dir ∨ = Dir d0 d1 d2 d0 d1 d2 f0 f1 File ∪ Dir × = d0∧d0 d0∧d1 d0∧d2 d0∧f0 d0∧f1 d1∧d0 d1∧d1 d1∧d2 d1∧f0 d1∧f1 d2∧d0 d2∧d1 d2∧d2 d2∧f0 d2∧f1 Dir × (File ∪ Dir)
d0∧d0 d0∧d1 d0∧d2 d0∧f0 d0∧f1 d1∧d0 d1∧d1 d1∧d2 d1∧f0 d1∧f1 d2∧d0 d2∧d1 d2∧d2 d2∧f0 d2∧f1
Formulas as constraints over matrix entries
11c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 contents ⇒ = contents ⊆ Dir × (File ∪ Dir) Dir × (File ∪ Dir) (c0 ⇒ d0∧d0) ∧ (c1 ⇒ d0∧d1) ∧ (c2 ⇒ d0∧d2) ∧ (c3 ⇒ d0∧f0) ∧ (c4 ⇒ d0∧f1) ∧ (c5 ⇒ d1∧d0) ∧ … (c14 ⇒ d2∧f1)
Dealing with sparseness and redundancy
12Dir × (File ∪ Dir) d0∧d0 d0∧d1 d0∧d2 d0∧f0 d0∧f1 d1∧d0 d1∧d1 d1∧d2 d1∧f0 d1∧f1 d2∧d0 d2∧d1 d2∧d2 d2∧f0 d2∧f1
Dealing with sparseness and redundancy
12Dir × (File ∪ Dir)
Empty regions in matrices (exponential w.r.t. relation arity).
d0∧d0 d0∧d1 d0∧d2 d0∧f0 d0∧f1 d1∧d0 d1∧d1 d1∧d2 d1∧f0 d1∧f1 d2∧d0 d2∧d1 d2∧d2 d2∧f0 d2∧f1
Dealing with sparseness and redundancy
12Dir × (File ∪ Dir)
Empty regions in matrices (exponential w.r.t. relation arity). Different circuits for the same formula.
d0∧d0 d0∧d1 d0∧d2 d0∧f0 d0∧f1 d1∧d0 d1∧d1 d1∧d2 d1∧f0 d1∧f1 d2∧d0 d2∧d1 d2∧d2 d2∧f0 d2∧f1
Dealing with sparseness and redundancy
12Dir × (File ∪ Dir) d0∧d0 d0∧d1 d0∧d2 d0∧f0 d0∧f1 d1∧d0 d1∧d1 d1∧d2 d1∧f0 d1∧f1 d2∧d0 d2∧d1 d2∧d2 d2∧f0 d2∧f1
Sparse matrices represented as interval trees. Compact Boolean Circuits (CBCs).
Overview of Kodkod
13formula in relational logic (FOL, relations, bit vectors, transitive closure) bounds (partial model and types) translator finite universe
Overview of Kodkod
13formula in relational logic (FOL, relations, bit vectors, transitive closure) bounds (partial model and types) translator symmetry breaker finite universe
Symmetry by example
14Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2} R D1 F1 F2 contents Root File Dir
Symmetry by example
14Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2} R D1 F1 F2 contents Root File Dir
Symmetry by example
14Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2} R D1 F1 F2 contents Root File Dir D2
Symmetry by example
14Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2} R F1 F2 contents Root File Dir D2
Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2}
Symmetries between models
15R D1 F1 F2 R D1 F2 F1 R D2 F1 F2 R D2 F2 F1
Symmetries between non-models
16Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2} R D1 F1 F2 R D1 F2 F1 R D2 F1 F2 R D2 F2 F1
Symmetries induce equivalence classes
17Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2}
R D1 F1 F2 R D1 F2 F1 R D2 F1 F2 R D2 F2 F1 R D1 F1 F2 R D1 F2 F1 R D2 F1 F2 R D2 F2 F1✓ ✗
Symmetries induce equivalence classes
17Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2}
R D1 F1 F2 R D1 F1 F2✓ ✗
sufficient to test
equivalence class
Symmetry detection
18Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2} R D1 F1 F2 R D1 F2 F1 R D2 F1 F2 R D2 F2 F1
Assignment symmetries = bound symmetries
Detecting symmetries is hard …
19Assignment symmetries = bound symmetries Graph automorphism detection
〈 , 〉 〈 , 〉 〈 , 〉 〈 , 〉 〈 , 〉 〈 , 〉 { }But only a few symmetries needed in practice
20Greedy algorithm that partitions the universe into equivalence classes Graph automorphism detection
✗ ✓
Base partitioning: practical symmetry detection
21{ R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2}
The coarsest partitioning of the universe such that all non-empty bounds are expressible as unions of products of partitions. R D1 D2 F1 F2
Finding the base partitioning
22R D1 D2 F1 F2 start with a single partition and refine greedily for each non-empty lower and upper bound
Finding base partitioning
23R D1 D2 F1 F2
Finding base partitioning
23R D1 D2 F1 F2
{⟨R⟩} ⊆ Root ⊆ {⟨R⟩}
Finding base partitioning
23D1 D2 F1 F2 R
{⟨R⟩} ⊆ Root ⊆ {⟨R⟩}
Finding base partitioning
23D1 D2 F1 F2 R
{⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩}
Finding base partitioning
23R
{⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩}
D1 D2 F1 F2
Finding base partitioning
23R
{⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩}
D1 D2 F1 F2
Finding base partitioning
23R
{⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2}
D1 D2 F1 F2
Overview of Kodkod
24formula in relational logic (FOL, relations, bit vectors, transitive closure) bounds (partial model and types) translator symmetry breaker finite universe
Overview of Kodkod
24formula in relational logic (FOL, relations, bit vectors, transitive closure) bounds (partial model and types) translator symmetry breaker SAT solver finite universe model
Overview of Kodkod
24formula in relational logic (FOL, relations, bit vectors, transitive closure) bounds (partial model and types) translator symmetry breaker SAT solver core extractor finite universe model minimal unsat core
A bug in the tiny filesystem
25Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2} R D1 F1 F2 contents Root File Dir
A bug in the tiny filesystem
25Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2} R D1 F1 F2 contents Root File Dir
The spec allows multiple parents.
Fixing the tiny filesystem
26Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) ∀ f: File | one contents.f ∀ d: Dir | one contents.d { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2}
Fixing the tiny filesystem
26Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) ∀ f: File | one contents.f ∀ d: Dir | one contents.d { R, D1, D2, F1, F2 } {⟨R⟩} ⊆ Root ⊆ {⟨R⟩} {} ⊆ Dir ⊆ {⟨R⟩, ⟨D1⟩, ⟨D2⟩} {} ⊆ File ⊆ {⟨F1⟩, ⟨F2⟩} {} ⊆ contents ⊆ {R, D1, D2} × {R, D1, D2, F1, F2}
Minimal unsatisfiable core: an unsatisfiable subset of a formula that becomes satisfiable if any of its members are removed.
Resolution-based core extraction
27Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) ∀ f: File | one contents.f ∀ d: Dir | one contents.d φ0 φ1 φ2 φ3 φ4 φ5
High-level minimal cores from low-level proofs
28φ0 φ1 φ2 φ3 φ4 φ5
How to use the proof at the SAT level to find a minimal core at the specification level when
a large specification core?
Recycling core extraction
29φ0 φ1 φ2 φ3 φ4 φ5
Key idea: minimize core by removing constraints at the specification level but re-use valid resolvents from the previous step so that the solver doesn’t have to re-derive them.
Summary
30Today
quantifiers, relations, and transitive closures Next lecture