Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!spool.mu.edu!uwm.edu!msunews!harbinger.cc.monash.edu.au!bunyip.cc.uq.oz.au!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: Nondeterminism
Message-ID: <9434911.21320@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU
Organization: Computer Science, University of Melbourne, Australia
References: <9434021.28025@mulga.cs.mu.OZ.AU> <D0Jt09.KBy@ecrc.de>
Date: Thu, 15 Dec 1994 00:32:18 GMT
Lines: 56

thom@ecrc.de (Thom Fruehwirth) writes:


>>From conway@munta.cs.mu.OZ.AU (Thomas Charles CONWAY)
>>Subject: Re: In defense of Prolog's dynamic typing
>>Date: Tue, 6 Dec 1994 10:56:12 GMT
>>
>>Number of modes:                  2209
>>        - det:                    1858 ( 84.11%)
>>        - semidet:                 344 ( 15.57%)
>>        - nondet:                   38 (  1.72%)
>
>Nondeterminism seems to be rare in logic programs. 

The above statistics are actually very biased.

The major reason is that when we first started writing the compiler,
we quite deliberately avoided using non-determinism since we thought
that it would be reasonably tricky to implement non-deterministic code
and we wanted to be able to bootstrap as soon as possible.
As it turned out, once we had implemented the det and semidet compilation
models, implementing non-deterministic code was pretty easy, and so we
started using non-deterministic code in the compiler.  But obviously
the statistics are rather skewed.

Also, you should look at not just how many modes of predicates are nondet,
but also at how often those modes are used.  There are quite a few
places in the Mercury compiler where deterministic predicates contain
some local non-determinism which does not escape, e.g. in goals like

	if some [X] member(X, L) then
		...
	else
		...

Unfortunately I don't have any statistics on the frequency of those
sort of usages.  (`awk' is not so good at doing mode analysis ;-).

>So why don't we get rid of the overhead of global/implicit search
>by chronological backtracking in favor of local/explicit search
>constructs ?

Mercury eliminates the overhead by doing determinism analysis at compile
time.  Predicates which do not use backtracking do not pay any overhead.

[To be completely accurate, there are two virtual machine registers
used for backtracking.  If they are allocated to real registers, they
decrease the number of real registers available for the deterministic
parts of the program.  We could probably reduce that to just one extra
register without that much trouble if it was worth the effort.  But the
overhead is currently extremely low anyway - for various reasons,
partly related to our current code generation scheme, programs don't
seem to use a lot of registers and so there are very few register spills.]

-- 
Fergus Henderson - fjh@munta.cs.mu.oz.au
