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)
list_to_ord_set(
+List,
?Set)
| ?- list_to_ord_set([p,r,o,l,o,g], P). P = [g,l,o,p,r]
ord_add_element(
+Set1,
+Element ?Set2)
| ?- ord_add_element([a,c,d,e,f], b, N). N = [a,b,c,d,e,f]
ord_del_element(
+Set1,
+Element,
?Set2)
ord_disjoint(
+Set1,
+Set2)
ord_intersect(
+Set1,
+Set2)
ord_intersection(
+Set1,
+Set2,
?Intersect)
ord_intersection(
+Set1,
+Set2,
?Intersect,
?Diff)
ord_intersection(
+Sets,
?Intersection)
| ?- ord_intersection([[1,2,3],[2,3,4],[3,4,5]], I). I = [3]
ord_member(
+Elt,
+Set)
ord_seteq(
+Set1,
+Set2)
ord_setproduct(
+Set1,
+Set2,
?SetProduct)
| ?- 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)
ord_subtract(
+Set1,
+Set2,
?Difference)
| ?- ord_subtract([1,2,3,4], [3,4,5,6], S). S = [1,2]
ord_symdiff(
+Set1,
+Set2,
?Difference)
| ?- ord_symdiff([1,2,3,4], [3,4,5,6], D). D = [1,2,5,6]
ord_union(
+Set1,
+Set2,
?Union)
ord_union(
+Set1,
+Set2,
?Union,
?New)
ord_union(
+Sets,
?Union)
| ?- ord_union([[1,2,3],[2,3,4],[3,4,5]], U). U = [1,2,3,4,5]