61
Sets and Logic CSC 1300 – Discrete Structures Villanova University Villanova CSC 1300 - Dr Papalaskari

Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

  • Upload
    lemien

  • View
    235

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

SetsandLogic

CSC1300–DiscreteStructuresVillanovaUniversity

VillanovaCSC1300-DrPapalaskari

Page 2: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

MajorThemes•  Sets

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

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

VillanovaCSC1300-DrPapalaskari

Page 3: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 4: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 5: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

Describingsets

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

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

VillanovaCSC1300-DrPapalaskari

Page 6: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 7: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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|

Page 8: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

Setequality

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

S=TiffS⊆TandT⊆S

VillanovaCSC1300-DrPapalaskari

Prooftechnique:doubleinclusion

Page 9: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 10: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 11: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 12: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

Venndiagrams

VillanovaCSC1300-DrPapalaskari

U

S T S⊆T

S TS T

disjointsetsSandTSandTarenotdisjoint

U U

Page 13: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 14: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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}

Page 15: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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}.

Page 16: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

Generalizedunions/intersecJons

VillanovaCSC1300-DrPapalaskari

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

n

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

n

Page 17: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 18: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 19: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 20: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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}

Page 21: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 22: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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.

Page 23: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

MajorThemes

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

•  Logic–  ProposiJons–  Truthtables–  Venndiagrams– QuanJfiers

VillanovaCSC1300-DrPapalaskari

Page 24: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

WhyLogic?

Logic–ascienceofreasoning

• BasisofmathemaJcalreasoning-givesprecisemeaningtomathemaJcalstatements-isusedtodisJnguishbetweenvalidandinvalidmathemaJcalarguments

• ApplicaJonsinCS:-designofhardware-programming-arJficialintelligence-databases

VillanovaCSC1300-DrPapalaskari

Page 25: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

ProposiNon

VillanovaCSC1300-DrPapalaskari

Page 26: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

Compoundproposi3onsareformedfromsimplerproposiJonsusingconnec3ves,alsocalledlogicaloperators.

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

CompoundProposiNonsandConnecNves

VillanovaCSC1300-DrPapalaskari

Page 27: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

NegaNonIfpisaproposiJon,thenthestatement

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

Example:WhatisthenegaJonof“TodayisWednesday”?

ThetruthtablefornegaJon:p¬pTF

VillanovaCSC1300-DrPapalaskari

Page 28: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

pqp∧qTTTFFTFF

ThetruthtableforconjuncJon:

Examples:TodayisWednesdayanditisraining.TodayisWednesdaybutitisnotraining.

VillanovaCSC1300-DrPapalaskari

Page 29: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

ThetruthtablefordisjuncJon:pqp∨qTTTFFTFF

Example:TodayisSundayoraholiday.

VillanovaCSC1300-DrPapalaskari

Page 30: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

ExclusiveOR(XOR)

TheproposiJonp⊕qiscalledtheexclusiveorofpandq.Itistruewhenexactlyoneofpandqistrue,otherwiseitisfalse.

Thetruthtableforexclusiveor:

pqp⊕qTTTFFTFF

Example:Thisdishcomeswithsouporsalad.

VillanovaCSC1300-DrPapalaskari

Page 31: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

ImplicaNonTheimplica3onorcondi3onalproposi3onp→qistheproposiJonthatisfalseonlywhenpistrueandqisfalse.piscalledthehypothesisandqiscalledtheconclusion.

ThetruthtableforimplicaJon:pqp→qTTTFFTFF

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

VillanovaCSC1300-DrPapalaskari

Page 32: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

ExamplesofImplicaNonWording

IfJohnisinL.A.,thenheisinCalifornia.

TobeinCalifornia,it issufficientforJohntobeinL.A.

TobeinLA,it isnecessaryforJohntobeinCalifornia.

YouwillgetanAifyoustudyhard.vs.YouwillgetanAonlyifyoustudyhard.

VillanovaCSC1300-DrPapalaskari

Page 33: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

MoreExamplesofImplicaNonwording:

Ifyouplaceyourorderby11:59pmDecember21st,thenweguaranteedeliverybyChristmas.

Placingyourorderby11:59pmDecember21stguaranteesdeliverybyChristmas.

WeguaranteedeliverybyChristmasifyouplaceyourorderby11:59pmDecember21st.

VillanovaCSC1300-DrPapalaskari

Page 34: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

MoreExamplesofImplicaNonwording:

Ifyouplaceyourorderby11:59pmDecember21st,thenweguaranteedeliverybyChristmas.

Placingyourorderby11:59pmDecember21stguaranteesdeliverybyChristmas.

WeguaranteedeliverybyChristmasifyouplaceyourorderby11:59pmDecember21st.

WeguaranteedeliverybyChristmasonlyifyouplaceyourorderby11:59pmDecember21st.

isthisthesametoo?

VillanovaCSC1300-DrPapalaskari

Page 35: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

BicondiNonal

Thebicondi3onalp↔qistheproposiJonthatistruewhenpandqhavethesametruthvalues,andisfalseotherwise.

ThetruthtableforbicondiJonal:

pqp↔qTTTFFTFF

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

VillanovaCSC1300-DrPapalaskari

Page 36: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

TruthtablesformorecomplexproposiNons

pqrr∨(q∧¬p)TTTTTFTFTTFFFTTFTFFFTFFF

VillanovaCSC1300-DrPapalaskari

Page 37: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

Tautology

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

-A(compound)proposi0onthatisalwaystrue(irrespec0veofthevaluesofitscomponents)

VillanovaCSC1300-DrPapalaskari

Page 38: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

LogicalEquivalence

pq¬p∨qp→qTTTFFTFF

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

Wesaythattwoproposi3onsarelogicallyequivalentifftheyhavethesametruthtable.

VillanovaCSC1300-DrPapalaskari

Page 39: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

DeMorgan’sLawsforLogic

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

Example:Negate:“TodayisSundayoraholiday”

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

VillanovaCSC1300-DrPapalaskari

Page 40: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

Converse,InverseandContraposiNve

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

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

Whichoftheabovearelogicallyequivalent?

VillanovaCSC1300-DrPapalaskari

Page 41: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Domainofdiscourse?P(2)

P(3)VillanovaCSC1300-DrPapalaskari

Page 42: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

UniversalquanNfier

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

“forallxP(x)”

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

VillanovaCSC1300-DrPapalaskari

Page 43: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 44: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

ExistenNalquanNfier

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

“thereisanxsuchthatP(x)”

“forsomexP(x)”

∃xP(x)existen0alquan0fier.

VillanovaCSC1300-DrPapalaskari

Page 45: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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”

Page 46: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

GeneralizedDeMorganLawsofLogic

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

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

“ThereisnoonewhodoesnotloveCS”≡“EveryonelovesCS” VillanovaCSC1300-DrPapalaskari

Page 47: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 48: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 49: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 50: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 51: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

Typesofproofsn  direct n  indirect (by contrapositive)

n  by contradiction

n  proof of equivalence

n  proof by cases n  proof by mathematical induction

VillanovaCSC1300-DrPapalaskari

Page 52: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

Provingp → q

•  DirectProof

•  IndirectProof/ContraposiJve

•  ProofbyContradicJon

p → q

p → q ≡ ¬ q → ¬ p

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

VillanovaCSC1300-DrPapalaskari

Page 53: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

DirectProof

Toprovep → q:Supposepistrue;provethatqmustalsobetrue

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

VillanovaCSC1300-DrPapalaskari

Page 54: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

IndirectProof

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

dominoes.

VillanovaCSC1300-DrPapalaskari

Page 55: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

ContradicJonProof

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

VillanovaCSC1300-DrPapalaskari

Page 56: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 57: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 58: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 59: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

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

Page 60: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

WhichProofMethod?

1.  Beginwithadirectproofapproach2.  Ifthisfails,tryeither

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

VillanovaCSC1300-DrPapalaskari

Page 61: Sets and Logic - Villanova Universitymap/1300/s17/chap02setsLogic.pdf · Sets and Logic CSC 1300 ... • ℕ = { 1, 2, 3, …} - the set of natural numbers ... We usually think of

MajorThemes•  Sets

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

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

VillanovaCSC1300-DrPapalaskari