logic and discrete math lecture notes set theoryzhang/teaching/cse240/spring10/sets.pdfset theory. 2...

33
1 Weixiong Zhang Washington University in St. Louis http://www.cse.wustl.edu/~zhang/teaching /cse240/Spring10/index.html CSE 240 Logic and Discrete Math Lecture notes Set Theory

Upload: others

Post on 05-Jul-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

1

Weixiong ZhangWashington University in St. Louis

http://www.cse.wustl.edu/~zhang/teaching/cse240/Spring10/index.html

CSE 240Logic and Discrete Math

Lecture notes Set Theory

Page 2: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

2

Coverage

Textbook 5.1, 5.2, 5.3

Reading assignmentChapter 5 of the textbook

Page 3: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

3

Sets

What is a set?A collection of elements:

Order is irrelevantNo repetitionsCan be infiniteCan be empty

Examples:{Angela, Belinda, Jean}{0,1,2,3,…}

Page 4: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

4

Operations on setsS is a setMembership:

x∈Sx is an element of SAngela∈{Angela, Belinda, Jean}

Subset:S1 ⊆ SSet S1 is a subset of set SAll elements of S1 are elements of S{Angela,Belinda} ⊆ {Angela, Belinda, Jean}

Proper subset S1⊂S

Page 5: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

5

Operations on sets

S, S1 are setsEquality:

S = S1

iff they have the same elements Difference:

S \ S1

is a set of all elements that belong to S but NOT to S1

{Angela, Belinda, Jean} \ {Angela,Dana} = {Belinda, Jean}

Page 6: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

6

Operations on sets

S, S1 are setsIntersection:

S ∩ S1

is a set of all elements that belong to both {Angela, Belinda, Jean} ∩ {Angela,Dana} = {Angela}

Union:S ∪ S1

is a set of all elements that belong to either {Angela, Belinda, Jean} ∪ {Angela,Dana} = {Angela,Belinda,Jean,Dana}

Page 7: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

7

More notation

In mathematics sets are often specified with a predicate and an enveloping set as follows:

S={x∈A | P(x)}S is the set of all elements of A that satisfy predicate P

Example:Q={x∈R | ∃a,b∈Z b≠0 & x=a/b}

Page 8: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

8

Set Equality

Two sets are equal iff they have the same elements

Def: for any sets A and B, A=B iff A⊆B & B⊆A

Page 9: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

9

Subset and Membership

Book example 5.1.52∈{1,2,3} ?{2}∈{1,2,3} ?2⊆{1,2,3} ?{2}⊆{1,2,3} ?{2}⊆{{1},{2}} ?{2}∈{{1},{2}} ?

How about set A such that {2} is a subset of it and A is an element of it?

A={1,2,{1},{2}}

Page 10: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

10

Universal Set

If we are dealing with sets which are all subsets of a larger set U then we call it a universal set UAll of your sets will be subsets of U

When does such a U exist?Always, for we can set U to the union of all sets involved

Page 11: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

11

Complement

So if I am dealing with set A which is a subset of the universal set U then:I can define complement of A:

AC=U\A

That is the set of all elements (of U) that are not in AOften “of U” is dropped and people say that AC is the set of everything that is not in A

Page 12: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

12

Quick questions

What is the complement of U?UC = Ø

What set has U as its complement?ØC=U

Page 13: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

13

Sets & Predicate Logic

All of the set operations and relations above can be defined in terms of Boolean connectives:

A∪B={x | x∈A v x∈B}A∩B={x | x∈A & x∈B}A\B={x | x∈A & not x∈B}AC={x | not x∈A}

A=B iff ∀x x∈A ⇔ x∈BA⊆B iff ∀x x∈A ⇒ x∈BA⊂B iff (∀x x∈A ⇒ x∈B) & not A=B

Page 14: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

14

Symmetric Difference

Set C is the symmetric difference of sets A and B iff every element of C belongs to A or B but not both

∀A∀B∀C [C=A ∆ B ⇔ ∀a (a∈C ⇔(a∈A xor a∈B))]

Page 15: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

15

Examples

A={1,2}, B={2,3}A ∆ B={1,3}

A={Clinton,Reagan}, B={Gorbachov,Bregnev}A ∆ B={Clinton,Reagan,Gorbachov,Bregnev}

A={CSE240 students}, B={CSE240 students}A ∆ B = {}

In general: A ∆ A = {}

Page 16: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

16

Exercise 2Intersection of two sets is contained in their union: ∀A∀B [ (A ∩ B) ⊆ (A ∪ B) ]Proof:

Page 17: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

17

Exercise 3Union is commutative

∀A∀B [ A ∪ B = B ∪ A ]

Page 18: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

18

Exercise 4

Intersection is commutative∀A∀B [ A ∩ B = B ∩ A ]

Proof: very similar to the one we just did. Try it yourself.

Page 19: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

19

Exercise 5Intersection distributes over union:∀A∀B∀C [ A ∩ (B ∪ C) =(A ∩ B) ∪ (A ∩ C) ]

There is an analogy between logical operations v and &and arithmetic operations:

v feels like +& feels like *So A & (B v C) = A & B v A & C[just like A*(B+C) = A*B + A*C]How about A+(B*C) --- is it (A+B)*(A+C)?NOSo what about A v (B & C) = (A v B) & (A v C)?

Page 20: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

20

The AnalogyThe analogy is incomplete:

Arithmetic: A+(B*C) ≠ (A+B)*(A+C)Logic: A v B&C = (A v B) & (A v C)

Proof of the latter:

Page 21: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

21

Exercise 6In Exercise #5 we proved:

∀A∀B∀C [ A ∩ (B ∪ C) =(A ∩ B) ∪ (A ∩ C) ]

using the fact that A&(B v C)=A&B v A&C

Given the statement just proved A v B&C = (A v B) & (A v C)

what can we now prove in terms of sets?

Union distributes over intersection:∀A∀B∀C [ A ∪ (B ∩ C) =(A ∪ B) ∩ (A ∪ C) ]

Page 22: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

22

Proof of Exercise 6

Page 23: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

23

More IdentitiesSee Theorem 5.2.2 in the book (study it and understand it)The proofs can often be done using:

the logical definitions of set operationslogical identities we have proven before

Using Venn diagramUnderstand propertiesFind solutions or proofs

I recommend doing some/all of them as an exercise

Page 24: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

24

Boolean Algebra

Are these similarities between set identities and logical identities incidental?

It turns out that both systems are examples of a more general construct called Boolean algebra

Page 25: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

25

Boolean AlgebraBoolean algebra is given by a set S and two operations: + and * defined over it such that the following identities hold (here a and b are arbitrary elements of S):

a+b=b+aa*b=b*a(a+b)+c=a+(b+c)(a*b)*c=a*(b*c)a*(b+c)=a*b+a*ca+(b*c)=(a+b)*(a+c)

There exist distinct 0,1 in S: a+0=aa*1=a

For each a from S there exists a complement a’ such that:a+a’=1a*a’=0

Page 26: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

26

Boolean Algebra - Logic - SetsS {true,false} P(U) (i.e., all sets)+ v ∪* & ∩a+b=b+a avb=bva a∪b=b∪aa*b=b*a a&b=b&a a∩b=b∩a(a+b)+c=a+(b+c) (avb)vc=av(bvc) (a∪b)∪c=a∪(b∪c)(a*b)*c=a*(b*c) (a&b)&c=a&(b&c) (a∩b)∩c=a∩(b∩c)a*(b+c)=(a*b)+(a*c) a&(bvc)=(a&b)v(a&c) a∩(b∪c)=(a∩b)∪(a∩c)a+(b*c)=(a+b)*(a+c) av(b&c)=(avb) & (avc) a∪(b∩c)=(a∪b)∩(a∪c)0 false Ø1 true Ua+0=a a v false = a a ∪ Ø = aa*1=a a & true = a a ∩ U = acomplement (a’) ~a aC

a+a’=1 a v ~a = true a ∪ aC = Ua*a’=0 a & ~a = false a ∩ aC = Ø

Page 27: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

27

Notes

How about numbers with addition and multiplication? Do they form a Boolean algebra?

Not quite

Why are these 5 groups of identities (page 266 in the book) important?

Other standard identities of any Boolean algebra (including Boolean logic and sets can be derived from them)

Page 28: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

Lecture 18 © Vadim Bulitko : CMPUT 272, Winter 2004, UofA 28

Cartesian Products

Intuition first:Suppose I have a function that takes two numbers x and y and returns x/yWhat is the set of valid inputs?Is it just R?

No -- cannot divide by 0

Is it R\{0}?No -- can happily have 0 as x

Page 29: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

Lecture 18 © Vadim Bulitko : CMPUT 272, Winter 2004, UofA 29

Combinations

Suppose I have:two independent attributes: sky conditions and temperaturetwo values for the sky conditions S={sunny, overcast};three values for the precipitation: P={snow, rain, nothing}.

How many combinations can I have?

Page 30: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

Lecture 18 © Vadim Bulitko : CMPUT 272, Winter 2004, UofA 30

Combinations - 26 combinations:

<sunny, rain><sunny, snow><sunny, nothing><overcast, rain><overcast, snow><overcast, nothing>

So the set of these 6 pairs is somehow a result of the original sets S and PWhat is this operation?

Page 31: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

Lecture 18 © Vadim Bulitko : CMPUT 272, Winter 2004, UofA 31

Cartesian Product

Set C is a Cartesian Product of set A and set B iff it is a set of all ordered pairs such that the 1st

element belongs to A and the 2nd

element belongs to B

∀A∀B∀C [C=A × B ⇔∀a∀b (<a,b>∈C ⇔ (a∈A & b∈B))]

Page 32: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

Lecture 18 © Vadim Bulitko : CMPUT 272, Winter 2004, UofA 32

ExamplesA={0,1}, B={Angela,Belinda}A×B = {<0,Angela>, <0,Belinda>, <1,Angela>, <1, Belinda>}

A={0,1}, B={Angela,Belinda}B×A = {<Angela,0>, <Belinda,0>, <Angela,1>, <Belinda,1>}

A={0}, B={a,b}, C={1,2}A×B×C={<0,a,1>,<0,b,1>, <0,a,2>,<0,b,2>}

Page 33: Logic and Discrete Math Lecture notes Set Theoryzhang/teaching/cse240/Spring10/Sets.pdfSet Theory. 2 Coverage Textbook 5.1, 5.2, 5.3 Reading assignment Chapter 5 of the textbook. 3

Lecture 18 © Vadim Bulitko : CMPUT 272, Winter 2004, UofA 33

More examples

A=B=C=D=R (set of all real numbers)A×B×C×D=R4 (time-space continuum)

What is the cardinality of Cartesian Product?

|A1 × … × An|=|A1| · … · |An| for finite sets

How about {} × {1,2}?{} × {1,2}={}