2 Basic Structures: Sets, Functions,Sequences, Sums, and Matrices
2.2 Set Operations
2.2.4 Computer Representation of Sets
i=1
Ai.
Similarly, the intersection of these sets is denoted by
A1∩ A2∩⋯ ∩ An∩⋯ =
⋂∞ i=1
Ai.
More generally, when I is a set, the notations ⋂
i∈IAi and ⋃
i∈IAi are used to denote the intersection and union of the sets Ai for i ∈ I, respectively. Note that we have⋂
i∈IAi= {x ∣ ∀i ∈ I (x ∈ Ai)} and⋃
i∈IAi= {x ∣ ∃i ∈ I (x ∈ Ai)}.
EXAMPLE 17 Suppose that Ai= {1, 2, 3, … , i} for i = 1, 2, 3, … . Then,
⋃∞ i=1
Ai=
⋃∞ i=1
{1, 2, 3, … , i} = {1, 2, 3, …} = Z+
and
⋂∞ i=1
Ai=
⋂∞ i=1
{1, 2, 3, … , i} = {1}.
To see that the union of these sets is the set of positive integers, note that every positive integer n is in at least one of the sets, because it belongs to An = {1, 2, … , n}, and every element of the sets in the union is a positive integer. To see that the intersection of these sets is the set {1}, note that the only element that belongs to all the sets A1, A2, … is 1. To see this note that
A1 = {1} and 1 ∈ Aifor i = 1, 2, ….
◂
2.2.4 Computer Representation of Sets
There are various ways to represent sets using a computer. One method is to store the elements of the set in an unordered fashion. However, if this is done, the operations of computing the union, intersection, or difference of two sets would be time consuming, because each of these operations would require a large amount of searching for elements. We will present a method for storing elements using an arbitrary ordering of the elements of the universal set. This method of representing sets makes computing combinations of sets easy.
Assume that the universal set U is finite (and of reasonable size so that the number of elements of U is not larger than the memory size of the computer being used). First, specify an arbitrary ordering of the elements of U, for instance a1, a2, … , an. Represent a subset A of U with the bit string of length n, where the ith bit in this string is 1 if aibelongs to A and is 0 if ai does not belong to A. Example 18 illustrates this technique.
EXAMPLE 18 Let U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, and the ordering of elements of U has the elements in in-creasing order; that is, ai= i. What bit strings represent the subset of all odd integers in U, the subset of all even integers in U, and the subset of integers not exceeding 5 in U?
Solution:The bit string that represents the set of odd integers in U, namely, {1, 3, 5, 7, 9}, has a one bit in the first, third, fifth, seventh, and ninth positions, and a zero elsewhere. It is
10 1010 1010.
(We have split this bit string of length ten into blocks of length four for easy reading.) Similarly, we represent the subset of all even integers in U, namely, {2, 4, 6, 8, 10}, by the string
01 0101 0101.
The set of all integers in U that do not exceed 5, namely, {1, 2, 3, 4, 5}, is represented by the string
11 1110 0000.
◂
Using bit strings to represent sets, it is easy to find complements of sets and unions, inter-sections, and differences of sets. To find the bit string for the complement of a set from the bit string for that set, we simply change each 1 to a 0 and each 0 to 1, because x ∈ A if and only if x ∉ A. Note that this operation corresponds to taking the negation of each bit when we associate a bit with a truth value—with 1 representing true and 0 representing false.
EXAMPLE 19 We have seen that the bit string for the set {1, 3, 5, 7, 9} (with universal set {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) is
10 1010 1010.
What is the bit string for the complement of this set?
Solution:The bit string for the complement of this set is obtained by replacing 0s with 1s and vice versa. This yields the string
01 0101 0101,
which corresponds to the set {2, 4, 6, 8, 10}.
◂
To obtain the bit string for the union and intersection of two sets we perform bitwise Boolean operations on the bit strings representing the two sets. The bit in the ith position of the bit string of the union is 1 if either of the bits in the ith position in the two strings is 1 (or both are 1), and is 0 when both bits are 0. Hence, the bit string for the union is the bitwise OR of the bit strings for the two sets. The bit in the ith position of the bit string of the intersection is 1 when the bits in the corresponding position in the two strings are both 1, and is 0 when either of the two bits is 0 (or both are). Hence, the bit string for the intersection is the bitwise AND of the bit strings for the two sets.
EXAMPLE 20 The bit strings for the sets {1, 2, 3, 4, 5} and {1, 3, 5, 7, 9} are 11 1110 0000 and 10 1010 1010, respectively. Use bit strings to find the union and intersection of these sets.
Solution:The bit string for the union of these sets is 11 1110 0000 ∨ 10 1010 1010 = 11 1110 1010,
which corresponds to the set {1, 2, 3, 4, 5, 7, 9}. The bit string for the intersection of these sets is
11 1110 0000 ∧ 10 1010 1010 = 10 1010 0000,
which corresponds to the set {1, 3, 5}.
◂
2.2.5 Multisets
Sometimes the number of times that an element occurs in an unordered collection matters. A multiset(short for multiple-membership set) is an unordered collection of elements where an element can occur as a member more than once. We can use the same notation for a multiset as we do for a set, but each element is listed the number of times it occurs. (Recall that in a set, an element either belongs to a set or it does not. Listing it more than once does not affect the membership of this element in the set.) So, the multiset denoted by {a, a, a, b, b} is the multiset that contains the element a thrice and the element b twice. When we use this notation, it must be clear that we are working with multisets and not ordinary sets. We can avoid this ambiguity by using an alternate notation for multisets. The notation {m1⋅ a1, m2⋅ a2, … , mr⋅ ar} denotes the multiset with element a1 occurring m1 times, element a2 occurring m2 times, and so on.
The numbers mi, i = 1, 2, … , r, are called the multiplicities of the elements ai, i = 1, 2, … , r.
(Elements not in a multiset are assigned 0 as their multiplicity in this set.) The cardinality of a multiset is defined to be the sum of the multiplicities of its elements. The word multiset was introduced by Nicolaas Govert de Bruijn in the 1970s, but the concept dates back to the 12th century work of the Indian mathematician Bhaskaracharya.
Let P and Q be multisets. The union of the multisets P and Q is the multiset in which the multiplicity of an element is the maximum of its multiplicities in P and Q. The intersection of P and Q is the multiset in which the multiplicity of an element is the minimum of its multiplicities in P and Q. The difference of P and Q is the multiset in which the multiplicity of an element is the multiplicity of the element in P less its multiplicity in Q unless this difference is negative, in which case the multiplicity is 0. The sum of P and Q is the multiset in which the multiplic-ity of an element is the sum of multiplicities in P and Q. The union, intersection, and differ-ence of P and Q are denoted by P ∪ Q, P ∩ Q, and P − Q, respectively (where these operations should not be confused with the analogous operations for sets). The sum of P and Q is denoted by P + Q.
EXAMPLE 21 Suppose that P and Q are the multisets {4⋅ a, 1 ⋅ b, 3 ⋅ c} and {3 ⋅ a, 4 ⋅ b, 2 ⋅ d}, respectively.
Find P ∪ Q, P ∩ Q, P − Q, and P + Q.
Solution:We have
P ∪ Q = {max(4, 3)⋅ a, max(1, 4) ⋅ b, max(3, 0) ⋅ c, max(0, 2) ⋅ d}
= {4⋅ a, 4 ⋅ b, 3 ⋅ c, 2 ⋅ d},
P ∩ Q = {min(4, 3)⋅ a, min(1, 4) ⋅ b, min(3, 0) ⋅ c, min(0, 2) ⋅ d}
= {3⋅ a, 1 ⋅ b, 0 ⋅ c, 0 ⋅ d} = {3 ⋅ a, 1 ⋅ b},
Dinodia Photos/Alamyc Stock Photo
BHASKARACHARYA (1114–1185) Bhaskaracharya was born in Bijapur in the Indian state of Karnataka.
(Bhaskaracharya’s name was actually Bhaskara, but the title Acharya, which means teacher, was added honorif-Links
ically.) His father was a well-known scholar and a famous astrologer. Bhaskaracharya was head of the astronom-ical observatory at Ujjain, the leading Indian mathematastronom-ical center of the day. He is considered to be the greatest mathematician of medieval India. Bhaskaracharya made discoveries in many parts of mathematics, including geometry, plane and spherical trigonometry, algebra, number theory, and combinatorics. Bhaskaracharya de-scribed the principles of differential calculus, which he applied to astronomical problems, predating the works of Newton and Leibniz by more than 500 years. In number theory he made many discoveries about Diophantine equations, the study of the solution in integers of equations, which were rediscovered more than 600 years later.
His greatest work is the Crown of Treatises (Siddhanta Shiromani), which includes four main parts, covering arithmetic, algebra, mathematics of the planets, and spheres.
P − Q = {max(4 − 3, 0)⋅ a, max(1 − 4, 0) ⋅ b, max(3 − 0, 0) ⋅ c, max(0 − 2, 0) ⋅ d}
= {1⋅ a, 0 ⋅ b, 3 ⋅ c, 0 ⋅ d} = {1 ⋅ a, 3 ⋅ c}, and P + Q = {(4 + 3)⋅ a, (1 + 4) ⋅ b, (3 + 0) ⋅ c, (0 + 2) ⋅ d}
= {7⋅ a, 5 ⋅ b, 3 ⋅ c, 2 ⋅ d}.
◂
Exercises
1. Let A be the set of students who live within one mile of school and let B be the set of students who walk to classes.
Describe the students in each of these sets.
a) A∩ B b) A∪ B
c) A− B d) B− A
2. Suppose that A is the set of sophomores at your school and B is the set of students in discrete mathematics at your school. Express each of these sets in terms of A and B.
a) the set of sophomores taking discrete mathematics in your school
b) the set of sophomores at your school who are not tak-ing discrete mathematics
c) the set of students at your school who either are sophomores or are taking discrete mathematics d) the set of students at your school who either are not
sophomores or are not taking discrete mathematics 3. Let A = {1, 2, 3, 4, 5} and B = {0, 3, 6}. Find
In Exercises 5–10 assume that A is a subset of some underly-ing universal set U.
5. Prove the complementation law in Table 1 by showing that A = A.
6. Prove the identity laws in Table 1 by showing that
a) A∪ ∅ = A. b) A∩ U = A.
7. Prove the domination laws in Table 1 by showing that
a) A∪ U = U. b) A∩ ∅ = ∅.
8. Prove the idempotent laws in Table 1 by showing that
a) A∪ A = A. b) A∩ A = A.
9. Prove the complement laws in Table 1 by showing that a) A∪ A = U. b) A∩ A = ∅.
10. Show that
a) A− ∅ = A. b) ∅ − A = ∅.
11. Let A and B be sets. Prove the commutative laws from Table 1 by showing that
a) A∪ B = B ∪ A.
b) A∩ B = B ∩ A.
12.Prove the first absorption law from Table 1 by showing that if A and B are sets, then A ∪ (A ∩ B) = A.
13. Prove the second absorption law from Table 1 by show-ing that if A and B are sets, then A ∩ (A ∪ B) = A.
14. Find the sets A and B if A − B = {1, 5, 7, 8}, B − A = {2, 10}, and A ∩ B = {3, 6, 9}.
15. Prove the second De Morgan law in Table 1 by showing that if A and B are sets, then A ∪ B = A ∩ B
a) by showing each side is a subset of the other side.
b) using a membership table.
18. Given sets A and B in a universe U, draw the Venn dia-grams of each of these sets.
a) A→ B = {x ∈ U | x ∈ A → x ∈ B}
b) A↔ B = {x ∈ U | x ∈ A ↔ x ∈ B}
19. Show that if A, B, and C are sets, then A ∩ B ∩ C = A ∪ B ∪ C
a) by showing each side is a subset of the other side.
b) using a membership table.
23. Prove the first associative law from Table 1 by show-ing that if A, B, and C are sets, then A ∪ (B ∪ C) = (A ∪ B) ∪ C.
24.Prove the second associative law from Table 1 by show-ing that if A, B, and C are sets, then A ∩ (B ∩ C) = (A ∩ B) ∩ C.
25.Prove the first distributive law from Table 1 by showing that if A, B, and C are sets, then A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C).
26. Let A, B, and C be sets. Show that (A − B) − C =
28. Draw the Venn diagrams for each of these combinations of the sets A, B, and C.
a) A∩ (B ∪ C) b) A ∩ B ∩ C
c) (A − B) ∪ (A − C) ∪ (B − C)
29. Draw the Venn diagrams for each of these combinations of the sets A, B, and C.
a) A∩ (B − C) b) (A ∩ B) ∪ (A ∩ C) c) (A ∩ B) ∪ (A ∩ C)
30. Draw the Venn diagrams for each of these combinations of the sets A, B, C, and D.
33. Let A and B be subsets of a universal set U. Show that A⊆ B if and only if B ⊆ A.
34. Let A, B, and C be sets. Use the the identity A − B = A ∩ B, which holds for any sets A and B, and the identities from Table 1 to show that (A − B) ∩ (B − C) ∩ (A − C)
= ∅.
35. Let A, B, and C be sets. Use the identities in Table 1 to show that (A ∪ B) ∩ (B ∪ C) ∩ (A ∪ C) = A ∩ B ∩ C.
36. Prove or disprove that for all sets A, B, and C, we have a) A× (B ∪ C) = (A × B) ∪ (A × C).
b) A× (B ∩ C) = (A × B) ∩ (A × C).
37. Prove or disprove that for all sets A, B, and C, we have a) A× (B − C) = (A × B) − (A × C).
b) A × (B ∪ C) = A × (B ∪ C).
The symmetric difference of A and B, denoted by A⊕ B, is the set containing those elements in either A or B, but not in both A and B.
38. Find the symmetric difference of {1, 3, 5} and {1, 2, 3}.
39. Find the symmetric difference of the set of computer sci-ence majors at a school and the set of mathematics majors at this school.
40. Draw a Venn diagram for the symmetric difference of the sets A and B.
41. Show that A⊕ B = (A ∪ B) − (A ∩ B).
42. Show that A⊕ B = (A − B) ∪ (B − A).
43. Show that if A is a subset of a universal set U, then
a) A⊕ A = ∅. b) A⊕ ∅ = A.
c) A⊕ U = A. d) A⊕ A = U.
44. Show that if A and B are sets, then
a) A⊕ B = B ⊕ A. b) (A⊕ B) ⊕ B = A.
45. What can you say about the sets A and B if A⊕ B = A?
∗46. Determine whether the symmetric difference is associa-tive; that is, if A, B, and C are sets, does it follow that
51. Show that if A is an infinite set, then whenever B is a set, A ∪ B is also an infinite set.
∗52. Show that if A, B, and C are sets, then
|A ∪ B ∪ C| = |A| + |B| + |C| − |A ∩ B|
−|A ∩ C| − |B ∩ C| + |A ∩ B ∩ C|.
(This is a special case of the inclusion–exclusion princi-ple, which will be studied in Chapter 8.)
53. Let Ai= {1, 2, 3, … , i} for i = 1, 2, 3,. … Find
55. Let Aibe the set of all nonempty bit strings (that is, bit strings of length at least one) of length not exceeding i.
Find
i=1Aiif for every positive integer i, a) Ai= {i, i + 1, i + 2, …}.
i=1Aiif for every positive integer i, a) Ai= {−i, −i + 1, … , −1, 0, 1, … , i − 1, i}. strings where the ith bit in the string is 1 if i is in the set and 0 otherwise.
a) {3, 4, 5}
b) {1, 3, 6, 10}
c) {2, 3, 4, 7, 8, 9}
59. Using the same universal set as in the last exercise, find the set specified by each of these bit strings.
a) 11 1100 1111 b) 01 0111 1000 c) 10 0000 0001
60. What subsets of a finite universal set do these bit strings represent?
a) the string with all zeros b) the string with all ones
61. What is the bit string corresponding to the difference of two sets?
62. What is the bit string corresponding to the symmetric dif-ference of two sets?
63. Show how bitwise operations on bit strings can be used to find these combinations of A = {a, b, c, d, e}, B = {b, c, d, g, p, t, v}, C = {c, e, i, o, u, x, y, z}, and D = {d, e, h, i, n, o, t, u, x, y}.
a) A∪ B b) A∩ B
c) (A ∪ D) ∩ (B ∪ C) d) A∪ B ∪ C ∪ D
64.How can the union and intersection of n sets that all are subsets of the universal set U be found using bit strings?
The successor of the set A is the set A ∪ {A}.
65.Find the successors of the following sets.
a) {1, 2, 3} b) ∅
c) {∅} d) {∅, {∅}}
66.How many elements does the successor of a set with n elements have? state-ments are true and which are false, where all sets shown are ordinary sets, and not multisets. Explain each answer.
a) {a, a} ∪ {a, a, a} = {a, a, a, a, a}
b) {a, a} ∪ {a, a, a} = {a}
c) {a, a} ∩ {a, a, a} = {a, a}
d) {a, a} ∩ {a, a, a} = {a}
e) {a, a, a} − {a, a} = {a}
69.Answer the same questions as posed in Exercise 68 where all sets are multisets, and not ordinary sets.
70.Suppose that A is the multiset that has as its elements the types of computer equipment needed by one depart-ment of a university and the multiplicities are the num-ber of pieces of each type needed, and B is the analogous multiset for a second department of the university. For instance, A could be the multiset {107⋅ personal comput-ers, 44⋅ routers, 6 ⋅ servers} and B could be the multiset {14⋅ personal computers, 6 ⋅ routers, 2 ⋅ mainframes}.
a) What combination of A and B represents the equip-ment the university should buy assuming both depart-ments use the same equipment?
b) What combination of A and B represents the equip-ment that will be used by both departequip-ments if both departments use the same equipment?
c) What combination of A and B represents the equip-ment that the second departequip-ment uses, but the first de-partment does not, if both dede-partments use the same equipment?
d) What combination of A and B represents the equip-ment that the university should purchase if the depart-ments do not share equipment?
The Jaccard similarity J(A, B) of the finite sets A and B is J(A, B) =|A ∩ B|∕|A ∪ B|, with J(∅, ∅) = 1. The
72. Prove that each of the properties in parts (a)–(d) holds whenever A and B are finite sets.
a) J(A, A) = 1 and dJ(A, A) = 0 triangle inequalityand together with parts (a), (b), and (c) implies that dJ is a metric.)
Fuzzy sets are used in artificial intelligence. Each element in the universal set U has a degree of membership, which is a real number between 0 and 1 (including 0 and 1), in a fuzzy set S. The fuzzy set S is denoted by listing the elements
Links with their degrees of membership (elements with 0 degree of membership are not listed). For instance, we write {0.6 Alice, 0.9 Brian, 0.4 Fred, 0.1 Oscar, 0.5 Rita} for the set F (of fa-mous people) to indicate that Alice has a 0.6 degree of mem-bership in F, Brian has a 0.9 degree of memmem-bership in F, Fred has a 0.4 degree of membership in F, Oscar has a 0.1 degree of membership in F, and Rita has a 0.5 degree of membership in F (so that Brian is the most famous and Oscar is the least famous of these people). Also suppose that R is the set of rich people with R = {0.4 Alice, 0.8 Brian, 0.2 Fred, 0.9 Oscar, 0.7 Rita}.
73. The complement of a fuzzy set S is the set S, with the