1.3: Set Operations
Terminology
Just as there are arithmetic operations on numbers, there are set operations on sets.
The set \(C\) is the union of the sets \(A\) and \(B\), denoted \(A \cup B\), if and only if \(C=\{ x | x \in A \mbox{ or } x \in B \}\).
Consider \(A=\{a,l,k,s\}\) and \(B=\{a,c,l,k\}\). \(A \cup B = \{a,c,l,k,s \}\) because \(a \in A\text{,}\) \(c \in B\text{,}\) \(l \in A\text{,}\) \(k \in A\text{,}\) and \(s \in B\text{.}\) Note it does not matter if we say because \(a \in A\) or because \(a \in B\text{.}\) This is further discussed in Section 2.1
Checkpoint \(\PageIndex{3}\) Compare/Contrast.
Union can be thought of as taking the elements of the first set and adding any elements of the second set that are different. Our question is how does union differ from addition ?
- ►Hint
-
Add texts here. Do not delete this text first. Try unions of \(A=\{1,2,3\}\) with the following sets \(B_1=\{4,5,7\}\text{,}\) \(B_2=\{3,4,5\}\text{,}\) and \(B_3=\{2,3\}\text{.}\)
The set \(C\) is the intersection of the sets \(A\) and \(B\), denoted \(A \cap B\), if and only if \(C=\{ x | x \in A \mbox{ and } x \in B \}\).
Watch the video in Figure 1.3.5 demonstrating reading the set intersection definition twice. The first time think about what set intersection is. The second time think about how it illustrates reading and understanding a definition.
Figure \(\PageIndex{5}\): Understanding the set intersection definition
The set \(C\) is the difference between the sets \(A\) and \(B\), denoted \(A-B\), if and only if \(C=\{ x | x \in A \mbox{ but } x \not\in B \}\).
Checkpoint \(\PageIndex{7}\) Compare/Contrast.
Just as we considered how union is like addition we can compare and contrast set difference with subtraction .
- ►Hint
-
Add texts here. Do not delete this text first. Try the set difference of \(A=\{1,2,3\}\) with the following sets \(B_3=\{2,3\}\), \(B_2=\{3,4,5\}\), and \(B_1=\{4,5,7\}\).
A programmer must consider how to implement an operation like set difference.
(a) Find \(A-B\) for \(A=\{1,3,5,7,9\}\) and \(B=\{1,3,9\}\)
(b) Set difference must remove from \(A\) every element in \(B\). Consider the following psuedo-code.
for x in A do for y in B do if y==x then remove(A,x) exit inner for loop end if end for end for
How many times will the comparison (
if x==y
line) be run for these sets \(A\) and \(B\).
(c) If the psuedo-code algorithm were reversed so the outside loop were for \(B\) and the inside loop for \(A\) would it change the number of comparisons?
In many circumstance there is a universal set that is part of the context for a problem. It may or may not be explicitly stated. For example the set of all integers may be the universal set for discussion of even and odd numbers.
The set \(C\) is the complement of the set \(A\) with respect to the universal set \(U\), denoted \(\neg A\) or \(\overline{A}\), if and only if \(C=U-A\).
The set \(P\) is the
power set
of the set \(A\), denoted \(P(A)\) or \(2^A\), if and only if \(P\) is the set of all subsets of
\(A\).
For example if \(A=\{0,1\}\) then \(P(A)=\{ \emptyset, \{0\}, \{1\}, \{0,1\}\}.\)
Checkpoint \(\PageIndex{11}\). Developing Power Sets. Power sets are sets. This means they are unordered. However, to generate them it helps us list all subsets if we impose some convenient order. The following suggest parts of a heuristic for listing elements of power sets. We consider the power set of \(S=\{a,b,c\}\text{.}\)
(a) There are subsets of \(S\) of size 0,1,2, and 3. What is the only subset of size 0? What is the only subset of size 3?
(b) List all subsets of size 1.
(c) List all subsets of size 2.
(d) There are an equal number of subsets of size 1 and size 2 for \(S\text{.}\) Find a logical correspondence between the subsets of size 1 and size 2 (pair each subset of size 1 with a subset of size 2).
(e) In general for a set of size \(n\) how could one generate all subsets? Note the steps above only suggests two parts of an algorithm.
The set \(C\) is the Cartesian product of the sets \(A\) and \(B,\) denoted \(A \times B,\) if and only if \(C=\{(a,b) | a \in A \mbox{ and } b \in B. \}.\)
For example if \(A=\{0,1\}\) and \(B=\{a,b\}\) then \(A \times B =\) \(\{(0,a), (0,b), (1,a),\) \((1,b)\}.\)
Note for a set \(A\) and positive integer \(n \ge 1\) we use the notation \(A^n\) to mean \(n\) copies of \(A\) in a Cartesian product. For example, \(A^3 = A \times A \times A\text{.}\)
We define the size of a finite set \(A\text{,}\) denote \(|A|\) to be the number of elements it contains.
For example if \(A=\{a,b,c\}\) then \(|A|=3.\) There are ways to define the size of infinite sets, but those must wait for later classes.
Checkpoint \(\PageIndex{14}\).
WeBWork: http://aholiab.uaa.alaska.edu/webwor...VU1FTlQoKTs%3D
1.3.2 Practice
Checkpoint \(\PageIndex{16}\) Identify the following in the diagram above.
- \(\displaystyle A \cup B\)
- \(\displaystyle A \cap B\)
- \(\displaystyle A-B\)
- \(\displaystyle B-A\)
- \(\displaystyle \neg A\)
- \(\displaystyle \neg B\)
Checkpoint \(\PageIndex{17}\) Calculate the following for \(A=\{0,1,2\}\) and \(B=\{0,1\}.\)
- \(\displaystyle P(A)\)
- \(\displaystyle A \times B\)
- \(\displaystyle B \times A\)
- \(\displaystyle A-B\)
- \(\displaystyle B-A\)
Checkpoint 1\(\PageIndex{18}\) Perform the set operations indicated on the sets below. The universal set is all integers.
- \(A=\{n | n=2k \) for some integer \(k\}\)
- \(B=\{n | n=5k \) for some integer \(k\}\)
- \(C=\{n | n=6k \) for some integer \(k\}\)
- \(D=\{n | n=10k \) for some integer \(k \}\)
- \(\displaystyle A \cup B\)
- \(\displaystyle A \cap B\)
- \(\displaystyle C \cap D\)
- \(\displaystyle A-B\)
- \(\displaystyle B-A\)
- \(\displaystyle \neg A\)
- \(\displaystyle \neg B\)