tr1413 set_theory

35
TR1413: Discrete TR1413: Discrete Mathematics For Computer Mathematics For Computer Science Science Lecture 22: Set Lecture 22: Set Theory Theory

Upload: masharah

Post on 17-Jan-2015

666 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Tr1413 set_theory

TR1413: Discrete TR1413: Discrete Mathematics For Computer Mathematics For Computer

ScienceScience

Lecture 22: Set TheoryLecture 22: Set Theory

Page 2: Tr1413 set_theory

IntroductionIntroduction• Z formal specification notation is

based on set. • Everything in Z is actually a set.• So it is important for us to

understand the concept of sets and set theory.

Page 3: Tr1413 set_theory

SetsSets

• Set = a collection of distinct unordered objects

• Members of a set are called elements• How to determine a set

– Listing:• Example: A = {1,3,5,7}

– Description• Example: B = {x | x = 2k + 1, 0 < k < 3}

Page 4: Tr1413 set_theory

Empty setEmpty set

• The empty set or { } has no elements.

Also called null set or void set.

Page 5: Tr1413 set_theory

Universal setUniversal set

Universal set: the set of all elements about which we make assertions.

Examples:– U = {all natural numbers}– U = {all real numbers}– U = {x| x is a natural number and 1< x<10}

Page 6: Tr1413 set_theory

CardinalityCardinality

• Cardinality of a set A (in symbols |A| or #A) is the number of elements in A

• Examples:If A = {1, 2, 3} then |A| = 3

If B = {x | x is a natural number and 1< x< 9}

then |B| = 9

• Infinite cardinality– Countable (e.g., natural numbers, integers)– Uncountable (e.g., real numbers)

Page 7: Tr1413 set_theory

SubsetsSubsets

• X is a subset of Y if every element of X is also contained in Y

(in symbols X Y)

• Observation: is a subset of every set. So for any set X, X

• Observation: A set is always a subset to itself, i.e . X X

Page 8: Tr1413 set_theory

SubsetsSubsets

• X is a proper subset of Y (in symbol X Y) if X Y but X Y.

Page 9: Tr1413 set_theory

EqualityEquality

Equality: X = Y if X Y and Y X

Page 10: Tr1413 set_theory

Power setPower set

• The power set of X is the set of all subsets of X, in symbols P(X),– i.e. P(X)= {A | A X}– Example: if X = {1, 2, 3},

then P(X) = {, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}}

Page 11: Tr1413 set_theory

UnionUnion

• Given two sets X and Y. The union of X and Y is defined as the set

X Y = { w | w X w Y}

Page 12: Tr1413 set_theory

IntersectionIntersection

• Given two sets X and Y. The intersection of X and Y is defined as the set

X Y = { w | w X w Y}• Two sets X and Y are disjoint if X Y =

Page 13: Tr1413 set_theory

DifferenceDifference

• The difference of two sets

X – Y = { w | w X and w Y}

The difference is also called the relative complement of Y in X

Page 14: Tr1413 set_theory

ComplementComplement

The complement of a set A contained in a universal set U is the set Ac = U – A In symbols Ac = U - A

Page 15: Tr1413 set_theory

Cartesian ProductCartesian Product

• Given two sets X and B, its Cartesian product X x Y is the set of all ordered pairs (x,y) where x X and y Y

• In symbols X x Y = {(x, y) | x X and y Y}

Page 16: Tr1413 set_theory

Binary RelationBinary Relation

• A binary relation R from a set X to a set Y is a subset of the Cartesian product X x Y– Example: X = {1, 2, 3} and Y = {a, b}– R = {(1,a), (1,b), (2,b), (3,a)} is a relation between X

and Y

Page 17: Tr1413 set_theory

Domain and rangeDomain and range

Given a relation R from X to Y,• The domain of R is the set

– Dom(R) = { x X | (x, y) R for some y Y}

• The range of R is the set– Rng(R) = { y Y | (x, y) R for some x X}

Page 18: Tr1413 set_theory

Domain and rangeDomain and range

Given a relation R from X to Y,• Example:

– if X = {1, 2, 3} and Y = {a, b}

– R = {(1,a), (1,b), (2,b)}

– Then: • Dom(R)= {1, 2}

• Rng(R) = (a, b}

Page 19: Tr1413 set_theory

Inverse of a relationInverse of a relation

• Given a relation R from X to Y, its inverse R-1 is the relation from Y to X defined by

R-1 = { (y,x) | (x,y) R }

Page 20: Tr1413 set_theory

Relation CompositionRelation Composition• Let R1 be a relation from X to Y and R2 be a

relation from Y to Z. The composition of R1 and R2, denoted as R1 ◦ R2 is the relation from X to Z defined by

R1 ◦ R2 = {(x,z) | (x,y) R∊ 1 and (y,z) R∊ 2 for some y Y}∊

Page 21: Tr1413 set_theory

Relation CompositionRelation Composition

• Example:– R1 = {(1,2),(1,6),(2,4),(3,4),(3,6),(3,8)}

– R2 = {(2,u),(4,s),(4,t),(6,t),(8,u)}

– R1 ◦ R2 = {(1,u),(1,t),(2,s),(2,t),(3,s),(3,t),(3,u)}

Page 22: Tr1413 set_theory

Domain RestrictionDomain Restriction• We can restrict a given relation to a

certain domain.• For example

R = {(1,2),(1,6),(2,4),(3,4),(3,6),(3,8)}

{1,2} \dres R = {(1,2),(1,6),(2,4)}

{1,2} \ndres R = {(3,4),(3,6),(3,8)}

Page 23: Tr1413 set_theory

Range RestrictionRange Restriction• We can restrict a given relation to a

certain range.• For example

R = {(1,2),(1,6),(2,4),(3,4),(3,6),(3,8)}

R \rres {2,4} = {(1,2),(2,4),(3,4)}

R \nrres {2,4} = {(1,6),(3,6),(3,8)}

Page 24: Tr1413 set_theory

FunctionsFunctions

• A special kind of relation.• A function f from X to Y (in symbols f : X Y)

is a relation from X to Y such that 1. dom(f) = X

2. if two pairs (x,y) and (x,y’) f, then y = y’

• If dom(f) ⊂ X, f is called a partial function otherwise it is called a total function.

Page 25: Tr1413 set_theory

FunctionsFunctions

– Domain of f = X

– Range of f =

{ y | y = f(x) for some x X}

– A function f : X Y assigns to each x in dom(f) = X a unique element y in rng(f) Y.

– Therefore, no two pairs in f have the same first coordinate.

Page 26: Tr1413 set_theory

FunctionsFunctions

• Example: Dom(f) = X = {a, b, c, d},

Rng(f) = {1, 3, 5}

f(a) = f(b) = 3,

f(c) = 5, f(d) = 1.

Page 27: Tr1413 set_theory

One-to-one functionsOne-to-one functions

• A function f : X Y is one-to-one (injective)

for each y Y there exists at most one x X with f(x) = y.

Page 28: Tr1413 set_theory

One-to-one functionsOne-to-one functions

• Alternative definition: f : X Y is one-to-one for each pair of distinct elements x1, x2 X there exist two distinct elements y1, y2 Y such that f(x1) = y1 and f(x2) = y2.

Page 29: Tr1413 set_theory

Onto functionsOnto functions

• A function f : X Y is onto (surjective)

for each y Y there exists at least one x X with f(x) = y, i.e. rng(f) = Y.

Page 30: Tr1413 set_theory

Bijective functionsBijective functions

• A function f : X Y is bijective

f is one-to-one and onto

Page 31: Tr1413 set_theory

Types of FunctionsTypes of Functions• Partial Function• Total Function• Injective (one-to-one)

– Partial injective– Total injective

• Surjective (onto)– Partial surjective– Total surjective

• Bijective– Partial bijective– Total bijective

Page 32: Tr1413 set_theory

Inverse functionInverse function

• Given a function y = f(x), the inverse f -1 is the set {(y, x) | y = f(x)}.

• The inverse f -1 of f is not necessarily a function.

• However, if f is a bijective function, it can be shown that f -1 is a function.

Page 33: Tr1413 set_theory

Composition of functionsComposition of functions

• Given two functions g : X Y and f : Y Z, the composition f ◦ g is defined as follows:

f ◦ g (x) = f(g(x)) for every x X.

Page 34: Tr1413 set_theory

Composition of functionsComposition of functions

Composition of functions is associative:

f ◦ (g ◦h) = (f ◦ g) ◦ h, But, in general, it is not commutative:

f ◦ g g ◦ f.

Page 35: Tr1413 set_theory

OverrideOverride• We can replace elements in a function

with new elements.• Example:

f = {(1,a),(2,a),(3,b),(4,c)}

f \override {(2,b),(3,a),(5,a)}

={(1,a),(2,b),(3,a),(4,c),(5,a)}