4.21 Analysing and Constructing Terms
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • Built-in Predicates
        • Analysing and Constructing Terms
          • functor/3
          • functor/4
          • arg/3
          • =../2
          • compound_name_arity/3
          • compound_name_arguments/3
          • numbervars/3
          • numbervars/4
          • var_number/2
          • term_variables/2
          • nonground/2
          • term_variables/3
          • term_singletons/2
          • is_most_general_term/1
          • copy_term/2
          • copy_term/4
          • copy_term_nat/4
          • term_factorized/3
          • term_factorized/4
          • term_minimal/2
          • term_automaton/2
          • automaton_minimal/2
          • automaton_minimal/3
          • Non-logical operations on terms
    • Packages
Availability:built-in
[det]term_minimal(+Term, -Minimal)
True when Minimal == Term and Minimal uses the least possible number of compound cells. Subterms denoting the same tree are shared, so a cyclic term or one with repeated subterms comes back smaller, while one with neither comes back unchanged:
?- X = f(g(a),g(a)), term_minimal(X, M), M == X.
true.

Because ==/2 on rational trees is bisimulation, there is no smaller term that is still ==/2 to Term. A term of N cells can denote a tree with 2^N nodes, or an infinite one, so this can be a large saving: a cyclic term of a million cells all denoting h(h(h(...))) minimises to one cell.

After term_minimal/2, operations that walk the term graph, such as ==/2, copy_term/2, assertz/1 and term_hash/2, have less to walk.

See also term_automaton/2, which writes the term graph out as an explicit automaton, and automaton_minimal/2, which minimises one.