Article View: comp.lang.prolog
Article #3521iterative deepening
From: Thom Fruehwirth
Date: Wed, 27 Jul 1988 16:05
Date: Wed, 27 Jul 1988 16:05
35 lines
1296 bytes
1296 bytes
I implemented the following meta-interpreter for iterative deepening in Prolog: /*1*/ prove(G,N) :- prove(G,N,0). prove(true,N,N). prove((G1,G2),N,M) :- prove(G1,N,N1), prove(G2,N1,M). prove(G,N,M) :- N>0, N1 is N-1, clause(G,Gs), prove(Gs,N1,M). One can add cuts as first subgoals to get more speed. Just for fun I replaced the integer arithmetic for computing the depth by peano arithmetic using a successor function s(N). I only had to change the last clause into: /*2*/ ... prove(G,s(N),M) :- clause(G,Gs). prove(Gs,N,M). Surprisingly, version /*2*/ is about 25% faster than version /*1*/. After that I found out that it takes more time on my Prolog to do a comparison and a substraction than to unfiy with s(N). As Richard O'Keefe says "Elegancy is not optional". Version /*2*/ is more readable, uses no built-ins but clause/2 and one can even call prove(G,N) with N unbound to get the behaviour of a standard meta-interpreter! thom fruehwirth, vienna
Technical Details
Message-ID:
<1076@tuhold>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcvax!tuvie!tuhold!thomShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcvax!tuvie!tuhold!thom From: thom@tuhold (Thom Fruehwirth) Newsgroups: comp.lang.prolog Subject: iterative deepening Message-ID: <1076@tuhold> Date: 27 Jul 88 16:05:24 GMT Organization: Institut f. Angewandte Informatik, TU Vienna Lines: 35