The union and intersection set operations were introduced in a previous post using two sets, \(a\) and \(b\). These set operations can be generalized to accept any number of sets.
Arbitrary Set Unions Operation
Consider a set of infinitely many sets:
It would be very tedious and unnecessary to repeat the union statement repeatedly for any non-trivial amount of sets, for example, the first few unions would be written as:
Thus a more general operation for performing unions is needed. This operation is denoted by the ⋃ symbol. For example, the set \(A\) above and the desired unions of the member sets can be generalized to the following using the new notation:
We can then state the following definition: For a set \(A\), the union ⋃\(A\) of \(A\) is defined by:
For example, consider the three sets:
The union of the three sets is written as:
Recalling our union axiom from a previous post, the union axiom states for two sets \(A\) and \(B\), there is a set whose members consist entirely of those belonging to sets \(A\) or \(B\), or both. More formally, the union axiom is stated as:
As we are now dealing with an arbitrary amount of sets, we need an updated version of the union axiom to account for the change.
Restating the union axiom:
For any set \(A\), there exists a set \(B\) whose members are the same elements of the elements of \(A\). Stated more formally:
The definition of ⋃\(A\) can be stated as:
For example, we can demonstrate the updated axiom with the union of four sets \({a, b, c, d}\):
We can implement the set operation for an arbitrary amount of sets by expanding upon the function we wrote previously.
set.unions <- function(a, b, ...) {
u <- a
for (i in 1:length(b)) {
if (!(b[i] %in% u)) {
u <- append(u, b[i])
}
}
s <- list(...)
for (i in s) {
for (j in i) {
if (!(j %in% u)) {
u <- append(u, j)
}
}
}
return(u)
}
Perform the set union operation of four sets:
a <- c(1,2,3)
b <- c(3,4,5)
c <- c(1,4,6)
d <- c(2,5,7)
set.unions(a, b, c, d)
## [1] 1 2 3 4 5 6 7
Intersections of an Arbitrary Number of Sets
The intersection set operation can also be generalized to any number of sets. Consider the previous set containing an infinite number of sets.
As before, writing out all the intersections would be tedious and not elegant. The intersection can instead be written as:
As before in our previous example of set intersections, there is no need for a separate axiom for intersections, unlike unions. Instead, we can state the following theorem, for a nonempty set \(A\), a set \(B\) exists that such for any element \(x\):
Consider the following four sets:
The intersection of the sets is written as:
We can write another function to implement the set intersection operation given any number of sets.
set.intersections <- function(a, b, ...) {
intersect <- vector()
for (i in a) {
if (i %in% b) {
intersect <- append(intersect, i)
}
}
s <- list(...)
for (i in s) {
for (j in i) {
if (j %in% intersect) {
intersect <- append(intersect, j)
}
}
}
intersect <- unique(intersect)
return(intersect)
}
Perform set intersections of the four sets specified earlier.
a <- c(1,2,3,5)
b <- c(1,3,5)
c <- c(1,4,5,3)
d <- c(2,5,1,3)
set.intersections(a, b, c, d)
## [1] 1 3 5
References
Enderton, H. (1977). Elements of set theory (1st ed.). New York: Academic Press.