@ciao-lang/ts-ciao-interface
Version:
Simple Ciao interface for node.
51 lines (36 loc) • 6.4 kB
HTML
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><meta name="theme-color" content="#273f79"/><link rel="stylesheet" href="lpdoc.css" type="text/css"/><script type="text/javascript" src="lpdoc.js"></script><title>Iterative-deepening execution — The Ciao System v1.22</title></head><body><div class="lpdoc-page fixleftbar"><a href="#" id="sidebar-toggle-button" class="lpdoc-navbutton"><span id="sidebar-button-arrow">☰</span></a><div id="sidebar" class="lpdoc-sidebar"><div style="height: 40px; margin-left: auto; margin-right: auto"><img src="ciao-logo_autofig.png" width=auto height=100%></div><div class="lpdoc-nav"><span class="lpdoc-on-right"><a class="lpdoc-navbutton" href="ExtendLang.html">↑</a><a class="lpdoc-navbutton" href="bf_doc.html">←</a><a class="lpdoc-navbutton" href="odd.html">→</a><a class="lpdoc-navbutton" href="ciaosearch.html">🔍</a></span><span><a href="ciaofulltoc.html">TOC</a></span></div><hr></hr><ul class="lpdoc-itemize-sectpath"><li><a href="ciao.html">The Ciao System</a> »<br/> </li><li><a href="ExtendLang.html">PART IV - Language extensions</a> »<br/> </li><li><a href=""><strong>Iterative-deepening execution</strong></a></li></ul><hr></hr><em>ON THIS PAGE</em><ul><li><a href="#Usage and interface">Usage and interface</a></li></ul></div><div class="lpdoc-main"><div id=""><h1>Iterative-deepening execution</h1><a class="lpdoc-idx-anchor" href="ciaosearch.html#id"></a>
<strong>Author(s):</strong> <a class="lpdoc-idx-anchor" id="Remy Haemmerle" href="ciaosearch.html#Remy Haemmerle">Rémy Haemmerlé</a>, <a class="lpdoc-idx-anchor" id="Manuel Carro" href="ciaosearch.html#Manuel Carro">Manuel Carro</a>, <a class="lpdoc-idx-anchor" id="Claudio Vaucheret" href="ciaosearch.html#Claudio Vaucheret">Claudio Vaucheret</a>, <a class="lpdoc-idx-anchor" id="Manuel Hermenegildo" href="ciaosearch.html#Manuel Hermenegildo">Manuel Hermenegildo</a>.<p>
This package applies a <em>compiling control</em> technique to implement <a class="lpdoc-idx-anchor" id="0" href="ciaosearch.html#depth first iterative deepening"><em>depth first iterative deepening</em></a> execution [<a class="lpdoc-idx-anchor" id="1" href="ciaorefs.html#iterative-deepening">Kor85</a>]. It changes the usual <em>depth-first</em> search rule by <a class="lpdoc-idx-anchor" id="2" href="ciaosearch.html#iterative-deepening"><em>iterative-deepening</em></a> on those predicates specifically marked. This is very useful in search problems when a <a class="lpdoc-idx-anchor" id="3" href="ciaosearch.html#complete proof procedure">complete proof procedure</a> is needed.<p>When this search rule is used, first all goals are expanded only up to a given depth. If no solution is found or more solutions are needed by backtracking, the depth limit is incremented and the whole goal is repeated. Although it might seem that this approach is very inefficient because all higher levels are repeated for the deeper ones, it has been shown that is performs only about b/(b - 1) times as many operations than the corresponding breadth-first search, (where b is the branching factor of the proof tree) while the waste of memory is the same as depth first.<p>The usage is by means of the following directive:<p><tt>:- iterative(Name, FirstCut, Formula).</tt> <p>which states than the predicate 'Name' given in functor/arity form will be executed using iterative deepening rule starting at the depth 'FirstCut' with depth being incremented by the predicate 'Formula'. This predicate compute the new depth using the previous one. It must implement a dilating function i.e. the new depth must be greater. For example, to start with depth 5 and increment by 10 you can write:<p><tt>:- iterative(p/1,5,f).</tt> <p><tt>f(X,Y) :- Y is X + 10.</tt> <p>or if you prefer,<p><tt>:- iterative(p/1,5,(_(X,Y):- Y is X + 10)).</tt> <p><a class="lpdoc-idx-anchor" id="4" href="ciaosearch.html#depth limit"></a> You can also use a fourth parameter to set a limiting depth. All goals below the given depth limit simply fail. Thus, with the following directive:<p><tt>:- iterative(p/1,5,(_(X,Y):- Y is X + 10),100).</tt> <p>all goals deeper than 100 will fail.<p>An example of code using this package would be:<p><pre class="lpdoc-codeblock">:- module(example_id, _,[id]).
test(id) :-
idchain(a,d).
test(df) :-
chain(a,d). % loops!
:- iterative(idchain/2, 3, ( _(X,Z) :- Z is X + 1) ).
idchain(X,X).
idchain(X,Y) :-
arc(X,Z),
idchain(Z,Y).
chain(X,X).
chain(X,Y) :-
arc(X,Z),
chain(Z,Y).
arc(a,b).
arc(a,d).
arc(b,c).
arc(c,a).
</pre> <p>The order of solutions are first the shallower and then the deeper. Solutions which are between two cutoff are given in the usual left to right order. For example,<p><pre class="lpdoc-codeblock">:- module(_,_,[id]).
% All goals deeper than 2 will fail
:- iterative(p/1,0,(_(X,Z) :- Z is X + 1),2).
% Change the solutions' order to goal p(X).
%:- iterative(p/1,1,(_(X,Z) :- Z is X + 3)).
p(X) :- q(X).
p(a).
q(X) :- r(X).
q(b).
r(X) :- s(X).
r(c).
s(d).
</pre> <p>Another complete proof procedure implemented is the <a class="lpdoc-idx-anchor" id="5" href="bf_doc.html"><tt>bf</tt></a> package (<a class="lpdoc-idx-anchor" id="6" href="ciaosearch.html#breadth first execution">breadth first execution</a>).<br/><div id="Usage and interface"><h2>Usage and interface</h2><div class="lpdoc-cartouche"><ul><li><strong>Library usage:</strong><br/><tt>:- use_package(id).</tt>
or
<tt>:- module(...,...,[id]).</tt><li><strong>Implicit imports:</strong><br/><ul class="lpdoc-itemize-minus"><li><em>Packages:</em><br/><a class="lpdoc-idx-anchor" id="7" href="ciaosearch.html#prelude"><tt>prelude</tt></a>, <a class="lpdoc-idx-anchor" id="8" href="ciaosearch.html#initial"><tt>initial</tt></a>, <a class="lpdoc-idx-anchor" id="9" href="condcomp_doc.html"><tt>condcomp</tt></a>, <a class="lpdoc-idx-anchor" id="10" href="assertions_doc.html"><tt>assertions</tt></a>, <a class="lpdoc-idx-anchor" id="11" href="ciaosearch.html#assertions/assertions_basic"><tt>assertions/assertions_basic</tt></a>.
</ul></ul></div></div></div><div class="lpdoc-footer">Generated with LPdoc using Ciao</div></div><div class="lpdoc-clearer"></div></div></body></html>