Sets and relations
Reading: Chapter 5 (72-93) from the text book
1
Sets
• We’ll look briefly at the main ideas of sets• Our intention is to introduce terminology &
notation that will be useful later• The term set means a collection of items• The items are called the elements of the set• A set can be described in 2 ways –
1. in enumerated form (i.e. as a list)2. in predicate form (i.e. using a property that
defines the elements of the set)2
Examples of Enumerated Sets
• the set of summer months is {June, July, August} note the use of braces (‘curly brackets’) for sets
• the set of positive even numbers less than 10 is {2, 4, 6, 8}
• the set of positive even numbers less than 100 is {2, 4, 6, 8, …, 98} – an ellipsis (3 dots) is used if there is a clear pattern
• the set of positive even numbers is {2, 4, 6, 8, …}
3
Examples of Sets in predicate form
• The set of positive even numbers less than 100 can be written in predicate form as {x: x is even and 0 < x < 100}• This definition is read as ‘the set of all x such that x is even and 0 < x < 100’• Sets are usually denoted by capital letters e.g. A = {2, 4, 6, 8}, B = {x: x is a pos. even no.}• The symbols ∈ and ∉ mean ‘is an element of’ and ‘is not an element of’, respectively• e.g. 6 ∈ A, 120 ∈ B, 7 ∉ A
4
Symbols for Special Sets
• Special symbols are used for certain sets of nos:N = set of natural numbers = {1, 2, 3, 4, …}J = set of integers = {…, –3, –2, –1, 0, 1, 2, 3,…}Q = set of rational nos = {x: x = m/n for some integers m and n with n ≠ 0}R = set of all real nos
∅ = the null set or empty set. It has no elements, & may be written as { } or even as {x: x = x + 1} (any predicate that is always false can be used)
5
The Universal Set
• The universal set, denoted by U, contains all elements that could be under discussion in a particular situation
• U changes according to circumstances• e.g. If we’re dealing with months of the year,
U = {January, February, March, …, December} If we’re dealing with numbers, U might be R (the set of all real nos)
6
Subsets, Set Operations andVenn Diagrams
• If A& B are sets so that every element of B is an element of A, B is a subset of A (written B ⊆ A)
• e.g. A = {1,2,3,4}, B = {1,3,4}, C = {4,5,6}. Then B ⊆ A, but C is not a subset of A.
• In a picture:
7
Venn Diagrams
• A picture such as in the previous slide is called a Venn diagram
• Venn diagrams were introduced by John Venn, who used them in his book Symbolic Logic (1881) to illustrate principles of logic
• Venn diagrams are easy to use for 2 or 3 sets.• For more than 3 sets, the diagrams become
quite complicated and are not so easy to use.
8
Properties of Sets
• Recall: If every element of B is an element of A, B is a subset of A, written as B ⊆ A• Thus, for any set A, it is true that A ⊆ A• Also, for any set A, it is true that ∅⊆ A i.e.we can’t find an element of ∅ which isn’t in A• Two sets A and B are equal if A ⊆ B and B ⊆ A
Thus 2 sets are equal if they have the same elts• So the order of listing elts is immaterial
e.g. {1, 2, 3} = {2, 1, 3} – & there’s no reason to list an elt more than once – e.g. {1, 2, 1} = {1, 2}
9
Set Operations• The intersection of 2 sets A and B is A ∩ B = {x: x ∈ A and x ∈ B}• 2 sets A and B are disjoint if A ∩ B = ∅ (i.e. if the
sets have no elements in common)• The union of 2 sets A and B is A ∪ B = {x: x ∈ A or x ∈ B}
where ‘or’ means the inclusive ‘or’ • The complement of a set A consists of all the
elements of the universal set that are not in A. i.e.
= {x : x ∈U and x ∉ A}A
10
Set Operations
• The difference of 2 sets A and B is A – B = {x: x ∈ A and x ∉ B}
A – B isshaded in red
• Note that A − B = A ∩• This can be shown using the defns of set operations, or by using Venn diagrams
B
11
Example
Suppose E = {a, b, c, d, e, f, g, h, i, j},A = {a, b, c, d, e, f, g}, B = {b, d, f, i, j},C = {a, c, f, j}. Find:
(i) A ∪ C(ii) A ∩ B(iii) A∩ C(iv) (B ∩ A) ∪ C(v) A (∪ C ∩ B)
12
Laws of Sets
Laws of Sets Name
AA
absorption
inverse
onannihilati
identitysMorgan’ de
vedistributi
eassociativ
ecommutativ
idempotent
complement double
A B) (A A
A A
A
A A
B A B AC) (A B) (A
C) (B A C) (B A
C B) (A
A B B A
A A A
U
UU
A B) (A A
A A
A
A UA
B A B AC) (A B) (A
C) (B A C) (B A
C B) (A
A B B A
A A A
13
Verifying and Using the Laws of Sets
• All the laws of sets can be verified• Another way of verifying the laws is to use Venn
diagrams• Example: Use Venn diagrams to illustrate the 2nd
de Morgan’s law for sets• The laws of sets can be used to simplify a given
set (just as we will use the laws of Algebra to simplify a given algebraic expression)
• Example: Use laws of sets to simplify A)BA( 14
The Power Set
• Suppose A = {a, b}. The subsets of A are ∅, {a}, {b} & {a, b}
• The set of these subsets is called the power set of A, denoted by P (A) i.e.
P(A) = { , {∅ a}, {b}, {a, b}}• Note that P (A) is a set whose elements are
themselves sets – i.e. it is a set of sets• Also note that A has 2 elements, & P (A) has 4
elements• Exercise: If A = {a, b, c}, write down P(A) 15
Cardinality of the Power Set• The cardinality of a finite set A is the no. of
elements in the set, written as | A |• Example: If A = {a, b, c}, then | A | = 3• Observe that A has 3 elements, & P(A) has 8
elements• This leads to the general observation: If A has n elements, then P(A) has 2n elements i.e. if | A | = n, then |P(A) | = 2n
• Then a set with n elements has 2n subsets16
Ordered Pairs
• When dealing with sets, the ordering of elements inthe set is immaterial – e.g. {2, 1, 4} = {1, 4, 2}
• Sometimes, though, order does matter e.g.: (i) a list of place-getters in a race, or a list offootball teams in order of leader position;
(ii) an ordered string of characters such as atax file no., password, credit card PIN or car reg. no.
• An ordered pair is a pair of elements in a particularorder, written as (a, b)
17
Ordered n-tuples• Thus the ordered pair (3, 5) is different to (5, 3)• Note the use of parentheses (‘round brackets’),
and not braces (‘curly brackets’) as for sets• If we have n elements, an ordered n-tuple is a
list of the n elements in a particular order – it iswritten as (x1, x2, x3,…, xn)
• Since order is important, the only way for (x1, x2, x3,…, xn) = (y1, y2, y3,…, yn) is if the 1st
elements are the same (i.e. x1 = y1), the 2nd
elements are the same (i.e. x2 = y2), and so on• So (1, 4, 5) ≠ (1, 5, 4) (but {1, 4, 5} = {1, 5, 4})
18
The Cartesian Product of 2 Sets• The Cartesian product of 2 sets A and B is A × B = {(x, y): x ∈ A and y ∈ B}
i.e. It is the set of all ordered pairs, where thefirst element is from A & the second elementis from B
• e.g. If A is the set of digits 0-9, & B is the set ofletters a-z, then (3, t) is in A × B, but (m, 7) is notin A × B – although it is in B × A
• e.g. If A = {1, 2, 3} & B = {p, q}, then A × B = {(x, y): x ∈ A and y ∈ B} = {(1, p), (1, q), (2, p), (2, q), (3, p), (3, q)} 19
The Cartesian Product of n Sets
• The Cartesian product of n sets A1, A2,…, An is A1 × A2 ×… × An =
{(x1, x2, x3,…, xn): x1 ∈ A1, x2 ∈ A2, …, xn ∈ An}• i.e. It is the set of all ordered n-tuples, where
the 1st elt is from A1, the 2nd elt is from A2,etc• e.g. A car reg. no. such as KCT454 can be
regarded as an ordered 6-tuple (K, C, T, 4, 5,4).• If L is the set of all letters, & D is the set of all
decimal digits, then the set of all possible carregistration nos is L × L × L × D × D × D 20
Cartesian Product of a Set with Itself
• The set A × A ×… × A (n times) is written as An
• e.g. If R is the set of real nos, then R2 is the set of all ordered pairs (x, y), where x& y are real nos – geometrically, R2 is the 2-dimensional plane
• Similarly, think of R3 as all points in 3-dim space
21
Cartesian Product of a Set with Itself
• e.g. {0, 1}2 = {(0, 0), (0, 1), (1, 0), (1, 1)}
• e.g. The elements of {0, 1}n are ordered n-tuplesin which each element is 0 or 1 – so a typicalelement of {0, 1}6 is (0, 1, 1, 1, 0, 1)
• Think of {0, 1}n as the set of all strings of n bits
• Note that L × L × L × D × D × D = L3 × D3
22
Computer Repn of Sets• To enable computers to handle sets, assume
the elements of the universal set U are listed in a definite order.
• Then, if |U| = n and A is a set, A is representedby a string of n bits b1b2b3…bn.
• Here bi is 1 if the ith elt of U is in A, and bi is 0if the ith elt of U is not in A.
23
Computer Repn of Sets
• Example: Suppose U = {a, b, c, d, e, f, g}. Find: (a) the representation of {d, f, a, g} as a bit string (b) the set represented by the bit string 0111011
• For sets defined w.r.t. the same universal set, theoperations of intersection, union & complementcan be carried out directly on the bit strings, without having to convert to the original sets.
24
Computer Repn of Sets• The bit string of A ∩ B has a 1 if the bit strings of
A & B both have a 1, & otherwise has a 0
• This process is termed a bitwise and operation
• The bit string of A ∪ B has a 0 if the bit strings of A & B both have a 0, & otherwise has a 1 (this is a bitwise or operation)
25
Set Operations Using Bit Strings
• The bit string for the complement of A isobtained from that of A by simply replacing 0with 1, and 1 with 0 (a bitwise not operation)
• Example: Suppose the bit strings of A& B are A: 0110110101, B: 1111001001 Find the bitstrings of A ∩ B, A ∪ B &
26
A
Relations• A binary relation occurs when we say
something about a property of an object relative to another object of the same type
• Example: The statement ‘Ali is taller than Yasir’ illustrates a relation
• The word ‘binary’ refers to the fact that two objects are compared – in future, we’ll omit this word and refer to just a ‘relation’ 27
Examples which Illustrate Relations
• Examples of statements from everyday life which illustrate relations:
‘Ali is the husband of Alia’‘Nadir is the sister of Nuha’‘Australia has a smaller population than
China’‘Discrete Maths is a prerequisite for
Encryption and Network Security’28
More Examples which Illustrate Relations
• Examples of statements from mathematics which illustrate relations:
‘12 is greater than 4’‘{a} is a subset of {a, b, c}’‘20 is divisible by 4’‘Line L1 is parallel to line L2’
29
Comments on the Examples• In each of the examples, a statement is made
about a pair of objects of the same type.
• The order of the objects is often important – e.g. it is true that ‘Australia has a smaller population than China’, but it is not true that ‘China has a smaller population than Australia’
• Thus relations involve 2 objects of the same type (i.e. from the same set), where order is important30
Definitions of a Relation• Informal Defn: A relation can be thought of as
a statement about ordered pairs (x, y) that are in A × A, where A is some set.
• This is the basic idea of a relation, although the formal definition looks a little different.
• Formal Defn: A (binary) relation on a set A is a subset R of A × A. We say that x & y are related iff (x, y) ∈ R. 31
Example• Consider the relation ‘is greater than’ on the
set A = {3, 5, 6, 8}.
• For any (x, y) ∈ A × A, either x is greater than y, and then x is related to y or x is not greater than y, and then x is not related to y.
• The set of the ordered pairs (x, y) ∈ A × A, for which x is related to y is given by: R = {(5, 3), (6, 3), (8, 3), (6, 3), (6, 5), (8, 6)} 32
Notation for a Relation
• In the previous example, we can state that x & y are related by writing (x, y) ∈ R.
• In practice, this is often written as xRy (read this as ‘x is related to y’).
• For the previous example, we can write ‘x > y’ instead of xRy to mean that x is related to y
33
Graphical Repn of a Relation
• Example: The reln ‘>’ on the set A = {3, 5, 6, 8} can be depicted using a graph. The elements of A are represented by dots, & if x is related to y, an arrow is drawn from x to y. The result is called a directed graph.
34
Matrix Repn of a Relation
• A relation can also be represented by a matrix (plural ‘matrices’) called the relation matrix.
• The entry in row x & column y is T if x is related to y, and is F otherwise.
• e.g. For ‘>’ on {3, 5, 6, 8}, the relation matrix is given by
35
Top Related