<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\subsection{Tabling}
You can also use tabling in inference to speed up the computation and/or avoid loops, see
the \href{http://www.swi-prolog.org/pldoc/man?section=tabling}{SWI-Prolog manual}.

To do so you have to use the \verb|tabling| library module and declare some of the predicates
as tabled. The tabling declarations go after the \verb|:-pita.| or \verb|:- mc.| directives.

For example, to compute the probability of paths in undirected graphs you can use
the program (\href{http://cplint.eu/e/path_tabling.swinb}{\texttt{path\_tabling.swinb}})
\begin{verbatim}
:- use_module(library(pita)).
:- use_module(library(tabling)).
:- pita.
:- table path/2.
:- begin_lpad.
path(X,X).
path(X,Y):-
  path(X,Z),edge(Z,Y).
edge(X,Y):-arc(X,Y).
edge(X,Y):-arc(Y,X).
arc(a,b):0.2.
arc(b,e):0.5.
arc(a,c):0.3.
arc(c,d):0.4.
arc(d,e):0.4.
arc(a,e):0.1.
:- end_lpad.
\end{verbatim}
Then you can compute the probability that \verb|a| and \verb|e| are connected with
\begin{verbatim}
prob(path(a,e),Prob).
\end{verbatim}
This programs has loops so if you run the above query without tabling \verb|pita| would loop forever.

You can use tabling with both \verb|pita| and \verb|mcintyre|.

</pre></body></html>