% This LaTeX document was generated using the LaTeX backend of PlDoc,
% The SWI-Prolog documentation system



\section{library(occurs): Finding and counting sub-terms}

\label{sec:occurs}

\begin{tags}
    \tag{See also}
\verb$library(terms)$ provides similar predicates and is probably
more wide-spread than this library.
\end{tags}

This is a SWI-Prolog implementation of the corresponding Quintus
library, based on the generalised \predref{arg}{3} predicate of SWI-Prolog.\vspace{0.7cm}

\begin{description}
    \predicate[semidet]{contains_term}{2}{+Sub, +Term}
Succeeds if \arg{Sub} is contained in \arg{Term} (=, deterministically)

    \predicate[det]{contains_var}{2}{+Sub, +Term}
Succeeds if \arg{Sub} is contained in \arg{Term} (==, deterministically)

    \predicate{free_of_term}{2}{+Sub, +Term}
Succeeds of \arg{Sub} does not unify to any subterm of \arg{Term}

    \predicate{free_of_var}{2}{+Sub, +Term}
Succeeds of \arg{Sub} is not equal (\Sequal{}) to any subterm of \arg{Term}

    \predicate{occurrences_of_term}{3}{+SubTerm, +Term, ?Count}
\arg{Count} the number of SubTerms in \arg{Term}

    \predicate{occurrences_of_var}{3}{+SubTerm, +Term, ?Count}
\arg{Count} the number of SubTerms in \arg{Term}

    \predicate{sub_term}{2}{-Sub, +Term}
Generates (on backtracking) all subterms of \arg{Term}.

    \predicate{sub_var}{2}{-Sub, +Term}
Generates (on backtracking) all subterms (\Sequal{}) of \arg{Term}.
\end{description}

