| Did you know ... | Search Documentation: |
| Predicate term_minimal/2 |
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.