deduction systems - answer-set programming motivation and

146
Artificial Intelligence, Computational Logic DEDUCTION SYSTEMS Answer-Set Programming Motivation and Introduction * slides adapted from Torsten Schaub [Gebser et al.(2012)] Sarah Gaggl Dresden, 27 May 2013

Upload: others

Post on 04-Feb-2022

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Deduction Systems - Answer-Set Programming Motivation and

Artificial Intelligence, Computational Logic

DEDUCTION SYSTEMS

Answer-Set Programming Motivation and Introduction∗

slides adapted from Torsten Schaub [Gebser et al.(2012)]

Sarah Gaggl

Dresden, 27 May 2013

Page 2: Deduction Systems - Answer-Set Programming Motivation and

Agenda1 Motivation

– Declarative Problem Solving– ASP in a Nutshell– ASP Paradigm

2 Introduction– Syntax– Semantics– Examples– Language Constructs– Modeling

TU Dresden, 27 May 2013 Deduction Systems slide 2 of 146

Page 3: Deduction Systems - Answer-Set Programming Motivation and

Informatics

“What is the problem?” versus “How to solve the problem?”

Problem

Computer

Solution

Output?

-

6

TU Dresden, 27 May 2013 Deduction Systems slide 3 of 146

Page 4: Deduction Systems - Answer-Set Programming Motivation and

Informatics

“What is the problem?” versus “How to solve the problem?”

Problem

Computer

Solution

Output?

-

6

TU Dresden, 27 May 2013 Deduction Systems slide 4 of 146

Page 5: Deduction Systems - Answer-Set Programming Motivation and

Traditional programming

“What is the problem?” versus “How to solve the problem?”

Problem

Computer

Solution

Output?

-

6

TU Dresden, 27 May 2013 Deduction Systems slide 5 of 146

Page 6: Deduction Systems - Answer-Set Programming Motivation and

Traditional programming

“What is the problem?” versus “How to solve the problem?”

Problem

Program

Solution

Output?

-

6

Programming Interpreting

Executing

TU Dresden, 27 May 2013 Deduction Systems slide 6 of 146

Page 7: Deduction Systems - Answer-Set Programming Motivation and

Declarative problem solving

“What is the problem?” versus “How to solve the problem?”

Problem

Computer

Solution

Output?

-

6

Interpreting

TU Dresden, 27 May 2013 Deduction Systems slide 7 of 146

Page 8: Deduction Systems - Answer-Set Programming Motivation and

Declarative problem solving

“What is the problem?” versus “How to solve the problem?”

Problem

Representation

Solution

Output?

-

6

Modeling Interpreting

Solving

TU Dresden, 27 May 2013 Deduction Systems slide 8 of 146

Page 9: Deduction Systems - Answer-Set Programming Motivation and

Declarative problem solving

“What is the problem?” versus “How to solve the problem?”

Problem

Representation

Solution

Output?

-

6

Modeling Interpreting

Solving

TU Dresden, 27 May 2013 Deduction Systems slide 9 of 146

Page 10: Deduction Systems - Answer-Set Programming Motivation and

Answer Set Programmingin a Nutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

• ASP has its roots in– (deductive) databases– logic programming (with negation)– (logic-based) knowledge representation and (nonmonotonic)

reasoning– constraint solving (in particular, SATisfiability testing)

• ASP allows for solving all search problems in NP (and NPNP)in a uniform way

• ASP is versatile as reflected by the ASP solver clasp, winningfirst places at ASP, CASC, MISC, PB, and SAT competitions

• ASP embraces many emerging application areas

TU Dresden, 27 May 2013 Deduction Systems slide 10 of 146

Page 11: Deduction Systems - Answer-Set Programming Motivation and

Answer Set Programmingin a Nutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

• ASP has its roots in– (deductive) databases– logic programming (with negation)– (logic-based) knowledge representation and (nonmonotonic)

reasoning– constraint solving (in particular, SATisfiability testing)

• ASP allows for solving all search problems in NP (and NPNP)in a uniform way

• ASP is versatile as reflected by the ASP solver clasp, winningfirst places at ASP, CASC, MISC, PB, and SAT competitions

• ASP embraces many emerging application areas

TU Dresden, 27 May 2013 Deduction Systems slide 11 of 146

Page 12: Deduction Systems - Answer-Set Programming Motivation and

Answer Set Programmingin a Nutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

• ASP has its roots in– (deductive) databases– logic programming (with negation)– (logic-based) knowledge representation and (nonmonotonic)

reasoning– constraint solving (in particular, SATisfiability testing)

• ASP allows for solving all search problems in NP (and NPNP)in a uniform way

• ASP is versatile as reflected by the ASP solver clasp, winningfirst places at ASP, CASC, MISC, PB, and SAT competitions

• ASP embraces many emerging application areas

TU Dresden, 27 May 2013 Deduction Systems slide 12 of 146

Page 13: Deduction Systems - Answer-Set Programming Motivation and

Answer Set Programmingin a Nutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

• ASP has its roots in– (deductive) databases– logic programming (with negation)– (logic-based) knowledge representation and (nonmonotonic)

reasoning– constraint solving (in particular, SATisfiability testing)

• ASP allows for solving all search problems in NP (and NPNP)in a uniform way

• ASP is versatile as reflected by the ASP solver clasp, winningfirst places at ASP, CASC, MISC, PB, and SAT competitions

• ASP embraces many emerging application areas

TU Dresden, 27 May 2013 Deduction Systems slide 13 of 146

Page 14: Deduction Systems - Answer-Set Programming Motivation and

Answer Set Programmingin a Nutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

• ASP has its roots in– (deductive) databases– logic programming (with negation)– (logic-based) knowledge representation and (nonmonotonic)

reasoning– constraint solving (in particular, SATisfiability testing)

• ASP allows for solving all search problems in NP (and NPNP)in a uniform way

• ASP is versatile as reflected by the ASP solver clasp, winningfirst places at ASP, CASC, MISC, PB, and SAT competitions

• ASP embraces many emerging application areas

TU Dresden, 27 May 2013 Deduction Systems slide 14 of 146

Page 15: Deduction Systems - Answer-Set Programming Motivation and

Answer Set Programmingin a Nutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

• ASP has its roots in– (deductive) databases– logic programming (with negation)– (logic-based) knowledge representation and (nonmonotonic)

reasoning– constraint solving (in particular, SATisfiability testing)

• ASP allows for solving all search problems in NP (and NPNP)in a uniform way

• ASP is versatile as reflected by the ASP solver clasp, winningfirst places at ASP, CASC, MISC, PB, and SAT competitions

• ASP embraces many emerging application areas

TU Dresden, 27 May 2013 Deduction Systems slide 15 of 146

Page 16: Deduction Systems - Answer-Set Programming Motivation and

Answer Set Programmingin a Hazelnutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

tailored to Knowledge Representation and Reasoning

TU Dresden, 27 May 2013 Deduction Systems slide 16 of 146

Page 17: Deduction Systems - Answer-Set Programming Motivation and

Answer Set Programmingin a Hazelnutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

tailored to Knowledge Representation and Reasoning

ASP = DB+LP+KR+SAT

TU Dresden, 27 May 2013 Deduction Systems slide 17 of 146

Page 18: Deduction Systems - Answer-Set Programming Motivation and

KR’s shift of paradigm

Theorem Proving based approach (eg. Prolog)1 Provide a representation of the problem2 A solution is given by a derivation of a query

Model Generation based approach (eg. SATisfiability testing)1 Provide a representation of the problem2 A solution is given by a model of the representation

TU Dresden, 27 May 2013 Deduction Systems slide 18 of 146

Page 19: Deduction Systems - Answer-Set Programming Motivation and

KR’s shift of paradigm

Theorem Proving based approach (eg. Prolog)1 Provide a representation of the problem2 A solution is given by a derivation of a query

Model Generation based approach (eg. SATisfiability testing)1 Provide a representation of the problem2 A solution is given by a model of the representation

TU Dresden, 27 May 2013 Deduction Systems slide 19 of 146

Page 20: Deduction Systems - Answer-Set Programming Motivation and

KR’s shift of paradigm

Theorem Proving based approach (eg. Prolog)1 Provide a representation of the problem2 A solution is given by a derivation of a query

Model Generation based approach (eg. SATisfiability testing)1 Provide a representation of the problem2 A solution is given by a model of the representation

TU Dresden, 27 May 2013 Deduction Systems slide 20 of 146

Page 21: Deduction Systems - Answer-Set Programming Motivation and

Model Generation based Problem Solving

Representation Solutionconstraint satisfaction problem assignmentpropositional horn theories smallest modelpropositional theories models

SAT

propositional theories minimal modelspropositional theories stable modelspropositional programs minimal modelspropositional programs supported modelspropositional programs stable modelsfirst-order theories modelsfirst-order theories minimal modelsfirst-order theories stable modelsfirst-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

......

TU Dresden, 27 May 2013 Deduction Systems slide 21 of 146

Page 22: Deduction Systems - Answer-Set Programming Motivation and

Model Generation based Problem Solving

Representation Solutionconstraint satisfaction problem assignmentpropositional horn theories smallest modelpropositional theories models

SAT

propositional theories minimal modelspropositional theories stable modelspropositional programs minimal modelspropositional programs supported modelspropositional programs stable modelsfirst-order theories modelsfirst-order theories minimal modelsfirst-order theories stable modelsfirst-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

......

TU Dresden, 27 May 2013 Deduction Systems slide 22 of 146

Page 23: Deduction Systems - Answer-Set Programming Motivation and

Model Generation based Problem Solving

Representation Solutionconstraint satisfaction problem assignmentpropositional horn theories smallest modelpropositional theories models SATpropositional theories minimal modelspropositional theories stable modelspropositional programs minimal modelspropositional programs supported modelspropositional programs stable modelsfirst-order theories modelsfirst-order theories minimal modelsfirst-order theories stable modelsfirst-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

......

TU Dresden, 27 May 2013 Deduction Systems slide 23 of 146

Page 24: Deduction Systems - Answer-Set Programming Motivation and

LP-style playing with blocks

Prolog programon(a,b).on(b,c).

above(X,Y) :- on(X,Y).above(X,Y) :- on(X,Z), above(Z,Y).

Prolog queries?- above(a,c).true.

?- above(c,a).no.

TU Dresden, 27 May 2013 Deduction Systems slide 24 of 146

Page 25: Deduction Systems - Answer-Set Programming Motivation and

LP-style playing with blocks

Prolog programon(a,b).on(b,c).

above(X,Y) :- on(X,Y).above(X,Y) :- on(X,Z), above(Z,Y).

Prolog queries?- above(a,c).true.

?- above(c,a).no.

TU Dresden, 27 May 2013 Deduction Systems slide 25 of 146

Page 26: Deduction Systems - Answer-Set Programming Motivation and

LP-style playing with blocks

Prolog programon(a,b).on(b,c).

above(X,Y) :- on(X,Y).above(X,Y) :- on(X,Z), above(Z,Y).

Prolog queries?- above(a,c).true.

?- above(c,a).no.

TU Dresden, 27 May 2013 Deduction Systems slide 26 of 146

Page 27: Deduction Systems - Answer-Set Programming Motivation and

LP-style playing with blocks

Prolog programon(a,b).on(b,c).

above(X,Y) :- on(X,Y).above(X,Y) :- on(X,Z), above(Z,Y).

Prolog queries (testing entailment)?- above(a,c).true.

?- above(c,a).no.

TU Dresden, 27 May 2013 Deduction Systems slide 27 of 146

Page 28: Deduction Systems - Answer-Set Programming Motivation and

LP-style playing with blocks

Shuffled Prolog programon(a,b).on(b,c).

above(X,Y) :- above(X,Z), on(Z,Y).above(X,Y) :- on(X,Y).

Prolog queries?- above(a,c).

Fatal Error: local stack overflow.

TU Dresden, 27 May 2013 Deduction Systems slide 28 of 146

Page 29: Deduction Systems - Answer-Set Programming Motivation and

LP-style playing with blocks

Shuffled Prolog programon(a,b).on(b,c).

above(X,Y) :- above(X,Z), on(Z,Y).above(X,Y) :- on(X,Y).

Prolog queries?- above(a,c).

Fatal Error: local stack overflow.

TU Dresden, 27 May 2013 Deduction Systems slide 29 of 146

Page 30: Deduction Systems - Answer-Set Programming Motivation and

LP-style playing with blocks

Shuffled Prolog programon(a,b).on(b,c).

above(X,Y) :- above(X,Z), on(Z,Y).above(X,Y) :- on(X,Y).

Prolog queries (answered via fixed execution)?- above(a,c).

Fatal Error: local stack overflow.

TU Dresden, 27 May 2013 Deduction Systems slide 30 of 146

Page 31: Deduction Systems - Answer-Set Programming Motivation and

SAT-style playing with blocks

Formula

on(a, b)∧ on(b, c)∧ (on(X, Y)→ above(X, Y))∧ (on(X, Z) ∧ above(Z, Y)→ above(X, Y))

Herbrand model{

on(a, b), on(b, c), on(a, c), on(b, b),above(a, b), above(b, c), above(a, c), above(b, b), above(c, b)

}

TU Dresden, 27 May 2013 Deduction Systems slide 31 of 146

Page 32: Deduction Systems - Answer-Set Programming Motivation and

SAT-style playing with blocks

Formula

on(a, b)∧ on(b, c)∧ (on(X, Y)→ above(X, Y))∧ (on(X, Z) ∧ above(Z, Y)→ above(X, Y))

Herbrand model{

on(a, b), on(b, c), on(a, c), on(b, b),above(a, b), above(b, c), above(a, c), above(b, b), above(c, b)

}

TU Dresden, 27 May 2013 Deduction Systems slide 32 of 146

Page 33: Deduction Systems - Answer-Set Programming Motivation and

SAT-style playing with blocks

Formula

on(a, b)∧ on(b, c)∧ (on(X, Y)→ above(X, Y))∧ (on(X, Z) ∧ above(Z, Y)→ above(X, Y))

Herbrand model (among 426!){

on(a, b), on(b, c), on(a, c), on(b, b),above(a, b), above(b, c), above(a, c), above(b, b), above(c, b)

}

TU Dresden, 27 May 2013 Deduction Systems slide 33 of 146

Page 34: Deduction Systems - Answer-Set Programming Motivation and

SAT-style playing with blocks

Formula

on(a, b)∧ on(b, c)∧ (on(X, Y)→ above(X, Y))∧ (on(X, Z) ∧ above(Z, Y)→ above(X, Y))

Herbrand model (among 426!){

on(a, b), on(b, c), on(a, c), on(b, b),above(a, b), above(b, c), above(a, c), above(b, b), above(c, b)

}

TU Dresden, 27 May 2013 Deduction Systems slide 34 of 146

Page 35: Deduction Systems - Answer-Set Programming Motivation and

SAT-style playing with blocks

Formula

on(a, b)∧ on(b, c)∧ (on(X, Y)→ above(X, Y))∧ (on(X, Z) ∧ above(Z, Y)→ above(X, Y))

Herbrand model (among 426!){

on(a, b), on(b, c), on(a, c), on(b, b),above(a, b), above(b, c), above(a, c), above(b, b), above(c, b)

}

TU Dresden, 27 May 2013 Deduction Systems slide 35 of 146

Page 36: Deduction Systems - Answer-Set Programming Motivation and

KR’s shift of paradigm

Theorem Proving based approach (eg. Prolog)1 Provide a representation of the problem2 A solution is given by a derivation of a query

Model Generation based approach (eg. SATisfiability testing)1 Provide a representation of the problem2 A solution is given by a model of the representation

TU Dresden, 27 May 2013 Deduction Systems slide 36 of 146

Page 37: Deduction Systems - Answer-Set Programming Motivation and

KR’s shift of paradigm

Theorem Proving based approach (eg. Prolog)1 Provide a representation of the problem2 A solution is given by a derivation of a query

Model Generation based approach (eg. SATisfiability testing)1 Provide a representation of the problem2 A solution is given by a model of the representation

å Answer Set Programming (ASP)

TU Dresden, 27 May 2013 Deduction Systems slide 37 of 146

Page 38: Deduction Systems - Answer-Set Programming Motivation and

Model Generation based Problem Solving

Representation Solutionconstraint satisfaction problem assignmentpropositional horn theories smallest modelpropositional theories modelspropositional theories minimal modelspropositional theories stable modelspropositional programs minimal modelspropositional programs supported modelspropositional programs stable modelsfirst-order theories modelsfirst-order theories minimal modelsfirst-order theories stable modelsfirst-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

......

TU Dresden, 27 May 2013 Deduction Systems slide 38 of 146

Page 39: Deduction Systems - Answer-Set Programming Motivation and

Answer Set Programming at large

Representation Solution

constraint satisfaction problem assignment

propositional horn theories smallest modelpropositional theories modelspropositional theories minimal modelspropositional theories stable modelspropositional programs minimal modelspropositional programs supported modelspropositional programs stable modelsfirst-order theories modelsfirst-order theories minimal modelsfirst-order theories stable modelsfirst-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

......

TU Dresden, 27 May 2013 Deduction Systems slide 39 of 146

Page 40: Deduction Systems - Answer-Set Programming Motivation and

Answer Set Programming commonly

Representation Solution

constraint satisfaction problem assignmentpropositional horn theories smallest modelpropositional theories modelspropositional theories minimal models

propositional theories stable models

propositional programs minimal modelspropositional programs supported models

propositional programs stable models

first-order theories modelsfirst-order theories minimal models

first-order theories stable models

first-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

......

TU Dresden, 27 May 2013 Deduction Systems slide 40 of 146

Page 41: Deduction Systems - Answer-Set Programming Motivation and

Answer Set Programming in practice

Representation Solution

constraint satisfaction problem assignmentpropositional horn theories smallest modelpropositional theories modelspropositional theories minimal modelspropositional theories stable modelspropositional programs minimal modelspropositional programs supported models

propositional programs stable models

first-order theories modelsfirst-order theories minimal modelsfirst-order theories stable modelsfirst-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

......

TU Dresden, 27 May 2013 Deduction Systems slide 41 of 146

Page 42: Deduction Systems - Answer-Set Programming Motivation and

Answer Set Programming in practice

Representation Solution

constraint satisfaction problem assignmentpropositional horn theories smallest modelpropositional theories modelspropositional theories minimal modelspropositional theories stable modelspropositional programs minimal modelspropositional programs supported models

propositional programs stable models

first-order theories modelsfirst-order theories minimal modelsfirst-order theories stable modelsfirst-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

first-order programs stable Herbrand models

TU Dresden, 27 May 2013 Deduction Systems slide 42 of 146

Page 43: Deduction Systems - Answer-Set Programming Motivation and

ASP-style playing with blocks

Logic programon(a,b).on(b,c).

above(X,Y) :- on(X,Y).above(X,Y) :- on(X,Z), above(Z,Y).

Stable Herbrand model

{ on(a,b), on(b,c), above(b,c), above(a,b), above(a,c) }

TU Dresden, 27 May 2013 Deduction Systems slide 43 of 146

Page 44: Deduction Systems - Answer-Set Programming Motivation and

ASP-style playing with blocks

Logic programon(a,b).on(b,c).

above(X,Y) :- on(X,Y).above(X,Y) :- on(X,Z), above(Z,Y).

Stable Herbrand model

{ on(a,b), on(b,c), above(b,c), above(a,b), above(a,c) }

TU Dresden, 27 May 2013 Deduction Systems slide 44 of 146

Page 45: Deduction Systems - Answer-Set Programming Motivation and

ASP-style playing with blocks

Logic programon(a,b).on(b,c).

above(X,Y) :- on(X,Y).above(X,Y) :- on(X,Z), above(Z,Y).

Stable Herbrand model (and no others)

{ on(a,b), on(b,c), above(b,c), above(a,b), above(a,c) }

TU Dresden, 27 May 2013 Deduction Systems slide 45 of 146

Page 46: Deduction Systems - Answer-Set Programming Motivation and

ASP-style playing with blocks

Logic programon(a,b).on(b,c).

above(X,Y) :- above(Z,Y), on(X,Z).above(X,Y) :- on(X,Y).

Stable Herbrand model (and no others)

{ on(a,b), on(b,c), above(b,c), above(a,b), above(a,c) }

TU Dresden, 27 May 2013 Deduction Systems slide 46 of 146

Page 47: Deduction Systems - Answer-Set Programming Motivation and

ASP versus LP

ASP Prolog

Model generation Query orientationBottom-up Top-downModeling language Programming language

Rule-based formatInstantiation UnificationFlat terms Nested terms

(Turing +) NP(NP) Turing

TU Dresden, 27 May 2013 Deduction Systems slide 47 of 146

Page 48: Deduction Systems - Answer-Set Programming Motivation and

ASP versus SAT

ASP SAT

Model generationBottom-up

Constructive Logic Classical LogicClosed (and open) Open world reasoning

world reasoningModeling language —Complex reasoning modes Satisfiability testing

Satisfiability SatisfiabilityEnumeration/Projection —Optimization —Intersection/Union —

(Turing +) NP(NP) NP

TU Dresden, 27 May 2013 Deduction Systems slide 48 of 146

Page 49: Deduction Systems - Answer-Set Programming Motivation and

ASP solving

Problem

LogicProgram Grounder Solver Stable

Models

Solution

- - -

?

6

Modeling Interpreting

Solving

TU Dresden, 27 May 2013 Deduction Systems slide 49 of 146

Page 50: Deduction Systems - Answer-Set Programming Motivation and

SAT solving

Problem

Formula(CNF) Solver Classical

Models

Solution

- -

?

6

Programming Interpreting

Solving

TU Dresden, 27 May 2013 Deduction Systems slide 50 of 146

Page 51: Deduction Systems - Answer-Set Programming Motivation and

Rooting ASP solving

Problem

LogicProgram Grounder Solver Stable

Models

Solution

- - -

?

6

Modeling Interpreting

Solving

TU Dresden, 27 May 2013 Deduction Systems slide 51 of 146

Page 52: Deduction Systems - Answer-Set Programming Motivation and

Rooting ASP solving

Problem

LogicProgram

LP

Grounder

DB

Solver

SAT

StableModels

DB+KR+LP

Solution

- - -

?

6

Modeling KR Interpreting

Solving

TU Dresden, 27 May 2013 Deduction Systems slide 52 of 146

Page 53: Deduction Systems - Answer-Set Programming Motivation and

Two sides of a coin

• ASP as High-level Language– Express problem instance(s) as sets of facts– Encode problem (class) as a set of rules– Read off solutions from stable models of facts and rules

• ASP as Low-level Language– Compile a problem into a logic program– Solve the original problem by solving its compilation

TU Dresden, 27 May 2013 Deduction Systems slide 53 of 146

Page 54: Deduction Systems - Answer-Set Programming Motivation and

What is ASP good for?• Combinatorial search problems in the realm of P, NP, and NPNP

(some with substantial amount of data), like

– Automated Planning– Code Optimization– Composition of Renaissance Music– Database Integration– Decision Support for NASA shuttle controllers– Model Checking– Product Configuration– Robotics– System Biology– System Synthesis– (industrial) Team-building– and many many more

TU Dresden, 27 May 2013 Deduction Systems slide 54 of 146

Page 55: Deduction Systems - Answer-Set Programming Motivation and

What is ASP good for?• Combinatorial search problems in the realm of P, NP, and NPNP

(some with substantial amount of data), like– Automated Planning– Code Optimization– Composition of Renaissance Music– Database Integration– Decision Support for NASA shuttle controllers– Model Checking– Product Configuration– Robotics– System Biology– System Synthesis– (industrial) Team-building– and many many more

TU Dresden, 27 May 2013 Deduction Systems slide 55 of 146

Page 56: Deduction Systems - Answer-Set Programming Motivation and

What does ASP offer?

• Integration of DB, KR, and SAT techniques

• Succinct, elaboration-tolerant problem representations– Rapid application development tool

• Easy handling of dynamic, knowledge intensive applications– including: data, frame axioms, exceptions, defaults, closures, etc

ASP = DB+LP+KR+SAT

TU Dresden, 27 May 2013 Deduction Systems slide 56 of 146

Page 57: Deduction Systems - Answer-Set Programming Motivation and

What does ASP offer?

• Integration of DB, KR, and SAT techniques

• Succinct, elaboration-tolerant problem representations– Rapid application development tool

• Easy handling of dynamic, knowledge intensive applications– including: data, frame axioms, exceptions, defaults, closures, etc

ASP = DB+LP+KR+SAT

TU Dresden, 27 May 2013 Deduction Systems slide 57 of 146

Page 58: Deduction Systems - Answer-Set Programming Motivation and

Agenda1 Motivation

– Declarative Problem Solving– ASP in a Nutshell– ASP Paradigm

2 Introduction– Syntax– Semantics– Examples– Language Constructs– Modeling

TU Dresden, 27 May 2013 Deduction Systems slide 58 of 146

Page 59: Deduction Systems - Answer-Set Programming Motivation and

Problem solving in ASP: Syntax

Problem

Logic Program

Solution

Stable Models

?-

6

Modeling Interpreting

Solving

TU Dresden, 27 May 2013 Deduction Systems slide 59 of 146

Page 60: Deduction Systems - Answer-Set Programming Motivation and

Normal logic programs• A (normal) logic program over a set A of atoms is a finite set of rules• A (normal) rule, r, is of the form

a0 ← a1, . . . , am, not am+1, . . . , not an

where 0 ≤ m ≤ n and each ai ∈ A is an atom for 0 ≤ i ≤ n

• Notation

head(r) = a0

body(r) = {a1, . . . , am, not am+1, . . . , not an}body(r)+ = {a1, . . . , am}body(r)− = {am+1, . . . , an}

• A program is called positive if body(r)− = ∅ for all its rules

TU Dresden, 27 May 2013 Deduction Systems slide 60 of 146

Page 61: Deduction Systems - Answer-Set Programming Motivation and

Normal logic programs• A (normal) logic program over a set A of atoms is a finite set of rules• A (normal) rule, r, is of the form

a0 ← a1, . . . , am, not am+1, . . . , not an

where 0 ≤ m ≤ n and each ai ∈ A is an atom for 0 ≤ i ≤ n

• Notation

head(r) = a0

body(r) = {a1, . . . , am, not am+1, . . . , not an}body(r)+ = {a1, . . . , am}body(r)− = {am+1, . . . , an}

• A program is called positive if body(r)− = ∅ for all its rules

TU Dresden, 27 May 2013 Deduction Systems slide 61 of 146

Page 62: Deduction Systems - Answer-Set Programming Motivation and

Normal logic programs• A (normal) logic program over a set A of atoms is a finite set of rules• A (normal) rule, r, is of the form

a0 ← a1, . . . , am, not am+1, . . . , not an

where 0 ≤ m ≤ n and each ai ∈ A is an atom for 0 ≤ i ≤ n

• Notation

head(r) = a0

body(r) = {a1, . . . , am, not am+1, . . . , not an}body(r)+ = {a1, . . . , am}body(r)− = {am+1, . . . , an}

• A program is called positive if body(r)− = ∅ for all its rules

TU Dresden, 27 May 2013 Deduction Systems slide 62 of 146

Page 63: Deduction Systems - Answer-Set Programming Motivation and

Rough notational convention

We sometimes use the following notation interchangeablyin order to stress the respective view:

default classicaltrue, false if and or iff negation negation

source code :- , | not -logic program ← , ; not ¬formula ⊥,> → ∧ ∨ ↔ ∼ ¬

TU Dresden, 27 May 2013 Deduction Systems slide 63 of 146

Page 64: Deduction Systems - Answer-Set Programming Motivation and

Problem solving in ASP: Semantics

Problem

Logic Program

Solution

Stable Models

?-

6

Modeling Interpreting

Solving

TU Dresden, 27 May 2013 Deduction Systems slide 64 of 146

Page 65: Deduction Systems - Answer-Set Programming Motivation and

Formal DefinitionStable models of positive programs

• A set of atoms X is closed under a positive program P ifffor any r ∈ P, head(r) ∈ X whenever body(r)+ ⊆ X

– X corresponds to a model of P (seen as a formula)

• The smallest set of atoms which is closed under a positive program P isdenoted by Cn(P)

– Cn(P) corresponds to the ⊆-smallest model of P (ditto)

• The set Cn(P) of atoms is the stable model of a positive program P

TU Dresden, 27 May 2013 Deduction Systems slide 65 of 146

Page 66: Deduction Systems - Answer-Set Programming Motivation and

Formal DefinitionStable models of positive programs

• A set of atoms X is closed under a positive program P ifffor any r ∈ P, head(r) ∈ X whenever body(r)+ ⊆ X

– X corresponds to a model of P (seen as a formula)

• The smallest set of atoms which is closed under a positive program P isdenoted by Cn(P)

– Cn(P) corresponds to the ⊆-smallest model of P (ditto)

• The set Cn(P) of atoms is the stable model of a positive program P

TU Dresden, 27 May 2013 Deduction Systems slide 66 of 146

Page 67: Deduction Systems - Answer-Set Programming Motivation and

Formal DefinitionStable models of positive programs

• A set of atoms X is closed under a positive program P ifffor any r ∈ P, head(r) ∈ X whenever body(r)+ ⊆ X

– X corresponds to a model of P (seen as a formula)

• The smallest set of atoms which is closed under a positive program P isdenoted by Cn(P)

– Cn(P) corresponds to the ⊆-smallest model of P (ditto)

• The set Cn(P) of atoms is the stable model of a positive program P

TU Dresden, 27 May 2013 Deduction Systems slide 67 of 146

Page 68: Deduction Systems - Answer-Set Programming Motivation and

Formal DefinitionStable models of positive programs

• A set of atoms X is closed under a positive program P ifffor any r ∈ P, head(r) ∈ X whenever body(r)+ ⊆ X

– X corresponds to a model of P (seen as a formula)

• The smallest set of atoms which is closed under a positive program P isdenoted by Cn(P)

– Cn(P) corresponds to the ⊆-smallest model of P (ditto)

• The set Cn(P) of atoms is the stable model of a positive program P

TU Dresden, 27 May 2013 Deduction Systems slide 68 of 146

Page 69: Deduction Systems - Answer-Set Programming Motivation and

Some “logical” remarks• Positive rules are also referred to as definite clauses

– Definite clauses are disjunctions with exactly one positive atom:

a0 ∨ ¬a1 ∨ · · · ∨ ¬am

– A set of definite clauses has a (unique) smallest model

• Horn clauses are clauses with at most one positive atom– Every definite clause is a Horn clause but not vice versa– Non-definite Horn clauses can be regarded as integrity constraints

– A set of Horn clauses has a smallest model or none

• This smallest model is the intended semantics of such sets of clauses– Given a positive program P, Cn(P) corresponds to the smallest

model of the set of definite clauses corresponding to P

TU Dresden, 27 May 2013 Deduction Systems slide 69 of 146

Page 70: Deduction Systems - Answer-Set Programming Motivation and

Some “logical” remarks• Positive rules are also referred to as definite clauses

– Definite clauses are disjunctions with exactly one positive atom:

a0 ∨ ¬a1 ∨ · · · ∨ ¬am

– A set of definite clauses has a (unique) smallest model

• Horn clauses are clauses with at most one positive atom– Every definite clause is a Horn clause but not vice versa– Non-definite Horn clauses can be regarded as integrity constraints

– A set of Horn clauses has a smallest model or none

• This smallest model is the intended semantics of such sets of clauses– Given a positive program P, Cn(P) corresponds to the smallest

model of the set of definite clauses corresponding to P

TU Dresden, 27 May 2013 Deduction Systems slide 70 of 146

Page 71: Deduction Systems - Answer-Set Programming Motivation and

Some “logical” remarks• Positive rules are also referred to as definite clauses

– Definite clauses are disjunctions with exactly one positive atom:

a0 ∨ ¬a1 ∨ · · · ∨ ¬am

– A set of definite clauses has a (unique) smallest model

• Horn clauses are clauses with at most one positive atom– Every definite clause is a Horn clause but not vice versa– Non-definite Horn clauses can be regarded as integrity constraints

– A set of Horn clauses has a smallest model or none

• This smallest model is the intended semantics of such sets of clauses– Given a positive program P, Cn(P) corresponds to the smallest

model of the set of definite clauses corresponding to P

TU Dresden, 27 May 2013 Deduction Systems slide 71 of 146

Page 72: Deduction Systems - Answer-Set Programming Motivation and

Basic idea

Consider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

TU Dresden, 27 May 2013 Deduction Systems slide 72 of 146

Page 73: Deduction Systems - Answer-Set Programming Motivation and

Basic ideaConsider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

TU Dresden, 27 May 2013 Deduction Systems slide 73 of 146

Page 74: Deduction Systems - Answer-Set Programming Motivation and

Basic ideaConsider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

TU Dresden, 27 May 2013 Deduction Systems slide 74 of 146

Page 75: Deduction Systems - Answer-Set Programming Motivation and

Basic ideaConsider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

TU Dresden, 27 May 2013 Deduction Systems slide 75 of 146

Page 76: Deduction Systems - Answer-Set Programming Motivation and

Basic ideaConsider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

TU Dresden, 27 May 2013 Deduction Systems slide 76 of 146

Page 77: Deduction Systems - Answer-Set Programming Motivation and

Basic ideaConsider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

TU Dresden, 27 May 2013 Deduction Systems slide 77 of 146

Page 78: Deduction Systems - Answer-Set Programming Motivation and

Basic ideaConsider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

TU Dresden, 27 May 2013 Deduction Systems slide 78 of 146

Page 79: Deduction Systems - Answer-Set Programming Motivation and

Basic idea

Consider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

TU Dresden, 27 May 2013 Deduction Systems slide 79 of 146

Page 80: Deduction Systems - Answer-Set Programming Motivation and

Formal DefinitionStable model of normal programs

• The Gelfond-Lifschitz Reduct[Gelfond and Lifschitz(1991)], PX , of aprogram P relative to a set X of atoms is defined by

PX = {head(r)← body(r)+ | r ∈ P and body(r)− ∩ X = ∅}

• A set X of atoms is a stable model of a program P, if Cn(PX) = X

• Note: Cn(PX) is the ⊆–smallest (classical) model of PX

• Note: Every atom in X is justified by an “applying rule from P”

TU Dresden, 27 May 2013 Deduction Systems slide 80 of 146

Page 81: Deduction Systems - Answer-Set Programming Motivation and

Formal DefinitionStable model of normal programs

• The Gelfond-Lifschitz Reduct[Gelfond and Lifschitz(1991)], PX , of aprogram P relative to a set X of atoms is defined by

PX = {head(r)← body(r)+ | r ∈ P and body(r)− ∩ X = ∅}

• A set X of atoms is a stable model of a program P, if Cn(PX) = X

• Note: Cn(PX) is the ⊆–smallest (classical) model of PX

• Note: Every atom in X is justified by an “applying rule from P”

TU Dresden, 27 May 2013 Deduction Systems slide 81 of 146

Page 82: Deduction Systems - Answer-Set Programming Motivation and

Formal DefinitionStable model of normal programs

• The Gelfond-Lifschitz Reduct[Gelfond and Lifschitz(1991)], PX , of aprogram P relative to a set X of atoms is defined by

PX = {head(r)← body(r)+ | r ∈ P and body(r)− ∩ X = ∅}

• A set X of atoms is a stable model of a program P, if Cn(PX) = X

• Note: Cn(PX) is the ⊆–smallest (classical) model of PX

• Note: Every atom in X is justified by an “applying rule from P”

TU Dresden, 27 May 2013 Deduction Systems slide 82 of 146

Page 83: Deduction Systems - Answer-Set Programming Motivation and

A closer look at PX

• In other words, given a set X of atoms from P,

PX is obtained from P by deleting1 each rule having not a in its body with a ∈ X

and then2 all negative atoms of the form not a

in the bodies of the remaining rules

• Note: Only negative body literals are evaluated w.r.t. X

TU Dresden, 27 May 2013 Deduction Systems slide 83 of 146

Page 84: Deduction Systems - Answer-Set Programming Motivation and

A closer look at PX

• In other words, given a set X of atoms from P,

PX is obtained from P by deleting1 each rule having not a in its body with a ∈ X

and then2 all negative atoms of the form not a

in the bodies of the remaining rules

• Note: Only negative body literals are evaluated w.r.t. X

TU Dresden, 27 May 2013 Deduction Systems slide 84 of 146

Page 85: Deduction Systems - Answer-Set Programming Motivation and

A first example

P = {p← p, q← not p}

X

PX

Cn(PX)∅

p ← pq ←

{q} 8

{p}

p ← p ∅ 8

{q}

p ← pq ←

{q} 4

{p, q}

p ← p ∅ 8

TU Dresden, 27 May 2013 Deduction Systems slide 85 of 146

Page 86: Deduction Systems - Answer-Set Programming Motivation and

A first example

P = {p← p, q← not p}

X

PX

Cn(PX)∅

p ← pq ←

{q} 8

{p}

p ← p ∅ 8

{q}

p ← pq ←

{q} 4

{p, q}

p ← p ∅ 8

TU Dresden, 27 May 2013 Deduction Systems slide 86 of 146

Page 87: Deduction Systems - Answer-Set Programming Motivation and

A first example

P = {p← p, q← not p}

X PX Cn(PX)∅ p ← p

q ←{q}

8

{p} p ← p ∅

8

{q} p ← pq ←

{q}

4

{p, q} p ← p ∅

8

TU Dresden, 27 May 2013 Deduction Systems slide 87 of 146

Page 88: Deduction Systems - Answer-Set Programming Motivation and

A first example

P = {p← p, q← not p}

X PX Cn(PX)∅ p ← p

q ←{q} 8

{p} p ← p ∅

8

{q} p ← pq ←

{q}

4

{p, q} p ← p ∅

8

TU Dresden, 27 May 2013 Deduction Systems slide 88 of 146

Page 89: Deduction Systems - Answer-Set Programming Motivation and

A first example

P = {p← p, q← not p}

X PX Cn(PX)∅ p ← p

q ←{q} 8

{p} p ← p ∅ 8

{q} p ← pq ←

{q}

4

{p, q} p ← p ∅

8

TU Dresden, 27 May 2013 Deduction Systems slide 89 of 146

Page 90: Deduction Systems - Answer-Set Programming Motivation and

A first example

P = {p← p, q← not p}

X PX Cn(PX)∅ p ← p

q ←{q} 8

{p} p ← p ∅ 8

{q} p ← pq ←

{q} 4

{p, q} p ← p ∅

8

TU Dresden, 27 May 2013 Deduction Systems slide 90 of 146

Page 91: Deduction Systems - Answer-Set Programming Motivation and

A first example

P = {p← p, q← not p}

X PX Cn(PX)∅ p ← p

q ←{q} 8

{p} p ← p ∅ 8

{q} p ← pq ←

{q} 4

{p, q} p ← p ∅ 8

TU Dresden, 27 May 2013 Deduction Systems slide 91 of 146

Page 92: Deduction Systems - Answer-Set Programming Motivation and

A second example

P = {p← not q, q← not p}

X PX Cn(PX)∅ p ←

q ←{p, q}

8

{p} p ← {p}

4

{q}q ←

{q}

4

{p, q} ∅

8

TU Dresden, 27 May 2013 Deduction Systems slide 92 of 146

Page 93: Deduction Systems - Answer-Set Programming Motivation and

A second example

P = {p← not q, q← not p}

X PX Cn(PX)∅ p ←

q ←{p, q}

8

{p} p ← {p}

4

{q}q ←

{q}

4

{p, q} ∅

8

TU Dresden, 27 May 2013 Deduction Systems slide 93 of 146

Page 94: Deduction Systems - Answer-Set Programming Motivation and

A second example

P = {p← not q, q← not p}

X PX Cn(PX)∅ p ←

q ←{p, q} 8

{p} p ← {p}

4

{q}q ←

{q}

4

{p, q} ∅

8

TU Dresden, 27 May 2013 Deduction Systems slide 94 of 146

Page 95: Deduction Systems - Answer-Set Programming Motivation and

A second example

P = {p← not q, q← not p}

X PX Cn(PX)∅ p ←

q ←{p, q} 8

{p} p ← {p} 4

{q}q ←

{q}

4

{p, q} ∅

8

TU Dresden, 27 May 2013 Deduction Systems slide 95 of 146

Page 96: Deduction Systems - Answer-Set Programming Motivation and

A second example

P = {p← not q, q← not p}

X PX Cn(PX)∅ p ←

q ←{p, q} 8

{p} p ← {p} 4

{q}q ←

{q} 4

{p, q} ∅

8

TU Dresden, 27 May 2013 Deduction Systems slide 96 of 146

Page 97: Deduction Systems - Answer-Set Programming Motivation and

A second example

P = {p← not q, q← not p}

X PX Cn(PX)∅ p ←

q ←{p, q} 8

{p} p ← {p} 4

{q}q ←

{q} 4

{p, q} ∅ 8

TU Dresden, 27 May 2013 Deduction Systems slide 97 of 146

Page 98: Deduction Systems - Answer-Set Programming Motivation and

A third example

P = {p← not p}

X PX Cn(PX)∅ p ← {p}

8

{p} ∅

8

TU Dresden, 27 May 2013 Deduction Systems slide 98 of 146

Page 99: Deduction Systems - Answer-Set Programming Motivation and

A third example

P = {p← not p}

X PX Cn(PX)∅ p ← {p}

8

{p} ∅

8

TU Dresden, 27 May 2013 Deduction Systems slide 99 of 146

Page 100: Deduction Systems - Answer-Set Programming Motivation and

A third example

P = {p← not p}

X PX Cn(PX)∅ p ← {p} 8

{p} ∅

8

TU Dresden, 27 May 2013 Deduction Systems slide 100 of 146

Page 101: Deduction Systems - Answer-Set Programming Motivation and

A third example

P = {p← not p}

X PX Cn(PX)∅ p ← {p} 8

{p} ∅ 8

TU Dresden, 27 May 2013 Deduction Systems slide 101 of 146

Page 102: Deduction Systems - Answer-Set Programming Motivation and

Some properties

• A logic program may have zero, one, or multiple stable models!

• If X is an stable model of a logic program P,then X is a model of P (seen as a formula)

• If X and Y are stable models of a normal program P,then X 6⊂ Y

TU Dresden, 27 May 2013 Deduction Systems slide 102 of 146

Page 103: Deduction Systems - Answer-Set Programming Motivation and

Some properties

• A logic program may have zero, one, or multiple stable models!• If X is an stable model of a logic program P,

then X is a model of P (seen as a formula)• If X and Y are stable models of a normal program P,

then X 6⊂ Y

TU Dresden, 27 May 2013 Deduction Systems slide 103 of 146

Page 104: Deduction Systems - Answer-Set Programming Motivation and

Programs with Variables

Let P be a logic program• Let T be a set of (variable-free) terms

(also called Herbrand universe)

• Let A be a set of (variable-free) atoms constructable from T

(also called alphabet or Herbrand base)• Ground Instances of r ∈ P: Set of variable-free rules obtained by

replacing all variables in r by elements from T :

ground(r) = {rθ | θ : var(r)→ T , var(rθ) = ∅}

where var(r) stands for the set of all variables occurring in r;θ is a (ground) substitution

• Ground Instantiation of P: ground(P) =⋃

r∈Pground(r)

TU Dresden, 27 May 2013 Deduction Systems slide 104 of 146

Page 105: Deduction Systems - Answer-Set Programming Motivation and

Programs with Variables

Let P be a logic program• Let T be a set of

(

variable-free

)

terms (also called Herbrand universe)• Let A be a set of (variable-free) atoms constructable from T

(also called alphabet or Herbrand base)

• Ground Instances of r ∈ P: Set of variable-free rules obtained byreplacing all variables in r by elements from T :

ground(r) = {rθ | θ : var(r)→ T , var(rθ) = ∅}

where var(r) stands for the set of all variables occurring in r;θ is a (ground) substitution

• Ground Instantiation of P: ground(P) =⋃

r∈Pground(r)

TU Dresden, 27 May 2013 Deduction Systems slide 105 of 146

Page 106: Deduction Systems - Answer-Set Programming Motivation and

Programs with Variables

Let P be a logic program• Let T be a set of (variable-free) terms

(also called Herbrand universe)

• Let A be a set of (variable-free) atoms constructable from T

(also called alphabet or Herbrand base)

• Ground Instances of r ∈ P: Set of variable-free rules obtained byreplacing all variables in r by elements from T :

ground(r) = {rθ | θ : var(r)→ T , var(rθ) = ∅}

where var(r) stands for the set of all variables occurring in r;θ is a (ground) substitution

• Ground Instantiation of P: ground(P) =⋃

r∈Pground(r)

TU Dresden, 27 May 2013 Deduction Systems slide 106 of 146

Page 107: Deduction Systems - Answer-Set Programming Motivation and

Programs with Variables

Let P be a logic program• Let T be a set of (variable-free) terms

(also called Herbrand universe)

• Let A be a set of (variable-free) atoms constructable from T

(also called alphabet or Herbrand base)

• Ground Instances of r ∈ P: Set of variable-free rules obtained byreplacing all variables in r by elements from T :

ground(r) = {rθ | θ : var(r)→ T , var(rθ) = ∅}

where var(r) stands for the set of all variables occurring in r;θ is a (ground) substitution

• Ground Instantiation of P: ground(P) =⋃

r∈Pground(r)

TU Dresden, 27 May 2013 Deduction Systems slide 107 of 146

Page 108: Deduction Systems - Answer-Set Programming Motivation and

An example

P= { r(a, b)←, r(b, c)←, t(X, Y)← r(X, Y) }

T = {a, b, c}

A=

{r(a, a), r(a, b), r(a, c), r(b, a), r(b, b), r(b, c), r(c, a), r(c, b), r(c, c),t(a, a), t(a, b), t(a, c), t(b, a), t(b, b), t(b, c), t(c, a), t(c, b), t(c, c)

}

ground(P) =

r(a, b) ← ,r(b, c) ← ,t(a, a) ← r(a, a), t(b, a) ← r(b, a), t(c, a) ← r(c, a),t(a, b) ← r(a, b), t(b, b) ← r(b, b), t(c, b) ← r(c, b),t(a, c) ← r(a, c), t(b, c) ← r(b, c), t(c, c) ← r(c, c)

• Intelligent Grounding aims at reducing the groundinstantiation

TU Dresden, 27 May 2013 Deduction Systems slide 108 of 146

Page 109: Deduction Systems - Answer-Set Programming Motivation and

An example

P= { r(a, b)←, r(b, c)←, t(X, Y)← r(X, Y) }

T = {a, b, c}

A=

{r(a, a), r(a, b), r(a, c), r(b, a), r(b, b), r(b, c), r(c, a), r(c, b), r(c, c),t(a, a), t(a, b), t(a, c), t(b, a), t(b, b), t(b, c), t(c, a), t(c, b), t(c, c)

}

ground(P) =

r(a, b) ← ,r(b, c) ← ,t(a, a) ← r(a, a), t(b, a) ← r(b, a), t(c, a) ← r(c, a),t(a, b) ← r(a, b), t(b, b) ← r(b, b), t(c, b) ← r(c, b),t(a, c) ← r(a, c), t(b, c) ← r(b, c), t(c, c) ← r(c, c)

• Intelligent Grounding aims at reducing the groundinstantiation

TU Dresden, 27 May 2013 Deduction Systems slide 109 of 146

Page 110: Deduction Systems - Answer-Set Programming Motivation and

An example

P= { r(a, b)←, r(b, c)←, t(X, Y)← r(X, Y) }

T = {a, b, c}

A=

{r(a, a), r(a, b), r(a, c), r(b, a), r(b, b), r(b, c), r(c, a), r(c, b), r(c, c),t(a, a), t(a, b), t(a, c), t(b, a), t(b, b), t(b, c), t(c, a), t(c, b), t(c, c)

}

ground(P) =

r(a, b) ← ,r(b, c) ← ,

t(a, a) ← r(a, a), t(b, a) ← r(b, a), t(c, a) ← r(c, a),

t(a, b) ←

r(a, b)

,

t(b, b) ← r(b, b), t(c, b) ← r(c, b),t(a, c) ← r(a, c),

t(b, c) ←

r(b, c), t(c, c) ← r(c, c)

• Intelligent Grounding aims at reducing the ground

instantiationTU Dresden, 27 May 2013 Deduction Systems slide 110 of 146

Page 111: Deduction Systems - Answer-Set Programming Motivation and

Stable models of programs with Variables

Let P be a normal logic program with variables

• A set X of (ground) atoms is a stable model of P,

if Cn(ground(P)X) = X

TU Dresden, 27 May 2013 Deduction Systems slide 111 of 146

Page 112: Deduction Systems - Answer-Set Programming Motivation and

Stable models of programs with Variables

Let P be a normal logic program with variables

• A set X of (ground) atoms is a stable model of P,

if Cn(ground(P)X) = X

TU Dresden, 27 May 2013 Deduction Systems slide 112 of 146

Page 113: Deduction Systems - Answer-Set Programming Motivation and

———————————————————————-

TU Dresden, 27 May 2013 Deduction Systems slide 113 of 146

Page 114: Deduction Systems - Answer-Set Programming Motivation and

Problem solving in ASP: Extended Syntax

Problem

Logic Program

Solution

Stable Models

?-

6

Modeling Interpreting

Solving

TU Dresden, 27 May 2013 Deduction Systems slide 114 of 146

Page 115: Deduction Systems - Answer-Set Programming Motivation and

Language Constructs

• Variables (over the Herbrand Universe)– p(X) :- q(X) over constants {a,b,c} stands for

p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 27 May 2013 Deduction Systems slide 115 of 146

Page 116: Deduction Systems - Answer-Set Programming Motivation and

Language Constructs• Variables (over the Herbrand Universe)

– p(X) :- q(X) over constants {a,b,c} stands forp(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 27 May 2013 Deduction Systems slide 116 of 146

Page 117: Deduction Systems - Answer-Set Programming Motivation and

Language Constructs

• Variables (over the Herbrand Universe)– p(X) :- q(X) over constants {a,b,c} stands for

p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 27 May 2013 Deduction Systems slide 117 of 146

Page 118: Deduction Systems - Answer-Set Programming Motivation and

Language Constructs

• Variables (over the Herbrand Universe)– p(X) :- q(X) over constants {a,b,c} stands for

p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 27 May 2013 Deduction Systems slide 118 of 146

Page 119: Deduction Systems - Answer-Set Programming Motivation and

Language Constructs

• Variables (over the Herbrand Universe)– p(X) :- q(X) over constants {a,b,c} stands for

p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 27 May 2013 Deduction Systems slide 119 of 146

Page 120: Deduction Systems - Answer-Set Programming Motivation and

Language Constructs

• Variables (over the Herbrand Universe)– p(X) :- q(X) over constants {a,b,c} stands for

p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 27 May 2013 Deduction Systems slide 120 of 146

Page 121: Deduction Systems - Answer-Set Programming Motivation and

Language Constructs

• Variables (over the Herbrand Universe)– p(X) :- q(X) over constants {a,b,c} stands for

p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 27 May 2013 Deduction Systems slide 121 of 146

Page 122: Deduction Systems - Answer-Set Programming Motivation and

Language Constructs• Variables (over the Herbrand Universe)

– p(X) :- q(X) over constants {a,b,c} stands forp(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 27 May 2013 Deduction Systems slide 122 of 146

Page 123: Deduction Systems - Answer-Set Programming Motivation and

Modeling• For solving a problem class C for a problem instance I,

encode1 the problem instance I as a set PI of facts and2 the problem class C as a set PC of rules

such that the solutions to C for I can be (polynomially) extractedfrom the stable models of PI ∪ PC

• PI is (still) called problem instance• PC is often called the problem encoding

• An encoding PC is uniform, if it can be used to solve all itsproblem instancesThat is, PC encodes the solutions to C for any set PI of facts

TU Dresden, 27 May 2013 Deduction Systems slide 123 of 146

Page 124: Deduction Systems - Answer-Set Programming Motivation and

Modeling• For solving a problem class C for a problem instance I,

encode1 the problem instance I as a set PI of facts and2 the problem class C as a set PC of rules

such that the solutions to C for I can be (polynomially) extractedfrom the stable models of PI ∪ PC

• PI is (still) called problem instance• PC is often called the problem encoding

• An encoding PC is uniform, if it can be used to solve all itsproblem instancesThat is, PC encodes the solutions to C for any set PI of facts

TU Dresden, 27 May 2013 Deduction Systems slide 124 of 146

Page 125: Deduction Systems - Answer-Set Programming Motivation and

Modeling• For solving a problem class C for a problem instance I,

encode1 the problem instance I as a set PI of facts and2 the problem class C as a set PC of rules

such that the solutions to C for I can be (polynomially) extractedfrom the stable models of PI ∪ PC

• PI is (still) called problem instance• PC is often called the problem encoding

• An encoding PC is uniform, if it can be used to solve all itsproblem instancesThat is, PC encodes the solutions to C for any set PI of facts

TU Dresden, 27 May 2013 Deduction Systems slide 125 of 146

Page 126: Deduction Systems - Answer-Set Programming Motivation and

Example 3-Colorability

• Vertices are represented with predicates vertex(X);• Edges are represented with predicates edge(X, Y).

Question: Is there a valid assignment of three colors for an input graph G suchthat no two adjacent vertices have the same color?

TU Dresden, 27 May 2013 Deduction Systems slide 126 of 146

Page 127: Deduction Systems - Answer-Set Programming Motivation and

Graph coloring

node(1..6).

edge(1,2). edge(1,3). edge(1,4).edge(2,4). edge(2,5). edge(2,6).edge(3,1). edge(3,4). edge(3,5).edge(4,1). edge(4,2).edge(5,3). edge(5,4). edge(5,6).edge(6,2). edge(6,3). edge(6,5).

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 27 May 2013 Deduction Systems slide 127 of 146

Page 128: Deduction Systems - Answer-Set Programming Motivation and

Graph coloring

node(1..6).

edge(1,2). edge(1,3). edge(1,4).edge(2,4). edge(2,5). edge(2,6).edge(3,1). edge(3,4). edge(3,5).edge(4,1). edge(4,2).edge(5,3). edge(5,4). edge(5,6).edge(6,2). edge(6,3). edge(6,5).

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 27 May 2013 Deduction Systems slide 128 of 146

Page 129: Deduction Systems - Answer-Set Programming Motivation and

Graph coloring

node(1..6).

edge(1,2). edge(1,3). edge(1,4).edge(2,4). edge(2,5). edge(2,6).edge(3,1). edge(3,4). edge(3,5).edge(4,1). edge(4,2).edge(5,3). edge(5,4). edge(5,6).edge(6,2). edge(6,3). edge(6,5).

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 27 May 2013 Deduction Systems slide 129 of 146

Page 130: Deduction Systems - Answer-Set Programming Motivation and

Graph coloring

node(1..6).

edge(1,2). edge(1,3). edge(1,4).edge(2,4). edge(2,5). edge(2,6).edge(3,1). edge(3,4). edge(3,5).edge(4,1). edge(4,2).edge(5,3). edge(5,4). edge(5,6).edge(6,2). edge(6,3). edge(6,5).

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 27 May 2013 Deduction Systems slide 130 of 146

Page 131: Deduction Systems - Answer-Set Programming Motivation and

Graph coloring

node(1..6).

edge(1,2). edge(1,3). edge(1,4).edge(2,4). edge(2,5). edge(2,6).edge(3,1). edge(3,4). edge(3,5).edge(4,1). edge(4,2).edge(5,3). edge(5,4). edge(5,6).edge(6,2). edge(6,3). edge(6,5).

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 27 May 2013 Deduction Systems slide 131 of 146

Page 132: Deduction Systems - Answer-Set Programming Motivation and

Graph coloring

node(1..6).

edge(1,2). edge(1,3). edge(1,4).edge(2,4). edge(2,5). edge(2,6).edge(3,1). edge(3,4). edge(3,5).edge(4,1). edge(4,2).edge(5,3). edge(5,4). edge(5,6).edge(6,2). edge(6,3). edge(6,5).

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 27 May 2013 Deduction Systems slide 132 of 146

Page 133: Deduction Systems - Answer-Set Programming Motivation and

Graph coloring

node(1..6).

edge(1,2). edge(1,3). edge(1,4).edge(2,4). edge(2,5). edge(2,6).edge(3,1). edge(3,4). edge(3,5).edge(4,1). edge(4,2).edge(5,3). edge(5,4). edge(5,6).edge(6,2). edge(6,3). edge(6,5).

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 27 May 2013 Deduction Systems slide 133 of 146

Page 134: Deduction Systems - Answer-Set Programming Motivation and

Graph coloring

node(1..6).

edge(1,2). edge(1,3). edge(1,4).edge(2,4). edge(2,5). edge(2,6).edge(3,1). edge(3,4). edge(3,5).edge(4,1). edge(4,2).edge(5,3). edge(5,4). edge(5,6).edge(6,2). edge(6,3). edge(6,5).

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 27 May 2013 Deduction Systems slide 134 of 146

Page 135: Deduction Systems - Answer-Set Programming Motivation and

Graph coloring

node(1..6).

edge(1,2). edge(1,3). edge(1,4).edge(2,4). edge(2,5). edge(2,6).edge(3,1). edge(3,4). edge(3,5).edge(4,1). edge(4,2).edge(5,3). edge(5,4). edge(5,6).edge(6,2). edge(6,3). edge(6,5).

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 27 May 2013 Deduction Systems slide 135 of 146

Page 136: Deduction Systems - Answer-Set Programming Motivation and

color.lp

node(1..6).

edge(1,2). edge(1,3). edge(1,4).edge(2,4). edge(2,5). edge(2,6).edge(3,1). edge(3,4). edge(3,5).edge(4,1). edge(4,2).edge(5,3). edge(5,4). edge(5,6).edge(6,2). edge(6,3). edge(6,5).

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 27 May 2013 Deduction Systems slide 136 of 146

Page 137: Deduction Systems - Answer-Set Programming Motivation and

ASP solving process

Problem

LogicProgram Grounder Solver Stable

Models

Solution

- - -

?

6

Modeling Interpreting

Solving

TU Dresden, 27 May 2013 Deduction Systems slide 137 of 146

Page 138: Deduction Systems - Answer-Set Programming Motivation and

Graph coloring: Grounding

$ gringo --text color.lp

node(1). node(2). node(3). node(4). node(5). node(6).

edge(1,2). edge(1,3). edge(1,4). edge(2,4). edge(2,5). edge(2,6).edge(3,1). edge(3,4). edge(3,5). edge(4,1). edge(4,2). edge(5,3).edge(5,4). edge(5,6). edge(6,2). edge(6,3). edge(6,5).

col(r). col(b). col(g).

1 {color(1,r), color(1,b), color(1,g)} 1.1 {color(2,r), color(2,b), color(2,g)} 1.1 {color(3,r), color(3,b), color(3,g)} 1.1 {color(4,r), color(4,b), color(4,g)} 1.1 {color(5,r), color(5,b), color(5,g)} 1.1 {color(6,r), color(6,b), color(6,g)} 1.

:- color(1,r), color(2,r). :- color(2,g), color(5,g). ... :- color(6,r), color(2,r).:- color(1,b), color(2,b). :- color(2,r), color(6,r). :- color(6,b), color(2,b).:- color(1,g), color(2,g). :- color(2,b), color(6,b). :- color(6,g), color(2,g).:- color(1,r), color(3,r). :- color(2,g), color(6,g). :- color(6,r), color(3,r).:- color(1,b), color(3,b). :- color(3,r), color(1,r). :- color(6,b), color(3,b).:- color(1,g), color(3,g). :- color(3,b), color(1,b). :- color(6,g), color(3,g).:- color(1,r), color(4,r). :- color(3,g), color(1,g). :- color(6,r), color(5,r).:- color(1,b), color(4,b). :- color(3,r), color(4,r). :- color(6,b), color(5,b).:- color(1,g), color(4,g). :- color(3,b), color(4,b). :- color(6,g), color(5,g).:- color(2,r), color(4,r). :- color(3,g), color(4,g).:- color(2,b), color(4,b). :- color(3,r), color(5,r).:- color(2,g), color(4,g). :- color(3,b), color(5,b).:- color(2,r), color(5,r). :- color(3,g), color(5,g).:- color(2,b), color(5,b). :- color(4,r), color(1,r).

TU Dresden, 27 May 2013 Deduction Systems slide 138 of 146

Page 139: Deduction Systems - Answer-Set Programming Motivation and

Graph coloring: Grounding

$ gringo --text color.lp

node(1). node(2). node(3). node(4). node(5). node(6).

edge(1,2). edge(1,3). edge(1,4). edge(2,4). edge(2,5). edge(2,6).edge(3,1). edge(3,4). edge(3,5). edge(4,1). edge(4,2). edge(5,3).edge(5,4). edge(5,6). edge(6,2). edge(6,3). edge(6,5).

col(r). col(b). col(g).

1 {color(1,r), color(1,b), color(1,g)} 1.1 {color(2,r), color(2,b), color(2,g)} 1.1 {color(3,r), color(3,b), color(3,g)} 1.1 {color(4,r), color(4,b), color(4,g)} 1.1 {color(5,r), color(5,b), color(5,g)} 1.1 {color(6,r), color(6,b), color(6,g)} 1.

:- color(1,r), color(2,r). :- color(2,g), color(5,g). ... :- color(6,r), color(2,r).:- color(1,b), color(2,b). :- color(2,r), color(6,r). :- color(6,b), color(2,b).:- color(1,g), color(2,g). :- color(2,b), color(6,b). :- color(6,g), color(2,g).:- color(1,r), color(3,r). :- color(2,g), color(6,g). :- color(6,r), color(3,r).:- color(1,b), color(3,b). :- color(3,r), color(1,r). :- color(6,b), color(3,b).:- color(1,g), color(3,g). :- color(3,b), color(1,b). :- color(6,g), color(3,g).:- color(1,r), color(4,r). :- color(3,g), color(1,g). :- color(6,r), color(5,r).:- color(1,b), color(4,b). :- color(3,r), color(4,r). :- color(6,b), color(5,b).:- color(1,g), color(4,g). :- color(3,b), color(4,b). :- color(6,g), color(5,g).:- color(2,r), color(4,r). :- color(3,g), color(4,g).:- color(2,b), color(4,b). :- color(3,r), color(5,r).:- color(2,g), color(4,g). :- color(3,b), color(5,b).:- color(2,r), color(5,r). :- color(3,g), color(5,g).:- color(2,b), color(5,b). :- color(4,r), color(1,r).

TU Dresden, 27 May 2013 Deduction Systems slide 139 of 146

Page 140: Deduction Systems - Answer-Set Programming Motivation and

ASP solving process

Problem

LogicProgram Grounder Solver Stable

Models

Solution

- - -

?

6

Modeling Interpreting

Solving

TU Dresden, 27 May 2013 Deduction Systems slide 140 of 146

Page 141: Deduction Systems - Answer-Set Programming Motivation and

Graph coloring: Solving

$ gringo color.lp | clasp 0

clasp version 2.1.0Reading from stdinSolving...Answer: 1edge(1,2) ... col(r) ... node(1) ... color(6,b) color(5,g) color(4,b) color(3,r) color(2,r) color(1,g)Answer: 2edge(1,2) ... col(r) ... node(1) ... color(6,r) color(5,g) color(4,r) color(3,b) color(2,b) color(1,g)Answer: 3edge(1,2) ... col(r) ... node(1) ... color(6,g) color(5,b) color(4,g) color(3,r) color(2,r) color(1,b)Answer: 4edge(1,2) ... col(r) ... node(1) ... color(6,r) color(5,b) color(4,r) color(3,g) color(2,g) color(1,b)Answer: 5edge(1,2) ... col(r) ... node(1) ... color(6,g) color(5,r) color(4,g) color(3,b) color(2,b) color(1,r)Answer: 6edge(1,2) ... col(r) ... node(1) ... color(6,b) color(5,r) color(4,b) color(3,g) color(2,g) color(1,r)SATISFIABLE

Models : 6Time : 0.002s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)CPU Time : 0.000s

TU Dresden, 27 May 2013 Deduction Systems slide 141 of 146

Page 142: Deduction Systems - Answer-Set Programming Motivation and

Graph coloring: Solving

$ gringo color.lp | clasp 0

clasp version 2.1.0Reading from stdinSolving...Answer: 1edge(1,2) ... col(r) ... node(1) ... color(6,b) color(5,g) color(4,b) color(3,r) color(2,r) color(1,g)Answer: 2edge(1,2) ... col(r) ... node(1) ... color(6,r) color(5,g) color(4,r) color(3,b) color(2,b) color(1,g)Answer: 3edge(1,2) ... col(r) ... node(1) ... color(6,g) color(5,b) color(4,g) color(3,r) color(2,r) color(1,b)Answer: 4edge(1,2) ... col(r) ... node(1) ... color(6,r) color(5,b) color(4,r) color(3,g) color(2,g) color(1,b)Answer: 5edge(1,2) ... col(r) ... node(1) ... color(6,g) color(5,r) color(4,g) color(3,b) color(2,b) color(1,r)Answer: 6edge(1,2) ... col(r) ... node(1) ... color(6,b) color(5,r) color(4,b) color(3,g) color(2,g) color(1,r)SATISFIABLE

Models : 6Time : 0.002s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)CPU Time : 0.000s

TU Dresden, 27 May 2013 Deduction Systems slide 142 of 146

Page 143: Deduction Systems - Answer-Set Programming Motivation and

Guess & Check Methodology1 Guess all possible assignments of colors;2 Check whether adjacent vertices have indeed different colors.

πcol = πguess ∪ πcheck

πguess = { red(X)← vertex(X), not green(X), not blue(X);

green(X)← vertex(X), not red(X), not blue(X);

blue(X)← vertex(X), not red(X), not green(X) }πcheck = { fail← red(X), red(Y), edge(X, Y);

fail← green(X), green(Y), edge(X, Y);

fail← blue(X), blue(Y), edge(X, Y);

← fail }

TU Dresden, 27 May 2013 Deduction Systems slide 143 of 146

Page 144: Deduction Systems - Answer-Set Programming Motivation and

Problem solving in ASP: Reasoning Modes

Problem

Logic Program

Solution

Stable Models

?-

6

Modeling Interpreting

Solving

TU Dresden, 27 May 2013 Deduction Systems slide 144 of 146

Page 145: Deduction Systems - Answer-Set Programming Motivation and

Reasoning Modes

• Satisfiability• Enumeration†

• Projection†

• Intersection‡

• Union‡

• Optimization

• and combinations of them

† without solution recording‡ without solution enumeration

TU Dresden, 27 May 2013 Deduction Systems slide 145 of 146

Page 146: Deduction Systems - Answer-Set Programming Motivation and

References

Martin Gebser, Benjamin Kaufmann Roland Kaminski, and TorstenSchaub.Answer Set Solving in Practice.Synthesis Lectures on Artificial Intelligence and Machine Learning.Morgan and Claypool Publishers, 2012.doi=10.2200/S00457ED1V01Y201211AIM019.

Michael Gelfond and Vladimir Lifschitz.Classical negation in logic programs and disjunctive databases.New Generation Comput., 9(3–4):365–386, 1991.

• See also: http://potassco.sourceforge.net

TU Dresden, 27 May 2013 Deduction Systems slide 146 of 146