🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #2843

Re: forall/2 and negation as failure

#2843
From: Lee Naish
Date: Mon, 26 Oct 1987 07:59
61 lines
3050 bytes
In article <8781@shemp.UCLA.EDU> reeves@CS.UCLA.EDU (John F. Reeves) writes:
>I'm having a problem reading forall/2 and wondered if anyone  could  help.
>
>    forall(father(X,C),male(C))
>
>....Alternatively, is there a case where:
>
>	forall(G,C) :- not(G, not C).
>
>behaves counterintuitively, due to the use of not as negation-as-failure?
BTW, it should be not (G, not C) or not((G, not C)).

forall has the same problems as \+ (not) in most Prolog systems.
It is not logical.  Even its name has an operational flavor rather than a
declarative one.  It should be logical and be called implies, or =>
(declared as an operator, of course).  Also, there should be a way of
stating the quantification of variables.  In NU-Prolog you can write

all C father(X,C) => male(C)	% all children X fathered are male
or
all X father(X,C) => male(C)	% meaningful but not useful

These are both compiled into the not not form, which delays until the
unquantified variables are ground (hence it is sound).  If the construct
appears in a predicate declared 'pure', further transformation may be
done by the compiler.  For example

all [C,S] (father(X, C), sex(X, S) => S ~= female)
is currently compiled into
all [C,S] not (S = female, father(X, C), sex(X, S))
	(we could do better, of course)

This is all very easy to implement and every Prolog system should have
it (if the system doesnt support delaying then it should write error
messages instead).  It really is useful for programming - it makes
programming easier and programs much more readable.  It is also useful
for teaching.  Here is an game playing example from Bratko (p 360):

win(Pos) :-
	not terminallost(Pos),
	move(Pos, Pos1),
	not ( move(Pos1, Pos2),
	      not won(Pos2)).

The last two lines should be

	all Pos2 move(Pos1, Pos2) => won(Pos2).

Which do you think is easier to understand?

I have just finished teaching an introductory AI/logic programming
course.  For the first time, students have not been (ab)using cut.
Although some of the programming style has not been great (overuse
of if-then-else being the most common flaw), we consider this to be
a significant advance.  A major reason for it is the higher level
logical constructs which are available.   The aggregate functions
(sum, count etc) which Philip Dart mentioned on the network recently
were also used more than I expected.  It seems that they are another
worthwhile logical extension to Prolog.

	lee
Technical Details
Message-ID: <2335@mulga.oz>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!munnari!mulga!lee
References: <8781@shemp.UCLA.EDU>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!munnari!mulga!lee
From: lee@mulga.oz (Lee Naish)
Newsgroups: comp.lang.prolog
Subject: Re: forall/2 and negation as failure
Message-ID: <2335@mulga.oz>
Date: Mon, 26-Oct-87 02:59:04 EST
Article-I.D.: mulga.2335
Posted: Mon Oct 26 02:59:04 1987
Date-Received: Wed, 28-Oct-87 04:27:10 EST
References: <8781@shemp.UCLA.EDU>
Reply-To: lee@mulga.UUCP (Lee Naish)
Organization: Comp Sci, Melbourne Uni, Australia
Lines: 61
Summary: use implication and quantifiers