writing declarative specifications for clauses
play

Writing Declarative Specifications for Clauses Martin Gebser 1 , - PowerPoint PPT Presentation

Writing Declarative Specifications for Clauses Martin Gebser 1 , Tomi Janhunen 2 , Roland Kaminski 1 , Torsten Schaub 1 , 3 , Shahab Tasharrofi 2 1 ) University of Potsdam, Germany 2 ) Aalto University, Finland 3 ) INRIA Rennes, France JELIA16,


  1. Writing Declarative Specifications for Clauses Martin Gebser 1 , Tomi Janhunen 2 , Roland Kaminski 1 , Torsten Schaub 1 , 3 , Shahab Tasharrofi 2 1 ) University of Potsdam, Germany 2 ) Aalto University, Finland 3 ) INRIA Rennes, France JELIA’16, Larnaca, Cyprus, November 10, 2016

  2. Background: Boolean Satisfiability Satisfiability (SAT) solvers provide an efficient implementation of classical propositional logic. ◮ SAT solvers expect their input in the conjunctive normal form (CNF), i.e., a conjunction of clauses l 1 ∨ . . . ∨ l k . ◮ Clauses can be viewed as “machine code” for expressing constraints and representing knowledge. ◮ Typically clauses are either — generated using a procedural program or — obtained when more complex formulas are translated. ◮ First-order formulas are prone to combinatorial effects: ¬ edge ( X , Y ) ∨ ¬ edge ( Y , Z ) ∨ ¬ edge ( Z , X ) ∨ ( X = Y ) ∨ ( X = Z ) ∨ ( Y = Z ) JELIA’16, November 10, 2016 2/19

  3. Analogue: Assembly Languages s♠♦❞❡❧s✿ t❡st❧ ✪❡❛①✱ ✪❡❛① ♣✉s❤q ✪r❜♣ ❥❡ ✳▲✷ ♠♦✈q ✪rs♣✱ ✪r❜♣ ♠♦✈❧ ✩✵✱ ✪❡❛① s✉❜q ✩✸✷✱ ✪rs♣ ❥♠♣ ✳▲✸ ♠♦✈q ✪r❞✐✱ ✲✷✹✭✪r❜♣✮ ✳▲✷✿ ♠♦✈q ✪rs✐✱ ✲✸✷✭✪r❜♣✮ ♠♦✈q ✲✷✹✭✪r❜♣✮✱ ✪r❛① ♠♦✈❧ ✩✵✱ ✲✹✭✪r❜♣✮ ♠♦✈q ✪r❛①✱ ✪r❞✐ ♠♦✈q ✲✸✷✭✪r❜♣✮✱ ✪r❞① ♠♦✈❧ ✩✵✱ ✪❡❛① ♠♦✈q ✲✷✹✭✪r❜♣✮✱ ✪r❛① ❝❛❧❧ ❝♦♠♣❧❡t❡ ♠♦✈q ✪r❞①✱ ✪rs✐ t❡st❧ ✪❡❛①✱ ✪❡❛① ♠♦✈q ✪r❛①✱ ✪r❞✐ ❥❡ ✳▲✹ ❝❛❧❧ ♣r♦♣❛❣❛t❡ ♠♦✈❧ ✩✲✶✱ ✪❡❛① ♠♦✈q ✪r❛①✱ ✲✷✹✭✪r❜♣✮ ❥♠♣ ✳▲✸ ♠♦✈q ✲✷✹✭✪r❜♣✮✱ ✪r❛① ✳✳✳ ♠♦✈q ✪r❛①✱ ✪r❞✐ ✳▲✸✿ ♠♦✈❧ ✩✵✱ ✪❡❛① ❧❡❛✈❡ ❝❛❧❧ ❝♦♥❢❧✐❝t r❡t JELIA’16, November 10, 2016 3/19

  4. How to Generate Machine Code? 1. Assembly language 2. Assembly language + macros [ t✐❣❝❝✳t✐❝❛❧❝✳♦r❣ ] ✳❧♦♥❣ ✵ ✳♠❛❝r♦ s✉♠ ❢r♦♠❂✵✱ t♦❂✺ ✳❧♦♥❣ ✶ ✳❧♦♥❣ ❭❢r♦♠ ✳❧♦♥❣ ✷ ✳✐❢ ❭t♦✲❭❢r♦♠ �− → ✳❧♦♥❣ ✸ s✉♠ ✧✭❭❢r♦♠✰✶✮✧✱❭t♦ ✳❧♦♥❣ ✹ ✳❡♥❞✐❢ ✳❧♦♥❣ ✺ ✳❡♥❞♠ 3. High level language (C, C++, scala, ...) + compilation How much can we control the actual output in each case? JELIA’16, November 10, 2016 4/19

  5. Our Approach ◮ A fully declarative approach where intended clauses are given first-order specifications in analogy to ASP . ◮ In the implementation, we harness state-of-the-art ASP grounders for instantiating terms variables in clauses. ◮ The benefits of our approach: — Complex domain specifications supported — Database operations available — Uniform encodings enabled — Elaboration tolerance ◮ WYSIWYG: black ( X ) ∨ gray ( X ) ∨ white ( X ) ← node ( X ) . node ( a ) . black ( a ) ∨ gray ( a ) ∨ white ( a ) . node ( b ) . �− → black ( b ) ∨ gray ( b ) ∨ white ( b ) . black ( c ) ∨ gray ( c ) ∨ white ( c ) . node ( c ) . JELIA’16, November 10, 2016 5/19

  6. Outline Clause Programs Modeling Methodology and Applications Implementation Discussion and Conclusion JELIA’16, November 10, 2016 6/19

  7. Clause Programs: Syntax ◮ The signature P for predicate symbols is partitioned into domain predicates P d and varying predicates P v . ◮ Domain rules in P d are normal rules of the form a ← c 1 , . . . , c m , ∼ d 1 , . . . , ∼ d n . ◮ The syntax for clause rules is a 1 ∨ · · · ∨ a k ∨ ¬ b 1 ∨ · · · ∨ ¬ b l ← c 1 , . . . , c m , ∼ d 1 , . . . , ∼ d n . where the head (resp. body) is expressed in P v (resp. P d ). ◮ For standard use cases, the domain part of a program should be stratified to enable evaluation by the grounder. JELIA’16, November 10, 2016 7/19

  8. Example: Graph Coloring Domain rules node ( X ) ← edge ( X , Y ) . node ( Y ) ← edge ( X , Y ) . Clause rules black ( X ) ∨ gray ( X ) ∨ white ( X ) ← node ( X ) . ¬ black ( X ) ∨ ¬ black ( Y ) ← edge ( X , Y ) . ¬ gray ( X ) ∨ ¬ gray ( Y ) ← edge ( X , Y ) . ¬ white ( X ) ∨ ¬ white ( Y ) ← edge ( X , Y ) . Uniform encoding that works for any graph instance! JELIA’16, November 10, 2016 8/19

  9. Clause Programs: Semantics ◮ The Herbrand universe Hu ( P ) and the Herbrand base Hb ( P ) of a clause program P are defined as usual. ◮ The ground program Gnd ( P ) is the respective Herbrand instantiation of P over the universe Hu ( P ) . ◮ The domain reduct P I of P with respect to I contains the positive rule a ← c 1 , . . . , c m for every domain rule a ← c 1 , . . . , c m , ∼ d 1 , . . . , ∼ d n . such that { d 1 , . . . , d n } ∩ I d = ∅ . Definition An Herbrand interpretation I ⊆ Hb ( P ) is a domain stable model = Gnd ( P ) and I d is the least model of Gnd ( P ) I . of P iff I | JELIA’16, November 10, 2016 9/19

  10. Example: Continued 1. Suppose the following facts as instance information: edge ( a , b ) , edge ( b , c ) , edge ( c , a ) . 2. Additional domain atoms from node ( X ; Y ) ← edge ( X , Y ) : node ( a ) , node ( b ) , node ( c ) . 3. Clauses from black ( X ) ∨ gray ( X ) ∨ white ( X ) ← node ( X ) : black ( a ) ∨ gray ( a ) ∨ white ( a ) , black ( b ) ∨ gray ( b ) ∨ white ( b ) , black ( c ) ∨ gray ( c ) ∨ white ( c ) . 4. Clauses from ¬ black ( X ) ∨ ¬ black ( Y ) ← edge ( X , Y ) etc: ¬ black ( a ) ∨ ¬ black ( b ) , ¬ gray ( a ) ∨ ¬ gray ( b ) , ¬ white ( a ) ∨ ¬ white ( b ) , ¬ black ( b ) ∨ ¬ black ( c ) , ¬ gray ( b ) ∨ ¬ gray ( c ) , ¬ white ( b ) ∨ ¬ white ( c ) , ¬ black ( c ) ∨ ¬ black ( a ) , ¬ gray ( c ) ∨ ¬ gray ( a ) , ¬ white ( c ) ∨ ¬ white ( a ) . JELIA’16, November 10, 2016 10/19

  11. Encodings In the paper, we illustrate the use of clause programs: ◮ Graph n -coloring ◮ n -Queens ◮ Full propositional logic ◮ Haplotype inference Further sample encodings can found from our website: ◮ Structure learning for Markov networks ◮ Instruction scheduling ◮ SuDoku puzzles ❤tt♣✿✴✴r❡s❡❛r❝❤✳✐❝s✳❛❛❧t♦✳❢✐✴s♦❢t✇❛r❡✴s❛t✴s❛t❣r♥❞✴ JELIA’16, November 10, 2016 11/19

  12. Graph n -Coloring ◮ The number of colors is parameterized by n . ◮ We may exploit many advanced features of the grounder: — Range specifications — Pooling (substantially revised in GRINGO v. 4) — Conditional literals ◮ If need be, the lengths of clauses can vary dynamically depending on the problem instance! color ( 1 . . . n ) . node ( X ; Y ) ← edge ( X , Y ) . � ← hascolor ( X , C ) : color ( C ) node ( X ) . ¬ hascolor ( X , C ) ∨ ¬ hascolor ( Y , C ) ← edge ( X , Y ) , color ( C ) . JELIA’16, November 10, 2016 12/19

  13. More Complex Domains: Highlights ◮ Parameterization and non-trivial domains in n -Queens: coord ( 1 . . . n ) . dir ( 0 , − 1 ) . dir ( − 1 , 0 ) . dir ( − 1 , − 1 ) . dir ( − 1 , 1 ) . target ( X , Y , R , C ) ← coord ( X ; Y ; X + R ; Y + C ) , dir ( R , C ) . attack ( X + R , Y + C , R , C ) ∨ ¬ attack ( X , Y , R , C ) ← target ( X , Y , R , C ) , target ( X − R , Y − C , R , C ) . ◮ Dynamic-length clauses for haplotype inference: used ( G 2 , E 2 ) ∨ � same ( G 1 , E 1 , G 2 , E 2 ) : ( keep ( G 1 ) , E 1 = 0 . . . 1 , ( G 1 , E 1 ) < ( G 2 , E 2 )) ← keep ( G 2 ) , E 2 = 0 . . . 1 . JELIA’16, November 10, 2016 13/19

  14. Beyond Clauses: Full Propositional Logic 1. Domains of subsentences, compounds, and atoms: sub ( S ) ← sat ( S ) . sub ( S 1 ; S 2 ) ← sub ( a ( S 1 , S 2 )) . co ( a ( S 1 , S 2 )) ← sub ( a ( S 1 , S 2 )) . sub ( S 1 ; S 2 ) ← sub ( o ( S 1 , S 2 )) . co ( o ( S 1 , S 2 )) ← sub ( o ( S 1 , S 2 )) . sub ( S ) ← sub ( n ( S )) . co ( n ( S )) ← sub ( n ( S )) . true ( S ) ← sat ( S ) . at ( S ) ← sub ( S ) , ∼ co ( S ) . 2. Tseitin transformations (e.g., for a ( S 1 , S 2 ) ): true ( a ( S 1 , S 2 )) ∨ ¬ true ( S 1 ) ∨ ¬ true ( S 2 ) ← co ( a ( S 1 , S 2 )) . ¬ true ( a ( S 1 , S 2 )) ∨ true ( S 1 ) ← co ( a ( S 1 , S 2 )) . ¬ true ( a ( S 1 , S 2 )) ∨ true ( S 2 ) ← co ( a ( S 1 , S 2 )) . 3. Sentences to satisfy as instance information: sat ( o ( n ( a ) , b )) . sat ( o ( n ( b ) , c )) . sat ( o ( n ( c ) , a )) . JELIA’16, November 10, 2016 14/19

  15. Implementation Strategy ◮ Clause programs can be directly grounded using the state-of-the-art ASP grounder GRINGO (v. 2 onward). ◮ The output of GRINGO is a ground disjunctive logic program Gnd ( P ) consisting of bodyless disjunctive rules a 1 ∨ · · · ∨ a k ∨ ¬ b 1 ∨ · · · ∨ ¬ b l . where each a i and ¬ b j is a classical literal over Hb v ( P ) . ◮ The semantic connection of a and its negation ¬ a can be re-established by viewing such disjunctions as clauses. ◮ The classical models of Gnd ( P ) correspond to the domain stable models of the clause program P . JELIA’16, November 10, 2016 15/19

Recommend


More recommend