Set Theory in Computer Science A Gentle Introduction to Mathematical Modeling I Jose´ Meseguer UniversityofIllinoisatUrbana-Champaign Urbana,IL61801,USA (cid:13)c Jose´ Meseguer,2008–2010;allrightsreserved. February28,2011 2 Contents 1 Motivation 7 2 SetTheoryasanAxiomaticTheory 11 3 TheEmptySet,Extensionality,andSeparation 15 3.1 TheEmptySet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.2 Extensionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.3 TheFailedAttemptofComprehension . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.4 Separation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 4 Pairing,Unions,Powersets,andInfinity 19 4.1 Pairing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 4.2 Unions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 4.3 Powersets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 4.4 Infinity. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 5 CaseStudy: AComputableModelofHereditarilyFiniteSets 29 5.1 HF-SetsinMaude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 5.2 Terms,Equations,andTermRewriting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 5.3 Confluence,Termination,andSufficientCompleteness . . . . . . . . . . . . . . . . . . . 36 5.4 AComputableModelofHF-Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 5.5 HF-SetsasaUniverseforFinitaryMathematics . . . . . . . . . . . . . . . . . . . . . . . 43 5.6 HF-SetswithAtoms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 6 Relations,Functions,andFunctionSets 51 6.1 RelationsandFunctions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 6.2 Formula,Assignment,andLambdaNotations . . . . . . . . . . . . . . . . . . . . . . . . 52 6.3 Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 6.4 ComposingRelationsandFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 6.5 AbstractProductsandDisjointUnions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 6.6 RelatingFunctionSets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 7 SimpleandPrimitiveRecursion,andthePeanoAxioms 65 7.1 SimpleRecursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 7.2 PrimitiveRecursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 7.3 ThePeanoAxioms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 8 CaseStudy: ThePeanoLanguage 71 9 BinaryRelationsonaSet 73 9.1 DirectedandUndirectedGraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 9.2 TransitionSystemsandAutomata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 9.3 RelationHomomorphismsandSimulations . . . . . . . . . . . . . . . . . . . . . . . . . 76 9.4 Orders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 3 9.5 SupsandInfs,CompletePosets,Lattices,andFixpoints . . . . . . . . . . . . . . . . . . . 81 9.6 EquivalenceRelationsandQuotients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 9.7 ConstructingZandQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 10 CaseStudy: FixpointSemanticsofRecursiveFunctionsandLispy 91 10.1 RecursiveFunctionDefinitionsinaNutshell . . . . . . . . . . . . . . . . . . . . . . . . . 92 10.2 FixpointSemanticsofRecursiveFunctionDefinitions . . . . . . . . . . . . . . . . . . . . 93 10.3 TheLispyProgrammingLanguage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 11 SetsComeinDifferentSizes 97 11.1 Cantor’sTheorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 11.2 TheSchroeder-BernsteinTheorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 12 I-IndexedSets 99 12.1 I-IndexedSetsareSurjectiveFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 12.2 ConstructingI-IndexedSetsfromotherI-IndexedSets . . . . . . . . . . . . . . . . . . . 104 12.3 I-IndexedRelationsandFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 13 FromI-IndexedSetstoSets,andtheAxiomofChoice 107 13.1 SomeConstructionsAssociatingaSettoanI-IndexedSet . . . . . . . . . . . . . . . . . 107 13.2 TheAxiomofChoice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 14 Well-FoundedRelations,andWell-FoundedInductionandRecursion 117 14.1 Well-FoundedRelations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 14.1.1 ConstructingWell-FoundedRelations . . . . . . . . . . . . . . . . . . . . . . . . 118 14.2 Well-FoundedInduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 14.3 Well-FoundedRecursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 14.3.1 ExamplesofWell-FoundedRecursion . . . . . . . . . . . . . . . . . . . . . . . . 120 14.3.2 Well-FoundedRecursiveDefinitions: StepFunctions . . . . . . . . . . . . . . . . 121 14.3.3 TheWell-FoundedRecursionTheorem . . . . . . . . . . . . . . . . . . . . . . . 123 15 CardinalNumbersandCardinalArithmetic 125 15.1 CardinalArithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 15.2 TheIntegersandtheRationalsareCountable . . . . . . . . . . . . . . . . . . . . . . . . 129 15.3 TheContinuumandtheContinuumHypothesis . . . . . . . . . . . . . . . . . . . . . . . 131 15.3.1 PeanoCurves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 15.3.2 TheContinuumHypothesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 16 Classes,IntensionalRelationsandFunctions,andReplacement 135 16.1 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 16.1.1 MathematicalTheoremsareAssertionsaboutClasses . . . . . . . . . . . . . . . . 138 16.2 IntensionalRelations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 16.3 IntensionalFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 16.3.1 TypingIntensionalFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 16.3.2 ComputingwithIntensionalFunctions . . . . . . . . . . . . . . . . . . . . . . . . 143 16.3.3 DependentandPolymorphicTypes . . . . . . . . . . . . . . . . . . . . . . . . . 144 16.4 TheAxiomofReplacement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 17 CaseStudy: DependentandPolymorphicTypesinMaude 149 17.1 DependentTypesinMaude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 17.2 Polymorphic-and-DependentTypesinMaude . . . . . . . . . . . . . . . . . . . . . . . . 152 17.3 DefinabilityIssues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 4 18 WellOrders,Ordinals,Cardinals,andTransfiniteConstructions 155 18.1 Well-OrderedSets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 18.2 Ordinals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 18.2.1 OrdinalsasTransitiveSets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 18.2.2 SuccessorandLimitOrdinals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 18.2.3 OrdinalArithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 18.3 TransfiniteInduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 18.4 TransfiniteRecursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 18.4.1 α-Recursion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 18.4.2 SimpleIntensionalRecursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 18.4.3 TransfiniteRecursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 18.5 Well-Orderings,Choice,andCardinals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 18.5.1 Cardinals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 18.5.2 MoreCardinalArithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 18.5.3 Regular,Singular,andInaccessibleCardinals . . . . . . . . . . . . . . . . . . . . 172 19 Well-FoundedSetsandTheAxiomofFoundation 173 19.1 Well-FoundedSetsfromtheTopDown . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 19.1.1 (cid:51)-Induction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 19.2 Well-FoundedSetsfromtheBottomUp . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 19.3 TheAxiomofFoundation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 5 6 Chapter 1 Motivation “... we cannot improve the language of any science without at the same time improving the science itself; neither can we, on the other hand, improve a science, without improving the languageornomenclaturewhichbelongstoit.” (Lavoisier,1790,quotedinGoldenfeldandWoese[23]) Ifoundtheinadequacyoflanguagetobeanobstacle;nomatterhowunwieldlytheexpressions Iwasreadytoaccept,Iwaslessandlessable,astherelationsbecamemoreandmorecomplex, to attain the precision that my purpose required. This deficiency led me to the idea of the presentideography. ...IbelievethatIcanbestmaketherelationofmyideographytoordinary languageclearifIcompareittothatwhichthemicroscopehastotheeye.Becauseoftherange ofitspossibleusesandtheversatilitywithwhichitcanadapttothemostdiversecircumstances, the eye is far superior to the microscope. Considered as an optical instrument, to be sure, it exhibitsmanyimperfections,whichordinarilyremainunnoticedonlyonaccountofitsintimate connection with our mental life. But, as soon as scientific goals demand great sharpness of resolution, the eye proves to be insufficient. The microscope, on the other hand, is prefectly suitedtopreciselysuchgoals,butthatisjustwhyitisuselessforallothers. (Frege,1897,Begriffsschrift,in[52],5–6) Language and thought are related in a deep way. Without any language it may become impossible to conceive and express any thoughts. In ordinary life we use the different natural languages spoken on the planet. Butnaturallanguage,althoughextremelyflexible,canbehighlyambiguous,anditisnotatallwell suitedforscience. Imagine,forexample,thetaskofprofessionallydevelopingquantummechanics(itself relying on very abstract concepts, such as those in the mathematical language of operators in a Hilbert space)inordinaryEnglish. Suchataskwouldbevirtuallyimpossible;indeed,ridiculous: aspreposterous as trying to build the Eiffel tower in the Sahara desert with blocks of vanilla ice cream. Even the task of popularization,thatis,ofexplaininginformallyinordinaryEnglishwhatquantummechanicsis,ishighly nontrivial,andmustofnecessityremaintoaconsiderableextentsuggestive,metaphorical,andfraughtwith thepossibilityofgrossmisunderstandings. Thepointisthatwithoutaprecisescientificlanguageitbecomesvirtuallyimpossible,oratleastenor- mously burdensome and awkward, to think scientifically. This is particularly true in mathematics. One of the crowning scientific achievements of the 20th century was the development of set theory as a pre- ciselanguageforallofmathematics,thankstotheeffortsofCantor,Dedekind,Frege,Peano,Russelland Whitehead,Zermelo,Fraenkel, Skolem,Hilbert,vonNeumann,Go¨del,Bernays,Cohen, andothers. This achievementhasbeensoimportantanddefinitivethatitledDavidHilberttosay,alreadyin1925,that“no one will drive us from the paradise which Cantor created for us” (see [52], 367–392, pg. 376). It was of 7 course possible to think mathematically before set theory, but in a considerably more awkward and quite restrictedway,becausethelevelsofgenerality,rigorandabstractionmadepossiblebysettheoryaremuch greaterthanatanyotherprevioustime. Infact,manykeymathematicalconceptswenowtakeforgranted, suchathoseofanabstractgrouporatopologicalspace,couldonlybeformulatedaftersettheory,precisely becausethelanguageneededtoconceiveandarticulatethoseconceptswasnotavailablebefore. Set theory is not really the only rigorous mathematical language. The languages of set theory and of mathematicallogicweredevelopedtogether,sothat,asamathematicaldiscipline,settheoryisabranchof mathematicallogic. Technically,asweshallseeshortly,wecanviewthelanguageofsettheoryasaspecial sublanguageoffirst-orderlogic. Furthermore,othertheoriessuchascategorytheoryandintuitionistictype theoryhavebeenproposedasalternativestosettheorytoexpressallofmathematics. Therearevariouspreciselogicalformalismsotherthansettheorywhichareparticularlywell-suitedto expressspecificconceptsinagivendomainofthought. Forexample,temporallogicisquitewell-suitedto expresspropertiessatisfiedbythedynamicbehaviorofaconcurrentsystem;andbothequationallogicand thelambdacalculusareverywellsuitedtodealwithfunctionsandfunctionalcomputation. However, set theoryplaysaprivilegedroleasamathematicallanguageinwhichallthemathematicalstructuresweneed in order to give a precise meaning to the models described by various other logical languages, and to the satisfactionofformulasinsuchlanguages,canbedefined. All this hasa direct bearing on thetask of formal software specificationand verification. Sucha task would be meaningless, indeed utter nonsense and voodoo superstition, without the use of mathematical models and mathematical logic. And it is virtually impossible, or extremely awkward, to even say what needs to be said about such mathematical models and logical properties without a precise mathematical language. Moreimportantly,itbecomesvirtuallyimpossibletothinkproperlywithouttheconceptualtools provided by such a language. Either set theory or some comparable language become unavoidable: it is partofwhatanywelleducatedcomputerscientistshouldbeconversantwith,liketheaironebreathes. These notes include a review of basic set theory concepts that any well educated computer scientist should already be familiar with. Although they go beyond reviewing basic knowledge in various ways, nothingexceptbasicacquaintancewiththeuseoflogicalconnectivesandofuniversalandexistentialquan- tificationinlogicisassumed: thepresentationisentirelyself-contained,andmanyexercisesareproposed tohelpthereadersharpenhis/herunderstandingofthebasicconcepts. Theexercisesareanessentialpart of these notes, both because they are used in proofs of quite a few theorems, and because by solving problems in a mathematical theory one avoids having a superficial illusion of understanding, and gains realunderstanding. Forthosealreadywell-versedinelementarysettheory, thesenotescanbereadrather quickly. However, some topics such as well-founded relations, well-founded induction, well-founded re- cursive functions, I-indexed sets, ordinals and cardinals, classes, and transfinite induction and recursion, may be less familiar. Also, already familiar notions are here presented in a precise, axiomatic way. This mayhelpevensomereadersalreadythoroughlyfamiliarwith“naive”settheorygainamoredetailedun- derstandingofitasalogicallyaxiomatizedtheory. Becomingusedtoreasoncorrectlywithinanaxiomatic theory—Euclideangeometryistheclassicalexample,andaxiomaticsettheoryfollowsthesameconcep- tualpattern—isthebestwayIknowoflearningtothinkinaprecise, mathematicalway. Furthermore, a number of useful connections between set theory and computer science are made explicit in these notes; connectionsthatareusuallynotdevelopedinstandardpresentationsofsettheory. Ishouldaddsomefinalremarksonthestyleofthesenotes. Therearethreeparticularstylisticfeatures thatIwouldliketoexplain. First,thesenotestaketheformofanextendedconversationwiththereader,in whichIproposeanddiscussvariousproblems,whytheymatter,andthrowoutideasonhowtosolvesuch problems. ThisisbecauseIbelievethatscienceitselfisanongoingcriticaldialogue,andaskingquestions in a probing way is the best way to understand anything. Second, I do not assume the proverbial mathe- maticalmaturityonthepartofthereader, sincesuchmaturityispreciselythequoderatdemonstrandum, andbringingitaboutisoneofthemaingoalsofthesenotes: Iamconvincedthatinthe21stcenturymath- ematicalmaturityisvirtuallyimpossiblewithoutmasteringthelanguageofsettheory. Onthecontrary, I assume the potential mathematical immaturity of some readers. This means that, particularly in the early chapters, there is a generous amount of what might be called mathematical spoon feeding, hand holding, andevenafewnurserytales. Thisdoesnotgoonforever,sinceateachstageIassumeasknownallthathas beenalreadypresented,thatis,themasteryofthelanguagealreadycovered,sothatinmoreadvancedchap- ters,althoughtheconversationalstyle,examples,andmotivationremain,thediscoursegraduallybecomes 8 more mature. By the way, all this does not necessarily mean that the book is of no interest to mathemat- ically mature readers, including professional mathematicians. What it does mean is that it should be an easy read for them; one from which they may gain at least two things: (i) a more reflective, systematic understandingof thesettheory theyuseevery day; and(ii)a goodunderstanding ofsomeof thewaysin which mathematical models are used in computer science. The third stylistic feature I want to discuss is thatthemindsetofcategorytheory,pervasiveinmodernmathematics,ispresenteverywhereinthesenotes, but in Parts I and II this happens in a subliminal way. Categories and functors are only defined in Part III;buttheyarepresentfromthebeginninglikeahiddenmusic. Andfunctorialconstructionsmakeearly cameoappearancesinPartI(verymuchlikeAlfredHitchcockinhisownmovies)infourexercisesandin §15. Indeed,§15,oncardinalsandcardinalarithmetic,isagreatbeneficiaryofthissubliminal,categorical style; because much of basic cardinal arithmetic turns out to be an easy corollary of the functoriality of theset-theoreticconstructionsusedtodefinearithmeticoperationsoncardinals. Thetempoofthishidden categoricalmusicpicksupwhenuniversalalgebraandfirst-orderlogicarediscussedinPartII;buttherich harvestfromthissubliminal,categoricalsowingisreallyreapedinPartIII.Inmyview,thisisagoodway ofgentlypreparingthereader,witharichcollectionofexamples,tofullyappreciatethebeauty,power,and conceptualeconomyofthelanguageofcategorytheory. 9 10