Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!news.acsu.buffalo.edu!news.uoregon.edu!tezcat!cam-news-hub1.bbnplanet.com!news.bbnplanet.com!howland.erols.net!rill.news.pipex.net!pipex!uknet!usenet1.news.uk.psi.net!uknet!uknet!newsfeed.ed.ac.uk!dcs.ed.ac.uk!cnews
From: ato@dcs.ed.ac.uk (Alan Ogilvie)
Subject: Re: interval to a list
X-Nntp-Posting-Host: ramna.dcs.ed.ac.uk
Message-ID: <E5Cu24.HuA.0.staffin.dcs.ed.ac.uk@dcs.ed.ac.uk>
Sender: cnews@dcs.ed.ac.uk (UseNet News Admin)
Organization: Department of Computer Science, Edinburgh University
X-Newsreader: knews 0.9.6
References: <32F496D3.1EA7@cips2.gm.fh-koeln.de>
  <E53Isu.65C.0.staffin.dcs.ed.ac.uk@dcs.ed.ac.uk>
  <32F7D080.1FC7@dial.pipex.com> <5da030$6d1@mulga.cs.mu.oz.au>
  <32F8B5C4.7321@dial.pipex.com>
Date: Sun, 9 Feb 1997 21:22:50 GMT
Lines: 82

Hey, cool it - you all seem to be loosing the duster about this...

>>  >Alan Ogilvie wrote:
>>  >>
>>  >> interval(X,X,[X]).
>>  >> interval(A,B,[A|Rest]):-
>>  >>         NewA is A+1,
>>  >>         interval(NewA,B,Rest).
>>  >
>>  >I'm sure you meant to say:
[...snip]

Okay, so in actual fact. When I originally hashed the predicate into
my version of Sicstus I did check that A<B in predicate/3 rule. If you
insist that you are never going to redo it, then it works without it,
hence this is why I dropped it from my posted code. But I see now that
it is necessary _if_ you are going to make it redo.

>> I'm not quite sure why you reordered the clauses, though.
>> It can't be for performance, since in this example putting
>> the base case last result in performance that is either the
>> same, if your Prolog compiler is smart, or (more likely!)
>> performance that is significantly worse.
>The reordering of the clauses was a 'hint' cf: "how I knew it was broken
>without testing it". The broken version will survive very rudimentary
>tests _because_ of its clause ordering; the corrected version will
>survive much more severe tests _irrespective_ of clause ordering.

Yes, but then I like to put base cases before others, unless there is
a specific reason for doing so (and if there is I frown upon the code,
and think that there must be some other way to do it - which usually
results in better efficiency). So, in my eyes the reordered version
_looks_ worse and is probably less efficient....

>> (How many maths textbooks list the base cases of definitions
>> or proofs after the recursive cases?  None that I've seen.)
>But then again, 'slavish adherence to tradition' was implicated in
>the original faulty code.......

'slavish adherence to tradition'? Hmmm. never heard it called that
before.  Possibly more commonly known as 'a stupid mistake', 'a bug',
'a feature', or 'doing a Micro$oft'.

>> Note that unless you are assuming that your Prolog compiler is quite
>> smart, your code has a performance bug, because it leaves lots of
>> choice points around. This will have the further effect of preventing
>> the system from reclaiming garbage, so your code can cause space leaks.

Choice points are highly difficult to notice (or at least I find
this), perhaps someone just never explained to to me correctly. But
then my theory above of reordering probably sorts this out...

>How do you know? If the code is usually called with an interval size of
>1 or 2 the reordered clauses might be better. It's always dangerous to
>make generalisations about performance, not that you'd ever guess from
>reading this newsgroup.

...on the other hand, maybe it doesn't...

>> This is a good example of why Prolog is IMHO an awful language to use
>> if you're the least bit interested in performance.
>Here I go again, claiming to know what people meant to say: "This is a
>good example of why Prolog is I(Fergus')HO an awful language to use if
>you're obsessed by performance." :)

Prolog vs Performance - an interesting point. From what I've done with
it (Artificial Intelligence) I really haven't had many performance
problems, but then I am using a SparcStation 5, and if I use my
reordering theory I laid out above, then usually have no problems.

-- 
--
-------------------------------------------------------------------------
:Alan Ogilvie : A.T.Ogilvie@ed.ac.uk                          (Personal):
:WWW Page/s   : http://www.tardis.ed.ac.uk/~alan/             (Personal):
-------------------------------------------------------------------------
"Some men see things as they are and say 'why?' I dream things that never
were and say 'why not?'"                                [Robert F.Kenedy]
=========================================================================



