sets - cse.unl.educse.unl.edu/~choueiry/s17-235h/files/sets.pdf · sets sec’ons 2.1 and 2.2 of...
TRANSCRIPT
Sets
Sec'ons2.1and2.2ofRosenSpring2017
CSCE235HIntroduc7ontoDiscreteStructures(Honors)Courseweb-page:cse.unl.edu/~cse235h
Ques7ons:Piazza
SetsCSCE235 2
Nota7onandLaTeX• Asetisacollec7onofobjects.• Forexample:
– S={s1,s2,s3,…,sn}isafinitesetofnelements– S={s1,s2,s3,…}isainfinitesetofelements.
• s1∈Sdenotesthattheobjects1isanelementofthesetS• s1∉Sdenotesthattheobjects1isnotanelementofthesetS• LaTex
– $S=\{s_1,s_2,s_3,\ldots,s_n\}$– $s_i\inS$– $si\no7nS$
• Usingthepackage:\usepackage{amssymb}– Setofnaturalnumbers:$\mathbb{N}$– Setofintegernumbers:$\mathbb{Z}$– Setofra7onalnumbers:$\mathbb{Q}$– Setofrealnumbers:$\mathbb{R}$– Setofcomplexnumbers:$\mathbb{C}$
SetsCSCE235 3
Outline• Defini7ons:set,element• Terminologyandnota7on
• Setequal,mul7-set,bag,setbuilder,intension,extension,VennDiagram(representa7on),emptyset,singletonset,subset,propersubset,finite/infiniteset,cardinality
• Provingequivalences• Powerset• Tuples(orderedpair)• CartesianProduct(a.k.a.Crossproduct),rela7on• Quan7fiers• SetOpera7ons(union,intersec7on,complement,difference),Disjointsets• Setequivalences(cheatsheetorTable1,page130)
• Inclusioninbothdirec7ons• Usingmembershiptables
• GeneralizedUnionsandIntersec7on• ComputerRepresenta7onofSets
SetsCSCE235 4
Introduc7on(1)
• Wehavealreadyimplicitlydealtwithsets– Integers(Z),ra7onals(Q),naturals(N),reals(R),etc.
• Wewilldevelopmorefully– Thedefini7onsofsets– Theproper7esofsets– Theopera7onsonsets
• Defini'on:Asetisanunorderedcollec7onof(unique)objects
• Setsarefundamentaldiscretestructuresandforthebasisofmorecomplexdiscretestructureslikegraphs
SetsCSCE235 5
Introduc7on(2)
• Defini'on:Theobjectsinasetarecalledelementsormembersofaset.Asetissaidtocontainitselements
• Nota7on,forasetA:– x∈A:xisanelementofA$\in$– x∉A:xisnotanelementofA$\no7n$
SetsCSCE235 6
Terminology(1)
• Defini'on:Twosets,AandB,areequalistheycontainthesameelements.WewriteA=B.
• Example:– {2,3,5,7}={3,2,7,5},becauseasetisunordered– Also,{2,3,5,7}={2,2,3,5,3,7}becauseasetcontainsuniqueelements
– However,{2,3,5,7}≠{2,3}$\neq$
SetsCSCE235 7
Terminology(2)
• Amul7-setisasetwhereyouspecifythenumberofoccurrencesofeachelement:{m1⋅a1,m2⋅a2,…,mr⋅ar}isasetwhere– m1occursa17mes– m2occursa27mes– …– mroccursar7mes
• InDatabases,wedis7nguish– Aset:elementscannotberepeated– Abag:elementscanberepeated
SetsCSCE235 8
Terminology(3)
• Theset-buildernota7onS={x|(x∈Z)∧(x=2k)forsomek∈Z}
reads:Sisthesetthatcontainsallxsuchthatxisanintegerandxiseven
• Asetisdefinedinintensionwhenyougiveitsset-buildernota7on
S={x|(x∈Z)∧(0≤x≤8)∧(x=2k)forsomek∈Z}
• Asetisdefinedinextensionwhenyouenumeratealltheelements:
S={0,2,4,6,8}
SetsCSCE235 9
VennDiagram:Example
• AsetcanberepresentedgraphicallyusingaVennDiagram
U
a
x y
zA
C
B
SetsCSCE235 10
MoreTerminologyandNota7on(1)
• Asetthathasnoelementsiscalledtheemptysetornullsetandisdenoted∅$\emptyset$
• Asetthathasoneelementiscalledasingletonset.– Forexample:{a},withbrackets,isasingletonset– a,withoutbrackets,isanelementoftheset{a}
• Notethesubtletyin∅≠{∅}– Thelep-handsideistheemptyset– Therighthand-sideisasingletonset,andasetcontainingaset
SetsCSCE235 11
MoreTerminologyandNota7on(2)
• Defini'on:AissaidtobeasubsetofB,andwewriteA⊆B,ifandonlyifeveryelementofAisalsoanelementofB$\subseteq$
• Thatis,wehavetheequivalence:A⊆B⇔∀x(x∈A⇒x∈B)
SetsCSCE235 12
MoreTerminologyandNota7on(3)
• Theorem:ForanysetSTheorem1,page120– ∅⊆Sand– S⊆S
• Theproofisinthebook,anexcellentexampleofavacuousproof
SetsCSCE235 13
MoreTerminologyandNota7on(4)
• Defini'on:AsetAthatisasubsetofasetBiscalledapropersubsetifA≠B.
• Thatisthereisanelementx∈Bsuchthatx∉A• Wewrite:A⊂B,A⊂B• InLaTex:$\subset$,$\subsetneq$
SetsCSCE235 14
MoreTerminologyandNota7on(5)
• Setscanbeelementsofothersets• Examples
– S1={∅,{a},{b},{a,b},c}– S2={{1},{2,4,8},{3},{6},4,5,6}
SetsCSCE235 15
MoreTerminologyandNota7on(6)
• Defini'on:Ifthereareexactlyndis7nctelementsinasetS,withnanonnega7veinteger,wesaythat:– Sisafiniteset,and– ThecardinalityofSisn.Nota7on:|S|=n.
• Defini'on:Asetthatisnotfiniteissaidtobeinfinite
SetsCSCE235 16
MoreTerminologyandNota7on(7)
• Examples– LetB={x|(x≤100)∧(xisprime)},thecardinalityofBis|B|=25becausethereare25primeslessthanorequalto100.
– Thecardinalityoftheemptysetis|∅|=0– ThesetsN,Z,Q,Rareallinfinite
SetsCSCE235 17
ProvingEquivalence(1)• Youmaybeaskedtoshowthatasetis
– asubsetof,– propersubsetof,or– equaltoanotherset.
• ToprovethatAisasubsetofB,usetheequivalencediscussedearlierA⊆B⇔∀x(x∈A⇒x∈B)– ToprovethatA⊆Bitisenoughtoshowthatforanarbitrary
(nonspecific)elementx,x∈AimpliesthatxisalsoinB.– Anyproofmethodcanbeused.
• ToprovethatAisapropersubsetofB,youmustprove– AisasubsetofBand– ∃x(x∈B)∧(x∉A)
SetsCSCE235 18
ProvingEquivalence(2)
• Finallytoshowthattwosetsareequal,itissufficienttoshowindependently(muchlikeabicondi7onal)that– A⊆Band– B⊆A
• Logicallyspeaking,youmustshowthefollowingquan7fiedstatements:
(∀x(x∈A⇒x∈B))∧(∀x(x∈B⇒x∈A))wewillseeanexamplelater..
SetsCSCE235 19
PowerSet(1)
• Defini'on:ThepowersetofasetS,denotedP(S),isthesetofallsubsetsofS.
• Examples– LetA={a,b,c},P(A)={∅,{a},{b},{c},{a,b},{b,c},{a,c},{a,b,c}}– LetA={{a,b},c},P(A)={∅,{{a,b}},{c},{{a,b},c}}
• Note:theemptyset∅andthesetitselfarealwayselementsofthepowerset.ThisfactfollowsfromTheorem1(Rosen,page120).
SetsCSCE235 20
PowerSet(2)
• Thepowersetisafundamentalcombinatorialobjectusefulwhenconsideringallpossiblecombina7onsofelementsofaset
• Fact:LetSbeasetsuchthat|S|=n,then|P(S)|=2n
SetsCSCE235 21
Outline• Defini7ons:set,element• Terminologyandnota7on
• Setequal,mul7-set,bag,setbuilder,intension,extension,VennDiagram(representa7on),emptyset,singletonset,subset,propersubset,finite/infiniteset,cardinality
• Provingequivalences• Powerset• Tuples(orderedpair)• CartesianProduct(a.k.a.Crossproduct),rela'on• Quan'fiers• SetOpera7ons(union,intersec7on,complement,difference),Disjointsets• Setequivalences(cheatsheetorTable1,page130)
• Inclusioninbothdirec7ons• Usingmembershiptables
• GeneralizedUnionsandIntersec7on• ComputerRepresenta7onofSets
SetsCSCE235 22
Tuples(1)
• Some7mesweneedtoconsiderorderedcollec7onsofobjects
• Defini'on:Theorderedn-tuple(a1,a2,…,an)istheorderedcollec7onwiththeelementaibeingthei-thelementfori=1,2,…,n
• Twoorderedn-tuples(a1,a2,…,an)and(b1,b2,…,bn)areequaliffforeveryi=1,2,…,nwehaveai=bi(a1,a2,…,an)
• A2-tuple(n=2)iscalledanorderedpair
SetsCSCE235 23
CartesianProduct(1)• Defini'on:LetAandBbetwosets.TheCartesianproductof
AandB,denotedAxB,isthesetofallorderedpairs(a,b)wherea∈Aandb∈B
AxB={(a,b)|(a∈A)∧(b∈B)}• TheCartesianproductisalsoknownasthecrossproduct• Defini'on:AsubsetofaCartesianproduct,R⊆AxBiscalleda
rela7on.Wewilltalkmoreaboutrela7onsinthenextsetofslides
• Note:AxB≠BxAunlessA=∅orB=∅orA=B.Findacounterexampletoprovethis.
SetsCSCE235 24
CartesianProduct(2)
• CartesianProductscanbegeneralizedforanyn-tuple
• Defini'on:TheCartesianproductofnsets,A1,A2,…,An,denotedA1×A2×…×An,isA1×A2×…×An={(a1,a2,…,an)|ai∈Aifori=1,2,…,n}
\prod\limits_{i=1}^nA_i=A_1\7mesA_2\7mes\ldots\7mesA_n
nY
i=1
Ai = A1 ⇥A2 ⇥ . . .⇥An
SetsCSCE235 25
Nota7onwithQuan7fiers
• Wheneverwewrote∃xP(x)or∀xP(x),wespecifiedtheuniverseofdiscourseusingexplicitEnglishlanguage
• Nowwecansimplifythingsusingsetnota7on!• Example
– ∀x∈R(x2≥0)– ∃x∈Z (x2=1)– Alsomixingquan7fiers:
∀a,b,c∈R∃x∈C (ax2+bx+c=0)
SetsCSCE235 26
Outline• Defini7ons:set,element• Terminologyandnota7on
• Setequal,mul7-set,bag,setbuilder,intension,extension,VennDiagram(representa7on),emptyset,singletonset,subset,propersubset,finite/infiniteset,cardinality
• Provingequivalences• Powerset• Tuples(orderedpair)• CartesianProduct(a.k.a.Crossproduct),rela7on• Quan7fiers• SetOpera7ons(union,intersec7on,complement,difference),Disjointsets• Setequivalences(cheatsheetorTable1,page130)
• Inclusioninbothdirec7ons• Usingmembershiptables
• GeneralizedUnionsandIntersec7on• ComputerRepresenta7onofSets
SetsCSCE235 27
SetOpera7ons• Arithme7coperators(+,-,×,÷)canbeusedonpairsofnumberstogiveusnewnumbers
• Similarly,setoperatorsexistandactontwosetstogiveusnewsets– Union$\cup$– Intersec7on$\cap$– Setdifference$\setminus$– Setcomplement$\overline{S}$– Generalizedunion$\bigcup$– Generalizedintersec7on$\bigcap$
SetsCSCE235 28
SetOperators:Union
• Defini'on:TheunionoftwosetsAandBisthesetthatcontainsallelementsinA,B,orboth.Wewrite:
A∪B={x|(x∈A)∨(x∈B)}
U A B
SetsCSCE235 29
SetOperators:Intersec7on
• Defini'on:Theintersec7onoftwosetsAandBisthesetthatcontainsallelementsthatareelementofbothAandB.Wewrite:
A∩B={x|(x∈A)∧(x∈B)}U
A B
SetsCSCE235 30
DisjointSets
• Defini'on:Twosetsaresaidtobedisjointiftheirintersec7onistheemptyset:A∩B=∅
UA B
SetsCSCE235 31
SetDifference
• Defini'on:ThedifferenceoftwosetsAandB,denotedA\B($\setminus$)orA−B,isthesetcontainingthoseelementsthatareinAbutnotinB
UA B
SetsCSCE235 32
SetComplement
• Defini'on:ThecomplementofasetA,denotedA($\bar$),consistsofallelementsnotinA.ThatisthedifferenceoftheuniversalsetandU:U\A
A=AC={x|x∉A}
U A A
SetsCSCE235 33
SetComplement:Absolute&Rela7ve
• GiventheUniverseU,andA,B⊂U.• The(absolute)complementofAisA=U\A• The(rela7ve)complementofAinBisB\A
UAA
UBA
SetsCSCE235 34
SetIdendi7esLet’stakeaquicklookatthisCheatSheetoratTable1onpage130inyourtextbook
SetsCSCE235 35
ProvingSetEquivalences
• Recallthattoprovesuchiden7ty,wemustshowthat:1. Thelep-handsideisasubsetoftheright-handside2. Theright-handsideisasubsetofthelep-handside3. Thenconcludethatthetwosidesarethusequal
• Thebookprovesseveralofthestandardsetiden77es
• Wewillgiveacoupleofdifferentexampleshere
SetsCSCE235 36
ProvingSetEquivalences:ExampleA(1)
• Let– A={x|xiseven}– B={x|xisamul7pleof3}– C={x|xisamul7pleof6}
• ShowthatA∩B=C
SetsCSCE235 37
ProvingSetEquivalences:ExampleA(2)
• A∩B⊆C:∀x∈A∩B⇒ xisamul7pleof2andxisamul7pleof3⇒ wecanwritex=2.3.kforsomeintegerk⇒ x=6kforsomeintegerk⇒xisamul7pleof6⇒ x∈C
• C⊆A∩B:∀x∈C⇒ xisamul7pleof6⇒x=6kforsomeintegerk⇒ x=2(3k)=3(2k)⇒xisamul7pleof2andof3⇒ x∈A∩B
SetsCSCE235 38
ProvingSetEquivalences:ExampleB(1)
• Analterna7veproveistousemembershiptableswhereanentryis– 1ifachosen(butfixed)elementisintheset– 0otherwise
• Example:ShowthatA∩B∩C=A∪B∪C
SetsCSCE235 39
ProvingSetEquivalences:ExampleB(2)AB C A∩B∩C A∩B∩C A B C A∪B∪C
0 0 0 0 1 1 1 1 1
0 0 1 0 1 1 1 0 1
0 1 0 0 1 1 0 1 1
0 1 1 0 1 1 0 0 1
1 0 0 0 1 0 1 1 1
1 0 1 0 1 0 1 0 1
1 1 0 0 1 0 0 1 1
1 1 1 1 0 0 0 0 0
• 1underasetindicatesthat“anelementisintheset”• Ifthecolumnsareequivalent,wecanconcludethatindeed
thetwosetsareequal
SetsCSCE235 40
GeneralizingSetOpera7ons:UnionandIntersec7on
• Inthepreviousexample,weshowedDeMorgan’sLawgeneralizedtounionsinvolving3sets
• Infact,DeMorgan’sLawsholdforanyfinitesetofsets
• Moreover,wecangeneralizesetopera7onsunionandintersec7oninastraighyorwardmannertoanyfinitenumberofsets
SetsCSCE235 41
GeneralizedUnion
• Defini'on:Theunionofacollec7onofsetsisthesetthatcontainsthoseelementsthataremembersofatleastonesetinthecollec7on
$\bigcup_{i=1}^{n}A_i=A_1\cupA_2\cup\ldots\cupA_n$
n[
i=1
Ai = A1 [A2 [ . . . [An
SetsCSCE235 42
GeneralizedIntersec7on
• Defini'on:Theintersec7onofacollec7onofsetsisthesetthatcontainsthoseelementsthataremembersofeverysetinthecollec7on
LaTex:$\bigcap_{i=1}^{n}A_i=A_1\capA_2\cap\ldots\capA_n$
n\
i=1
Ai = A1 \A2 \ . . . \An
SetsCSCE235 43
ComputerRepresenta7onofSets(1)
• Therereallyaren’twaystorepresentinfinitesetsbyacomputersinceacomputerhasafiniteamountofmemory
• IfweassumethattheuniversalsetUisfinite,thenwecaneasilyandeffec7velyrepresentsetsbybitvectors
• Specifically,weforceanorderingontheobjects,say:U={a1,a2,…,an}
• ForasetA⊆U,abitvectorcanbedefinedas,fori=1,2,…,n– bi=0ifai∉A– bi=1ifai∈A
SetsCSCE235 44
ComputerRepresenta7onofSets(2)
• Examples– LetU={0,1,2,3,4,5,6,7}andA={0,1,6,7}– Thebitvectorrepresen7ngAis:11000011– Howistheemptysetrepresented?– HowisUrepresented?
• Setopera7onsbecometrivialwhensetsarerepresentedbybitvectors– Unionisobtainedbymakingthebit-wiseOR– Intersec7onisobtainedbymakingthebit-wiseAND
SetsCSCE235 45
ComputerRepresenta7onofSets(3)
• LetU={0,1,2,3,4,5,6,7},A={0,1,6,7},B={0,4,5}• Whatisthebit-vectorrepresenta7onofB?• Compute,bit-wise,thebit-vectorrepresenta7onofA∩B
• Compute,bit-wise,thebit-vectorrepresenta7onofA∪B
• Whatsetsdothesebitvectorsrepresent?
SetsCSCE235 46
ProgrammingQues7on
• Usingbitvector,wecanrepresentsetsofcardinalityequaltothesizeofthevector
• Whatifwewanttorepresentanarbitrarysizedsetinacomputer(i.e.,thatwedonotknowapriorithesizeoftheset)?
• Whatdatastructurecouldweuse?