Minimum depth limit
- From: "Mauro Di Nuzzo" <picorna@xxxxxxxxx>
- Date: Fri, 12 Aug 2005 16:20:46 GMT
Prolog is not Logic. This is evident. So, in many introductory Prolog books,
facts are suggested to be separated by rules. For example, the following is
a bad practice, according to most...
f(t,z).
f(e,q).
f(b,e).
f(w,i).
f(a,b).
f(q,w).
f(i,t).
f(X,X).
f(X,Y) :- f(Y,X).
f(X,Y) :- f(X,Z), f(Z,Y).
In this example, facts and rules, are both represented by f/1.
A call like:
?- f(a,z).
will start an infinite loop.
A suggestion is to replace database facts, with another name, and to use
this into the rules. This has to be done to avoid recursion.
Another method could be to limit the depth (i.e. recursion level) of a call.
In SWI Prolog this is done via call_with_recursion_limit/3 predicate.
So, one can write such a predicate:
prove(Goal) :-
call_with_depth_limit(Goal, ???, Result),
Result \= depth_limit_exceeded.
In this way, it will be possible to call, for example:
?- prove(f(a,z)).
yes
Anyone know if a formal description of depth-limited calls does exist?
I found that the number in the place of ??? must be at least 5 (try
?-prove(f(z,a)).).
Any suggestions will be appreciated.
Thank you,
M
.
- Follow-Ups:
- Re: Minimum depth limit
- From: zu61
- Re: Minimum depth limit
- Prev by Date: Re: newbie question: how to measure run-time with Sicstus under linux?
- Next by Date: Re: newbie question: how to measure run-time with Sicstus under linux?
- Previous by thread: newbie question: how to measure run-time with Sicstus under linux?
- Next by thread: Re: Minimum depth limit
- Index(es):
Relevant Pages
|
|