Download pdf Theoretical computer science for the working category theorist noson s. yanofsky full c

Page 1


Computer Science for the Working Category Theorist Noson S.

Visit to download the full and correct content document: https://ebookmeta.com/product/theoretical-computer-science-for-the-working-categor y-theorist-noson-s-yanofsky/

More products digital (pdf, epub, mobi) instant download maybe you interests ...

Click Start Level 4 Student s Book Computer Science for Schools CBSE Computer Science Anjna Virmani

https://ebookmeta.com/product/click-start-level-4-student-s-bookcomputer-science-for-schools-cbse-computer-science-anjna-virmani/

Formal Methods for Software Engineering: Languages, Methods, Application Domains (Texts in Theoretical Computer Science. An EATCS Series) Markus Roggenbach

https://ebookmeta.com/product/formal-methods-for-softwareengineering-languages-methods-application-domains-texts-intheoretical-computer-science-an-eatcs-series-markus-roggenbach/

The Self Taught Computer Scientist The Beginner s Guide to Computer Science 1st Edition Althoff

https://ebookmeta.com/product/the-self-taught-computer-scientistthe-beginner-s-guide-to-computer-science-1st-edition-althoff/

Computer Science Principles The Foundational Concepts of Computer Science Kevin Hare

https://ebookmeta.com/product/computer-science-principles-thefoundational-concepts-of-computer-science-kevin-hare/

Computer Science Principles : The Foundational Concepts of Computer Science 4th Edition Kevin Hare

https://ebookmeta.com/product/computer-science-principles-thefoundational-concepts-of-computer-science-4th-edition-kevin-hare/

Computer Science Principles: The Foundational Concepts of Computer Science, 4th Edition Kevin P Hare

https://ebookmeta.com/product/computer-science-principles-thefoundational-concepts-of-computer-science-4th-edition-kevin-phare/

Mathematics for Computer Graphics (Undergraduate Topics in Computer Science), 6th Edition 2022 John Vince

https://ebookmeta.com/product/mathematics-for-computer-graphicsundergraduate-topics-in-computer-science-6th-edition-2022-johnvince/

The Data Science Design Manual Texts in Computer Science Skiena

https://ebookmeta.com/product/the-data-science-design-manualtexts-in-computer-science-skiena/

Computer Science Theory and Applications 17th

International Computer Science Symposium in Russia CSR 2022 Virtual Event June 29 July 1 2022 Lecture Notes in Computer Science 13296 Alexander S. Kulikov (Editor)

https://ebookmeta.com/product/computer-science-theory-andapplications-17th-international-computer-science-symposium-inrussia-csr-2022-virtual-event-june-29-july-1-2022-lecture-notes-

UniversityPrintingHouse,CambridgeCB28BS,UnitedKingdom OneLibertyPlaza,20thFloor,NewYork,NY10006,USA

477WilliamstownRoad,PortMelbourne,VIC3207,Australia

314–321,3rdFloor,Plot3,SplendorForum,JasolaDistrictCentre, NewDelhi–110025,India

103PenangRoad,#05–06/07,VisioncrestCommercial,Singapore238467

CambridgeUniversityPressispartoftheUniversityofCambridge. ItfurtherstheUniversity’smissionbydisseminatingknowledgeinthepursuitof education,learning,andresearchatthehighestinternationallevelsofexcellence.

www.cambridge.org Informationonthistitle: www.cambridge.org/9781108792745 DOI: 10.1017/9781108872348

©NosonS.Yanofsky2022

Thispublicationisincopyright.Subjecttostatutoryexception andtotheprovisionsofrelevantcollectivelicensingagreements, noreproductionofanypartmaytakeplacewithoutthewritten permissionofCambridgeUniversityPress.

Firstpublished2022

AcataloguerecordforthispublicationisavailablefromtheBritishLibrary.

ISBN978-1-108-79274-5Paperback

ISSN2633-1861(online)

ISSN2633-1853(print)

CambridgeUniversityPresshasnoresponsibilityforthepersistenceoraccuracyof URLsforexternalorthird-partyinternetwebsitesreferredtointhispublication anddoesnotguaranteethatanycontentonsuchwebsitesis,orwillremain, accurateorappropriate.

TheoreticalComputerSciencefortheWorking CategoryTheorist

ElementsinAppliedCategoryTheory

DOI:10.1017/9781108872348

Firstpublishedonline:January2022

NosonS.Yanofsky

BrooklynCollege,CityUniversityofNewYork

Authorforcorrespondence: NosonS.Yanofsky, noson@sci.brooklyn.cuny.edu

Abstract: Usingbasiccategorytheory(category,functor,natural transformation,etc.),thisElementdescribesallthecentralconceptsand provesthemaintheoremsoftheoreticalcomputerscience.Category theory,whichworkswithfunctions,processes,andstructures,isuniquely qualifiedtopresentthefundamentalresultsoftheoreticalcomputer science.Inthistext,wemeetsomeofthedeepestideasandtheoremsof moderncomputersandmathematics,e.g.,Turingmachines,unsolvable problems,theP=NPquestion,KurtGödel’sincompletenesstheorem, intractableproblems,Turing’sHaltingproblem,andmuchmore.The conceptscomealivewithmanyexamplesandexercises.Thisshorttext coverstheusualmaterialtaughtinayear-longcourse.

Keywords: categorytheory,computationalmodels,computabilitytheory, complexitytheory

MSC2020SubjectClassification: 18AXX,18DXX,18MXX,03BXX,03DXX, 68NXX,68QXX,68RXX

©NosonS.Yanofsky2022

ISBNs:9781108792745(PB),9781108872348(OC) ISSNs:2633-1861(online),2633-1853(print)

Dedicatedtothememory ofmybrother

ThisworkisdedicatedtothememoryofmybrotherRabbiEliyahuMordechai YanofskyZTL(February19,1964–March12,2018).Hewasabrilliantscholar whospenthisentirelifestudyingJewishtextsandhelpingothers.Elihadawarm personalityandacleverwitthatendearedhimtomany.Hewasaninspiration tohundredsoffriendsandstudents.Asanolderbrother,hewasaparagonof excellence.Heleftbehindparents,awife,siblings,andtenwonderfulchildren. Hislosswasterriblypainful.Heissorelymissed.

Preface

“Unsolvableproblems,”“TheP=NPquestion,”“AlanTuring’sHalting problem,”“KurtGödel’sincompletenesstheorem,”“Intractableproblems,” etc.Thesearejustsomeofthemanybuzzwordsthatonehearsaboutinthe currenttechnologymedia.Theseconceptsareallassociatedwiththeoretical computersciencewhichtouchesonsomeofthedeepestandmostprofoundparts ofcontemporaryscienceandmathematics.Theissuesdiscussedinthiswork emergeinalmosteveryareaofcomputers,theoreticalphysics,andmathematics. Inthisshorttextyouwilllearnthemainideasandtheoremsoftheoretical computerscience.

Whiletherearemanytextbooksabouttheoreticalcomputerscience,this Elementisunique.Itisthefirsttextthattranslatestheideasoftheoretical computerscienceintothebasiclanguageofcategorytheory.Withsomeofthe simpleconceptsofcategorytheoryinhand,thereaderwillbeabletounderstand alltheideasandtheoremsthataretaughtinayear-longcourseoftheoretical computerscience.

Whyisitbettertolearntheoreticalcomputersciencewithcategorytheory?

• Itiseasy!Mostoftheideasandtheoremsoftheoreticalcomputerscienceare consequencesofthecategoricaldefinitions.Oncethecategoriesandfunctors ofthedifferentmodelsofcomputationaresetup,theconceptsoftheoretical computersciencesimplyemerge.Manytheoremsareastraightforward consequenceofcompositionandfunctoriality.

• Itisshort!Thepowerfullanguageofcategorytheoryensuresusthatwhatis usuallytaughtinalargetextbookcanbetaughtinthesefewpages.

• Itgivesyoutherightperspective!Anyonewhohaseverexperiencedany categorytheoryknowsthatitmakesyou“zoomout”andseethingsfroma “bird’s-eyeview.”Ratherthangettingoverwhelmedbyallthelittledetailsso thatyoucannot“seetheforestforthetrees,”categorytheoryletsyouseethe bigpicture.

• Itgetstothecoreoftheissues!Categorytheorydistillstheimportantaspects ofasubjectandleavesonewiththemainstructuresneededtounderstand whatisgoingon.

• Itconnectsbetterwithotherareasofscienceandmath!Categorytheoryhas becomethe linguafranca ofnumerousareasofmathematics,andtheoretical physics(e.g.,BaezandStay,2011;CoeckeandKissinger,2017).Byputting theideasoftheoreticalcomputerscienceinthelanguageofcategorytheory, connectionsaremadetotheseotherareas.

Thereareseveraltextsandpapersforthecomputerscientisttolearncategory

theory(BarrandWells,1999;Walters,1991;Pierce,1991;AspertiandLongo, 1991;Scott,2000;Spivak,2014;Poigné,1992).Oursistotallydifferent.The intendedaudiencehereissomeonewhoalreadyknowsthebasicsofcategory theoryandwhowantstolearntheoreticalcomputerscience.

OnedoesnotneedtobeacategorytheoryexperttoreadthisElement.We donotassumethatthereaderknowsmuchmorethanthenotionofcategory, functor,andequivalence.Anymoreadvancedcategoricalconceptsaretaught in§2or“onthefly”whenneeded.

Organisation

Westartwithaquickintroductiontothemajorthemesoftheoreticalcomputer scienceandexplainwhycategorytheoryisuniquelyqualifiedtodescribethose ideasandtheorems.Thenextsectionisashortteachingaidofsomecategorical structuresthatariseinthetextandthatmightbeunknowntothecategorytheory novice.

Sincewewillbediscussingcomputation,wemustfixourideasanddeal withvarious modelsofcomputation.Whatdowemeanbyacomputation? Theliteratureisfullofsuchmodels.Section 3 classifiesandcategorizesthese variousmodelswhileshowinghowtheyarealllinkedtogether.Withthe definitionsandnotationgivenin§§3.1and3.2,onecansafelymoveontoalmost anyotherpart.

Sections 4 and 5 arethecoreofthework.Section 4 describeswhichfunctions canbecomputedbyacomputer–andmoreimportantly–whichfunctions cannot becomputedbyacomputer.Thisiscalled computabilitytheory.Wegive manyexamplesoffunctionsthatnocomputercanperform.Alongtheway,we meetAlanTuring’sHaltingproblemandKurtGödel’sfamousincompleteness theorem.Wealsodiscussaclassificationandhierarchyofallthefunctionsthat cannotbecomputedbycomputers.

Wegoontodiscuss complexitytheory in§5.Thisiswhereweaskand answerwhatis efficiently computable.Everycomputablefunctiondemandsa certainamountoftimeorspacetocompute.Wediscusshowlongandhow complicatedcertaincomputationsare.Alongthewaywemeetthefamous NP-completeproblemsandtheP=NPquestion.

Section 6 isaboutaspecialtypeofproofthatarisesinmanypartsof theoreticalcomputerscience(andmanyareasofmathematics)calleda diagonal argument.Althoughthediagonalargumentscomeinmanydifferentforms,we showthattheyareallinstancesofasinglesimpletheoremofcategorytheory. AlongthewaywemeetStephenKleene’srecursiontheorem,GeorgCantor’s differentlevelsofinfinity,andJohnvonNeumann’sself-reproducingmachine.

Section 6 summarizeswhatwaslearnedabouttheoreticalcomputerscience fromthecategoricalperspective.Itlistsoffsomecommonthemesthatwere seenthroughoutthetext.Italsohasaguideforreaderswhowishtocontinue withtheirstudies.

Whilecomputabilitytheoryandcomplexitytheoryarethemaintopicstaught inatypicaltheoreticalcomputerscienceclass,therearemanyothertopicsthat areeithertouchedonoraretaughtinmoreadvancedcourses.Asupplementary sectiononthewebpageofthetextisaseriesofshortintroductionsforseveral excitingtopics: Formallanguagetheory, Cryptography, Kolmogorovcomplexity theory,and Algorithms.

Thetexthasmanyexamplesandexercises.Thereaderisstronglyurged toworkoutalltheexercises.Inaddition,theElementissprinkledwithshort “AdvancedTopics”thatpointoutcertainadvancedtheoremsorideas.Wealso directthereadertowheretheycanlearnmoreaboutthesetopics.Manysections endwithideasforapotential“ResearchProject.”

Attheendofeverysection,thereaderisdirectedtoplaceswheretheycan learnmoreaboutthetopicfromsourcesinclassicaltheoreticalcomputerscience andincategorytheory.

Thereare,however,omissionsforreasonsofspace.Wedonotcoverevery partoftheoreticalcomputerscience.Forexample,wewillnotdealwith programsemanticsandverification,analysisofalgorithms,datastructures, andinformationtheory.Whilealltheseareinterestingandcanbetreated withacategoricalperspective,wehaveomittedthesetopicsbecauseofspace considerations.Invariably,evenwithinthetopicsthatwedocover,certain theoremsandideasaremissedorglossedover.

Thisisnotatextbookabouttherelationshipbetweencategorytheoryand computerscience.Overthepasthalfcentury,categorytheoristshavemade tremendousadvancesincomputersciencebyapplyingcategoricalconceptsand constructionstothestructuresandprocessesofcomputation.Theliteraturein thisareaisimmense.Section 7.2 givessometextsandpaperstolookformore inthisdirection.Thistextwillnotpresentalltheseareas.Rather,itisfocused onthetaskathand.Hereweuseanovelpresentationtounderstandtheclassic partsoftheoreticalcomputerscience.

Thistextdoesnotstandalone.Imaintainawebpageforthetextat http://www.sci.brooklyn.cuny.edu/noson/TCStext.html

Thewebpagecontainssupplementarymaterial.Therewillalsobelinks tointerestingbooksandarticlesoncategorytheoryandtheoreticalcomputer science,somesolutionstoexercises,andalistoferrata.Thereaderisencouraged tosendanyandallcorrectionsandsuggestionsto noson@sci.brooklyn.cuny.edu.

1Introduction

Theoreticalcomputersciencestartedbeforelarge-scaleelectroniccomputers actuallyexisted.Inthe1930s,whenengineerswerejustbeginningtowork outtheproblemsofmakingviablecomputers,AlanTuringandotherswere alreadyexploringthelimitsofcomputation.Beforephysicistsandengineers beganstrugglingtocreatequantumcomputers,theoreticalcomputerscientists designedalgorithmsforquantumcomputersanddescribedtheirlimitations. Eventoday,beforethereareanylarge-scalequantumcomputers,theoretical computerscienceisworkingon“post-quantumcryptography.”Theprescient natureofthisfieldisaconsequenceofthefactthatitstudiesonlytheimportant andfoundationalissuesaboutcomputation.Itasksandanswersquestionssuch as“Whatisacomputation?”“Whatiscomputable?”“Whatisefficiently computable?”“Whatisinformation?”“Whatisrandom?”“Whatisan algorithm?”etc.

Forus,thecentralroleofacomputeristocalculatefunctions.Computers inputdataofacertaintype,manipulatethedata,andhaveoutputsofacertain type.Inordertostudycomputationwemustlookatthecollectionofallsuch functions.Wemustalsolookatallmethodsofcomputationandseehowthey describefunctions.Toeverycomputationalmethod,thereisanassociated function.Whatwillbeimportantistostudywhichfunctionsarecomputedbya computationalmethodandwhicharenot.Whichfunctionsareeasilycomputed andwhichfunctionsneedmoreresources?Alltheseissues–andmanymore–willbedealtwithinthesepages.

Categorytheoryisuniquelyqualifiedtopresenttheideasoftheoretical computerscience.Thebasiclanguageofcategorytheorywasformulated bySamuelEilenbergandSaundersMacLaneinthe1940s.Theywantedto classifyandcategorizetopologicalobjectsbyassociatingthemtoalgebraic objects.Todothistheyhadtoformulatealanguagethatwasnotspecifically relatedtotopologyoralgebra.Itneededtobeabstractenoughtodealwith bothtopologicalandalgebraicobjects.Thisiswherecategorytheorygetsits power.Bybeingaboutnothinginparticular,or“generalabstractnonsense,” itisabouteverything.Inthistext,wewillseecategoriescontainingvarious typesoffunctionsanddifferentmodelsofcomputation.Therearethenfunctors comparingthesefunctionsandcomputationalmethods.

Whencategoriesfirststarted,themorphismsinacategorywerethoughtof ashomomorphismsbetweenalgebraicstructuresorcontinuousmapsbetween topologicalspaces.Themorphism f : X − Y mightbeahomomorphism f fromgroup X togroup Y oritmightbeacontinuousmapfromtopologicalspace X totopologicalspace Y .However,astimeprogressed,researchersrealizedthat

theymightlookat f asa process ofgoingfrom X to Y .Analgebraicexampleis when X and Y arevectorspacesand f isalineartransformation,awayofgoing from X to Y .Inlogic, X and Y canbepropositionsand f isawayofshowing thatafterassuming X onecaninfer Y .Orforlogiciansinterestedinproofs, again X and Y werepropositionsand f representedaproof(oraformalwayof showing)thatwith X asanassumption,onecanconcludewith Y .Physicists alsogotintotheaction.Forthem, X and Y werestatesofasystemand f representedadynamicoraprocessofgoingfromonetotheother.Geometers andphysicistsconsidered X and Y tobemanifoldsofacertaintypeand f tobe alargershapewhoseboundarieswere X and Y .Computerscientistsconsider X and Y tobetypesofdataand f isafunctionoracomputationalprocessthat takesinputsoftype X tooutputoftype Y .Inthistext,manyofourcategories willbeofthisform.(SeeBaezandStay,2011,CoeckeandKissinger,2017,for comparisonsofmanydifferenttypesofprocesses.)

Itpaystoreexaminethedefinitionofacategorywiththenotionofamorphism asaprocess.Whentherearetwocomposablemaps,

theircomposition g ◦ f istobethoughtofas sequentialprocessing,i.e.,first performingthe f processandthenperformingthe g process.If X isanyobject, thenthereisanidentityprocess Id X : X − X whichdoesnothingto X .No changeismade.Whenanyprocessiscomposedwiththeidentityprocess,itis essentiallythesameastheoriginalprocess.Whentherearethreecomposable maps,

theassociativity ( h ◦ g )◦ f = h ◦(g ◦ f ) essentiallyfollowsfromthefactthat wearedoingtheseprocessesinorder:first f ,then g ,andfinally h .

Inthe1960s,withthedevelopmentof monoidalcategories,itwasrealizedthat notonlydocategoriescontainstructures,butsometimescategoriesthemselves havestructure.Incertaincasesobjectsandmorphismsofcategoriescanbe “tensored”or“multiplied.”Forexample,given X and X inthecategoryof vectorspaces,onecanformtheirtensorproduct X ⊗ X asanobjectofthe categoryofvectorspaces.Or,if X and X areobjectsinthecategoryofsets, thentheirCartesianproduct, X × X ,isalsoanobjectinthecategoryofsets. Asusualincategorytheory,weareconcernedwithmorphisms.If f : X − Y and f : X − Y aremorphismsthenwecannotonlyform X ⊗ X and Y ⊗ Y

butalso f ⊗ f whichwecanwriteas

f Y ⊗ or X ⊗ X f ⊗ f Y ⊗ Y .

Y

Thisshouldbeconsideredasmodeling parallelprocessing,i.e.,performing the f and f processindependentlyandatthesametime.Acategorywhere onecantensortheobjectsandmorphismsiscalledamonoidalcategory.When the f ⊗ f processisessentiallythesameasthe f ⊗ f process,wecallthe structurea symmetricmonoidalcategory.Mostofthecategorieswewillmeet inthesepageswillbetypesofsymmetricmonoidalcategories.

Letussummarize.Thecategorieswewillusehaveobjectsthataretypes ofdatathatdescribetheinputsandoutputsoffunctionsandprocesses,while themorphismsarethefunctionsortheprocesses.Therewillbetwowaysof composingthemorphisms:(i)regularcompositionwillcorrespondtofunction compositionorsequentialprocessing,and(ii)themonoidalcompositionwill correspondtoparallelprocessingoffunctionsorprocesses.Therewillbe variousfunctorsbetweensuchcategorieswhichtakecomputationalprocedures tofunctionsorothercomputationalprocedures.Wewillaskquestionssuchas: Whenarethesefunctorssurjective?Whatisintheirimage?Whatisnotintheir image?Whenaretheyequivalences?etc.

ThisElementwillnotonlyusethelanguageofcategories,itwillalsousethe mindsetofcategories.Asanyonewhohasstudiedatopicincategorytheory knows,thislanguagehasauniquewayofseeingthings.Ratherthanjumpingin tothenitty-grittydetails,categoristsinsistonsettingupwhattheyaretalking aboutfirst.Theyliketoexaminethelargerpicturebeforegettingintothedetails. Also,categorytheoryhasaknackforgettingtotheessenceofaproblemwhile leavingoutallthedrossthatisrelatedtoasubject.Theoreticalcomputerscience standstogainfromthismindset.

Herearesomeofthetopicsthatwewillmeetinthesepages.Westart offbyconsideringdifferent modelsofcomputation.Theseareformal,virtual machinesthatperformcomputations.Weclassifythemintothreedifferent groupings.Therearemodels,suchas Turingmachines,thatperformsymbol manipulations.Historically,thisisoneofthefirstcomputationalmodels. Therearemodelscalled registermachines thatperformcomputationsthrough manipulatingwholenumbers.Ahand-heldcalculatorisatypeofcomputer thatmanipulatesnumbers.Yetanothercomputationalmodeliscalled circuits andperformsbitmanipulations.Everymoderndigitalelectroniccomputer worksbymanipulatingbits.Andfinally,anotherwayofdescribingcomputation

–whichisnotreallyacomputationalmodel–iswith logicalformulas.For eachofthesetypesofcomputationalmodel,wewilldescribeacategorical structurethatcontainsthemodels.Therearefunctorsfromthecategoriesof modelstothecategoriesoffunctions.Therealsoexistfunctorsbetweenthe categoricalstructuresofmodels.Forexample,ahand-heldcalculatorappears tomanipulatewholenumbers.Infact,whatisreallyhappeningisthatthere isacircuitwhichmanipulatesbitsthatperformsthecalculations.Thisisthe essencebehindafunctorbetweenthecategoricalstructureofregistermachines andthecategoricalstructureofcircuits.

Letuslookattheoreticalcomputersciencefromabroadlyphilosophical perspective.Bythe“syntax”ofafunctionwemeanadescriptionofthefunction suchasaprogramthatimplementsthefunction,acomputerthatrunsthe function,alogicalformulathatcharacterizesthefunction,acircuitthatexecutes thefunction,etc.Bythe“semantics”ofafunctionwemeantherulethatassigns toeveryinputanoutput.Computabilitytheoryandcomplexitytheorystudy therelationshipbetweenthesyntaxandthesemanticsoffunctions.Thereare manyaspectstothisrelationship.Computabilitytheoryaskswhatfunctionsare definedbysyntax,and–moreinterestingly–whatfunctionsare not definedby syntax.Complexitytheoryaskshowcanweclassifyandcharacterizefunctions byexaminingtheirsyntax.

Inacategoricalsetting,therelationshipbetweenthesyntaxandsemantics offunctionsisdescribedbyafunctorfromacategoryofsyntaxtoacategory ofsemantics.Thefunctortakesadescriptionofafunctiontothefunctionit describes.Computabilitytheorythenaskswhatisintheimageofthisfunctor and–moreinterestingly–whatis not intheimageofthefunctor.Complexity theorytriestoclassifyandcharacterizewhatisintheimageofthefunctorby examiningitspreimage.

Letuslookatsomeoftheothertopicswecoveronthesepagesandthe supplement.Diagonalargumentsarerelatedtoself-reference.Abouttwoanda halfthousandyearsago,Epimenides(acantankerousCretanphilosopherwho proclaimedCretansalwayslie)taughtusthatlanguagecantalkaboutitself andisself-referential.Heshowedthatbecauseofthisself-referencethereis acertainlimitationoflanguage(somesentencesaretrueifandonlyifthey arefalse.)Inthelatenineteenthcentury,theGermanmathematicianGeorg Cantorshowedthatsetscanbeself-referentialandBertrandRussellshowed thatonemustrestrictthisabilityorsettheorywillbeinconsistent.Inthe1930s, KurtGödelshowedthatmathematicalstatementscanrefertothemselves(“I amunprovable”)andhencethereisalimitationtothepowerofproofs.We arechieflyinterestedinAlanTuringshowingthatcomputerscanreference themselves(afterall,anoperatingsystemisaprogramdealingwithprograms).

Thisentailsalimitationofcomputers.Diagonalargumentsareusedinsystems withself-referencetofindsomelimitationofthesystem.Wedescribeasimple categoricaltheoremthatmodelsallthesedifferentexamplesofself-reference. Manyresultsoftheoreticalcomputerscienceareshowntobeinstancesofthis theorem.

Formallanguagetheorydealswiththeinterplaybetweenmachinesand languages.Themorecomplicatedamachine,themorecomplicatedisthe languageitunderstands.Withcategories,weactuallydescribeafunctorfrom acategoryofmachinestoacategoryoflanguages.Machinesthatareweaker thanTuringmachinesandtheirassociatedlanguagesareexplored.

Moderncryptographyisaboutusingcomputerstoencryptmessages.While itshouldbecomputationallyeasytoencodethesemessages,onlytheintended receiverofthemessageshouldbeabletodecodewithease.Categorically, wewillusesomeoftheideaswelearnedincomplexitytheorytodiscussa subcategoryofcomputablefunctionscontainingeasilycomputablefunctions. Incontradistinction,someothercomputablefunctionscanbethoughtofas hard.Agoodcryptographicprotocoliswhentheencodinganddecodingare easytocomputeandwherethedecoderishardtofind.Thepowerofcategory theorywillbecomeapparentwhenwemakeasimplecategoricaldefinitionand showthatmostmoderncryptographicprotocolscanbeseenaninstanceofthis definition.

Kolmogorovcomplexitytheoryisconcernedwiththecomplexityofstrings. WeuseTuringmachinestoclassifyhowcomplicatedstringsofcharactersare. Thesectionalsohasadiscussionofthenotionofrandomness.

Algorithmsareatthecoreofcomputerscience.Fromabroadprospective, algorithmsareonthethinlinebetweenthesyntaxandsemanticsofcomputable functions.Thefunctorfromsyntaxtosemanticsfactorsas

Thisviewaffordsusadeeperunderstandingoftherelationshipbetweenprogramming,computerscience,andmathematics.

Thefirstpartof§7isacontinuationofthisIntroduction.Itsummarizeswhat wasdoneinthistextusingtechnicallanguage.Weshowthattherearecertain unifyingthemesandcategoricalstructuresthatmaketheoreticalcomputer sciencemoreunderstandable.Wealsoclosethatsectionwithareader’sguide togoingfurtherwiththeirstudies.

Let’srollupoursleevesandgettowork!

2Aide-MémoireonCategoryTheory

Weassumethebasicsofcategorytheory.Thereaderisexpectedtoknow theconceptofacategory,functor,naturaltransformation,equivalence,limit, etc.Wereviewsomelesswell-knownconceptsofcategorytheory.Anyother requiredcategoricalconstructionswillbereviewedalongtheway.Feelfreeto skipthissectionandreturnasneeded.

2.1SliceCategoriesandCommaCategories

Thesliceandcosliceconstructionsmakethemorphismsofonecategoryinto theobjectsofanothercategory.

Definition2.1. Givenacategory A andanobject a of A,the slicecategory, A/ a ,isacategorywhoseobjectsarepairs ( b, f : b − a ) where b isanobject of A and f isamorphismof A whosecodomainis a .Amorphismof A/ a from ( b, f : b − a ) to ( b , f : b − a ) isamorphism g : b − b of A that makesthefollowingtrianglecommute:

Compositionofmorphismscomesfromthecompositionin A,andtheidentity morphismfortheobject ( b, f : b − a ) isid b .

Example2.2. Someexamplesofaslicecategory:

• Considerthecategory Set.Let bethesetofallrealnumbers.Thecategory Set/ isthecollectionofall -valuedfunctions.

• Letusforeshadowbyshowinganexamplethatwewillseeinourtext.Let Func bethecategorywhoseobjectsaredifferenttypesandwhosemorphisms areallfunctionsbetweentypes.OneofthegiventypesisBoolean, Bool, whichhasthepossiblevaluesof0and1.Then Func/Bool isthecategory whoseobjectsarefunctionsfromanytypeto Bool.Suchfunctionsarecalled decisionproblems andtheywillplayamajorroleinthecomingpages.We alsohaveanotionofamorphismbetweendecisionproblems:

where f and f aredecisionproblemsand g isamorphismfrom f to f . Suchamorphismofdecisionproblemswillbecalleda“reduction.”Themap g isareductionof f to f .Theideabehindareductionisthatifweknow theanswerto f thenwecanalsofindtheanswerto f .Sincethetriangle commutes,tofindtheanswerto f onaninput,simplyevaluatetheinputusing g andthenfindtheanswerusing f .Inotherwords,solving f reducesto solving f .

Exercise2.3. Showthatid a : a − a istheterminalobjectin A/ a .

Exercise2.4. Provethatany f : a − a in A inducesafunctor f∗ : A/ a − A/ a thattakesanyobject g : b − a of A/ a to f ◦ g isin A/ a .

Thedualnotionofaslicecategoryisacoslicecategory:

Definition2.5. Givenacategory A andanobject a of A,the coslicecategory, a /A isacategorywhoseobjectsarepairs ( b, f : a − b) where b isanobject of A and f isamorphismof A withdomain a .Amorphismof a /A from ( b, f : a − b) to ( b , f : a − b ) isamorphism g : b − b of A thatmakes thefollowingtrianglecommute:

Compositionofmorphismscomesfromthecompositionin A,andtheidentity morphismfortheobject ( b, f : b − a ) isid b

Example2.6. Someexamplesofacoslicecategory:

• Considertheoneelementset {∗} .Thecategory {∗}/Set hasobjectsthatare setswithafunctionthatpicksoutadistinguishedelementoftheset.An objectisapair ( S, s0 ) where S isasetand s0 isadistinguishedelementof thatset.Themorphismsfrom ( S, s0 ) to (T , t0 ) aresetfunctionsthatpreserve thedistinguishedelement.Thatis, f : S − T suchthat f ( s0 ) = t0 .Thisis thecategoryofpointedsets.

• Whenwetalkaboutfiniteautomata,wewillgeneralizetheaboveexample.Let FinGraph bethecategoryoffinitegraphsandgraphhomomorphisms.Let 20 bethegraphwithjusttwovertices(named s and t for“source”and“target.”) Then 20 /FinGraph isthecategoryoffinitegraphswithadistinguishedvertex for s andadistinguishedvertexfor t .(Theymightbethesamevertex.)

• Let Prop bethecategoryofpropositionswithatmostonemorphismfrom a to b if a entails b.Let p ∈ Prop beaparticularproposition.Then p/Prop is thecategoryofallpropositionsthatareimpliedby p.

Exercise2.7. Showthatid a : a − a istheinitialobjectin a /A.

Definition2.8. Givenfunctors F : A − C and G : B − C,onecanform the commacategory ( F , G ),sometimeswritten F G .Theobjectsofthis categoryaretriples ( a, f , b) where a isanobjectof A, b isanobjectof B and, f : F ( a ) − G ( b) isamorphismin C.Amorphismfrom ( a, f , b) to ( a , f , b ) in ( F , G ) consistsofapairofmorphisms (g, h ) where g : a − a isin A and h : b − b isin B suchthatthefollowingdiagramcommutes:

Compositionofmorphismscomesfromthefactthatonecommutingsquare ontopofanotherensuresthatthewholediagramcommutes.Theidentity morphismsareobvious.

Example2.9. Someexamplesofcommacategoriesarefamiliaralready.

• If B = 1 and G : 1 − C picksouttheobject c0 and A = C with F = IdC , thenthecommacategory ( F , G ) istheslicecategory C/c0 .

• If A = 1 and F : 1 − C picksouttheobject c0 and B = C with G = IdC , thenthecommacategory ( F , G ) isthecoslicecategory c0 /C.

Inthistext,wewilluseacommacategoryconstructionwith F beinganinclusion functor.Inthiscasethecommacategorywillhaveobjectsofacertaintypeand morphismsfromthesubcategory.Thiswillbeimportantforreductionsofone problemtoanother.

Thereareforgetfulfunctors U1 : ( F , G ) − A and U2 : ( F , G ) − B which aredefinedonobjectsasfollows: U1 takes ( a, f , b) to a and U2 takes ( a, f , b) to b.

Exercise2.10. Showthatifthefollowingtwotrianglesofcategoriesand functorscommute

where C − C isaninclusionfunctor,thenthereisaninclusionfunctor ( F , G ) − ( F , G )

2.2SymmetricMonoidalCategoriesandBicategories

Manyofourcategoriesarecollectionsofprocesseswhere,besidessequentiallycomposingprocesses,wecancomposeprocessesinparallel.Such categoriesareformulatedascategorieswithextrastructure.

Definition2.11. A strictlyassociativemonoidalcategory ora strictmonoidal category isatriple (A, I , ⊗) where A isacategory, I isanobjectin A calleda “unit,”and ⊗ isabifunctor ⊗ : A × A − A calleda“tensor”whichsatisfies thefollowingaxioms:

• ⊗ isstrictlyassociative,i.e.,forallobjects a, b and c in A, ( a ⊗ b)⊗ c = a ⊗( b ⊗ c ), and

• I actslikeaunit,i.e.,forallobjects a in A, a ⊗ I = a = I ⊗ a .

Example2.12. Anymonoid(including ,thenaturalnumbers)canbethought ofasastrictlyassociativemonoidalcategory.Theelementsofthemonoid formadiscretecategoryandtheunitofthemonoidbecomestheunitofthe symmetricmonoidalcategory.Themultiplicationinthemonoidbecomesthe tensorofthecategory.

Intheliterature,thereisaweakerdefinitionofa monoidalcategory.Thisis acategorywherethereisanisomorphismbetween ( a ⊗ b)⊗ c and a ⊗( b ⊗ c ) Theseisomorphismsmustsatisfyhigher-dimensionalaxiomscalleda“coherence conditions.”Whilethisconceptisveryimportantinmanyareasofmathematics, physics,andcomputerscience,itwillnotariseinourpresentation.Thereis atheoremofSaundersMacLanethatsaysthateverymonoidalcategoryis equivalent(inaverystrongway)toastrictmonoidalcategory.Thecategories thatwewillbedealingwithwillhavethenaturalnumbersorsequencesoftypes asobjectsandwillbestrictmonoidalcategories.

Beforewegoon,weneedthefollowingfunctor.Foranycategory A,thereis a“twisting”functor

tw: A × A − A × A (2.6)

thatisdefinedfortwoelements a and b as tw( a, b) = ( b, a ) . Thefunctor tw is definedsimilarlyformorphisms.

Definition2.13. A symmetricstrictlymonoidalcategory or symmetricmonoidal category isaquadruple (A, I , ⊗,γ ) where (A, I , ⊗) isastrictmonoidalcategory and γ isanaturaltransformationthatisanisomorphism γ : ⊗ − (⊗◦ tw),i.e., forallobjects a, b in A,thereisanisomorphism a ⊗ b γ a , b b ⊗ a whichisnaturalin a and b. γ mustsatisfythefollowingcoherenceaxioms:

•thesymmetryaxiom,

•thebraidingaxiom,

This γ iscalleda“braiding.”

Ofcoursewearenotonlyinterestedinsuchsymmetricmonoidalcategories, butinthewaytheyrelatetoeachother.

Definition2.14. A strongsymmetricmonoidalfunctor from (A, I , ⊗,γ ) to (A , I , ⊗ ,γ ) isatriple ( F ,ι, ∇) where F : A − A isafunctor, ι : I − F ( I ) isannaturalisomorphismin A ,and ∇ : (⊗ ◦( F × F )) − ( F ◦⊗) isanatural transformationwhichisanisomorphism.Thatis,forevery a, a in A,thereis anisomorphism ∇ a , a : F ( a )⊗ F ( a ) − F ( a ⊗ a ) naturalin a and a .These naturaltransformationsmustsatisfythefollowingcoherencerules

• ∇ mustcoherewiththebraidings

• ι mustcoherewith ∇

(thereisasimilarcoherencerequirementwith ι and ∇ a , I ;)

• ∇ mustcoherewithitself,i.e.,itisassociative F ( a )⊗ F ( a )⊗ F ( a ) Id ⊗ ∇ a , a

∇ a , a ⊗ Id

( a )⊗ F ( a ⊗ a )

a , a ⊗ a

Wewillalsoneedastrongernotionofafunctor.

Definition2.15. A symmetricmonoidalstrictfunctor from (A, I , ⊗,γ ) to (A , I , ⊗ ,γ ) isafunctor F : A − A where F ( I ) = I and F ( a )⊗ F ( a ) = F ( a ⊗ a );i.e.,the ι and ∇ aretheidentity.

Definition2.16. A symmetricmonoidalnaturaltransformation from ( F ,ι, ∇) to ( F ,ι , ∇ ) isanaturaltransformation μ : F − F ;i.e.,forevery a in A, anaturalmorphism μ a : F ( a ) − F ( a ) whichmustsatisfythefollowing coherenceaxioms:

Someoftheseaxiomswilleasilybesatisfiedwhenwedealwithstrictfunctors.

Giventhenotionofasymmetricmonoidalnaturaltransformation,wecan easilydescribewhatitmeansfortwosymmetricmonoidalcategoriestobe equivalent.

Definition2.17. Thereisa symmetricmonoidalequivalence between (A, I , ⊗,γ ) and (A , I , ⊗ ,γ ) ifthereisasymmetricmonoidalfunctor ( F ,ι, ∇) from A to A andasymmetricmonoidalfunctor ( F ,ι , ∇ ) from A to A withsymmetric monoidalnaturaltransformationswhichareisomorphisms μ :IdA − F ◦ F and μ : F ◦ F − IdA . Asusual,anequivalenceinthiscasemeansthatthe functorisfull,faithful,andessentiallysurjective.

Wewillfindthat,ingeneral,themodelsofcomputationdonotfitneatlyinto thestructureofacategory.Rather,theyformabicategory.Thisisastructure introducedbyJeanBénabouin1967,thatisweakerthanacategory(inthe sensethatitdoesnotsatisfysomeoftheaxiomsofacategory)anditisatype ofhighercategory(therearenotonlyobjectsandmorphisms,butalso2-cells.)

Definition2.18. A bicategory ora weak 2-category B isacollectionof

•Objectsor0-cells a, b, c,...

• Betweentwoobjects,say a and b,therearemorphismsor1-cells f : a − b

Thecollectionofallmorphismsfrom a to b formsacategoryandisdenoted HomB ( a, b)

•Betweentwomorphsims,say f and g ,thereare2-cells f =⇒ g . Furthermore,

•foranythreeobjects, a, b,,and c of B,thereisacompositionfunctor

•forevery b in B,thereisanidentitymorphismid b : b − b.

Ratherthentheusualruleforacategory–thatthecompositionisassociative, andtheidentitiesactlikeaunitforthecomposition–inabicategory,weinsist thattherearethefollowing2-cells.

• Foreverythreecomposablemorphisms f , g, and h in B,thereisan“associator” isomorphic2-cell

whichisnaturalin f , g ,and h .

• Foreverymorphism f : a − b in B therearethefollowingtwo“identity constraints”isomorphic2-cells:

These2-cellsmustsatisfyarulelikethepentagoncoherenceconditionofa monoidalcategoryaswellasacoherenceconditionthatshowsthatassociators coherewiththeidentityconstraints.

Noticethateverycategoryisatypeofbicategorywhereallthe2-cells (includingtheassociatorsandtheidentityconstraints)areidentity2-cells.There arenonon-trivial2-cells.

Onecanformulatethenotionofafunctorbetweentwobicategories.The functorhastorespecttheassociatorandidentityconstraints(perhapsuptoa 2-cell).Wewillnotneedthisbecause,forthemostpart,wewilldealwith functorsfromabicategorytoacategory(whichonlyhastrivial2-cells).This entailsthatmostofthecoherenceconditionswilleasilybesatisfied.

Onethenproceedstodiscussa monoidalbicategory,a braidedmonoidal bicategory,a symmetricmonoidalbicategory,andappropriatefunctorsbetween them.Thisbringsupagiantmorassofcoherenceconditions.Essentially,the symmetricmonoidalstructurehastocoherewiththestructureofthebicategory. Ratherthangettingboggeddownbylistingallthecoherenceconditions,we focusonthewhattheweakcategoriescontainandpointtotheliteratureatthe endofthissectiontolearnmore.

ResearchProject2.19. Symmetricandbraidedmonoidalcategoriesand bicategorieswerefirstformulatedtodealwithtopicsingeometryandphysics. Itwouldbenicetounderstandwhythesestructuresariseinthosefields.With thisknowledgetohand,whileyoureadthistext,seehowthesecategorical

structureswhichconsistofcomputablefunctionsandthevariousmodelsof computationfitinwiththegeometricandphysicalideas.Doesthegeometric andphysicalnotionshaveanythingtosayaboutcomputablefunctionsormodels ofcomputation?Dothestructuresthatwemeetinthistexthaveanythingto contributetoourunderstandingofgeometryorphysics?

FurtherReading

ThenotionsofasliceandcommacategoriescanbefoundinSectionII.6of MacLane(1998)andpages3,13,and47ofBarrandWells(1985).Symmetric monoidalcategoriescanbefoundinChapterXIofMacLane(1998)and ChaptersXI–XIVofKassel(1995).BicategoriescanbefoundinBénabou (1967),theoriginalpaper,Leinster(1998),andSection9ofStreet(1996). Braidedmonoidalbicategoriesandsymmetricmonoidalbicategoriescanbe foundinGurski(2011),Shulman(2010),andsourcestherein.

3ModelsofComputation

Sincewearegoingtodealwiththequestions“Whichfunctionsarecomputable?”and“Whichfunctionsareefficientlycomputable?”webetterfirst dealwiththequestion“Whatisacomputation?”Weallhaveaprettygood intuitionthatacomputationisaprocessthatacomputerperforms.Computer scientistshavegivenother,moreformal,definitionsofacomputation.They havedescribeddifferentmodelswherecomputationsoccur.Thesemodelsare virtualcomputersthatareexactandhaveafewsimplerules.Inmosttextbooks, onecomputationalmodelisemployed.Ascategorytheorists,wehavetolook atseveralmodelsandseehowtheyarerelated.Thisaffordsusamoreglobal viewofcomputation.

3.1TheBigPicture

WehaveunitedallthedifferentmodelsthatwewilldealwithinFigure 3.1 Warning:thisfigurecanlookquiteintimidatingthefirsttimeyourseeit.Fear notdearreader!Wewillspend§§3.1,3.2,3.3,and3.4explainingthisdiagram andmakingitdigestible.Wecallthediagram TheBigPicture.Ithasacenter andthreespokescomingoutofit.Thesewillcorrespondtodifferentwaysof modelingcomputations.Mostoftherestofthistextwillconcentrateonthe topspokewhichisconcernedwithperformingcomputationsbymanipulating strings.

Tomake TheBigPicture lessintimidating.Allthecategoriesareessentially

TotTuring Turing

TotCirc Circ TotRegMach RegMach

Figure3.1 “TheBigPicture”offunctionsandmodelsofcomputation symmetricmonoidalcategories.Allthefunctorsareessentiallysymmetric monoidalfunctors.Allhorizontalarrowsareinclusionfunctorswhicharethe identityonobjects.Almosteverycategorycomesintwoforms:(i)allthe possiblemorphismswhichincludemorphismsthatrepresentpartialfunctions, –thatisfunctionsthatdonothaveoutputsforcertaininputs;and(ii)the subcategoryoftotalmorphisms,i.e.,morphismswhereeveryinputhasan output.Thediagramhasacentrallineconsistingofdifferenttypesoffunctions thatthemodelsofcomputationcompute.Thislinewillbeourfocus.Thereare threespokespointingtothatline.Thesecorrespondtothreetypesofmodelsof computation:(i)thetopspokecorrespondstomodelsthatmanipulatestrings; (ii)thelowerrightspokecorrespondstomodelsthatmanipulatenaturalnumbers; and(iii)thelowerleftspokecorrespondstomodelsthatmanipulatebits.

Inallthesecategories,thecompositioncorrespondstosequentialprocessing (thatis,performingoneprocessafteranother).Themonoidalstructurecorrespondstoparallelprocessing.Thesymmetricmonoidalstructurecorresponds tothefactthattheorderinparallelprocessingiseasilyinterchanged.

TotCompString CompString
TotCompFunc CompFunc Func
TotCompBool CompBool TotCompN CompN

Weneedalittlediscussionabouttypes.Everyfunctionandeverycomputationaldevicetakesinputsandreturnsoutputs.Inordertokeeptrackofall thedifferentfunctionsweusuallydescribetheinputandoutputastypes.There are basictypes suchas Nat, Int, Real, Char, String,and Bool whichcorrespond tonaturalnumbers,integers,realnumbers 1 ,characters,stringsofcharacters, andBooleans(0and1).Usingthesewecandescribesimplefunctions.

Example3.1. Someexamplesoffunctionswithbasictypes.

• – : Real − Int istheceilingfunctionthattakesarealnumberandoutputs thesmallestintegerequalorgreaterthanit.

•Prime: Nat − Bool isafunctionthattakesanaturalnumberandoutputsa1 ifthenumberisaprimeand0otherwise.

•Beautiful: String − Nat takesastringofcharacters(tobethoughtofasa poem)andoutputsanintegerfrom1to10determinedbythebeautyofthe poem.Thisisnotobjective(“Beautyisintheeyeofthebeholder”)soitis probablynotreallyafunction.Andevenifyoubelievethatbeautyisobjective, itisprobablynotcomputable.Youmightgetacomputertoimitateabelief thatmosthumanshave,butthatdoesnotmeanthecomputerisjudgingitwith acomparativeaestheticexperience.

Exercise3.2. Describethetypesoftheinputsandoutputsofthefollowing functions.

•Afunctionthatdeterminesthelengthofastringofcharacters.

• Afunctionthattakesanaturalnumberandoutputsawrittendescriptionof thatnumber.Forexample42 − “forty-two”.

• Afunctionthattakesacomputerprogramanddetermineshowmanylinesof codethereareintheprogram.

Basictypesarenotenough.Weneedoperationsontypestoformothertypes.

• Listtypes:Givenatype T ,wecanform T ∗ whichcorrespondstofinitelists ofelementsoftype T .Forexample, Bool∗ isthetypeoflistsofBooleansand Nat∗ correspondstofinitelistsofnaturalnumbers.

• Functiontypes:Giventypes T1 and T2 ,weformtype Hom(T1, T2 ) = T T1 2 . Thistypecorrespondstofunctionsthattakeinputsoftype T1 andoutput T2 types.

• Producttypes:Giventypes T1 and T2 ,weformtype T1 × T2 .Thistypewill correspondtopairsofelements,thefirstoftype T1 andthesecondoftype

1 Finitecomputerswithfinitememorycannotdealwitharbitrarylargenaturalnumbersor integers.Theyalsodonotdealwitharbitraryrealnumbers.Wewillnotbebotheredwiththisissue andpermitnumbersofanysizeandprecisionwhenworkingwithourmodels.

T2 .Whenthereisatupleoftypes,wewillcallthema sequenceoftypes. Forexample Seq = Nat × String × Bool or Seq = Float × CharNat × Nat∗ × Int. Giventwosequencesoftypes,wecanconcatenatethem.Forexamplethe concatenationof Seq and Seq is

Seq × Seq = (Nat × String × Bool)×(Float × CharNat × Nat∗ × Int) = Nat × String × Bool × Float × CharNat × Nat∗ × Int .

Foratype T ,weshorten T × T as T 2 and T × T × T as T 3 .Ingeneral T n willbeasequenceof n lotsof T .Thetype T 0 wetaketomean ∗ whichis calledtheterminaltype.Itisusedtopickoutanelementofanothertype.A function f : ∗ − Seq picksoutanelementoftype Seq.

Example3.3. Hereareafewfunctionsthatusecompoundtypes:

•DayOfWeek: String × Nat × Nat − Nat isafunctionthattakesadateasthe nameofthemonth,thedayofthemonth,andtheyear.Thefunctionreturns thedayoftheweek(1,2,...,7)forthatdate.

•Comp: T T2 3 × T T1 2 − T T1 3 isafunctionthatcorrespondstofunctioncomposition.Ittakesan f : T1 − T2 anda g : T2 − T3 andoutputs g ◦ f : T1 − T3 .

•Inverse: T T1 2 − T T2 1 takesafunctionandreturnstheinverseofthefunction (ifitexists).Thiswillariseinourdiscussionofcryptography.

Exercise3.4. Describethefollowingasfunctionsfromsequencesoftypesto sequencesoftypes.

• Afunctionthattakesalistofnaturalnumbersandreturnsthemaximumof thenumbers,themeanofthenumbers,andtheminimumofthenumbers.

• Afunctionthattakes(i)afunctionfromthenaturalnumberstothenatural numbers,and(ii)anaturalnumber.Thefunctionshouldevaluatethegiven functiononthenumber.

• Afunctionthattakestwonaturalnumbersanddeterminesiftheyarethelast twinprimes.Thatis,(i)bothnumbersareprime,(ii)theyareoftheform n and n + 2,and(iii)therearenogreatertwinprimes.

Therearemuchmorecomplicatedtypesthatareneededtodescribealltypes offunctions.Thereare“coproducttypes”andthingscalled“dependenttypes.” However,wewillnotusetheminourpresentation.

AdvancedTopic3.5. Thesetypesarethebeginningofseveralareasoftheoreticalcomputerscience. Typetheory studiescomplicatedtypesandhowthey relatetocomputation.Italsoworkswithhigher-orderlogicswhichcanfunction asafoundationforallofmathematics.Categorytheoristshavebeenmaking

categoriesoftypesandlookingatalloftheirpossiblestructures(seeAsperti andLongo,1991;BarrandWells,1999.)Thisisalsorelatedto λ -calculus or lambdacalculus whichisanotherwayofdescribingcomputations(seeLambek andScott,1986.)Thetheoryoftypesisalsothebeginningofacurrent,veryhot areaofresearchcalled homotopytypetheory.Thishasalltypesofconnections tofoundationsofmathematicsandproofcheckers(seeUnivalent,2013.)

Nowthatwehavethelanguageoftypesdownpat,letusmoveontoourmost importantdefinition.

Definition3.6. Thecategory Func consistsofallfunctions.Theobjectsare sequencesoftypes.Themorphismsin Func from Seq to Seq areallfunctions thathaveinputsfromtype Seq andoutputsoftype Seq .Wepermitallfunctions includingpartialfunctionsandfunctionsthatcomputerscannotcompute.The identityfunctionsareobvious.Compositioninthecategoryissimplyfunction composition.Forexample,if f : Seq1 − Seq2 and g : Seq2 − Seq3 are twofunctions,then g ◦ f : Seq1 − Seq3 istheusualcomposition.The categoryalsohasamonoidalstructure.Onobjects,themonoidalstructureis concatenationorproductofsequencesoftypes.Given f : Seq1 − Seq2 and g : Seq3 − Seq4 ,theirtensorproductis

whichcorrespondstoperformingbothfunctionsinparallel.Whilethemonoidal productisnotstrictlyassociative,thankstogeneralcoherencetheory,wewill thinkof Func asastrictlyassociativemonoidalcategory.Thesymmetric monoidalstructurecomesfromthetrivialfunctionthatswapssequencesof types,i.e.,tw: Seq × Seq − Seq × Seq.Weleavethedetailstothereader.

Exercise3.7. Whatistheunitofthesymmetricmonoidalcategorystructure?

Exercise3.8. Showthatthefunction tw satisfiestheaxiomsmaking Func into asymmetricmonoidalcategory.

Definition3.9. Thecategoryofallcomputablefunctions,called CompFunc, isasymmetricmonoidalsubcategoryof Func whichhasthesameobjects.The morphismsofthissubcategoryarefunctions(includingpartialfunctions)thata computercancompute.Acomputercancomputeapartialfunctionifforany inputforwhichthereisanoutput,thecomputerwillgivethatoutput,andif thereisnooutput,thecomputerwillgivenooutputandmightgointoaninfinite loop.Inasense,alargepartoftheoreticalcomputerscienceisdedicatedto givinganexactdefinitionofthissubcategoryof Func.

Thereisafurthersymmetricmonoidalsubcategory TotCompFunc which containsallthetotalcomputablefunctions.Thesearefunctionsforwhichevery inputhasanoutputandacomputercancomputethefunction.

Both CompFunc and TotCompFunc havesymmetricmonoidalcategory structuressimilarto Func.Thereareobvioussymmetricmonoidalinclusion functors

whicharetheidentityonobjects.

Example3.10. Hereareafewexamplesoffunctionsandthecategoriesto whichtheybelong.

•Det n : (Real n ) n − Real isthedeterminantofan n × n matrix.(Notice thatforeach n thereisadeterminantfunction.Todescribethedeterminant functionforallsquarematrices,wewouldneed dependenttypes.)This functionistotalandcomputable.

•Sqrt: Real − Real takesarealnumberandreturnsitspositiverealsquare root.Thisisacomputablepartialfunctionandhenceisin CompFunc.By theway, ±√ : Real − Real × Real takesarealnumbertoitspositiveand negativerealrootsandisalsoin CompFunc.

•Der: RealReal − RealReal ,thederivativefunctionisonlypartiallycomputable.Theinputfunctionmustbedifferentiable.Thereisalsotheintegral functionwhichisroughly Int: RealReal − RealReal andisalsoin CompFunc Thefundamentaltheoremofcalculusessentiallysaysthat Der istheinverse ofInt,thatis,Der ◦ Int = Id = Int ◦ Der.

Exercise3.11. Whichcategorydothefollowingfunctionsbelongto?

•Matrixmultiplication ∗ : (Real m ) n ×(Real n ) p − (Real m ) p

•Empty: String − Bool.Thefunctionthatdeterminesifaprogramstopson anyinput,oralwaysgoesintoaninfiniteloop.Thatis,takeaprogramand seeifthedomainoftheprogramisempty(seeExample4.12.)

• : Nat × Nat − Nat.Thenaturalnumbersubtractionwhichisdefinedas x . y = x y if x ≥ y and0otherwise.

InDefinition3.9wedescribedcomputablefunctionsasfunctions“thata computercancompute.”Theobviousquestioniswhattypeofcomputerare wediscussing?Whatcomputerprocessislegitimate?Thissectionwillgive severalanswerstothatquestion.

3.2ManipulatingStrings

TotCompFunc CompFunc Func (3.2)

Definition3.12. Thecategory CompString isthesubcategoryof CompFunc thatdealswithfunctionsfromstringstostrings.Theobjectsarepowersof String types.Thismeanstheobjectsare String0 = ∗ (whichistheterminaltype), String1 = String, String2 = String × String, String3 = String × String × String,... . Themorphismsofthiscategoryarecomputablefunctionsbetweenpowers of String types.Therearepartialfunctionsinthiscategory.Thesymmetric monoidalstructureissimilarto Func.

Thesubcategory TotCompString hasthesameobjectsas CompString but withonlytotalcomputablestringfunctions.Thereisanobvioussymmetric monoidalinclusionfunctor TotCompString − CompString.

Thesymmetricmonoidalinclusionfunctor

Inc: CompString − CompFunc

takes String n in CompString tothesameobjectin CompFunc.Everycomputablestringfunction f : String m − String n in CompString goestothesame functionin CompFunc.Thefunctor, Inc,isinjectiveonobjectsandisfulland faithful.But,aswewillpresentlysee, Inc ismorethanjustaninclusionfunctor.

Thesymmetricmonoidalfunctor

: CompFunc − CompString (3.3) takesanarbitraryobjectof CompFunc,e.g. Seq,to F (Seq) = String m ,for some m .Theideaisthateverysequenceoftypescanbeencodedasapower of String.Thefunctor F willtakecomputablefunction f : Seq − Seq to F ( f ) : String m − String n whichisacomputablefunctionthattakesencoded dataoftheinputof f toencodedoutputof f .Inotherwords, F insuresthatall computablefunctionscanbeencodedasacomputablefunctionbetweenpowers of String.

Whatistherelationshipbetween F and Inc?Sinceeverypowerof String shouldbeencodedasitself,i.e., F (String m ) = String m ,wehave

Bycontrast,ingeneral,

Eventhoughthesetwofunctorsarenotequal,thereisanaturaltransformation

Foreverysequence Seq in CompFunc,wehave EncSeq : Seq − (Inc ◦ F )(Seq) orEncSeq : Seq −

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.
Download pdf Theoretical computer science for the working category theorist noson s. yanofsky full c by roymendez3835 - Issuu