writing declarative specifications for clauses
play

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

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


  1. Writing Declarative Specifications for Clauses Martin Gebser 1 , 2 , Tomi Janhunen 1 , Roland Kaminski 2 , Torsten Schaub 2 , 3 , Shahab Tasharrofi 1 1 ) Aalto University, Finland 2 ) University of Potsdam, Germany 3 ) INRIA Rennes, France GTTV’15, Lexington, Kentucky, September 27, 2015

  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. GTTV’15, September 27, 2015 2/48

  3. 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. GTTV’15, September 27, 2015 3/48

  4. 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 ) GTTV’15, September 27, 2015 4/48

  5. Analogue: Assembly Languages smodels: testl %eax, %eax pushq %rbp je .L2 movq %rsp, %rbp movl $0, %eax subq $32, %rsp jmp .L3 movq %rdi, -24(%rbp) .L2: movq %rsi, -32(%rbp) movq -24(%rbp), %rax movl $0, -4(%rbp) movq %rax, %rdi movq -32(%rbp), %rdx movl $0, %eax movq -24(%rbp), %rax call complete movq %rdx, %rsi testl %eax, %eax movq %rax, %rdi je .L4 call propagate movl $-1, %eax movq %rax, -24(%rbp) jmp .L3 movq -24(%rbp), %rax ... movq %rax, %rdi .L3: movl $0, %eax leave call conflict ret GTTV’15, September 27, 2015 5/48

  6. How to Generate Machine Code? 1. Assembly language GTTV’15, September 27, 2015 6/48

  7. How to Generate Machine Code? 1. Assembly language 2. Assembly language + macros [ tigcc.ticalc.org ] .long 0 .macro sum from=0, to=5 .long 1 .long \from .long 2 .if \to-\from �− → .long 3 sum "(\from+1)",\to .long 4 .endif .long 5 .endm GTTV’15, September 27, 2015 7/48

  8. How to Generate Machine Code? 1. Assembly language 2. Assembly language + macros [ tigcc.ticalc.org ] .long 0 .macro sum from=0, to=5 .long 1 .long \from .long 2 .if \to-\from �− → .long 3 sum "(\from+1)",\to .long 4 .endif .long 5 .endm 3. High level language (C, C++, scala, ...) + compilation GTTV’15, September 27, 2015 8/48

  9. How to Generate Machine Code? 1. Assembly language 2. Assembly language + macros [ tigcc.ticalc.org ] .long 0 .macro sum from=0, to=5 .long 1 .long \from .long 2 .if \to-\from �− → .long 3 sum "(\from+1)",\to .long 4 .endif .long 5 .endm 3. High level language (C, C++, scala, ...) + compilation How much can we control the actual output in each case? GTTV’15, September 27, 2015 9/48

  10. 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. GTTV’15, September 27, 2015 10/48

  11. 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 GTTV’15, September 27, 2015 11/48

  12. 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 ) ∨ grey ( X ) ∨ white ( X ) ← node ( X ) . black ( a ) ∨ grey ( a ) ∨ white ( a ) . node ( a ) . node ( b ) . �− → black ( b ) ∨ grey ( b ) ∨ white ( b ) . black ( c ) ∨ grey ( c ) ∨ white ( c ) . node ( c ) . GTTV’15, September 27, 2015 12/48

  13. Outline Clause Programs Modeling Methodology and Applications Implementation Discussion and Conclusion GTTV’15, September 27, 2015 13/48

  14. Clause Programs: Syntax ◮ The signature P for predicate symbols is partitioned into domain predicates P d and varying predicates P v . GTTV’15, September 27, 2015 14/48

  15. 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 . GTTV’15, September 27, 2015 15/48

  16. 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 ). GTTV’15, September 27, 2015 16/48

  17. 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. GTTV’15, September 27, 2015 17/48

  18. Example: Graph Colouring Domain rules node ( X ) ← edge ( X , Y ) . node ( Y ) ← edge ( X , Y ) . GTTV’15, September 27, 2015 18/48

  19. Example: Graph Colouring Domain rules node ( X ) ← edge ( X , Y ) . node ( Y ) ← edge ( X , Y ) . Clause rules black ( X ) ∨ grey ( X ) ∨ white ( X ) ← node ( X ) . ¬ black ( X ) ∨ ¬ black ( Y ) ← edge ( X , Y ) . ¬ grey ( X ) ∨ ¬ grey ( Y ) ← edge ( X , Y ) . ¬ white ( X ) ∨ ¬ white ( Y ) ← edge ( X , Y ) . GTTV’15, September 27, 2015 19/48

  20. Example: Graph Colouring Domain rules node ( X ) ← edge ( X , Y ) . node ( Y ) ← edge ( X , Y ) . Clause rules black ( X ) ∨ grey ( X ) ∨ white ( X ) ← node ( X ) . ¬ black ( X ) ∨ ¬ black ( Y ) ← edge ( X , Y ) . ¬ grey ( X ) ∨ ¬ grey ( Y ) ← edge ( X , Y ) . ¬ white ( X ) ∨ ¬ white ( Y ) ← edge ( X , Y ) . Uniform encoding that works for any graph instance! GTTV’15, September 27, 2015 20/48

  21. 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 ) . GTTV’15, September 27, 2015 21/48

  22. 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 = ∅ . GTTV’15, September 27, 2015 22/48

  23. 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 | GTTV’15, September 27, 2015 23/48

  24. 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 ) . GTTV’15, September 27, 2015 24/48

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend