[ Comparing and Sorting | Reference Manual | Alphabetic Index ]

prune_instances(+List, -PrunedList)

Succeeds if PrunedList is the smallest list that subsumes the list List.
List
List of instantiated terms.
PrunedList
List or variable.

Description

Used to get the smallest list PrunedList whose elements subsume elements of the list List. List must not contain variables. If List contains elements which are variants of each other, then of these, PrunedList will only contain the first element found. If List contains element(s) which are instances of another element, then of these, PrunedList will only contain the latter.

Note that if List contains only ground terms, it cannot contain proper instances or variants, but only duplicates. Therefore, it is faster to use a sorting predicate to prune it.

Modes and Determinism

Examples

Success:
      prune_instances([5,2,3,5,4,2],L).
          (gives L=[5,2,3,4]).

      prune_instances([f(1,2),f(1,M),1],L).    % instance
          (gives L=[f(1,M),1]).

      prune_instances([f(1,2,3),f(1,M,3),f(1,2,N)],L).
          (gives L=[f(1,M,3),f(1,2,N)]).

      prune_instances([f(1,N),f(1,M),1],L).    % variants (first one retained)
          (gives L=[f(1,N),1]).

      prune_instances([f(1,X),f(1,2),g(1)],L).
          (gives L=[f(1,X),g(1)]).

      :- lib(ic).
      X::2..5, prune_instances([1,3,X,5,8], L).
          (gives L=[X,1,8]).
Fail:
      prune_instances([1,2,3,1,4,2],[2,3,4]).



See Also

sort / 2, sort / 4