Upload
vuongkhanh
View
223
Download
0
Embed Size (px)
Citation preview
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
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,…}
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
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}
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}
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}
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
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}}
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
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
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
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))]
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 = {}
18
Exercise 4
Intersection is commutative∀A∀B [ A ∩ B = B ∩ A ]
Proof: very similar to the one we just did. Try it yourself.
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)?
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:
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) ]
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
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
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
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 = Ø
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)
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
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?
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?
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))]
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>}