0% found this document useful (0 votes)
76 views

Cs5002 Lect4 Fall18 Notes Blank

Sets and matrices were discussed. Some key points: 1. A set is a collection of distinct objects. Sets can be defined by listing elements or using set builder notation. Special sets include N, Z, R. 2. Set operations include union, intersection, complement, difference, and symmetric difference. The inclusion-exclusion principle relates the sizes of unions and intersections. 3. A matrix is a rectangular array of numbers or other mathematical objects. Matrices have rows and columns and can be used to represent linear systems of equations.

Uploaded by

Ruby Poddar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

Cs5002 Lect4 Fall18 Notes Blank

Sets and matrices were discussed. Some key points: 1. A set is a collection of distinct objects. Sets can be defined by listing elements or using set builder notation. Special sets include N, Z, R. 2. Set operations include union, intersection, complement, difference, and symmetric difference. The inclusion-exclusion principle relates the sizes of unions and intersections. 3. A matrix is a rectangular array of numbers or other mathematical objects. Matrices have rows and columns and can be used to represent linear systems of equations.

Uploaded by

Ruby Poddar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

CS 5002: Discrete Structures Fall 2018

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.

Sets and Matrices


Readings for this week:
Rosen, Chapter 2.1, 2.2, 2.5, 2.6
Sets, Set Operations, Cardinality of Sets, Matrices

4.1 Overview
1. Sets
2. Set Operations
3. Cardinality of Sets
4. DeMorgan’s Law for Sets
5. Matrices

4.2 Introduction

4.3 Situating Problem 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

• Example: The set V of vowels in English is V = {a, e, i, o, u}


• Example: The set O of all odd positive integers less than 10 is: O = {x|x is an odd positive integer less than 10}
• We use uppercase letters to denote a set.
Special Sets
N, Z, R are reserved to represent special sets:
• N: the natural numbers {1, 2, ...}
• Z: the set of integers {..., −2, −1, 0, 1, 2, ...}
• Z+ : the set of non-negative integers
• R: the set of real numbers.
• ∅: the empty set (no elements)
Set Equality
Two sets are equal if and only if they contain the same elements.
Venn Diagrams
A Venn diagram is a graphical representation of a set.

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

Another way to think about a subset:

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

Use subsets to prove equality of sets


A and B have the same elements if each set is a subset of the other.
For example:

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

Example: Let S be the set of letters in the alphabet. What’s |S|?


Answer:
Example: What’s |∅|?
Answer:
Power Set
Let S be a set. The power set of S is the set of all subsets of the set S.
The power set of S is written P(S).
Let S be the set {0, 1, 2}.
P(S) = {∅, {0}, {1}, {2}, {0, 1}, {0, 2}, {1, 2}, {0, 1, 2}}
Note: The empty set and S (the set itself) are members of the power set.
Power Set: Note
Example: What is the power set of the empty set?
Answer:
Example: What is the power set of the set {∅}?
Answer:
n-tuples
Sets are unordered, but we usually care about the ordering of elements.
For example, we may have a bunch of words, but it would be easier to search them if they’re
sorted, or put in a particular order.
Ordered n-tuple
The ordered n-tuple (a1 , a2 , . . . , an ) is the ordered collection that has a1 as its first element,
a2 as its second element, and an as its nth element.
Ordered n-tuples are equal if and only if each corresponding pair of their elements are equal:
(a1 , a2 , . . . an ) = (b1 , b2 , . . . bn ) if and only if:
ai = bi for i = 1, 2, . . . n.

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

Example: What is the Cartesian product of A = {1, 2} and B = {a, b, c}?


Answer: A×B =
Cartesian Products of multiple sets
The Cartesian product of sets A1 , A2 , . . . An denoted A1 ×A2 . . .×An is the set of n-tuples
(a1 , a2 , . . . an ) where ai ∈ Ai for i = 1, 2, . . . n.

A1 × A2 . . . × An = {(a1 , a2 , . . . an )|ai ∈ Ai for i = 1, 2, . . . n} (4.1)

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:

|A ∪ B| = |A| + |B| − |A ∩ B| (4.4)

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 Example: {5, 6, 7, 8, 9, 10} \ {7, 8, 9} =


?
Answer:
Symmetric Difference
The symmetric difference of sets A and B, denoted A ⊕ B is the set of elements that
belong to A or B but not both.

A⊕B

A ⊕ B = (A ∪ B) \ (A ∩ B) (4.7)
A B

Example:

Union of many sets


We use the following notation to denote the union of sets A1 , A2 , ..., An :

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:

Intersections of many sets


We use the following notation to denote the intersection of sets A1 , A2 , ..., An :
4-8 Lecture 4: September 27, 2018

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

4.5 Worked Problems: Sets

1. Let A, B and C be sets. Show that (A − B) − C is not necessarily equal to A − (B − C).


4-10 Lecture 4: September 27, 2018

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

A matrix is a rectangular array of numbers. A matrix with m rows and n


columns is called an m × n matrix. The plural of matrix is matrices. A
matrix with the same number of rows as columns is called square. Two
matrices are equal if they have the same number of rows and the same
number of columns and the corresponding entries in every position are
equal.

 
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)

4.6.0.1 Adding Matrices


     
x0,0 x0,1 x0,2 y0,0 y0,1 y0,2 x0,0 + y0,0 x0,1 + y0,1 x0,2 + y0,2
x1,0 x1,1 x1,2  + y1,0 y1,1 y1,2  = x1,0 + y1,0 x1,1 + y1,1 x1,2 + y1,2  (4.17)
x2,0 x2,1 x2,2 y2,0 y2,1 y2,2 x2,0 + y2,0 x2,1 + y2,1 x2,2 + y2,2

Example: Adding 2 matrices

     
5 4 3 0 15 30
3 3 3  +  5 20 35 =   (4.18)
−1 −2 −3 10 25 35

Example: Adding two different matrices

 
  0 15
5 4 3
+  5 20 =??? (4.19)
3 3 3
10 25

4.6.0.2 Multiplying Matrices

Definition 2: Matrix multiplication

cij = ai1 b1j + ai2 b2j + · · · + aik bkj

Number of columns in A needs to equal number of rows in B.

   
  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)

4.6.0.3 Zero-One Matrices

Example: Sending email

 
1 1 1
0 0 1 (4.22)
1 0 1

Boolean operations on zero-one matrices: And,OR, XOR, ...

4.6.1 Situating Example: Graphics

Problem: I have this picture, about as simple as it can be:

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

Per our earlier statement that p0 = p + t:

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)

Putting numbers to this:


I have a point at (1, 2). I need to move it 3cm horizontally, and 4cm vertically. What’s the
final position?

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)

The new location of the point is 4, 6.


Let’s make translation a little more complicated:

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)

Translation is pretty straightforward. Let’s do something a little more complicated.


Scaling

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

which, similar to our translation transfromation, can be summarized as:

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)

In the above image, we have a polygon with the following coordinates:

 
0 0
0 1

1
 (4.43)
1
1 0

We want to scale it by 4 in the x direction, and 6 in the y direction: sx = 4, sy = 6.

   
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

Or, you can write it as P 0 = S(sx , sy ) · T (tx , ty ) · P .


Let’s do the example for the point (1, 1) for the above scaling/translating:

     
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

Prove it by transforming the other points in the diagram above.


Matrix multiplication is associative, but not necessarily communtative:

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

To flip around the y axis:

 
−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!

Readings for NEXT week:

Rosen, Chapter 4.1, 4.2, 4.3, 4.4


Divisibility and Modular Arithmetic, Integer Representations and Algorithms,
Primes and Greatest Common Divisors, Solving Congruences Solving Congruences

You might also like