22 Ordered Set Operations

This package defines operations on ordered sets. Ordered sets are sets represented as lists with the elements ordered in a standard order. The ordering is defined by the @< family of term comparison predicates and it is the ordering produced by the built-in predicate sort/2 (see Term Compare).

To load the package, enter the query

     | ?- use_module(library(ordsets)).
is_ordset(+Set)
Set is an ordered set.
list_to_ord_set(+List, ?Set)
Set is the ordered representation of the set denoted by the unordered representation List. Example:
          | ?- list_to_ord_set([p,r,o,l,o,g], P).
          
          P = [g,l,o,p,r]
     

ord_add_element(+Set1, +Element ?Set2)
Set2 is Set1 with Element inserted in it, preserving the order. Example:
          | ?- ord_add_element([a,c,d,e,f], b, N).
          
          N = [a,b,c,d,e,f]
     

ord_del_element(+Set1, +Element, ?Set2)
Set2 is like Set1 but with Element removed.
ord_disjoint(+Set1, +Set2)
The two ordered sets have no elements in common.
ord_intersect(+Set1, +Set2)
The two ordered sets have at least one element in common.
ord_intersection(+Set1, +Set2, ?Intersect)
Intersect is the ordered set representation of the intersection between Set1 and Set2.
ord_intersection(+Set1, +Set2, ?Intersect, ?Diff)
Intersect is the intersection between Set1 and Set2, and Diff is the difference between Set2 and Set1.
ord_intersection(+Sets, ?Intersection)
Intersection is the ordered set representation of the intersection of all the sets in Sets. Example:
          | ?- ord_intersection([[1,2,3],[2,3,4],[3,4,5]], I).
          
          I = [3]
     

ord_member(+Elt, +Set)
is true when Elt is a member of Set.
ord_seteq(+Set1, +Set2)
Is true when the two arguments represent the same set. Since they are assumed to be ordered representations, they must be identical.
ord_setproduct(+Set1, +Set2, ?SetProduct)
SetProduct is the Cartesian Product of the two Sets. The product is represented as pairs: Elem1-Elem2 where Elem1 is an element from Set1 and Elem2 is an element from Set2. Example
          | ?- ord_setproduct([1,2,3], [4,5,6], P).
          
          P = [1-4,1-5,1-6,2-4,2-5,2-6,3-4,3-5,3-6]
     

ord_subset(+Set1, +Set2)
Every element of the ordered set Set1 appears in the ordered set Set2.
ord_subtract(+Set1, +Set2, ?Difference)
Difference contains all and only the elements of Set1 that are not also in Set2. Example:
          | ?- ord_subtract([1,2,3,4], [3,4,5,6], S).
          
          S = [1,2]
     

ord_symdiff(+Set1, +Set2, ?Difference)
Difference is the symmetric difference of Set1 and Set2. Example:
          | ?- ord_symdiff([1,2,3,4], [3,4,5,6], D).
          
          D = [1,2,5,6]
     

ord_union(+Set1, +Set2, ?Union)
Union is the union of Set1 and Set2.
ord_union(+Set1, +Set2, ?Union, ?New)
Union is the union of Set1 and Set2, and New is the elements of Set2 that are not also in Set1. This is useful if you are accumulating members of a set and you want to process new elements as they are added to the set.
ord_union(+Sets, ?Union)
Union is the union of all the sets in Sets. Example:
          | ?- ord_union([[1,2,3],[2,3,4],[3,4,5]], U).
          
          U = [1,2,3,4,5]