Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!travelers.mail.cornell.edu!news.kei.com!news.mathworks.com!newsfeed.internetmci.com!howland.reston.ans.net!news.sprintlink.net!online!online1.magnus1.com!paulb
From: paulb@online1.magnus1.com (Paul Broome)
Subject: Re: is there a sound/complete implementation of negation as failure?
Organization: Home Paramount
Date: Wed, 13 Sep 1995 14:46:08 GMT
Message-ID: <DEuMCx.50y@online.magnus1.com>
Summary: constructive relation complement
X-Nntp-Posting-Host: online1.magnus1.com
Keywords: Constructive negation
References: <42q4gc$1vb@coopers.cs.ubc.ca> <DEqtF3.Dzo@uns.bris.ac.uk>
Sender: usenet@online.magnus1.com (Usenet)
Lines: 142

In <42q4gc$1vb@coopers.cs.ubc.ca>, poole@cs.ubc.ca (David Poole) writes:
> I am looking for a version of a Prolog-like language that correctly
> implements negation as failure, say according to Clark's semantics or
> the stable model semantics or the well founded semantics (I am only
> interested in acyclic programs, so I am not concerned about cases
> where these semantics differ). I am not satisfied with a program that
> delays negation as failure with free variables, and flounders on
> programs that have free variables in the negation.
> 
> Here is the application:
> I am constructing a list of terms of the form p(X,Y) and want to enforce
> the constraint that p is functional (if the X's agree the Y's must agree).
> 
> Here is a specification of the program:
> 
> functional(L) :-
>    \+ notfun(L).
> notfun(L) :-
>    member(p(X,Y1),L),
>    member(P(X,Y2),L),
>    Y1 \= Y2.
> 
> member(X,[X|_]).
> member(X,[_|Z]) :-
>    member(X,Z).
> 
> %  X \= Y is true of X and Y are not equal
> X \= Y :-
>    \+ X=Y.
> 
> 
> I expect the following results (all of which follow from the above program
> using Clark's completion, or the stable model semantics or ... )
> 
> ? functional([p(a,b),p(b,c),p(a,d)])
> fails
> 
> ? functional([p(a,b),p(b,c),p(d,d)])
> succeeds
> 
> ? functional([p(a,b),p(b,c),p(a,X)])
> succeeds with X=b
> 
> ? functional([p(a,Y),p(b,c),p(a,X)])
> succeeds with Y=X
> 
> ? functional([p(a,b),p(Z,c),p(c,d)])
> succeeds with the costraint that Z \= a and Z \= c
> 
> ? functional([p(a,Y),p(Z,c),p(a,X)])
> succeeds with two answers:
>   X=Y & Z\=a
>   Z=a X=Y=c
> (or some other representation of the constraints on these)
> 
> Thanks for your help,
> David

RAlog is based on Tarski-Givant's set theory and aspects of category theory
(allegories).  All programs are binary relations expressed with combinators
and program execution (solve) is a proof that such a combinatory expression
has a representation in set theory in disjunctive normal form.

One interesting aspect of the RAlog answer to David Poole's question is that
all of his examples can be solved at once or individually.  (More
definitions will come later.)

2 ?- define all_examples = ex1 + ex2 + ex3 + ex4 + ex5 + ex6.
all_examples => ex1 + ex2 + ex3 + ex4 + ex5 + ex6 defined.
Yes
3 ?- solve all_examples.
all_examples={X;Y:
   X=1 ^ Y=[p(a, b),p(b, c),p(a, d)]
 V X=2 ^ Y=[p(a, b),p(b, c),p(d, d)]
 V X=3 ^ Y=[p(a, b),p(b, c),p(a, X2)]
 V X=4 ^ Y=[p(a, X3),p(b, c),p(a, X2)]
 V X=5 ^ Y=[p(a, b),p(X2, c),p(c, d)]
 V X=6 ^ Y=[p(a, X4),p(X3, c),p(a, X2)]}.

Yes
4 ?- solve functional(all_examples).
functional(all_examples)={X;Y:
   X=2 ^ Y=[p(a, b),p(b, c),p(d, d)]
 V X=3 ^ Y=[p(a, b),p(b, c),p(a, b)]
 V X=4 ^ Y=[p(a, X2),p(b, c),p(a, X2)]
 V X=5 ^ Y=[p(a, b),p(X2, c),p(c, d)] ^ X2 # a ^ X2 # c
 V X=6 ^ Y=[p(a, X3),p(X2, c),p(a, X3)] ^ X2 # a
 V X=6 ^ Y=[p(a, c),p(a, c),p(a, c)]}.

Yes

The first example (X=1) is not functional so it doesn't appear in the
resulting set.  The last example (X=6) has simpler versions of the two 
expected answers.

Also, any sound and complete implementation of negation should deal with 
universally quantified variables correctly.  Here is a more complex example.

5 ?- solve ex7.
ex7={X;Y:
   X=7 ^ Y=[p(X4, c),p(X3, X2)] ^ (Z3)(Z2)(X3 # s(Z3, c, Z2))}.

Yes
6 ?- solve functional(ex7).
functional(ex7)={X;Y:
   X=7 ^ Y=[p(X2, c),p(X2, c)] ^ (Z3)(Z2)(X2 # s(Z3, c, Z2))
 V X=7 ^ Y=[p(X4, c),p(X3, X2)] ^ X3 # X4 ^ (Z3)(Z2)(X3 # s(Z3, c, Z2))}.

Yes

Are there other LP systems that do this?

The program follows David Poole's specification. 'functional' is a function
from R to a subset of R, those examples that represent functions.  Relation
complement performs a set construction so functional(R) must constrain
complement(R;notfun) to a subset of R.  The (symmetric) recursion operator
is pi.

def functional(R) = R*complement(R;notfun).

def member = pi(id,hd,tl).
def notfun = [id,[member,member];[samedomain, diffrange]];hd.

def samedomain = (hd;p^2/1) * (tl;hd;p^2/1).
def diffrange = (hd;p^2/2;di) * (tl;hd;p^2/2).

def domaina = 1;{a;a};converse(p^2/1).
def rangec = 1;{c;c};converse(p^2/2).

def ex1 = {1;[p(a,b),p(b,c),p(a,d)]}.
def ex2 = {2;[p(a,b),p(b,c),p(d,d)]}.
def ex3 = {3;[p(a,b),p(b,c)]} ; [hd,tl;hd,domaina].
def ex4 = {4;[p(b,c)]} ; [domaina,hd,domaina].
def ex5 = {5;[p(a,b),p(c,d)]} ; [hd,rangec,tl;hd].
def ex6 = {6;a};[domaina, rangec, domaina].
def ex7 = {7;c};[converse(p^2/2), complement(converse(s^3/2));converse(p^2/1)].



Paul Broome

<paulb@online1.magnus1.com> or <broome@msiadmin.cit.cornell.edu>
