thom@tuhold (Thom Fruehwirth) (07/27/88)
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