Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!oitnews.harvard.edu!purdue!lerc.nasa.gov!magnus.acs.ohio-state.edu!math.ohio-state.edu!cs.utexas.edu!swrinde!tank.news.pipex.net!pipex!newsfeed.internetmci.com!news.mel.aone.net.au!inferno.mpx.com.au!news.unimelb.EDU.AU!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: Linear Equation Solver in Prolog available?
Message-ID: <9524100.1310@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU (CS-Usenet)
Organization: Computer Science, University of Melbourne, Australia
References: <40a0eg$5oh@zruty.dfv.rwth-aachen.de> <8081537678-312206@ai.univie.ac.at> <40ujb1$4ec@lace.Colorado.EDU> <411icp$37m@goanna.cs.rmit.edu.au> <416pe0$fr3@elna.ethz.ch>
Date: Mon, 28 Aug 1995 14:32:30 GMT
Lines: 55

marti@inf.ethz.ch (Robert Marti) writes:

>ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe) comments on
>the code by gbrenner@euclid.Colorado.EDU (Gary M. Brenner)
>to solve systems of linear equations:
>
>|> AAAAAAAAAAAAAAAAAAAAAAAAARGH!
>|> 
>|> This is a textbook example of how _NOT_ to write Prolog.
>[...]
>|> I'll let you into a little secret:  no cuts are necessary...
>
>Since we have a license for Quintus, I briefly looked at
>Richard's code.  As I suspected, it doesn't use assert/
>retract either, which I feel is more important than the
>cuts.  Besides, while I couldn't detect a cut, Richard's
>code _does_ use at least one "higher form" of cut, namely
>If -> Then ; Else.

There are very significant differences between Prolog's ->;
and cut.  Cut is a totally non-logical operator with non-local
operational effects; it is widely mis-used, and most code using
cut is not steadfast.  (See Richard O'Keefe's "The Craft of Prolog".)
Prolog's ->; is non-logical, but its effect is local, and furthermore
under conditions which are easy to satisfy, it does have a well-defined
logical semantics.  The conditions are that the "if" part of the
if-then-else

	(1) doesn't have any side effects,
	(2) doesn't have more than one solution, and
	(3) doesn't bind any non-local variables.

If these conditions hold, then (A -> B ; C) is equivalent to
(A /\ B) \/ ((not A) /\ C).  I haven't seen Richard O'Keefe's Gaussian
elimination code, but I suspect that there is a high probability that
every use of ->; in that code satisfies these 3 conditions.

Note that Mercury, which is a 100% pure logic programming language,
includes an (If -> Then ; Else) construct whose syntax is exactly the
same as that of Prolog.  The semantics in Mercury are slightly
different, because Mercury guarantees that ->; will always have a
well-defined logical semantics.  Condition (2) does not need to hold
for Mercury, because Mercury's ->; will not prune away the second and
subsequent solutions of the condition (unless the compiler can prove
that it is safe to do so, e.g. because the condition doesn't have any
output variables).  The Mercury compiler checks condition (3) at
compile time, and reports a mode error if it is not satisfied.  Of
course, condition (1) always holds, since Mercury is a pure logic
programming language.

-- 
Fergus Henderson             |  #define x t=a[i],a[i]=a[m],a[m]=t
                             |  char a[]=" 12345678";main(m,i,j,t){for(i=m;i<
fjh@cs.mu.oz.au              |  9;x,i++)for(x,j=m;--j?(t=a[m-j]-a[m])-j&&t+j:
http://www.cs.mu.oz.au/~fjh  |  main(m+1)*0;);m-9||puts(a+1);} /* 8 queens */
