Upload
others
View
6
Download
0
Embed Size (px)
Citation preview
1
Introduction to DiscreteMathematics
Course OutlineProf. G. Kesidis, instructor
CourseOutline• Introductiontologic• Introductiontomethodsofproof• Sequencesandinduction• Introductiontosettheory• Countingandprobability– discreterandomvariables(seeslidedeck on
undergraduateprobability)• Functionsandthepigeonholeprinciple• Recursions• IntroductiontoComplexity• Relations• Introductiontomodulararithmeticandpublic-keycryptography• Introductiontographs
2
3
Introduction to DiscreteMathematics
Introduction to Logic© S.S. Epp (2006)
This revision G. Kesidis (2013)This document revision is copy-left 2013.
It is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
4
Intro to Logic – Outline• LogicalFormandEquivalence• ConditionalStatements• ValidandInvalidArguments• IntrotoPredicatesandQuantifiedStatements• StatementswithMultipleQuantifiers• ArgumentswithQuantifiedStatements
5
Concept of Logical Form
Howdoyouknowtodayisn'tEaster?
IftodayisEaster,thenitisSunday.ItisnotSundayTherefore,todayisnotEaster.
Theformofthisargumentiscalled“modustollens”.
Ifp,thenq.Notq.Thereforenotp.
6
Modus tollens exampleExample: Argumentintheformofmodustollens.
IfSueisguilty,thenSuewasinRioonAug.18.(Ifp,thenq.)
SuewasnotinRioonAug.18.(Notq.)
Therefore,Sueisnotguilty.(Therefore,notp.)
7
Modus tollens: premises, conclusionCommonform(modustollens):
Ifp,thenq.(premise)Notq.(premise)Thereforenotp.(conclusion)
Apremiseisastatementpresumed trueforpurposesofanargument.
Modustollensisvalid inthesensethat• ifyouhaveanargumentofthisforminwhichthefirsttwo
statements(thepremises)arebothtrue,• thenyoucanbe100%surethatthefinalstatement(theconclusion)
willbetrue.
8
Mathematical Communication
• Mustbeunambiguous
• Mustexpressthingssothateveryoneunderstandsexactlywhatwearesaying
• Consequence: Carefuldefinitionsarenecessary
9
Statements
Statement: Adeclarativesentencethatiseithertrueor
falsebutnotboth.
Example: Whichofthefollowingarestatements?
§ 1+1=2 isastatement– truesentence
§ 1+1=5 isastatement– falsesentence
§ 1+x=5 isnotastatement;trueforsomexand
falseforothers(thiskindofsentenceis
calleda“predicate”).
10
Logical Connectives
Usedtoputsimplestatementstogethertomakecompoundstatements
not ~ negationand, but ⋀ conjunctionor (inclusive) ⋁ disjunctionif-then → conditional
if-and-only-if ↔ biconditional
11
Precedence Rules1.~
2.⋁and⋀(withleft-to-rightprecedenceamongthesetwooperations,butbettertouseparenthesestoavoidambiguityinsteadoftheleft-to-rightprecedence)
3.→and↔(ditto)
4.Parenthesesmaybeusedtooverriderules1-3
Example:• ~p⋀q=(~p)⋀q:checkthatthisisnotthesameas~(p⋀q)• p⋀ q⋁ rmaybeambiguous.Byleft-to-rightprecedence,thisisthe
sameas(p⋀ q)⋁ r.Bettertojustspecifywhether(p⋀ q)⋁ rorp⋀(q⋁ r)isintended.
Recallleft-to-rightprecedencefromarithmetic:6/3�9=18(not0.5).
12
Logical connectives - examplesLetpbe“Itiswinter”,qbe“Itiscold”,andrbe“Itisraining”.
Writethefollowingstatementssymbolically.
• Itiswinterbutitisnotcold=p⋀~q=p⋀(~q)
• Neitherisitwinternorisitcold=~p⋀~q=(~p)⋀(~q)
• Itisnotwinterifitisnotcold=~q→~p
• Itisnotwinterbutitisrainingoritiscold=(~p⋀r)⋁q
• Itisnotwinterbutitisrainingorcold=~p⋀(r⋁q)?
Notetheuseofleft-to-rightprecedenceinthesecond-lastexampleabove.
Noteinthelastexamplethatthelackofseparatesubjectandverb(“itis”)withtheclause“cold”mayimplythedifferentanswergiven.
13
Truth Values for Compound Statement Forms
• NotStatements(Negations): Thenegationofastatementisastatementthatexactlyexpresseswhatitwouldmeanforthegivenstatementtobefalse.
• Thenegationofastatementhasoppositetruthvaluefromthestatement.
p ~pT F
F T
14
TruthTablefor⋁ (“inclusiveor”)• Notehowallpossiblecombinationsofveracityofthetwocomponent
statements(independentvariables)areconsideredinthefirsttwocolumnsofthetruthtableforlogical or:
• Theonlytimeanor statementisfalseiswhenbothcomponentstatementsarefalse– cf.DeMorgan’slawsonnegatinglogicalor statements:~(p⋁q)=~p⋀~q
p q p⋁q
T T T
T F TF T TF F F
15
TruthTablefor⋀(“and”,“but”)
• Theonlytimeanand statementistrueiswhenbothcomponentsaretrue– againcf.DeMorgan’slawonnegatinglogicalandstatements:~(p⋀q)=~p⋁ ~q
p q p⋀q
T T TT F FF T FF F F
16
De Morgan’s laws for negating ⋀
• Notehowthe~(p⋀q)and ~p⋁ ~q columnsareidentical,i.e.,thetwocompoundstatementsarelogicallyequivalent).
• Thisproofthat~(p⋀q)≡ ~p⋁ ~q isdirectlybytakingallcases(eachcaseisarow ofthetruthtable)ontheveracity(truthvalues)ofcomponentstatementspandq.
p q p⋀q ~(p⋀q) ~p ~q ~p⋁ ~q
T T T F F F FT F F T F T TF T F T T F TF F F T T T T
17
De Morgan’s laws for negating ⋁• Exercise:repeatthisfornegatingor statements,i.e.,show~(p⋁q)≡ ~p⋀~q
18
De Morgan’s laws - examples• Question:Writethenegationof,“Sueleftthedoorunlockedorsheleftthewindowopen.”
• Answer:“Suelockedthedoorandsheclosedthewindow.”• But isthenegationof“Sueleftthedoorunlocked”really“Suelockedthedoor”?
• Question:Writethenegationof,“HalgotanAonthemidtermandHalgotanAonthefinalexam.”
• Answer:“Haldidnot getanAonthemidtermor HaldidnotgetanAonthefinalexam.”
19
Truth Table for → (implies)• Theonlytimeastatementoftheformifpthenqisfalseiswhenthe
hypothesis(p )istrueandtheconclusion(q)isfalse,i.e.,~(p→q)≡p⋀~q(Exercise:checkthisbytruthtable)
• Whenthehypothesisofanif-thenstatementisfalse,wesaythattheif-thenstatementis�vacuouslytrue� or�truebydefault.� Inotherwords,itistruebecauseitisnotfalse.
• p→q≡ifpthenq≡qifp≡ponlyifq≡qisanecessaryconditionforp≡pisasufficientconditionforq
≡~porq
p q p→ qT T T
T F FF T T
F F T
p q
20
If-then Statements (Conditionals)• Imagine thatIpromiseyou:
"IfyougetanAonthefinalexam,thenyouwillgetanAinthecourse.”• Formofconditional:“Ifhypothesis,thenconclusion”,equivalently
“hypothesis→conclusion”.• Jumpforwardtooneweekaftertheendofthesemester.Findingout
yourfinalexamgradeandyourcoursegrade,youexclaim:”Helied.”• WhatwouldhavetobetruetoleadyoutosaythatIlied?• YouwouldhavetohaveearnedanAonthefinalexam andnotreceived
anAforthecourse.InallothercasesitwouldnotbefairtosaythatIlied.
• Note:Theexamplestatementaboveislogicallyequivalentto”YougetanAonthefinalexamonlyifyougetanAinthecourse.”
If-then statements (cont)• Question:Writethenegationof“IfJimgottherightanswer,thenhesolvedtheproblemcorrectly.”
• Answer:“Jimgottherightanswerand hedidnot solvetheproblemcorrectly.”
• Notethatonecoulduse“but” insteadof“and” intheanswer.
• ~(p→q)≡p⋀ ~q
21
22
If-and-Only-If (iff) Statements (Biconditionals)• Astatementoftheformpifandonlyifq istruewhenbothpandqhavethesametruthvalue(veracity).
• pifandonlyifq isfalsewhenpandqhaveoppositetruthvalues.
• Exercise:Checkbytruthtablethatp↔ q≡(q→p)⋀(p→q),i.e.,pifandonlyifq≡(pifq)and(ponlyifq)
p q p↔ qT T T
T F F
F T F
F F T
23
Some Potentially Ambiguous TermsOr
• Example:Asyourprize,youmaychoosetheTVor themicrowaveoven.
• Question:Isittobeunderstoodthatyoucan'tchooseboththeTVand
themicrowave?
• Answer:YES.Inthissentence,theintendedmeaningof“or”iscalled
“exclusiveor”,i.e.,
p⊕q=falsewhenp=trueandq=true.
If-then
• Example:If youeatyourdinner,then youwillgetdessert.
• Question:Doesthisimplythatifyoudon'teatyourdinner,thenyou
won'tgetdessert?Inotherwords,doesitmeanthatifyougetdessert,
youwillhaveeatenyourdinner?
• Answer:Momwantsyoutothinkthis,butitisnotimpliedbythelogical
meaningofif-then.
24
Moral
• Inordinaryspeech,wordslike“or” and“if-then”mayhavemultiplemeanings,
• butintechnicalsubjects,wemustallunderstandwordsinthesameway.
• Sowechooseonemeaningforeachword.
25
Compound Statement FormsExample :§ p:DePaulUniversityisinChicago§ q:1+1=5§ r:ChicagoisnexttoLakeMichigan
Question:Knowingthatp isT,q isFandr isT,whatisthetruthvalueofthefollowingcompoundstatement?
(p⋀~q)⋁~r
Answer:(T⋀~F)⋁~T=(T⋀T)⋁F=T⋁F=Ti.e.,theanswerisTrue.
Notehowwefollowedprecedenceorder.
26
Truth Table for Exclusive Or
• logicalexpressionforastatementoftheformp orq butnotboth:(p⋁q)⋀~(p⋀q)≝p⊕q
p q p⋁q p⋀q ~(p⋀q) (p⋁q)⋀~(p⋀q)
T T T T F FT F T F T TF T T F T TF F F F T F
27
Arguments and Argument Forms • Argument:Sequenceofstatements.Thefinalstatementinthesequenceisthe(final)conclusion;theprecedingstatementsarepremises. Somestatementsfollowingthe“initial”premisesmaythemselvesbeconclusions,i.e.,formingcomponentarguments.
• ArgumentForm:Obtainedbyreplacingcomponentstatementsintheargumentbyvariables.
• Example(modustollens):Ifpthenq. (premise)Notq. (premise)Therefore,notp. (∴conclusion)
28
Valid Arguments• Formofargumentisvalidwhen: Everyargumentofthatformthathas
truepremiseshasatrueconclusion.(Amoreformalversionofthedefinitionisinthebook)
• Claim:Modustollensisavalidformofargument.
• Proof:Bylastrowofthefollowingtruthtable,whereinbothpremises(columns3and4)aretrueand(rightmost)column5isthetrueconclusion.
p q p→q ~q ~p
T T T F FT F F T FF T T F TF F T T T
29
Invalid Arguments• Aformofargumentisinvalid ifthereisatleastoneargumentofthatformthathastruepremisesandafalseconclusion.
• Example:Determinewhetherthefollowingargumentform(withthreepremises)isvalidorinvalid:
~p⋁qp→rq→p∴r
30
Valid or Invalid? Example (cont)
p q r ~p ~p⋁q p→r q→p rT T T F T T T TT T F F T F T FT F T F F T T TT F F F F F T FF T T T T T F TF T F T T T F FF F T T T T T TF F F T T T T F
• Onlyrows1,7,8aregermaneasallpremises(cols.5,6,7)aretruejustforthosecases.
• The8th (bottom)rowshowsthatitispossibleforanargumentofthisformtohavetruepremisesandafalseconclusion(col.8).
• Sothisformofargumentisinvalid.
31
More Valid and Invalid Forms of Argument
• Modusponens(valid):
IfTedisaCSmajor,thenTedhastotakeCSC211.
TedisaCSmajor.
Therefore,TedhastotakeCSC211.
• Form: Ifpthenq
p
∴q
• Itisobviouslynotpossibleforthetwopremisestobetrueandtheconclusiontobefalse,sothisformofargumentisvalid.
• Foraproof,seethefirstrowofthetruthtableforp→q
32
Invalid Argument with a “Converse Error”• Example:IftodayisEaster,thenitisSunday.ItisSunday.Therefore,todayisEaster.
• Form: Ifpthenqq∴p
• Exercise:Checkbytruthtablethatthisisnot avalidformofargument(3rd rowofthetruthtableforp→q).
• Thestatementq→pisthe converseofthestatementp→q.• Theconverseofatruestatementmaybetrueorfalse,soemploying
theconverseasaboveresultsinaninvalidargument.
33
Invalid Argument with an “Inverse Error” • Example:IfTedisamathmajor,thenTedhastotakeMAT152.Tedisnotamathmajor.Therefore,TeddoesnothavetotakeMAT152.
• Form: Ifpthenq~p∴~q
• Exercise:Checkbytruthtablethatthisisnot avalidformofargument.
• Thestatement~p→~qistheinverse ofthestatementp→q.• Again,ifastatementistrueitsinversemaybetrueorfalseso
employingtheinverseasaboveresultsinaninvalidargument.
34
�Sound Argument�: Valid Argument with True Premises (and thus a true conclusion)
• Aninvalidargumentmayhaveatrueconclusionandavalidargument(withafalsepremise)mayhaveafalseconclusion,thoughthesedefinitionsareoftenusedinterchangeablyinordinaryspeech.
• Thevalidityoftheargumentdoesnotdependonthetruthvaluesofthepremises.
• Example:Invalidargument(converseerror)withtrueconclusion.IfDickCheneywasvicepresident,thenD.C.workedforHalliburton.D.C.workedforHalliburton.Therefore,D.C.wasvicepresident.
• Example:Validargument(modusponens)withfalseconclusion.Ifallhumansaremicethenallmicearesixfeettall.Allhumansaremice.Therefore,allmicearesixfeettall.
35
Exercise: Spot the logical errorsParaphrasedfromMontyPythonandTheHolyGrail:Note:Shewas awitchintheendbecauseshedidweighasmuchasaduck((i.e.,trueconclusionthoughargumentisinvalid)
SIRBEDEMIR:Therearewaysoftellingwhethersheisawitch.VILLAGER#1:Arethere?BEDEMIRTellme.Whatdoyoudowithwitches?CROWD:Burn!Burnthemup!Burn!...BEDEMIR:Andwhatdoyouburnapartfromwitches?VILLAGER#1:Wood!BEDEMIR:So,whydowitchesburn?VILLAGER#3:B--...'causethey'remadeof...wood?BEDEMIR:Good!So,howdowetellwhethershe’smadeofwood?
VILLAGER#1:Buildabridgeoutofher.BEDEMIR:Ah,butcanyounotalsomakebridgesoutofstone?VILLAGER#1:Oh,yeah.BEDEMIR:Doeswoodsinkinwater?VILLAGER#2:No,itfloats!Itfloats!BEDEMIR:Whatalsofloatsinwater?(Villagersdon’tknow)KINGARTHUR:Aduck!BEDEMIR:Exactly.So,logically...VILLAGER#1:If...she...weighs...thesameasaduck,...she'smadeofwood.BEDEMIR:Andtherefore?VILLAGER#2:Awitch!
36
Logical Equivalence: e.g., De Morgan
• Recallhowthe~(p⋀q)and ~p⋁ ~q columnsareidentical,i.e.,thesetwocompoundstatementsarelogicallyequivalent.
• Thisproofthat~(p⋀q)≡ ~p⋁ ~q isbytakingallcases(rows ofthetruthtable)ontheveracity(truthvalues)ofcomponentstatementspandq.
p q p⋀q ~(p⋀q) ~p ~q ~p⋁~q
T T T F F F FT F F T F T TF T F T T F TF F F T T T T
37
Definition of Logical Equivalence
• Definition: Twostatementformsarelogicallyequivalentif,andonlyif,itisimpossibleforoneofthemtobetrueandtheotherfalse.
• Logicalequivalencemakesitconvenienttoexpressstatementsinmorethanoneway.
• Thesymbolforlogicalequivalenceis≡
38
De Morgan�s Laws, Negation of �If p Then q�• DeMorgan’slaws:
~(p⋀q)≡ ~p⋁~q ,~(p⋁q)≡ ~p⋀ ~q
• Example:Thenegationof
-4<x≤7(read:-4<xandx≤7)
is
-4≥ xorx>7.
• Negationof→:~(p→q)≡ p⋀~q
• Example:Thenegationof
IfTomisAnn’sfather,thenLeoisheruncle.
is
Tomis Ann’sfatherandLeoisnot heruncle.
• So,byDeMorgan,p→q≡ ~(p⋀~q)≡ ~p⋁qandrecall
howp→qisvacuouslytrue.
39
Contrapositive,Converse,Inverseofp →q
Fortheconditionalstatement“ifpthenq”:• theconverse is:ifqthenp• thecontrapositiveis: ifnotqthennotp• theinverse is:ifnotpthennotq.
40
ConditionalStatement:IfSamlivesinChicagothenSamlivesinIllinois.
Converse:IfSamlivesinIllinois,thenSamlivesinChicago.
Contrapositive:IfSamdoesnotliveinIllinois,thenSamdoesnotliveinChicago.
Inverse:IfSamdoesnotliveinChicago,thenSamdoesnotliveinIllinois.
Example– Converse,InverseandContrapositive
41
Which are Logically Equivalent?
• p→q≡~q→~p(conditionalstatementis logicallyequivalenttoitscontrapositive,recallmodustollens)
• p→q≢ q→p(conditionalstatementis notlogicallyequivalenttoitsconverse)
• p→q≢ ~p→~q(conditionalstatementisnot logicallyequivalenttoitsinverse)
• inverseiscontrapositiveofconverse,soinverseandconversearelogicallyequivalent:q→p≡~p→~q
• Proofbytruthtable(directlybyexhaustivecases):p q ~q ~p p→q ~q→~p q→p ~p→~ qT T F F T T T TT F T F F F T TF T F T T T F FF F T T T T T T
Converse (of an if-then statement) • Note from the truth table that “p→q” truedoes notimplythatitsconverse“q→p” istrue,i.e.,itsconversemaybetrueorfalse.
• Thatis,theconverseofatrueconditional(if-then)statementisnotnecessarilytrue.
• Ontheotherhand,when“p→q” isfalse(i.e.,pand~qaretrue),theconverse“q→p” is(vacuously)true.
42
p q ~q ~p p→q ~q→~p q→p ~p→~ qT T F F T T T TT F T F F F T TF T F T T T F FF F T T T T T T
43
Sets
• SetNotation:x∈ Ameansthat“xisanelementofthesetA,”or“xisinA.”
• Importantsetsofrealnumbers:ℝ,thesetofallrealnumbersℚ,thesetofallrationalnumbersℤ,thesetofallintegersℝ>0,thesetofallstrictlypositiverealnumbersℤ≥0=G,thesetofallnonnegativeintegers(wholenumbers)ℤ>0= ℕ,thesetofallstrictlypositiveintegers(naturalnumbers),sometimealsodenotedℤ+etc.
44
Quantified Statements§ Apredicate isasentencethatisnotastatementbutcontainsoneor
morevariablesandbecomesastatementifspecificvaluesare
substitutedforthevariables.
§ Thedomainofapredicatevariable isthesetofallowablevaluesfor
thevariable.
§ Example: LetP(x)bethesentence“x2 >4” wherethedomainofxis
understoodtobethesetofallrealnumbers.ThenP(x)isapredicate.
§ Question: ForwhatnumbersxisP(x)true?
Answer:Thesetofallrealnumbersforwhichx>2orx<-2.
45
Truth Set of a Predicate• Thetruthsetofapredicate P(x)isthesetofelementsinthedomainD
ofxforwhichP(x)istrue.
• WewritetruthsetofP(x)as{x∈D|P(x)}
andwereadthisas“thesetofallxinDsuchthatPofx.”
• Note:Theverticallinedenotesthewords“suchthat”fortheset-bracketnotationonly.
• Thewords“suchthat”mayalsobesymbolizedby“s.t.”or“s.th.” or“∋”or“:”
46
Truth set of a predicate - example• LetP(x)bethepredicate“x2 <x”,withdomainthesetℝofallrealnumbers.
• Whichofthestatements P(0),P(1/2),P(2)andP(-3)aretrueandwhicharefalse?
• WhatisthetruthsetofP(x)?P(0): 02 <0 FALSEP(1/2): (½)2 <½ TRUEP(2): 22 <2 FALSEP(-3): (-3)2 <-3 FALSETruthset={x∈ℝ|0<x<1}
47
UniversalQuantification∀• Thesymbol ∀,standingforthewords“forall”iscalledtheuniversal
quantifier.• Question:Rephrasethefollowinguniversalstatementinlessformal
language.∀MAT140studentsx,x hasstudiedcalculus.
• Answers:– AllMAT140studentshavestudiedcalculus.– EveryMAT140studenthasstudiedcalculus.– IfapersonisaMAT140student,thenthatpersonhasstudiedcalculus.
– etc.
48
Definition of Counterexample• Definition: Givenauniversalstatementoftheform
“∀x∈D,P(x)”,acounterexample forthestatement
isavalueofx∈DforwhichP(x)isfalse.
• Notethat:∀x∈D,P(x)≡∀x,x∈D⇒P(x)wherethecontextisthat
xmaybelongtosomesupersetcontainingD(⇒is“implies”for
predicates).
• Alsonotethat“∀x∈D,P(x)”isastatementifDisdisclosedor
understood,otherwiseit’sapredicatewithvariableD.
• Example:Trueorfalse?
∀MAT140studentsx,xhasstudiedcalculus.
• Answer:ThestatementisfalsebecauseyouhappentoknowthatFred
isacounterexampletothestatement,i.e., becauseFredisaMAT140
studentandFredhasnot studiedcalculus.
49
ExistentialQuantification∃• Thesymbol∃,standingforthewords“thereexists”,iscalledthe
existentialquantifier
• Example:Rephrasethefollowingexistentialstatementinlessformallanguage,anddeterminewhetheritistrueorfalse.
∃aMAT140studentx suchthatx hasstudiedcalculus.
• Answers:– ThereisaMAT140studentwhohasstudiedcalculus.– SomeMAT140studenthasstudiedcalculus.– SomeMAT140studentshavestudiedcalculus.– AtleastoneMAT140studenthasstudiedcalculus.– etc.
50
Truth Values of Universal and Existential Statements, and their negations
• Universalstatement:“∀x∈D,Q(x)”istrue if,andonlyif,Q(x)istrueforeachindividualx∈D.
• Itisfalse if,andonlyif,Q(x)isfalseforatleastonex∈D.• AvalueofxforwhichQ(x)isfalseiscalledacounterexample tothe
statement“∀x∈D,Q(x)”.• So,~(∀x∈D,Q(x))≡∃x∈Dsuchthat~Q(x)
• Existentialstatement:“∃x∈DsuchthatQ(x)”istrue if,andonlyif,Q(x)istrueforatleastonex∈D.
• Itisfalse if,andonlyif,Q(x)isfalseforeachindividualx∈D.• So,~(∃x∈DsuchthatQ(x))≡∀x∈D,~Q(x)
51
Universal/Existential Statement Examples• Determinewhetherthefollowingstatementsaretrueandrewritethem
formallyusingaquantifierandavariable:
• Allevenintegersarepositive.– False:-2isacounterexample;itisevenbutnotpositive.– ∀evenintegersn,nispositive.– ∀integersn,ifniseventhennispositive.– ∀n,ifnisanevenintegerthennispositive.– Noteinthepreviousanswer,thereisanimpliedsupersetoftheevenintegerstowhichnbelongs
• Someintegershaveintegersquareroots.– True:Thenumber4hasasquarerootof2,whichisaninteger.– ∃ anintegerxsuchthatxhasanintegersquareroot.– ∃xsuchthatxisanintegerandxhasanintegersquareroot.
52
• Indicate,ifpossible,whichofthefollowingstatementsaretrueandwhicharefalse,andrewritethemformallyusingaquantifierandavariable:
• Noprimenumbersareeven.– False:Thenumber2isevenandprime.– ∀ primenumbersp,pisnoteven.– ∀ integersp,ifpisprimethenpisnoteven.– Notethattheintegersareasupersetoftheprimes.
• IfapersonisastudentinMAT140,thenthatpersonisatleast18yearsold.– True?– ∀ studentsPinMAT140,Pisatleast18yearsold.– ∀ peopleP,ifPisastudentinMAT140thenPisatleast18yearsold.– Notethatpeopleareasupersetofstudents.
Universal/Existential Statement Examples
53
Negating Quantified Statements - Examples
1.∀studentsxinMAT140,xisatleast30yearsold.Negation:∃ astudentxinMAT140suchthatxislessthan30yearsold.
2.∃astudentxinMAT140suchthatxisatleast70yearsold.Negation:∀studentsxinMAT140,xislessthan70yearsold.
54
Negating Quantified Statements - Examples
3.∀realnumbersx,x2 >0.Negation:∃arealnumberxsuchthatx2 ≤0.
4.∃arealnumberxsuchthatx2 =-1.Negation:∀realnumbersx,x2 ≠-1.
Notethattheoriginalstatementinbothexamplesabovehappenstobefalse.
Negating Quantified Statements and De Morgan’s Laws
• InSummary:~(∀x∈D,Q(x))≡∃x∈Dsuchthat~Q(x)…i.e.,acounterexample~(∃x∈DsuchthatQ(x))≡∀x∈D,~Q(x)• ButthesearejustDeMorgan’slawsonthe(potentiallyuncountablyinfinite)setD,becausewehavethefollowinglogicalequivalents:∀x∈D,Q(x)≡⋀x∈DQ(x)∃x∈DsuchthatQ(x)≡⋁x∈DQ(x)
• Forexample,ifthesetD={a,b,c}(hasthreeelements),then∀x∈D,Q(x)≡Q(a)⋀Q(b)⋀Q(c)∃x∈DsuchthatQ(x)≡Q(a)⋁Q(b)⋁Q(c)
• SobyDeMorgan,~(∀x∈D,Q(x))≡⋁x∈D~Q(x)55
56
Universal Conditional Statements
• Definition:Anystatementofthefollowingformiscalledauniversalconditionalstatement:
∀x∈D,ifP(x)thenQ(x)
• Equivalentnotationforif-thenstatementsinvolvingpredicates:
∀x∈D,P(x)⇒Q(x)
i.e.,⇒means“implies”forpredicates.
57
Universal Conditional Statement - Example• ∀ x∈ℝ,x>2⇒ x2 >4.• Read:Forallxinthesetofrealnumbers,ifxisgreaterthan2thenx-squaredisgreaterthan4.
• Lessformalversions:• Allrealnumbersthataregreaterthan2havesquaresthataregreaterthan4.
• Ifarealnumberisgreaterthan2,thenitssquareisgreaterthan4.
58
Disproving a Universal Statement
CommonMethod:Findacounterexample!
Example:
• Isthefollowingstatementtrueorfalse?Explain.
∀x∈ℝ,ifx2 >25thenx>5.
• Solution:
– Letx=-6.Thenx2 =(-6)2 =36,and36>-6but-6≤5.
– So(forthisx),x2 >25andx≤5.
– So,thestatementisfalsebycounterexample.
59
Negate a universal-conditional statement
• ~(∀x∈D,ifP(x)thenQ(x))≡∃x∈Ds.t.P(x)⋀~Q(x)
• Example:Writeanegationforthefollowingstatement∀x∈ℝ,ifx2 >4thenx>2.
• Negation:∃ x∈ℝs.t.x2 >4andx≤2.
• Notethatthefactthatthenegationistrue(andoriginalstatementisfalse)isimmaterialtowhatisbeingasked.
60
Example: Vacuous truth
• Supposethat:Therearenoelephantsonthisdesk.
• IsthefollowingstatementTrueorFalse?
Alltheelephantsonthisdeskhavetwoheads.(*)
• Thenegationofthisstatementis:
Thereisanelephantonthisdeskwithouttwoheads.
whichisclearlyfalse.
• So,theoriginalstatement(*)hastobetrue!
• Thisisanotherexampleof“vacuoustruth”or“truthbydefault”
becauseitinvolvesanempty-setquantifier:
∀x∈{elephantsonthisdesk},xhastwoheads,
wherethesetofelephantsonthedeskisempty.
• Thisisrelatedvacuoustruthofp→qwhenthepremisestatementp
isfalse;forpredicatestatementswewrite,
x∈{elephantsonthisdesk}⇒xhastwoheads
61
Arguments with Quantified Statements• Universalinstantiation:Ifapropertyistrueforalltheelementsinaset,
thenitistrueforeachindividualelementoftheset.• Example(multiplicationdistributesoveraddition):
∀a,b,c∈ℝ,a(b+c)=ab+ac.
Thus:7∙106=7(100+6)=7∙100+7∙6=742
And:Ifk∈ℝ,then2k∙3+2k ∙5=2k ∙(3+5) (=2k∙8=2k ∙23 =2k+3)
62
Universal Modus Ponens and Modus Tollens• Exampleuniversalfact(truestatement)
Allhumansaremortal.• Equivalently,
∀x,ifxishumanthenxismortal.• xisimplicitlyinthesupersetofelementsforwhichmortalityor
immortalityareattributes,i.e.,asupersetoflivingbeingsincludinggods,butnotinanimateobjectslikerocks.
• Byuniversalinstantiationthefollowingistrue:IfSocratesishuman,thenSocratesismortal.
• Sowecanargue(modusponens):Socratesishuman.∴Socratesismortal.
• Byuniversalinstantiation,thefollowingistrue:IfZeusishumanthenZeusismortal.
• Sowecanargue(modustollens):Zeusisnotmortal.∴Zeusisnothuman.
63
Necessary and Sufficient ConditionsExample:Whatdothefollowingsentencesmean?
• PassingallthetestsisasufficientconditionforJontopassthecourse.Answer:IfJonpassesallthetests,thenJonwillpassthecourse.
• PassingallthetestsisanecessaryconditionforJontopassthecourse.Answer:IfJondoesn’tpassallthetests,thenJonwon’tpassthecourse.Or:IfJonpassesthecourse,thenJonwillhavepassedallthetests.
• Notethatreplacing“sufficient”with“necessary”createsaconversestatement.
64
Necessary and sufficient conditions -Definitions
• AisasufficientconditionforB– meansifAthenB.– i.e.,theoccurrenceofAimplies/guaranteestheoccurrenceofB.
• AisanecessaryconditionforB– means if~Athen~B.– i.e.,ifAdidn’toccur,thenBdidn’toccureither.– Or,equivalently, itmeansthecontrapositive,ifBthenA.
– i.e.,ifBoccurredthenAalsohadtooccur.
65
Necessary and sufficient conditions -Examples
Writeeachofthefollowingusingif-thenstatements:
1. Beingatleast35yearsoldisanecessaryconditionforAnntobecomepresidentoftheU.S.IfAnnislessthan35yearsold,thenAnncannotbecomepresidentoftheU.S.IfAnnbecomespresidentoftheU.S.,thenAnnisatleast35yearsold.
2. Beingappropriatelydressedforajobinterviewisnecessary(butnotsufficient)forTomtogetthejob.IfTomisnotappropriatelydressedforajobinterview,thenTomwon’tgetthejob,butitcanhappenthatTomisappropriatelydressedandstilldoesn’tgetthejob.
66
Necessary and sufficient conditions –Examples (cont)
3. GettingallA’sissufficient(butnotnecessary)forSuetograduatewithhonors.
IfSuegetsallA’sthenshewillgraduatewithhonors,butit’spossibleforSuetograduatewithhonorsevenifshedoesn’tgetallA’s.
4. Supposeateachersays:Getting100%correctonalltheexamsisbothnecessaryandsufficientforyoutoearnanAinthecourse.Whatdoesthismean?IfyouearnanAinthecourse,thenyougot100%correctonalltheexams,andifyougot100%correctonalltheexams,thenyougotanAinthecourse.
67
Only if and the Biconditional
Example: Cinderella’sstepmothermakesthefollowingstatement.Writeitasanif-thenstatement:
Youhavepermissiontogototheballonlyifyoufinishallyourwork.
Answer:Ifyoudonotfinishallyourwork,thenyoudonothavepermissiontogototheball.
Or:Ifyouhavepermissiontogototheball,thenyouwillhavefinishedallyourwork.
68
Definition: Only If
• ronlyifsmeans if~sthen~r• Thatis,ifsdidn’toccur,thenrdidn’toccureither.• Or,equivalently,thecontrapositive, ifrthens• Thatis,ifristruethensalsohastobetrue.
69
Interpretation of If and Only If• So,ronlyifsmeans ifrthens
• and rifsmeansifsthenr(theconverseof:ifrthens)
• Thus,rifandonlyifs
– Means ronlyifs and rifs
– Whichmeans ifrthens and ifsthenr
• Symbolically,
r↔s≡(r→s)⋀(s→r)≡s↔r
≡risanecessaryandsufficientconditionfors
≡sisanecessaryandsufficientconditionforr
• Example:
Anemployeeisanon-profitcollege’sfootballcoachifandonlyif
theyarethehighestpaidemployeeoftheirnon-profitcollege.
r=“employeeisfootballcoachofnon-profitcollege”
s=“employeeishighestpaidinnon-profitcollege”
70
Introduction to DiscreteMathematics
Introduction to Methods of Proof© S.S. Epp (2006)
This revision G. Kesidis (2013)This document revision is copy-left 2013.
It is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
71
Intro to Methods of Proof - Outline
• Directproofandcounterexample– Introduction– ExampleswithRationalNumbers– ExamplesonDivisibility– MethodofDivisionintoCases– ExampleswithFloorandCeilingOperators
• IndirectArguments:contradictionandcontraposition• Examples:√2isirrational,andthatthereareinfinitelymanyprimes
72
Elementary Number Theory and Methods of Proof
Assumptions:• Knowledgeofpropertiesoftherealnumbers(AppendixA),“basic” algebra,andlogic
• Propertiesofequality:A=A (=isreflexive)IfA=B,thenB=A. (=iscommutative)IfA=BandB=C,thenA=C. (=istransitive)
• Integersℤ={0,1,2,3,…,-1,-2,-3,…}={…-3,-2,-1,0,1,2,3,…}
• Anysum,difference,orproductofintegersisaninteger.
73
Definition of Even and Odd• Anintegeriseven↔itcanbeexpressedas2timessomeinteger.
• Anintegerisodd↔itcanbeexpressedas2timessomeintegerplus1.
Clarifyingtheroleof↔(ifandonlyif)inthesedefinitions:• Ifaninteger,sayn,iseventhenthereisanintegerksuchthatn=2k.
ANDtheconverse,• Ifaninteger,sayn,canbeexpressedas2k,forsomeintegerk,thenniseven.
Yes!
74
Exercise
• Question:Ifkisaninteger,is2k– 1anoddinteger?• Referencefact/definition:Anintegerisodd↔itcanbeexpressedas2timessomeintegerplus 1.
• Alsocanusebasicfacts,e.g.re.arithmeticwithintegers.• Answer:Yes(sotheaboveQuestionisaLemma).• Explanation/Proof:– Notethatk– 1isanintegerbecauseitisadifferenceofintegers.
– And2(k– 1)+1=2k– 2+1=2k– 1– Q.E.D.
75
Exercise
• Somepeoplesaythatanintegerisevenifitequals2k.Aretheyright?
• Is1anevennumber?
• Does1=2k?
• Yes:1=2(0.5)
• Soit’sprettyimportantthat“somepeople”requirektobeaninteger(therebyprecludingk=0.5),
• otherwisewehaveadisproofofwhat“somepeoplesay”bycounter-example,i.e.,takek=0.5.
76
Directly Proving a Universal Statement• MethodofGeneralizingfromtheGenericParticular: Ifaproperty
canbeshowntobetrueforaparticularbutarbitrarilychosenelementofaset,thenitistrueforeveryelementoftheset.
• Theorem: Picka(finite!)number.Add3.Multiplyby6.Subtract10.Divideby2.Subtract3timestheoriginalnumbertoarriveatyourfinalanswer,whichisalways4.
• Proof:Considerparticularbutarbitrary finitenumberx.Thefinalansweris(6(x+3)-10)/2-3x=3(x+3)–5-3x
=3x+9-5-3x=4.Q.E.D.
• Notethattheelementaryarithmeticoperationsintheproofholdforandarbitrarynumberx!
77
Direct Proving a Universal Statement Over a Finite Set
• MethodofExhaustion:Ifatheoremstatementconcernselementsofa
finiteset,thenthismethodprovesthetheoremseparatelyforeach
elementoftheset.
• Notethatourproofsoflogicalequivalencebytruthtablewere
exhaustive:checkingtheequivalenceforeverycombinationoftruth-
valuesoftheindependentvariables.
• Theorem:Provethateveryevenintegerfrom2through10canbe
expressedasasumofatmost3perfectsquares.
• Proof: 2=12 +12
4=22
6=22 +12 +12
8=22 +22
10=32 +12 Q.E.D.
78
Direct Proof - Example
• Question:Isthesumofanevenintegerplusanoddintegeralwayseven?alwaysodd?sometimesevenandsometimesodd?
• Theorem:∀x,y ∈ℤ,ifxisevenandyisodd,thenx+yisodd.• Proof:Takeparticularbutarbitraryx,y ∈ℤ.Byhypothesis,thereare
k,i ∈ℤ suchthatx=2kandy=2i+1.Thus,x+y =2k+2i+1=2(k+i)+1whichisoddbecausek+i ∈ℤ (ℤ isclosedunderaddition).Q.E.D.
• Notethatanexhaustiveproofwouldnotworkbecausetheintegersℤ isnotafiniteset.
79
Directproofgeneralizingfromthegenericparticular:form
Theorem:∀ xinD,if<hypothesis>then<conclusion>
Proof:• supposexisaparticularbutarbitrarilychosenelementinDsuchthat<hypothesis>istrue,and
• showthat<conclusion>istrueforx(notrelyingonanythingaboutxthefactthatx∈D).
• Q.E.D.(quoderat demonstrandum,i.e.,“whichwastobeshown).
80
Directions for Writing Proofs1. Copythestatementofthetheoremtobeprovedontoyourpaper
(exceptonexams!).
2. Clearlymarkthebeginningofyourproofwiththeword“Proof:”.
3. Writeyourproofincompletesentences.
4. Makeyourproofself-contained.(E.g.,introduceallvariables,but
donotrenamevariablesalreadydefinedthere!)
5. Giveareasonforeachassertioninyourproof.
6. Includethe“littlewords” thatmakethelogicofyourarguments
clear.(E.g.,then,thus,therefore,so,hence,because,since,Notice
that,etc.)
7. Makeuseofdefinitionsbutdonotincludethemverbatiminthe
bodyofyourproof.
81
Common Proof-Writing Mistakes1. Arguingfromnon-arbitraryexamples.
2. Usingthesamelettertomeantwodifferentthingsortwodifferentvariablestomeanthesamething.
3. Jumpingtoaconclusion.
4. Beggingthequestion.
5. Misuseoftheword “if.”
82
Rational Numbers• Definition: Arealnumberisrational if,andonlyif,itcanbewrittenasa
ratioofintegerswithanonzerodenominator.• Thatis:r∈ℚ⇔ ∃a,b∈ℤsuchthatr=a/bandb≠0.• (*)Numberswithfiniteorrepeatingdecimalexpansionsarerational.• Forexample,
43.205=43205/10002.3333…=7/3-1.2=(-6)/5=6/(-5)0=0/121.34343434…=:xwhere100x-x=2134-21sox=(2134-21)/99
• Theseexamplesdonotformaproofof(*).• Exercise:Buttheideasfortheproofarethere…
83
Example: ℚ closed under addition
• SimpleFact(ZeroProductProperty): Ifanytwononzerorealnumbersaremultiplied,theproductisnonzero.
• Theorem: Ifm,n∈ℤ≠0 (arenonzerointegers), then(n/m)+(m/n)∈ℚ(isrational).
• Proof:– Byexpressingwithacommondenominator(nm),wegetthat
(m/n)+(n/m)=(m2+n2)/(nm),where:– m2+n2 andmn∈ℤ(sinceintegersareclosedunderbothmultiplicationandaddition)and
– mn≠0bytheabovesimplefact.– Q.E.D.
• Exercise:Proveℚisclosedunderadditionandmultiplication.
84
Disproof of a universal statement by counter- example
Theorem:Therationals arenotclosedunderdivision.Proof:• Notethatweneedtoprovethefollowingstatementisfalse:∀x,y∈ℚ,x/y∈ℚ
• Equivalentlythatthefollowingstatementistrue:~(∀x,y∈ℚ,x/y∈ℚ )≡∃x,y∈ℚ s.t. x/y∉ℚ
• Considertherationalnumbersx=1=1/1andy=0=0/1.
• Theirquotientx/y=1/0isnotrational(notevenreal).
• Q.E.D.
85
Note regarding the last example
• Readthetheoremstatementcarefullyanddon’tconfusedefinitions.
• Theprevioustheoreminvolvesaquotientofrationalnumbers,not(directly)aquotientofintegers(asfactorsinthedefinitionofarationalnumber).
• Alsonotethatthetheoremstatementneedsitsconditionsbecausethequotientofanytworealnumbers,e.g.,20.5/3,isobviouslynotrational.
86
Divisibility
Definition: Givenanyintegersnandd≠0,thefollowingstatementsareequivalent.
• nisdivisibleby d• nisamultipleof d• disafactorof n• disadivisorof n• ddivides n• d| n• nequalsdtimessomeinteger• ∃k∈ℤ suchthatn=dk.
87
Examples
1.Is18divisibleby6?Answer:Yes,18=6∙3.
2.Does3divide15?Answer:Yes,15=3∙5.
3.Does5|30?Answer:Yes,30=5∙6.
4.Is32amultipleof8?Answer:Yes,32=8∙4.
5.Ifkisanyinteger,doeskdivide0?Answer:Yes,0=k∙0,except0ł 0.
88
Examples (cont)
• Fact:Ifaandbarepositiveintegersanda|b,thena≤b.
6.Whichintegersdivide1?Answer:Only1and-1.
7.Ifmandnareintegers,is10m+25ndivisibleby5?Answer:Yes.10m+25n=5(2m+5n)and2m+5nisaninteger
becauseitisasumofproductsofintegers(thesetofintegersisclosedundersumsandproducts).
89
Divisibility stated formally
nisdivisiblebyd(d≠0)impliesddividesn:d|n⇒∃k∊ℤ suchthatn=dk.
Thecontrapositiveofthisstatementis: ∀k∀k∊ℤ,n≠dk ⇒d ł n
Example:Does5|12?Solution: Nobecause12/5isnotaninteger.
Note:• 12/5isanumber:(twelfthfifths)=2.4• 5|12isastatement:“5divides12”.
90
Divisibility is transitive
Theorem:∀a,b,c∈ℤ,ifa|bandb|cthena|c.
Proof:• Takearbitrarya,b,c∈ℤ suchthata|bandb|c.• So,∃n,m ∈ℤ suchthatb=na andc=mb.• Bysubstitution,c=m(na)=(mn)a,wherethesecondequalityis
theassociativepropertyofmultiplicationofrealnumbers.• Sincetheintegersareclosedundermultiplication,mn ∈ℤ.• So,a|c.• Q.E.D.
91
Disproof of a universal statement by counter-example
Theorem:Thefollowingstatementisfalse:∀a,b ∈ℤ,ifa|b2 thena|b.
Proof:• Wearerequiredtoprovethatthefollowingstatementistrue:
~(∀a,b ∈ℤ,ifa|b2 thena|b)≡∃a,b ∈ℤ s.t. a|b2 anda ł b
• Fora=20andb=10,clearly:• 20,10∈ℤ• 20|102 where102=100• 20 ł 10• Q.E.D.
92
48
4 12
2 2 4 3
2 2
Prime and Composite Numbers• Definition:Anintegernisprime if,andonlyif,n>1andtheonly
positivefactorsofnare1andn.• Definition:Anintegerniscomposite if,andonlyif,n>1andn=rs
forsomepositiveintegersrandswhereneitherrnorsis1.• Note:Anintegerniscomposite if,andonlyif,n>1andn=rsfor
somepositiveintegersrandswhere1<r<nand1<s<n.• Also,anintegern>1iseitherprimeorcomposite.• Theorem (DivisibilitybyaPrime): Givenanyintegern>1,thereis
aprimenumberpsothatp| n.• Recallingthatdivisibilityistransitive:Tracingdownanybranchofa
binaryfactortreeleadstoaprimefactor(attheleaf)ofthenumber(attheroot),e.g.,
93
Unique Factorization Theorem(a.k.a. Fundamental Theorem of Arithmetic)
• UniqueFactorizationTheoremfortheIntegers: Givenanyintegern>1,eithernisprimeorncanbewrittenasaproductofprimenumbersinawaythatisunique,except,possibly,fortheorderinwhichthenumbersarewritten
• Ex.1:500=5�100=5�25�4=5�5�5�2�2=2�5�5�2�5=2253(standardfactoredform)
• Ex.2:5003 =(2253)3 =(2253)(2253)(2253)=2659
• Note:If1wereprime,thenprimefactorizationswouldnotbeunique.Forinstance,10=2�5=1�2�5=1�1�2�5.
• Note: theprevioustheoremsimplyimpliedby(acorollaryof)theUFT.
94
Examplere.8!=8�7�6�5�4�3�2�1
Ex.3:Howmany0’sareattheendof8!?
Solution:• 8!=8�7�6�5�4�3�2�1=23�7� (2�3)�5� (2�2)�3�2=27�32�5�7
• Eachfactorof10givesrisetoonezeroattheendofanumber.• 10=2�5.• Thefactorizationof8!containsonlyonepair2�5.• Sotheansweristhatthereisonlyonezeroattheendof8!
95
Quotient-Remainder Theorem • Example:Suppose14objectsaredividedintogroupsof3?
• Thatis:xxxxxxxxxxxxxx
• Theresultis4groupsof3eachwith2leftover.
• Wewrite14=4�3+2where– 4isthequotientand
– 2istheremainder(theremainderisalwaysnonnegativeandlessthanthedivisor,3).
• Equivalently,14/3=4+2/3
• Andbylongdivision:
4 ⃪quotient
divisor→3)14⃪dividend
-12
2⃪remainder
96
Quotient-Remainder Theorem• Forallintegersnandpositive integersd,thereexist
uniqueintegersqandrsuchthat
n=dq +rand 0≤r<d.
• Ex:Findqandrifn=23andd=6.
Answer:q=3andr=5
• Ex:Findqandrifn=–23andd=6.
Answer:q=– 4andr=1
97
Consequences: every integer is either even or odd
• Applyingthequotient-remaindertheoremwithd=2givesthatthere
existuniqueintegersqandrsuchthat
n=2q+rand0≤r<2.
• Whatarepossiblevaluesforr?
Answer:r=0orr=1
• Consequence:Nomatterwhatintegeryoustartwith,iteitherequals
2q+0(=2q)or2q+1forsomeintegerq.
• So: Everyintegeriseitherevenorodd.
98
Consequence: dividing by 3• Similarly:Givenanyintegern,applythequotient-remaindertheorem
withd=3.Theresultisthatthereexistuniqueintegersqandrsuchthat
n=3q+rand0≤r<3.• Whatarepossiblevaluesforr?Answer:r=0orr=1orr=2
• Consequence:Givenanyintegern,thereisanintegerqsothatncanbewritteninoneofthefollowingthreeforms:
n=3q, n=3q+1,n=3q+2.
• Similarlyforothervaluesofintegerdivisorsd>0:onecandefineddifferentgroupsofintegersbasedontheirremaindersafterdividingbyd,cf.equivalenceclasses.
99
Example Direct Proof by Division into CasesTheorem: Givenanyintegern,thereisanintegerksothatn2 =3korn2 =
3k+1.OutlineofProof:• Supposenisany integer.• Bythequotient-remaindertheoremwithd=3,thereisanintegerqso
thatn=3qORn=3q+1ORn=3q+2.
• Wewillshowthatregardlessofwhichofthesehappenstobethecase,theconclusionofthetheoremfollows.
• Case1,n=3qforsomeintegerq:(exercise:fillin)• Case2,n=3q+1forsomeintegerq:(exercise:fillin)• Case3,n=3q+2forsomeintegerq:(exercise:fillin)• Hence,ineverycasethereexistsanintegerksothat
n2 =3korn2 =3k+1.• Q.E.D.
100
Example Direct Proof by Division into Cases (cont)HowwouldwefillinCase2,forexample?
• Ifn=3q+1forsomeintegerq,thenn2 =(3q+1)2 bysubstitution
=(3q+1)(3q+1)
=9q2 +6q+1
=3(3q2 +2q)+1.
• Letk=3q2 +2q.• kisanintegerbecauseitisasumofproductsofintegers.
• Thusthereisanintegerksuchthatn2 =3k+1.
101
Proof by Division into Cases
• Howdoyouprove:IfAor BistruethenCisalsotrue.• Technique: ProveifAistruethenCistrueand ifBistruethenCistrue.• Thisisacorrectformofargumentbecause
(A⋁B)→C≡(A→C)⋀(B→C)• Exercise:checkthisbytruthtable,i.e.,thatthisformofproofisvalid.
Also,drawtherelatedVenndiagram.• SomesignificantthoughtmayberequiredtodividethestatementA⋁B
intothecases(hereA,B)whichresultinthesimplestproofsforeachcase(A→C,B→C).
• Obviously,morethantwocasesmaybeinplayandeachcasemayhavesub-cases,andeachsub-casehavesub-sub-cases,etc.
• Example:Allproofsoflogicalequivalencebytruthtableemploydivisionintocases,whereeachcasecorrespondstoarowinourtableformat.
102
IdeaofProof:
• Supposenisanarbitraryintegersuchthatn>1.Taketwocases.
• Ifnisprime,wearedone(sincen|n).
• Ifnot(i.e.,ifniscomposite),thenbydef’n n=rsforsomeintegersrands
satisfying
1<r<nand1<s<n.
• Ifeitherrorsisprime,wearedone.
• Ifnot,r=r1s1,wherer1 ands1 areintegerswith
1<r1 <rand1<s1 <r.
• Ifeitherr1 ors1 isprime,wearedone(asthesearefactorsofnbytransitivityofdivisibility).
• Ifnot,repeatwithr1 inplaceofr.Etc.
• Thisprocessmusteventuallyterminateataprimefactorofnbecause:each
successivefactorisapositivefactorofn(transitivityofdivisibility)andn<∞sothatthereareonlyafinitenumberofsuccessivelystrictlysmallerfactorsr(all>1bydefinition).
• Q.E.D.
Theorem:∀n∊ℤ,ifn>1then∃primeps.t.p|n.
103
Floor and Ceiling -mapping Reals to integers
• Definition:Givenanyrealnumberx,thefloorofx,denoted⌊x⌋(or[x]),istheuniqueintegernsuchthat
n≤x<n+1.• Definition:Theceilingofx,denoted⌈x⌉,istheuniqueintegernsuch
thatn– 1<x≤n.
• Examples:⌊2.8⌋=2;⌈2.8⌉=3;⌊–2.8⌋ =-3;⌈–2.8⌉=-2• Lemma:Forallintegersk,⌊k+1/2⌋=k.• Proof:k≤k+1/2<k+1,so⌊k+1/2⌋=kbydefinition.
104
Example theorem involving floor functionwith a direct proof not involving cases
Theorem:Ifnisodd,then⌊ n/2⌋=(n– 1)/2.
Proof:• Letnbeanarbitraryoddinteger.• Bydefinitionofodd,thereisanintegerksothatn=2k+1.
• ThentheLHSoftheequationis• ⌊ n/2 ⌋ =⌊ k+1/2 ⌋ bysubstitution
=k bylemmaofpreviousslide=(n-1)/2 bysubstitution
• Q.E.D.
105
Proof by Contradiction: Introduction• Definition:Acontradictionisastatementthatis�always� false.• Ifcisacontradiction,thenthefollowingisavalidformofargumentthatp
istrue:~p (premise,i.e.,presumedtrue)~p →c (bysomevalidargument)∴c (modusponens)butacontradictioncisalwaysfalsesothepremisepmustbefalse∴p (validconclusionbyproofbycontradiction)
• Notethatif~p →c≡p⋁cistrue(byavalidargument)andcisfalsethenpmustbetrue.
106
Method of Proof by Contradiction
• Suppose thestatementtobeprovedisnottrue.
• Show thatthissuppositionleadslogicallytoacontradiction.
• Conclude:Thesuppositionisfalse.Thatis,concludethatthegivenstatementistrue.
107
Example 1 – Proof by ContradictionTheorem:Thereisnolargestrealnumber.
Proof:• Supposetherewerealargestrealnumber,N.• ConsiderthenumberN+1.• N+1isarealnumber(realsareclosedunderaddition),andN+1islargerthanN.
• ThisresultcontradictsthesuppositionthatNisthelargestrealnumber.
• Hencethesuppositionisfalse.• Q.E.D.
108
Example 2 – Proof by ContradictionDefinition:Anirrationalnumber isarealnumberthatisnotrational.
Theorem: Thenegativeofanyirrationalnumberisirrational(∊ℚ*).Proof:
• Restatingthetheoremstatementformally:
∀x∊ℚ*,–x∊ℚ*
• Foraproofbycontradiction,assume thenegationofwhatistobe
proved:
∃x∊ℚ* s.t –x∊ℚ
• Takeanysuchx.
• Since–x∊ℚ,∃a,b ∈ℤ suchthatb≠0and–x=a/b.
• Thusx=(-a)/b.
• Sincea∈ℤ and-a∈ℤ.
• So,x∊ℚ.
• Thiscontradictsthepreviousassumption,whichmustthereforebe
false.
• Q.E.D.
109
Review of elementary definitions
• Anintegernisevenif,andonlyifnisequaltotwicesomeinteger.
• Anintegernisoddif,andonlyifnisequaltotwicesomeintegerplus1.• Arealnumberrisrationalif,andonlyifitisequaltoaquotientof
integers(withnonzerodenominatorotherwiserwouldnotbereal).• Givenintegersnandd≠0,ddividesn(d|n)if,andonlyif,nequalsd
timessomeinteger.• Anintegernisprimeif,andonlyif,n>1andtheonlypositiveinteger
divisorsofnare1andn.• Givenarealnumberx,thefloorofxistheintegern=⌊x⌋suchthat
n≤ x<n+1(nisthelargestinteger≤ x)• Givenarealnumberx,theceilingofxistheintegern=⌈x⌉suchthat
n– 1<x≤n(nisthesmallestinteger≥x)• Note:Thereareotherequivalentdefinitions.
110
Recall• Thequotient-remainder theorem:Forallintegersnandpositive
integersd,thereexistuniqueintegersqandrsuchthatn=dq +rand0≤r<d.
• The“transitivityofdivisibility” theorem:∀a,b,c∈ℤ,ifa|bandb|c,thena|c.
• Anintegerniscomposite ⇔n>1andnisaproductofpositiveintegers,neitherofwhichis1.
• Theuniquefactorization theorem:Givenanyintegern>1,eithernisprimeorncanbewrittenasaproductofprimenumbersinawaythatisunique,except,possibly,fortheorderinwhichthenumbersarewritten.
111
Proof by Contraposition: Outline
Toproveauniversalconditionalstatement(i.e.,oftheform“∀ xinD,ifP(x)thenQ(x)” bycontraposition:
1) Firstformulatethelogicallyequivalentcontrapositiveofthestatement,i.e.,“∀ xinD,if~Q(x)then~P(x)”
2) Useadirectproofforthecontrapositivestatement.
112
Example proof by contraposition
Lemma:∀ integersn,ifn2 iseventhenniseven.Proof:• The(logicallyequivalent)contrapositiveoftheconditionalstatement
inthelemmais∀ integersn,ifnisoddthenn2 isodd.
• Toprovethiscontrapositive,takeanarbitraryoddintegern.• Sincenisodd,∃anintegerksuchthatn=2k+1.• Thus,n2=(2k+1)2 =2(2k2+2k)+1.• Since2k2 +2kisaninteger(beingthesumofproductsofintegers),
n2 isodd.• Q.E.D.
Recall:Alemmaisastatementusedtoproveamoreimportantresult.Exercise:Trytoprovethistheoremdirectly.
113
Proving√2IsIrrational:Background
§ Foranynonnegativerealnumbern,thesquarerootofnisthenonnegativenumbern0.5 =√nwhich,whensquared(multipliedbyitself),equalsn.
§ Examples:√4=2,(25)0.5 =5,(16/9)0.5 =4/3
§ Recall:Anirrationalnumberisarealnumberthatisnotrational.
§ Notethat1/0isnotrationalasitisnotreal.
§ Recall:Everyrationalnumbercanbewrittenin“lowestterms” (withsmallestdenominatorinmagnitude)bycancellingoutcommonfactorsinthenumeratoranddenominator,i.e.,sothatthey’re“co-prime.”
§ Example:18/24=3/4(cancelledout6),20/(-10)=-2/1(cancelledout-10)
114
Theorem:√2IsIrrationalProofbycontradiction:• Supposenot.Thatis,assume√2isrational.• So,thereexistsintegersaandbwithb≠0suchthat√2=a/b
whereaandbareassumedtohavenocommonfactors.• Thus,a2 =2b2.• So,a2 iseven,andhencealsothataisevenbythepreviouslemma.• So,thereexistsanintegerksuchthata=2k.• Aftersubstitutingfora,weget4k2 =2b2 ,so2k2 =b2.• Thusb2 iseven,andhencebisevenbythepreviouslemma.• Sinceaandbarebotheven,theyhaveacommonfactorof2.• Thiscontradictstheassumptionthataandbhavenocommon
factors.• Thustheassumptionthat√2isrationalisfalse.• Q.E.D.
115
Theorem: There are infinitely many prime numbers
Proofbycontradiction:• Supposenot.Thatis,assumethereisafinitesetofprimenumbers
p1 ,p2 …,pn withn<∞.• Considertheproductoftheseprimesplus1,i.e.,theinteger
k=1+p1�p2�…�pn• Notethatkisanintegerlargerthanallprimes(obviouslyk>1
becauseweknowthereexistsomeprimeslike2,3,5,7,11,…).• Also,noprimenumberdividesk,indeeddivisionbyanyprime
leadstoaremainderof1(i.e.,kmodp=1forallprimesp).• Thuskisnotacompositenumberasithasnoprimefactors.• Thuskisprime,whichisacontradiction.• Q.E.D.
Euclid’s algorithm for greatest common divisor (gcd)
Def’n:gcd(A,B)isthegreatestcommondivisor(>0)ofintegersAandB.0. InitialdataA,BwithA≥B≥0.Also,initiallynotethatgcd(A,A)=Aand
gcd(0,0)isnotdefined(inlattercasereturn0orerrorstatement).1. IfB=0,thenreturngcd=AandSTOP.2. Elsefinduniqueintegersq,r suchthatA=Bq+r,where0≤r<B(i.e.,
quotient-remaindertheorem).3. SetA=BandthenB=r(i.e.,(A,B)→(B,r)),andgotostep1.Notes:• Exercisere.step2:provethatgcd(A,B)=gcd(B,r);i.e.,foreachiteration
ofsteps2and3,gcd(A,B)doesnotchange.• Asaresultofsteps2and3,B(≥0)isstrictly reduced(r<B).• Alsoinstep2,r=0impliesB=gcd(A,B)(i.e.,B|A).• So,Euclid’salgorithmwillconvergetofindthegcd inafinitenumberof
iterations(cf.wellorderingprinciple).• 1845theoremofLamegivescomplexityofEAusingFibonaccisequence,
seehttp://wwwdh.cs.fau.de/IMMD8/Lectures/THINF3/Texte/euclid4.pdf 116
Euclid’s algorithm - example
• Findgcd(284,16)byEuclid’salgorithm.• Euclid’salgorithmproceedsbythefollowingiterationssince,initially,A=284>B=16>0.
1. 284=16∙17+122. 16 =12∙1+43. 12=4∙3+0(remainderisnow0)4. B=0soreturnA=4– i.e.,Euclid’salgorithm
stopshere.• So,gcd(284,16)=4.
117
118
Introduction to DiscreteMathematics
Sequences and InductionThis revision G. Kesidis (2013)
This document revision is copy-left 2013. It is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Note: these slides adapted in part from those of S.J. Lomonaco Jr., available at
http://www.csee.umbc.edu/~lomonaco/f05/203/Slides203.html
119
Sequences and Induction- Outline
• Sequences• Induction• StrongInduction
120
Sequences• Sequences representorderedlists ofelements.
• Asequence isdefinedasafunctionfromasubsetofℕ (i.e.,fhascountabledomain)toasetS.
• Weusethenotationan =f(n)todenotetheimageoftheintegern.• Wecallan aterm(thenth term)ofthesequence.
• Example:f(n)=2nforn∈ℕ (hereSmustcontainallevenpositiveintegers);sinceherefisdefinedforallnaturalnumbers(positiveintegers),wecanwritef:ℕ→S.
121
Sequences• Weusethenotation{an}n∈ℕ todescribeasequence.• Whenpossibleitisconvenienttodescribeasequencewithaformula.• Forexample,thesequence{2,4,6,8,…}ofthepreviousslidecanbe
specifiedmorepreciselyas{an}n=1∞ ={an}n∈ℕ wherean=2n.
• Findingaformula,whenoneexistsandisunique,foragivennumericalsequence(orportionthereof)canbeverytricky.
122
Formulas for simple example sequencesWhataretheformulasthatdescribethefollowingsequencesa1,a2,a3,…?
• 1,3,5,7,9,… answer:an =2n– 1
• -1,1,-1,1,-1,… answer:an =(-1)n
• 2,5,10,17,26,… answer:an =n2 +1
• 0.25,0.5,0.75,1,1.25… answer:an =0.25n
• 3,9,27,81,243,… answer:an =3n
123
Series summations of numeric sequences• ∑k=mn ak represents the sum am + am+1 + am+2 + … + an.
• This sum has n-m+1 terms when n≥m (otherwisethesumissometimesdefinedtobezero).
• The variable k is called the index of summation, running from its lower limit m to its upper limit n.
• We could as well have used any other letter to denote this index, i.e., k is a “dummy” variable.
124
Summations - examples
• Expressincompactsummationnotationthesumofthefirst1000termsofthesequence{an}withan=n2 forn∈ℕ.
Answer:∑k=11000 k2
• Whatisthevalueof∑j=16 j?
Answer:1+2+3+4+5+6=21
125
Summations
• Itissaidthatasachild,Gausscameupwiththefollowingformula:
∑k=1n k=1+2+…+n=n(n+1)/2
• Forexample:1+2+…+100=100(101)/2=5050
• Gaussusedthefollowingargument:
• LetS(n)=∑k=1n k.
• Writingthesumforwardandbackward,weget:
S(n)=1+2+3+…+n-1+n
S(n)=n+n-1+n-2+…+2+1
• Notethatwehavealignednnumbersincolumns,e.g.,1andn,2andn-1,
3andn-2,etc.,eachcolumnwithsumn+1.
• Thus,byaddingthecolumnsweget
2S(n)=(n+1)+(n+1)+…+(n+1),
wheretherearenidenticalterms(n+1)beingadded.
• Thus,2S(n)=(n+1)n.
• Exercise:Writetheaboveasatheoremstatementanddirectproof.
Arithmetic sequences of real numbers• Anarithmeticsequenceisonewherethedifferencebetween
consecutivetermsisconstant,whentheyarearrangedineitherincreasingordecreasingorder.
• Letdbethisdifferenceanda1 bethe“initial”termofanarithmeticsequence.
• So,thekth termofthisseriesisak=a1+(k-1)d
• Forexample,thesequenceofnaturalnumbersisanarithmeticserieswithd=1anda1=1.
• Notethatifd>0thena1 isthesmallesttermofthesequence,butifd<0thena1isthelargesttermofthesequence.
• Alsonotethatthesetofalloddintegersisanarithmeticsequencewithoutalargestorsmallestterm(withd=2).
• Exercise:UseGauss’sdirectargumenttodirectlyprovetheidentity∑k=1
n (a1+(k-1)d)=n(2a1+(n-1)d)/2=n(a1+an)/2∀a1,d∊ℝ,n∈ℕ,i.e.,ntimestheaveragenumberinthesequence.
126
Arithmetic series - Example• Findthesumofthearithmeticseries7+4.5+…-18.
Solution:
• Fromthegivenfacts(includingthatwearedealingwithanarithmeticsequence),weimmediatelydeducea1=7andd=-2.5.
• Thefinal(nth)termisan=a1+(n-1)d=-18;so,n=11.
• Finally,applythepriorformulatogetthatthesumis
n(a1+an)/2=11(7– 18)/2=-60.5
• Exercise: Showthatthesamesumisobtainedbyaddingthearithmeticseriesinreverseorder,i.e.,witha1=-18andd=2.5.
127
Geometric sequences of real numbers• Ageometricsequenceisonewheretheratiobetweenconsecutive
termsisconstant.
• Letrbethisratioanda1 bethe“initial”termofageometricsequence.
• So,thekth termofthissequenceis
ak=a1rk-1
• Notethatif|r|>1thena1 isthesmallesttermofthesequenceinmagnitude(absolutevalue),butif|r|<1thena1isthelargesttermofthesequenceinmagnitude.
• Foraformulaforthesumofageometricseries,S:=∑k=1n a1rk-1,first
notethatrS=∑k=2n+1 a1rk-1
• Thus,(r-1)S=rS – S=a1rn – a1 aftern-2commontermscanceloutfromeachseriesrS andS.
• Andso,
∑k=1n a1rk-1=a1(rn-1)/(r-1)∀a1,r∊ℝ withr≠1.
• Exercise: Writetheaboveasatheoremstatementanddirectproof.128
Geometric series - Example• Findthesumofthegeometricseries3-3/5+…+3/625.Solution:• Fromthegivenfacts(includingthatwearedealingwithangeometric
sequence),weimmediatelydeducea1=3,r=-1/5.• Thefinal(nth)termisan=a1rn-1 =3/625;so,n=5.• Finally,applythepriorformulatogetthatthesumis
a1(1-rn)/(1-r)=…• Exercise: Showthatthesamesumisobtainedbyaddingthegeometric
seriesinreverseorder,i.e.,witha1=3/625andr=-5.
129
130
Two Other Useful Series
• ∑k=1n k=n(n+1)/2 …arithmetic
• ∑k=1n rk =(1-rn)/(1-r) …geometric
• ∑k=1n k2 =n(n+1)(2n+1)/6
• ∑k=1n k3 =n2(n+1)2/4
• We’llreturntotheproofsofthelasttwoidentitieslater.
131
Multiple Summations
• ∑j=ab ∑k=m(j)
n(j) f(j,k)= ∑j=abg(j)whereg(j):=∑k=m(j)
n(j) f(j,k)• Obviously,multiplesummationsarenumericallycomputedbynested
loops.• Example:
∑j=1b ∑k=1
j k= ∑j=1b j(j+1)/2=0.5∑j=1
b j2 +0.5∑j=1b j
=0.5b(b+1)(2b+1)/6+0.5b(b+1)/2
• Note:Thoughthesummationorderand“splitting”thesumupasintheexampleaboveisgenerallyOKforsumsoverfinitedomains,equivalenceafterswitchingtheorderofsummation(Fubini’s theorem)overinfinitedomainsrequiresuniformconvergence.
• Exercise: Workoutthepreviousexamplebyfirstswitchingtheorderofsummations,i.e.,∑k=1
b ∑j=kb k=∑k=1
b (b-k+1)(b+k)/2=…
Induction for proof of predicate over a countably infinite domain
• Supposewewanttoprove∀n∈D,Q(n)
wherethesetSisofcountablyinfinitesize,i.e.,Scanbeenumerated
(mapped)bythenaturalnumbersℕ orsubsetthereof.
• Clearly,wecannotprovebydividingintoindividualcasesifthe
numberofcasesisinfinite.
• Wemighttrytodirectlyprovethestatementbeginningwithan
arbitraryn∈S.
• Alternatively,aproofbyinductionmaybepossible.
• ForD=ℕ,theinductiveproofof“∀n∈ℕ,Q(n)”isoftheform:
1. ProveQ(1),i.e.,basecase.
2. Forarbitraryn∈ℕ,assumeQ(n),i.e.,inductiveassumption.
3. ProveQ(n+1),i.e.,inductivestep.
4. Q.E.D.
132
Induction for proof of predicate over a countably infinite domain (cont)
• Theinductiveassumptionistrueforthelowestindexn=1(basecase)ofthepredicatetobeproved.
• So,theinductivestepiteratively(ascounting)provesQ(n)forarbitrarilylargen∈ℕ startingfrom1.
• Moresuccinctly,theinductiveargumentonℕ is∀n∈ℕ,Q(n)≡Q(1)⋀(∀n∈ℕ,ifQ(n)⋀Q(1)thenQ(n+1))
133
Induction Example
Theorem:n<2n forallpositiveintegersn.
Proof:
• LetQ(n)bethepredicate“n<2n.”
• Q(1)istruebecause1<21 =2.
• Forarbitraryintegern≥1,assumeQ(n).
• Nownotethat:
n+1<2n +1(bytheinductiveassumption)
<2n +2n (sincen≥1,2n ≥21>1)
=2n+1
i.e.,wehaveestablishedQ(n+1).
• Q.E.D.
• Notethatinsteadwecouldhavearguedasn+1≤ 2n<2n+1 wherethesecondinequalityistheinductiveassumptiontimes2.
134
Induction Example
Theorem:∀n∈ℕ, ∑k=1n k2 =n(n+1)(2n+1)/6
Proof:
• LetQ(n)bethepredicate“∑k=1n k2 =n(n+1)(2n+1)/6”.
• Forn=1,wehavethat12=1(1+1)(2∙1+1)/6,i.e.,Q(1)istrue.
• Forarbitraryintegern≥1,assumeQ(n).
• ToestablishQ(n+1),beginwith:
∑k=1n+1 k2 =(n+1)2+∑k=1
n k2
=(n+1)2+ n(n+1)(2n+1)/6(inductiveassumption)=(n+1)(n+2)(2n+3)/6
• Q.E.D.Exercise:Checkthelastequality
Exercise:Provetheformulafor∑k=1n k3
135
Induction Example (cont)• In the previous example, the inductive step can instead be argued as:Q(n+1)≡ ∑k=1
n+1 k2 =(n+1)(n+2)(2n+3)/6
⇔ (n+1)2+∑k=1n k2 =(n+1)(n+2)(2n+3)/6
⇔ ∑k=1n k2 =(n+1)(n+2)(2n+3)/6- (n+1)2 …algebra…
⇔ ∑k=1n k2 =n(n+1)(2n+1)/6 ≡Q(n)
• SinceQ(n)istruebytheinductiveassumptionandeachstepaboveis“if
andonlyif”(⇔),Q(n+1)istrue.
• Exercise:Spotthelogicalflawinthefollowingargumentthat1=0
leveragingthefactthat1=1:
1=0
0=1
1+0=0+1
1=1
136
Strong Induction
• Theprincipleofstrongmathematicalinductioninvolvesa“stronger”inductiveassumption.
• Inordertoprove“∀n∈ℕ,Q(n)”,bystronginduction:1. ProveQ(1)(basecase)2. Forarbitraryintegern≥1,assumeQ(k)forall
k∈{1,2,…,n}(strong inductiveassumption)3. ProveQ(n+1).(inductivestep)Q.E.D.
137
Strong Induction Example 1Theorem:Ifs(0)=1,s(1)=2,ands(k+1)=2s(k-1)forallintegersk>0,
thens(k)=2⌊0.5k+0.5⌋ forallintegersk≥0.Proof:
• LetQ(k)bethepredicate“s(k)=2⌊0.5k+0.5⌋”.
• Q(0)istruebecause2⌊0.5∙0+0.5⌋ =2⌊0.5⌋ =20=1=s(0),wherethelastequalityisthetheorem’shypothesis.
• Forarbitraryintegerk≥0,assumeQ(n)foralln ∈{0,1,2,3,…,k}.
• ToproveQ(k+1),wetaketwocases.
– Ifk=0,then2⌊0.5∙1+0.5⌋ =2⌊1⌋ =21=2,establishingQ(1)bytheorem’shypothesis.
– Ifk>0,thens(k+1) =2s(k-1)…bytheorem’shypothesis
=2∙2⌊0.5(k-1)+0.5⌋ …bystronginductiveassump.
=2⌊0.5(k-1)+0.5⌋+1=2⌊0.5(k-1)+0.5+1⌋=2⌊0.5(k+1)+0.5⌋
• Q.E.D.138
Strong Induction Example 1 (cont)• Theproofofthepreviousexamplecanbereworkedas:1. ProveQ(0)andQ(1)areestablishedinthebasecase2. Forarbitraryintegerk≥1,assumeQ(k)andQ(k-1)
(inductiveassumption).3. ProveQ(k+1)byusingthedifferenceequation
(inductivestep).• Thisisavalidargumentbecause:
ifQ(0)⋀Q(1)and∀k≥1, Q(k)⋀Q(k-1) ⇒Q(k+1),then∀k≥0, Q(k).
• Thefollowingtheoremrequiresastronginductionproof.
139
Strong Induction Example 2
Theorem:Everyintegergreaterthanoneiseitherprimeorcanbewrittenasaproductofprimes.
Proof:• LetQ(n)bethepredicate“nisprimeorcanbewrittenasaproduct
ofprimes.”• Q(2)istruebecause2isprime.• Forarbitraryintegern≥2,assumeQ(k)forallk ∈{2,3,…,n}.• ToproveQ(n+1),wetaketwocases.
– Ifn+1isprime,Q(n+1)istruebydefinition.– Ifn+1isnotprime(composite),
• thenthereexistsintegersn≥a,b ≥2suchthatn+1=ab;• applytheinductiveassumptiontobothaandb,and• substitutetheirprimefactorizationsinton+1=abtoshown+1is
aproductofprimes.• Q.E.D.
140
Induction - Comments
• Notethattheinitialindexinthisexamplewas2,not1,andthattheinductiveassumptionwasadjustedaccordingly.
• Exercise:Caninductionbeusedtoproveapredicatetrueoverafinitedomain?Ifso,how(ifatall)doestheformoftheinductiveproofchange?
141
More general �bootstrapping� examples
• ConsiderapredicateP.• SupposethatwehaveprovedP(3).• FindthecompletesetofintegerskforwhichP(k)istrueifwealso
provedthat:∀k≥1,P(k+1)⇒P(k)⋀P(k+3).(*)
• Answer:The�bootstrap� (*)worksforP(k+1)onlywithk+1≥2.So:P(3)⇒P(2)⋀P(5)P(2)⇒P(1)⋀P(4)P(4)⇒P(3)⋀P(6)
• Sofar,weseehowP(3)canbebootstrappedtoshowP(k)fork∈{1,2,3,4,5,6}
• Continuinginthisway,weseethattheP(k)istrueforallintegersk≥1.• Exercise: WhyisP(0)notnecessarilytrue?
142
More general �bootstrapping� examples
• FindthecompletesetofintegerskforwhichP(k)istrueifP(5)istrueandwealsoprovedthat:
∀k>0,P(k)⇒P(2k)⋀P(k-1).(*)• Answer:
P(5)⇒P(10)⋀P(4)P(4)⇒P(8)⋀P(3)P(10)⇒P(9)⋀P(20)
• Sofar,weseehowP(5)canbebootstrappedtoshowP(k)fork∈{3,4,5,8,9,10,20}
• Continuinginthisway,weseethattheP(k)istrueforallintegersk≥0(notethat(*)cannotbeappliedwithk=0).
• NotethatP(5)and∀k>0,P(k)⇒P(2k)impliesthat∀k≥0,P(5∙2k),and∀k>0,P(k)⇒P(2k)”fillsthegaps”betweenthesenumbersandgivesP(1),P(2),P(3),P(4).
143
144
Remarks:InductionandCountability
• Asetiscountable ifeachofitselementcanbeplacedinone-to-onecorrespondencewithasubsetofthepositiveintegers,ℕ=ℤ>0
• Asetiscountablyinfinite ifitiscountable andhasaninfinitenumberofelements,e.g.,
– thesetofall integers,ℤ– thesetofallrationalnumbers,ℚ
• Toseethatℚ+ iscountable,constructthematrixwhose(i,j)th entryisi/jandcounttheseentriesalongtheanti-diagonalsstartingfrom1=1/1.
• Toseethatℚ iscountable,countzerothenproceedasforℚ+ butcounteachentryi/jtwice(onceforthepositiveandtheotherforthenegative).
• Uncountable setsinclude:
– thesetofrealnumbers,ℝ
– thesetofirrationalnumbers,ℚ*=ℝ-ℚ
• Inductioncannotbeusedtoprove“∀x∈D,Q(x)”foranuncountablesetD.
THE WELL-ORDERING PRINCIPLE -background
• Definition: LetBbeasetofintegers.AnintegermiscalledaleastelementofBifmisanelementofB,andforeveryjinB,m≤j.
• Example: 3isaleastelementoftheset{4,3,5,11}.• Example: IfAbethesetofallpositiveoddintegers,then1isaleastelementofA.
• Example: LetUbethesetofalloddintegers.ThenUhasnoleastelement.
• Exercise:Giveaproofofthepreviousstatementbycontradiction.
145
WELL-ORDERING PRINCIPLE -definition
• TheWell-OrderingPrinciple: IfBisanon-emptysetofintegersandthereexistsanintegercsuchthateveryelementjofBsatisfiesc<j,thenthereexistsaleastelementofB.
• Forexample:IfBisanonemptysetofnonnegativeintegersthenthereexistsaleastelementinB(sinceBhasthewell-orderingpropertywhencisanynegativenumber).
146
WELL-ORDERING - existence of quotient-remainder theorem
Theorem:Foreveryintegeraandpositiveintegerd>0thereexist
integersqandrsuchthat0≤r<danda=qd +r.
Proof:
• LetAbethesetofallvaluesa– kd forintegersksuchthat
a– kd ≥0,i.e.,A={a-kd |k∊ℤ,a-kd≥0}.
• Toapplythewell-orderingprinciple,weneedtoshowthatAisnotempty:
– Ifa ≥0,thena-kd=a ≥0fork=0,i.e.,a∊A;
– else(a<0),letk=asothata-kd=a-ad=a(1-d) ≥0 because
1-d≤0(sinced>0)anda<0,i.e.,a ∊A.
• Bythewell-orderingprinciple,Ahasaleastelement.
• Letthatleastelementber=a– qd whereq∊ℤ
• Soa=qd +rand0≤r.
• So,thetheoremisprovedifr<d,whichcanbeshownbycontradiction…
147
WELL ORDERING – existence of quotient remainder theorem (cont)
Proof(continued):• Supposethatd≤r.• Notethata=qd +r=qd +d+(r-d)=(q+1)d+r’wherer’:=(r-d)≥0.
• Alsor’=r-d<r,becaused>0.• Soa– (q+1)d=r’<r=a– qd,anda– (q+1)d=r’≥0.• Sor’=a– (q+1)disinA,andr’<r,thuscontradictingthefactthatristheleastelementofA.
• Q.E.D.
Recallthatforeacha,d,suchq,r inthetheoremstatementmustalsobeunique,andthatthisisquicklyprovedbycontradiction.
148
149
Introduction to DiscreteMathematics
Introduction to Set TheoryThis revision G. Kesidis (2013)
This document revision is copy-left 2013.
It is licensed under a Creative Commons Attribution-
Noncommercial-Share Alike 3.0 United States License
Note: these slides adapted in part from those of
© S.S. Epp and S.J. Lomonaco Jr., the latter available at
http://www.csee.umbc.edu/~lomonaco/f05/203/Slides203.html
150
• Setscontainelementsandarecompletelydeterminedbytheelementstheycontain.
• So:twosetsareequalifandonlyiftheyhaveexactlythesameelements.
• Notation:x∈Aisread�xisanelementofA� (or�xisinA�)• x∉Aisread�xisnotanelementofA� (or�xisnotinA�)
• Ex:Let A={1,3,5}B={5,1,3}C={1,1,3,3,5}D={x∈ℤ | xisanoddintegerand0<x<6}
HowareA,B,C,andDrelated?Answer:Theyareallequal.
A Glimpse into Set Theory
151
Sets – some notation and examples• {a,b}isthesetcontainingelements�a� and�b�• {a,{a}}isthesetcontainingelements�a� and{a},thelatterbeingtheset
containingtheelement�a�• So,setscontainelementsandelementsthemselvesmaybesets,cf.the
powersetofaset.• Cannotlistelementsas{a,b,…}foranuncountableset.• Fora,b∊ℝ,thefollowingareintervals(�connected� subsets)ofℝ (an�ordered� set):• (a,b]={x∊ℝ |a<x≤b}• [a,b)={x∊ℝ |a≤x<b}• [a,b]={x∊ℝ |a≤x≤b},a�closed� interval• (a,b)={x∊ℝ |a<x<b},an�open� interval
152
Subsets• Definition:GivensetsAandB,A⊆ B(read�AisasubsetofB”)
meanseveryelementinAisalsoinB.• Equivalently:A⊆ B⇔∀x,ifx∈Athenx∈B
• Note:A⊄ B⇔∃xsuchthatx∈Aandx∉B.• Note:A= B⇔A⊆ BandB⊆ A.
• Ex:LetA={2,4,5}andB={1,2,3,4,6,7}.IsA⊆B?• Answer:No,because5isinAbut5isnotinB.
• Ex:LetC={2,4,7}andB={1,2,3,4,6,7}.IsC⊆B?• Answer:Yes,becauseeveryelementinCisinB.
153
• GivensetsAandBthataresubsetsofa�universalset”Ω.• TheirunionisA⋃B={x∈Ω | x∈Aor x∈B}
where�or� isinclusive.• TheirintersectionA⋂B={x∈Ω | x∈A and x∈B}• ThesetdifferenceA– B={x∈Ω | x∈Aandx ∉ B}• ThecomplementofAisAc ={x∈Ω | x∉A}=U– A.• Notethatonlycomplementarityrequiresspecifyingtheuniversalset.• Venndiagrams:
Definitions of Basic Set Operations
A È B
A Ç B
A – B
Ac
154
The Empty Set• Example:Assumepeopleliveinonlyoneplace.LetAbethesetof
allthepeopleintheroomwholiveinChicagoandBbethesetofallpeopleintheroomwholiveoutsideChicago.
• WhatisA⋂B=A⋂Bc ? NoteB=AcAnswer:Thissetcontainsnoelementsatall.
• Notation:Thesymbolϕ denotesasetwithnoelements.• Wecallittheemptysetorthenullset.• ToshowasetAisempty,onemightfirstassumethereisanelement
ofAandproveacontradictionresults.• Exercise:Show(5,3]=ϕ.• Notethatϕ ⊆AforanysetA(vacuouslytruebythe�if…then…�
definitionofthesubsetrelation,⊆).
155
Example
• LetA={1,2,3}andB={3,4,5}andlettheuniversalsetbeΩ ={1,2,3,4,5,6,7,8}.
• A⋃B={1,2,3,4,5}• A⋂B={3}• A– B={1,2}=A– (A⋂B)=A⋂Bc• Ac ={4,5,6,7,8}
156
Venn Diagrams• TheVenndiagrambelowrepresentssetsA,B,andCsothat
A⊆C,A⋂B=ϕ (i.e.,AandBaredisjoint),andB⋂ C≠ϕ.• AVenndiagramrepresentsinfinitelymanydifferentdiscreteinstances,
e.g.,A={1},C={1,2},andB={2,3},sothatA⊆C,A⋂B=ϕ,andB⋂ C={2}≠ϕ.
• WeallowVenndiagramstocontainemptyspaces,sowemayplaceadotinsidetheregionB⋂Ctoexplicitlyindicateotherwise.
• Notethataccordingtothe3facts- A⊆C,A⋂B=ϕ,B⋂ C≠ϕ – it’spossiblethatB⊆C(astrongercondition)butit’salsopossiblethatB⊄C.
Reviewofsettheory
• SupposefollowingsetsaresubsetsofsomeuniversalsetΩ.• “xisanelementofA”isdenotedx∈A• AisasubsetofB,denotedA⊆B,whenthefollowingstatementholds:
∀(forall)x∈Ω,ifx∈Athenx∈B• TheintersectionoftwosetsAandBistheset
AB=A∩B={s∈Ω |s∈Aand s∈B}={s∈Ω |s∈A, s∈B}=BAwherethesymbol“|”denotes“suchthat”(asdoes“:”)
• TheunionoftwosetsAandBisthesetA∪B={s∈Ω |s∈Aor s∈B}=B∪A
where“or”isinclusiveallowings∈AB• Thedifferenceoftwosetsisdefinedas
A- B=A\ B={s∈Ω |s∈Aands∉ B}=A∩Bc =A-AB• Theexclusiveunionoftwosetsisdefinedas
A⊕B={s∈Ω |s∈Aor s∈Bbut s∉ AB}=A∪B- AB• ThecomplementofasetAc ={s∈Ω |s∉ A}=Ω –A(hereneedtospecifyΩ)• NotethatΩc=ϕ,theemptyset,andϕc=Ω.• Forexample,ifA={1,2}andB={2,3,4},thenA∪B={1,2,3,4},AB={2},
A-B={1},B-A={3,4},A⊕B{1,3,4}.157
Venndiagramsforsetoperations/relations,whereeverythinginsidetheboxisΩ
158
E
F
(h)E⊆F
Ω
DeMorgan’stheorem- adirectproofTheorem:∀setsA,B,(A∩ B)c =Ac ∪ Bc
Proof:• Plan:showtwosetsareequalbyshowingtheycontaineachother.• ChoosearbitrarysetsA,B(addressingtheuniversalqualifier∀).• FirstshowAc ∪ Bc ⊆ (A∩ B)c :• Ifx∈Ac ∪ Bc thenx∉Aorx∉Bbydefinitionofunion,soconsiderthe
twocases.1.Ifx∉Athen x∉A∩ BbecauseA∩ B⊆A.2.Ifx∉B then x∉A∩ BbecauseA∩ B⊆B.
• Thus,x∉A∩ B(asthisisaconsequenceofbothpossiblecases).• Nextshow(A∩ B)c ⊆ Ac ∪Bc.• Ifx∈A∩ Bthenx∈B andx∈A,i.e.,xisanelementofboth.• So,ifx∈(A∩ B)c then:xcannotbeinbothAandB,i.e.,eitherx∉Aor
x∉B,equivalentlyx∈Ac ∪Bc.• Q.E.D.
159
DeMorgan’stheoremforlogic–
Directproofbyexhaustivecases
• Statementspandq,e.g.,foranarbitraryx∈ Ω,p=x∈Aandq=x∈B.
• p,qareeitherTrue=1orFalse=0.
• Thelogicalnegationoperatoris~,e.g.,~p=x∉ A.
• Notethatx∈AB≡p∧q(i.e.,pandq),x∈A∪B≡p∨q(i.e.,porq).
• ProofofDeMorgan’stheorembytruthtable(allcombinationsofp,q):
• Notethelogicalequivalence(bycolumn)~(p∧q)≡~p∨~q.Q.E.D.
• Exercise:Show(A∪ B)c=A
c∩B
cforallsetsA,B,asanimmediateconsequence
(corollary)oftheabovehalfofDeMorgan’stheorembytruthtable.
• Exercise:Showthemorebasic“contrapositive”:A⊆BifandonlyifBc⊆Ac.
p q ~p ~q ~p�~q p�q ~(p�q)0 0 1 1 1 0 10 1 1 0 0 1 01 0 0 1 0 1 01 1 0 0 0 1 0
160
pq ~(p∧ q)≡~p∨ ~q
p ~p∨ ~qq
DeMorgan’stheoremforequivalentAND(∧)andOR(∨) gateconfigurations
161
DeMorgan’stheorem–
Proofbycontradiction:background• SupposewanttoshowX≝ (A∩B)
c⊆ Y≝ A
c∪ B
cforarbitraryA,B⊆Ω.
• Definethestatementsp=z∈Xandq=z∈Yforarbitraryz∈Ω.
• So,wewanttoshowp→q,i.e.,“ifpthenq”.
• Thenegationofthisstatement,~(p→q)≡p∧ ~q
• Toprovep→qistrue,wewillshowp∧ ~qresultsinacontradiction
(andsoisfalse).
p q p→q p � ~q
1 1 1 01 0 0 10 1 1 00 0 1 0
162
DeMorgan’stheorem–Proofbycontradiction (cont)
• Assumep∧ ~q,i.e., z∈X=(A∩B)c butz∉Y=Ac ∪ Bc.
• Ifz∉Ythenz∉ Ac andz∉ Bc otherwisezwouldbeintheirunion(Y).
• So,z ∈Aandz∈B.
• So,z ∈A∩B,whichcontradictsz∈X.
• Thus,thefirstassumptionaboveisfalseandsoX⊆Y.
• Similarlyshowq∧ ~pisfalsesothatY⊆ X.
• Thus,X=Y.
• Q.E.D.
Inthiscase,thisargumentisverysimilartothedirectproofabove.
163
DeMorgan’stheoremforarbitrarynumberofsets-Proofbyinduction
Theorem:(A1∪A2 ∪…∪An)c =A1c∩ A2c ∩ … ∩ Anc foranysetsAk andanyn∈{2,3,4,…}.Proof:• DefinepredicateQ(n)=“(A1∪A2 ∪…∪An)c =A1c∩A2c ∩ … ∩ Anc ”• WehavealreadyestablishedQ(2).• Stronginductiveassumption:Forarbitraryintegern≥2,assumeQ(k)
forallk∈{2,3,…,n}.• Tocompletetheinductiveproof,weneedtoshowQ(n+1):• Tothisend,letB=A1∪A2 ∪…∪An• ByQ(2),(B∪An+1)c=Bc∩ An+1candsubstitutetheinductive
assumptionQ(n)appliedto Bc.• Q.E.D.
Note: Boththebasecaseandinductiveassumptionwereusedtoprovetheinductivestep.Also,wecouldhaveusedweakinduction.
164
Miscellaneoussimplesetidentities• Commutativepropertyof∪
A∪B=B∪AforallsetsA,B• Associativepropertyof∪
(A∪B)∪C=A∪(B∪C)forallsetsA,B,C• Similarly,associativeandcommutativepropertiesof∩• Distributivepropertyof∩over∪:
(A∪B)∩C=(AC) ∪(BC)forallsetsA,B,C.• Distributivepropertyof∪ over∩:
(AC) ∪B=(A∪B)∩(C∪B)forallsetsA,B,C.• Exercise:provetheseidentities.
165
PartitionsandDisjointCoverings• Ann-partitionofasetBisacollectionofnsetsΔ1,Δ2,…,Δn suchthat:
– Noneareempty,Δk≠ ϕ forallk– Covering,B=Δ1 ∪ Δ2 ∪…∪ Δn– Disjoint(non-overlapping), Δk∩Δj=ϕ forallk ≠ j
• Wecanwriteanobviousinclusion-exclusionformulafortheunionoftwoarbitrarysetsastheunionof3disjointsets(adisjointcovering):A∪B=[A-B]∪[B-A]∪[AB]
• Similarly,wecanwritetheunionofthreearbitrarysetsasdisjoint-coveringof7sets:A∪B∪C=[A-(B∪C)]∪[B-(A∪C)]∪[C-(A∪B)]∪[AB-C]∪ [BC-A]
∪ [CA-B] ∪[ABC]=ABcCc ∪AcBCc∪AcBcC ∪ABCc∪AcBC ∪ABcC∪ABC
• Ignoringtheemptysets,these“inclusion-exclusion”decompositions(disjoint-coverings)formpartitionsoftheleft-hand-sideunionsofarbitrarysets.
• NotethatAcBcCc⊄A∪B∪CbyDeMorgan’slaw. 166
Partitioning∪i=13 Ei intosevendisjointregions(Δ1,...,Δ7)byinclusion/exclusion
Exercise:WriteeachΔsetintermsoftheEsets.
167
Disjointcoveringsformulaforunionofan
arbitrarynumberofsetsbyinduction
• WriteA1∪A2 ∪…∪Ak =B∪Ak whereB=A1 ∪…∪Ak-1
• Findthe3-disjoint-coveringofB∪Ak byinclusion-exclusion.
• NotethatbyDeMorgan,thetermtoAk –B=Ak ∩Bc simplifiestoa
singleelementoftheinclusion-exclusionexpansion.
• Applytheinductivelyassumedknowninclusion-exclusionexpansion
forB=A1 ∪…∪Ak-1 toeachoftheothertwoterms.
• Eachoftheseothertermswillproducen-1elementsafterdistribution
of-Ak (∩Akc)or∩Ak
• Notethatifg(k-1)isthenumberofsetsinvolvedintheinclusion-
exclusionformulafork-1sets,theng(k)=2g(k-1)+1.
• Exercise:Fillinthedetailsofthisinductiveargument.
• Exercise:Doestheargumentworkifyoudistribute∪Ak overthe
expansionofBfirst,andthenapplythe3-partitionineachofthe
resultingterms?
168
AnInclusion-ExclusionFormulawithNot-DisjointSets
• ConsiderfoursetsA,B,C,Dnotnecessarilydisjoint.• Aninclusion-exclusionformulafor
P(A⋃B⋃C⋃D)=P(A)+P(B)+P(C)+P(D)-P(AB)-P(AC)-P(AD)-P(BC)-P(BD)-P(CD)+P(ABC)+P(ABD)+P(ACD)+P(BCD)-P(ABCD)
• Note:P(ABCD)isadded4=C(4,1)timesinP(A)+…+P(D),6=C(4,2)timesin–P(AB)-…-P(CD),andadded4=C(4,3)timesinP(ABC)+…+P(BCD),andthusmustsubtractedoncesothatitcontributesonlyoncetotheuniononLHS.
• Exercise:Stateandprovethisinclusion-exclusionformulaforarbitraryfinitenumberofsetsnbyinduction.
169
Cartesian products• Supposewewanttodefinethesetof“outcomes”aftertossingtwo
different6-sideddice(i.e.,thenumbersontheirupturnedfacesaftertheystopmoving).
• Eachdiehasoutcomesbelongingtotheset{1,2,3,4,5,6}.• So,thepairofdicehasoutcomesbelongingtotheCartesianproduct,
{1,2,3,4,5,6}� {1,2,3,4,5,6}={1,2,3,4,5,6}2={(n,m)|n,m∈{1,2,3,4,5,6}},wherenistheindexofthefirstdie,andmisthatofthesecond.
• Thetotalnumberofpossibleoutcomesofthepairis6⨯6=36.• Similarly,ℝ�ℝ�ℝ=ℝ3 ={(x,y,z)|x,y,z∊ℝ}.• TheCartesianproductofintervalsofℝis
(a,b]�[c,d]�(e,f)={(x,y,z)|a<x≤b,c≤y≤d,e<z<f}⊆ℝ3
170
Power Set
• ThepowersetofasetX,denoted2X,isthesetofallsubsetsofX,includingtheemptyset,ϕ,andXitself.
• Forexample,ifX={1,2},then2X={ϕ,{1},{2},X}
• Again,notehowtheelementsofthepowerset2X arethemselvessets.
• IfthenumberofelementsinXisfinite,i.e.,|X|<∞,thenthesizeofitspowersetis2|X|,i.e.,|2X|=2|X|.
• Exercise:Provethisbyinductionon|X|.
• Cf.thebinomialtheorem.
171
172
Introduction to DiscreteMathematics
Introduction to Probability TheoryThis revision G. Kesidis (2013)
This document revision is copy-left 2013. It is licensed under a Creative Commons Attribution-Noncommercial-Share Alike
3.0 United States License
See slidedeck on undergraduate probability
173
Introduction to DiscreteMathematics
Functions & Pigeonhole PrincipleThis revision G. Kesidis (2013)
This document revision is copy-left 2013. It is licensed under a Creative Commons Attribution-Noncommercial-
Share Alike 3.0 United States License
Note: these slides adapted in part from those of S.J. Lomonaco Jr.,available at
http://www.csee.umbc.edu/~lomonaco/f05/203/Slides203.html
174
Functions - definition• AfunctionffromasetAtoasetBisanassignment
– ofexactlyone elementofB
– toeachandevery elementofA.
• Wewrite
f(x)=y
ifyistheuniqueelementofBassignedbythefunctionftox∈A.
• So,iffisafunctionthen:∀x∈A,∃!y∈B s.t. f(x)=y
• IffisafunctionisamappingfromsetAtoB,wewrite
f:A→B
175
Functions – domain, co-domain and range
• Iff:A→B,wesaythatAisthedomainoffandBistheco-domainoff(theco-domainissometimescalledtherange).
• Iff(x)=y,wesaythatyistheimageofxunderfandxisapre-imageofyunderf.
• Therangeoff:A→B isthesetofallimagesofelementsofA(this�range� issometimescalledthestrictrange),whichisdenoted
f(A):={f(x)|x∈A}⊆ B
176
Functions –example where range = co-domain
Let’stakealookatthefunctionf:P→Cwith• P={Linda,Max,Kathy,Peter},and• C={Boston,NewYork,HongKong,Moscow}.
Suppose:• f(Linda)=Moscow• f(Max)=Boston• f(Kathy)=HongKong• f(Peter)=NewYork
Here,therangeoffisC,i.e.,f(P)=C.
177
Functions –example where range ⊊ co-domain
Letusre-specifyfasfollows:
• f(Linda)=Moscow• f(Max)=Boston• f(Kathy)=HongKong• f(Peter)=Boston
• Isfstillafunction? Answer:Yes.• Therangeoffisjust{Moscow,Boston,HongKong}
178
Functions – table or bipartite-graph representations
• Otherwaystorepresentafunctionf:
BostonPeter
Hong KongKathy
BostonMax
MoscowLinda
f(x)x Linda
Max
Kathy
Peter
Boston
New York
Hong Kong
Moscow
179
FunctionsIfthedomainofourfunctionfislarge,itisconvenienttospecifyfwithaformula,e.g.,
f:ℝ→ℝ withf(x)=2x,∀x∈ℝ
Thisleadsto,e.g.,• f(1)=2• f(3)=6• f(-2.5)=-5
180
Sums and products of functions• Letf1 andf2 befunctionsfromAtoℝ.• Thenthesumandtheproductoff1 andf2 arealsofunctions
fromAtoℝ definedby:(f1 +f2)(x)=f1(x)+f2(x),∀x∈ℝ(f1f2)(x)=f1(x)f2(x),∀x∈ℝ
• Examples:∀x∈ℝ:f1(x)=3x,f2(x)=x+5(f1 +f2)(x)=f1(x)+f2(x)=3x+x+5=4x+5(f1f2)(x)=f1(x)f2(x)=3x(x+5)=3x2 +15x
181
Functions – image of a domain subset
• Recalltherangeofafunctionf:A→Bisthesetofallimagesf(x)ofelementsx∈A,denotedf(A).
• IfweonlyregardasubsetS⊆A,thesetofallimagesofelementss∈S iscalledtheimageofS.
• WesimilarlydenotetheimageofSbyf(S):
f(S)={f(s)|s∈S}⊆ B
A BS f(S)f
182
FunctionsConsiderthefollowingfunction:• f(Linda)=Moscow• f(Max)=Boston• f(Kathy)=HongKong• f(Peter)=Boston
• WhatistheimageofS={Linda,Max}?• Answer:f(S)={Moscow,Boston}
• WhatistheimageofS={Max,Peter}?• Answer:f(S)={Boston}
183
Properties of Functions –one-to-one/injective
• Afunctionf:A→B issaidtobeone-to-one(orinjective),if∀x,y ∈A,f(x)=f(y)⇒ x=y.
• Sincefisafunction,wecanstatethatit’sone-to-oneif∀x,y ∈A,f(x)=f(y)⇔ x=y.
• Inotherwords:fisone-to-oneifandonlyifitdoesnotmaptwodistinctelementsofAontothesameelementofB.
• Thatis,theabove(first)definitionin(logicallyequivalent)contrapositiveformis:Afunctionf:A→B issaidtobeone-to-one(orinjective),if
∀x,y ∈A,x≠ y⇒ f(x)≠ f(y).
184
Properties of Functions –one-to-one: example
Considerthefunctionsfandg:• f(Linda)=Moscow• f(Max)=Boston• f(Kathy)=HongKong• f(Peter)=Boston
• Isfone-to-one?
• No,MaxandPeteraremappedontothesameelementoftheimage.
• g(Linda)=Moscow• g(Max)=Boston• g(Kathy)=HongKong• g(Peter)=NewYork
• Isgone-to-one?
• Yes,eachelementisassignedauniqueelementoftheimage.
185
Properties of Functions –disproving one-to-one property
• Howcanweprovethatafunctionfisone-to-one?
• Wheneveryouwanttoprovesomething,firsttakealookattherelevant
definition(s);here,
∀x,y ∈A,x≠ y⇒ f(x)≠ f(y)
• Example:
f:ℝ→ℝ withf(x)=x2
Note~[∀x,y ∈A,x≠ y⇒ f(x)≠ f(y)]≡∃x,y ∈As.t. x≠y ⋀ f(x)=f(y)
Disproofofone-to-onestatementbycounterexample:x=3,y=-3,i.e.,
3≠-3butf(3)=f(-3),sofisnotone-to-one.
• Forℝ-valuedfunctions,thereisthehorizontallinetest:i.e.,ifyoucan
drawahorizontallinethatmeetsthegraphofthefunctionatmorethan
onepoint,thenthefunctionisnotone-to-one.
• Ifbipartite-graphrepresentationoff(withfinite-sizeddomainandco-
domain)hastwoarrowsthatmeetatthesameco-domainelement,thenf
isnotone-to-one.
186
Properties of Functions –one-to-one example
• …andyetanotherexample:f:ℝ→ℝ with f(x)=3x
• Def’n:f:A→B isone-to-one,orinjective,if:∀x,y ∈A,f(x)=f(y)⇒ x=y.
• Exercise: Writethisdefinitionincontrapositiveform.
• Toshowfisone-to-oneconsiderarbitraryx,y ∈Asuchthatf(x)=f(y)⇒ 3x=3y⇒x=y.
187
Increasing and decreasing functions are one-to-one
• Considerafunctionf:A→B withA,B⊆ ℝ (bothorderedsets).
• fiscalledstrictlyincreasing,if
∀x,y∈A,x<y⇔ f(x)<f(y),
• fisstrictlydecreasing,if
∀x,y∈A,x>y⇔ f(x)<f(y).
• Exercise: Provethatafunctionthatiseitherstrictlyincreasingorstrictly
decreasingisone-to-one
– byusingtheoriginaldefinitionofone-to-oneandcontradiction,and
– byusingthecontrapositivefprm andadirectproof.
188
Properties of Functions –onto/surjective, bijective
• Afunctionf:A→B iscalledonto,orsurjective,ifandonlyifforeveryelementy∈B thereisanelementx∈A withf(x)=y.
• Inotherwords,fisontoifandonlyifitsrangeisitsentireco-domain,i.e.f(A)=B.
• RecallthatasetSiscountableifthereisasurjective fsuchthatf:ℕ→S.
• Afunctionf:A→Bisbijective ifandonlyifitisbothone-to-oneandonto.
• Exercise:Provebycontractionthatiff:A→B isabijection andAandBarefinite-sizedsets,then|A|=|B|.
189
Properties of Functions - examples
• Inthefollowingexamples,weusethebipartite-graph(arrows)representationtoillustratefunctionsf:A→B.
• Ineachexample,thecompletesetsAandBareshown.
190
Properties of Functions - example
• Isfinjective?• No.• Isfsurjective?• No.• Isfbijective?• No.
Linda
Max
Kathy
Peter
Boston
New York
Hong Kong
Moscow
191
Properties of Functions - example
• Isfinjective?• No.• Isfsurjective?• Yes.• Isfbijective?• No.
Linda
Max
Kathy
Peter
Boston
New York
Hong Kong
Moscow
Paul
192
Properties of Functions - example
• Isfinjective?• Yes.• Isfsurjective?• No.• Isfbijective?• No.
Linda
Max
Kathy
Peter
Boston
New York
Hong Kong
Moscow
Lübeck
193
Properties of Functions - example
• Isfinjective?• No.• fisnotevenafunction
becausex=ydoesnotimplythatf(x)=f(y)forthecasewherex=Peter,i.e.,fistwovaluedatPeter:f(Peter)={NewYork,Lubeck}.
Linda
Max
Kathy
Peter
Boston
New York
Hong Kong
Moscow
Lübeck
194
Properties of Functions - example
• Isfinjective?• Yes.• Isfsurjective?• Yes.• Isfbijective?• Yes.
Linda
Max
Kathy
Peter
Boston
New York
Hong Kong
Moscow
LübeckHelena
195
Inversion
• Aninterestingpropertyofbijectionsisthattheyhaveaninversefunction.
• Theinversefunction ofthebijectionf:A→B isalsoafunctiondenotedf-1:B→Awith
f-1(y)=xwheneverf(x)=y.• Toseewhy,notethat
– fisontoimpliesthatf-1(y)isdefined∀y∈B– fisone-to-oneimpliesthatf-1(y)isaunique∈A
• Sometimesbijectionsarecalledinvertiblefunctions.
196
Inversion - exampleExample:
f(Linda)=Moscowf(Max)=Bostonf(Kathy)=HongKongf(Peter)=Lübeckf(Helena)=NewYork
Clearly,fisbijective.
Theinversefunctionf-1 isgivenby:
f-1(Moscow)=Lindaf-1(Boston)=Maxf-1(HongKong)=Kathyf-1(Lübeck)=Peterf-1(NewYork)=Helena
197
Inversion - exampleLinda
Max
Kathy
Peter
Boston
New York
Hong Kong
Moscow
LübeckHelena
f
f -1
f-1:C→Pisnotafunctionbecause
• itisnotdefinedforallelementsofC(i.e.,forBoston),and
• itassignstwoimagestoitspre-imageNewYork.
Relations
• Abroaderfamilyofmappingsf:A→2B arerelations fromAtoB,i.e.,frelates elementsx∈A tosubsetsofB.
• It’spossiblethatforsomex∈A,f(x)=ϕ,i.e.,noelementsofBarerelatedtox∈A underf.
• If∀x∈A,f(x)isasingletonsubsetofB,thenrelationfcorrespondstoafunctionfromAtoB.
• So,ifafunctionfisnotabijection,f-1 isonlyarelation.• Forexample,iff:ℝ→ℝ isafunctionsuchthatf(x)=x2 thenf-1:ℝ→ℝis
relationsuchthatf-1(x)=ϕ forx<0andf-1(x)={�√x}forx≥0.
198
199
Composition• Thecompositionoftwofunctionsg:A→B andf:B→C,denotedby
f∘g ,isdefinedby
(f∘g)(x)=f(g(x))
• Thismeansthat:• First,functiongisappliedtoelementx∈A mappingitontoan
elementy=g(x)ofB,• Then,functionfisappliedtothiselementofy∈B,mappingit
ontoanelementz=f(y)=f(g(x))ofC.• Therefore,thecompositefunctionf∘g:A→C (mapsfromAtoC).
• Notethatg∘f iswelldefinediftherangef(B)⊆A,i.e.,f(B)⊆A⋂C
Ax g
By
f
Cz
200
Composition - example
• Example:
• f(x)=7x– 4,g(x)=3x,• f:ℝ→ℝ,g:ℝ→ℝ
• (f∘g)(5)=f(g(5))=f(15)=105– 4=101
• (f∘g)(x)=f(g(x))=f(3x)=21x– 4
• Exercise:Showg∘f≠f ∘g
201
Composition with inverse
• Compositionofabijection anditsinverse:
(f-1 ∘f)(x)=f-1(f(x))=x,∀x.
• Thecompositionofafunctionanditsinverseistheidentityfunction
f-1 ∘f=f∘f-1 =IwhereI(x)≡x.
• Whenf:A →B isnotabijection(i.e.,f-1 isarelation),then(f-1 ∘f)(x)={a
202
Graphs of functions
• Thegraph ofafunctionf:A→B isthesetoforderedpairs
{(x,y)|x∈A andy=f(x)}={(x,f(y))|x∈A }⊆A�B.
• Thegraphcanbeusedtovisualizefinatwo-dimensionalcoordinatesystem.
• Plottingthegraphwiththedomainasahorizontalaxis:
• Allhorizontallinescutthegraphofaone-to-one(injective)functionlessthan2places.
• Allhorizontallinescutthegraphofanonto(surjective)functioninatleast1place.
203
Recall Floor and Ceiling Functions• Thefloor andceiling functionsmaptherealnumbersontothe
integers:⌊∙⌋,⌈∙⌉:ℝ→ℤ.
• Thefloor functionassignstor∈ℝ thelargestz∈ℤ withz≤r,denotedby ⌊r⌋
• Examples: ⌊2.3⌋ =2,⌊2⌋ =2,⌊0.5⌋=0,⌊-3.5⌋ =-4
• Theceiling functionassignstor∈ℝ thesmallestz∈ℤ withz≥r,denotedby⌈r⌉.
• Examples: ⌈2.3⌉ =3,⌈2⌉ =2,⌈0.5⌉ =1,⌈-3.5⌉ =-3
204
The Pigeonhole Principle• Thepigeonholeprinciple: If(k+1)ormoreobjectsareplacedintok
boxes,thenthereisatleastoneboxcontainingtwoormoreoftheobjects.
• Example1: Ifthereare11playersinasoccerteamthatwins12-0,theremustbeatleastoneplayerintheteamwhoscoredatleasttwice.
• Example2: Ifyouhave6classesfromMondaytoFriday,theremustbeatleastonedayonwhichyouhaveatleasttwoclasses.
• Wenowprovethepigeonholeprinciplebycontradiction:– Assume∀k∈ℤ+,allkboxeshave<2objects,i.e.,has1or0objects.– Thusthetotalnumberofobjects≤k <k+1 (acontradiction).– Q.E.D.
205
The Generalized Pigeonhole Principle• Thegeneralizedpigeonholeprinciple: IfNobjectsareplacedintokboxes,
thenthereisatleastoneboxcontainingatleast⌈N/k⌉ oftheobjects.
• Example1: Ina62-studentclass,atleast13=⌈62/5⌉ studentswillgetthesamelettergrade,ofwhichthereare5differentones(A,B,C,D,orF).
• Exercise: Provethegeneralizedpigeonholeprinciplebycontradiction.Hint:∀x∈ℝ,⌈x⌉-1<x
206
The Pigeonhole Principle• Example2: Assumeyouhaveadrawercontainingarandomdistributionof
adozenidenticalbrownsocksandadozenidenticalblacksocks,alllooseinthedrawer.Itisdark,sohowmanysocksdoyouhavetopicktobesurethatamongthemthereisamatchingpair?
• Therearetwotypesofsocks,soifyoupickatleast3socks,theremustbeeitheratleasttwobrownsocksoratleasttwoblacksocks.
• Thatis,bythegeneralizedpigeonholeprinciple,wewanttofindtheintegernsuchthat⌈n/2⌉ =2.Thesolutionisn=3.
Pigeonhole principle example: Dirichlet’s Approximation Theorem
• Theorem:∀a∈ℝand∀positiveN∈ℤ,∃p,q∈ℤsuchthat
1≤q≤Nand|qa-p|<1/N.
• Note:Thisimpliesthatforanyirrationala,thereisarationalp/qsuchthat|a-p/q|<1/(qN)≤1/N,i.e.,anarbitrarilycloseapproximationbyarational.
• Thus,ℚisadensesubsetofℝ,andsinceℚiscountable,wesaythat(uncountable!)ℝisseparable.
• Dirichlet,whoemployedthepigeonholeprincipletoprovethistheorem,alsocoinedthenameforthismethodofargument.
• Notethatyoucanintuitivelydosuchapproximations(givenadecimalexpansionofanirrational)bytruncatingitsdecimalexpansion,thetruncationbeingrational:ifonetruncatesatthekthdecimaldigit,thentheresultingapproximationerroris<10-k
207
Proof of Dirichlet’s Approximation Theorem
• Ifaisrational,wearedonebydefinition.Sosupposeaisirrational.• Definef(a)=a- ⌊a⌋ asthefractionalpartofa∈ℝ,sothatf:ℝ→(0,1).• Dividetheinterval[0,1)intoNsubintervalsofequallength,1/N.• Considerthesetofnumbers{f(an)|n∈{1,2,…,N+1}}.• Exercise:OnecaneasilyshowthatthereareN+1differentnumbersin
thisset(otherwisethereisacontradictionoftheirrationalityofa).• So,bythepigeonholeprinciple,theremustbetwodifferentnumbers
fromthissetthatareinthesamesubdivision,sayk/N≤f(an),f(am)<(k+1)/Nforsomek∈{0,1,2,…,N-1}withn>m.
• So,1/N>|f(an)-f(am)|=|an- ⌊an⌋- (am-⌊am⌋)|• Wecantakeq=n-mandp=⌊an⌋-⌊am⌋.• Q.E.D.
208
Introduction to Discrete Mathematics
RecursionsThis revision G. Kesidis (2013)
This document revision is copy-left 2013. It is licensed under a Creative Commons
Attribution-Noncommercial-Share Alike 3.0 United States License
Outline• Definitionofarecurrencerelationandinitialconditionsdefininga
numericalsequence.• Numericallygeneratingthesequencebyiterativesubstitutionfrominitial
conditions.• Verifyinganexplicitformula(solution)totherecurrencerelationby
stronginduction.• Heuristictechniquesforsolvingrecursions.• Systematicsolutionofalinearandtime-invariantrecurrencerelation.• Examples.
210
Recursively defined sequences• Considerasequencesofnumbersx0,x1,x2,x3,...• Sequencescanbeexplicitlyspecifiedwithafunctionf:ℤ≥0 →ℝ,i.e.,
xn =f(n),foralln∈{0,1,2,3,...}.• Forexample,theharmonicsequencexn =1/(n+1),foralln≥0.• Alternatively,wecandefinethesequence“recursively”byexpressing
xn asafunctionofxn-1,xn-2,xn-3,...,,x0 ,foralln∈{1,2,3,...}.• Thatis,inarecursivespecification,asequenceelementisdefinedinterms
ofpastelements.• Formanyproblemsofinterest,thereisafinite“order” or“degree”,sayk,of
therecursioninthateachsequenceelementcanbespecified(recursively)onlyintermsofthepastkvaluesofthesequence,i.e.,
xn asafunctionofxn-1,xn-2,xn-3,...,,xn-k ,foralln∈{k,k+1,k+2,...}where
x0,x1,x2,...xk-1arethek“initialconditions” ofthesequencefortherecursion.
211
Recursively defined sequences –computing terms
• Givenarecursionoffiniteorderk,xn =gn(xn-1,xn-2,xn-3,...,,xn-k )forn≥k,
(i.e.,givengn)andgiventhekinitialconditionsx0,x1,x2,...xk-1 ,
wecaniterativelysubstitutetocomputexk,xk+1,xk+2,...
• Forexample,supposek=2,xn =gn(xn-1,xn-2)=xn-1+3nxn-2+7forn≥2,x0=1,x1 =0.
• Bysubstitution:x2=g2(x1,x0)=x1+3∙2∙x0+7=0 +3∙2∙1+7=13x3=g3(x2,x1)=x2+3∙3∙x1+7=13 +3∙3∙0+7=20x4=g4(x3,x2)=x3+3∙4∙x2+7=20 +3∙4∙13+7=183etc.
• Notehowboththerecursiongn andtheinitialconditionsaffecttheoutcome
• Note:Thisexampleistime-varyingbecausethecoefficientofxn-2,3n,dependsonindexn(time).
212
Recursively defined sequences –checking a solution
• Supposeaputativeexplicitformula(�solution�)xn =f(n)foragivenrecursionxn =gn(xn-1,xn-2,xn-3,...,,xn-k ),forn≥k,andi.c.�sx0,x1,x2,...xk-1 .
• Toverifythesolution,weneedtocheckf(n)=xn forall0≤n≤k-1(i.e.,theinitialconditions)andf(n)=gn(f(n-1),f(n-2))forarbitraryn≥k …bystronginduction!
• Example:Theorem:xn= f(n)=2(-2)n -2.5n(-2)n isthesolutiontoxn=-4xn-1-4xn-2 forn≥2,x0=2,x1 =1.
• Proof:Toverifythissolution,firstcheckthek=2initialconditions:f(0)=2(-2)0 -2.5∙0∙(-2)0 =2=x0f(1)=2(-2)1 -2.5∙1∙(-2)1 =-4+5=1=x1
• Foranarbitraryn≥1,assumexm= f(m)uptom=n.• Toprovetheclaimforn+1:
xn+1 =-4xn-4xn-1 (bythegivenrecursion)=-4f(n)-4f(n-1) (bytheinductiveassumption)=-4[2(-2)n -2.5n(-2)n ]-4[2(-2)n-1 -2.5(n-1)(-2)n-1 ]=f(n+1).Q.E.D.
• Exercise:verifythelastequality.• Exercise:Explainwhyn≥1intheinductiveassumptionandnotn≥0orn≥2.
213
Solving simple first-order recursions:Arithmetic and geometric progressions
• Recallthe(firstorder)arithmeticprogression,xn =xn-1 +dforn≥1,withinitialconditionx0
• Thus,forn≥0,xn =(xn-2 +d)+d(substitutingforxn-1 )
=xn-2 +2d=xn-n +nd (afternsuchsubstitutions)=x0 +nd (=f(n))forn≥0
• Similarly,forageometricprogression,xn =rxn-1 forn≥1,withinitialconditionx0 ,
thesolutionisxn =rn x0 (=f(n))forn≥0
214
Solving simple first-order recursions:Arithmetic and geometric progressions
• Wecan,e.g.,sumasequencetocreateanothersn =∑i=0n xi i.e.,sn =sn-1 +xn =sn-1 +x0 +nd
• sisafirstorderrecursion.• Recallthatifxisarithmeticthenthesolutionforsis:
sn =(n+1)(xn +x0 )/2=(n+1)(2x0 +nd )/2• Ifxisgeometric,thentheseriesrecursionis
sn =sn-1 +xn =sn-1 +x0rnandrecallthatthesolutionforsis:
sn =x0 (rn+1 -1)/(r-1).
215
Solving linear and time-invariant recurrence relations of finite degree• Supposethattherecurrencerelationisoffinitedegree/orderkandis
linearandtime-invariant:xn =∑i=1k aixn-i =g(xn-1,xn-2,xn-3,...,,xn-k), (*)
wheregislinear(theai areallscalars)anddoesnotdependonindex/time(n).
• Giventhekinitialconditions,oneemploythetheoryofZ-transformstoderiveanexplicitformulaforxn foralln≥k.
• Equivalently,findtherootsofthe(characteristic)polynomialQ(z)=zk - ∑i=1k aizk-i .
• Bythefundamentaltheoremofalgebra,thereareksuchroots(orcharacteristicmodes),r1,r2,...rk
• Exercise:Verifyxn =rn satisfiestherecursion(*)above∀ rootsrofQ.• Ingeneral,therootsrmayberepeatedandmaybecomplex,butif
complextheycomeincomplex-conjugatepairsbecauseallcoefficientsaiofQareassumedreal.
216
Linear and time-invariant recurrence relations of finite degree• AssumingnoneoftherootsrofQarenotrepeated(i.e.,eachisjusta
singlerootofQ),wecanwriteanexplicitformulafor xn (i.e.,“solve” xn ):xn =∑i=1k cirin foralln≥0
wherethekscalarsci arefoundbyusingthekgiveninitialconditions,i.e.,solvethekequations,
xn =∑i=1k cirin k-1≥n≥0,forthekunknownsc1,c2,...ck
• IftherootrofQisofmultiplicitym≤k,thenusethefollowingm“linearlyindependent”characteristicmodesinthesolutionabove(insteadofminstancesofrin ):
rin ,nrin ,n2rin ,...nm-1rin ,seethepreviousexampleforrootr=-2oforderm=2.
217
Linear and time-invariant recurrence relations of finite degree• Forexample,supposeandxn=gn(xn-1,xn-2)=3xn-1-2xn-2 forn≥2,and
x0=1,x1 =-1.
• Here,k=2andQ(z)=z2 -3z +2=(z-2)(z-1)
• So,therootsofQare2and1.
• Thus,thesolutionxn= f(n)=c22n +c1 1n =c22n +c1 forn≥0.
• Tosolveforthescalarsc2,c1 ,usethegiveninitialconditions:
f(0)=c2 +c1 =1=x0f(1)=2c2 +c1 =-1=x1
leadingto
c2 =-2andc1 =3.
• Thus,xn=-2n+1 +3forn≥0.
218
Solving more general forms ofrecurrence relations
• SystematicapproachestotheLTIrecursioncanbeextendedtoconsidergiven“input”(orforcing)function,sothatthesolutioncanbewrittenasasumof– asolutiondependingonlyontheinitialconditions(zeroinput
response)and– anothersolutiondependingonlyonthegiveninputfunction(zero
initialstateresponse);– e.g.,theconstantinput(7)ofthepreviousaffineexample.
• Systematicapproachestothesolutionofmoregeneral(e.g.,nonlinear)formsofrecurrencerelationsmaynotexist.
• Sometimes,iterativesubstitutionornumericallyevaluatingthesequenceforseveralinstanceswillgivesomeinsightandbethebasisofaguessaboutthesolution.
• Anyguessshouldbecheckedbystronginductiveproof,ofcourse.
219
The Tower of Hanoi• Inthe3-pegTowerofHanoiproblem,astackofdisksinitiallyresideona
singlepeg,whiletheothertwopegsareempty.• Thedisksareallofdifferentwidths.• Initially,theyarestackedinwidth-ordersuchthatthelargestdiskisatthe
bottom,i.e.,theyformaconeshapeonthepeg.• Theproblemistomoveallthedisksfrompegtopegsothat
– theyformthesameconeonadifferentpeg,and– alargediskisneversetdownuponasmallerdiskonapeg.
220
The Tower of Hanoi - 3 pegs• Letxn =betheminimum numberofmoves/stepsrequiredtomovendisks.• Thinking“inductively”,supposewehaven+1disksonpeg1.• Leavethelargestdiskatbottomalone,andmovetheremainingndisksto
peg2inxn steps.• Movethelargest(n+1)st topeg3,requiring1step.• Finally,movethendisksfrompeg2topeg3(atopthelargestdisk),again
requiringxn steps.• So,xn+1 = xn +1+ xn =2xn +1steps.
221
The Tower of Hanoi (cont)• Toseewhythisrecursiongivestheminimalnumberofmoves,notethatone
simplycannotmovethelargestdiskuntilonoftheothertwopegsisempty.• Whenthisoccurs,onlythelargestdiskisononepeg,onepegisempty,and
thethirdpegmusthaveallnotherdisksstackedbywidthorder.• Thatis,togettothepointwhereonecanallowablymovethelargedisk
requiresaminimumofxn steps/movesofthensmallerdisks.• Nowhowthisargumentdoesnotholdiftherearefourormorepegs
becauseneednotstackallnsmallerdisksonasinglepostbeforewecanmovethelargerone.
• So,inthecaseof4ormoreposts,wecanusetheaboveargumentonlytoconcludeisthat
xn+1 ≤ 2xn +1.
222
The Tower of Hanoi (cont)• Forthe3-pegproblem,notethat
xn+1 =2xn +1forn>1withx1 =1isafirstorderrecursionwithconstantinput1.
• Numericallyevaluatingthesequence,weget1,3,7,15,31,…
fromwhichwecanguessxn =2n-1forn≥1.• Thezeroinputresponse(tojusttheinitialconditions)is
xn =2n-1x1 =2n-1 forn≥1• Thezero(initial)stateresponse(tojusttheinput1)is
xn =2n-1-1forn≥0;(thiscanbesystematicallyfoundbyconvolutionorZ-transform).
• So,thetotalresponseisxn =2n-1 +2n-1-1=2n-1forn≥1.
223
Example:Choosingyournoodles• Considerabowlwithnnoodlestrands,eachwith2ends.• Twonoodle-endsareindependentlychosenuniformlyatrandomfrom
thebowl;ifbothendsbelongtothesamenoodle,thenoodleisremovedfromthebowl,otherwisetheendsarejoinedtoformalongernoodlewhichisreturnedtothebowl.
• Thisprocessisrepeateduntilthebowlisempty(innsteps).• FindtheexpectednumberXn ofnoodlesEXn drawnfromthebowl.• Clearly1≤Xn≤n.
224
Example:Choosingyournoodles (cont)• Toobtaintheanswer,considerwhathappensinthefirst choice:
– withprobabilityn/C(2n,2)=1/(2n-1)theendsofthesamenoodlearechosen,i.e.,Xn =1+Xn-1
– withprobability1- 1/(2n-1)theendsofthedifferentnoodlesarechosen,i.e.,Xn =Xn-1
• So,by conditioningonthefirstchoice,EXn =(1+EXn-1)∙1/(2n-1)+(EXn-1)∙(1-1/(2n-1))
=1/(2n-1)+EXn-1wherewehaveobviouslyusedthelinearitypropertyofexpectation.
• Byrecursivesubstitution,EXn =1/(2n-1)+1/(2n-3)+…+1/3+1,
whereEX1 =X1 =1,i.e.,X1 isconstant.
• ThisquestionwasaskedduringQualcommjobinterviewsin2011.225
Finding the maximum of a unimodal function by sectional search
• Afunctionf:[a,b]→ℝ isstrictlyunimodaloveraninterval[a,b]⊆ℝ if– ithasauniquemaximizingpointz∈[a,b],– fisstrictlyincreasingon[a,z],and– fisstrictlydecreasingon[z,b].
• Theobjectiveistofindzbysamplingfin[a,b].• Butassumef(x)isverycostlytoevaluateforallpointsx∈[a,b].• Initially,for“sectional”search,wehave
– intervalI(0)=[a,b],withendpointsa(0)=aandb(0)=b– Twoinitialintermediatepointsx(0),y(0)∈I(0)suchthat
a(0)<x(0)<y(0)<b(0).– Thefunctionfevaluatedatallofthesefourpoints.
226
Finding the maximum of a unimodal function by sectional search
• Sincefisunimodal:If f(x(0))≥f(y(0)) thenz∈[a(0),y(0)],elseiff(x(0))≤f(y(0))thenz∈[x(0),b(0)]
• Thatis,wecandeterminethesub-intervalcontainingthef-maximizingpointzifwehavetwointermediatepoints.
• Notethatonecannotmakethisdeterminationifonlyoneintermediatepointisused.
• Theplanistoshrinktheintervaldowntothesub-intervalcontainingzinthenextiteration,andtodosobyaconstantfactorforeveryiteration.
227
a
f
y bxy' b'a' x'
Finding the maximum of a unimodal function by sectional search
So,forthenthintervalI(n)=[a(n),b(n)],n≥0:• iff(x(n))≥f(y(n))then:
• a(n+1)=a(n)andb(n+1)=y(n), (sincez∈[a(n),y(n)])• selectapointv∈[a(n+1),b(n+1)],• evaluatef(v),and• take{x(n+1),y(n+1)}={x(n),v}s.t. x(n+1)<y(n+1)
• else:• a(n+1)=x(n)andb(n+1)=b(n), (sincez∈[x(n),b(n)])• selectapointv∈[a(n+1),b(n+1)],• evaluatef(v),and• take{x(n+1),y(n+1)}={y(n),v}s.t. x(n+1)<y(n+1)
• Iffisalsocontinuousnearitsmaximum,anaturalstoppingruleforsearchiswhentheintervalbecomessmallerthanapredefinedthreshold,otherwisen++andrepeattheabove.
228
Finding the maximum of a unimodal function by golden-section search
• Notethat,beyondpreservinga(n)<x(n)<y(n)<b(n),
wehaven’tyetpreciselyspecifiedhowsectionalsearchworks.• Supposeourobjectiveis:foreachiterationn:
– evaluatefatjustonenewpointv(exceptattwopointsinitially(n=0)),and– reducethewidthoftheintervalbythesamefactor,g.
• Thatis,letd(n)=b(n)-a(n)betheintervalwidth,andsupposethat,foralln,wewishtofixtheproportions
g:=[y(n)-a(n)]/d(n)=[b(n)-x(n)]/d(n)⇒[b(n)-y(n)]/d(n)=1-[y(n)-a(n)]/d(n)=1-g.
• So,ifa(n+1)=x(n)andb(n+1)=b(n),sothatd(n+1)=gd(n),wethenassignx(n+1)=y(n)andtakev=y(n+1)>x(n+1)suchthatg=[v-a(n+1)]/d(n+1).
• Thusalsog=[b(n+1)-x(n+1)]/d(n+1)whichimpliesg=[b(n)-y(n)]/[gd(n)]=(1-g)/g
229
Finding the maximum of a unimodal function by golden-section search
• So,g=(1-g)/g,i.e.,g2 +g-1=0.
• Therefore,g=(-1+50.5)/2≈0.618
• 1+gisthe“goldenratio”ofancientGreece.• Ifthestoppingthresholdispositiveθ≪1thenbecausethelengthofthe
intervalssatisfiestherecursiond(n+1)=gd(n),thenumberofiterationsNrequiredbygolden-sectionsearchisthesmallestintegerNs.t.d(N)=d(0)gN <θ ,i.e.,N=é log(θ/d(0))/log(g)ù .
• So,thecomputationalcomplexityofgolden-sectionsearchisΘ(N).
230
231
Introduction to DiscreteMathematics
Introduction to ComplexityThis revision G. Kesidis (2013)
This document revision is copy-left 2013. It is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Note: these slides adapted in part from those of S.J. Lomonaco Jr.,available at
http://www.csee.umbc.edu/~lomonaco/f05/203/Slides203.html
232
Algorithms
• Whatisanalgorithm?
• Analgorithmisafinitesetofpreciseinstructionsforperformingacomputationorforsolvingaproblem.
• Thisisarathervaguedefinition.Youwillgettoknowamorepreciseandmathematicallyusefuldefinition.
• Butthisoneisgoodenoughfornow…
233
Algorithms
• Analgorithmhasaninput fromaspecifiedset,
andproducesanoutput fromaspecifiedset(solution).
• Propertiesofalgorithms:• Definiteness ofeverystepinthecomputation,• Correctness ofoutputforeverypossibleinput,• Finiteness ofthenumberofcalculationsteps,• Effectiveness ofeachcalculationstepand• Generality foraclassofproblems.
234
Algorithm Example:Find the Maximum
• Wewilluseapseudocodetospecifyalgorithms,whichslightlyremindsusofBasicandPascal.
• Example:
procedure max(a1,a2,…,an:integers)max:=a1for i :=2to n
if max<ai then max:=ai
• Notethattheprocedurefinds�max� =largestelementof{a1,a2,…,an}
235
Algorithm Example: Linear Search of Unordered List
• Anotherexample:alinearsearchalgorithm,thatis,analgorithmthat
linearlysearchesasequenceforaparticularelement.
procedure linear_search(x:integer;a1,a2,…,an:integers)
i :=1
while(i £ nandx¹ ai)i :=i +1
if i £ nthen location:=ielse location:=0
• Notethatlocationisthesubscriptofthetermthatequalsx,oriszeroifx
isnotfound
• Also,theworst-casenumberofiterationsisn-1.
236
Algorithm Example:Binary Search of Ordered List
• Ifthetermsinasequenceareordered,abinarysearchalgorithmismoreefficientthanlinearsearch.
• Thebinarysearchalgorithmiterativelyrestrictstherelevantsearchintervaluntilitclosesinonthepositionoftheelementtobelocated.
237
Algorithm Example:Binary Search of Ordered List (cont)
procedure binary_search(x:integer;a1,a2,…,an:integers)i :=1{i isleftendpointofsearchinterval}j:=n{jisrightendpointofsearchinterval}while(i <j)begin
m:=⌊(i +j)/2 ⌋if x>am then i :=m+1else j:=m
endif x=ai then location:=ielse location:=0
• Note:locationisthesubscriptofthetermthatequalsx,oriszeroifxisnotfound
• Exercise:Showthatintheworstcase,thenumberofiterationsi requiredsatisfies 1=n/2i ,i.e.,i =log2(n)
• Comparetheproblemaddressedbythisalgorithmtothatofgolden-sectionsearch(assumingunimodalfunction).
238
Complexity
• Wearetypicallynotsomuchinterestedinthetimeandspace(memorysize)complexityforverysmallinputssizes.
• Forexample,whilethedifferenceintimecomplexitybetweenlinearandbinarysearchismeaninglessforasequencewithn=10elements,itisgiganticforn=230.
239
Complexity - example
• Forexample,letusassumetwoalgorithmsAandBthatsolvethesameclassofproblemsof�size� n,wherenreflectstheamountofinputdata.
• ThetimecomplexityofAis5,000n,theoneforBisé1.1nùforaninputwithnelements.
• Forn=10,Arequires50,000steps,butBonly3,soBseemstobesuperiortoA.
• Forn=1000,however,Arequires5,000,000steps,whileBrequires2.5�1041 steps.
240
Complexity - example (cont)
• ThismeansthatalgorithmBcannotbeusedforlargeinputs,whilealgorithmAisstillfeasible.
• Sowhatisimportantisthegrowth ofthecomplexityfunctions.
• Thegrowthoftimeandspacecomplexitywithincreasinginputsizenisasuitablemeasureforthecomparisonofalgorithms.
241
Complexity - example (cont)
• Comparison:timecomplexityofalgorithmsAandB
AlgorithmA AlgorithmBInputSize
n
10
100
1,000
1,000,000
5,000n
50,000
500,000
5,000,000
5�109
é1.1nù
3
2.5�104113,781
4.8�1041392
242
The Growth of Functions• Thegrowthoffunctionsisusuallydescribedusingthebig-Onotation.
• Definition: Letfandgbefunctionsfromtheintegersortherealnumberstotherealnumbers.
• Wesaythatfisoforderatmost g(orjustoforderg),i.e.,f(x)isO(g(x))(orjustf=O(g))iftherearepositiveconstantsC,k <∞ suchthat
|f(x)|£ C|g(x)|wheneverx>k,
i.e.,theinequalityholdsforallsufficientlylargex.
243
The Growth of Functions
• Whenweanalyzethegrowthofcomplexityfunctions,f(x)andg(x)arealwayspositive.
• Therefore,wecansimplifythebig-Orequirementto
f(x)£ C×g(x)wheneverx>k,
i.e.,absolutevaluesarenotnecessary.
• Ifwewanttoshowthatf=O(g),weonlyneedtofindone pair(C,k),neverunique,thatmaketheinequalitywork.
244
The Growth of Functions• Theideabehindthebig-Onotationistoestablishanupperbound forthe
growthofafunctionf(x)forlargex.
• Thisboundisspecifiedbyafunctiong(x)thatisusuallymuchsimplerthanf(x).
• WeaccepttheconstantCintherequirement
f(x)£ C×g(x)wheneverx>k,
becauseCdoesnotgrowwithx.
• Weareonlyinterestedinlargex,soitisOKiff(x)>C×g(x)forx£ k.
245
The Growth of Functions –Polynomial Example
• Example:Showthatf(x)=x2 +5x+1isO(x2).
• Forx>1wehave:
x2 +5x+1£ x2 +5x2 +x2Þ x2 +5x+1£ 7x2
• Therefore,forC=7andk=1,
f(x)£ Cx2 wheneverx>k
Þ f(x)=O(x2).
246
Complexity Example• Whatdoesthefollowingalgorithmcompute?
procedure who_knows(a1,a2,…,an:integers)m:=0for i :=1ton-1
for j:=i +1tonif |ai – aj|>mthen m:=|ai – aj|
• Answer:(thereturnedvalueof)misthemaximumdifferencebetweenanytwonumbersintheinputsequence,maxi<j |ai - aj|
• Numberofcomparisonsmadeintheprocedurearen-1+n-2+n-3+…+1=(n– 1)n/2=0.5n2 – 0.5n=C(n,2)
• So,timecomplexityoftheprocedureisO(n2).
247
Complexity Example• Anotheralgorithmsolvingthesameproblem:
procedure max_diff(a1,a2,…,an:integers)min:=a1max:=a1for i :=2ton
if ai <minthen min:=aielse ifai >maxthen max:=ai
m:=max- min
• Thatis,maxi<j |ai - aj|=maxiai - miniai• Thenumberofcomparisonsinthisprocedureis2n- 2
• So,thetimecomplexityisO(n).
248
The Growth of Functions –common simple functions
• Common“simple”functionsg(n)are1,2n,n2,n!,n,n3,log(n),nlog(n),etc.
• Exercise:DoweneedtospecifythebaseoftheloginO(logn)?• Listedfromslowesttofastestgrowth:
1log(n) …binarysearchoforderedlistn …linearsearchofunorderedlistisO(n)nlog(n) …somesortingalgorithmsareO(nlogn)n2
n3
2n
n!nn
• Note:costofsortingn-listmaybeamortizedovermsearches:nlogn +mlogn =m((nlogn)/m+logn)<mn forsufficientlylargem
249
Simple Properties for Big-O• Foranypolynomial f(x)=anxn +an-1xn-1 +…+a0,wherea0,a1,…,an are
realnumbers,f(x)isO(xn),i.e.,∃C,k>0s.t. |f(x)|≤C∀x≥k
• Toseewhynotethatbythetriangleinequality|f(x)|≤∑k=0
n |akxk |=∑k=0n |ak|xk ≤(∑k=0
n |ak|)xn forx≥max{1,k}
• Similarly,onecanusethetriangleinequalitytoshowthenexttwostatements.
• Iff1 =O(g)andf2=O(g),thenf1 +f2=(g);forexample,seepolynomialfabove.
• Moregenerally,iff1 =O(g1)andf2 =O(g2),thenf1 +f2=O(max{g1,g2});orderoftandemalgorithmsismostcomplexone.
• Iff1=O(g1)andf2=O(g2),thenf1f2=O(g1g2);eachiterationofonealgorithmcallsanother.
250
The Growth of Functions –Imprecision of big-O
• IfCisverylargeinorderfortheupperboundtohold,thenthebig-Oboundmaybecrude.
• Also,ifkismuchlargerthanthejobsizesxseeninpractice,thenthebig-Oboundmaynotberelevant.
• Foralgorithmsofcomplexityfonlargeinputsx,wecanaskthefollowingtypeofquestion:
Iff(x)isO(x2),isitalsoO(x3)?• TheanswerisYes: x3 growsfasterthanx2,sox3 alsogrowsfasterthan
f(x).• Therefore,wealwayswanttofindthesmallest simple-functiongfor
whichf=O(g).
Ω and Θ notation• Wesayfisoforderatleast g,i.e.,f=Ω(g),if∃positivec,k<∞suchthat
|f(x)|≥c|g(x)|∀x>k.
• Wesayfisoforderexactly g(orjustoforderg),i.e.,
f=Θ(g)if∃positiveC,c,k<∞suchthat
C|g(x)|≥|f(x)|≥c|g(x)|∀x>k.
• Clearly,f= Θ(g)⇔f=O(g)andf=Ω(g).
• ThesimplepropertiesforBig-OmentionedabovehaveanalogsforΩ
andΘ.
• Notethatwhenauthorssayjust�oforderg� theyoftenmean=O(g).
251
252
The Growth of Functions –Rational Polynomial Example
Example:Showthatf(x)=(x5 +2x+1)/(5x2+6x)isΘ(x3).• Asabove,wehavex5 +2x+1=O(x5)withk=1andC=4,and
5x2+6x=O(x2)withk=5andC=11.• Butalso,x5 +2x+1≥ x5 forallx>1,sox5 +2x+1=Ω(x5)withk=1
(alsowithk=0)andC=1.• Similarly,5x2+6x=Ω(x2)withk=1andC=5.• Thus,byusingtheupperboundonthenumeratorandlowerboundon
thedenominator,wegetf(x)=O(x3)becausef(x)£ Cx3 wheneverx>kwithk=1andC=4/5.
• Orjustf(x)=O(x5)/Ω(x2)=O(x3).• Similarly,byusingthelowerboundonthenumeratorandthelower
boundonthedenominator,wegetf(x)=Ω(x3)becausef(x)≥Cx3 wheneverx>kwithk=1andC=1/11.
• Orjust,f(x)=Ω(x5)/O(x2)= Ω(x3).• Thus,f(x)=Θ(x3).• Notehowweestablishedthesimplerresultthatx5 +2x+1=Θ(x5).• Exercise:Provethisresultbyfirstusingpolynomiallongdivisiononf.• Exercise: Prove5x2-6x=Ω(x2).Hint:consider5x2(1-6/(5x))forlargex.
253
Problem tractability and solvability
• Aproblemthatcanbesolvedwithpolynomialworst-casecomplexityiscalledtractable.
• Problemsofhighercomplexityarecalledintractable.
• Therearesomewell-knownproblemsforwhichthequestionoftractabilityisnotknown,e.g.,thetravellingsalesmanproblem.
• Problemsthatnoalgorithmcansolvearecalledunsolvable.
• Moreonthissubjectinlatercourses…
254
Introduction to DiscreteMathematics
RelationsThis revision G. Kesidis (2013)
This document revision is copy-left 2013. It is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Note: these slides adapted in part from those of S.J. Lomonaco Jr., available at
http://www.csee.umbc.edu/~lomonaco/f05/203/Slides203.html
255
Relations• IfwewanttodescribearelationshipbetweenelementsoftwosetsAandB,
wecanuseorderedpairs withtheirfirstelementtakenfromAandtheirsecondelementtakenfromB.
• Sincethisisarelationbetweentwosets,itiscalledabinaryrelation.• Definition: LetAandBbesets.AbinaryrelationfromAtoBisasubsetof
A´B.• Inotherwords,forabinaryrelationRwehave
RÍ A´B={(a,b)|aÎA,bÎB}.• WemayalsousethenotationaRb todenotethat(a,b)ÎR.
256
Relations• When(a,b)belongstoR,aissaidtoberelated tobbyR.• Example: LetPbeasetofpeople,Cbeasetofvehicles,andDbethe
relationdescribingwhichpersondriveswhichvehicle(s).• P={Carl,Suzanne,Peter,Carla},• C={Mercedes,BMW,tricycle},• D={(Carl,Mercedes),(Suzanne,Mercedes),(Suzanne,BMW),
(Peter,tricycle)}• ThismeansthatCarldrivesaMercedes,SuzannedrivesaMercedesanda
BMW,Peterdrivesatricycle,andCarladoesnotdriveanyofthesevehicles.• Thatis,CarlDMercedes.• NotehowCarladoesnotdriveanythingandhowSuzannedrivesmore
thanonevehicle- foreitherofthesereasons,Risnotafunction.
257
Functions as Relations• Youmightrememberthatafunction ffromasetAtoasetB(f:A→B)
assignsasingleelementbÎ BtoeachelementaÎ A,i.e.,fisafunctionfromdomainAtoco-domainBif
∀a Î A, ∃uniquebÎ Bs.t. b=f(a).• Recallthatwedonot meanthatthereisasingleelementofBtowhichf
mapsallelementsofA,i.e.,noticethedifferencebetweentheabovedefinitionofafunctionand
∃uniquebÎ Bs.t. ∀a Î A,b=f(a).• So,wecandefinetherelationcorrespondingtofunctionfas
{(a,f(a))|aÎA}.• Conversely,ifRisarelationfromAtoBsuchthateveryelementinAisthe
firstelementofexactlyoneorderedpairofR,thenafunctioncanbedefinedusingR.
• ThisisdonebyassigningtoeachelementaÎA theuniqueelementbÎBsuchthat(a,b)ÎR.
258
Relations on a (single) set
• Definition: ArelationonthesetAisarelationfromAtoA.
• Inotherwords,arelationonthesetAisasubsetofA´A=A2.
• Example: LetA={1,2,3,4}.WhichorderedpairsareintherelationR={(a,b)|a<b}?
• Solution: R={(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)}
259
Relations – Bipartite Graph Depiction(both domain and co-domain depicted)
• Example:R={(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)}
1 1
2
3
4
2
3
4
260
Relations on a single set –directed graph (digraph) depiction
• Example: R={(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)}
1
2
3
4
261
Relations – adjacency matrix• ExampleSolution: R={(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)}• Note:rowisdomainelementandcolumnsareco-domainelements
R 1 2 3 4
1
2
3
4
X X X
X X
Xúúúú
û
ù
êêêê
ë
é
=
0000100011001110
R
262
Number of Relations on a SetHowmanydifferentrelationscanwedefineonasetAwithnelements?
• ArelationonasetAisasubsetofA´A.• HowmanyelementsareinA´A?
• Therearen2 elementsinA´A,sohowmanysubsets(=relationsonA)doesA´Ahave?
• Thenumberofsubsetsthatwecanformoutofasetwithmelementsis2m.
• Therefore,2n2 =2n∙n subsetscanbeformedoutofA´A.
263
Properties of Relations on a Set - Reflexivity• Wewillnowlookatsomeusefulwaystoclassifyrelations.
• Definition: ArelationRonasetAiscalledreflexive if(a,a)ÎRforeveryelementaÎA,i.e.:∀aÎA,aRa.
• Arethefollowingrelationson{1,2,3,4}reflexive?
• R={(1,1),(1,2),(2,3),(3,3),(4,4)}…No,missing(2,2)
• R={(1,1),(2,2),(2,3),(3,3),(4,4)}…Yes.
• R={(1,1),(2,2),(3,3)}…No,missing(4,4)
• Definition: ArelationonasetAiscalledirreflexive if(a,a)ÏRforeveryelementaÎA,i.e.:∀aÎA,(a,a)∉R.
• Notethatareflexiverelationwillhaveanadjacencymatrixwithdiagonal
all1s(diag(R)=1),whileanirreflexiverelation�sadjacencymatrixwillhavediagonalall0s(diag(R)=0).
• Also,allelementswillhaveselfloopsinthedirected-graphdepictionofa
reflexiverelation,whileanirreflexiverelationwillhavenoself-loops.
• Noneofthethreeexamplesaboveareirreflexive.
• Previous�<� relationwasirreflexive,while�≤� isreflexive.
264
Properties of Relations on a Set - Symmetry
• ArelationRonasetAiscalledsymmetric if:(b,a)ÎRwhenever(a,b)ÎR; equivalently,∀a,bÎA,if(a,b)ÎRthen(b,a)ÎR.
• NotethatifRissymmetric,itsadjacencymatrixR=RT (itstranspose).• ArelationRonasetAiscalledantisymmetric if:
∀a,bÎA,if(a,b)ÎRand(b,a)ÎRthena=b≡ ∀a,bÎA,ifa≠b then(a,b)∉Ror(b,a) ∉R
• ArelationRonasetAiscalledasymmetric if:∀a,bÎA,if(a,b)ÎRthen(b,a)ÏR.
• Notethatif(a,a)ÎRforsomeaÎA,thenRmaybeantisymmetricbutnotasymmetric.
• Exercise:ArguethatRisasymmetricifandonlyifitisirreflexiveandantisymmetric.
265
Properties of Relations –Symmetry Examples
• Arethefollowingrelationson{1,2,3,4}symmetric,antisymmetric,asymmetric,reflexive,orirreflexive?
• R={(1,1),(1,2),(2,1),(3,3),(4,4)}issymmetric• R={(1,1)}issymmetricandantisymmetric• R={(1,3),(3,2),(2,1)}isantisymmetric,irreflexiveandasymmetric• R={(4,4),(3,3),(1,4)}isantisymmetric
266
Counting Relations with Properties
• HowmanydifferentreflexiverelationscanbedefinedonasetAcontainingnelements?• Areflexiverelationmust containthenelements(a,a)foreveryaÎA.• Consequently,wecanonlychooseamongtheremaining
n2 – n=n(n– 1)elementstogeneratedifferentreflexiverelations.• So,thereare2n(n– 1) ofthem.
• HowmanydifferentsymmetricrelationscanbedefinedonasetAcontainingnelements?• Asymmetricrelationmay containthen=C(n,1)elements(a,a)for
everyaÎA.• Asymmetricrelationmay containC(n,2)=n(n-1)/2elementpairs
(a,b)and(b,a)fora≠b.• So,thereare2n2n(n– 1)/2 =2n(n+1)/2 ofthem,includingthenullrelation.
• Exercise:ShowthatthenumberofantisymmetricrelationsonasetAcontainingnelementsis2n 3n(n– 1)/2 ,andfindthenumberofasymmetricrelations.Hint:∑k=1
N C(N,k)2k =3N whereN=C(n,2)=n(n-1)/2
267
Properties of Relations - Transitivity
• ArelationRonasetAiscalledtransitive if∀ a,b,cÎA,if (a,b)ÎRand(b,c)ÎR,then(a,c)ÎR.
• Thedirected-graphdepictionoftransitiverelationshavethepropertythatalltwo-hoppathsconnectingelementsalsohavesingle-hoppathsconnecting(relating)thoseelements.
• Forexample,�<� and�≤� arebothtransitive.
• Arethefollowingrelationson{1,2,3,4}transitive?
• R={(1,1),(1,2),(2,2),(2,1),(3,3)} …Yes• R={(1,3),(3,2),(2,1)} …No• R={(2,4),(4,3),(2,3),(4,1)} …No
268
Combining Relations
• Relationsaresets,andtherefore,wecanapplytheusualsetoperations tothem.
• IfwehavetworelationsR1 andR2,andbothofthemarefromasetAtoasetB,thenwecancombinethemtoR1 ⋂ R2,R1 ⋃ R2,orR1 – R2.
• Ineachcase,theresultwillbeanotherrelationfromAtoB.
Closure of Relations to Achieve Properties• SupposearelationRonasetAdoesnot possessapropertyP.• TherelationSonAiscalledtheP-closureofRif
– R⊆S,– ShaspropertyP,and– S-R(therelationsaddedtoRtoobtainS)isminimal insize.
269
Transitive Closure - Example• Forexample,recallthatR={(1,3),(3,2),(2,1)}onA={1,2,3,4}was
nottransitive.• LetS=R.• Fortransitiveclosure,weneed(1,2)because(1,3),(3,2)∈S,soset
S=S⋃{(1,2)}.• Similarly,weneed(3,1)because(3,2),(2,1)∈S,soset
S=S⋃{(3,1)}.• Butadding(1,2)meanswealsoneedtoadd(1,1)and(2,2)since
(2,1)∈S,sosetS= S⋃{(1,1),(2,2)}.• Now,(2,1)and(1,3)∈S,soweneedtoadd(2,3)toSand,because
(3,2)∈S,wealsoneedtoadd(3,3).• VerifythatS={(a,b)|a,b ∈{1,2,3}},i.e.,the�completelyconnected�
relationon{1,2,3} ⊆A,isthetransitiveclosureofRonA.
270
271
Combining Relations by Composition• Definition: LetRbearelationfromasetAtoasetBandSarelationfromB
toasetC.Thecomposite ofRandSistherelationconsistingoforderedpairs(a,c),whereaÎA,cÎC,andforwhichthereexistsanelementbÎBsuchthat(a,b)ÎRand(b,c)ÎS:
• WedenotethiscompositeofRandSbyS°R.
• Again,If(a,c)Î S°Rthen∃bÎB s.t. (a,b)Î Rand(b,c)Î S
• Also:If(a,b)Î Rand(b,c)Î S,then(a,c)Î S°R
272
Combining Relations - Example• Example: LetDandSberelationsonA={1,2,3,4}.• D={(a,b)|b=5- a}�bequals(5– a)�• S={(a,b)|a<b}�aissmallerthanb�• Equivalently,
D={(1,4),(2,3),(3,2),(4,1)}S={(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)}
• S °D={(2,4),(3,3),(3,4),(4,2),(4,3),(4,4)}• Dmapsanelementatotheelement(5– a),andafterwardsSmaps(5– a)to
allelementslargerthan(5– a),resultinginS °D={(a,b)|b>5– a},equivalentlyS°D={(a,b)|a+b>5}.
• Exercise:FindD ° SandcomparewithS °D.
273
Combining a Relation with Itself
• Definition: LetRbearelationonthesetA.ThepowersRn,n=1,2,3,…,aredefinedinductivelybyR1 =R,andRn+1 =Rn°Rforn≥1.
• Inotherwords:Rn =R°R° …°R(nrelationsRcomposed)
274
Self-Combining Transitive RelationsTheorem: TherelationRonasetAistransitiveifandonlyifRn Í Rforallpositiveintegersn.Proof:• RecallthatArelationRonasetAiscalledtransitiveifwhenever(a,b)ÎR
and(b,c)ÎR,then(a,c)ÎRforalla,b,cÎA.• Sobydefinition,transitivityofR⇔ R°RÍ R.• WhatremainstoproveisthatifRistransitive,thenRn Í Rforallintegers
n>2.• Thiscanbeeasilyshownbyinduction,i.e.,compositionofRn-1 by
(transitive)RdoesnotaddrelationsnotalreadyÎR.• Q.E.D.
Partial-order relations (PORs)
• ArelationRonAisapartial-orderrelation(POR)ifitisreflexive,
antisymmetric,andtransitive.
• Forexample,ifAisasetofsetsandRisthesubsetrelation⊆,thenRis
aPORbecause⊆isclearlyreflexiveandtransitive,andforanytwo
different subsetsa,b ∈A,ifa⊆bthenb⊄a (i.e.,⊆isantisymmetric).
• Exercise:Checkthatthedivides“|”relationonℤ isaPOR.
• Notethattherelations>and<onℝ arenotPORsbecausetheyarenot
reflexive.
• Orderrelationsaresometimescalledstrongorweakdependingon
whethertheyarereflexive-and-antisymmetric(as≥and≤)or
asymmetric(as<and>)– wewillnotconsidersuchqualifications
here.
275
Total-order relations (TORs)
• ArelationRonAistotal if
∀a,b∈A,ifa≠b then(a,b)∈Ror(b,a)∈Rbutnotboth.
• Thatis,RonAistotalifeverypairofelementsinAiscomparable/relatable.
• ArelationRonAisatotal-orderrelation(TOR)ifitisatotalPOR.
• Forexample,ifAisasetofrealnumbersthenanyR∈{≤,≥}isaTOR.
• WithatotalorderrelationR,allelementsofacountablesetAcanbeenumeratedas{an}=Asothat(an,an+1)∈Rforalln.
• Notethat⊆maynotbetotal,andhencenotaTOR,becauseit’spossibletohavetwodifferentsetsa,b∈A suchthatb⊄a anda⊄b,e.g.,
a={1,2,3}andb={2,3,4}.
276
Chains and extrema in PORs
• AchainofaPORRonAisasubsetB⊆AsuchthatPisaTORonB.
• Forexample,forthedivides�|� relationonA={3k4i :k,i ∈{0,1,2,3,4}},thesets{3,9,27}and{1,4,12,36}arechains.
• IfweinterpretaRb asbis�greaterthanorequalto� foraPORR,thenwehavethefollowingnotions:
• Amaximalelementisthelargestelementofachain,ifitexists.• Agreatestelementistheuniquemaximalelement,ifitexists.
• Aminimalelementisthesmallestelementofachain,ifitexists.
• Aleastelementistheuniquemaximalelement,ifitexists.
• Fortheaboveexample,theleastelementis1andthegreatest3444.
• Butforthesamedividesrelationon{3,4,12,16,18,24,32},theminimalelementsare3,4,themaximalonesare18,24,32,andthereisneitheragreatestnorleastelement.
277
HasseDiagramsforPORs– Example:divideson{3,4,12,16,18,24,32}
278
43
1612
322418
279
Equivalence Relations - Definition
• Equivalencerelations areusedtorelateobjectsthataresimilarinsomeway.
• Definition: ArelationonasetAiscalledanequivalencerelationifitisreflexive,symmetric,andtransitive.
• TwoelementsthatarerelatedbyanequivalencerelationRarecalledequivalent.
280
Equivalence Relations –Definition (cont)
• SinceRissymmetric,aisequivalenttobwheneverbisequivalenttoa.
• SinceRisreflexive,everyelementisequivalenttoitself.
• SinceRistransitive,ifaandbareequivalentandbandcareequivalent,thenaandcareequivalent.
• Obviously,thesethreepropertiesarenecessaryforareasonabledefinitionofequivalence.
281
Equivalence Relations - Example Example:SupposethatRistherelationonthesetofstringsthatconsistofEnglishletterssuchthataRb ifandonlyifl(a)=l(b),wherel(x)isthelengthofthestringx.IsRanequivalencerelation?Solution:• Risreflexive,becausel(a)=l(a)andthereforeaRa foranystringa.• Rissymmetric,becauseifl(a)=l(b)thenl(b)=l(a),soifaRb thenbRa.• Ristransitive,becauseifl(a)=l(b)andl(b)=l(c),thenl(a)=l(c),soaRb
andbRc impliesaRc.• Risanequivalencerelation.
282
Equivalence Classes • Definition:LetRbeanequivalencerelationonasetA.Thesetofall
elementsthatarerelatedtoanelementa∈ Aiscalledtheequivalenceclassofa.
• TheequivalenceclassofawithrespecttoRisdenotedby[a]R.• Whenonlyonerelationisunderconsideration,wewilldeletethesubscript
Randwrite[a] forthisequivalenceclass.• IfbÎ[a]R,biscalledarepresentative ofthisequivalenceclassandwecan
write[a]R =[b]R .
283
Equivalence Classes - Example
• Example:Inthepreviousexample(stringsofidenticallength),whatistheequivalenceclassofthewordmouse,denotedby[mouse]?
• Solution: [mouse]isthesetofallwordscontainingfiveEnglishletters.
• Forexample,“horse” wouldbearepresentativeofthisequivalenceclass.
284
Equivalence Classes and Set Partitions • Theorem:IfRisanequivalencerelationonasetA,thenthefollowing
statementsareequivalent:• aRb• [a]=[b]• [a]Ç [b]¹ Æ
• Definition: ApartitionofasetAisacollectionofdisjointnonemptysubsetsofAthathaveAastheirunion(i.e.,that“cover”A).
• Inotherwords,thecollectionofsubsetsSi,iÎI,formsapartitionofAifandonlyif– Si ¹ Æ foriÎI– SiÇ Sj =Æ ifi ¹ j– ÈiÎI Si =A
285
Equivalence Classes - Examples Examples:LetAbetheset{u,m,b,r,o,c,k,s}.DothefollowingcollectionsofsetspartitionA?• {{m, o, c, k}, {r, u, b, s}} yes.• {{c, o, m, b}, {u, s}, {r}} no (k is missing).• {{c, o, m, t}, {b,u, s}, {r}} no (t ∉ A).• {{u, m, b, r, o, c, k, s}} yes (A is the trivial 1-partition of itself).• {{b, o, o, k}, {r, u, m}, {c, s}} yes ({b,o,o,k} = {b,o,k}).• {{u, m, b}, {r, o, c, k, s}, Æ} no (Æ is not allowed as a partition element).
286
Equivalence Classes and Set Partitions (cont)
Theorem:• IfRisanequivalencerelationonasetA,thentheequivalenceclasses ofR
formapartition ofA.• Conversely,givenapartition{Si |iÎI}ofthesetA,thereisanequivalence
relationRthathasthesetsSi,iÎI,asitsequivalenceclasses.
Proof:• Theproofofthefirststatementfollowsdirectlybydefinition(theprevious
Theorem).• GivenapartitionofA,onecanconstructthecorrespondingequivalence
relationbysimply�relating� (ineveryway)elementsofAthatarepartofthesamepartitionelement,andbynotrelating(inanyway)elementsofAfromdifferentpartitions.
287
Equivalence Classes - Example • Example:LetusassumethatFrank,SuzanneandGeorgeliveinBoston,
StephanieandMaxliveinLübeck,andJenniferlivesinSydney.• LetRbetheequivalencerelation {(a,b)|aandbliveinthesamecity}on
thesetP={Frank,Suzanne,George,Stephanie,Max,Jennifer}.• ThenR={(Frank,Frank),(Frank,Suzanne),
(Frank,George),(Suzanne,Frank),(Suzanne,Suzanne),(Suzanne,George),(George,Frank),(George,Suzanne),(George,George),(Stephanie,Stephanie),(Stephanie,Max),(Max,Stephanie),(Max,Max),(Jennifer,Jennifer)}.
• Exercise:CanoneconstructanequivalencerelationonPifSuzannealsolivedinSydney?
288
Equivalence Classes – Example (cont) • Thentheequivalenceclasses ofRare:
{{Frank,Suzanne,George},{Stephanie,Max},{Jennifer}}.• ThisisapartitionofP.• TheequivalenceclassesofanyequivalencerelationRdefinedonasetS
constituteapartitionofS,becauseeveryelementinSisassignedtoexactlyone oftheequivalenceclasses.
• IftheelementsofasetParelistedbyequivalenceclass,thentheadjacencymatrixoftheequivalencerelationisblockdiagonal.
• ForthepreviousexamplewithP={F,Su,G,St,M,J},
úúúúúúúú
û
ù
êêêêêêêê
ë
é
=
100000011000011000000111000111000111
R
289
Equivalence Classes – Modulo Relation • Anotherexample:LetRbetherelation
{(a,b)|aº b(mod3)}onthesetofintegers.• IsRanequivalencerelation?• Yes,Risreflexive,symmetric,andtransitive.
• WhataretheequivalenceclassesofR?• [0]={{…,-6,-3,0,3,6,…},
[1]={…,-5,-2,1,4,7,…},[2]={…,-4,-1,2,5,8,…}}
Introduction to Discrete Mathematics
Introduction to Modular Arithmetic and Public Key Cryptography
This revision G. Kesidis (2013)This document revision is copy-left 2013. It is licensed under a Creative Commons
Attribution-Noncommercial-Share Alike 3.0 United States LicenseThisslidedeckwasrevisedfromthoseavailableat
http://www.cs.kent.edu/~rothstei/modular_arith.ppthttp://homepages.gold.ac.uk/rachel/CIS326week5lession1.ppt
Definition of modulo operator• Theremainderafterdividingintegerkbyn≠0 denoted
kmodn or k%n• Thatisr=kmodnmeansn|(k-r)or∃q∊ℤ s.t. k=nq+r.• Thisremainderistypicallyrestrictedtorange
{0,1,2,…,n-1}• So,thesetofintegersℤ isdividedintonequivalenceclassesbythemodn
operator,i.e.,twointegerskandmareinthesameequivalenceclassiftheyarecongruentmodn,i.e.,ifk≡mmodn,equivalently:kmodn≡mmodn,0≡(k-m)modn,k-m≡0modn.
• Congruence(equivalence)modn(i.e.,equalremaindersafterdivisionbyn)isoftensignifiedby≡,thoughwewillusejust=inthefollowing.
• Forexample,5=40mod7=-9mod7,so5,40and-9areinthesameequivalenceclass(congruent)mod7– thisequivalenceclassisdenoted“5”because0≤5<7,i.e.,here“5”=[5]={…,-9,-2,5,12,17,…}
291
What is modular arithmetic?
• Modulararithmeticisarithmeticwiththeremaindersupondivisionbyafixednumbern.
• Itisbasedupontheideathattheremainderofthesum/difference/productoftwonumbersistheremainderofthesum/difference/productoftheremainders.
• Foranexampleofhowmoddistributesover+:ifn=5,– (34+7)%5=41%5=1,and– (34%5+7%5)%5=(4+2)%5=1too
292
Properties of Modular Arithmetic
Theorem:∀n≠0,a,b∈ℤ,1. [(amod n)+(bmod n)]mod n=(a+b)mod n2. [(amod n)- (bmod n)]mod n=(a- b)mod n3. [(amod n)� (bmod n)]mod n=(a� b)mod n
Proof of3.: Forarbitraryn≠0,a,b∈ℤ,• Let Ra=amod nand Rb =bmod n.• So ∃j,k∈ℤ s.t. a=Ra +jn and b=Rb +kn.• Thus,the right-hand side ofstatement 3.is
(ab)mod n =(Ra Rb +n(jRb +kRa +nkj)) mod n=Ra Rb mod n=[(amod n)(bmod n)]mod n
• Q.E.D.
293
So, what is arithmetic mod n?
• Our“numbers” areequivalenceclasses0,1,2,...,n-1.• Weadd,subtractasusual,butsubtractoraddnasnecessarytogetananswerbetween0andn-1.
• Formultiplication,theprocessissimilar;multiplythetwonumberstogether,andthentaketheremainderafterdividingbyn.
294
Some examples mod n for n= 6
• (28+3)%6=31%6=1=7%6=4%6+3%6=28%6+3%6• (13– 15)%6=-2%6=4=13%6-15%6• (8�7)%6=56%6=2=2�1=8%6�7%6• Toefficientlycompute1119 %6:
§ 11=5%6§ Thus,112 =52 %6=1%6§ Thus,1119 =11� (112)9 =5� 19 %6=5%6
§ Moregenerally,sincemoddistributesoverproduct:ifak =1%mthenan =an%k %m
• Notethat1=19%2intheaboveexample.• Wewillreturnefficientmodularexponentiationlater.
295
Division mod n for n=6
• Todivide%6,allnumbersneedamultiplicativeinverse%6.• Buttheprimefactorsof6donotpossessmultiplicativeinverses%6.• Suppose otherwise,i.e.,that2and3dohavemultiplicativeinverses%6.• Notethat1isthemultiplicativeidentityalsoformodarithmetic,sothatz
isthemultiplicativeinverseofxmod6ifxz=1mod6.• So,wearesupposingthat
– thereisazsuchthatz� 2=1%6,and– thereisysuchthaty� 3=1%6.
• Thus,z� 2� y� 3=1�1 %6=1%6.• However,z� 2� y� 3=6zy=0%6.• Thisisacontradiction,soourassumptionthattheprimefactorsof6have
amultiplicativeinversemod6isfalse.
296
We will see that we can divide mod p if p is a prime.
• Fromnowon,ourmodulus(divisor)willbeaprimep.• Wewillshowhowtodivideinarithmeticmodpbyusingtheextended Euclideanalgorithm.
• RecallthattheEuclideanalgorithmfindsthegreatestcommondivisor(gcd)oftwointegersaandb.
297
Recall basic Euclidean Algorithm to find gcd
1. Initialdata:integersn0 ,n1 s.t.0≠|n0|≥|n1|2. seta⃪|n0|3. setb⃪|n1|(≤a)4. whileb>0do
r⃪amodb,with0≤r<ba⃪bb⃪r
5. returna=gcd(n0,n1)• Again,asthewhileloopexecutes,b≥0strictlydecreasesandgcd(a,b)does
notchange- recallthewell-orderingprinciplere.convergenceoftheEuclideanalgorithminfinitetime.
• TheworkingofEuclid’sAlgorithmismadeclearerbyconsideringtheextended Euclideanalgorithmthatwillgiveintegerssandtsuchthat
sn0 +tn1 =gcd(n0,n1)
298
Extended Euclidean Algorithm1. Initialdata:integersn0 ,n1 s.t. n0 ≥n1>0
2. indexk=1
3. Ifn1 |n0 then{Returnn1 =gcd(n0,n1)=n0 -(-1+n0/n1)n1 }else:
4. whilenk >0do
nk+1 =nk-1 modnk with0≤nk+1 <nk
ifnk+1 >0then
nk+1 =nk-1- qk nk withquotientqk >0
=skn0 +tkn1 byrecursivesubstitution(seebelow)
k++
5. Returnnk-1 =gcd(n0,n1)and
6. Returnintegers(sk-2 ,tk-2)s.t. sk-2n0 +tk-2n1 =gcd(n0,n1)
• Notethats1=1andt1=-q1
• Exercise:writethepseudo-codefortherecursivesubstitution(seethe
followingexamples).
299
Extended Euclidean Algorithm – Example 1
• Ifn0 =21andn1 =15thentheEEAwillreturns=-2andt=3,sothat
sn0 +tn1 =3∙15- 2∙21=3=gcd(n0 ,n1)• ThestepsfortheEEAofthisexampleare:
1. 6 =21mod15 ⇒6 =-1∙15+1∙212. 3=15 mod6 ⇒3=-2∙6 +1∙15=3∙15– 2∙21(sub6fromstep1)3. 0=6mod34. Stop
5. Returngcd(21,15)=3=3∙15– 2∙21
300
Extended Euclidean Algorithm – Example 2
• Whenn0 =256andn1 =100,thestepsfortheEEAare:
1. 56 =256mod100 ⇒56 =-2∙100+1∙2562. 44=100 mod56 ⇒44 =1∙100- 1∙56 =3∙100– 1∙256(sub56ofstep1)3. 12=56mod44 ⇒12 =1∙56– 1∙44=-5∙100+2∙256(sub56,44ofsteps1,2)4. 8=44mod12 ⇒8=1∙44 – 3∙12 =18∙100– 7∙256(sub44,12ofsteps2,3)5. 4=12mod8 ⇒4=1∙12– 1∙8=-23∙100+9∙256(sub12,8ofsteps3,4)6. 0=8mod47. Stop8. Returngcd(256,100)=4=-23∙100+9∙256
301
Division mod p for prime p –multiplicative inverse mod p
• ByproofofconvergenceoftheExtendedEuclideanAlgorithminafinitenumberofiterations:ifaandbhavenocommonfactors>1(i.e.,theyare“relativelyprime”),thenthereexistintegerss,tsuchthat
as+bt =1.• Again,givena,b,theintegerss,t arefoundbytheEEA.• So,forallintegersbwithoutprimefactorp,wecanfindintegerss,t such
thatps +bt =1,
wheretiscalledthemultiplicativeinverse ofb(modulop).• Thatis,1=(bt)%p=(b%p)(t%p)%p.• Themultiplicativeinversetcanbereducedtoauniqueelementof
{1,2,…,p-1} bysuitablyselectings.• Restrictingourattentiontotherange{1,2,...,p-1},wehaveproved:
• Theorem:Forallprimepandb∈{1,2,…,p-1},thereisauniquemultiplicativeinverset∈{1,2,…,p-1} ofbsuchthat
1=(bt)%p
302
Division mod p for prime p
Theorem:Forallprimepandintegersa andywithoutfactorpbutwithfactorx,ifa%p=ythen(a/x)%p=(y/x).
Proof:• Notethatxalsodoesnothavefactorpbytransitivityofdivisibility.• Lets ∈{1,2,…,p-1}bethemodpmultiplicative-inverseofx,i.e.,
1=sx%p=(s%p)(x%p)%p• So,(as)%p=(a/x)%pand(ys)%p=(y/x)%p.• Ifamodp=ythenbymultiplicativepropertyofmoduloarithmetic:
(as)%p=ys.• Q.E.D.
303
Modular division - example
• Whatis5� 3mod11?• Note11isprime.• Weneedtomultiply5bytheinverse of3mod11• Bysimplearithmetic,ifyoumultiplyanumberbyits(multiplicative)inverse
thentheansweris1(themultiplicativeidentity),e.g.,themultiplicativeinverseof2is½since2�½=1
• So,theinverseof3mod11is4since3�4=12=1mod11• Thus5� 3mod11=5� 4mod11=9
304
Fermat’s Little Theorem
Theorem:Ifadoesnothaveprimefactorp,thenap-1 modp=1.Proof:• Thenumbersa,2a,3a,…,(p-1)ahavedifferentremaindersmodp(easilyproven
bycontradiction).• So,{1,2,…,p-1}and{a,2a,…,(p-1)a}arethesamesetofnumbersmodp.• So,theproductsarethesamemodp,i.e.,
(p-1)!=a∙2a∙3a…∙(p-1)amodp=ap-1 (p-1)!modp
• Finally,sincepisprime,wecandividethisequationby(p-1)!.• Q.E.D.
305
Chinese Remainder Theorem
• Iftheintegersm1,m2,m3,....mk anda1,a2,a3,....ak aresuchthat
• themi arepositive,pairwiserelativelyprime,and• theai <miarealsopositiveintegers,
• thenthereexistsanintegerr suchthat∀i,mi|r-ai ,i.e.,∀i ,ai =r%mi
• Ifwerequirethatr<∏imi,thenthisrisunique.
306
Proof of Chinese Remainder Theorem
• Sufficestotakek=2becausethegeneralk≥2istheneasilyproved byinduction.
• Thus,weneedtoprovethat,for0<a1 <m1 and0<a2 <m2 ifm1 andm2arerelativelyprime,thereexistsauniquerbetween0andm1m2 suchthat
r%m1 =a1 andr%m2 =a2• Sincem1 andm2 arerelativelyprime,thereexistintegerssandtsuchthat
sm1 +tm2 =1(*).• r:=a2sm1 +a1tm2 %m1m2 satisfiesalloftheconditions.• Inparticular,notethatbydefinitionofrthereisanintegerqsuchthat
a2sm1 +a1tm2 =qm1m2 +r;• so,
r%m1 =a1tm2%m1 =a1(1-sm1)%m1 =a1 ,whereweused(*)forthesecondequality.
• Q.E.D.
Exercise:CheckthatthedefinedrsatisfiestheotherrequiredpropertiesoftheCRT,andprovethemoregeneralresultfork>2.
307
The RSA TheoremTheorem:Ifpandqaretwodifferentprimesandtheintegeraisrelatively
primetopandqsuchthat1≤a≤pq -1,thenforallpositiveintegersk,
a1+k(p-1)(q-1) =amod(pq)
Proof:
• ByFermat’sLittleTheorem,ap-1 =1modp.
• Thus,ak(p-1)(q-1) =(ap-1)k(q-1) =1modp(sincemoddistributesover
product).
• Thus,a1+k(p-1)(q-1) =amodp(ditto).
• Similarly,a1+k(p-1)(q-1) =amodq.
• Thatis,q|a1+k(p-1)(q-1) - aandp|a1+k(p-1)(q-1) – a.
• So,(pq)|a1+k(p-1)(q-1) – a.
• Q.E.D.
308
How RSA works to send confidential messages• AnindividualAwishestobeablesecurelycommunicatewithothers(even
potentiallyuntrustworthystrangers)overaninsecurecommunicationmedium.
• Taketwolargeprimes,pandq.• Letn=pq.• Choseanintegere,relativelyprimeto(p-1)(q-1).• UsingtheextendedEuclideanalgorithm,findadsuchthat
de– k(p-1)(q-1)=1.• Thatis,de=1+k(p-1)(q-1).• “Publish” (n,e)asapublickey,i.e.,securelydisseminatethepublickey
throughatrustworthyKeyDistributionCenter (KDC),acriticalcomponentofthepublickeyinfrastructure(PKI).
• Thatis,individualsarereliably“bound”totheirpublickeysbytheKDC.• Retain(n,d)asaprivatekey.• Now,anotherindividualBmayencryptaplain-textbinarymessage�m� to
Abyraisingm totheeth power,andtransmittingthecypher-textme mod(pq).
• Uponreceipt,Awilldecryptthecypher-textbyraisingittothedth powerandtherebyrecoverm=(me mod(pq))d =med mod(pq).Ex.:Prove.
309
How RSA works to sign messages• SupposeBwishestoreceiveamessagemfromAthatissignedby
AinawaythatcannotbelaterrepudiatedbyAoreasilyforgedbyanotherparty.
• Using its privatekey(d,n=pq),AsignsthemessagebysendingtoBmdmodn
together with the messagem(oritscypher)• Having received this signaturefromA,Bcan“check”itby
decryptingitusingA’spublic keyandcomparingtheresulttotheplaintextmessagem,i.e.,
(mdmodn)emodn=m• BcannotforgeA’ssignaturewithoutfactoringn=pq andAcannot
laterrepudiateitssignatureforthesamereason.
310
Strength of RSA
• ThestrengthofRSApublic-keycryptographyliesinthedifficultyinfactoringntofindpandq.
• Thatis,athirdpartyinterceptingthecypher-textae willalsohavethepublickeyofA,particularlyn,butwillneedtofactorntofindpandqandhenced.
• So,typically,pandqareverylargeprimessothatfactoringnisdifficult,thoughrecentlyprovedtobeofpolynomialcomplexityinthesizeofn.
• Asofthiswriting,thelargestprimenumberyetfoundisoftheform2k-1(aMersenneprime)withk=57,885,161.
• Fewerthan50Mersenneprimesareknown.
• Exercise:Showthatthisprimenumberwillbe17,425,170decimaldigitslong.
311
“Efficient” exponentiationtocomputean
• power(a,n)• setr:=1• ifn=0,returnr• whilen>1do
– Ifnisodd,setr:=ar andn:=n-1– n:=n/2anda:=a2
• returnar
Exercise:Provethecorrectnessofthisalgorithm,i.e.,thatitreturnsan,by(strong?)induction.Intheprocess,observethestrategyusedforexponentiation.
Notethattheearlierexampleofefficientcomputationofakmodnrequireddiscoveringanon-negativeintegeri≪k suchthat1=aimodn;thus,
akmodn=akmodimodn.
312
Another Crypto-system: Diffie-Hellman key exchange
• Letpbealargeprime,sanumberbetween2andp-2;pandsare“publiclyknown”.
• Supposetwopeoplewishtosecurelycommunicateandeachpersonhasaprivatekey,respectivelyaandb.
• Theyfirstsendeachothernumbers,respectivelyx=sa modpandy=sb modp,
i.e.,employingtheirownprivatekeys.• Theyraisethenumbertheyreceivetotheirprivatekeypowermodp,andtherebyhaveacommonexchangekeykforasymmetriccrypto-system,i.e.,
k = ya modp=xb modp.
313
Another Crypto System: El-Gamal
• Asbefore,letpbealarge(publiclyknown)primenumber,ssomenumberbetween2andp-2.
• Eachpersonchoosesaprivatekeyeand“publishes”E=se modp.
• Tosendmessagem,wefirstgeneratea“sessionkey” k,andsendt=sk modpandc =(Ek m)modp
• Wedecryptbycomputingt-e c=mmodp
314
Secure communication protocols
• See Kurose & Ross, Chapter 8, available athttp://www.pearsonhighered.com/educator/product/PowerPoint-Slides-for-
Computer-Networking-6E/9780132856225.page
315