138
An Answer Set Programming Tutorial Minh Dao-Tran Institut für Informationsysteme, TU Wien Supported by Austrian Science Fund (FWF) project P20841, and the Marie Curie action IRSES under Grant No. 2476 Based on slides from Thomas Eiter, Giovambattista Ianni, Thomas Krennwallner in the Reasoning Web Summer School 2009 and slides from Torsten Schaub DERI, July 2011

Exchanging More than Complete Data

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Exchanging More than Complete Data

An Answer Set Programming Tutorial

Minh Dao-Tran

Institut für Informationsysteme, TU Wien

Supported by Austrian Science Fund (FWF) project P20841, and the Marie Curie action IRSESunder Grant No. 2476

Based on slides from Thomas Eiter, Giovambattista Ianni, Thomas Krennwallner in the Reasoning Web Summer School 2009

and slides from Torsten Schaub

DERI, July 2011

Page 2: Exchanging More than Complete Data

An Answer Set Programming Tutorial

Outline

1. Introduction

2. Horn Logic Programming2.1 Positive Logic Programs2.2 Minimal Model Semantics

3. Stable Logic Programming

4. Extensions4.1 Disjunction4.2 Integrity Constraints

5. Answer Set for the Semantic Web5.1 DL-Programs5.2 HEX-Programs

6. Future Directions of ASP

Minh Dao-Tran DERI, July 2011 1/33

Page 3: Exchanging More than Complete Data

An Answer Set Programming Tutorial 1. Introduction

Introduction

Answer Set Programming (ASP) is a recent problem solvingapproach

ASP has its roots in:• (logic-based) knowledge representation and reasoning

• (deductive) databases

• constraint solving, SAT solving

• logic programming (with negation)

ASP allows for solving all search problems in NP (and NPNP) in auniform way

Minh Dao-Tran DERI, July 2011 2/33

Page 4: Exchanging More than Complete Data

An Answer Set Programming Tutorial 1. Introduction

Knapsack Problem

Minh Dao-Tran DERI, July 2011 3/33

Page 5: Exchanging More than Complete Data

An Answer Set Programming Tutorial 1. Introduction

Sudoku

6 1 4 58 3 5 6

2 18 4 7 6

6 37 9 1 45 2

7 2 6 94 5 8 7

Task:

Fill in the grid so that every row, every column, and every 3x3 boxcontains the digits 1 through 9.

Minh Dao-Tran DERI, July 2011 4/33

Page 6: Exchanging More than Complete Data

An Answer Set Programming Tutorial 1. Introduction

Wanted!

A general-purpose, declarative approach for modeling and solvingthese and many other problems.

Declarative:• “What is the problem?”

instead of

• “How to solve the problem?”

Proposal:

Answer Set Programming (ASP) paradigm!

Minh Dao-Tran DERI, July 2011 5/33

Page 7: Exchanging More than Complete Data

An Answer Set Programming Tutorial 1. Introduction

Wanted!

A general-purpose, declarative approach for modeling and solvingthese and many other problems.

Declarative:• “What is the problem?”

instead of

• “How to solve the problem?”

Proposal:

Answer Set Programming (ASP) paradigm!

Minh Dao-Tran DERI, July 2011 5/33

Page 8: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.1 Positive Logic Programs

Positive Logic Programs

Definition (Positive Logic Program)

A positive logic program P is a finite set of clauses (rules) in the form

a← b1, . . . , bm

where a, b1, . . . , bm are atoms of a first-order language L.

a is the head of the rule

b1, . . . , bm is the body of the rule.

If m = 0, the rule is a fact (written shortly a)

Exampleprof (supervisor(X)) ← phd_student(X).

poor(X) ← phd_student(X).phd_student(Y) ← phd_student(X), couple(X,Y).

Minh Dao-Tran DERI, July 2011 6/33

Page 9: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.1 Positive Logic Programs

Positive Logic Programs

Definition (Positive Logic Program)

A positive logic program P is a finite set of clauses (rules) in the form

a← b1, . . . , bm

where a, b1, . . . , bm are atoms of a first-order language L.

a is the head of the rule

b1, . . . , bm is the body of the rule.

If m = 0, the rule is a fact (written shortly a)

Exampleprof (supervisor(X)) ← phd_student(X).

poor(X) ← phd_student(X).phd_student(Y) ← phd_student(X), couple(X,Y).

Minh Dao-Tran DERI, July 2011 6/33

Page 10: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.1 Positive Logic Programs

Herbrand Semantics by an Example

A logic program P:prof (supervisor(X)) ← phd_student(X). phd_student(peter).

poor(X) ← phd_student(X). couple(peter, jane).phd_student(Y) ← phd_student(X), couple(X, Y).

Constant symbols: peter, jane; Function symbols: supervisor.

Herbrand Universe

HU(P) ={

peter, supervisor(peter), supervisor(supervisor(peter)), . . . ,jane, supervisor(jane), supervisor(supervisor(jane)), . . .

}

Herbrand Base

HB(P) =

phd_student(peter), phd_student(jane), phd_student(supervisor(peter)), . . . ,prof (peter), prof (jane), prof (supervisor(peter)), prof (supervisor(jane)), . . . ,poor(peter), poor(jane), poor(supervisor(peter)), poor(supervisor(jane)), . . . ,couple(peter, jane), couple(peter, supervisor(peter)), couple(jane, jane), . . .

Herbrand Interpretation

I1 = ∅ I2 = HB(P)I3 = {phd_student(peter), phd_student(jane), couple(peter, jane), prof (supervisor(peter))}

Minh Dao-Tran DERI, July 2011 7/33

Page 11: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.1 Positive Logic Programs

Herbrand Semantics by an Example

A logic program P:prof (supervisor(X)) ← phd_student(X). phd_student(peter).

poor(X) ← phd_student(X). couple(peter, jane).phd_student(Y) ← phd_student(X), couple(X, Y).

Constant symbols: peter, jane; Function symbols: supervisor.

Herbrand Universe

HU(P) ={

peter, supervisor(peter), supervisor(supervisor(peter)), . . . ,jane, supervisor(jane), supervisor(supervisor(jane)), . . .

}

Herbrand Base

HB(P) =

phd_student(peter), phd_student(jane), phd_student(supervisor(peter)), . . . ,prof (peter), prof (jane), prof (supervisor(peter)), prof (supervisor(jane)), . . . ,poor(peter), poor(jane), poor(supervisor(peter)), poor(supervisor(jane)), . . . ,couple(peter, jane), couple(peter, supervisor(peter)), couple(jane, jane), . . .

Herbrand Interpretation

I1 = ∅ I2 = HB(P)I3 = {phd_student(peter), phd_student(jane), couple(peter, jane), prof (supervisor(peter))}

Minh Dao-Tran DERI, July 2011 7/33

Page 12: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.1 Positive Logic Programs

Herbrand Semantics by an Example

A logic program P:prof (supervisor(X)) ← phd_student(X). phd_student(peter).

poor(X) ← phd_student(X). couple(peter, jane).phd_student(Y) ← phd_student(X), couple(X, Y).

Constant symbols: peter, jane; Function symbols: supervisor.

Herbrand Universe

HU(P) ={

peter, supervisor(peter), supervisor(supervisor(peter)), . . . ,jane, supervisor(jane), supervisor(supervisor(jane)), . . .

}

Herbrand Base

HB(P) =

phd_student(peter), phd_student(jane), phd_student(supervisor(peter)), . . . ,prof (peter), prof (jane), prof (supervisor(peter)), prof (supervisor(jane)), . . . ,poor(peter), poor(jane), poor(supervisor(peter)), poor(supervisor(jane)), . . . ,couple(peter, jane), couple(peter, supervisor(peter)), couple(jane, jane), . . .

Herbrand Interpretation

I1 = ∅ I2 = HB(P)I3 = {phd_student(peter), phd_student(jane), couple(peter, jane), prof (supervisor(peter))}

Minh Dao-Tran DERI, July 2011 7/33

Page 13: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.1 Positive Logic Programs

Herbrand Semantics by an Example

A logic program P:prof (supervisor(X)) ← phd_student(X). phd_student(peter).

poor(X) ← phd_student(X). couple(peter, jane).phd_student(Y) ← phd_student(X), couple(X, Y).

Constant symbols: peter, jane; Function symbols: supervisor.

Herbrand Universe

HU(P) ={

peter, supervisor(peter), supervisor(supervisor(peter)), . . . ,jane, supervisor(jane), supervisor(supervisor(jane)), . . .

}

Herbrand Base

HB(P) =

phd_student(peter), phd_student(jane), phd_student(supervisor(peter)), . . . ,prof (peter), prof (jane), prof (supervisor(peter)), prof (supervisor(jane)), . . . ,poor(peter), poor(jane), poor(supervisor(peter)), poor(supervisor(jane)), . . . ,couple(peter, jane), couple(peter, supervisor(peter)), couple(jane, jane), . . .

Herbrand Interpretation

I1 = ∅ I2 = HB(P)I3 = {phd_student(peter), phd_student(jane), couple(peter, jane), prof (supervisor(peter))}

Minh Dao-Tran DERI, July 2011 7/33

Page 14: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.1 Positive Logic Programs

Grounding

Grounding a rule

r = poor(X)← phd_student(X).

A ground instance of r is obtained by replacing its variables by terms from HUP.

grnd(r) =

poor(peter) ← phd_student(peter).poor(jane) ← phd_student(jane).

poor(supervisor(peter)) ← phd_student(supervisor(peter))....

Grounding a program

grnd(P) =⋃

r∈P grnd(r)

Minh Dao-Tran DERI, July 2011 8/33

Page 15: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.1 Positive Logic Programs

Herbrand Models

Definition (Model, satisfaction)

An interpretation I is a (Herbrand) model of a

a ground (variable-free) rule r = a← b1, . . . , bm, if either{b1, . . . , bm} * I or a ∈ I; (I |= r)

a rule r, if I |= r′ for every r′ ∈ grnd(r); (I |= r)

a program P, if I |= r for every rule r in P. (I |= P)

Minh Dao-Tran DERI, July 2011 9/33

Page 16: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.1 Positive Logic Programs

Example (Program P)prof (supervisor(X)) ← phd_student(X). phd_student(peter).

poor(X) ← phd_student(X). couple(peter, jane).phd_student(Y) ← phd_student(X), couple(X,Y).

Which of the following interpretations are models of P?

I1 = ∅

no

I2 = HB(P)

yes

I3 =

{phd_student(peter), couple(peter, jane), phd_student(jane),poor(peter), poor(jane), prof (supervisor(peter))

}

no

Minh Dao-Tran DERI, July 2011 10/33

Page 17: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.1 Positive Logic Programs

Example (Program P)prof (supervisor(X)) ← phd_student(X). phd_student(peter).

poor(X) ← phd_student(X). couple(peter, jane).phd_student(Y) ← phd_student(X), couple(X,Y).

Which of the following interpretations are models of P?

I1 = ∅ no

I2 = HB(P)

yes

I3 =

{phd_student(peter), couple(peter, jane), phd_student(jane),poor(peter), poor(jane), prof (supervisor(peter))

}

no

Minh Dao-Tran DERI, July 2011 10/33

Page 18: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.1 Positive Logic Programs

Example (Program P)prof (supervisor(X)) ← phd_student(X). phd_student(peter).

poor(X) ← phd_student(X). couple(peter, jane).phd_student(Y) ← phd_student(X), couple(X,Y).

Which of the following interpretations are models of P?

I1 = ∅ no

I2 = HB(P) yes

I3 =

{phd_student(peter), couple(peter, jane), phd_student(jane),poor(peter), poor(jane), prof (supervisor(peter))

}

no

Minh Dao-Tran DERI, July 2011 10/33

Page 19: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.1 Positive Logic Programs

Example (Program P)prof (supervisor(X)) ← phd_student(X). phd_student(peter).

poor(X) ← phd_student(X). couple(peter, jane).phd_student(Y) ← phd_student(X), couple(X,Y).

Which of the following interpretations are models of P?

I1 = ∅ no

I2 = HB(P) yes

I3 =

{phd_student(peter), couple(peter, jane), phd_student(jane),poor(peter), poor(jane), prof (supervisor(peter))

}no

Minh Dao-Tran DERI, July 2011 10/33

Page 20: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.2 Minimal Model Semantics

Minimal Model Semantics

Prefer models with true-part as small as possible.

Definition

A model I of P is minimal, if there exists no model J of P such that J ⊂ I.

Theorem

Every logic program P has a single minimal model (called the leastmodel), denoted LM(P).

Minh Dao-Tran DERI, July 2011 11/33

Page 21: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.2 Minimal Model Semantics

Minimal Model Semantics

Prefer models with true-part as small as possible.

Definition

A model I of P is minimal, if there exists no model J of P such that J ⊂ I.

Theorem

Every logic program P has a single minimal model (called the leastmodel), denoted LM(P).

Minh Dao-Tran DERI, July 2011 11/33

Page 22: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.2 Minimal Model Semantics

Computation

The minimal model can be computed via fixpoint iteration.

Exampleprof (supervisor(X)) ← phd_student(X). phd_student(peter).

poor(X) ← phd_student(X). couple(peter, jane).phd_student(Y) ← phd_student(X), couple(X,Y).

T0P = ∅

T1P = {phd_student(peter), couple(peter, jane)}

T2P =

{phd_student(peter), couple(peter, jane), phd_student(jane),poor(peter), prof (supervisor(peter))

}

T3P =

phd_student(peter), couple(peter, jane), phd_student(jane),poor(peter), prof (supervisor(peter)), poor(jane),prof (supervisor(jane))

T4

P = T3P

Minh Dao-Tran DERI, July 2011 12/33

Page 23: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.2 Minimal Model Semantics

Computation

The minimal model can be computed via fixpoint iteration.

Exampleprof (supervisor(X)) ← phd_student(X). phd_student(peter).

poor(X) ← phd_student(X). couple(peter, jane).phd_student(Y) ← phd_student(X), couple(X,Y).

T0P = ∅

T1P = {phd_student(peter), couple(peter, jane)}

T2P =

{phd_student(peter), couple(peter, jane), phd_student(jane),poor(peter), prof (supervisor(peter))

}

T3P =

phd_student(peter), couple(peter, jane), phd_student(jane),poor(peter), prof (supervisor(peter)), poor(jane),prof (supervisor(jane))

T4

P = T3P

Minh Dao-Tran DERI, July 2011 12/33

Page 24: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.2 Minimal Model Semantics

Computation

The minimal model can be computed via fixpoint iteration.

Exampleprof (supervisor(X)) ← phd_student(X). phd_student(peter).

poor(X) ← phd_student(X). couple(peter, jane).phd_student(Y) ← phd_student(X), couple(X,Y).

T0P = ∅

T1P = {phd_student(peter), couple(peter, jane)}

T2P =

{phd_student(peter), couple(peter, jane), phd_student(jane),poor(peter), prof (supervisor(peter))

}

T3P =

phd_student(peter), couple(peter, jane), phd_student(jane),poor(peter), prof (supervisor(peter)), poor(jane),prof (supervisor(jane))

T4

P = T3P

Minh Dao-Tran DERI, July 2011 12/33

Page 25: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.2 Minimal Model Semantics

Computation

The minimal model can be computed via fixpoint iteration.

Exampleprof (supervisor(X)) ← phd_student(X). phd_student(peter).

poor(X) ← phd_student(X). couple(peter, jane).phd_student(Y) ← phd_student(X), couple(X,Y).

T0P = ∅

T1P = {phd_student(peter), couple(peter, jane)}

T2P =

{phd_student(peter), couple(peter, jane), phd_student(jane),poor(peter), prof (supervisor(peter))

}

T3P =

phd_student(peter), couple(peter, jane), phd_student(jane),poor(peter), prof (supervisor(peter)), poor(jane),prof (supervisor(jane))

T4P = T3

P

Minh Dao-Tran DERI, July 2011 12/33

Page 26: Exchanging More than Complete Data

An Answer Set Programming Tutorial 2. Horn Logic Programming 2.2 Minimal Model Semantics

Computation

The minimal model can be computed via fixpoint iteration.

Exampleprof (supervisor(X)) ← phd_student(X). phd_student(peter).

poor(X) ← phd_student(X). couple(peter, jane).phd_student(Y) ← phd_student(X), couple(X,Y).

T0P = ∅

T1P = {phd_student(peter), couple(peter, jane)}

T2P =

{phd_student(peter), couple(peter, jane), phd_student(jane),poor(peter), prof (supervisor(peter))

}

T3P =

phd_student(peter), couple(peter, jane), phd_student(jane),poor(peter), prof (supervisor(peter)), poor(jane),prof (supervisor(jane))

T4

P = T3P

Minh Dao-Tran DERI, July 2011 12/33

Page 27: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Negation in Logic Programs

Why negation?

Natural linguistic concept

Facilitates convenient, declarative descriptions (definitions)

E.g., "Men who are not husbands are singles.”

Definition

A normal logic program is a set of rules of the form

a← b1, . . . , bm, not c1, . . . , not cn (n,m ≥ 0) (1)

where a and all bi, cj are atoms in a first-order language L.

not is called “negation as failure”, “default negation”, or “weak negation”

Things get more complex!

Minh Dao-Tran DERI, July 2011 13/33

Page 28: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Negation in Logic Programs

Why negation?

Natural linguistic concept

Facilitates convenient, declarative descriptions (definitions)

E.g., "Men who are not husbands are singles.”

Definition

A normal logic program is a set of rules of the form

a← b1, . . . , bm, not c1, . . . , not cn (n,m ≥ 0) (1)

where a and all bi, cj are atoms in a first-order language L.

not is called “negation as failure”, “default negation”, or “weak negation”

Things get more complex!Minh Dao-Tran DERI, July 2011 13/33

Page 29: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Stable model semantics

First, for variable-free (ground) programs P

Treat “not ” specially

Intuitively, literals not a are a source of “contradiction” or “unstability”.

Example (Dilbert, program P2)

man(dilbert). (f1)

single(dilbert)← man(dilbert), not husband(dilbert). (r1)

husband(dilbert)← man(dilbert), not single(dilbert). (r2)

M′ = {man(dilbert)}, get {man(dilbert), single(dilbert), husband(dilbert)}

M′′ = {man(dilbert), single(dilbert), husband(dilbert)}, get {man(dilbert)}.

Minh Dao-Tran DERI, July 2011 14/33

Page 30: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Stable model semantics

First, for variable-free (ground) programs P

Treat “not ” specially

Intuitively, literals not a are a source of “contradiction” or “unstability”.

Example (Dilbert, program P2)

man(dilbert). (f1)

single(dilbert)← man(dilbert), not husband(dilbert). (r1)

husband(dilbert)← man(dilbert), not single(dilbert). (r2)

M′ = {man(dilbert)}, get {man(dilbert), single(dilbert), husband(dilbert)}

M′′ = {man(dilbert), single(dilbert), husband(dilbert)}, get {man(dilbert)}.

Minh Dao-Tran DERI, July 2011 14/33

Page 31: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Stable model semantics

First, for variable-free (ground) programs P

Treat “not ” specially

Intuitively, literals not a are a source of “contradiction” or “unstability”.

Example (Dilbert, program P2)

man(dilbert). (f1)

single(dilbert)← man(dilbert), not husband(dilbert). (r1)

husband(dilbert)← man(dilbert), not single(dilbert). (r2)

M′ = {man(dilbert)}, get {man(dilbert), single(dilbert), husband(dilbert)}

M′′ = {man(dilbert), single(dilbert), husband(dilbert)}, get {man(dilbert)}.

Minh Dao-Tran DERI, July 2011 14/33

Page 32: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Stable model semantics

First, for variable-free (ground) programs P

Treat “not ” specially

Intuitively, literals not a are a source of “contradiction” or “unstability”.

Example (Dilbert, program P2)

man(dilbert). (f1)

single(dilbert)← man(dilbert), not husband(dilbert). (r1)

husband(dilbert)← man(dilbert), not single(dilbert). (r2)

M′ = {man(dilbert)}, get {man(dilbert), single(dilbert), husband(dilbert)}

M′′ = {man(dilbert), single(dilbert), husband(dilbert)}, get {man(dilbert)}.

Minh Dao-Tran DERI, July 2011 14/33

Page 33: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Stable Models

Definition (Gelfond-Lifschitz Reduct PM 1988)The GL-reduct (simply reduct) of a ground program P w.r.t. aninterpretation M, denoted PM, is the program obtained from P by

1 removing rules with not a in the body for each a ∈ M; and

2 removing literals not a from all other rules.

Intuition:M makes an assumption about what is true and what is false.The reduct PM incorporates this assumptions.As a “not ”-free program, PM derives positive facts, given by LM(PM).If this coincides with M, then the assumption of M is “stable”.

Definition (stable model)

An interpretation M of P is a stable model of P, if M = LM(PM).

Minh Dao-Tran DERI, July 2011 15/33

Page 34: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Stable Models

Definition (Gelfond-Lifschitz Reduct PM 1988)The GL-reduct (simply reduct) of a ground program P w.r.t. aninterpretation M, denoted PM, is the program obtained from P by

1 removing rules with not a in the body for each a ∈ M; and

2 removing literals not a from all other rules.

Intuition:M makes an assumption about what is true and what is false.The reduct PM incorporates this assumptions.As a “not ”-free program, PM derives positive facts, given by LM(PM).If this coincides with M, then the assumption of M is “stable”.

Definition (stable model)

An interpretation M of P is a stable model of P, if M = LM(PM).

Minh Dao-Tran DERI, July 2011 15/33

Page 35: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Stable Models

Definition (Gelfond-Lifschitz Reduct PM 1988)The GL-reduct (simply reduct) of a ground program P w.r.t. aninterpretation M, denoted PM, is the program obtained from P by

1 removing rules with not a in the body for each a ∈ M; and

2 removing literals not a from all other rules.

Intuition:M makes an assumption about what is true and what is false.The reduct PM incorporates this assumptions.As a “not ”-free program, PM derives positive facts, given by LM(PM).If this coincides with M, then the assumption of M is “stable”.

Definition (stable model)

An interpretation M of P is a stable model of P, if M = LM(PM).

Minh Dao-Tran DERI, July 2011 15/33

Page 36: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Example (P2 cont’d)

man(dilbert). (f1)

single(dilbert)← man(dilbert), not husband(dilbert). (r1)

husband(dilbert)← man(dilbert), not single(dilbert). (r2)

Candidate interpretations:

M1 = {man(dilbert), single(dilbert)},M2 = {man(dilbert), husband(dilbert)},M3 = {man(dilbert), single(dilbert), husband(dilbert)},M4 = {man(dilbert)}

M1 and M2 are stable models.

Minh Dao-Tran DERI, July 2011 16/33

Page 37: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Example (P2 cont’d)

man(dilbert). (f1)

single(dilbert)← man(dilbert), not husband(dilbert). (r1)

husband(dilbert)← man(dilbert), not single(dilbert). (r2)

Candidate interpretations:

M1 = {man(dilbert), single(dilbert)},M2 = {man(dilbert), husband(dilbert)},M3 = {man(dilbert), single(dilbert), husband(dilbert)},M4 = {man(dilbert)}

M1 and M2 are stable models.

Minh Dao-Tran DERI, July 2011 16/33

Page 38: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Example (P2 cont’d)

man(dilbert). (f1)

single(dilbert)← man(dilbert), not husband(dilbert). (r1)

husband(dilbert)← man(dilbert), not single(dilbert). (r2)

M1 = {man(dilbert), single(dilbert)}:

reduct PM12 :

man(dilbert).

single(dilbert)← man(dilbert).

The least model of PM12 is {man(dilbert), single(dilbert)} = M1.

M2 = {man(dilbert), husband(dilbert)}: by symmetry of husband andsingle, also M2 is stable.

Minh Dao-Tran DERI, July 2011 17/33

Page 39: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Example (P2 cont’d)

man(dilbert). (f1)

single(dilbert)← man(dilbert), not husband(dilbert). (r1)

husband(dilbert)← man(dilbert), not single(dilbert). (r2)

M1 = {man(dilbert), single(dilbert)}:

reduct PM12 :

man(dilbert).

single(dilbert)← man(dilbert).

The least model of PM12 is {man(dilbert), single(dilbert)} = M1.

M2 = {man(dilbert), husband(dilbert)}: by symmetry of husband andsingle, also M2 is stable.

Minh Dao-Tran DERI, July 2011 17/33

Page 40: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Example (P2 cont’d)

man(dilbert). (f1)

single(dilbert)← man(dilbert), not husband(dilbert). (r1)

husband(dilbert)← man(dilbert), not single(dilbert). (r2)

M1 = {man(dilbert), single(dilbert)}:

reduct PM12 :

man(dilbert).

single(dilbert)← man(dilbert).

The least model of PM12 is {man(dilbert), single(dilbert)} = M1.

M2 = {man(dilbert), husband(dilbert)}: by symmetry of husband andsingle, also M2 is stable.

Minh Dao-Tran DERI, July 2011 17/33

Page 41: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Example (P2 cont’d)

man(dilbert). (f1)

single(dilbert)← man(dilbert), not husband(dilbert). (r1)

husband(dilbert)← man(dilbert), not single(dilbert). (r2)

M3 = {man(dilbert), single(dilbert), husband(dilbert)}:

PM32 is

man(dilbert).

LM(PM32 ) = {man(dilbert)} 6= M3.

M4 = {man(dilbert)}:

PM42 is

man(dilbert).

single(dilbert)← man(dilbert).

husband(dilbert)← man(dilbert).

LM(PM42 ) = {man(dilbert), single(dilbert), husband(dilbert)} 6= M4.

Minh Dao-Tran DERI, July 2011 18/33

Page 42: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Example (P2 cont’d)

man(dilbert). (f1)

single(dilbert)← man(dilbert), not husband(dilbert). (r1)

husband(dilbert)← man(dilbert), not single(dilbert). (r2)

M3 = {man(dilbert), single(dilbert), husband(dilbert)}:

PM32 is

man(dilbert).

LM(PM32 ) = {man(dilbert)} 6= M3.

M4 = {man(dilbert)}:

PM42 is

man(dilbert).

single(dilbert)← man(dilbert).

husband(dilbert)← man(dilbert).

LM(PM42 ) = {man(dilbert), single(dilbert), husband(dilbert)} 6= M4.

Minh Dao-Tran DERI, July 2011 18/33

Page 43: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Example (P2 cont’d)

man(dilbert). (f1)

single(dilbert)← man(dilbert), not husband(dilbert). (r1)

husband(dilbert)← man(dilbert), not single(dilbert). (r2)

M3 = {man(dilbert), single(dilbert), husband(dilbert)}:

PM32 is

man(dilbert).

LM(PM32 ) = {man(dilbert)} 6= M3.

M4 = {man(dilbert)}:

PM42 is

man(dilbert).

single(dilbert)← man(dilbert).

husband(dilbert)← man(dilbert).

LM(PM42 ) = {man(dilbert), single(dilbert), husband(dilbert)} 6= M4.

Minh Dao-Tran DERI, July 2011 18/33

Page 44: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Example (P2 cont’d)

man(dilbert). (f1)

single(dilbert)← man(dilbert), not husband(dilbert). (r1)

husband(dilbert)← man(dilbert), not single(dilbert). (r2)

M3 = {man(dilbert), single(dilbert), husband(dilbert)}:

PM32 is

man(dilbert).

LM(PM32 ) = {man(dilbert)} 6= M3.

M4 = {man(dilbert)}:

PM42 is

man(dilbert).

single(dilbert)← man(dilbert).

husband(dilbert)← man(dilbert).

LM(PM42 ) = {man(dilbert), single(dilbert), husband(dilbert)} 6= M4.

Minh Dao-Tran DERI, July 2011 18/33

Page 45: Exchanging More than Complete Data

An Answer Set Programming Tutorial 3. Stable Logic Programming

Programs with Variables

As for positive programs, view a program rule as a shorthand for allits ground instances.

Recall: grnd(P) is the grounding of program P.

Definition (stable model, general case)

An interpretation M of P is a stable model of P, if M is a stable model ofgrnd(P).

Minh Dao-Tran DERI, July 2011 19/33

Page 46: Exchanging More than Complete Data

An Answer Set Programming Tutorial 4. Extensions

Extensions

Many extensions exist, partly motivated by applicationsSome are syntactic sugar, other strictly add expressivenessIncomplete list:

• disjunction• integrity constraints• strong negation• nested expressions• cardinality constraints (Smodels)• optimization: weight constraints, minimize (Smodels);

weak constraints (DLV)• aggregates (Smodels, DLV)• templates (for macros), external functions (DLVHEX)• Frame Logic syntax (for Semantic Web)• preferences: e.g., PLP, LOPDs• KR frontends (diagnosis, inheritance, planning,...) in DLV

Comprehensive survey: [Niemelä (ed.), 2005]

Minh Dao-Tran DERI, July 2011 20/33

Page 47: Exchanging More than Complete Data

An Answer Set Programming Tutorial 4. Extensions

Extensions

Many extensions exist, partly motivated by applicationsSome are syntactic sugar, other strictly add expressivenessIncomplete list:

• disjunction• integrity constraints• strong negation• nested expressions• cardinality constraints (Smodels)• optimization: weight constraints, minimize (Smodels);

weak constraints (DLV)• aggregates (Smodels, DLV)• templates (for macros), external functions (DLVHEX)• Frame Logic syntax (for Semantic Web)• preferences: e.g., PLP, LOPDs• KR frontends (diagnosis, inheritance, planning,...) in DLV

Comprehensive survey: [Niemelä (ed.), 2005]

Minh Dao-Tran DERI, July 2011 20/33

Page 48: Exchanging More than Complete Data

An Answer Set Programming Tutorial 4. Extensions 4.1 Disjunction

Disjunction

The use of disjunction is natural to express indefinite knowledge.

Example

female(X) ∨ male(X)← person(X).

single(dilbert) ∨ husband(dilbert)← man(dilbert).

Disjunction is natural for expressing a “guess” and to createnon-determinism

Example

ok(C) ∨ notok(C)← component(C).

Minh Dao-Tran DERI, July 2011 21/33

Page 49: Exchanging More than Complete Data

An Answer Set Programming Tutorial 4. Extensions 4.1 Disjunction

Disjunction

The use of disjunction is natural to express indefinite knowledge.

Example

female(X) ∨ male(X)← person(X).

single(dilbert) ∨ husband(dilbert)← man(dilbert).

Disjunction is natural for expressing a “guess” and to createnon-determinism

Example

ok(C) ∨ notok(C)← component(C).

Minh Dao-Tran DERI, July 2011 21/33

Page 50: Exchanging More than Complete Data

An Answer Set Programming Tutorial 4. Extensions 4.1 Disjunction

Disjunction

The use of disjunction is natural to express indefinite knowledge.

Example

female(X) ∨ male(X)← person(X).

single(dilbert) ∨ husband(dilbert)← man(dilbert).

Disjunction is natural for expressing a “guess” and to createnon-determinism

Example

ok(C) ∨ notok(C)← component(C).

Minh Dao-Tran DERI, July 2011 21/33

Page 51: Exchanging More than Complete Data

An Answer Set Programming Tutorial 4. Extensions 4.1 Disjunction

Disjunction

The use of disjunction is natural to express indefinite knowledge.

Example

female(X) ∨ male(X)← person(X).

single(dilbert) ∨ husband(dilbert)← man(dilbert).

Disjunction is natural for expressing a “guess” and to createnon-determinism

Example

ok(C) ∨ notok(C)← component(C).

Minh Dao-Tran DERI, July 2011 21/33

Page 52: Exchanging More than Complete Data

An Answer Set Programming Tutorial 4. Extensions 4.2 Integrity Constraints

Integrity Constraints

Addingfail← b1, . . . , bm, not c1, . . . , not cn, not fail.

to P “kills” all stable models of P that• contain b1, . . . , bm, and

• do not contain c1, . . . , cn

This is convenient to eliminate scenarios which does not satisfyintegrity constraints.

Short:

Integrity Constraint

← b1, . . . , bm, not c1, . . . , not cn.

Minh Dao-Tran DERI, July 2011 22/33

Page 53: Exchanging More than Complete Data

An Answer Set Programming Tutorial 4. Extensions 4.2 Integrity Constraints

Integrity Constraints

Addingfail← b1, . . . , bm, not c1, . . . , not cn, not fail.

to P “kills” all stable models of P that• contain b1, . . . , bm, and

• do not contain c1, . . . , cn

This is convenient to eliminate scenarios which does not satisfyintegrity constraints.

Short:

Integrity Constraint

← b1, . . . , bm, not c1, . . . , not cn.

Minh Dao-Tran DERI, July 2011 22/33

Page 54: Exchanging More than Complete Data

An Answer Set Programming Tutorial 4. Extensions 4.2 Integrity Constraints

Example (P2 cont’d)

man(dilbert). (f1)

single(dilbert) ∨ husband(dilbert)← man(dilbert). (r′1)

← husband(X), not wedding_ring(X). (c1)

The constraint c1 eliminates models in which there is no evidence fora husband having a wedding ring.

Single stable model: M1 = {man(dilbert), single(dilbert)}

Minh Dao-Tran DERI, July 2011 23/33

Page 55: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web

Answer Set Solvers

DLV1 http://www.dbai.tuwien.ac.at/proj/dlv/Smodels2 http://www.tcs.hut.fi/Software/smodels/

GnT http://www.tcs.hut.fi/Software/gnt/Cmodels http://www.cs.utexas.edu/users/tag/cmodels/

ASSAT http://assat.cs.ust.hk/NoMore(++) http://www.cs.uni-potsdam.de/~linke/nomore/

Platypus http://www.cs.uni-potsdam.de/platypus/clasp http://www.cs.uni-potsdam.de/clasp/

XASP http://xsb.sourceforge.net/, distributed with XSBaspps http://www.cs.engr.uky.edu/ai/aspps/ccalc http://www.cs.utexas.edu/users/tag/cc/

1+ many extensions, e.g., DLVEX, DLVHEX, DLVDB, DLT, DLV-Complex2+ Smodels_cc

Minh Dao-Tran DERI, July 2011 24/33

Page 56: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web

Answer Set Programming Systems for Debian/Ubuntu

Easy to install:• $ sudo add-apt-repository ppa:tkren/asp• $ sudo apt-get update• $ sudo apt-get install clasp gringo potassco-guide

dlv-installer

With the next version of Ubuntu in October 2011, clasp and gringowill be built in

More details athttp://www.kr.tuwien.ac.at/staff/tkren/deb.html

Minh Dao-Tran DERI, July 2011 25/33

Page 57: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.1 DL-Programs

DL-Programs

A clean approach to combine description logics and logic programsunder answer set semantics

A dl-program consists of two parts:a logic program P,a description logic knowledge base L

L is accessible from P by means of dl-atoms.

ASP Solver ? DL Engine

Minh Dao-Tran DERI, July 2011 26/33

Page 58: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.1 DL-Programs

The famous tweety example

L =

Flier v ¬NonFlier,Penguin v Bird,Penguin v NonFlier,—————–Bird v FlierBird(tweety),Penguin(joe)

P =

{flies(X) ← DL[Flier ] flies;Bird](X),

not DL[Flier ] flies;¬Flier](X).

}The dl-atom device

Can specify a query to L:

DL[Bird](X)

DL[Bird](tweety) true for y s.t. L |= Bird(tweety).

Can push knowledge to L before querying:

DL[Flier] flies;¬Flier](X).

Minh Dao-Tran DERI, July 2011 27/33

Page 59: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.1 DL-Programs

The famous tweety example

L =

Flier v ¬NonFlier,Penguin v Bird,Penguin v NonFlier,—————–Bird v FlierBird(tweety),Penguin(joe)

P =

{flies(X) ← DL[Flier ] flies;Bird](X),

not DL[Flier ] flies;¬Flier](X).

}

The dl-atom device

Can specify a query to L:

DL[Bird](X)

DL[Bird](tweety) true for y s.t. L |= Bird(tweety).

Can push knowledge to L before querying:

DL[Flier] flies;¬Flier](X).

Minh Dao-Tran DERI, July 2011 27/33

Page 60: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.1 DL-Programs

The famous tweety example

L =

Flier v ¬NonFlier,Penguin v Bird,Penguin v NonFlier,—————–Bird v FlierBird(tweety),Penguin(joe)

P =

{flies(X) ← DL[Flier ] flies;Bird](X),

not DL[Flier ] flies;¬Flier](X).

}The dl-atom device

Can specify a query to L:

DL[Bird](X)

DL[Bird](tweety) true for y s.t. L |= Bird(tweety).

Can push knowledge to L before querying:

DL[Flier] flies;¬Flier](X).

Minh Dao-Tran DERI, July 2011 27/33

Page 61: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.1 DL-Programs

The famous tweety example

L =

Flier v ¬NonFlier,Penguin v Bird,Penguin v NonFlier,—————–Bird v FlierBird(tweety),Penguin(joe)

P =

{flies(X) ← DL[Flier ] flies;Bird](X),

not DL[Flier ] flies;¬Flier](X).

}The dl-atom device

Can specify a query to L:

DL[Bird](X)

DL[Bird](tweety) true for y s.t. L |= Bird(tweety).

Can push knowledge to L before querying:

DL[Flier] flies;¬Flier](X).

Minh Dao-Tran DERI, July 2011 27/33

Page 62: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.2 HEX-Programs

HEX-programs

Extends dl-programs from one-to-one coupling to many-one.• Outer Knowledge sources are not constrained to DL knowledge

bases only.

P can interface multiple external sources of knowledge of any sortvia so called external atoms

P has higher order atoms

Minh Dao-Tran DERI, July 2011 28/33

Page 63: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.2 HEX-Programs

HEX-programs

Extends dl-programs from one-to-one coupling to many-one.• Outer Knowledge sources are not constrained to DL knowledge

bases only.

P can interface multiple external sources of knowledge of any sortvia so called external atoms

P has higher order atoms

Minh Dao-Tran DERI, July 2011 28/33

Page 64: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.2 HEX-Programs

HEX-programs

Extends dl-programs from one-to-one coupling to many-one.• Outer Knowledge sources are not constrained to DL knowledge

bases only.

P can interface multiple external sources of knowledge of any sortvia so called external atoms

P has higher order atoms

Minh Dao-Tran DERI, July 2011 28/33

Page 65: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.2 HEX-Programs

An example

subRelation(brotherOf , relativeOf ).

brotherOf (john, al).

relativeOf (john, joe).

brotherOf (al,mick).

invites(john,X) ∨ skip(X)← X 6= john,&reach[relativeOf , john](X).

R(X,Y)← subRelation(P,R),P(X,Y).

someInvited ← invites(john,X).

← not someInvited.

← &degs[invites](Min,Max),Max > 2.

Example

Input: Some data about John’s neighborhoodOutput: Possible picks for persons John might want to invite, according to someconstraints

Minh Dao-Tran DERI, July 2011 29/33

Page 66: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.2 HEX-Programs

An example

subRelation(brotherOf , relativeOf ).

brotherOf (john, al).

relativeOf (john, joe).

brotherOf (al,mick).

invites(john,X) ∨ skip(X)← X 6= john,&reach[relativeOf , john](X).

R(X,Y)← subRelation(P,R),P(X,Y).

someInvited ← invites(john,X).

← not someInvited.

← &degs[invites](Min,Max),Max > 2.

Example

Input: Some data about John’s neighborhoodOutput: Possible picks for persons John might want to invite, according to someconstraints

Minh Dao-Tran DERI, July 2011 29/33

Page 67: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.2 HEX-Programs

An example

subRelation(brotherOf , relativeOf ).

brotherOf (john, al).

relativeOf (john, joe).

brotherOf (al,mick).

invites(john,X) ∨ skip(X)← X 6= john,&reach[relativeOf , john](X).

R(X,Y)← subRelation(P,R),P(X,Y).

someInvited ← invites(john,X).

← not someInvited.

← &degs[invites](Min,Max),Max > 2.

Example

Input: Some data about John’s neighborhoodOutput: Possible picks for persons John might want to invite, according to someconstraints

Minh Dao-Tran DERI, July 2011 29/33

Page 68: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.2 HEX-Programs

An example

subRelation(brotherOf , relativeOf ).

brotherOf (john, al).

relativeOf (john, joe).

brotherOf (al,mick).

invites(john,X) ∨ skip(X)← X 6= john,&reach[relativeOf , john](X).

R(X,Y)← subRelation(P,R),P(X,Y).

someInvited ← invites(john,X).

← not someInvited.

← &degs[invites](Min,Max),Max > 2.

Example

Input: Some data about John’s neighborhoodOutput: Possible picks for persons John might want to invite, according to someconstraints

Minh Dao-Tran DERI, July 2011 29/33

Page 69: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.2 HEX-Programs

Higher order atoms

subRelation(brotherOf , relativeOf ).

R(X,Y)← subRelation(P,R),P(X,Y).

brotherOf (john, al).

relativeOf (john, joe).

brotherOf (al,mick).

The device of higher order atoms

Predicate names can be variables

Constants can appear both as terms values or as predicate values

Allows (comfortable) meta-reasoning

subRelation(brotherOf , relativeOf ). ⇒ relativeOf (X,Y)← brotherOf (X,Y).

R(X,Y)← subRelation(P,R),P(X,Y).

Minh Dao-Tran DERI, July 2011 30/33

Page 70: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.2 HEX-Programs

Higher order atoms

subRelation(brotherOf , relativeOf ).

R(X,Y)← subRelation(P,R),P(X,Y).

brotherOf (john, al).

relativeOf (john, joe).

brotherOf (al,mick).

The device of higher order atoms

Predicate names can be variables

Constants can appear both as terms values or as predicate values

Allows (comfortable) meta-reasoning

subRelation(brotherOf , relativeOf ). ⇒ relativeOf (X,Y)← brotherOf (X,Y).

R(X,Y)← subRelation(P,R),P(X,Y).

Minh Dao-Tran DERI, July 2011 30/33

Page 71: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.2 HEX-Programs

Higher order atoms

subRelation(brotherOf , relativeOf ).

R(X,Y)← subRelation(P,R),P(X,Y).

brotherOf (john, al).

relativeOf (john, joe).

brotherOf (al,mick).

The device of higher order atoms

Predicate names can be variables

Constants can appear both as terms values or as predicate values

Allows (comfortable) meta-reasoning

subRelation(brotherOf , relativeOf ). ⇒ relativeOf (X,Y)← brotherOf (X,Y).

R(X,Y)← subRelation(P,R),P(X,Y).

Minh Dao-Tran DERI, July 2011 30/33

Page 72: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.2 HEX-Programs

Higher order atoms

subRelation(brotherOf , relativeOf ).

R(X,Y)← subRelation(P,R),P(X,Y).

brotherOf (john, al).

relativeOf (john, joe).

brotherOf (al,mick).

The device of higher order atoms

Predicate names can be variables

Constants can appear both as terms values or as predicate values

Allows (comfortable) meta-reasoning

subRelation(brotherOf , relativeOf ).

⇒ relativeOf (X,Y)← brotherOf (X,Y).

R(X,Y)← subRelation(P,R),P(X,Y).

Minh Dao-Tran DERI, July 2011 30/33

Page 73: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.2 HEX-Programs

Higher order atoms

subRelation(brotherOf , relativeOf ).

R(X,Y)← subRelation(P,R),P(X,Y).

brotherOf (john, al).

relativeOf (john, joe).

brotherOf (al,mick).

The device of higher order atoms

Predicate names can be variables

Constants can appear both as terms values or as predicate values

Allows (comfortable) meta-reasoning

subRelation(brotherOf , relativeOf ). ⇒ relativeOf (X,Y)← brotherOf (X,Y).

R(X,Y)← subRelation(P,R),P(X,Y).

Minh Dao-Tran DERI, July 2011 30/33

Page 74: Exchanging More than Complete Data

An Answer Set Programming Tutorial 5. Answer Set for the Semantic Web 5.2 HEX-Programs

External atoms

&reach[relativeOf , john](X) (2)

&degs[invites](Min,Max) (3)

The device of external atoms

Each external predicate is tied to a corresponding evaluationfunction

E.g. &reach corresponds to f&reach.

For a given interpretation I, I |= &reach[relativeOf , john](x) iff&reach(I, relativeOf , john) = 1

Minh Dao-Tran DERI, July 2011 31/33

Page 75: Exchanging More than Complete Data

An Answer Set Programming Tutorial 6. Future Directions of ASP

Current state-of-the-art

Semantics

Introduction of Function Symbols [Syrjänen, 2001],[Bonatti,2004],[Calimeri et al., 2008],[Šimkus and Eiter, 2007],[Eiter and Šimkus,2009]

Modularity [Dao-Tran et al., 2009],[Janhunen et al., 2007],[Oikarinen andJanhunen, 2008],[Tari et al., 2005],[Balduccini, 2007],[Baral et al.,2006],[Calimeri and Ianni, 2006],[Polleres et al., 2006],[Analyti et al., 2008]

Study of equivalence [Lifschitz et al., 2001],[Gelfond, 2008],[Eiter et al.,2007],[Eiter et al., 2004],[Woltran, 2008]

Engineering

Debuggers [El-Khatib et al., 2005],[Brain and Vos, 2005] and in-databaseevaluation [Terracina et al., 2008]

See the SEA workshop series http://sea07.cs.bath.ac.uk/

Minh Dao-Tran DERI, July 2011 32/33

Page 76: Exchanging More than Complete Data

An Answer Set Programming Tutorial 6. Future Directions of ASP

Current state-of-the-art

Semantics

Introduction of Function Symbols [Syrjänen, 2001],[Bonatti,2004],[Calimeri et al., 2008],[Šimkus and Eiter, 2007],[Eiter and Šimkus,2009]

Modularity [Dao-Tran et al., 2009],[Janhunen et al., 2007],[Oikarinen andJanhunen, 2008],[Tari et al., 2005],[Balduccini, 2007],[Baral et al.,2006],[Calimeri and Ianni, 2006],[Polleres et al., 2006],[Analyti et al., 2008]

Study of equivalence [Lifschitz et al., 2001],[Gelfond, 2008],[Eiter et al.,2007],[Eiter et al., 2004],[Woltran, 2008]

Engineering

Debuggers [El-Khatib et al., 2005],[Brain and Vos, 2005] and in-databaseevaluation [Terracina et al., 2008]

See the SEA workshop series http://sea07.cs.bath.ac.uk/

Minh Dao-Tran DERI, July 2011 32/33

Page 77: Exchanging More than Complete Data

An Answer Set Programming Tutorial 6. Future Directions of ASP

Current state-of-the-art II

Scalability

Intelligent and lazy grounders [Calimeri et al., 2008],[Gebser et al.,2008],[Palù et al., 2008], [Lefévre and Nicolas, 2008]

Incremental reasoning [Gebser et al., 2011]

See the Answer Set Programming competitionhttp://www.cs.kuleuven.be/∼dtai/events/ASP-competition/https://www.mat.unical.it/aspcomp2011

Minh Dao-Tran DERI, July 2011 33/33

Page 78: Exchanging More than Complete Data

An Answer Set Programming Tutorial 7. Playing with ASP

xkcd Knapsack

order(Food) ∨ skip(Food)← menu(Food, _).

ok ← 825 ≤ #sum{Price : order(Food),menu(Food,Price)} ≤ 825.

← not ok.

menu(mixed_fruit, 215).menu(french_fries, 275).menu(side_salad, 335).menu(host_wings, 355).menu(mozzarella_sticks, 420).menu(samples_place, 580).

Minh Dao-Tran DERI, July 2011 34/33

Page 79: Exchanging More than Complete Data

An Answer Set Programming Tutorial 7. Playing with ASP

Graph 3-Coloring

r(X) ∨ g(X) ∨ b(X) ← node(X).← edge(X,Y), r(X), r(Y).← edge(X,Y), g(X), g(Y).← edge(X,Y), b(X), b(Y).

node(a). node(b). node(c).edge(a, b). edge(b, c). edge(a, c).

Minh Dao-Tran DERI, July 2011 35/33

Page 80: Exchanging More than Complete Data

An Answer Set Programming Tutorial 7. Playing with ASP

Hamilton Path/Cycle

inPath(X,Y) ∨ outPath(X,Y) ← edge(X,Y).

← inPath(X,Y), inPath(X,Y1), Y 6= Y1.← inPath(X,Y), inPath(X1,Y), X 6= X1.← node(X), not reached(X).

← not start_reached.

reached(X)← start(X).reached(X)← reached(Y), inPath(Y,X).

start_reached ← start(Y), inPath(X,Y).

Minh Dao-Tran DERI, July 2011 36/33

Page 81: Exchanging More than Complete Data

An Answer Set Programming Tutorial 7. Playing with ASP

Hamilton Path/Cycle

inPath(X,Y) ∨ outPath(X,Y) ← edge(X,Y).

← inPath(X,Y), inPath(X,Y1), Y 6= Y1.← inPath(X,Y), inPath(X1,Y), X 6= X1.← node(X), not reached(X).← not start_reached.

reached(X)← start(X).reached(X)← reached(Y), inPath(Y,X).start_reached ← start(Y), inPath(X,Y).

Minh Dao-Tran DERI, July 2011 36/33

Page 82: Exchanging More than Complete Data

An Answer Set Programming Tutorial 7. Playing with ASP

Choosing wine

Assume that we have a Wine ontology and specification of who preferwhich type of wine.

person(“axel”). preferredWine(“axel”, “SweetWine”).person(“gibbi”). preferredWine(“gibbi”, “DessertWine”).person(“roman”). preferredWine(“roman”, “ItalianWine”).

isA(X, “SweetWine”) ← DL[SweetWine](X).isA(X, “DessertWine”) ← DL[DessertWine](X).isA(X, “ItalianWine”) ← DL[ItalianWine](X).

compliantBottle(X,Z)← preferredWine(X,Y), isA(Z,Y).

bottleChosen(X) ∨ nonbottleChosen(X)← compliantBottle(_,X).

hasBottleChosen(X)← bottleChosen(Z), compliantBottle(X,Z).

← person(X), not hasBottleChosen(X).

← bottleChosen(X).[1 : 1]

Minh Dao-Tran DERI, July 2011 37/33

Page 83: Exchanging More than Complete Data

An Answer Set Programming Tutorial 7. Playing with ASP

Choosing wine

Assume that we have a Wine ontology and specification of who preferwhich type of wine.

person(“axel”). preferredWine(“axel”, “SweetWine”).person(“gibbi”). preferredWine(“gibbi”, “DessertWine”).person(“roman”). preferredWine(“roman”, “ItalianWine”).

isA(X, “SweetWine”) ← DL[SweetWine](X).isA(X, “DessertWine”) ← DL[DessertWine](X).isA(X, “ItalianWine”) ← DL[ItalianWine](X).

compliantBottle(X,Z)← preferredWine(X,Y), isA(Z,Y).

bottleChosen(X) ∨ nonbottleChosen(X)← compliantBottle(_,X).

hasBottleChosen(X)← bottleChosen(Z), compliantBottle(X,Z).

← person(X), not hasBottleChosen(X).

← bottleChosen(X).[1 : 1]

Minh Dao-Tran DERI, July 2011 37/33

Page 84: Exchanging More than Complete Data

An Answer Set Programming Tutorial 7. Playing with ASP

Choosing wine

Assume that we have a Wine ontology and specification of who preferwhich type of wine.

person(“axel”). preferredWine(“axel”, “SweetWine”).person(“gibbi”). preferredWine(“gibbi”, “DessertWine”).person(“roman”). preferredWine(“roman”, “ItalianWine”).

isA(X, “SweetWine”) ← DL[SweetWine](X).isA(X, “DessertWine”) ← DL[DessertWine](X).isA(X, “ItalianWine”) ← DL[ItalianWine](X).

compliantBottle(X,Z)← preferredWine(X,Y), isA(Z,Y).

bottleChosen(X) ∨ nonbottleChosen(X)← compliantBottle(_,X).

hasBottleChosen(X)← bottleChosen(Z), compliantBottle(X,Z).

← person(X), not hasBottleChosen(X).

← bottleChosen(X).[1 : 1]

Minh Dao-Tran DERI, July 2011 37/33

Page 85: Exchanging More than Complete Data

An Answer Set Programming Tutorial 7. Playing with ASP

Choosing wine

Assume that we have a Wine ontology and specification of who preferwhich type of wine.

person(“axel”). preferredWine(“axel”, “SweetWine”).person(“gibbi”). preferredWine(“gibbi”, “DessertWine”).person(“roman”). preferredWine(“roman”, “ItalianWine”).

isA(X, “SweetWine”) ← DL[SweetWine](X).isA(X, “DessertWine”) ← DL[DessertWine](X).isA(X, “ItalianWine”) ← DL[ItalianWine](X).

compliantBottle(X,Z)← preferredWine(X,Y), isA(Z,Y).

bottleChosen(X) ∨ nonbottleChosen(X)← compliantBottle(_,X).

hasBottleChosen(X)← bottleChosen(Z), compliantBottle(X,Z).

← person(X), not hasBottleChosen(X).

← bottleChosen(X).[1 : 1]

Minh Dao-Tran DERI, July 2011 37/33

Page 86: Exchanging More than Complete Data

An Answer Set Programming Tutorial 7. Playing with ASP

Choosing wine

Assume that we have a Wine ontology and specification of who preferwhich type of wine.

person(“axel”). preferredWine(“axel”, “SweetWine”).person(“gibbi”). preferredWine(“gibbi”, “DessertWine”).person(“roman”). preferredWine(“roman”, “ItalianWine”).

isA(X, “SweetWine”) ← DL[SweetWine](X).isA(X, “DessertWine”) ← DL[DessertWine](X).isA(X, “ItalianWine”) ← DL[ItalianWine](X).

compliantBottle(X,Z)← preferredWine(X,Y), isA(Z,Y).

bottleChosen(X) ∨ nonbottleChosen(X)← compliantBottle(_,X).

hasBottleChosen(X)← bottleChosen(Z), compliantBottle(X,Z).

← person(X), not hasBottleChosen(X).

← bottleChosen(X).[1 : 1]

Minh Dao-Tran DERI, July 2011 37/33

Page 87: Exchanging More than Complete Data

An Answer Set Programming Tutorial 7. Playing with ASP

Choosing wine

Assume that we have a Wine ontology and specification of who preferwhich type of wine.

person(“axel”). preferredWine(“axel”, “SweetWine”).person(“gibbi”). preferredWine(“gibbi”, “DessertWine”).person(“roman”). preferredWine(“roman”, “ItalianWine”).

isA(X, “SweetWine”) ← DL[SweetWine](X).isA(X, “DessertWine”) ← DL[DessertWine](X).isA(X, “ItalianWine”) ← DL[ItalianWine](X).

compliantBottle(X,Z)← preferredWine(X,Y), isA(Z,Y).

bottleChosen(X) ∨ nonbottleChosen(X)← compliantBottle(_,X).

hasBottleChosen(X)← bottleChosen(Z), compliantBottle(X,Z).

← person(X), not hasBottleChosen(X).

← bottleChosen(X).[1 : 1]

Minh Dao-Tran DERI, July 2011 37/33

Page 88: Exchanging More than Complete Data

An Answer Set Programming Tutorial 7. Playing with ASP

Choosing wine

Assume that we have a Wine ontology and specification of who preferwhich type of wine.

person(“axel”). preferredWine(“axel”, “SweetWine”).person(“gibbi”). preferredWine(“gibbi”, “DessertWine”).person(“roman”). preferredWine(“roman”, “ItalianWine”).

isA(X, “SweetWine”) ← DL[SweetWine](X).isA(X, “DessertWine”) ← DL[DessertWine](X).isA(X, “ItalianWine”) ← DL[ItalianWine](X).

compliantBottle(X,Z)← preferredWine(X,Y), isA(Z,Y).

bottleChosen(X) ∨ nonbottleChosen(X)← compliantBottle(_,X).

hasBottleChosen(X)← bottleChosen(Z), compliantBottle(X,Z).

← person(X), not hasBottleChosen(X).

← bottleChosen(X).[1 : 1]Minh Dao-Tran DERI, July 2011 37/33

Page 89: Exchanging More than Complete Data

An Answer Set Programming Tutorial 7. Playing with ASP

People whom Axel knows

triple(X,Y,Z) ← &rdf [“foaf .axel.rdf”](X,Y,Z).

knownbyAxelbyName(X) ← triple(ID, “foaf : name”, “Axel Polleres”),triple(ID, “foaf : knows”, ID2),triple(ID2, “foaf : name”,X).

Minh Dao-Tran DERI, July 2011 38/33

Page 90: Exchanging More than Complete Data

References I

Anastasia Analyti, Grigoris Antoniou, and Carlos Viegas Damásio.

A principled framework for modular web rule bases and its semantics.

In Proceedings of the 11th International Conference on Principles ofKnowledge Representation and Reasoning (KR2008). AAAI Press,September 2008.

Marcello Balduccini.

Modules and Signature Declarations for A-Prolog: Progress Report.

In Marina de Vos and Torsten Schaub, editors, Informal Proceedings of the1st International Workshop on Software Engineering for Answer SetProgramming, Tempe, AZ (USA), May 2007, 2007.

Available at http://sea07.cs.bath.ac.uk/downloads/sea07-proceedings.pdf.

Page 91: Exchanging More than Complete Data

References II

Chitta Baral, Juraj Dzifcak, and Hiro Takahashi.

Macros, Macro calls and Use of Ensembles in Modular Answer SetProgramming.

In Proceedings of the 22th International Conference on Logic Programming(ICLP 2006), number 4079 in LNCS, pages 376–390. Springer, 2006.

Piero A. Bonatti.

Reasoning with infinite stable models.

Artificial Intelligence, 156(1):75–111, 2004.

Martin Brain and Marina De Vos.

Debugging logic programs under the answer set semantics.

In Answer Set Programming, 2005.

Page 92: Exchanging More than Complete Data

References III

Francesco Calimeri and Giovambattista Ianni.

Template programs for Disjunctive Logic Programming: An operationalsemantics.

AI Communications, 19(3):193–206, 2006.

Francesco Calimeri, Susanna Cozza, Giovambattista Ianni, and NicolaLeone.

Computable Functions in ASP: Theory and Implementation.

In Logic Programming, 24th International Conference, ICLP 2008, Udine,Italy, December 9-13 2008, Proceedings, volume 5366 of LNCS, pages407–424. Springer, 2008.

Minh Dao-Tran, Thomas Eiter, Michael Fink, and Thomas Krennwallner.

Modular nonmonotonic logic programming revisited.

In P. Hill and D.S. Warren, editors, Proceedings 25th InternationalConference on Logic Programming (ICLP 2009), volume 5649 of LNCS,pages 145–159. Springer, July 2009.

Page 93: Exchanging More than Complete Data

References IV

Thomas Eiter and Mantas Šimkus.

Bidirectional answer set programs with function symbols.

In C. Boutilier, editor, Proceedings of the 21st International JointConference on Artificial Intelligence (IJCAI-09). AAAI Press/IJCAI, 2009.

T. Eiter, M. Fink, H. Tompits, and S. Woltran.

Simplifying logic programs under uniform and strong equivalence.

In Ilkka Niemelä and Vladimir Lifschitz, editors, Proceedings of the 7thInternational Conference on Logic Programming and NonmonotonicReasoning (LPNMR 2004), number 2923 in LNCS, pages 87–99. Springer,2004.

Thomas Eiter, Michael Fink, and Stefan Woltran.

Semantical Characterizations and Complexity of Equivalences in AnswerSet Programming.

ACM Trans. Comput. Log., 8(3), 2007.

Article 17 (53 + 11 pages).

Page 94: Exchanging More than Complete Data

References V

Omar El-Khatib, Enrico Pontelli, and Tran Cao Son.

Justification and debugging of answer set programs in asp.

In AADEBUG, pages 49–58, 2005.

Martin Gebser, Roland Kaminski, Benjamin Kaufmann, Max Ostrowski,Torsten Schaub, and Sven Thiele.

Engineering an Incremental ASP Solver.

In M.G. de La Banda and E. Pontelli, editors, Proceedings 24thInternational Conference on Logic Programming (ICLP 2008), number 5366in LNCS, pages 190–205. Springer, 2008.

Martin Gebser, Orkunt Sabuncu, and Torsten Schaub.

An incremental answer set programming based system for finite modelcomputation.

AI Commun., 24(2):195–212, 2011.

Page 95: Exchanging More than Complete Data

References VI

Michael Gelfond and Vladimir Lifschitz.

The Stable Model Semantics for Logic Programming.

In Logic Programming: Proceedings Fifth Intl Conference and Symposium,pages 1070–1080, Cambridge, Mass., 1988. MIT Press.

Michael Gelfond and Vladimir Lifschitz.

Classical Negation in Logic Programs and Disjunctive Databases.

New Generation Computing, 9:365–385, 1991.

M. Gelfond.

Answer sets.

In B. Porter F. van Harmelen, V. Lifschitz, editor, Handbook of KnowledgeRepresentation, chapter 7, pages 285–316. Elsevier, 2008.

Page 96: Exchanging More than Complete Data

References VII

Tomi Janhunen, Emilia Oikarinen, Hans Tompits, and Stefan Woltran.

Modularity Aspects of Disjunctive Stable Models.

In Proceedings of the 9th International Conference on Logic Programmingand Nonmonotonic Reasoning, volume 4483 of LNCS, pages 175–187.Springer, May 2007.

Claire Lefévre and Pascal Nicolas.

Integrating grounding in the search process for answer set computing.

In ASPOCP: Answer Set Programming and Other Constraint Paradigms,pages 89–103, 2008.

Vladimir Lifschitz, David Pearce, and Agustín Valverde.

Strongly equivalent logic programs.

ACM Trans. Comput. Log., 2(4):526–541, 2001.

Page 97: Exchanging More than Complete Data

References VIII

Ilkka Niemelä (ed.).

Language Extensions and Software Engineering for ASP.

Technical Report WP3, Working Group on Answer Set Programming(WASP), IST-FET-2001-37004, September 2005.

Available at http://www.tcs.hut.fi/Research/Logic/wasp/wp3/wasp-wp3-web/.

Emilia Oikarinen and Tomi Janhunen.

Achieving compositionality of the stable model semantics for Smodelsprograms.

Theory and Practice of Logic Programming, 8(5–6):717–761, November2008.

A. Dal Palù, A. Dovier, E. Pontelli, and G. Rossi.

Gasp: Answer set programming with lazy grounding.

In LaSh 2008: LOGIC AND SEARCH - Computation of structures fromdeclarative descriptions, 2008.

Page 98: Exchanging More than Complete Data

References IX

Axel Polleres, Cristina Feier, and Andreas Harth.

Rules with Contextually Scoped Negation.

In Proceedings of the 3rd European Conference on Semantic Web (ESWC2006), volume 4011 of LNCS, pages 332–347. Springer, 2006.

Mantas Šimkus and Thomas Eiter.

FDNC: Decidable non-monotonic disjunctive logic programs with functionsymbols.

In N. Dershowitz and A. Voronkov, editors, Proceedings 14th InternationalConference on Logic for Programming, Artificial Intelligence and Reasoning(LPAR 2007), number 4790 in LNCS, pages 514–530. Springer, 2007.

Extended Paper to appear in ACM Trans. Computational Logic.

Page 99: Exchanging More than Complete Data

References X

Tommi Syrjänen.

Omega-restricted logic programs.

In Proceedings of the 6th International Conference on Logic Programmingand Nonmonotonic Reasoning, Vienna, Austria, September 2001.Springer-Verlag.

Luis Tari, Chitta Baral, and Saadat Anwar.

A Language for Modular Answer Set Programming: Application to ACCTournament Scheduling.

In Proceedings of the 3Proceedings of the 3rd International ASP’05Workshop, Bath, UK, 27th–29th July 2005, volume 142 of CEUR WorkshopProceedings, pages 277–293. CEUR WS, July 2005.

Giorgio Terracina, Nicola Leone, Vincenzino Lio, and Claudio Panetta.

Experimenting with recursive queries in database and logic programmingsystems.

TPLP, 8(2):129–165, 2008.

Page 100: Exchanging More than Complete Data

References XI

Allen Van Gelder, Kenneth A. Ross, and John S. Schlipf.

The Well-Founded Semantics for General Logic Programs.

Journal of the ACM, 38(3):620–650, 1991.

Stefan Woltran.

A common view on strong, uniform, and other notions of equivalence inanswer-set programming.

Theory and Practice of Logic Programming, 8(2):217–234, 2008.

Page 101: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.1 ASP Performance

The 3rd ASP Competition

Results from https://www.mat.unical.it/aspcomp20111

Input size (plain text of facts):

Reachability: 0.5 — 20 MB

Grammar Based Information Extraction: 1.5 — 5 MB

1Many thanks to Giovambattista Ianni for insightful analysis of the results.Minh Dao-Tran DERI, July 2011 50/33

Page 102: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.1 ASP Performance

The 3rd ASP Competition - Scoring

Minh Dao-Tran DERI, July 2011 51/33

Page 103: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.1 ASP Performance

clasp Benchmarking

http://www.cs.uni-potsdam.de/clasp/?page=experiments

Check some of the well-known problems: HamiltonianCycle,HamiltonianPath, Su-DoKu, TowersOfHanoiCompetition

Minh Dao-Tran DERI, July 2011 52/33

Page 104: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.2 What is ASP good for?

What is ASP good for?

Combinatorial search problems (some with substantial amount ofdata):

• For instance, auctions, bio-informatics, computer-aided verification,configuration, constraint satisfaction, diagnosis, informationintegration, planning and scheduling, security analysis, semantic web,wire-routing, zoology and linguistics, and many more

A favorite application : Using ASP as a basis for a decision supportsystem for NASA’s space shuttle (Gelfond et al., Texas Tech)And more:

• Automatic synthesis of multiprocessor systems• Inconsistency detection, diagnosis, repair, and prediction in large

biological networks• Home monitoring for risk prevention in ambient assisted living• General game playing

Minh Dao-Tran DERI, July 2011 53/33

Page 105: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.3 What is the difference compared to Prolog?

Logic Programming – Prolog revisited

Prolog = “Programming in Logic”

Basic data structures: terms

Programs: rules and facts

Computing: Queries (goals)

• Proofs provide answers• SLD-resolution• unification - basic mechanism to manipulate data structures

Extensive use of recursion

Minh Dao-Tran DERI, July 2011 54/33

Page 106: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.3 What is the difference compared to Prolog?

Prolog – Truly Declarative Programming?

Exampleparent(John,Mary).parent(Mary,James).

ancestor(X,Y) : − parent(X,Y).ancestor(X,Z) : − parent(X,Y),ancestor(Y,Z).

vs.

parent(John,Mary).parent(Mary,James).

ancestor(X,Z) : − ancestor(Y,Z),parent(X,Y).ancestor(X,Y) : − parent(X,Y).

Query: ?- ancestor(John,W)

Minh Dao-Tran DERI, July 2011 55/33

Page 107: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.3 What is the difference compared to Prolog?

Desiderata

Relieve the programmer from several concerns.

It is desirable that

the order of program rules does not matter;

the order of subgoals in a rule does not matter;

termination is not subject to such order.

“Pure” declarative programming

Prolog does not satisfy these desiderata

Satisfied e.g. by the answer set semantics of logic programs

Minh Dao-Tran DERI, July 2011 56/33

Page 108: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.3 What is the difference compared to Prolog?

Desiderata

Relieve the programmer from several concerns.

It is desirable that

the order of program rules does not matter;

the order of subgoals in a rule does not matter;

termination is not subject to such order.

“Pure” declarative programming

Prolog does not satisfy these desiderata

Satisfied e.g. by the answer set semantics of logic programs

Minh Dao-Tran DERI, July 2011 56/33

Page 109: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.3 What is the difference compared to Prolog?

Programs with Negation

Prolog: “not 〈X〉” means “Negation as Failure (to prove to 〈X〉)”

Different from negation in classical logic!

Example (Program P3)

man(dilbert).single(X) : − man(X), nothusband(X).husband(X) : − fail.

Query:?− single(X).

Answer:X = dilbert.

Minh Dao-Tran DERI, July 2011 57/33

Page 110: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.3 What is the difference compared to Prolog?

Programs with Negation

Prolog: “not 〈X〉” means “Negation as Failure (to prove to 〈X〉)”

Different from negation in classical logic!

Example (Program P3)

man(dilbert).single(X) : − man(X), nothusband(X).husband(X) : − fail.

Query:?− single(X).

Answer:X = dilbert.

Minh Dao-Tran DERI, July 2011 57/33

Page 111: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.3 What is the difference compared to Prolog?

Programs with Negation

Prolog: “not 〈X〉” means “Negation as Failure (to prove to 〈X〉)”

Different from negation in classical logic!

Example (Program P3)

man(dilbert).single(X) : − man(X), nothusband(X).husband(X) : − fail.

Query:?− single(X).

Answer:X = dilbert.

Minh Dao-Tran DERI, July 2011 57/33

Page 112: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.3 What is the difference compared to Prolog?

Programs with Negation

Prolog: “not 〈X〉” means “Negation as Failure (to prove to 〈X〉)”

Different from negation in classical logic!

Example (Program P3)

man(dilbert).single(X) : − man(X), nothusband(X).husband(X) : − fail.

Query:?− single(X).

Answer:X = dilbert.

Minh Dao-Tran DERI, July 2011 57/33

Page 113: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.3 What is the difference compared to Prolog?

Example (cont’d)

Modifying the last rule of P3, we get P4:

man(dilbert).

single(X)← man(X), not husband(X).

husband(X)← man(X), not single(X).

Result in Prolog ????

Problem: not a single intuitive model!

Two intuitive Herbrand models:

M1 = {man(dilbert), single(dilbert)}, and

M2 = {man(dilbert), husband(dilbert)} .

Which one to choose?

Minh Dao-Tran DERI, July 2011 58/33

Page 114: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.3 What is the difference compared to Prolog?

Example (cont’d)

Modifying the last rule of P3, we get P4:

man(dilbert).

single(X)← man(X), not husband(X).

husband(X)← man(X), not single(X).

Result in Prolog ????

Problem: not a single intuitive model!

Two intuitive Herbrand models:

M1 = {man(dilbert), single(dilbert)}, and

M2 = {man(dilbert), husband(dilbert)} .

Which one to choose?

Minh Dao-Tran DERI, July 2011 58/33

Page 115: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.3 What is the difference compared to Prolog?

Example (cont’d)

Modifying the last rule of P3, we get P4:

man(dilbert).

single(X)← man(X), not husband(X).

husband(X)← man(X), not single(X).

Result in Prolog ????

Problem: not a single intuitive model!

Two intuitive Herbrand models:

M1 = {man(dilbert), single(dilbert)}, and

M2 = {man(dilbert), husband(dilbert)} .

Which one to choose?

Minh Dao-Tran DERI, July 2011 58/33

Page 116: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.4 Semantics of Logic Programs With Negation

Semantics of Logic Programs With Negation

“War of Semantics” in Logic Programming (1980/90s):

Meaning of programs like the Dilbert example above

Great Schism: Single model vs. multiple model semantics

To date:• Well-Founded Semantics [Van Gelder et al., 1991]

Partial model: man(dilbert) is true,single(dilbert), husband(dilbert) are unknown

• Answer Set (alias Stable Model) Semantics by Gelfond and Lifschitz[1988,1991].

Alternative models: M1 = {man(dilbert), single(dilbert)},M2 = {man(dilbert), husband(dilbert)}.

Agreement for so-called “stratified programs”

Different selection principles for non-stratified programs

Minh Dao-Tran DERI, July 2011 59/33

Page 117: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.4 Semantics of Logic Programs With Negation

Semantics of Logic Programs With Negation

“War of Semantics” in Logic Programming (1980/90s):

Meaning of programs like the Dilbert example above

Great Schism: Single model vs. multiple model semantics

To date:• Well-Founded Semantics [Van Gelder et al., 1991]

Partial model: man(dilbert) is true,single(dilbert), husband(dilbert) are unknown

• Answer Set (alias Stable Model) Semantics by Gelfond and Lifschitz[1988,1991].

Alternative models: M1 = {man(dilbert), single(dilbert)},M2 = {man(dilbert), husband(dilbert)}.

Agreement for so-called “stratified programs”

Different selection principles for non-stratified programs

Minh Dao-Tran DERI, July 2011 59/33

Page 118: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.4 Semantics of Logic Programs With Negation

Semantics of Logic Programs With Negation

“War of Semantics” in Logic Programming (1980/90s):

Meaning of programs like the Dilbert example above

Great Schism: Single model vs. multiple model semantics

To date:• Well-Founded Semantics [Van Gelder et al., 1991]

Partial model: man(dilbert) is true,single(dilbert), husband(dilbert) are unknown

• Answer Set (alias Stable Model) Semantics by Gelfond and Lifschitz[1988,1991].

Alternative models: M1 = {man(dilbert), single(dilbert)},M2 = {man(dilbert), husband(dilbert)}.

Agreement for so-called “stratified programs”

Different selection principles for non-stratified programs

Minh Dao-Tran DERI, July 2011 59/33

Page 119: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.4 Semantics of Logic Programs With Negation

Semantics of Logic Programs With Negation

“War of Semantics” in Logic Programming (1980/90s):

Meaning of programs like the Dilbert example above

Great Schism: Single model vs. multiple model semantics

To date:• Well-Founded Semantics [Van Gelder et al., 1991]

Partial model: man(dilbert) is true,single(dilbert), husband(dilbert) are unknown

• Answer Set (alias Stable Model) Semantics by Gelfond and Lifschitz[1988,1991].

Alternative models: M1 = {man(dilbert), single(dilbert)},M2 = {man(dilbert), husband(dilbert)}.

Agreement for so-called “stratified programs”

Different selection principles for non-stratified programs

Minh Dao-Tran DERI, July 2011 59/33

Page 120: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.4 Semantics of Logic Programs With Negation

Semantics of Logic Programs With Negation

“War of Semantics” in Logic Programming (1980/90s):

Meaning of programs like the Dilbert example above

Great Schism: Single model vs. multiple model semantics

To date:• Well-Founded Semantics [Van Gelder et al., 1991]

Partial model: man(dilbert) is true,single(dilbert), husband(dilbert) are unknown

• Answer Set (alias Stable Model) Semantics by Gelfond and Lifschitz[1988,1991].

Alternative models: M1 = {man(dilbert), single(dilbert)},M2 = {man(dilbert), husband(dilbert)}.

Agreement for so-called “stratified programs”

Different selection principles for non-stratified programs

Minh Dao-Tran DERI, July 2011 59/33

Page 121: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.5 Minimality

Minimality

Semantics: disjunction is minimal (different from classical logic):

a ∨ b ∨ c.

Minimal models: {a}, {b}, and {c}.

actually subset minimal:

a ∨ b. a ∨ c.

Minimal models: {a} and {b, c}.

a ∨ b. a← b

Models {a} and {a, b}, but only {a} is minimal.

but minimality is not necessarily exclusive:

a ∨ b. b ∨ c. a ∨ c.

Minimal models: {a, b}, {a, c}, and {b, c}.

Minh Dao-Tran DERI, July 2011 60/33

Page 122: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.5 Minimality

Minimality

Semantics: disjunction is minimal (different from classical logic):

a ∨ b ∨ c.

Minimal models: {a}, {b}, and {c}.

actually subset minimal:

a ∨ b. a ∨ c.

Minimal models: {a} and {b, c}.

a ∨ b. a← b

Models {a} and {a, b}, but only {a} is minimal.

but minimality is not necessarily exclusive:

a ∨ b. b ∨ c. a ∨ c.

Minimal models: {a, b}, {a, c}, and {b, c}.

Minh Dao-Tran DERI, July 2011 60/33

Page 123: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.5 Minimality

Minimality

Semantics: disjunction is minimal (different from classical logic):

a ∨ b ∨ c.

Minimal models: {a}, {b}, and {c}.

actually subset minimal:

a ∨ b. a ∨ c.

Minimal models: {a} and {b, c}.

a ∨ b. a← b

Models {a} and {a, b}, but only {a} is minimal.

but minimality is not necessarily exclusive:

a ∨ b. b ∨ c. a ∨ c.

Minimal models: {a, b}, {a, c}, and {b, c}.

Minh Dao-Tran DERI, July 2011 60/33

Page 124: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.5 Minimality

Minimality

Semantics: disjunction is minimal (different from classical logic):

a ∨ b ∨ c.

Minimal models: {a}, {b}, and {c}.

actually subset minimal:

a ∨ b. a ∨ c.

Minimal models: {a} and {b, c}.

a ∨ b. a← b

Models {a} and {a, b}, but only {a} is minimal.

but minimality is not necessarily exclusive:

a ∨ b. b ∨ c. a ∨ c.

Minimal models: {a, b}, {a, c}, and {b, c}.Minh Dao-Tran DERI, July 2011 60/33

Page 125: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.5 Minimality

Minimal Model Semantics

A logic program has multiple models in general.

Select one of these models as the canonical model.

Commonly accepted: truth of an atom in model I should be“founded” by clauses.

Example

GivenP2 = {a← b. b← c. c},

truth of a in the model I = {a, b, c} is “founded.”

GivenP2 = {a← b. b← a. c},

truth of a in the model I = {a, b, c} is not founded.

Minh Dao-Tran DERI, July 2011 61/33

Page 126: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.5 Minimality

Minimal Model Semantics

A logic program has multiple models in general.

Select one of these models as the canonical model.

Commonly accepted: truth of an atom in model I should be“founded” by clauses.

Example

GivenP2 = {a← b. b← c. c},

truth of a in the model I = {a, b, c} is “founded.”

GivenP2 = {a← b. b← a. c},

truth of a in the model I = {a, b, c} is not founded.

Minh Dao-Tran DERI, July 2011 61/33

Page 127: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.5 Minimality

Minimal Model Semantics

A logic program has multiple models in general.

Select one of these models as the canonical model.

Commonly accepted: truth of an atom in model I should be“founded” by clauses.

Example

GivenP2 = {a← b. b← c. c},

truth of a in the model I = {a, b, c} is “founded.”

GivenP2 = {a← b. b← a. c},

truth of a in the model I = {a, b, c} is not founded.

Minh Dao-Tran DERI, July 2011 61/33

Page 128: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.5 Minimality

Minimal Model Semantics (cont’d)

Semantics: Prefer models with true-part as small as possible.

Definition

A model I of P is minimal, if there exists no model J of P such that J ⊂ I.

Theorem

Every logic program P has a single minimal model (called the leastmodel), denoted LM(P).

Example

For P1 = { a← b. b← c. c }, we have LM(P1) = {a, b, c}.For P2 = { a← b. b← a. c }, we have LM(P2) = {c}.

Minh Dao-Tran DERI, July 2011 62/33

Page 129: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.5 Minimality

Minimal Model Semantics (cont’d)

Semantics: Prefer models with true-part as small as possible.

Definition

A model I of P is minimal, if there exists no model J of P such that J ⊂ I.

Theorem

Every logic program P has a single minimal model (called the leastmodel), denoted LM(P).

Example

For P1 = { a← b. b← c. c }, we have LM(P1) = {a, b, c}.For P2 = { a← b. b← a. c }, we have LM(P2) = {c}.

Minh Dao-Tran DERI, July 2011 62/33

Page 130: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.5 Minimality

Minimal Model Semantics (cont’d)

Semantics: Prefer models with true-part as small as possible.

Definition

A model I of P is minimal, if there exists no model J of P such that J ⊂ I.

Theorem

Every logic program P has a single minimal model (called the leastmodel), denoted LM(P).

Example

For P1 = { a← b. b← c. c }, we have LM(P1) = {a, b, c}.For P2 = { a← b. b← a. c }, we have LM(P2) = {c}.

Minh Dao-Tran DERI, July 2011 62/33

Page 131: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.6 TP operator

Computation

The minimal model can be computed via fixpoint iteration.

Definition (TP Operator)

Let TP : 2HB(P) → 2HB(P) be defined as

TP(I) ={

a∣∣∣∣ there exists some a← b1, . . . , bm

in grnd(P) such that {b1, . . . , bm} ⊆ I

}.

We let denote T0P = ∅, T i+1

P = TP(T iP), i ≥ 0.

Fundamental result:

Theorem

TP has a least fixpoint, lfp(TP), and the sequence 〈T iP〉, i ≥ 0,

converges to lfp(TP).

Minh Dao-Tran DERI, July 2011 63/33

Page 132: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.6 TP operator

Computation

The minimal model can be computed via fixpoint iteration.

Definition (TP Operator)

Let TP : 2HB(P) → 2HB(P) be defined as

TP(I) ={

a∣∣∣∣ there exists some a← b1, . . . , bm

in grnd(P) such that {b1, . . . , bm} ⊆ I

}.

We let denote T0P = ∅, T i+1

P = TP(T iP), i ≥ 0.

Fundamental result:

Theorem

TP has a least fixpoint, lfp(TP), and the sequence 〈T iP〉, i ≥ 0,

converges to lfp(TP).

Minh Dao-Tran DERI, July 2011 63/33

Page 133: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.7 Answer Set Programming Systems for Debian/Ubuntu

Answer Set Programming Systems for Debian/Ubuntu

Minh Dao-Tran DERI, July 2011 64/33

Page 134: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.7 Answer Set Programming Systems for Debian/Ubuntu

Answer Set Programming Systems for Debian/Ubuntu

Minh Dao-Tran DERI, July 2011 65/33

Page 135: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.7 Answer Set Programming Systems for Debian/Ubuntu

Answer Set Programming Systems for Debian/Ubuntu

Minh Dao-Tran DERI, July 2011 66/33

Page 136: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.7 Answer Set Programming Systems for Debian/Ubuntu

Answer Set Programming Systems for Debian/Ubuntu

Minh Dao-Tran DERI, July 2011 67/33

Page 137: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.7 Answer Set Programming Systems for Debian/Ubuntu

Answer Set Programming Systems for Debian/Ubuntu

Minh Dao-Tran DERI, July 2011 68/33

Page 138: Exchanging More than Complete Data

An Answer Set Programming Tutorial 8. References 8.7 Answer Set Programming Systems for Debian/Ubuntu

Answer Set Programming Systems for Debian/Ubuntu

Minh Dao-Tran DERI, July 2011 69/33