13
Answer Set Programming (ASP) Putting into Practice (PiP) 2021 Jef Wijsen UMONS March 5, 2021 Jef Wijsen (UMONS) ASP March 5, 2021 1/9

Answer Set Programming (ASP) - moodle.umons.ac.be

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Answer Set Programming (ASP) - moodle.umons.ac.be

Answer Set Programming (ASP)Putting into Practice (PiP)

2021

Jef Wijsen

UMONS

March 5, 2021

Jef Wijsen (UMONS) ASP March 5, 2021 1 / 9

Page 2: Answer Set Programming (ASP) - moodle.umons.ac.be

Table of Contents

1 PiP 1

Jef Wijsen (UMONS) ASP March 5, 2021 2 / 9

Page 3: Answer Set Programming (ASP) - moodle.umons.ac.be

First Solution for PiP 1

Let P be as follows.

var(P) :- r(I,P,V).

clause(I) :- r(I,P,V).

% Every variable is either true or false.

true(P) :- var(P), not false(P). %(1)

false(P) :- var(P), not true(P). %(2)

% Compute the satisfied clauses.

satisfied(I) :- r(I,P,0), false(P). %(3)

satisfied(I) :- r(I,P,1), true(P). %(4)

% No clause must be unsatisfied.

:- clause(I), not satisfied(I). %(5)

Jef Wijsen (UMONS) ASP March 5, 2021 3 / 9

Page 4: Answer Set Programming (ASP) - moodle.umons.ac.be

Claim 1For every formula ', if enc(') [ P0 has a stable model, then ' is satisfiable.

Proof.Let P := enc(') [ P0. Let M be a stable model of P. Thus, from here on, our proofcan use that M is the minimal model of the reduct PM .

1. Show that M includes a truth assignment. That is, show that for every propositionalvariable p, (i) the model M contains either true(p) or false(p),(ii) but does not contain both true(p) and false(p).

Proof of (ii). Assume for the sake of contradiction that M contains both true(p) andfalse(p) for some propositional variable p in '. Then, it can be easily seen that no rulehead in PM equals true(p) or false(p), and therefore M is not supported,contradicting that stable models are supported. We conclude by contradiction that Mcontains at most one of true(p) or false(p).Proof of (i). By (ii), one of true(p) or false(p) is not in M. Since M satisfies thegroundings of rules (1) and (2), M must contain either true(p) or false(p).

Jef Wijsen (UMONS) ASP March 5, 2021 4 / 9

Page 5: Answer Set Programming (ASP) - moodle.umons.ac.be

Hypothesis :

My tweeps , false Cpl. . . . }

9

ground ( p) contains :tweeps ← varCp) , 7 false Lp) .

false Cp) ← var Cpl , 7 true Cp) .

but when we compute the redroot pm :

tweeps ← varCp) , 7 false Lp) .

false Cp) ← var Cpl , a true Cp) .Both ground rules are removed ,

and hence neither true Cpr )nd false Cp ) is supported .

Inot stable

Page 6: Answer Set Programming (ASP) - moodle.umons.ac.be

Assume tweeps f M( the case false Cpl EfM

is symmetrical )

ground Cp ) contains :

false Cp ) ← var (p ) , 7 true Cpr) .

When we compute the ieduct PM :

false Cpl ← var (p ) , 7 true Cpr) .Since M is a model of PM,

falseCp ) E M .

Page 7: Answer Set Programming (ASP) - moodle.umons.ac.be

Proof (Cont.)

2. Show that M makes ' true. Formally, it remains to be shown that for every ibetween 1 and the number of clauses, there is a propositional variable psuch that one of the following holds true:

1 enc(') contains r(i , p, 1) and M contains true(p); or

2 enc(') contains r(i , p, 0) and M contains false(p).

To this end, let i be an integer between 1 and the number of clauses. By (5), M mustcontain satisfied(i), which must be supported. Since satisfied(i) can only besupported by groundings of rules (3) or (4), it must be the case that for some p, one ofthe preceding bullets (1) or (2) holds true. This conclude the proof.

Jef Wijsen (UMONS) ASP March 5, 2021 5 / 9

Page 8: Answer Set Programming (ASP) - moodle.umons.ac.be

ground Cp ) contains :

satisfied Ci ) ← re (i. p , o ) , false Cpl . (39satisfiedCi) ← recipe , 11 , true Cpl . Cy)← clause (is , not satisfiedCil . cry

since M is a model , it satisfiesconstraint ( 54 , hence

satisfied Ci) E M .

Since M is stable , it must

support satisfiedCi ) . Such supportmust come from (3

' ) or (y') .

I

Page 9: Answer Set Programming (ASP) - moodle.umons.ac.be

Claim 2For every formula ', if ' is satisfiable, then P := enc(') [ P0 has a stable model.

Proof.Let ' be an arbitrary formula. Let T be a satisfying truth assignment for ', i.e.,

1 for every propositional variable p, we have that T contains either true(p) orfalse(p), but does not contain both; and

2 for every i between 1 and the number of clauses, there exists p such that:

enc(') contains r(i , p, 1) and T contains true(p); orenc(') contains r(i , p, 0) and T contains false(p).

Let M be an interpretation that includes T . Moreover, M contains all r-facts, allvar-facts, and all clause-facts. More importantly, M contains all satisfied-facts.For every p, if M contains false(p), then PM contains false(p):-var(p); and if Mcontains true(p), then PM contains true(p):-var(p). Moreover, PM contains allgroundings of rules (3) and (4). Since M contains all satisfied-facts, PM contains nogrounding of (5).It is obvious that M is a model of PM . Importantly, M is a minimal model: in particular,for every i , the smaller interpretation M \ {satisfied(i)} will falsify some groundingof rules (3) or (4), and is therefore not a model of PM .

Jef Wijsen (UMONS) ASP March 5, 2021 6 / 9

Page 10: Answer Set Programming (ASP) - moodle.umons.ac.be

and tweeps of M .

Page 11: Answer Set Programming (ASP) - moodle.umons.ac.be

Discussion

For p ^ (p _ q), the database is

r(1,p,1). r(2,p,1). r(2,q,1).

and the output is

Solving...

Answer: 1

true(p) true(q)

Answer: 2

true(p) false(q)

SATISFIABLE

Wouldn’t it be nicer to have a single model {true(p)}?

Jef Wijsen (UMONS) ASP March 5, 2021 7 / 9

Page 12: Answer Set Programming (ASP) - moodle.umons.ac.be

Second Solution for PiP1

% p AND (p OR q)

r(1,p,1). r(2,p,1). r(2,q,1).

clause(I) :- r(I,P,V).

1 { let(P,V) : r(I,P,V) } :- clause(I).

:- let(P,0), let(P,1).

% false(P) :- let(P,0).

% true(P) :- let(P,1).

#show let/2.

Solving...

Answer: 1

let(p,1)

Answer: 2

let(p,1) let(q,1)

SATISFIABLE

How come the second answer is not minimal?

Jef Wijsen (UMONS) ASP March 5, 2021 8 / 9

r ( 2.p, o)r ( 2. 9,2)r ( 2, r,I)

>pvgvr

Page 13: Answer Set Programming (ASP) - moodle.umons.ac.be

Second Solution for PiP1 (without cardinality rules)

% p AND (p OR q)

r(1,p,1). r(2,p,1). r(2,q,1).

% Select at least one literal from each clause

% without ever selecting both p and not p.

clause(I) :- r(I,P,V).

reject(I,P,V) :- r(I,P,V), not select(I,P,V).

select(I,P,V) :- r(I,P,V), not reject(I,P,V).

satisfied(I) :- clause(I), select(I,P,V).

:- clause(I), not satisfied(I).

:- select(I,P,0), select(J,P,1).

% false(P) :- select(I,P,0).

% true(P) :- select(I,P,1).

#show reject/3.

#show select/3.

Jef Wijsen (UMONS) ASP March 5, 2021 9 / 9