The test predicate ground/1 checks whether the given term is
ground. This means that no un-instantiated variable occurs in the
term. The predicate term_variables/2 allows collecting the
un-instantiated variables that occur in a term. The predicate will
thus return an empty list if the term was ground. Finally the
predicate sys_term_singletons/2 collects the un-instantiated
variables that only occur once. They are a subset of all the
variables that occur in the term.

?- sys_goal_kernel(X^p(X,Y),K).

K = p(X,Y)

?- sys_goal_globals(X^p(X,Y),L).

L = [Y]

Further there are predicates to deal with existential
quantifiers. The existential quantifier is represented by the
(^)/2 operator. In a goal X_{1}^..^X_{n}^K we call
K the kernel of the goal and the variables K subtracted by the
variables of X_{1},..,X_{n} the global variables
of the goal. The predicates sys_goal_kernel/2 and
sys_goal_globals/2 cater for the determination of the kernel and
the global variables of a goal.

An alternative to using the ‘$VAR’(<number>) construct is
dynamically creating a variable names map. This has the advantage
that the construct itself can be written out. The predicate
sys_number_variables/4 helps in creating a variable names map. The
resulting variable names map can be used with the predicates
write_term/[2,3].

The variable names map from the current top-level query can be
retrieved via the predicate sys_get_variable_names/1. The
predicate will skip non-variable and duplicate entries. In the
case of duplicates the entry with a lower dereferencing count is
preferred. The result is intended to be used with the predicates
write_term/[2,3].

The following term variable predicates are provided:

**term_variables(X, L): [TC2 8.5.5]****term_variables(X, L, R):**- The predicate succeeds when L unifies with the variables of X. The variant with a third argument produces a difference list.
**sys_term_singletons(X, L):**- The predicate succeeds when L unifies with the variables of X that occur only once.
**sys_goal_kernel(G, K):**- The predicate succeeds when K unifies with the kernel of the goal G.
**sys_goal_globals(G, L):**- The predicate succeeds when L unifies with the global variables of the goal G.
**numbervars(X, N, M):**- The predicate instantiates the un-instantiated variables of the term X with compounds of the form ‘$VAR’(<index>). The <index> starts with N. The predicate succeeds when M unifies with the next available <index>.
**sys_number_variables(V, N, S, M):**- The predicate succeeds with variable names M resulting from giving names to the variables in V, respecting the variable names N and the unnamed singletons S.
**ground(X): [TC2 8.3.10]**- The predicate succeeds when X is a ground term, i.e. contains no variables.
**sys_get_variable_names(L):**- The predicate succeeds in L with the current variable names from the top-level query excluding non-variables and duplicates.
**acyclic_term(X): [TC2 8.3.11]**- The predicate succeeds when X is an acyclic term, i.e. contains no cycles.