ebook img

Mathematics of discrete structures for computer science PDF

300 Pages·2012·2.055 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Mathematics of discrete structures for computer science

Gordon J. Pace Mathematics of Discrete Structures for Computer Science GordonJ.Pace DepartmentofComputerScience, FacultyofInformationand CommunicationTechnology UniversityofMalta Msida,Malta ISBN978-3-642-29839-4 ISBN978-3-642-29840-0(eBook) DOI10.1007/978-3-642-29840-0 SpringerHeidelbergNewYorkDordrechtLondon LibraryofCongressControlNumber:2012940954 ACMComputingClassification(1998): F.4,F.2,G.2 ©Springer-VerlagBerlinHeidelberg2012 Thisworkissubjecttocopyright.AllrightsarereservedbythePublisher,whetherthewholeorpartof thematerialisconcerned,specificallytherightsoftranslation,reprinting,reuseofillustrations,recitation, broadcasting,reproductiononmicrofilmsorinanyotherphysicalway,andtransmissionorinformation storageandretrieval,electronicadaptation,computersoftware,orbysimilarordissimilarmethodology nowknownorhereafterdeveloped.Exemptedfromthislegalreservationarebriefexcerptsinconnection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’slocation,initscurrentversion,andpermissionforusemustalwaysbeobtainedfromSpringer. PermissionsforusemaybeobtainedthroughRightsLinkattheCopyrightClearanceCenter.Violations areliabletoprosecutionundertherespectiveCopyrightLaw. Theuseofgeneraldescriptivenames,registerednames,trademarks,servicemarks,etc.inthispublication doesnotimply,evenintheabsenceofaspecificstatement,thatsuchnamesareexemptfromtherelevant protectivelawsandregulationsandthereforefreeforgeneraluse. Whiletheadviceandinformationinthisbookarebelievedtobetrueandaccurateatthedateofpub- lication,neithertheauthorsnortheeditorsnorthepublishercanacceptanylegalresponsibilityforany errorsoromissionsthatmaybemade.Thepublishermakesnowarranty,expressorimplied,withrespect tothematerialcontainedherein. Printedonacid-freepaper SpringerispartofSpringerScience+BusinessMedia(www.springer.com) DedicatedtoClaudia and tomyparents Foreword Profoundknowledgeandskillsindiscretemathematicsaremandatoryforawelled- ucatedcomputerscientist.Thereforeacorrespondingcurriculumtypicallyrequires atleastabasiccourseonthissubject.Thistextbook,whichisbasedonthelectures given by the author at the University of Malta, is a perfect companion for every studenttakingsuchacourse. Whenteachingaformalcomputersciencetopiconecaneitherfollowaso-called descriptiveoralgorithmicapproach.Traditionallymosttextbooksondiscretemath- ematicsfollowthedescriptiveapproachmeaningthatthepropertiesofmathematical structuresarelistedfirstwhilethealgorithmstocomputecorrespondingresultsare ofsecondaryinterest.Thistextbookfollowsthealgorithmicapproachwhichseems tobebettersuitedforcomputersciencestudents:Mathematicalstructuresareintro- ducedanddefinedusingalgorithmswhicharethencharacterizedbytheirproperties inasecondstep. Thebookcoversthematerialthatisessentialknowledgeforacomputerscience student. Starting with propositional and first order logic it discusses sets, relations andfurtherdiscretemathematicalstructures.Itcontainsachapterontypetheorybe- foreintroducingthenaturalnumbers.Inthefinalchapteritdiscusseshowtoreason aboutprogramsandgivesthebasicsofcomputabilitytheory. Besidesathoroughformalpresentationthebookalwaysgivesaconvincingmo- tivationforstudyingthecorrespondingstructuresandexplainsthemainideasusing illustrations. A well chosen set of exercises rounds off each topic. After studying thepresentedmaterialacomputersciencestudentwillbewellpreparedforfurther, morespecializedcourses. Lübeck,Germany MartinLeucker vii Preface Incomputerscience,asinothersciences,mathematicsplaysanimportantrole.In fact,computersciencehasmoreincommonwithmathematicsthanwiththetradi- tionalsciences.Considerphysics,forexample.Clearly,mathematicsisrightatthe coreofthesubject,usedtodescribemodelswhichexplainandpredictthephysical world. Without mathematics, most of modern physics would have been impossi- bletodevelop,sinceapurelyqualitativeanalysisdoesnotallowonetoreasonand deduce what logically follows from an observation or a hypothesised model. No manner of qualitative reasoning would have enabled Newton to formulate his law ofgravitybasedonKepler’sclaimsaboutplanetarymotion.Computersciencealso exploitsmathematicalreasoninginasimilarmanner.Givenacomputersystem,one can apply mathematical reasoning to prove that it will always calculate your pay- checkcorrectly. However,thelinkiseventighterthanthis.Computerscienceisadirectdescen- dant of mathematics, and computers are nothing but the physical embodiment of mathematical systems developed long before the first modern computer was even conceived,letalonebuilt. Inthisbook,wewillbeexploringthefoundationalmathematicswhichisneces- saryfortheunderstandingofmoreadvancedcoursesincomputerscience.Whether youaredesigningadigitalcircuit,acomputerprogramoranewprogramminglan- guage, mathematics is needed to reason about the design—its correctness, robust- nessanddependability. There are two distinct approaches used to present mathematical concepts and operators.Inthefirstapproachconceptsandoperatorsaredefinedintermsofprop- ertieswhichtheysatisfy.Basedonthesedefinitions,waysofcomputingtheresultof applyingtheseoperatorsarethendevelopedandprovedtobecorrect.Incontrast,in computersciencefrequentlyonetakestheoppositeapproach—onestartsbydefin- ingwaysofcalculatingtheresultofanoperator,andthenprovesthattheoperator oneknowshowtocomputesatisfiesanumberofproperties.Thetwoapproachesare, intheend,equivalent.However,giventhatthisbookisaimedatcomputerscience students,thelatterapproachisusuallyadopted. ix x Preface Finally,mostsectionsareaccompaniedbyexerciseswhichareusuallynecessary as part of the learning process. Learning mathematics is surprisingly like learning to ride a bicycle. You must try to write formal expressions and proofs before you really understand the concepts you read about. Some of the concepts covered in thisbookmayinitiallyappeartobedifficult.However,asyouprogressthroughthe bookandfamiliariseyourselfwiththeconcepts,youwillhopefullystartrequiring lessefforttofollowthedefinitionsandproofs,andbegintoenjoythebeautyofhow various concepts in mathematics can be built and reasoned about, based on just a smallnumberofbasicconcepts. BuenosAires,Argentina GordonJ.Pace Acknowledgements Theoriginalinspirationwhichledtothisbookdatesbackalmosttwodecades,when IfollowedacourseonmathematicsforsystemspecificationlecturedbyJoeStoyat theUniversityofOxford.Hisapproachofbuildingupthenecessarymathematical machinery from the ground up, akin to building a software system, provided the spark which years later led to the design of the structure and content of a course in mathematics of discrete structures, and consequently to this book. Without Joe Stoy’sspark,thisbookwouldneverhavebeen. Thisbookhasbeenlonginthemaking.Lifekeptgettingintheway.Manystu- dents would havebenefittedhad the book beenfinished earlier.Instead,they were exposedto the intendedcontentin my lectures—questions and blank faces expos- ingthepartsofthebookwhichIhadtorethink.Thanksgoouttothosehundredsof studentswithoutwhomthebookwouldhavebeenmuchpoorer. Thanks also go out to those people who used initial drafts of the book to de- liver and support taught courses in mathematics of discrete structures: Christian Colombo, Adrian Francalanza, Ingram Bondin, Mark Bonnici, Andrew Calleja, KarlstonDemanuele,KevinFalzon,AndrewGauciandChristineVella.Theirfeed- backwasinvaluable. Finally,theshortestthanksgoouttothosewhosesupportcanneverbefullyac- knowledged,nomatterhowlongIwriteaboutit—Claudia,DodieandJosie.Thank you. xi Contents 1 WhyMathematics? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 WhatIsMathematics? . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2 AHistoricalPerspective . . . . . . . . . . . . . . . . . . . . . . . 2 1.3 OntheSuperiorityofFormalReasoning . . . . . . . . . . . . . . 4 1.4 TheMathematicsofComputing . . . . . . . . . . . . . . . . . . . 4 1.4.1 TheAnalysisofPrograms . . . . . . . . . . . . . . . . . . 5 1.4.2 FormalSpecificationofRequirements . . . . . . . . . . . 6 1.4.3 ReasoningAboutPrograms . . . . . . . . . . . . . . . . . 6 1.4.4 TheLimitsofComputing . . . . . . . . . . . . . . . . . . 7 1.4.5 APhysicalEmbodimentofMathematics . . . . . . . . . . 8 1.5 Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2 PropositionalLogic . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.1 WhatIsaProposition? . . . . . . . . . . . . . . . . . . . . . . . . 9 2.2 TheLanguageofDiscourse . . . . . . . . . . . . . . . . . . . . . 10 2.3 ModelTheory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.3.1 TruthTables:PropositionalOperators . . . . . . . . . . . . 16 2.3.2 PropertiesofPropositionalSentences . . . . . . . . . . . . 22 2.3.3 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 28 2.4 ProofTheory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.4.1 WhatIsaProof? . . . . . . . . . . . . . . . . . . . . . . . 29 2.4.2 ExampleAxiomsandRulesofInference . . . . . . . . . . 30 2.4.3 WhyProofs? . . . . . . . . . . . . . . . . . . . . . . . . . 47 2.5 ComparingTruthTablesandProofs . . . . . . . . . . . . . . . . . 47 2.5.1 Completeness . . . . . . . . . . . . . . . . . . . . . . . . 48 2.5.2 Soundness . . . . . . . . . . . . . . . . . . . . . . . . . . 48 2.6 MoreAboutPropositionalLogic . . . . . . . . . . . . . . . . . . 48 2.6.1 BooleanAlgebra . . . . . . . . . . . . . . . . . . . . . . . 48 2.6.2 DoingwithLess . . . . . . . . . . . . . . . . . . . . . . . 50 2.6.3 DoingwithEvenLess . . . . . . . . . . . . . . . . . . . . 51 2.6.4 WhatiftheAxiomsAreWrong? . . . . . . . . . . . . . . 52 xiii xiv Contents 2.7 SomeNotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 2.7.1 NotationandSymbols . . . . . . . . . . . . . . . . . . . . 53 2.7.2 ProofElegance . . . . . . . . . . . . . . . . . . . . . . . . 54 2.7.3 HowtoComeupwithaProof . . . . . . . . . . . . . . . . 55 2.7.4 NotAllProofsAreEqual . . . . . . . . . . . . . . . . . . 55 3 PredicateCalculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 3.1 TheLimitsofPropositionalLogic . . . . . . . . . . . . . . . . . . 57 3.2 TheLanguageofDiscourse . . . . . . . . . . . . . . . . . . . . . 58 3.3 TheUseofVariables . . . . . . . . . . . . . . . . . . . . . . . . . 61 3.3.1 FreeVariables . . . . . . . . . . . . . . . . . . . . . . . . 62 3.3.2 SubstitutionofVariables . . . . . . . . . . . . . . . . . . . 64 3.4 AxiomatisationofPredicateLogic . . . . . . . . . . . . . . . . . 67 3.4.1 UniversalQuantification . . . . . . . . . . . . . . . . . . . 67 3.4.2 ExistentialQuantification . . . . . . . . . . . . . . . . . . 69 3.4.3 ExistentialQuantificationandEquality . . . . . . . . . . . 76 3.5 BeyondPredicateCalculus . . . . . . . . . . . . . . . . . . . . . 76 4 Sets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 4.1 WhatAreSets? . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 4.2 QueriesAboutSets . . . . . . . . . . . . . . . . . . . . . . . . . 80 4.3 ComparingSets . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 4.3.1 Subsets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 4.3.2 SetEquality . . . . . . . . . . . . . . . . . . . . . . . . . 83 4.4 ConstructingSets . . . . . . . . . . . . . . . . . . . . . . . . . . 84 4.4.1 FiniteSets . . . . . . . . . . . . . . . . . . . . . . . . . . 84 4.4.2 TheEmptySet . . . . . . . . . . . . . . . . . . . . . . . . 85 4.4.3 SetComprehensions . . . . . . . . . . . . . . . . . . . . . 86 4.5 SetOperators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 4.5.1 SetUnion . . . . . . . . . . . . . . . . . . . . . . . . . . 92 4.5.2 SetIntersection . . . . . . . . . . . . . . . . . . . . . . . 93 4.5.3 SetComplement . . . . . . . . . . . . . . . . . . . . . . . 95 4.5.4 SetDifference . . . . . . . . . . . . . . . . . . . . . . . . 97 4.5.5 OtherPropertiesoftheSetOperators . . . . . . . . . . . . 98 4.5.6 GeneralisedSetOperators . . . . . . . . . . . . . . . . . . 99 4.6 SetsasaBooleanAlgebra . . . . . . . . . . . . . . . . . . . . . . 102 4.7 MoreAboutTypes . . . . . . . . . . . . . . . . . . . . . . . . . . 104 4.7.1 TypesandSets . . . . . . . . . . . . . . . . . . . . . . . . 104 4.7.2 OnWhyTypesAreDesirable:Russell’sParadox . . . . . . 108 4.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 5 Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 5.1 AnInformalViewofRelations . . . . . . . . . . . . . . . . . . . 111 5.2 FormalisingRelations . . . . . . . . . . . . . . . . . . . . . . . . 112 5.2.1 TheTypeofaRelation. . . . . . . . . . . . . . . . . . . . 113 5.2.2 SomeBasicRelations . . . . . . . . . . . . . . . . . . . . 114 Contents xv 5.2.3 RelationalEquality . . . . . . . . . . . . . . . . . . . . . 115 5.2.4 CombiningRelationsasSets . . . . . . . . . . . . . . . . 115 5.3 DomainandRange. . . . . . . . . . . . . . . . . . . . . . . . . . 118 5.4 BuildingNewRelationsfromOldOnes . . . . . . . . . . . . . . . 119 5.4.1 CompositionofRelations . . . . . . . . . . . . . . . . . . 119 5.4.2 RelationalInverse . . . . . . . . . . . . . . . . . . . . . . 123 5.4.3 RepeatedRelations . . . . . . . . . . . . . . . . . . . . . 127 5.4.4 Closure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 5.5 OtherRelationalOperators . . . . . . . . . . . . . . . . . . . . . 134 5.6 BeyondBinaryRelations . . . . . . . . . . . . . . . . . . . . . . 138 5.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 6 ClassifyingRelations . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 6.1 ClassesofRelations . . . . . . . . . . . . . . . . . . . . . . . . . 141 6.1.1 Totality . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 6.1.2 Surjectivity . . . . . . . . . . . . . . . . . . . . . . . . . . 143 6.1.3 Injectivity . . . . . . . . . . . . . . . . . . . . . . . . . . 144 6.1.4 Functionality . . . . . . . . . . . . . . . . . . . . . . . . . 146 6.1.5 CombiningtheResults. . . . . . . . . . . . . . . . . . . . 148 6.2 RelatingaTypetoItself . . . . . . . . . . . . . . . . . . . . . . . 149 6.2.1 PropertiesofTheseRelations . . . . . . . . . . . . . . . . 149 6.2.2 Order-InducingRelations . . . . . . . . . . . . . . . . . . 152 6.2.3 EquivalenceRelations . . . . . . . . . . . . . . . . . . . . 153 6.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 7 MoreDiscreteStructures . . . . . . . . . . . . . . . . . . . . . . . . 157 7.1 Multisets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 7.2 Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 7.3 GraphTheory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 8 DefiningNewStructuredTypes . . . . . . . . . . . . . . . . . . . . . 175 8.1 NotionsandNotation . . . . . . . . . . . . . . . . . . . . . . . . 176 8.1.1 SimpleEnumeratedTypes . . . . . . . . . . . . . . . . . . 176 8.1.2 MoreElaborateTypes . . . . . . . . . . . . . . . . . . . . 177 8.1.3 Self-ReferentialTypes . . . . . . . . . . . . . . . . . . . . 179 8.1.4 ParametrisedTypes . . . . . . . . . . . . . . . . . . . . . 181 8.2 ReasoningAboutNewTypes . . . . . . . . . . . . . . . . . . . . 184 8.2.1 AxiomatisingNewTypes . . . . . . . . . . . . . . . . . . 184 8.2.2 AGeneralInductivePrinciple . . . . . . . . . . . . . . . . 188 8.2.3 StructuralInduction . . . . . . . . . . . . . . . . . . . . . 193 8.3 UsingStructuredTypes . . . . . . . . . . . . . . . . . . . . . . . 194 8.3.1 Three-ValuedLogic . . . . . . . . . . . . . . . . . . . . . 194 8.3.2 ProcessingData . . . . . . . . . . . . . . . . . . . . . . . 198 8.3.3 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202 8.3.4 BinaryTrees . . . . . . . . . . . . . . . . . . . . . . . . . 206 8.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.