+ All Categories
Home > Documents > Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called...

Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called...

Date post: 18-Dec-2015
Category:
Upload: jemimah-cain
View: 234 times
Download: 3 times
Share this document with a friend
36
Chapter 3 – Set Theory
Transcript
Page 1: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Chapter 3 – Set Theory

Page 2: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

What is a Set?

A set is a collection of distinguishable objects called elements.

When writing out the elements of a set we use { }.

Two kinds of set definitions – list-based and rule-based. The above are examples of list-based definitions of sets. We list all the elements (or enough so that the pattern is obvious).

A rule-based definition of a set involves a predicate.

{ 1, 2, 3, ... } -- set of positive integers (Natural Numbers){red, green, blue} -- primary colors set

P = { x : P(x) }

E = { x : x is an even integer } = { 0, +2, -2, +4, -4, . . . }

We say “the set of all x such that ...”.

Page 3: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Alternative Definitions:

Give an alternative definition.

A = {x : x is an integer and x2 + 4x = 12 }B = {x : x is a day of the week not containing the letter 'u'}C = { n2 : n is an integer }

Page 4: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Well-known Sets:

Empty Set: Ø

Natural Numbers: N -- { 1, 2, 3, ... }

Integers: Z -- { 0, ±1, ±2, ±3, ... }

Rational Numbers: Q -- { a/b : a, b Є Z and b != 0 }

Real Numbers: R -- { all decimals }

The above sets correspond very closely to the data types of many programming languages

.

Page 5: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Data Types:

A set of objects (values) together with a well-defined set of operations.

When we declare a variable to be of a certain type we are saying that any value it takes on must come from a known set of values.

Note that in perl there is a numeric value you can assign to a scalar variable and this numeric value is not a number – NaN.

Page 6: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Sets and Their Operations:

A = {1, 2, 3} then we say that A is a subset of N.

A set is called a subset of another set if every element of the first set is also an element of the second. We denote this as

We use a Venn Diagram to represent this:

A B

U

A

B Universe of Discourseor Universal Set

Page 7: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Set Equality:

Two sets are defined to be equal if each is a subset of the other.

Symbolically we write:

Exercise: Define A = {n : n2 is an odd integer} and B = {n: n is an odd integer}. Prove A = B.

A = B if (x A => x B) and (x B => x A) are both trueє є є є

If x A, then x2 = 2m + 1. If x is even then x = 2n and so x2 = 4n2 so x2 is even, a contradiction. So by contraposition, x can not be even so x is odd. Hence x B.

Now suppose x B. Then x = 2m +1 and x2 = (2m + 1)2 =2m2 + 4m + 1 = 2(m2 + 2m) + 1 and so x2 is odd. Therefore x A.

This shows A = B.

є

є

є

є

Page 8: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Union:

The Union of two sets, A and B, is the set A B = { x: x A or x B}U є є

A B

Page 9: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Intersection:

The Union of two sets, A and B, is the set A B = { x: x A and x B}U

є є

BA

Page 10: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Complement of A Relative to B:

The Complement of the set A relative to a set B B, is the set A \ B = { x: x A and x B}є є

A B

Page 11: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Complement Set:

If no “relative” set is mentioned then the complement of a set A is with respect to a Universal Set (represented as the box in our Venn Diagrams). It is everything that is not in A.

A

Complement of A

Page 12: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Symmetric Difference of A and B:

The Complement of the set A relative to a set B B, is the set A B = { x: x A and x B} { x: x B and x A}

є

A B

є є є єU∆

Page 13: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Examples:

A = { 1, 3, 5, 7 }, B = { 2, 4, 6, 8 }, C = {1, 2, 3, 4 ,5 }

A B = { 1, 2, 3, 4, 5, 6, 7, 8 }

B C = { 2, 4 }

A \ C = { 7 }

B C = { 6, 8 } { 1, 3, 5 } = { 1, 3, 5, 6, 8 }

U

U

U

Page 14: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Exercise:

Suppose A = { x : 1 <= x <= 12 and x is an even integer }and B = { x : 1 <= x <= 12 and x is an integer multiple of 3 }

Verify ~(A B) = ~A ~B.UU

Calculate: ~(A B) =

Calculate ~A ~B =

U

U

A = { 2, 4, 6, 8, 10, 12 }

B = {3, 6, 9, 12 } U = { 1, 2, ..., 12 }

~ { 6, 12 } = { 1, 2, 3, 4, 5, 7, 8, 9, 10, 11 }

= {1, 3, 5, 7, 9, 11 } {1, 2, 3, 5, 7, 8, 10, 11 }

= { 1, 2, 3, 4, 5, 7, 8, 9, 10, 11 }

U

Page 15: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Algebra of Sets:

There is a nice correspondence between the boolean operators – and, or, not and => on predicates and the set operators intersection, union, complement and subset.

Page 16: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Example (de Morgan's Law):

Prove that for any two sets, A and B, ~(A B) = ~A ~B.

So we reduced a claim about sets to two compound logical propositions - ~(P and Q) and ~P or ~Q.

U

U

~(A B) = {x: x (A B)}

= {x: not ( x (A B))}

= { x: not ( x A and x B )}

U

Є

U

Є

U

Є Є

~A ~B = {x: (x A) or (x B)}

= { x: (not ( x A)) or (not( x B )}

Є

Є Є

U Є

Exercise: Prove the above are logically equivalent

Page 17: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Algebra of Sets:

The algebra of sets is governed by certain laws just as basic arithmetic is governed by laws of arithmetic such as association, commutativity, etc.

Associative Laws: A (B C) = (A B) C A (B C) = (A B) CU

U

U U U

U U U

Commutative Laws: B C = C B B C = C BU U

U U

Identity Laws: B = B B = B B = B =

U

U

O UO O

U

UU U

Page 18: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Algebra of Sets (cont):

Finally

Idempotent Laws: B B = B B B = BU

U

Distributive Laws: A (B C) = (A B) (A C) A (B C) = (A B) (A C)

UU U

UU U U

U U

U

Complement Laws: A ~A = A ~A = ~ = ~ = ~(~A) = A

OU O

OU UU

U

de Morgan's Laws: ~(B C) = ~C ~B ~(B C) = ~C ~BU U

U U

Page 19: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Example:

Use the laws of algebra of sets to prove:

A B = (A B) ~(A B)Δ

Proof: A B is symmetric difference. It is equal to (A ~B) (B ~A)

However

U

U U

(A B) ~(B A) = (A B) ((~A) (~B)) -- deM = ((A B) ~A) ((A B) ~B)

U UU

U UU

UU UU U U U U

= ((~A) (A B)) ((~B) (A B)) -- Comm Law= (((~A) A)) ((~A) B)) (((~B) A) ((~B) B)) --Dist Law= (((~A) A)) (B (~A))) ((A (~B)) ((~B) B)) --Comm Law=( (B (~A))) ((A (~B)) ) --Comp Law= (A ~B) (B ~A) -- Comm and Ident Law

-- Dist Law

U

U

U U UU U U

U U U

U U U

U UU U

U U U U

U UUО О

the same

U U

Page 20: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Further Properties of Sets:

The cardinality of a finite set is the number of elements in the set (written |S|).

If A and B are finite sets then |A B| = |A| + |B| - |A B|.

Proof: A B = (A\B) (A B) (B\A)so |A B| = |A\B| + |A B| + |B\A|Suppose |A\B| = m, |A B| = n, |B\A| = pThen |A B| = m + n + p = (m + n) + (n + p) – n = |A| + |B| - |A B|

A B

A \ B A B B \ AU U U

U

UU

U

U

U

U

U

U

Page 21: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Exercise:

63 students study CS – 16 with the Accounting option, 37 with the business option and 5 studied both. How many studied neither

511 32

?

Ans: 15

Page 22: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Cartesian Products:

An ordered pair is a tuple (a,b) where a A and b B.

A cartesian product A x B = {(a,b): a A, b B}.

Cartesian products are fundamentally important because they are the basis of all functions (math) and relations (dbms).

R2, the real plane, is an example of a cartesian product.

If A1, A

2, A

3, ..., A

n are a collection of sets then

A1 x A

2 x A

3 x ... x A

n =

{ (a1,a

2,a

3,..., a

n) : a

1 A

1, ..., a

n A

n}

If A1 = A

2 = A

3 = ... = A

n = A we express this as An.

є є

є є

є є

Page 23: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Relational Database Example:

The rows in the Employee table correspond in a 1-1 fashion to employees in a company.

They also belong to the following cartesian product

EmployeeID EName DOB Gender

Employee

{EmployeeID} x {EName} x {DOB} x {Gender}

You can refer to all the rows of the cartesian product that lie in Employeeas information rows and the rows outside Employee, the rows that don'tcorrespond to reality as the noise rows.

Page 24: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Example:

If B = {0,1} describe B8.

Suppose S is a finite ordered set with elements {s1, s

2, ..., s

n}.

Suppose A S. We define a characteristic function that corresponds to A as:

So fA corresponds to an ordered tuple of n 0s and 1s.

fA: S --> {0,1}

where f

A(s

i) = 1 if s

i A

= 0 if si Aєє

Page 25: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Example (cont):

S = {1,2,3,4,5,6,7,8}, A = {2,3,4,6,7}, B = {1,3,4,5}

fA = 01110110, f

B = 10111000

Find A B. This is just the bit operation fA or f

B = 11111110.

This is the characteristic function of the set {1,2,3,4,5,6,7} which is A B.

U

Exercise: Find A B.

UU

01110110and 10111000 00110000

00110000 is the characteristic functionof the set {3,4} so A B = {3,4}.

U

Page 26: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Bit Map Example:

Go back to the Employee table.

Suppose BD = {birth dates}, G = {male, female}.

For each element of G, create a sequence of 0s and 1s.

These sequences are called bit maps.

Repeat the process for every date in BD.

Convince yourself that finding all females born on August 4, 1975 is just a matter or ANDing two bit maps.

EmployeeID EName DOB Gender

Employee

male = 101.....1 where ith digit is 1 iff ith employee is malefemale = 010.....0 where ith digit is 1 iff ith employee is female

Page 27: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Homework:

Do the Exercises at the end of the chapter.

Page 28: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Prolog:

Prolog is a logic programming language.

Prolog uses facts and rules to deduce new facts.

% prolog facts% parent(x,y) means x is the parent of yparent(george_1, george_2).parent(george_3, george_4).parent(george_3,edward).parent(edward,victoria).parent(victoria,edward_7).parent(edward_7,george_5).parent(george_5,edward_8).parent(george_5,george_6).parent(george_6,elizabeth_2).parent(victoria,alice).parent(alice,victoria_alberta).parent(victoria_alberta,alice_mountbatten).parent(alice_mountbatten,philip).

% wife(x,y) means x is the wife of ywife(sophia,george_1).wife(wilemina,george_2).wife(charlotte,george_3).wife(caroline,george_4).wife(adelaide,william_4).wife(victoria,albert).wife(victoria_mary,george_5).wife(elizabeth_qm,george_6).wife(elizabeth_2,philip).

Page 29: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Prolog Rules and Questions:

% rules:female(X) :- wife(X,Y). % if X is wife of Y then X is femaleancestor(X,Y) :- parent(X,Y). % if X is parent of Y then X is ancestor of Yancestor(X,Y) :- parent(X,Z), ancestor(Z,Y). % is X is parent of Z and Z is ancestor of Y then X is ancestor of Y

%questionsfemale(victoria).

yes

female(george_3).

no

Page 30: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

How Do Questions Get Answered:

Logically, prolog rules are expressed as quantified predicates: female(X) :- wife(X,Y)can be expressed as X Y wife(X,Y) --> female(X)this is the same as X Y ~wife(X,Y) or female(x)Since this rule is part of the program it is TRUE.If I ask the questionfemale(victoria)then logically I am asking Y ~wife(victoria,Y) or female(victoria)Since wife(victoria,albert) is TRUE, ~wife(victoria,Y) can not be TRUE for all Y.Hence the only way this rule can be true is if female(victoria) is TRUE.

A A

AA

A

Page 31: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

How Do Questions Get Answered:

Logically, prolog rules are expressed as quantified predicates: female(X) :- wife(X,Y)can be expressed as X Y wife(X,Y) --> female(X)this is the same as X Y ~wife(X,Y) or female(x)Since this rule is part of the program it is assumed TRUE.If I ask the questionfemale(albert)then logically I am asking Y ~wife(albert,Y) or female(albert)Since wife(albert,Y) is never TRUE, ~wife(albert,Y) is TRUE for all Y.Hence the rule can be true even if female(albert) is FALSE.

This leads us to note that in prolog, FALSE means “no evidenceit is TRUE”.

A A

AA

A

Page 32: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Exercise

Understand the logic of findingThere are two ancestor(x,y) rules X Y parent(X,Y) -> ancestor(X,Y) X Y Z parent(X,Z) and ancestor(Z,Y) -> ancestor(X,Y)Which can be rewritten ( X Y ~parent(X,Y) or ancestor(X,Y)) or ( X Y Z ~(parent(X,Z) and ancestor(Z,Y)) or ancestor(X,Y)) Which can be rewritten ( X Y ~parent(X,Y) or ancestor(X,Y)) or ( X Y Z ~parent(X,Z) or ~ancestor(Z,Y)) or ancestor(X,Y))

Now we ask the question: ancestor(alice,X).We first try to find as many solutions as possible to ( Y ~parent(alice,Y) or ancestor(alice,Y))Since ~parent(alice,Y) fails for Y == victoria_alberta we canconclude that ancestor(alice,victoria_alberta) is TRUE.

A AA AA

A AA A A

A AAA A

A

Page 33: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Exercise

Now we work with ( Y ~parent(alice,victoria_alberta) or ~ancestor(victoria_alberta,Y)) or ancestor(alice,Y))

~parent(alice,victoria_alberta) is FALSE and we already have alice as anancestor of victoria_alberta so we look for a Y that makes ~ancestor(victoria_alberta,Y) fail; Y == alice_mountbatten does this

This makes the only way the above quantified pedicate can be TRUE is if ancestor(alice,alice_mountbatten)is TRUE.

Continuing in this way we get all royals for whom alice is an ancestor.A

Page 34: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Monty Python: girls are witches.

View the video.

http://youtube.com/watch?v=UTdDN_MRe64

Page 35: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Example: Monty Python

A witch is a female who burns. Witches burn - because they're made of wood. Wood floats. What else floats on water? A duck; if something has the same weight as a duck it must float. A duck and scales are fetched. The girl and the duck balance perfectly. “Burn the witch!”

witch(X) :- female(X), burns(X).burns(X) :- floats(X).floats(wood).floats(duck).floats(X) :- sameWeight(duck,X).sameWeight(duck,girl).female(girl).

:- witch(girl)?

yes

Page 36: Chapter 3 – Set Theory. What is a Set? A set is a collection of distinguishable objects called elements. When writing out the elements of a set we use.

Exercise:

Give as many examples of faulty logic from the skit as you can find. Are any of them inverse or converse reasoning?


Recommended