6.2.5 Complement Sets

A complement set represents the complement of a normal, enumerated set. That is, the complement of a set S contains every object that is not in S, and does not contain any object that is in S.

Complement sets are infinite, so they can’t be iterated over, and calling arb or size on one is an error, but some operations are available on them. They can be unioned, intersected, etc. with each other and with normal sets.

I don’t think of complement sets as adding much functionality; they are mostly just a notational convenience. One thing they do add is a representation of the full set, the set containing everything, which is sometimes handy, being the identity element for the intersection operation.

Data type: complement-set

A representation of the complement of a normal, enumerated set. Subclass of set.

Complement sets are printed as a tilde (~) followed by the set they’re the complement of.

Function: complement-set? x

Returns true iff x is a complement set.

Method: complement (set)  s

Returns a complement-set whose complement is s.

(This is consistent with cl:complement, which complements a boolean function, because a set can be considered as a boolean function.)

Method: complement (complement-set)  cs

Returns the normal set of which cs is the complement.

Function: full-set

Returns the full set, the complement of the empty set.

Method: contains? (complement-set)  cs x
Method: with (complement-set)  cs x
Method: less (complement-set)  cs x
Method: union (complement-set complement-set)  cs1 cs2
Method: union (complement-set set)  cs1 s2
Method: union (set complement-set)  s1 cs2
Method: intersection (complement-set complement-set)  cs1 cs2
Method: intersection (complement-set set)  cs1 s2
Method: intersection (set complement-set)  s1 cs2
Method: union (complement-set complement-set)  cs1 cs2
Method: union (complement-set set)  cs1 s2
Method: union (set complement-set)  s1 cs2
Method: set-difference (complement-set complement-set)  cs1 cs2
Method: set-difference (complement-set set)  cs1 s2
Method: set-difference (set complement-set)  s1 cs2
Method: subset? (complement-set complement-set)  cs1 cs2
Method: subset? (complement-set set)  cs1 s2
Method: subset? (set complement-set)  s1 cs2
Method: disjoint? (complement-set complement-set)  cs1 cs2
Method: disjoint? (complement-set set)  cs1 s2
Method: disjoint? (set complement-set)  s1 cs2
Method: bag-product (bag complement-set)  b cs
Method: bag-product (complement-set bag)  cs b

The operations available on complement sets. (I’ve added the two bag-product methods because the full set is the identity value for the bag product operation: it contains every value with multiplicity 1.)