sets and logic - villanova universitymap/1300/s17/chap02setslogic.pdf · sets and logic csc 1300...

Post on 06-Sep-2018

236 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

SetsandLogic

CSC1300–DiscreteStructuresVillanovaUniversity

VillanovaCSC1300-DrPapalaskari

MajorThemes•  Sets

– Waysofdefiningsets–  Subsets,complements,theuniversalset–  Venndiagrams–  Proofsofsetequalityviadoubleinclusion

•  Logic–  ProposiJons–  Truthtables–  Venndiagrams– QuanJfiers–  Prooftechniques:direct,indirect,contradicJon

VillanovaCSC1300-DrPapalaskari

BasicterminologyAsetisanunorderedcollecJonofdisJnctobjectscalledelementsormembersoftheset.ThecardinalityofafinitesetSisdenoted|S|.ThenotaJonx∈S—means“xisanelementofS” Example:S={2,4,6,8},|S|=42∈S—“2isanelementofS”3∉S—“3isnotanelementofS”Example:S={{2,4},{6},8},|S|=3{2,4}∈S—“{2,4}isanelementofS”2∉S—“2isnotanelementofS”Amul0setorabagisanunorderedcollecJonofobjectsthatarenotnecessarilydisJnct.

VillanovaCSC1300-DrPapalaskari

Someimportantsets

•  ℕ={1,2,3,…}-thesetofnaturalnumbers•  ℤ={…,-2,-1,0,1,2,…}-thesetofintegers•  𝕎={0,1,2,3,…}-thesetofposi0veintegers•  ℤ2={0,1}-thebinarydigits•  ℝ-thesetofrealnumbers•  ℚ={x|x=p/qwherep,q∈Z,q≠0}-thesetofra0onalnumbers

•  Theempty(ornull)set,denotedby∅,or{}.VillanovaCSC1300-DrPapalaskari

Describingsets

Twowaystodescribeaset:1. BylisJngelements,e.g.,S={2,4,6,8}

2. Byaproperty,e.g.,T={x|xisanevenposiJveinteger}

VillanovaCSC1300-DrPapalaskari

SubsetsSisasubsetofT,denotedS⊆T,iffeveryelementofSisalsoanelementofT.Examples:{a,b}⊆{a,b,c}{a,b,c}⊆{a,b,c}

ℤ ⊆ ℚS⊆S(foreveryS)∅⊆S (foreveryS)SisapropersubsetofT,denotedS⊂T,iffSisasubsetofTbutnotviceversa.Examples:{a,b}⊂{a,b,c}{b}⊂{a,b,c}whatabout∅⊂S???NotethatS⊂TiffS⊆TandS≠T

VillanovaCSC1300-DrPapalaskari

ThePowerSet

VillanovaCSC1300-DrPapalaskari

ThepowersetofasetSisthesetofallsubsetsofS.ThepowersetofSisdenotedbyP(S).

P(∅)={∅}

P({a})={∅,{a}}

P({a,b})={∅,{a},{b},{a,b}}

P({0,1,2})={∅,{0},{1},{2},{0,1},{0,2},{1,2},{0,1,2}}

Notethat|P(S)|=2|S|

Setequality

TwosetsSandTareequal,denotedS=T,ifftheyhavethesameelements,i.e.,foreveryx:ifx∈Sthenx∈Tandifx∈Tthenx∈SInotherwords:

S=TiffS⊆TandT⊆S

VillanovaCSC1300-DrPapalaskari

Prooftechnique:doubleinclusion

Setequality

Examples:

•  {a,b}={b,a}

•  {1,2,3}={x|xisanintegerand0<x<4}

•  {2,4,6}={x|x=2*y,wherey∈{1,2,3}}

VillanovaCSC1300-DrPapalaskari

TheUniversalSet

VillanovaCSC1300-DrPapalaskari

TwosetsSandTareequal,denotedS=T,ifftheyhavethesameelements,i.e.,foreveryx:ifx∈Sthenx∈Tandifx∈Tthenx∈S

Whatdoesthisevenmean????

TwosetsSandTareequal,denotedS=T,ifftheyhavethesameelements,i.e.,foreveryx:ifx∈Sthenx∈Tandifx∈Tthenx∈S

TheUniversalSetUWeusuallythinkofsetsassubsetsofauniversalsetU.•  Example:{a,b}and{b,d,e}èU={a,b,c,d,e}

(ormaybeU={a,b,c,d,e,f,g,…,z}-usuallydeterminedbycontext)ThecomplementofS,denotedSisthesetofelementsofUthatarenotinS.Example:{b,d,e}={a,c}Thesetdifference,denotedS–T(orS\T),isthesetofelementsofSthatareNOTalsoinT.Examples:{a,b,c,d,e}–{b,d,e}={a,c}(Note:S=U–S)

{b,c}–{a,b}={c}

VillanovaCSC1300-DrPapalaskari

Venndiagrams

VillanovaCSC1300-DrPapalaskari

U

S T S⊆T

S TS T

disjointsetsSandTSandTarenotdisjoint

U U

SetUnionandIntersecJon

VillanovaCSC1300-DrPapalaskari

S∪T ={x|x∈Sorx∈T} S∩T={x|x∈Sandx∈T}

S T S T

S∪Tisshaded S∩Tisshaded

Example:LetS={1,2,3,4}andT={2,3,5}.Then

S∪T={1,2,3,4,5} S∩T= {2,3}

U U

Setdifferenceandcomplement

VillanovaCSC1300-DrPapalaskari

S–T ={x|x∈Sandx∉T}

S T

S =U-S

S

U U

Example:LetU=NS={x|xisanintegergreaterthan6}T={x|xisanevenposiJveinteger}

ThenS-T={x|xisanoddintegergreaterthan6}S={x|xisanintegerlessthanorequalto6}

GeneralizedunionsandintersecJons

VillanovaCSC1300-DrPapalaskari

S1∩S2∩...∩Sndenotedby∩Sii=1

n

S1∪S2∪...∪Sndenotedby∪Si i=1

n

i=1

n

∩Si=and∪Si=i=1

n

Example:LetSi={i}.

Generalizedunions/intersecJons

VillanovaCSC1300-DrPapalaskari

AnotherExample:LetAi={k|k=p / i,p∈ℤ}.

n

∩Ai =and∪Ai=i=1i=1

n

Setsandcardinality

LetA={a,b,c},B={1,2}cardinalityofaset=numberofmembers

|A|=3|B|=2

AUB={a,b,c,1,2}AB=∅U

SumPrinciple:IfAandBaredisjoint |AUB|=|A|+|B|

VillanovaCSC1300-DrPapalaskari

review

Setsandcardinality

LetA={a,b,c,d,e},B={b,d}|A|=5

|B|=2A\B={a,c,e}DifferencePrinciple:IfA⊆B,

|A\B|=|A|-|B| VillanovaCSC1300-DrPapalaskari

Cartesianproduct

LetA={a,b,c},B={1,2}Thecartesianproductisthesetoforderedpairs(x,y)wherexεAandyεB:AxB={(a,1),(a,2),(b,1),(b,2),(c,1),(c,2)}

ProductPrinciple:|AxB|=|A|·|B|

VillanovaCSC1300-DrPapalaskari

review

Orderedpairsandn-tuples

VillanovaCSC1300-DrPapalaskari

orderedpairs(a1,a2)andorderedn-tuples(a1,a2,…,an)•  representsequenceswheretheorderofelements

doesmamerandrepeJJonsareallowed.

TheCartesianproductofthesetsS1,S2,…,Sn,denotedbyS1×S2×…×Sn,isthesetofallorderedn-tuples(s1,s2,…,sn)wheres1∈S1,s2∈S2,…,sn∈Sn.Inotherwords,S1×S2×…×Sn={(s1,s2,…,sn)|s1∈S1ands2∈S2and…andsn∈Sn}

SetidenJJes

VillanovaCSC1300-DrPapalaskari

S∪∅=SIdenJtyS∩U=SlawsS∪U=UDominaJonS∩∅=∅lawsS∪S=SIdempotentS∩S=SlawsS∪T=T∪SCommutaJveS∩T=T∩Slaws

ComplementaJon(S)=Slaw

S∪(T∪R)=(S∪T)∪RAssociaJveS∩(T∩R)=(S∩T)∩RlawsS∩(T∪R)=(S∩T)∪(S∩R)DistribuJveS∪(T∩R)=(S∪T)∩(S∪R)lawsS∪T=S∩TDeMorgan’sS∩T=S∪Tlaws

|S∪T|=|S|+|T|-|S∩T|Inclusion-exclusion

ProvingsetidenJJes-example

VillanovaCSC1300-DrPapalaskari

ProvethatS∩T=S∪T(deMorgan’sLawforsets).Proof:Weproceedbyshowingthateachsetisasubsetoftheother,i.e.S∩T⊆S∪TandS∪T⊆S∩T

1.Supposex∈S∩T. i.e.x∉S∩T. Thenx∉Sorx∉T.

Hence,x∈Sorx∈T. Thismeansthatx∈S∪T.

Thus,S∩T⊆S∪T.

2.Nowsupposex∈S∪T. Thenx∈Sorx∈T.Hencex∉Sorx∉T, whichmeansthatx∉S∩T.Therefore,x∈S∩T. Thus,S∪T⊆S∩T.

MajorThemes

•  Sets– Waysofdefiningsets–  Subsets,complements,theuniversalset–  Venndiagrams–  Proofsofsetequalityviadoubleinclusion

•  Logic–  ProposiJons–  Truthtables–  Venndiagrams– QuanJfiers

VillanovaCSC1300-DrPapalaskari

WhyLogic?

Logic–ascienceofreasoning

• BasisofmathemaJcalreasoning-givesprecisemeaningtomathemaJcalstatements-isusedtodisJnguishbetweenvalidandinvalidmathemaJcalarguments

• ApplicaJonsinCS:-designofhardware-programming-arJficialintelligence-databases

VillanovaCSC1300-DrPapalaskari

Adeclara0vestatementthatiseithertrueorfalseArethefollowingproposi0ons?• 1+2=3• todayismybirthday• NewYorkisthecapitaloftheUSA• 5-3+2• x+y>5• Areyouastudent?• Don’ttalk• Yourfeetareugly• Thissentenceisfalse

ProposiNon

VillanovaCSC1300-DrPapalaskari

Compoundproposi3onsareformedfromsimplerproposiJonsusingconnec3ves,alsocalledlogicaloperators.

TheconnecJveswewillstudyare:• nega3onornotoperatordenoted¬• conjunc3onorandoperator∧ • disjunc3onororoperator∨• exclusiveororxoroperator⊕• implica3on→• bicondi3onal↔

CompoundProposiNonsandConnecNves

VillanovaCSC1300-DrPapalaskari

NegaNonIfpisaproposiJon,thenthestatement

“Itisnotthecasethatp”isanotherproposiJon,calledthenega3onofp.ThenegaJonofp,denotedby¬pandread“notp”,istruewhenpisfalse,andisfalsewhenpistrue.

Example:WhatisthenegaJonof“TodayisWednesday”?

ThetruthtablefornegaJon:p¬pTF

VillanovaCSC1300-DrPapalaskari

ConjuncNonTheproposiJon“pandq”,denotedbyp∧q,iscalledtheconjunc3onofpandq.Itistruewhenbothpandqaretrue,otherwiseitisfalse.

pqp∧qTTTFFTFF

ThetruthtableforconjuncJon:

Examples:TodayisWednesdayanditisraining.TodayisWednesdaybutitisnotraining.

VillanovaCSC1300-DrPapalaskari

DisjuncNonTheproposiJon“porq”,denotedbyp∨q,iscalledthedisjunc3onofpandq.Itisfalsewhenbothpandqarefalse,otherwiseitistrue.

ThetruthtablefordisjuncJon:pqp∨qTTTFFTFF

Example:TodayisSundayoraholiday.

VillanovaCSC1300-DrPapalaskari

ExclusiveOR(XOR)

TheproposiJonp⊕qiscalledtheexclusiveorofpandq.Itistruewhenexactlyoneofpandqistrue,otherwiseitisfalse.

Thetruthtableforexclusiveor:

pqp⊕qTTTFFTFF

Example:Thisdishcomeswithsouporsalad.

VillanovaCSC1300-DrPapalaskari

ImplicaNonTheimplica3onorcondi3onalproposi3onp→qistheproposiJonthatisfalseonlywhenpistrueandqisfalse.piscalledthehypothesisandqiscalledtheconclusion.

ThetruthtableforimplicaJon:pqp→qTTTFFTFF

Readingsforp→q:• “ifpthenq”• “ponlyifq”• “qisnecessaryforp”• “pissufficientforq”• “pimpliesq”• “qifp”• “qwheneverp”

VillanovaCSC1300-DrPapalaskari

ExamplesofImplicaNonWording

IfJohnisinL.A.,thenheisinCalifornia.

TobeinCalifornia,it issufficientforJohntobeinL.A.

TobeinLA,it isnecessaryforJohntobeinCalifornia.

YouwillgetanAifyoustudyhard.vs.YouwillgetanAonlyifyoustudyhard.

VillanovaCSC1300-DrPapalaskari

MoreExamplesofImplicaNonwording:

Ifyouplaceyourorderby11:59pmDecember21st,thenweguaranteedeliverybyChristmas.

Placingyourorderby11:59pmDecember21stguaranteesdeliverybyChristmas.

WeguaranteedeliverybyChristmasifyouplaceyourorderby11:59pmDecember21st.

VillanovaCSC1300-DrPapalaskari

MoreExamplesofImplicaNonwording:

Ifyouplaceyourorderby11:59pmDecember21st,thenweguaranteedeliverybyChristmas.

Placingyourorderby11:59pmDecember21stguaranteesdeliverybyChristmas.

WeguaranteedeliverybyChristmasifyouplaceyourorderby11:59pmDecember21st.

WeguaranteedeliverybyChristmasonlyifyouplaceyourorderby11:59pmDecember21st.

isthisthesametoo?

VillanovaCSC1300-DrPapalaskari

BicondiNonal

Thebicondi3onalp↔qistheproposiJonthatistruewhenpandqhavethesametruthvalues,andisfalseotherwise.

ThetruthtableforbicondiJonal:

pqp↔qTTTFFTFF

Readingsforp↔q:• “pifandonlyifq”• “pisnecessaryandsufficientforq”• “ifp,thenq,andconversely”

VillanovaCSC1300-DrPapalaskari

TruthtablesformorecomplexproposiNons

pqrr∨(q∧¬p)TTTTTFTFTTFFFTTFTFFFTFFF

VillanovaCSC1300-DrPapalaskari

Tautology

pqr(¬p∧(p∨q))→qTTTTTFTFTTFFFTTFTFFFTFFF

-A(compound)proposi0onthatisalwaystrue(irrespec0veofthevaluesofitscomponents)

VillanovaCSC1300-DrPapalaskari

LogicalEquivalence

pq¬p∨qp→qTTTFFTFF

•  wewrite:¬p∨q≡p→qtoindicatethattheproposiJons¬p∨qandp→qarelogicallyequivalent

Wesaythattwoproposi3onsarelogicallyequivalentifftheyhavethesametruthtable.

VillanovaCSC1300-DrPapalaskari

DeMorgan’sLawsforLogic

FirstDeMorgan’slawforlogic:¬(p∨q)≡(¬p)∧(¬q)

Example:Negate:“TodayisSundayoraholiday”

SecondDeMorgan’slawforlogic:¬(p∧q)≡Example:Negate:“TodayisSundayandaholiday”

VillanovaCSC1300-DrPapalaskari

Converse,InverseandContraposiNve

• q→piscalledtheconverseofp→q• ¬p→¬qiscalledtheinverseofp→q• ¬q→¬piscalledthecontraposi3veofp→q

pqp→qq→p¬p→¬q¬q→¬pTTTFFTFF

Whichoftheabovearelogicallyequivalent?

VillanovaCSC1300-DrPapalaskari

ProposiNonalfuncNonsInteresJngstatementsinvolvevariables.DefiniNonAproposi0onalfunc0onP(x)isafuncJonwhosevaluesareproposiJons,i.e.,it’sanassignmenttoeachelementxofthefuncJon’sdomainDcalledthedomainofdiscourseaproposiJon(atrueorfalsestatement).ExampleLetP(x)denotethestatement“xiseven”.

Domainofdiscourse?P(2)

P(3)VillanovaCSC1300-DrPapalaskari

UniversalquanNfier

DefiniNon:universalquan0fica0onofP(x)“P(x)istrueforallvaluesofxinitsuniverseofdiscourse”

“forallxP(x)”

“foreveryxP(x)”∀xP(x)universalquan0fier

VillanovaCSC1300-DrPapalaskari

ExamplesofuniversalquanNficaNon∀x(x+0=x)∀x(x2>x)∀xP(x)whereP(x)denotesthestatement“xlovesCS”

Let M(x) denote “x is mortal” and H(x) denote “x is a human”

Express the proposition: “every human is mortal”

VillanovaCSC1300-DrPapalaskari

ExistenNalquanNfier

DefiniNon:existen0alquan0fica0onofP(x)“thereexistsanelementxinitsuniverseofdiscoursesuchthatP(x)istrue”

“thereisanxsuchthatP(x)”

“forsomexP(x)”

∃xP(x)existen0alquan0fier.

VillanovaCSC1300-DrPapalaskari

ExamplesofexistenNalquanNficaNon

Trueorfalse?

∃x(x+x=x*x)

∃x(x=x+1)

∃xP(x)whereP(x)denotesthestatement“xlovesmath”

VillanovaCSC1300-DrPapalaskari

Let Q(x) denote “x is a sophomore” Express the proposition: “there is a sophomore who loves math”

GeneralizedDeMorganLawsofLogic

• ¬∀xP(x)≡∃x¬P(x)“NoteveryonelovesCS”≡“ThereissomeonewhodoesnotloveCS”

• ¬∃x¬P(x)≡∀x¬¬P(x)≡∀xP(x)

“ThereisnoonewhodoesnotloveCS”≡“EveryonelovesCS” VillanovaCSC1300-DrPapalaskari

ExpressionswithseveralquanNfiers

Lettheuniverseofdiscoursebethesetofallstudents(ofVU).Let

C(x)means“xhasacomputer”F(x,y)means“xandyarefriends”

TranslatethefollowingintoEnglish:

• ∀xC(x)

• ∃x¬∃yF(x,y)

• ∀x[C(x)∨∃y(F(x,y)∧C(y))]

VillanovaCSC1300-DrPapalaskari

DoestheorderofthequanNfiersmaber?

—No,ifwehaveseveralconsecuJvequanJfiersofthesametype:∀x∀yQ(x,y)≡∀y∀xQ(x,y)∃x∃yQ(x,y)≡∃y∃xQ(x,y)—Yes,ifwehavedifferentquanJfiers:∀x∃yQ(x,y)≡∃y∀xQ(x,y)

Counterexample:LetQ(x,y)mean“x+y=0”,andlettheuniverseofdiscoursebethesetofallrealnumbers.Whatisthetruthvalueof:

∀x∃yQ(x,y)?∃y∀xQ(x,y)? VillanovaCSC1300-DrPapalaskari

theorems

proved to be true

MathemaJcalSystem

axioms

assumed to be true

definitions

used to create terms

Logic is a tool for the analysis

of inference

VillanovaCSC1300-DrPapalaskari

BasicTerminology

•  Axiom (postulate) – underlying assumption, does not require a proof •  Rules of inference – used to draw conclusions from other assertions •  Proof of a statement A – a sequence of statements, each of which is:

• an axiom or • follows from one or more earlier statements

and the last statement in the sequence is A

•  Informal proof vs. formal – uses rules of inference informally and formally, respectively

•  Theorem – a statement that has been proved

•  Lemma – a theorem used in the proof of other theorems •  Corollary – a theorem that immediately follows from another theorem

VillanovaCSC1300-DrPapalaskari

Typesofproofsn  direct n  indirect (by contrapositive)

n  by contradiction

n  proof of equivalence

n  proof by cases n  proof by mathematical induction

VillanovaCSC1300-DrPapalaskari

Provingp → q

•  DirectProof

•  IndirectProof/ContraposiJve

•  ProofbyContradicJon

p → q

p → q ≡ ¬ q → ¬ p

p → q ≡ (p ∧ ¬ q) → (r ∧ ¬ r)

VillanovaCSC1300-DrPapalaskari

DirectProof

Toprovep → q:Supposepistrue;provethatqmustalsobetrue

Example: If n is even, then n2 is also even

VillanovaCSC1300-DrPapalaskari

IndirectProof

Provep → qbyprovingcontraposi0ve:¬ q → ¬ pExample: If n·m is odd, then an n×m grid cannot be tiled with

dominoes.

VillanovaCSC1300-DrPapalaskari

ContradicJonProof

Provesbyshowingthat¬sisabsurd!•  ¬s→F(Reduc0oadabsurdum)Example:

VillanovaCSC1300-DrPapalaskari

Proofsofequivalence

A proof of equivalence of two assertions (i.e., p ↔ q), often stated by using “if and only if” or “necessary and sufficient,” requires two separate parts:

p → q and q → p. • Example: An integer n is odd iff n2 is odd.

VillanovaCSC1300-DrPapalaskari

ProofsbycasesA proof by cases is based on partitioning the theorem’s domain into subdomains and proving the theorem separately for each of these subdomains. Definition: ⌊x⌋, called the floor of x, is the largest integer ≤ x; ⌈x⌉, called the ceiling of x, is the smallest integer ≥ x. Example:

VillanovaCSC1300-DrPapalaskari

Proofs,examples,andcounterexamples:∀xP(x)

For universal statements:

• Checking validity of a theorem for specific examples does NOT constitute a proof (unless the examples exhaust all the values in the theorem’s domain, which is impossible if the latter is infinite).

•  Just a single example suffices to disprove a theorem. (Such an example is usually called a counterexample).

VillanovaCSC1300-DrPapalaskari

Proofs,examples,andcounterexamples∃x P(x)

For existential statements:

• A single example suffices to prove the theorem (constructive proof).

• Alternatively, using contradiction, prove that it is not possible for such a thing not to exist. (non-constructive proof) • Show that a player in a game has a winning strategy without actually saying what it is! • Famous proof: There exist irrational x, y such that xy is rational

VillanovaCSC1300-DrPapalaskari

WhichProofMethod?

1.  Beginwithadirectproofapproach2.  Ifthisfails,tryeither

–  indirect/contraposiJveapproach–  proofbycontradicJon–  proofbycases–  acombinaJon...

VillanovaCSC1300-DrPapalaskari

MajorThemes•  Sets

– Waysofdefiningsets–  Subsets,complements,theuniversalset–  Venndiagrams–  Proofsofsetequalityviadoubleinclusion

•  Logic–  ProposiJons–  Truthtables–  Venndiagrams– QuanJfiers–  Prooftechniques:direct,indirect,contradicJon

VillanovaCSC1300-DrPapalaskari

top related