🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #170

Re: memoization

#170
From: Bharat Jayaraman
Date: Fri, 10 Apr 1992 03:02
37 lines
1843 bytes
In message <1992Apr8.161318.17505@sbcs.sunysb.edu>, David has translated 
the program

       out(B) = (in(B) - kill(B)) U gen(B)
       in (B) = U {out(P) : P in pred(B)}

as follows (glad to hear that this brings back fond memories (8-)).

	X in out(B) :- X in in(B), ~ X in kill(B).
	X in out(B) :- X in gen(B).
	X in in(B)  :- X in out(P), P in pred(B).

It appears from this example and the previous one ("reach") that XOLDT avoids 
working with the actual set, but simply return the elements one at a time 
at the top-level.  There are problems where there seems to be a need to 
form the resulting set at an intermediate stage of the computation, perform 
some operation on it, and proceed until convergence is reached.  To be
more concrete, here's a formulation of shortest distance between a 
vertex-pair in a graph (in the SEL notation) illustrating this need.

	closure costs/2, costs2/2.	%closure = memo + redo

	short(X,Y) = if X=Y then 0 else min(costs(X,Y)). 
		% min returns smallest number in a set; it returns 
		% some large number ("infinity") if the set is empty.

	costs(X,Y) = costs2(edgesfrom(X),Y).

	costs2({to(X,D)\_},Y)  contains if X=Y then {D} else {D+short(X,Y)}.

	edgesfrom(a) = {to(b,10), to(c,16), to(d,8)}.  % to(vertex,distance)
	edgesfrom(b) = {to(a,20), to(c,2), to(e,4)}.
		etc.

	% use a different representation for the graph if you prefer.

Bharat
Technical Details
Message-ID: <1992Apr10.030227.7679@acsu.buffalo.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!rutgers!ub!acsu.buffalo.edu!bharat

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!rutgers!ub!acsu.buffalo.edu!bharat
From: bharat@acsu.buffalo.edu (Bharat Jayaraman)
Newsgroups: comp.lang.prolog
Subject: Re: memoization
Message-ID: <1992Apr10.030227.7679@acsu.buffalo.edu>
Date: 10 Apr 92 03:02:27 GMT
Sender: usenet@acsu.buffalo.edu
Organization: State University of New York at Buffalo/Comp Sci
Lines: 37
Nntp-Posting-Host: logic.cs.buffalo.edu