logic control an example
play

Logic + Control: An example or SAT solver of Howe & King as a - PowerPoint PPT Presentation

Intro. Specification Correctness&. . . Programs Final Logic + Control: An example or SAT solver of Howe & King as a logic program (File ./LIPIcs/29.pdf ) W lodzimierz Drabent Institute of Computer Science, Polish Academy of


  1. Intro. Specification Correctness&. . . Programs Final Logic + Control: An example or SAT solver of Howe & King as a logic program (File ./LIPIcs/29.pdf ) W� lodzimierz Drabent Institute of Computer Science, Polish Academy of Sciences Link¨ oping University (Sweden) http://www.ipipan.waw.pl/~drabent ICLP’12, 6th September 2012 Version compiled on September 10, 2012 1 / 25

  2. Intro. Specification Correctness&. . . Programs Final This file contains extra material, not intended to be shown within a short presentation. In particular, such are all the slides with their titles in parentheses. 2 / 25

  3. Intro. Specification Correctness&. . . Programs Final logic Is there in actual Logic Programming ? “logic” To which extent LP is declarative/logical ? 3 / 25

  4. Intro. Specification Correctness&. . . Programs Final Representation How to reason about logic programs? We present a construction of a practical Prolog program (SAT solver of Howe&King). Most of the reasoning done at the declarative level (formally) abstracting from any operational semantics. Plan ◮ Specification ◮ Logic programs 1, 2, 3 ◮ Proving correctness & ◮ Adding control completeness ◮ Conclusions 4 / 25

  5. Intro. Specification Correctness&. . . Programs Final Representation How to reason about logic programs? We present a construction of a practical Prolog program (SAT solver of Howe&King). Most of the reasoning done at the declarative level (formally) abstracting from any operational semantics. Plan ◮ Specification ◮ Logic programs 1, 2, 3 ◮ Proving correctness & ◮ Adding control completeness ◮ Conclusions 4 / 25

  6. Intro. Specification Correctness&. . . Programs Final Representation How to reason about logic programs? We present a construction of a practical Prolog program (SAT solver of Howe&King). Most of the reasoning done at the declarative level (formally) abstracting from any operational semantics. Plan ◮ Specification ◮ Logic programs 1, 2, 3 ◮ Proving correctness & ◮ Adding control completeness ◮ Conclusions 4 / 25

  7. Intro. Specification Correctness&. . . Programs Final Representation Preliminaries Definite programs. To describe relations to be defined by program predicates: Specification – a Herbrand interpretation S . Specified atom – a p ( t 1 , . . . , t n ) ∈ S . 5 / 25

  8. Intro. Specification Correctness&. . . Programs Final Representation Representation of propositional formulae for a SAT solver [Howe&King] Literals x ¬ x as pairs true-X false-X CNF formulae ( . . . ∧ ( . . . ∨ Literal ij ∨ . . . ) ∧ . . . ) as lists of lists [ . . . , [ . . . , Pair ij , . . . ] , . . . ] CNF formula [ f 1 , . . . , f n ] is satisfiable iff it has an instance [ f 1 θ, . . . , f n θ ] where ∀ i f i θ ∈ L 0 1 = { [ t 1 - u 1 , . . . , u - u, . . . , t n - u n ] ∈ H } . CNF formula f is satisfiable iff some fθ is in L 0 2 = { [ f 1 θ, . . . , f n θ ] | as above } . A program defining L 0 2 is a SAT solver. 6 / 25

  9. Intro. Specification Correctness&. . . Programs Final Towards Approximate specifications (Spec. 1) Specifying a SAT solver So apparently a SAT solver should compute L 0 2 . 7 / 25

  10. Intro. Specification Correctness&. . . Programs Final Towards Approximate specifications (Spec. 1) Specifying a SAT solver So apparently a SAT solver should compute L 0 2 . Computing exact L 0 2 unnecessary. E.g. nobody uses append/3 defining the list appending relation exactly! ❘ Common in LP: relations to be computed known approximately. 7 / 25

  11. Intro. Specification Correctness&. . . Programs Final Towards Approximate specifications (Spec. 1) Specifying a SAT solver So may a SAT solver should compute L 0 2 . Computing exact L 0 2 unnecessary. E.g. nobody uses append/3 defining the list appending relation exactly! ❘ Common in LP: relations to be computed known approximately. 7 / 25

  12. Intro. Specification Correctness&. . . Programs Final Towards Approximate specifications (Spec. 1) Specifying a SAT solver So may a SAT solver should compute L 0 2 . Also it may compute a certain L 2 ⊇ L 0 2 . L 2 = { s ∈ H | if s is a list of lists of pairs then s ∈ L 0 2 } . ❘ Common in LP: relations to be computed known approximately. 7 / 25

  13. Intro. Specification Correctness&. . . Programs Final Towards Approximate specifications (Spec. 1) Specifying a SAT solver So may a SAT solver should compute L 0 2 . Also it may compute a certain L 2 ⊇ L 0 2 . L 2 = { s ∈ H | if s is a list of lists of pairs then s ∈ L 0 2 } . Any set L 0 2 ⊆ L ′ 2 ⊆ L 2 will do: a CNF formula f is satisfiable iff some fθ is in L ′ 2 . ❘ Common in LP: relations to be computed known approximately. 7 / 25

  14. Intro. Specification Correctness&. . . Programs Final Towards Approximate specifications (Spec. 1) Approximate specifications S 0 � �� � required incorrect � �� � S , where S 0 ⊆ S . Approximate specification – ( S 0 , S ) ↑ ↑ for completeness for correctness S 0 ⊆ M P ⊆ S . S 0 – what has to be computed. Intention: S – what may be computed. 8 / 25

  15. Intro. Specification Correctness&. . . Programs Final Towards Approximate specifications (Spec. 1) Approximate specifications S 0 � �� � required incorrect � �� � S Approximate specification for SAT solver: ( S 0 1 , S 1 ) , 2 : L 0 states that predicate sat cnf defines a set L ′ 2 ⊆ L ′ 2 ⊆ L 2 . [Details � the paper] 8 / 25

  16. Intro. Specification Correctness&. . . Programs Final Towards Approximate specifications (Spec. 1) (Details – 1st specification for SAT solver) ( S 0 Specification: 1 , S 1 ) with the specified atoms S 0 1 : S 1 : where t ∈ L 0 sat cnf ( t ) , where t ∈ L 2 , sat cnf ( t ) , 2 , sat cl ( s ) , s ∈ L 0 1 , sat cl ( s ) , s ∈ L 1 , x = x, x = x, x ∈ H x ∈ H L 0 1 = { [ t 1 - u 1 , . . . , u - u, . . . , t n - u n ] ∈ H } , L 0 2 = { [ s 1 , . . . , s n ] | s 1 , . . . , s n ∈ L 0 1 } , L 1 = { t ∈ H | if t is a list of pairs then t ∈ L 0 1 } , L 2 = { s ∈ H | if s is a list of lists of pairs then s ∈ L 0 2 } . 9 / 25

  17. Intro. Specification Correctness&. . . Programs Final Correctness & completeness of programs Correctness (imperative programming) ւ ց Correctness Completeness (logic programming) M P ⊆ S S ⊆ M P Completeness: Everything required by the spec. is computed. Correctness: Everything computed is compatible with the spec. P semi-complete w.r.t. S = P complete for terminating queries (under some selection rule). [Details � the paper] 10 / 25

  18. Intro. Specification Correctness&. . . Programs Final Correctness & completeness of programs Correctness (imperative programming) ւ ց Correctness Completeness (logic programming) M P ⊆ S S ⊆ M P Completeness: Everything required by the spec. is computed. Correctness: Everything computed is compatible with the spec. P semi-complete w.r.t. S = P complete for terminating queries (under some selection rule). [Details � the paper] 10 / 25

  19. Intro. Specification Correctness&. . . Programs Final Correctness & completeness, sufficient conditions Th . (Clark 1979): P correct w.r.t. S when for each ( H ← B ) ∈ ground ( P ) , B ⊆ S ⇒ H ∈ S . (Out of correct atoms, the clauses produce only correct atoms.) Th .: P semi-complete w.r.t. S when for each H ∈ S , exists ( H ← B ) ∈ ground ( P ) where B ⊆ S . (Each required atom can be produced out of required atoms.) Semi-complete + terminating ⇒ complete. 11 / 25

  20. Intro. Specification Correctness&. . . Programs Final Correctness & completeness, sufficient conditions Th . (Clark 1979): P correct w.r.t. S when for each ( H ← B ) ∈ ground ( P ) , B ⊆ S ⇒ H ∈ S . (Out of correct atoms, the clauses produce only correct atoms.) Th .: P semi-complete w.r.t. S when for each H ∈ S , exists ( H ← B ) ∈ ground ( P ) where B ⊆ S . (Each required atom can be produced out of required atoms.) Semi-complete + terminating ⇒ complete. 11 / 25

  21. Intro. Specification Correctness&. . . Programs Final Program 1 (2 (2a) 3) 23 Control (Control details) SAT solver 1 P 1 : sat cnf ([ ]) . sat cnf ([ Clause | Clauses ]) ← sat cl ( Clause ) , sat cnf ( Clauses ) . sat cl ([ Pol - V ar | Pairs ]) ← Pol = V ar. sat cl ([ H | Pairs ]) ← sat cl ( Pairs ) . Can be constructed guided by the sufficient conditions above, and specification ( S 0 1 , S 1 ) . Correct w.r.t. S 1 , complete w.r.t. S 0 1 . [Details � the paper] Inefficient backtracking search. 12 / 25

  22. Intro. Specification Correctness&. . . Programs Final Program 1 (2 (2a) 3) 23 Control (Control details) SAT solver 1 P 1 : sat cnf ([ ]) . sat cnf ([ Clause | Clauses ]) ← sat cl ( Clause ) , sat cnf ( Clauses ) . sat cl ([ Pol - V ar | Pairs ]) ← Pol = V ar. sat cl ([ H | Pairs ]) ← sat cl ( Pairs ) . Can be constructed guided by the sufficient conditions above, and specification ( S 0 1 , S 1 ) . Correct w.r.t. S 1 , complete w.r.t. S 0 1 . [Details � the paper] Inefficient backtracking search. 12 / 25

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