Kodkod: A Constraint Solver for Relational Logic
Emina Torlak LaSh 2010 · Edinburgh, UK · July 15, 2010Kodkod: A Constraint Solver for Relational Logic Emina Torlak - - PowerPoint PPT Presentation
Kodkod: A Constraint Solver for Relational Logic Emina Torlak - - PowerPoint PPT Presentation
Kodkod: A Constraint Solver for Relational Logic Emina Torlak LaSh 2010 Edinburgh, UK July 15, 2010 A constraint solver for software engineering Alloy4 Miniatur design code Karun analysis checking MemSAT ExUML Analyzer
A constraint solver for software engineering …
2 ExUML Analyzer MIT Course Scheduler Miniatur Karun Whispec design analysis Kesit kodkod Alloy4 code checking test case generation declarative configuration ConfigAssure MemSAT… and research
3 [1] D. Batory. A modeling language for program design and synthesis. Advances in Software Engineering, pages 39–58, 2008. [2] J. Bendisposto, M. Leuschel, O. Ligot, and M. Samia. La validation de mod` eles event-b avec le plug-in prob pour rodin. TSI, pages 1065–1084, 2008. [3] D. L. Berre and A. Parrain. On sat technologies for dependency management and beyond. In ASPL 2008, 2008. [4] J. Blanchette. Relational analysis of (co) inductive predicates,(co) algebraic datatypes, and (co) recursive- functions. In TAP 2010, 2010.
- f Technology, 2009.
- f Automated Reasoning, pages 1–37, 2009.
- f Southampton, 2010.
- bounds. Scientific Commons, 2010.
- f 2010 ICSE Workshop on Search-driven Development: Users, Infrastructure, Tools and Evaluation,
- M. Tivoli, A. Bertolino, et al.
- guages. Software and Systems Modeling, 8(4):451–478, 2009.
- f New Mexico, 2009.
- f Technology, 2009.
- models. FM 2009: Formal Methods, pages 708–723, 2009.
- debugging. J. Netw. Syst. Manage., 16(3):235–258, 2008.
- f b models. Automated Formal Methods (AFM09), 2009.
- mization. In Proceedings of the 2009 Conference of the Center for Advanced Studies on Collaborative
- f Amsterdam, 2008.
- testing. Theory and Practice of Model Transformations, pages 148–164, 2009.
- tions. In Proceedings of the 2007 Symposium on Library-Centric Software Design, pages 11–20. ACM,
- specifications. PhD thesis, Massachusetts Institute of Technology, 2009.
- f the 7th international conference on Runtime verification, pages 202–213. Springer-Verlag, 2007.
Model finding with Kodkod
4 Network example adapted from [Narain08] kodkod ConfigAssure relational problem SAT problem SAT solver- addresses are distinct
- same masks on a subnet
- address range is 121.96.*.*
Model finding with Kodkod
4 Network example adapted from [Narain08] kodkod ConfigAssure relational problem SAT problem SAT solver partial model- addresses are distinct
- same masks on a subnet
- address range is 121.96.*.*
Model finding with Kodkod
4 Network example adapted from [Narain08] kodkod ConfigAssure relational problem SAT problem SAT solver boolean model model partial model b d a c h 121.96.128.35 / 17 121.96.128.43 / 17 121.96.128.47 / 17 121.96.0.7 / 25 121.96.0.11 / 25- addresses are distinct
- same masks on a subnet
- address range is 121.96.*.*
Core extraction with Kodkod
5 Network example adapted from [Narain08] kodkod ConfigAssure relational problem SAT problem SAT solver b d a c h ... / ... ... / ... ... / ... ... / ... ... / ...- addresses are distinct
- same masks on a subnet
- address range is 121.96.0.[0..3]
Core extraction with Kodkod
5 Network example adapted from [Narain08] kodkod ConfigAssure relational problem SAT problem SAT solver boolean proof of unsatisfiability minimal unsatisfiable core b d a c h ... / ... ... / ... ... / ... ... / ... ... / ...- addresses are distinct
- same masks on a subnet
- address range is 121.96.0.[0..3]
- address range is 121.96.0.[0..3]
- addresses are distinct
Relational logic by example: choosing and sorting files
6 unsorted collection of movies and music portable media player?
Relational logic by example: choosing and sorting files
6 unsorted collection of movies and music portable media player?
Automatically select interesting files according to some constraints, sort them into directories and transfer them to the mp3 player.Relational logic by example: choosing and sorting files
6 unsorted collection of movies and music portable media player?
Automatically select interesting files according to some constraints, sort them into directories and transfer them to the mp3 player. This is just constraint solving with partial models: use Kodkod!Relational logic by example: a toy file organizer
7Relational logic by example: a toy file organizer
7 The root of the hierarchy is a directory.Relational logic by example: a toy file organizer
7 Directories may contain files or directories.Relational logic by example: a toy file organizer
7 All directories and files are reachable from the root by following the contents relation zero or more times.Relational logic by example: a toy file organizer
7 contents relation is acyclic.Relational logic by example: a toy file organizer
7 { } universe of uninterpreted atoms.Relational logic by example: a toy file organizer
7 { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 bounds for each relation; root is constant.Relational logic by example: a toy file organizer
8 { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 Root File Dir contents contents contentsKodkod architecture
9 [Torlak07] [Torlak08] spec bounds universe skolemizer symmetry detector symmetry breaker skolemized formula universe partitioning circuit transformer boolean formula SBP translator SAT solver CNF model sharing detector sat? core extractor unsat? minimal coreKodkod architecture
9 [Torlak07] [Torlak08] translation to propositional logic using sparse matrices and compact boolean circuits spec bounds universe skolemizer symmetry detector symmetry breaker skolemized formula universe partitioning circuit transformer boolean formula SBP translator SAT solver CNF model sharing detector sat? core extractor unsat? minimal coreKodkod architecture
9 [Torlak07] [Torlak08] translation to propositional logic using sparse matrices and compact boolean circuits symmetry detection in the presence of arbitrary bounds spec bounds universe skolemizer symmetry detector symmetry breaker skolemized formula universe partitioning circuit transformer boolean formula SBP translator SAT solver CNF model sharing detector sat? core extractor unsat? minimal coreKodkod architecture
9 [Torlak07] [Torlak08] translation to propositional logic using sparse matrices and compact boolean circuits symmetry detection in the presence of arbitrary bounds recycling core extraction for finding minimal unsatisfiable cores of declarative specifications spec bounds universe skolemizer symmetry detector symmetry breaker skolemized formula universe partitioning circuit transformer boolean formula SBP translator SAT solver CNF model sharing detector sat? core extractor unsat? minimal coreKodkod architecture
9 [Torlak07] [Torlak08] translation to propositional logic using sparse matrices and compact boolean circuits spec bounds universe skolemizer symmetry detector symmetry breaker skolemized formula universe partitioning circuit transformer boolean formula SBP translator SAT solver CNF model sharing detector sat? core extractor unsat? minimal coreTranslation by example
10 Root ⊆ Dir contents ⊆ Dir × (File ∪ Dir) (File ∪ Dir) ⊆ Root.*contents ∀ d: Dir | ¬ (d ⊆ d.^contents) {} ⊆ File ⊆ { } {} ⊆ Dir ⊆ { } { } ⊆ Root ⊆ { } {} ⊆ contents ⊆ { }×{ } { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 Bottom-up translation: from relations to expressions to formulas.Relations as matrices
11 {} ⊆ contents ⊆ { }×{ } f0 f1 d0 d1 d2 1 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 〈 〉 〈 〉 {} ⊆ File ⊆ { } {} ⊆ Dir ⊆ { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 { } ⊆ Root ⊆ { }Relations as matrices
11 {} ⊆ contents ⊆ { }×{ } f0 f1 d0 d1 d2 1 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 〈 〉 〈 〉 {} ⊆ File ⊆ { } {} ⊆ Dir ⊆ { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 { } ⊆ Root ⊆ { }Relations as matrices
11 {} ⊆ contents ⊆ { }×{ } f0 f1 d0 d1 d2 1 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 〈 〉 〈 〉 {} ⊆ File ⊆ { } {} ⊆ Dir ⊆ { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 { } ⊆ Root ⊆ { }Relations as matrices
11 {} ⊆ contents ⊆ { }×{ } f0 f1 d0 d1 d2 1 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 〈 〉 〈 〉 {} ⊆ File ⊆ { } {} ⊆ Dir ⊆ { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 { } ⊆ Root ⊆ { }Relations as matrices
11 {} ⊆ contents ⊆ { }×{ } f0 f1 d0 d1 d2 1 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 〈 〉 〈 〉 {} ⊆ File ⊆ { } {} ⊆ Dir ⊆ { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 { } ⊆ Root ⊆ { }Expressions as matrix operations
12 f0 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)Formulas as constraints over matrix entries
13 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 contents ⇒ = contents ⊆ 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 Dir × (File ∪ Dir) (c0 ⇒ d0∧d0) ∧ (c1 ⇒ d0∧d1) ∧ (c2 ⇒ d0∧d2) ∧ (c3 ⇒ d0∧f0) ∧ (c4 ⇒ d0∧f1) ∧ (c5 ⇒ d1∧d0) ∧ (c6 ⇒ d1∧d1) ∧ (c7 ⇒ d1∧d2) ∧ (c8 ⇒ d1∧f0) ∧ (c9 ⇒ d1∧f1) ∧ (c10 ⇒ d2∧d0) ∧ (c11 ⇒ d2∧d1) ∧ (c12 ⇒ d2∧d2) ∧ (c13 ⇒ d2∧f0) ∧ (c14 ⇒ d2∧f1)Technical challenges: sparseness and redundancy
14 Dir × (File ∪ Dir)Technical challenges: sparseness and redundancy
14 Dir × (File ∪ Dir) sparseness: empty regions in expression matrices (exponential w.r.t. arity)Technical challenges: sparseness and redundancy
14 Dir × (File ∪ Dir) sparseness: empty regions in expression matrices (exponential w.r.t. arity) commutativityTechnical challenges: sparseness and redundancy
14 Dir × (File ∪ Dir) sparseness: empty regions in expression matrices (exponential w.r.t. arity) commutativityTechnical challenges: sparseness and redundancy
14 Dir × (File ∪ Dir) sparseness: empty regions in expression matrices (exponential w.r.t. arity) idempotence commutativityTechnical challenges: sparseness and redundancy
14 Dir × (File ∪ Dir) sparseness: empty regions in expression matrices (exponential w.r.t. arity) k-dimensional sparse matrices represented as interval trees [Torlak07] idempotence commutativity✔
Technical challenges: sparseness and redundancy
14 Dir × (File ∪ Dir)- n-the-fly sharing
✔ ✔
Experimental results (log scale)
15 1 5 25 126 632 3172 15905 79763 400000 AWD.OpTotal-51 NUM378-22 ALG197-14 SET967-4 ALG195-14 Handshake-10 COM008-12 SET948-14 GEO092-16 LAT258-7 List.Reflexive-28 SET943-7 GEO158-16 AWD.Ignore-51 FileSystem-90 List.Symm-16 RingElection-16 NUM374-5 GEO159-16 MED007-35 MED009-35 GEO115-18 ALG212-7 Dijkstra-60 Trees-7 GEO091-20 TOP020-10 List.Empties-120 AWD.Transfer-41 AWD.A241-51 model finding time (ms) kodkod alloy3 m/o m/o t/o t/o t/o t/o m/o m/o t/o m/o m/o Benchmarks (12 Alloy and 18 TPTP problems):- 4 to 59 constraints
- 4 to 120 atom universe
- 2 sat, 28 unsat
- 5 min timeout for translation & solving
- alloy3 timed out on 5 / 30 and ran out of
- kodkod 16x faster on average, with a 24x
Kodkod architecture and contributions
16 [Torlak07] [Torlak08] translation to propositional logic using sparse matrices and compact boolean circuits spec bounds universe skolemizer symmetry detector symmetry breaker skolemized formula universe partitioning circuit transformer boolean formula SBP translator SAT solver CNF model sharing detector sat? core extractor unsat? minimal coreKodkod architecture and contributions
16 [Torlak07] [Torlak08] symmetry detection in the presence of arbitrary bounds spec bounds universe skolemizer symmetry detector symmetry breaker skolemized formula universe partitioning circuit transformer boolean formula SBP translator SAT solver CNF model sharing detector sat? core extractor unsat? minimal coreSymmetry by example
17 { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 Root File Dir contents contents contentsSymmetry by example
17 { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 Root File Dir contents contents contentsSymmetry by example
17 { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 Root File Dir contents contents contentsSymmetry by example
17 { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 Root File Dir contents contents contents Is this still a model?Symmetry by example
17 { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 Root File Dir contents contents contents Is this still a model? Yes!Symmetry by example
17 { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 Root File Dir contents contents contents Is this still a model? Yes! How about now?Symmetry by example
17 { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 Root File Dir contents contents contents Is this still a model? Yes!Symmetries between models
18 equivalent models { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 Root Root Root RootSymmetries between non-models
19 equivalent non-models Root Root Root RootSymmetries partition bindings into equivalence classes
20 { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 Root Root Root Root Root Root Root Root models non-models Root Root Root Root Root Root Root RootExploiting symmetries (symmetry breaking)
21 { } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 Root Root Root Root Root Root sufficient to test one binding per classDetecting symmetries
22 non-model symmetries Root G0 Root G1 Root G2 Root G3Detecting symmetries
22 non-model symmetries ( ) Root G0 Root G2 Root G3Detecting symmetries
22 non-model symmetries ( ) ( ) Root G0 Root G3Detecting symmetries
22 non-model symmetries ( ) ( ) ( ) ( ) Root G0Detecting symmetries
22 ( ) non-model symmetries ( ) ( ) ( ) ( )Detecting symmetries
22 ( ) ( ) ( ) (non-)model symmetries = bound symmetries ( ) ( )Detecting symmetries
22 ( ) ( ) ( ) (non-)model symmetries = bound symmetries ( ) ( )Detecting symmetries
22 ( ) ( ) ( ) (non-)model symmetries = bound symmetries ( ) ( )Detecting symmetries
22 ( ) symmetry detection theorem [Torlak07] ( ) ( ) (non-)model symmetries = bound symmetries ( ) ( )Detecting all symmetries is hard …
23 (non-)model symmetries = bound symmetries graph automorphism detection ⇔ 〈 , 〉 〈 , 〉 〈 , 〉 〈 , 〉 〈 , 〉 〈 , 〉 { } symmetry detection theorem [Torlak07]✔ ✘
But effective symmetry breaking needs only a few symmetries
24 Detection by graph automorphism- non-polynomial
- finds all symmetries
- polynomial in size of bounds
- finds the symmetries that
Base partitioning of the file system universe
25 coarsest partitioning of the universe such that all non-empty bounds are expressible as unions of products of partitions 〈 〉 〈 〉 〈 〉 〈 〉Base partitioning of the file system universe
25 coarsest partitioning of the universe such that all non-empty bounds are expressible as unions of products of partitions 〈 〉 〈 〉 〈 〉 〈 〉Base partitioning of the file system universe
25 coarsest partitioning of the universe such that all non-empty bounds are expressible as unions of products of partitions 〈 〉 〈 〉 〈 〉 〈 〉 { } ∪ { } 〈 〉 〈 〉 〈 〉Base partitioning of the file system universe
25 coarsest partitioning of the universe such that all non-empty bounds are expressible as unions of products of partitions 〈 〉 〈 〉 〈 〉 〈 〉 { × } ∪ { × { }} ∪ { × { }} ∪ {{ } × } ∪ {{ } × { }} ∪ {{ } × { }} 〈 〉〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉Base partitioning of the file system universe
25 symmetries 〈 〉 〈 〉 〈 〉 〈 〉 { × } ∪ { × { }} ∪ { × { }} ∪ {{ } × } ∪ {{ } × { }} ∪ {{ } × { }} 〈 〉〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 ( ) ( ) ( ) ( ) ( )Finding base partitioning
26 start with a single partition and refine greedily for each non-empty lower and upper boundFinding base partitioning
27?
〈 〉 〈 〉 {} ⊆ File ⊆ { }Finding base partitioning
27✘
〈 〉 〈 〉 {} ⊆ File ⊆ { }Finding base partitioning
27✔
〈 〉 〈 〉 {} ⊆ File ⊆ { }Finding base partitioning
28✔ ?
〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 {} ⊆ File ⊆ { } {} ⊆ Dir ⊆ { }Finding base partitioning
28✔ ✔
〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 {} ⊆ File ⊆ { } {} ⊆ Dir ⊆ { }Finding base partitioning
29✔ ✔ ?
〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 {} ⊆ File ⊆ { } {} ⊆ Dir ⊆ { } {} ⊆ contents ⊆ { }×{ }Finding base partitioning
29✔ ✔
{ } × { } ∪ { } × { }✔
〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 {} ⊆ File ⊆ { } {} ⊆ Dir ⊆ { } {} ⊆ contents ⊆ { }×{ } 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉Finding base partitioning
30✔ ✔ ✔ ?
〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉Finding base partitioning
30✔ ✔ ✔ ✘
〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉Finding base partitioning
30✔ ✔ ✔ ✔
〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉 〈 〉Experimental results (log scale)
31 1 5 23 113 548 2650 12819 62013 300000 SET943-7 GEO158-16 AWD.Ignore-51 LAT258-7 List.Symm-16 COM008-12 GEO092-16 List.Reflexive-28 MED007-35 Trees-7 GEO091-20 TOP020-10 Handshake-10 RingElection-16 NUM374-5 AWD.Transfer-41 NUM378-22 SET967-4 FileSystem-90 MED009-35 Dijkstra-60 AWD.OpTotal-51 ALG197-14 ALG195-14 GEO115-18 ALG212-7 List.Empties-120 AWD.A241-51 SET948-14 GEO159-16 detection time (ms) greedy detection complete detection t/o t/o t/o t/o t/o Benchmarks (12 Alloy and 18 TPTP problems):- 10 with a partial model (1 to 462 tuples)
- 56 to 16,040 bits of state
- 1 to 7×10163 symmetries
- 5 min timeout
- complete detection with Nauty timed out on
- greedy detection 8,125x faster on average,
Discussion
32 language first order logic relational algebra partial models inductive definitions types bitvector arithmetic model finding partial models inductive definitions symmetry breaking high-arity relations nested quantifiers core extraction minimal core Kodkod IDP1.3 Paradox2.3 DarwinFM Mace4 full support partial support no supportSo long, and thanks for all the fish!
33 questions? alloy.mit.edu/kodkod/