Negation in logic programming Ex .: Old example program P f on family - - PowerPoint PPT Presentation

negation in logic programming
SMART_READER_LITE
LIVE PREVIEW

Negation in logic programming Ex .: Old example program P f on family - - PowerPoint PPT Presentation

Definite programs General programs Definite programs General programs NAF, CWA comp ( P ) Programs do not have any negative consequences. But sometimes we need them. Negation in logic programming Ex .: Old example program P f on family


slide-1
SLIDE 1

Definite programs General programs

Negation in logic programming Summary

TDDD08 tutorial Włodzimierz Drabent

For TDDD08 Link¨

  • ping University (Sweden)

Version 0.6 compiled on October 5, 2020

1 / 18 Definite programs General programs

Outline

◮ Negation and definite logic programs

◮ NAF, CWA ◮ Program completion

◮ General logic programs

◮ SLDNF-resolution (generalizing NAF) ◮ Generalizing CWA ◮ Stratified programs & standard models ◮ Stable model semantics 2 / 18 Definite programs General programs NAF, CWA comp(P )

Programs do not have any negative consequences. But sometimes we need them. Ex.: Old example program Pf on family relations. We would like to derive ¬child(a, b) when Pf | = child(a, b). Two approaches

  • 1. CWA (closed world assumption)

P ⊢CWA ¬A whenever P | = A

i.e. MP | = ¬A (A – ground atom)

  • 2. NAF (negation as finite failure)

(A – atom)

P ⊢NAF ¬A whenever P | = A and an SLD-tree for A is finite

(finitely failed tree)

3 / 18 Definite programs General programs NAF, CWA comp(P )

Difference CWA, NAF

Ex.: P = { p ← p } P ⊢CWA ¬p P ⊢NAF ¬p

4 / 18

slide-2
SLIDE 2

Definite programs General programs NAF, CWA comp(P )

CWA, NAF – declarative semantics

CWA characterized by the least Herbrand model MP NAF characterized by the completion of the program, comp(P)

5 / 18 Definite programs General programs NAF, CWA comp(P )

Program completion

NAF characterized by the completion of the program, comp(P) Main idea (roughly): comp(P) is P with ← converted into ↔.

so that comp(P) also says that A is false when not implied by the program Ex.: p(a) ← q(X) p(f(Y )) ← r(Y )

  • p(V ) ↔ V = a, ∃X. q(X) ∨

∃Y. (V = f(Y ), r(Y ))

6 / 18 Definite programs General programs NAF, CWA comp(P )

Program completion, roughly

p( t1) ← B1 · · · p( tn) ← Bn equivalent1 to

  • ne axiom

p(V1, . . . , Vk) ← β Then the completion contains p(V1, . . . , Vk) ↔ β

(for each predicate p in the program) As = occurs in β, the completion includes axioms for equality, called CET CET assures that distinct ground terms are not equal

1in a certain sense

7 / 18 Definite programs General programs NAF, CWA comp(P )

comp(P) works as expected

comp(P) describes NAF and the standard positive answers: Th.: (Soundness and completeness) For any definite program and query P, Q P ⊢NAF ¬Q iff comp(P) | = ¬Q P | = Q iff comp(P) | = Q iff Q is a computed answer of P

8 / 18

slide-3
SLIDE 3

Definite programs General programs SLDNF Generalizing CWA Stratified SMS

General logic programs

We would like to have negation in queries and programs.

E.g. A query grandchild(X , adam), ¬descendant(X , bill) General programs – also negated atoms (negative literals) allowed in clause bodies NAF SLDNF-resolution, natural generalization of SLD-resolution CWA . . .

9 / 18 Definite programs General programs SLDNF Generalizing CWA Stratified SMS

SLDNF-resolution

Like SLD-resolution: derivations, answers, SLDNF-trees When ¬A selected in a query Q, build an SLDNF-tree for A. 3 cases: A finitely fails

(A false, ¬A true)

Q | Q with ¬A removed answer A obtained2

(A true, ¬A false)

Q

  • no children,

“failed leaf”

  • therwise

(A – ? )

Q ×

  • no children,

floundering

  • A finitely fails = SLDNF-tree finite, no answers, no floundering

2 most general answer

10 / 18 Definite programs General programs SLDNF Generalizing CWA Stratified SMS

Declarative/logic characterization of SLDNF-resolution

SLDNF-resolution is sound w.r.t. comp(P): Th.: P, Q - general program and query Q is an SLDNF-computed answer for P ⇒ comp(P) | = Q A finitely failed tree for Q ⇒ comp(P) | = ¬Q But comp(P) does not describe SLDNF-resolution well It implies too much ··

☞ A “right” semantics: comp(P) in a certain 3-valued logic Equivalently, a modified completion (in standard logic, cf. old slides) For such semantics, SLDNF-resolution sound, and complete for non-floundering queries.

11 / 18 Definite programs General programs SLDNF Generalizing CWA Stratified SMS

Generalizing CWA

WFS (well-founded semantics)

general programs

CWA

definite programs

− → standard model

stratified programs

stable model semantics

general programs

ASP (answer set programming)

disjunctive programs (with rules H1 ∨ · · · ∨ Hm ← B1, . . . , Bn)

         NAF

definite programs

3v completion sem.,

(SLDNF-resolution) general programs

        

12 / 18

slide-4
SLIDE 4

Definite programs General programs SLDNF Generalizing CWA Stratified SMS

Stratified programs

Main feature - no recursion through negation. Program divided into strata. Each predicate defined in a single stratum. A predicate in a positive body literal – defined in the same or an earlier stratum A predicate in a negative body literal – defined in an earlier stratum

13 / 18 Definite programs General programs SLDNF Generalizing CWA Stratified SMS

Example, stratified program

P3 =

  • go well together(X, Y ) ← ¬ incompatible(X, Y ).

P2 = incompatible(X, Y ) ← ¬ likes(X, Y ). incompatible(X, Y ) ← ¬ likes(Y, X). P1 =        likes(X, Y ) ← harmless(Y ). likes(X, Y ) ← eats(X, Y ). harmless(rabbit). eats(python, rabbit).

14 / 18 Definite programs General programs SLDNF Generalizing CWA Stratified SMS

Generalizing CWA for stratified programs

The standard model of P constructed strata-wise Strata: P1, . . . , Pn A sequence of minimal Herbrand models: Mi – the standard model of P1 ∪ · · · ∪ Pi Mi \ Mi−1 contains only predicate symbols defined in Pi

Constructed similarly to least Herbrand model, Mi = ∞

j=1(TPi)j(Mi−1)

Details, example – [Nilsson,Małuszyński] Ch.4.4 Another approach, example – sli.10c.neg.∗

15 / 18 Definite programs General programs SLDNF Generalizing CWA Stratified SMS

Stable model semantics (SMS)

Main idea: Guess an Herbrand interpretation I. Use I to evaluate negative literals of P P I. P I – definite program, called the reduct of P w.r.t. I. If the the least Herbrand model of P I is I MP I = { A ∈ B

A | P I |

= A } = I then I is a stable model of P. Details:

P I is ground(P) without

◮ each rule with some ¬A, s.t. I |

= A

◮ each ¬A, s.t. I |

= ¬A

16 / 18

slide-5
SLIDE 5

Definite programs General programs SLDNF Generalizing CWA Stratified SMS

Stable model semantics (SMS)

Stratified program: unique stable model = standard model

17 / 18 Definite programs General programs SLDNF Generalizing CWA Stratified SMS

Stable model semantics (SMS)

Different pragmatics than the rest of Logic Programming: LP: problem solutions – program answers SMS: problem solutions – stable models of programs SMS usable only if the universe finite

no function symbols, no data structures

18 / 18