/* The weak well-founded model for the following program*/ %r(1,2). %r(2,3). %r(3,4). %p(X,Y) :- r(X,Y), not q(Y). %q(X) :- r(Y,X), not p(X,Y). /* Domain definition predicates*/ xdom(1). xdom(2). xdom(3). xdom(4). ydom(1). ydom(2). ydom(3). ydom(4). /* EDB */ /* complete the r predicate r = */ /* 16 tuples */ rplus(1,2). rplus(2,3). rplus(3,4). /* IDB */ /* the IDB has two rules */ /* qcomplement for the first rule */ qcomplementplus(X) :- qminus(X). qcomplementminus(X) :- qplus(X). /* join this with r to get p */ pplus(X,Y) :- rplus(X,Y),qcomplementplus(Y). pminus(X,Y) :- xdom(X),ydom(Y),not(rplus(X,Y)). pminus(X,Y) :- xdom(X),qcomplementminus(Y). /* second rule defines q */ /* pcomplement rule*/ pcomplementplus(X,Y) :- pminus(X,Y). pcomplementminus(X,Y) :- pplus(X,Y). /* join this with r and project first column to get q */ /* the join is stored in predicate temp */ tempplus(Y,X) :- rplus(Y,X),pcomplementplus(X,Y). tempminus(Y,X) :- ydom(Y),xdom(X),not(rplus(Y,X)). tempminus(Y,X) :- pcomplementminus(X,Y). /* project second column from temp to get q */ qplus(X) :- tempplus(_,X). temp1(X,Y) :- xdom(X),ydom(Y). temp2(Y) :- temp1(X,Y),not(tempminus(X,Y)). qminus(X) :- xdom(X), not(temp2(X)). punknown(X,Y) :- xdom(X),ydom(Y),not(pplus(X,Y)),not(pminus(X,Y)). qunknown(X) :- xdom(X),not(qplus(X)),not(qminus(X)).