Cs5002 Lect4 Fall18 Notes Blank
Cs5002 Lect4 Fall18 Notes Blank
1
Lecture 4: September 27, 2018
Instructors: Adrienne Slaughter, Tamara Bonaci
Disclaimer: These notes have not been subjected to the usual scrutiny reserved for formal pub-
lications. They may be distributed outside this class only with the permission of the Instructor.
4.1 Overview
1. Sets
2. Set Operations
3. Cardinality of Sets
4. DeMorgan’s Law for Sets
5. Matrices
4.2 Introduction
4.4 Sets
A set is a group of objects, usually with some relationship or similar property. The objects in the
set are called elements or members of the set. A set contains its elements.
We use the symbol ∈ to indicate that an element is or is not in a set:
x ∈ A: x is in set A
x 6∈ A: x is not in set A
A set is described by either listing out the elements of the set in braces, or using set builder
notation.
4-1
4-2 Lecture 4: September 27, 2018
U
i
o
e V
a
u
The rectangle represents U , the . The universal set is the set that contains all objects
under consideration. In this example, U is the set of all letters, and the set V is the set of
vowels. Specific elements are represented by a point (labeled or not).
Subset
The set A is a subset of B if and only if every element of A is also an element of the set B.
We use the notation: A ⊆ B
A⊆B
B
A
Lecture 4: September 27, 2018 4-3
If A ⊆ B, then ∀x(x ∈ A → x ∈ B)
The null set ∅ is a subset of every set: To see that ∅ ⊆ S, see that every element in
is in .
Further, every set is a subset of itself.
Proper Subset
When A is a subset of B and A 6= B, we say that A is a proper subset of B, and write it:
A⊂B
A = {1, 2, 3}
B = {x : 0 < x ≤ 4}
⇒A⊂B
A : {a, b, c, d}
B : {a, b, c, d}
A ⊆ B (all elements in A are in B)
B ⊆ A (all elements in B are in A)
⇒A=B
Cardinality
Let S be a set. If there are n distinct elements in S (and n is an integer greater than or
equal to 0), S is a finite set, and n is the cardinality or S.
The cardinality of S is written |S|
Cardinality: Examples
Example: Let A be the set of odd positive integers less than 10. What’s |A|?
Answer:
4-4 Lecture 4: September 27, 2018
Ordered Pairs
A 2-tuple is called a ordered pair.
The ordered pair (a, b) equals the ordered pair (c, d) if and only if a = c and b = d.
(a, b) only equals (b, a) if a = b.
Cartesian Products
The Cartesian product of sets A and B (denoted A × B) is the set of all ordered pairs
(a, b) where a ∈ A and b ∈ B.
A × B = {(a, b)|a ∈ A ∧ b ∈ B}
Lecture 4: September 27, 2018 4-5
A : {a, b, c}
B : {1, 2, 3}
C : {blue, red, green}
⇒ A × B × C = {(a, 1, blue), (a, 1, red), (a, 1, green), (a, 2, blue) . . .}
The Cartesian product A × B × C consists of all ordered triples (a, b, c), where a ∈ A, b ∈
B, c ∈ C.
Union
Let A and B be sets. The union of the sets A and B, denoted A ∪ B is the set that contains
the elements in either A or in B, or in both.
A∪B
A ∪ B = {x|x ∈ A ∨ x ∈ B} (4.2)
A B
Example: {1, 2, 3, 4} ∪ {7, 8, 9} = ?
Answer:
Intersection
Let A and B be sets. The intersection of the sets A and B, denoted A ∩ B is the set that
contains the elements in both A and B.
A∩B
A ∩ B = {x|x ∈ A ∧ x ∈ B} (4.3)
A B
Example: {1, 2, 3, 4} ∩ {x : x ∈ N } = ?
Answer:
4-6 Lecture 4: September 27, 2018
Disjoint
Let A and B be sets. The two sets are disjoint if their intersection is the empty set.
A B
Cardinality of sets
Inclusion-Exclusion Principle
We frequently want too know how many items are in groups.
Note that |A| + |B| counts all the elements in only A once, and all the elements in only B
once. BUT, it counts the elements in A and B TWICE.
Therefore, we need to subtract the number of elements that are in A and B:
Complement of sets
The complement of a set A, denoted Ac is the set of elements that belong to U but which
do not belong to A: t
Ac
Ac = {x : x ∈ U, x 6∈ A} (4.5)
U : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
A : {2, 5, 8}
AC =
Difference of sets
The relative complement or difference of a set B with respect to A, denoted A \ B (said
A minus B) is the set of elements that belong to A but which do not belong to B.
Lecture 4: September 27, 2018 4-7
A\B
A \ B = {x : x ∈ A, x 6∈ B} (4.6)
A⊕B
A ⊕ B = (A ∪ B) \ (A ∩ B) (4.7)
A B
Example:
3
S
A
n
i=1 [
A1 ∪ A2 ∪ . . . ∪ An = Ai (4.8)
i=1
A1 A2
Example: A1 = {1, 2, 3, 4}; A2 =
A3 {7, 8, 9}, A3 = {4, 5, 6, 7} = ?
Answer:
3
T
A n
i=1 \
A1 ∩ A2 ∩ . . . ∩ An = Ai (4.9)
i=1
A1 A2
A3
Membership table
Just like we use truth tables for determining equality of logic statements, we can use mem-
bership tables to prove equality of sets.
1 is used to indicate that an element belongs to a set; 0 is used to indicate that an element
is not in that set.
Membership for Distributive Property
A B C B ∪ C A ∩ (B ∪ C) A ∩ B A ∩ C (A ∩ B) ∪ (A ∩ C)
1 1 1 1 1
1 1 0 1 0
1 0 1 0 1
1 0 0 0 0
DeMorgan’s Law
¬(p ∧ q) ≡ ¬p ∨ ¬q (4.10)
¬(p ∨ q) ≡ ¬p ∧ ¬q (4.11)
Set Problems
Example: Let A be the set of students who live within one mile of school, and B the set of
students who walks to campus from home. Describe each of these sets of students:
1. A∩B
2. A∪B
3. A−B
4. B−A
Answer:
1. The students who live within a mile of school and walk to campus (but not take the
bus).
2. The students who live within a mile of school (and walk or drive), and the students
who walk to school (no matter how far it is).
Lecture 4: September 27, 2018 4-9
3. The students who live within a mile of school but DON’T walk to school.
4. The students who walk to school but live further than a mile away.
Set Identities
Set Identities
Identity Name
A∪∅=A Identity laws
A∩U =A
A∪U =U Domination laws
A∩∅=∅
A∪A=A Idempotent laws
A∩A=A
(A) = A Complementation law
A∪B =B∪A Commutative laws
A∩B =B∩A
A ∪ (B ∪ C) = (A ∪ B) ∪ C Associative laws
A ∩ (B ∩ C) = (A ∩ B) ∩ C
A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) Distributive laws
A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
A∪B =A∩B De Morgan’s laws
A∩B =A∪B
2. Let E denote the set of even integers and O the set of odd integers. Z is the set of all
integers. Determine these sets:
(a) E ∪ O
(b) E ∩ O
(c) Z − E
(d) Z − O
3. Show that if A and B are sets, then A − (A − B) = A ∩ B.
4. Show that if A is a subset of B, then the powerset of A is a subset of the power set of B.
5. Show that symmetric difference follows the associative property using the following Venn
diagrams. That is, (A ⊕ B) ⊕ C = A ⊕ (B ⊕ C)
A B A B
C C
A B A B
C C
Lecture 4: September 27, 2018 4-11
4.6 Matrices
Matrices are used throughout discrete mathematics to express relationships between elements
in sets. In subsequent chapters we will use matrices in a wide variety of models. For instance,
matrices will be used in models of communications networks and transportation systems.
Many algorithms will be developed that use these matrix models. This section reviews
matrix arithmetic that will be used in these algorithms.
Example: Social network
Here’s something you might be familiar with: We start with a shape on the screen, and it
transforms over time. First it moves from one place to another, then it gets
Definition 1: Matrix
1 1
2 3 (4.12)
4 5
m=3 (4.13)
n=2 (4.14)
x0,0 x0,1 x0,2
x1,0 x1,1 x1,2 (4.15)
x2,0 x2,1 x2,2
(4.16)
What can we do with a matrix? Regardless of what is represented by the matrix, for different
reasons (and different applications) we need to manipulate matrices in different ways. We
can:
• Add matrices (of the same shape) (Matrix Addition)
• (Scalar Multiplication)
• Multiply matrices
• Transpose
• Determinant
4-12 Lecture 4: September 27, 2018
• Inverse
Properties matrices can have:
• Square
• Symmetric
• Column/Row (Vector)
5 4 3 0 15 30
3 3 3 + 5 20 35 = (4.18)
−1 −2 −3 10 25 35
0 15
5 4 3
+ 5 20 =??? (4.19)
3 3 3
10 25
0 15 30 x0,0 + y0,0 x0,1 + y0,1 x0,2 + y0,2
5 4 3
× 5 20 35 = x1,0 + y1,0 x1,1 + y1,1 x1,2 + y1,2 (4.20)
3 3 3
10 25 35 x2,0 + y2,0 x2,1 + y2,1 x2,2 + y2,2
0 15
5 4 3
× 5 20 = (4.21)
3 3 3
10 25
Lecture 4: September 27, 2018 4-13
(We know the final matrix will be 2 x 2, because A has 2 rows, B has 2 columns, and the
final matrix of a matrix multiplication has the same number of rows as A, and the same
number of cols as B)
1 1 1
0 0 1 (4.22)
1 0 1
10 y
4
P0
2
P
x
2 4 6 8 10
I have a point on a screen, and I want to move it to another place. Right now, I’m just
working with a point, but you could imagine that it’s a shape of some kind (a sprite!).
How do computers deal with this?
The point is represented by a matrix! To represent a change in the location of the point, we
apply what’s called a transformation, or specifically in this case, a translation.
If the point is originally located at (x, y), the new position is (x0 , y 0 ), where:
x0 = x + tx (4.23)
y 0 = y + ty (4.24)
4-14 Lecture 4: September 27, 2018
That is: the new x is the original x plus the change in the x-direction, and the new y is the
original y plus the change in the y-direction.
Here’s where matrices come in: we model the point as a column vector. The change is
what we call the translation vector, also modeled as a column vector. Therefore we get
something like this:
0
x1 x1 t
P = 0
,P = 0 ,T = x (4.25)
y1 yy ty
P0 = P + T (4.26)
0
x1 x t
0 = 1 + x (4.27)
yy y1 ty
x + tx
= 1 (4.28)
y1 + ty
=⇒ x01 = x1 + tx (4.29)
y10 = y1 + ty (4.30)
10 y
P 0 =?
6
4
P = (1, 2)
2
2 4 6 8 10
Lecture 4: September 27, 2018 4-15
P0 = P + T (4.31)
0
x1 1 3
= + (4.32)
yy0 2 4
4 x1 + tx
= (4.33)
6 y1 + ty
(4.34)
10
2 4 6 8 10
What’s trickier here is that I have more points. To move the entire rectangle, I need to do
what’s called a rigid body transformation. That’s a fancy way of saying that we want
the rectangle to keep it’s shape when we move it: it’s a rigid body. Now, we need to somehow
represent this rigid body, and I want to do it as a series of points:
1 2
1 4
+ tx ty (4.35)
4 4
4 2
(4.36)
What’s tx ? ty ?
Wait: can we do this? The
• First, I represented each point in a row, instead of a column. That gives me two
columns, an x- and y- column. It doesn’t matter what I do here: I could represent x’s
as a row, and y’s as another row, so we have a 2 × n matrix, where n is the number
4-16 Lecture 4: September 27, 2018
points we have. Or, I could just represent each point as a 1 × 2 matrix, and apply the
same transform to each point.
• Now, I can make T as arbitrarily long as I need it by just duplicating rows of T .
1 2 tx ty
1 4 tx
ty
4 + (4.37)
4 tx ty
4 2 tx ty
(4.38)
10
2 4 6 8 10
x0 = x · s x , y 0 = y · s y (4.39)
This means that to scale a polygon, we’ll multiple each vertex by the scaling factors sx
and sy . sx is the amount to scale in the horizontal direction, and sy is the amount to scale
in the vertical direction.
0
x sx 0 x
0 = · (4.40)
y 0 sy y
P0 = S · P (4.41)
Where does those 0s in the scaling matrix above come from? Let’s do the math:
Lecture 4: September 27, 2018 4-17
sx 0 x (sx · x + 0 · y)
· = (4.42)
0 sy y (0 · x + xy · y)
0 0
0 1
1
(4.43)
1
1 0
0 0 (0 · 4 + 0 · 0) (0 · 0 + 0 · 6)
0 1 4 0 (0 · 4 + 1 · 6) (0 · 0 + 0 · 6)
· = (4.44)
1 1 0 6 (1 · 4 + 1 · 0) (1 · 0 + 1 · 6)
1 0 (1 · 4 + 0 · 0) (1 · 0 + 0 · 6)
0 0
6 0
=
4 6
(4.45)
4 0
If we reconcile these final coordinates with the original figure, you see they correspond.
Composite Transforms: Scale & Translation
10
2 4 6 8 10
If we want to scale and translate, you can take the points, and first apply one transform, and
then the other. But, that’s not terribly efficient. We can do multiple transforms at once,
combining a scale and a translate:
4-18 Lecture 4: September 27, 2018
sx 0 tx
0 sy ty (4.46)
0 0 1
Okay, so what do we know? I claim that the above matrix applied to a rigid body will reflect
it around the x-axis. To do this, we multiply each point by the transform matrix. But, this
matrix is 3x3, and our points are 1x2. How do we deal with that?
Answer:
Instead of representing a point by a 2x1 matrix, we represent it by a 3x1 matrix:
x
y
1
The above figure depicts a translation of (2, 3), and a scaling of (3, 4).
0
x 4 0 2 x
y 0 = 0 3 3 · y
1 0 0 1 1
4 0 2 x
0 3 3 · y =
0 0 1 1 1
= (Substituting x = 1, y = 1)
1
(We know the final matrix will be 3 x 1, because A has 3 rows, B has 1 column, and the final
matrix of a matrix multiplication has the same number of rows as A, and the same number
of cols as B)
We can draw the conclusion that for each point in our shape, we have a formula for the new
location:
x0 = xsx + tx
y 0 = xsy + ty
Lecture 4: September 27, 2018 4-19
A · B · C = (A · B) · C = A · (B · C)
A · B 6= B · A
Reflection
10
2 4 6 8 10
−5
−10
To reflect an object, we transform to produce a mirror image. The picture above shows a
reflection around the x-axis, which is the axis of reflection.
The transform for reflecting around the x-axis is below:
0
x 1 0 0 x
y 0 = 0 −1 0 · y (4.47)
1 0 0 1 1
−1 0 0
0 1 0 (4.48)
0 0 1
4.7 Summary
Today, we talked about sets and matrices. When it comes to sets, the biggest thing is figuring
out the size of a set. We use sets of known sizes to help us determine the sizes of other sets:
4-20 Lecture 4: September 27, 2018
Is that other set bigger than, smaller than, or the same size as this set? Now that we’ve
talked about sets, you can likely see their direct application to logic and functions. In fact,
set theory arose out of trying to reason about reasoning, that is what logic was.
We also talked about matrices. I used computer graphics to motivate our matrix manipula-
tion exercises. In addition to learning about matrices, you learned a little bit about graphics
as well!