Product Site

5.3.20.3. Set-Like Operations on Collections with Duplicates

Assume that the example bags are A={a,b,b} and B={b,b,c,c,d}. Except for subset, equivalent, and disjoint, the result of any set-like operation is a collection, in this case a bag. Using the collections A and B, the different set-like operators produce the following:
UNION operation

All elements of A and B are united:
A UNION B = {a,b,b,b,b,c,c,d}
DIFFERENCE operation

The resulting collection contains all elements of the first bag except for those that also appear in the second bag. The system iterates over the elements of the second bag and removes them from the first bag one by one.
A DIFFERENCE B = {a}
B DIFFERENCE A = {c,c,d}
XOR operation

The resulting collection contains all elements of the first bag that are not in the second bag and all elements of the second bag that are not in the second bag:
A XOR B = {a,c,c,d}
INTERSECTION operation

The resulting collection contains all elements that appear in both bags:
A INTERSECTION B = {b,b}
SUBSET operation

Returns .true if the first set contains only elements that also appear in the second set, otherwise it returns .false:
A SUBSET B = .false
B SUBSET A = .false
EQUIVALENT operation

Returns .true if the first set contains only elements that also appear in the second set and the two sets have the same number of elements, otherwise it returns .false:
A EQUIVALENT B = .false
B EQUIVALENT A = .false
DISJOINT operation

Returns .true if there are no elements that appear in both sets, otherwise it returns .false:
A DISJOINT B = .false
B DISJOINT A = .false