Complement (set theory)
When all sets under consideration are considered to be subsets of a given set U, the absolute complement of A is the set of elements in U that are not in A.
The relative complement of A with respect to a set B, also termed the set difference of B and A, written B \ A, is the set of elements in B that are not in A.
If A is a set, then the absolute complement of A (or simply the complement of A) is the set of elements not in A (within a larger set that is implicitly defined). In other words, let U be a set that contains all the elements under study; if there is no need to mention U, either because it has been previously specified, or it is obvious and unique, then the absolute complement of A is the relative complement of A in U:
Let A and B be two sets in a universe U. The following identities capture important properties of absolute complements:
The relative complement of A in B is denoted B ∖ A according to the ISO 31-11 standard. It is sometimes written B − A, but this notation is ambiguous, as in some contexts it can be interpreted as the set of all elements b − a, where b is taken from B and a from A.
Let A, B, and C be three sets. The following identities capture notable properties of relative complements:
Here, R is often viewed as a logical matrix with rows representing the elements of X, and columns elements of Y. The truth of aRb corresponds to 1 in row a, column b. Producing the complementary relation to R then corresponds to switching all 1s to 0s, and 0s to 1s for the logical matrix of the complement.
Some programming languages have sets among their builtin data structures. Such a data structure behaves as a finite set, that is, it consists of a finite number of data that are not specifically ordered, and may thus be considered as the elements of a set. In some cases, the elements are not necessary distinct, and the data structure codes multisets rather than sets. These programming languages have operators or functions for computing the complement and the set differences.
These operators may generally be applied also to data structures that are not really mathematical sets, such as ordered lists or arrays. It follows that some programming languages may have a function called
set_difference, even if they do not have any data structure for sets.