Answer Set Programming Cleyton Rodrigues, M. Sc.
So Far… Monotonic Logic Programming
Monotonic Logic “[…] Learning a new piece of knowledge cannot reduce the set of what is known.” A logic is monotonic if every thing that is entailed by a KB (Knowledge Base) is entailed by a superset of the KB: KB╞ a KB b╞ a
The “Problem”! A Monotonic Logic cannot handle various reasoning tasks; Default Reasoning Typical birds can fly. x bird(X) flies(X). sparrow? bird(sparrow). flies(sparrow). DR: (consequences may be derived only because of lack of evidence of the contrary
The “Problem”! A Monotonic Logic cannot handle various reasoning tasks; Default Reasoning Typical birds can fly. x bird(X) flies(X). sparrow? bird(sparrow). flies(sparrow). peguin? bird(peguin), flies(peguin). (taken by the rule). flies (peguin). Unsatisfiable! The default assumption must be retracted.
NAF – Negation as Failure Negation-As-Failure enables defaults flies(X) :- bird(X), not penguin(X). bird(tweety). bird(opus). penguin(opus). tweety flies because he isn’t declared a penguin if we also asserted penguin(tweety)... Non-Monotonic Reasoning! Closed-world assumption (CWA) everything that is true is asserted; everything unsaid is assumed to be false Minimal Models – only believe what you have to smallest set of tuples that satisfies KB
Answer Set Programming
Answer Set Programming (ASP) Declarative Programming; Search problems reduced to compute stable models; Non Monotonic Reasoning; “Unlike SLDNF resolution employed in Prolog, such algorithms, in principle, always terminate.”
ASP General Idea Problem Instance I P is a nonmonotonic logic program. Solver Encoding: Program P P is a nonmonotonic logic program. Model (s) Solution (s)
Stable Models Model: Set of Atoms that satisfies every rule in the program. “Informally, a model is stable if every atom in its has a reason to be there: for each atom in the model there has to be some rule that has the atom as a head such that the rule body is true in the model”. Example (Prolog-style Program): PC Configuration System ide_drive :- hard_drive, not scsi_drive. scsi_drive :- hard_drive, not ide_drive. scsi_controller:- scsi_drive. hard_drive.
Stable Models? ide_drive :- hard_drive, not scsi_drive. scsi_drive :- hard_drive, not ide_drive. scsi_controller: scsi_drive. hard_drive.
Stable Models? M1={hard_drive, ide_drive}. ide_drive :- hard_drive, not scsi_drive. scsi_drive :- hard_drive, not ide_drive. scsi_controller: scsi_drive. hard_drive.
Stable Models? M1={hard_drive, ide_drive}. M2={hard_drive, scsi_drive, scsi_controller}. ide_drive :- hard_drive, not scsi_drive. scsi_drive :- hard_drive, not ide_drive. scsi_controller: scsi_drive. hard_drive.
How to Find the Stable Model?
Without negative literals Unique minimal Model. a. b. c :- a. d :- c,b. e :- f. Knaster-Tarski operator TP, where: Tp(M) = {h | h l1, ..., ln is a rule in the program and l1, ..., ln M}.
Without negative literals Unique minimal Model. a. b. c :- a. d :- c,b. e :- f. Knaster-Tarski operator TP, where: Tp(M) = {h | h l1, ..., ln is a rule in the program and l1, ..., ln M}. SM = {a, b, c, d}.
With Negative Literals. Let SM be a (potentially) stable Model for a Program P. Removing negations from P PSM: Each rule that has a negative literal “not a” in its body when a belongs to M; and All negative literals in the bodies of remaining rules. If SM is a stable model por PSM então SM is a stable model for the program P.
Find the Stable Models... a :- not b. b :- not a.
Formalizing ASP Programs
ASP Programs (Prolog Style Rules) A Program P consists of a set of rules: General Rule <head> :- <body>. Fact <head>.
ASP Programs Example1: A P prolog-style Program consists of the following rules: p :- q. q :- not r. Stable Model SM
ASP Programs Example1: A P prolog-style Program consists of the following rules: p :- q. q :- not r. Stable Model SM SM = {p, q}.
ASP Programs (Extending Prolog) P is a (potentially disjunctive) finite set of rules of the form: a1 ... ak b1, ...,bm, not c1,...,not cn. All ax, bi, cj are FOL literals; Arbitrarily Choice {p,q,r} :- t. “If ‘t’ is included in the stable model then chose arbitrarily which of the atoms to include.” None Just One A subset of the individuals;
ASP Programs Example2: A P ASP Program consists of the following rules: p :- q. q :- not r. {s,t}:- p. Stable Model SM
ASP Programs Example2: A P ASP Program consists of the following rules: p :- q. q :- not r. {s,t}:- p. Stable Model SM SM1:{p, q}. SM2:{p, q, s}. SM3:{p, q, t}. SM4:{p, q, t , s}.
ASP Program Arbritrarily Choice Variation Numerical Bounds N {s,t} :- p. N: integer The bound means how many indivuals, at least, must be elected by Stable Models.
ASP Program Example 3: A P ASP Program consists of the following rules: p :- q. q :- not r. 1 {s,t} :- p Stable Models SM1: p q s SM2: p q t SM3: p q t s SM4: p q (error: not allowed due the numerical restriction)
ASP Program Constraint Rule (No Head) :- s, not t. “Prohibits generating ‘s’ if ‘t’ is not generated.”
ASP Program Example 2: A P prolog Program consists of the following rules: p :- q. q :- not r. 1 {s,t} :- p :- s, not t. Stable Models SM1: p q s (error: not allowed due the constraint Rule) SM2: p q t SM3: p q t s
Non-Ground Programs
Non-ground Programs Example: d(a). d(b). foo(X) :- not bar(X). bar(X) :- not foo(X). The set of stable Models for a non-ground logic program is defined to be the set of stable models o the Herbrand Instation of the Program.
Herbrand Instatiation Herbrand Universe (HU): set of all ground terms using fuctions symbols and constants. HU = {a,b}; Herbrand Base (HB): set of ground atoms that can be constructed using the predicates in the program and the HU. HB = {foo(a), foo(b), bar(a), bar(b)}; Herbrand Instantiation (HI): set of ground instances of the rule using HB;
Herbrand Instantiation Example: d(a). d(b). foo(X) :- not bar(X). bar(X) :- not foo(X). Herbrand Instantiantion: foo(a) :- not bar(a). bar(a) :- not foo(a). foo(b) :- not bar(b). bar(b) :- not foo(b).
Herbrand Instation SM? Herbrand Instantiantion: d(a). d(b). foo(a) :- not bar(a). bar(a) :- not foo(a). foo(b) :- not bar(b). bar(b) :- not foo(b).
Herbrand Instantiation Usually, most of the rules in the herbrand Instantiation have unsatisfiable bodies and they may be discarded without affecting the set of stable models. Example: d(a). e(b). e(c). foo(X) :- d(X), not bar(X). bar(X) :- d(X), not foo(X).
Example d(a). e(b). e(c). foo(a) :- d(a), not bar(a). bar(a) :- d(a), not foo(a). foo(b) :- d(b), not bar(b). bar(b) :- d(b), not foo(b). foo(c) :- d(c), not bar(c). bar(c) :- d(c), not foo(c).
Example d(a). e(b). e(c). foo(a) :- d(a), not bar(a). bar(a) :- d(a), not foo(a). foo(b) :- d(b), not bar(b). bar(b) :- d(b), not foo(b). foo(c) :- d(c), not bar(c). bar(c) :- d(c), not foo(c).
How we know which rules can be droped out? Example How we know which rules can be droped out? d(a). e(b). e(c). foo(a) :- d(a), not bar(a). bar(a) :- d(a), not foo(a). foo(b) :- d(b), not bar(b). bar(b) :- d(b), not foo(b). foo(c) :- d(c), not bar(c). bar(c) :- d(c), not foo(c).
Lparse/ SModels
Lparse/ SModels
Exercise p :- not q. q :- not p. r :- p. r :- q. p :- not q. Program 1 Program 2 p :- not q. q :- not p. r :- p. r :- q. p :- not q. q :- not p. r :- not r. r :- p.
Exercise Program 3 Program 4 person(joey). 1{male(X), female(X)} :- person(X). bachleor(X):- male(X), not married(X). :- male(X), female(X).