You are on page 1of 47

What is a set?

A Set is any well-defined collection of objects called the elements or members


of the set.
Well-defined means that it is possible to describe if a given object belongs to
the collection or not.

Describing a Set
Way one: List the elements of the set between braces (finite elements)
e.g. the set of all positive integers that are less than 4 : {1, 2, 3}

Way two: Specify a property that the elements of the set have in common
e.g. R={x | x is a real number }



1
1.1. Sets and Subset
Property of the elements
The order of the Set
{1, 2, 3}={1, 3, 2}={2, 3, 1}={2, 1,3 }={3, 1, 2}={3, 2, 1}

Repeated elements can be ignored
{1, 2, 3, 1} = {1, 2, 3}

Several commonly used sets





2
1.1. Sets and Subset
The relationships between Element & Set
Usually, we use uppercase letters such as A, B and C to denote
sets, and lowercase letters such as a, b, c, x, y and z to denote the
elements of sets
Binary cases: for a given element x and set A
1: x belongs to A denoted by x A
2: x does not belong to A denoted by x A
Fuzzy Sets
The collections of rich people, young girls, so on and so forth
Note: The words rich, young, beautiful, cool, hot, fat, thin etc. are
fuzzy (not well defined).



3
1.1. Sets and Subset
Subset
If every element of A is also an element of B, namely, if whether x c A then x
c B, we say that A is a subset of B, denoted by A B . Otherwise, .
Venn diagrams




A B



4
1.1. Sets and Subset
B
A
B A
A B
5
1.1. Sets and Subset
A B
A=B: A c B & B c A
A
U
An universal set (U) is a set containing all objects for
which the discussion is meaningful.
Example 10
Let A be a set and let B = {A, {A}}, then, since A and {A} are
elements of B, we have A e B and {A} e B.

6
1.1. Sets and Subset
The cardinality of a finite set
A set A is called finite if it has n distinct elements, where n e N.
In this case, n is the cardinality of A and is denoted by |A|.
e.g. A={1,2,3,1} |A| = 3
B={a, b, c, d, e, a}, |B| = 5
|A| < |B|

A set that is not finite is called infinite, for instances, N, Z, Q, R
as mentioned in Example 3.


7
1.1. Sets and Subset
Power set of a set A
If A is a set, then the set of all subsets of A is called the power
set of A and is denoted by P(A).
e.g. A={1,2,3}
Then P(A) consists of the following subsets of A: {}, {1}, {2},
{3}, {1,2}, {1,3}, {2,3}, and {1,2,3}

|P(A)| = 2^n, why? Assuming n = |A| e N

1.1. Sets and Subset
8
Union
If A and B are sets, we define their union as the set consisting of
all elements that belong to A or B and denote it by A U B.
A U B = { x | x e A or x e B }

1.2. Operations on Sets
9
A
U
B
Intersection
If A and B are sets, we define their intersection as the set
consisting of all elements that belong to both A and B and
denoted it by A B.
A B = { x | x e A and x e B }


1.2. Operations on Sets
10
U
A B
Complement of B with respect to A
If A and B are two sets, we define the complement of B with
respect to A as the set of all elements that belong to A but not to
B, and we denote it by A - B
A - B = { x | x e A and x e B }
1.2. Operations on Sets
11
U
A A B
Complement
If U is a universal set containing A, then U-A is called the
complement of A and is denoted by
= {x | x e A}




1.2. Operations on Sets
12
U
A
Symmetric difference
If A and B are two sets, we define their symmetric difference as
the set of all elements that belong to A or to B, but not to both A
and B, and we denote it by A B
A B = {x | (x e A and x e B) or (x e B and x e A) }

1.2. Operations on Sets
13
U
A B
Commutative Properties
A U B = B U A ; A B = B A

Associative Properties
A U (B U C) = ( A U B ) U C
A (B C) = ( A B ) C

Distribution Properties
A (B U C) = ( A B ) U ( A C )
A U (B C) = ( A U B ) ( A U C )


14
1.2. Operations on Sets
Idempotent Properties
A U A =A ; A A = A
Properties of the complement




De Morgans Law




15
1.2. Operations on Sets
Properties of a Universal set
A U U = U
A U = A

Properties of the empty set
A U = A
A =
16
1.2. Operations on Sets
How to proof above properties?
e.g. Proof:
Proof: suppose x e , then we have x e AB, so
x e or ,x e which means that x e . Thus,
e
Conversely, suppose x e then we have x e A or x e B ,
so x e A B, which means that x e .Thus

e
Therefore,

A common style of proof for statements about sets is to choose an
element in one of the sets and see what we know about it.



17
1.2. Operations on Sets
Addition Principle
Theorem 2: If A and B are finite sets, then
|A U B| = |A| + |B| - |A B |


18
1.2. Operations on Sets
U
A B
A B
Example 9
A computer company wants to hire 25 programmers to handle
systems programming jobs and 40 programmers for applications
programming. Of those hired, 10 will be expected to perform
jobs of both types. How many programmers must be hired? (at
least? )
Solution:
A: the set of system programmers hired
B: the set of applications programmers hired, then
|A| = 25, |B| = 40, |A B| =10
|A U B| = |A| + |B| - |A B |
= 25 + 40 -10 =55





1.2. Operations on Sets
19
Generalized case for three sets
Theorem 3: Let A, B and C be finite sets. Then
|A U B U C| = |A| + |B| + |C| - |AB| - |BC|-|AC| + |ABC|

20
1.2. Operations on Sets
A
B
C
AB
BC AC
ABC
Sequences
a list of objects arranged in a definite order
finite or infinite, explicit or recursive
some elements may be repeated in a sequence
set corresponding to a sequence set of all distinct
elements in the sequence;
A set is called countable if it is the set corresponding
to some sequence
All finite sets are countable
Not all infinite sets are countable (e.g. the set of all real
numbers)
A_U, characteristic function f
A
of A is defined for
each xeU,
f
A
(x)=

1 if xeA; f
A
(x)=0 if xeA
f
AB
= f
A
f
B
f
AB
= f
A
+f
B
- f
A
f
B

f
AB
= f
A
+f
B
-2f
A
f
B


While sets have no order and no repeated elements,
sequences have order and can contain repeats at differing
positions in the order.
The set {5,2,5} = {5,2} = {2,5}
The sequence (5,2,5) = (5,2) = (2,5)
Actually, there is a notion of a multiset or bag that we
sometimes use. It has no order, but repeated elements are
allowed. Since position is irrelevant, we just record each
unique elements with a count.
We can talk about the k-th element of a sequence, but not of
a set or multiset.
Finite sequences are often called tuples. Those of length k
are k-tuples. A 2-tuple is also called a pair.

Computer representation of Sets and Subsets
Let U={a,b,e,g,h,r,s,w}. The array of length 8 shown below represents U.
1, if x= a,b,e,g,h,r,s,w
f
U
(x)=
0 otherwise

If S={a,e,r,w} then
1, if x= a,e,r,w
f
S
(x)=
0 if x= b,g,h,s
The array representation of subset S is

1 0 1 0 0 1 0 1
Strings and Regular Expressions
alphabet A: a set of symbols
string: a finite sequence of symbols in A
A
*
consists of all finite strings from A
empty string A: contains no symbols
catenation of w
1
and w
2
is w
1
w
2

a regular expression over A is a string
constructed from the elements of A and the
symbols (, ), v, *, A, according to the following
definition: (a recursive definition)
RE1. The symbol A is a regular expression.
RE2. If x eA, the symbol x is a regular expression.
RE1 and RE2 provide initial regular expressions
Strings and Regular Expressions (cont)
RE3. If o and | are regular expressions, then the
expression o| is regular.
RE4. If o and | are regular expressions, then the
expression (ov|) is regular.
RE5. If o is a regular expression, then the expression
(o)* is regular.
each regular expression corresponds to a regular
subsets of A
*
, or regular set if no reference to A is
needed

the concept of regular expressions is important for
the study of the syntax of programming languages
To compute the regular set corresponding to a
regular expression, use the following correspondence
rules:
Strings and Regular Expressions (cont)
1. The expression A corresponds to the set {A}.
2. If xeA, then the regular expression x
corresponds to the set {x}.
3. If o and | are regular expressions corresponding
to the subsets M and N of A
*
, then o|
corresponds to MN={st| seM and teN}. Thus MN
is the set of all catenations of strings in M with
strings in N.
4. If the regular expressions o and | correspond to
the subsets M and N of A
*
, then (ov|)
corresponds to MN.
5. If the regular expression o corresponds to the
subset M of A
*
, then (o)
*
corresponds to the set
M
*
.
Example
Ex 1. Let A=(a,b,c,..,z}, the usual English alphabet. Then A* consists of
ordinary words, such as ape,queen and so on as well as yxaloble,esy etc.All
finite sequences from are A*, whether they have meaning or not.
Ex 2. If w
1
=s
1
s
2
s
n
and w
2
=t
1
t
2
t
n
are the elements of A* for some set A we
define the catenation of w
1
and w
2
as the sequence s
1
s
2
s
n
t
1
t
2
t
2
. The
catenation of w
1
and w
2
is written as w
1
.w
2
or w
1
w
2
and its another element
of A*.
Ex 3. If A={Ram,swims,Sam, walks, sleep,slowly} then A* contain real
sentences like Ram walks slowly as well as nonsense sentences like
swim sleep walks
Ex 4. Let A={0,1} 0*(0V1)* is regular expression.
By RE2, 0 and 1 are regular expression. Thus (0V1) us a regular expression
by RE4 and so 0* and (0V1)* are regular by RE5 and finally we see that
0*(0V1)* is regular by RE3.

Associated with each regular expression over A, there is a corresponding
subset of A*. Such sets are called regular subsets of A* or just regular sets.
Ex 1. Let A={a,b,c}. Then the regular expression a* corresponds to the set of all
finite sequences of as, such as aaa,aaaaa and so on. The regular
expression a(bVc) corresponds to the set {ab,ac} _ A* The regular
expression ab(bc)*corresponds to the set of all strings that begin with ab and
then repeat the symbol bc n times where n>=0. This set includes ab,abbc,
abbcbc and so on.
Ex 2. If A={0,1} the regular set of corresponding to regular expression
00*(0V1)*1 corresponds to the set of all sequences of 0s and 1s that begin
with at least one 0 and end with at least one 1.
Matrix
An array of numbers arranged in m horizontal rows
and n vertical columns:
A = a
11
a
12
a
13
. a
1n
a
21
a
22
a
23
a
2n



a
m1
a
m2
a
m3
a
mn



The ith row of A is [a
i1
, a
i2
, a
i3
, a
in
]; 1 s i s m
The jth column of A is a
1j

a
2j
; 1 s j s n

a
3j

a
mj

We say that A is a matrix m x n. If m = n, then A
is a square matrix of order n, and a
11
, a
22
, a
33
,
..a
nn
form the main diagonal of A.

a
ij
which is in the ith row and jth column, is said
to be the i, jth element of A or the (i, j) entry
of A, often written as A = [a
ij
].


Ex 2:
A = 8 0 0 0
0 3 0 0
0 0 7 0
0 0 0 1

A square matrix A = [a
ij
], for which every entry
off the main diagonal is zero, that is a
ij
= 0 for i
= j, is called a diagonal matrix.

Two m x n matrices A and B, A = [a
ij
] and B =
[b
ij
], are said to be equal if a
ij
= b
ij
for 1 s i s m,
1 s j s n; that is, if corresponding elements are
the same.
Ex 3:
A = a 5 3 B = 1 5 x
2 7 -1 y 7 -1
3 b 0 3 4 0

So, if A = B, then a = 1, x = 3, y = 2, b = 4.

Matrix summation
If A = [a
ij
] and B = [b
ij
] are m x n matrices, then
the sum of A and B is matrix C = [c
ij
], defined by
c
ij
= a
ij
+ b
ij
; 1 s i s m, 1 s j s n.

C is obtained by adding the corresponding
elements of A and B.

A = 1 5 3 B = 2 0 3
2 7 -1 6 1 3
3 4 0 -3 1 9

C = 3 5 6
8 8 4
0 5 9

The sum of the matrices A and B is defined only when
A and B have the same number of rows and the same
number of columns (same dimension).

A matrix in when all of its entries are zero is
called zero matrix, denoted by 0.

Theorems involved in summation :
A + B = B + A.
(A + B) + C = A + (B + C).
A + 0 = 0 + A = A.

Matrices Product
If A = [a
ij
] is an m x p matrix and B = [b
ij
] is a p x
n matrix, then the product of A and B, denoted
AB, will produce the m x n matrix C = [c
ij
],
defined by
c
ij
= a
i1
b
1j
+ a
i2
b
2j
+ + a
ip
b
pj
;
1 s i s n, 1 s j s m
That is, elements a
i1
, a
i2
, .. a
ip
from ith row of A
and elements b
1j
, b
2j
, .. b
pj
from jth column of B,
are multiplied for each corresponding entries
and add all the products.

Ex 5:
A = 2 3 -4 B = 3 1
1 2 3 -2 2
5 -3
2 x 3 3 x 2
AB = 2(3) + 3(-2) + -4(5) 2(1) + 3(2) + -4(-3)
1(3) + 2(-2) + 3(5) 1(1) + 2(2) + 3(-3)


= 6 6 20 2 + 6 + 12
3 4 + 15 1 + 4 9


= -20 20
14 -4
2 x 2

If A is an m x p matrix and B is a p x n matrix, in
which AB will produce m x n, BA might be
produce or not depends on:
n = m, then BA cannot be produced.
n = m, p = m @ n, then we can get BA but the
size will be different from AB.
n = m= p, A = B, then we can get BA, the size
of BA and AB is the same, but AB = BA.
n = m = p, A = B, then we can get BA, the size
of BA and AB is the same, and AB = BA.

Identity matrix
Let say A is a diagonal matrix n x n. If all entries on its
diagonal are 1, it is called identity matrix, ordered n,
written as I.
Ex 7:
1 0 1 0 0 1 0 0 0
0 1 0 1 0 0 1 0 0
0 0 1 0 0 1 0
0 0 0 1
Theorems involved are:
A(BC) = (AB)C.
A(B + C) = AB + AC.
(A + B)C = AC + BC.
IA = AI = A.


Transposition Matrix
If A = [a
ij
] is an m x n matrix, then A
T
= [a
ij
]
T
is a n x
m matrix, where
a
ij
T
= a
ji
; 1 s i s m, 1 s j s n

It is called transposition matrix for A.
Ex 8:
A = 2 -3 5 A
T
= 2 6
6 1 3 -3 1
5 3

Theorems involved are:
(A
T
)
T
= A
(A + B)
T
= A
T
+ B
T

(AB)
T
= B
T
A
T

Matrix A = [a
ij
] is said to be symmetric if A
T
= A, that
is a
ij
= a
ji
,
A is said to be symmetric if all entries are
symmetrical to its main diagonal.

Ex 9:
A = 1 2 -3 B = 1 2 -3
2 4 5 2 4 0
-3 5 6 3 2 1
Symmetric Not Symmetric, why?

Boolean Matrix and Its Operations
Boolean matrix is an m x n matrix where all of its entries
are either 1 or 0 only.
There are three operations on Boolean:

a)Join by
Given A = [a
ij
] and B = [b
ij
] are Boolean matrices with the
same dimension, join by A and B, written as A v B, will
produce a matrix C = [c
ij
], where
c
ij
= 1 if a
ij
= 1 OR b
ij
= 1
0 if a
ij
= 0 AND b
ij
= 0

b)Meet
Meet for A and B, both with the same dimension, written
as A . B, will produce matrix D = [d
ij
] where
d
ij
= 1 if a
ij
= 1 AND b
ij
= 1
0 if a
ij
= 0 OR b
ij
= 0
Ex 10: A =1 0 1 B = 1 1 0
0 1 1 0 0 1
1 1 0 0 1 0
0 1 0 1 1 0


A v B = 1 1 1 A . B = 1 0 0
0 1 1 0 0 1
1 1 0 0 1 0
1 1 0 0 1 0

c) Boolean product
If A = [a
ij
] is an m x p Boolean matrix, and B = [b
ij
] is a
p x n Boolean matrix, we can get a Boolean product
for A and B written as A B, producing C, where:

c
ij
= 1 if a
ik
= 1 AND b
kj
= 1; 1 s k s p.
0 other than that

It is using the same way as normal matrix product.
+
+
Ex 11:
A = 1 0 0 0 B = 1 1 0
0 1 1 0 0 1 0
1 0 1 1 1 1 0
3 x 4 0 0 1
4 x 3
A B = 1 + 0 + 0 + 0 1 + 0 + 0 + 0 0 + 0 + 0 + 0
0 + 0 + 1 + 0 0 + 1 + 1 + 0 0 + 0 + 0 + 0
1 + 0 + 1 + 0 1 + 0 + 1 + 0 0 + 0 + 0 + 1

A B = 1 1 0
1 1 0
1 1 1
3 x 3

+
Exercise 3:
A = 1 0 0 0 B = 0 1 0 0 C = 0 0 1 0
0 1 1 0 0 0 1 1 1 0 0 0
0 0 0 1 0 1 0 1 1 1 0 0
1 1 0 0 0 0 1 0 1 1 1 0

Find:
a) A v B
b) A . B
c) A B
d) A v C
e) A . C
f) A C
g) B v C
h) B . C
i) B C

+
+

You might also like