Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1...

84
Answer Set Programming: Basics Sebastian Rudolph Computational Logic Group Technische Universit¨ at Dresden Slides based on a lecture by Martin Gebser and Torsten Schaub. Potassco Slide Packages are licensed under a Creative Commons Attribution 3.0 Unported License. Sebastian Rudolph (TUD) Answer Set Programming: Basics 1 / 32

Transcript of Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1...

Page 1: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Answer Set Programming: Basics

Sebastian Rudolph

Computational Logic GroupTechnische Universitat Dresden

Slides based on a lecture by Martin Gebser and Torsten Schaub.

Potassco Slide Packages are licensed under a Creative Commons Attribution 3.0

Unported License.

Sebastian Rudolph (TUD) Answer Set Programming: Basics 1 / 32

Page 2: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Answer Set Programming – Basics:Overview

1 Motivation: ASP vs. Prolog and SAT

2 ASP Syntax

3 Semantics

4 Examples

5 Variables

6 Reasoning modes

Sebastian Rudolph (TUD) Answer Set Programming: Basics 2 / 32

Page 3: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

Outline

1 Motivation: ASP vs. Prolog and SAT

2 ASP Syntax

3 Semantics

4 Examples

5 Variables

6 Reasoning modes

Sebastian Rudolph (TUD) Answer Set Programming: Basics 3 / 32

Page 4: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

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

Sebastian Rudolph (TUD) Answer Set Programming: Basics 4 / 32

Page 5: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

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

Sebastian Rudolph (TUD) Answer Set Programming: Basics 4 / 32

Page 6: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

LP-style playing with blocks

Prolog program

on(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.

Sebastian Rudolph (TUD) Answer Set Programming: Basics 5 / 32

Page 7: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

LP-style playing with blocks

Prolog program

on(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.

Sebastian Rudolph (TUD) Answer Set Programming: Basics 5 / 32

Page 8: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

LP-style playing with blocks

Prolog program

on(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.

Sebastian Rudolph (TUD) Answer Set Programming: Basics 5 / 32

Page 9: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

LP-style playing with blocks

Prolog program

on(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.

Sebastian Rudolph (TUD) Answer Set Programming: Basics 5 / 32

Page 10: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

LP-style playing with blocks

Shuffled Prolog program

on(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.

Sebastian Rudolph (TUD) Answer Set Programming: Basics 6 / 32

Page 11: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

LP-style playing with blocks

Shuffled Prolog program

on(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.

Sebastian Rudolph (TUD) Answer Set Programming: Basics 6 / 32

Page 12: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

LP-style playing with blocks

Shuffled Prolog program

on(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.

Sebastian Rudolph (TUD) Answer Set Programming: Basics 6 / 32

Page 13: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

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

Sebastian Rudolph (TUD) Answer Set Programming: Basics 7 / 32

Page 14: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

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

Sebastian Rudolph (TUD) Answer Set Programming: Basics 7 / 32

Page 15: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

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)

}

Sebastian Rudolph (TUD) Answer Set Programming: Basics 8 / 32

Page 16: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

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)

}

Sebastian Rudolph (TUD) Answer Set Programming: Basics 8 / 32

Page 17: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

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)

}

Sebastian Rudolph (TUD) Answer Set Programming: Basics 8 / 32

Page 18: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

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)

}

Sebastian Rudolph (TUD) Answer Set Programming: Basics 8 / 32

Page 19: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

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)

}

Sebastian Rudolph (TUD) Answer Set Programming: Basics 8 / 32

Page 20: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

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

Sebastian Rudolph (TUD) Answer Set Programming: Basics 9 / 32

Page 21: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

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)

Sebastian Rudolph (TUD) Answer Set Programming: Basics 9 / 32

Page 22: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

ASP-style playing with blocks

Logic program

on(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) }

Sebastian Rudolph (TUD) Answer Set Programming: Basics 10 / 32

Page 23: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

ASP-style playing with blocks

Logic program

on(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) }

Sebastian Rudolph (TUD) Answer Set Programming: Basics 10 / 32

Page 24: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

ASP-style playing with blocks

Logic program

on(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) }

Sebastian Rudolph (TUD) Answer Set Programming: Basics 10 / 32

Page 25: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

ASP-style playing with blocks

Logic program

on(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) }

Sebastian Rudolph (TUD) Answer Set Programming: Basics 10 / 32

Page 26: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

ASP versus LP

ASP Prolog

Model generation Query orientation

Bottom-up Top-down

Modeling language Programming language

Rule-based format

Instantiation UnificationFlat terms Nested terms

(Turing +) NP(NP) Turing

Sebastian Rudolph (TUD) Answer Set Programming: Basics 11 / 32

Page 27: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

ASP versus SAT

ASP SAT

Model generation

Bottom-up

Constructive Logic Classical Logic

Closed (and open) Open world reasoningworld reasoning

Modeling language —

Complex reasoning modes Satisfiability testing

Satisfiability SatisfiabilityEnumeration/Projection —Intersection/Union —Optimization —

(Turing +) NP(NP) NP

Sebastian Rudolph (TUD) Answer Set Programming: Basics 12 / 32

Page 28: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

What is ASP good for?

Combinatorial search problems in the realm of P, NP, and NPNP

(some with substantial amount of data), like

Automated PlanningCode OptimizationComposition of Renaissance MusicDatabase IntegrationDecision Support for NASA shuttle controllersModel CheckingProduct ConfigurationRoboticsSystems BiologySystem Synthesis(industrial) Team-buildingand many many more

Sebastian Rudolph (TUD) Answer Set Programming: Basics 13 / 32

Page 29: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Motivation: ASP vs. Prolog and SAT

What is ASP good for?

Combinatorial search problems in the realm of P, NP, and NPNP

(some with substantial amount of data), like

Automated PlanningCode OptimizationComposition of Renaissance MusicDatabase IntegrationDecision Support for NASA shuttle controllersModel CheckingProduct ConfigurationRoboticsSystems BiologySystem Synthesis(industrial) Team-buildingand many many more

Sebastian Rudolph (TUD) Answer Set Programming: Basics 13 / 32

Page 30: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

ASP Syntax

Outline

1 Motivation: ASP vs. Prolog and SAT

2 ASP Syntax

3 Semantics

4 Examples

5 Variables

6 Reasoning modes

Sebastian Rudolph (TUD) Answer Set Programming: Basics 14 / 32

Page 31: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

ASP Syntax

Normal logic programs

A logic program, P, over a set A of atoms is a finite set of rules

A (normal) rule, r , is of the form

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

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

Notation

head(r) = a0

body(r) = {a1, . . . , am,∼am+1, . . . ,∼an}body(r)+ = {a1, . . . , am}body(r)− = {am+1, . . . , an}atom(P) =

⋃r∈P

({head(r)} ∪ body(r)+ ∪ body(r)−

)body(P) = {body(r) | r ∈ P}

A program P is positive if body(r)− = ∅ for all r ∈ P

Sebastian Rudolph (TUD) Answer Set Programming: Basics 15 / 32

Page 32: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

ASP Syntax

Normal logic programs

A logic program, P, over a set A of atoms is a finite set of rules

A (normal) rule, r , is of the form

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

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

Notation

head(r) = a0

body(r) = {a1, . . . , am,∼am+1, . . . ,∼an}body(r)+ = {a1, . . . , am}body(r)− = {am+1, . . . , an}atom(P) =

⋃r∈P

({head(r)} ∪ body(r)+ ∪ body(r)−

)body(P) = {body(r) | r ∈ P}

A program P is positive if body(r)− = ∅ for all r ∈ P

Sebastian Rudolph (TUD) Answer Set Programming: Basics 15 / 32

Page 33: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

ASP Syntax

Normal logic programs

A logic program, P, over a set A of atoms is a finite set of rules

A (normal) rule, r , is of the form

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

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

Notation

head(r) = a0

body(r) = {a1, . . . , am,∼am+1, . . . ,∼an}body(r)+ = {a1, . . . , am}body(r)− = {am+1, . . . , an}atom(P) =

⋃r∈P

({head(r)} ∪ body(r)+ ∪ body(r)−

)body(P) = {body(r) | r ∈ P}

A program P is positive if body(r)− = ∅ for all r ∈ P

Sebastian Rudolph (TUD) Answer Set Programming: Basics 15 / 32

Page 34: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

ASP Syntax

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 ← , ; ∼ ¬formula >,⊥ → ∧ ∨ ↔ ∼ ¬

Sebastian Rudolph (TUD) Answer Set Programming: Basics 16 / 32

Page 35: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

Outline

1 Motivation: ASP vs. Prolog and SAT

2 ASP Syntax

3 Semantics

4 Examples

5 Variables

6 Reasoning modes

Sebastian Rudolph (TUD) Answer Set Programming: Basics 17 / 32

Page 36: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

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 Pis denoted 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

Sebastian Rudolph (TUD) Answer Set Programming: Basics 18 / 32

Page 37: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

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 Pis denoted 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

Sebastian Rudolph (TUD) Answer Set Programming: Basics 18 / 32

Page 38: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

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 Pis denoted 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

Sebastian Rudolph (TUD) Answer Set Programming: Basics 18 / 32

Page 39: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

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 Pis denoted 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

Sebastian Rudolph (TUD) Answer Set Programming: Basics 18 / 32

Page 40: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

Basic idea

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

HHHH

HHHjp 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, ∼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) and G3 (Godel, 1932))

Sebastian Rudolph (TUD) Answer Set Programming: Basics 19 / 32

Page 41: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

Basic idea

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

HHHH

HHHjp 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, ∼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) and G3 (Godel, 1932))

Sebastian Rudolph (TUD) Answer Set Programming: Basics 19 / 32

Page 42: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

Basic idea

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

HHHH

HHHjp 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, ∼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) and G3 (Godel, 1932))

Sebastian Rudolph (TUD) Answer Set Programming: Basics 19 / 32

Page 43: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

Basic idea

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

HHHH

HHHjp 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, ∼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) and G3 (Godel, 1932))

Sebastian Rudolph (TUD) Answer Set Programming: Basics 19 / 32

Page 44: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

Basic idea

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

HHHH

HHHjp 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, ∼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) and G3 (Godel, 1932))

Sebastian Rudolph (TUD) Answer Set Programming: Basics 19 / 32

Page 45: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

Basic idea

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

HHHH

HHHjp 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, ∼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) and G3 (Godel, 1932))

Sebastian Rudolph (TUD) Answer Set Programming: Basics 19 / 32

Page 46: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

Basic idea

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

HHHH

HHHjp 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, ∼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) and G3 (Godel, 1932))

Sebastian Rudolph (TUD) Answer Set Programming: Basics 19 / 32

Page 47: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

Basic idea

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

HHHH

HHHjp 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, ∼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) and G3 (Godel, 1932))

Sebastian Rudolph (TUD) Answer Set Programming: Basics 19 / 32

Page 48: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

Formal DefinitionStable model of normal programs

The reduct, PX , of a program P relative to a set X of atoms isdefined 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”

Sebastian Rudolph (TUD) Answer Set Programming: Basics 20 / 32

Page 49: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

Formal DefinitionStable model of normal programs

The reduct, PX , of a program P relative to a set X of atoms isdefined 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”

Sebastian Rudolph (TUD) Answer Set Programming: Basics 20 / 32

Page 50: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

Formal DefinitionStable model of normal programs

The reduct, PX , of a program P relative to a set X of atoms isdefined 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”

Sebastian Rudolph (TUD) Answer Set Programming: Basics 20 / 32

Page 51: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

A closer look at PX

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

PX is obtained from P by deleting

1 each rule having ∼a in its body with a ∈ Xand then

2 all negative atoms of the form ∼ain the bodies of the remaining rules

Note Only negative body literals are evaluated wrt X

Sebastian Rudolph (TUD) Answer Set Programming: Basics 21 / 32

Page 52: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Semantics

A closer look at PX

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

PX is obtained from P by deleting

1 each rule having ∼a in its body with a ∈ Xand then

2 all negative atoms of the form ∼ain the bodies of the remaining rules

Note Only negative body literals are evaluated wrt X

Sebastian Rudolph (TUD) Answer Set Programming: Basics 21 / 32

Page 53: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

Outline

1 Motivation: ASP vs. Prolog and SAT

2 ASP Syntax

3 Semantics

4 Examples

5 Variables

6 Reasoning modes

Sebastian Rudolph (TUD) Answer Set Programming: Basics 22 / 32

Page 54: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A first example

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

X PX Cn(PX )

{ } p ← pq ←

{q} 8

{p } p ← p ∅ 8

{ q} p ← pq ←

{q} 4

{p, q} p ← p ∅ 8

Sebastian Rudolph (TUD) Answer Set Programming: Basics 23 / 32

Page 55: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A first example

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

X PX Cn(PX )

{ } p ← pq ←

{q} 8

{p } p ← p ∅ 8

{ q} p ← pq ←

{q} 4

{p, q} p ← p ∅ 8

Sebastian Rudolph (TUD) Answer Set Programming: Basics 23 / 32

Page 56: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A first example

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

X PX Cn(PX )

{ } p ← pq ←

{q} 8

{p } p ← p ∅ 8

{ q} p ← pq ←

{q} 4

{p, q} p ← p ∅ 8

Sebastian Rudolph (TUD) Answer Set Programming: Basics 23 / 32

Page 57: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A first example

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

X PX Cn(PX )

{ } p ← pq ←

{q} 8

{p } p ← p ∅ 8

{ q} p ← pq ←

{q} 4

{p, q} p ← p ∅ 8

Sebastian Rudolph (TUD) Answer Set Programming: Basics 23 / 32

Page 58: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A first example

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

X PX Cn(PX )

{ } p ← pq ←

{q} 8

{p } p ← p ∅ 8

{ q} p ← pq ←

{q} 4

{p, q} p ← p ∅ 8

Sebastian Rudolph (TUD) Answer Set Programming: Basics 23 / 32

Page 59: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A first example

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

X PX Cn(PX )

{ } p ← pq ←

{q} 8

{p } p ← p ∅ 8

{ q} p ← pq ←

{q} 4

{p, q} p ← p ∅ 8

Sebastian Rudolph (TUD) Answer Set Programming: Basics 23 / 32

Page 60: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A first example

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

X PX Cn(PX )

{ } p ← pq ←

{q} 8

{p } p ← p ∅ 8

{ q} p ← pq ←

{q} 4

{p, q} p ← p ∅ 8

Sebastian Rudolph (TUD) Answer Set Programming: Basics 23 / 32

Page 61: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A second example

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

X PX Cn(PX )

{ } p ←q ←

{p, q} 8

{p } p ← {p} 4

{ q}q ←

{q} 4

{p, q} ∅

Sebastian Rudolph (TUD) Answer Set Programming: Basics 24 / 32

Page 62: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A second example

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

X PX Cn(PX )

{ } p ←q ←

{p, q} 8

{p } p ← {p} 4

{ q}q ←

{q} 4

{p, q} ∅

Sebastian Rudolph (TUD) Answer Set Programming: Basics 24 / 32

Page 63: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A second example

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

X PX Cn(PX )

{ } p ←q ←

{p, q} 8

{p } p ← {p} 4

{ q}q ←

{q} 4

{p, q} ∅

Sebastian Rudolph (TUD) Answer Set Programming: Basics 24 / 32

Page 64: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A second example

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

X PX Cn(PX )

{ } p ←q ←

{p, q} 8

{p } p ← {p} 4

{ q}q ←

{q} 4

{p, q} ∅

Sebastian Rudolph (TUD) Answer Set Programming: Basics 24 / 32

Page 65: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A second example

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

X PX Cn(PX )

{ } p ←q ←

{p, q} 8

{p } p ← {p} 4

{ q}q ←

{q} 4

{p, q} ∅

Sebastian Rudolph (TUD) Answer Set Programming: Basics 24 / 32

Page 66: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A second example

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

X PX Cn(PX )

{ } p ←q ←

{p, q} 8

{p } p ← {p} 4

{ q}q ←

{q} 4

{p, q} ∅ 8

Sebastian Rudolph (TUD) Answer Set Programming: Basics 24 / 32

Page 67: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A third example

P = {p ← ∼p}

X PX Cn(PX )

{ } p ← {p} 8

{p} ∅

Sebastian Rudolph (TUD) Answer Set Programming: Basics 25 / 32

Page 68: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A third example

P = {p ← ∼p}

X PX Cn(PX )

{ } p ← {p} 8

{p} ∅

Sebastian Rudolph (TUD) Answer Set Programming: Basics 25 / 32

Page 69: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A third example

P = {p ← ∼p}

X PX Cn(PX )

{ } p ← {p} 8

{p} ∅

Sebastian Rudolph (TUD) Answer Set Programming: Basics 25 / 32

Page 70: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

A third example

P = {p ← ∼p}

X PX Cn(PX )

{ } p ← {p} 8

{p} ∅ 8

Sebastian Rudolph (TUD) Answer Set Programming: Basics 25 / 32

Page 71: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

Some properties

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

If X is a 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

Sebastian Rudolph (TUD) Answer Set Programming: Basics 26 / 32

Page 72: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Examples

Some properties

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

If X is a 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

Sebastian Rudolph (TUD) Answer Set Programming: Basics 26 / 32

Page 73: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Variables

Outline

1 Motivation: ASP vs. Prolog and SAT

2 ASP Syntax

3 Semantics

4 Examples

5 Variables

6 Reasoning modes

Sebastian Rudolph (TUD) Answer Set Programming: Basics 27 / 32

Page 74: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Variables

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 and 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∈P ground(r)

Sebastian Rudolph (TUD) Answer Set Programming: Basics 28 / 32

Page 75: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Variables

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 and 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∈P ground(r)

Sebastian Rudolph (TUD) Answer Set Programming: Basics 28 / 32

Page 76: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Variables

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 and 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∈P ground(r)

Sebastian Rudolph (TUD) Answer Set Programming: Basics 28 / 32

Page 77: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Variables

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 and 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∈P ground(r)

Sebastian Rudolph (TUD) Answer Set Programming: Basics 28 / 32

Page 78: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Variables

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 instantiation

Sebastian Rudolph (TUD) Answer Set Programming: Basics 29 / 32

Page 79: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Variables

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 instantiation

Sebastian Rudolph (TUD) Answer Set Programming: Basics 29 / 32

Page 80: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Variables

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 instantiation

Sebastian Rudolph (TUD) Answer Set Programming: Basics 29 / 32

Page 81: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Variables

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

Sebastian Rudolph (TUD) Answer Set Programming: Basics 30 / 32

Page 82: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Variables

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

Sebastian Rudolph (TUD) Answer Set Programming: Basics 30 / 32

Page 83: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Reasoning modes

Outline

1 Motivation: ASP vs. Prolog and SAT

2 ASP Syntax

3 Semantics

4 Examples

5 Variables

6 Reasoning modes

Sebastian Rudolph (TUD) Answer Set Programming: Basics 31 / 32

Page 84: Answer Set Programming: Basics - TU Dresden · Answer Set Programming { Basics: Overview 1 Motivation: ASP vs. Prolog and SAT 2 ASP Syntax 3 Semantics 4 Examples 5 Variables 6 Reasoning

Reasoning modes

Reasoning Modes

Satisfiability

Enumeration†

Projection†

Intersection‡

Union‡

Optimization

and combinations of them

† without solution recording‡ without solution enumeration

Sebastian Rudolph (TUD) Answer Set Programming: Basics 32 / 32