Surveys and Tutorials in the Applied Mathematical Sciences Volume 11 AdvisoryEditors MichaelBrenner,SchoolofEngineering,HarvardUniversity,Cambridge,USA GáborCsányi,EngineeringLaboratory,UniversityofCambridge,Cambridge,UK Lakshminarayanan Mahadevan, School of Engineering, Harvard University, Cambridge,USA ClarenceRowley,MAEDepartment,PrincetonUniversity,Princeton,USA AmitSinger,FineHall,PrincetonUniversity,Princeton,USA JonathonD.Victor,WeillCornellMedicalCollege,NewYork,USA Rachel Ward, Dept of Mathematics, Office 10.144, University of Texas at Austin, Austin,USA SeriesEditors AnthonyBloch,DeptofMathematics,2074EastHall,UniversityofMichigan,Ann Arbor,MI,USA Charles L. Epstein, Dept of Mathematics, Rm 4E7, University of Pennsylvania, Philadelphia,PA,USA AlainGoriely,Mathematics,UniversityofOxford,Oxford,UK L. Greengard, Department of Mathematics, Courant Institute of Mathematical Sciences,NewYorkUniversity,NewYork,NY,USA Featuring short books of approximately 80-200pp, Surveys and Tutorials in the Applied Mathematical Sciences (STAMS) focuses on emerging topics, with an emphasisonemergingmathematicalandcomputationaltechniquesthatareproving relevant in the physical, biological sciences and social sciences. STAMS also includesexpositorytextsdescribinginnovativeapplicationsorrecentdevelopments inmoreclassicalmathematicalandcomputationalmethods. Thisseriesisaimedatgraduatestudentsandresearchersacrossthemathematical sciences.Contributionsareintendedtobeaccessibletoabroadaudience,featuring clearexposition,alivelytutorialstyle,andpointerstotheliteratureforfurtherstudy. In some cases a volume can serve as a preliminary version of a fuller and more comprehensivebook. Clara Löh Exploring Formalisation A Primer in Human-Readable Mathematics in Lean 3 with Examples from Simplicial Topology Clara Löh Fakultät für Mathematik Universität Regensburg Regensburg, Germany ISSN 2199-4765 ISSN 2199-4773 (electronic) Surveys and Tutorials in the Applied Mathematical Sciences ISBN 978-3-031-14648-0 ISBN 978-3-031-14649-7 (eBook) https://doi.org/10.1007/978-3-031-14649-7 Mathematics Subject Classification (2020): 68V20, 68V15, 55U10, 18A99, 55N35, 55P65 © The Editor(s) (if applicable) and The Author(s), under exclusive license to Springer Nature Switzerland AG 2022 This work is subject to copyright. All rights are solely and exclusively licensed by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use. The publisher, the authors, and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations. This Springer imprint is published by the registered company Springer Nature Switzerland AG The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland Contents Introduction 1 1 The Lean Proof Assistant 7 1.1 Proof Assistants 8 1.2 Foundations 9 1.3 Types 10 1.4 Proofs 12 1.E Exercises 18 2 Basic Examples 21 2.1 Injectivity and Surjectivity of Maps 22 2.1.1 Pen-and-Paper 22 2.1.2 Lean 24 2.2 Induction 31 2.2.1 Pen-and-Paper 32 2.2.2 Lean 32 2.2.3 LeanwithSums 34 2.3 Commutators 37 2.3.1 Pen-and-Paper 37 2.3.2 Lean 38 2.4 The Real Zero 40 2.4.1 Pen-and-Paper 40 2.4.2 Lean 41 2.4.3 LeanwithLimits 44 2.E Exercises 46 v vi Contents 3 Design Choices 49 3.1 Recurring Design Options 50 3.1.1 TypesandSets 50 3.1.2 StructuresandProperties 50 3.1.3 RestrictiveTypesandCuttingCorners 51 3.1.4 ConstructingExamplesandEvaluation 51 3.2 Simplicial Complexes 52 3.2.1 Pen-and-Paper 52 3.2.2 Lean 54 3.3 Simplicial Maps 58 3.3.1 Pen-and-Paper 58 3.3.2 Lean 60 3.4 Finite Simplicial Complexes 67 3.4.1 Pen-and-Paper 67 3.4.2 Lean 67 3.5 Generating Simplicial Complexes 72 3.5.1 Pen-and-Paper 72 3.5.2 Lean 75 3.6 Combining Simplicial Complexes 78 3.6.1 Pen-and-Paper 79 3.6.2 Lean 80 3.7 The Euler Characteristic 83 3.7.1 Pen-and-Paper 83 3.7.2 Lean 85 3.8 Towards a Library 89 3.8.1 InteractionwithOtherLibraries 89 3.8.2 Completeness 89 3.8.3 SubstructuresandQuotients 90 3.8.4 Generality 91 3.E Exercises 92 4 Abstraction and Prototyping 97 4.1 Direct Formalisation: Functorial Semi-Norms 98 4.1.1 Pen-and-Paper 98 4.1.2 Lean 100 4.2 Indirect Formalisation: Amenable Multiplicity 112 4.2.1 Pen-and-Paper 112 4.2.2 Abstraction 115 4.2.3 Lean 120 4.E Exercises 136 Bibliography 137 Index 143 Introduction Proof assistants allow us to formalise mathematical de(cid:12)nitions, examples, theorems, and proofs, and to verify these proofs. The key feature of such a formalisation is the associated machine-checkable guarantee for correctness of proofs. The formalisation of mathematics in a proof assistant also has the following bene(cid:12)ts: • Implementing mathematics requires a very thorough understanding of the subject and all corner cases. Therefore, a successful formalisation leads to a better knowledge of the details. • Aformalisationinaproofassistantcanleadtoexecutablecodeandthus provides the opportunity to run experiments on concrete examples. • Proof assistants encourage abstraction. It is often easier to formalise concepts declaratively through universal properties instead of through concrete, potentially cumbersome, constructions. This can lead to a clearer view on core issues and ideas. • Interacting with a proof assistant is fun. And addictive. Allofthesebene(cid:12)tsarenotonlyvaluableforresearch,butalsoinateach- ing setting: A better understanding of details can increase the awareness for potentialpitfalls,short-cutsthatmightnotbeobvioustonovicesinthe(cid:12)eld, andotherstrugglesofstudents.Ifstudentslearnbasicprooftechniquesviaa proofassistant,theycanobtainimmediatefeedback[52]andcanexperiment withproofsandexamples.Moreover,studentscanseeinmorepracticalterms how abstractions simplify mathematical life. These notes are an extended version of the material for the seminar ProofLab: Simplicial Topology at Universit(cid:127)at Regensburg in WS 2021/22. 1 2 Introduction The goal of this seminar was to learn the basics of formalising mathematics in a proof assistant. In addition to basic examples from (cid:12)rst-year mathemat- ics, as our sample theory we chose simplicial topology, which is a higher- dimensional version of graph theory. For the implementation we used the Lean3proofassistantandthe mathliblibrary,whichcoversasigni(cid:12)cantpart of undergraduate mathematics. The focus of this seminar was to (cid:12)nd straightforward formalisations that lead to human-readable machine-veri(cid:12)able proofs. While some of the chal- lengesarespeci(cid:12)ctosimplicialcomplexesandLean,mostofthemaregeneric and will also occur with other (cid:12)elds and other proof assistants. These notes are not a comprehensive treatment of the full programming language Lean and the underlying dependent type theory. Instead, we study thetransitionbetweenpen-and-papermathematicsandthemachinecounter- partaswellasthedesignoptionsinthisprocess.Thisisillustratedwithvar- ious examples, proceeding in three stages: Examples from (cid:12)rst year courses, examples from simplicial topology, and recent sample results from algebraic and geometric topology. Overview of these notes • Chapter1Westartwithaquickintroductiontoproofassistantsandto Lean in particular. This requires a basic understanding of the founda- tions of mathematics, i.e., how objects, statements, and proofs can be described in a formal language. In particular, this includes the ability to assemble and disassemble logical statements. • Chapter 2 We then consider a (cid:12)rst selection of simple examples: In- jectivity and surjectivity of maps, induction and sums over (cid:12)nite sets, commutatorsingrouptheory,andafundamentalpropertyofrealnum- bers. We always follow the same structure: We (cid:12)rst develop a pen-and- paper version and then formalise it in Lean. The examples are chosen in such a way that basic proof patterns occur. The later examples also illustrate the interaction with the mathlib library. • Chapter 3 As a larger example theory, we consider basic concepts and examples from simplicial topology. We formalise simplicial complexes, simplicial maps, and the Euler characteristic. During this formalisa- tion, we discuss typical design questions and experiment with concrete examples. • Chapter 4 Finally, we consider situations from recent research in al- gebraic and geometric topology. These serve as examples of how proof assistants encourage abstraction and thus can lead to interesting per- spectives. PrerequisitesItriedtokeepthingsassimpleaspossible.Onthemathemati- calside,basicexperiencewithproofsandlogicalformulaeaswellaswithbasic Introduction 3 mathematical objects (e.g., sets, maps, groups, reals) is required. Chapter 4 uses basic terminology on categories and functors; Section 4.2 is probably a bit mysterious without background knowledge in basic algebraic topology (fundamental groups, universal coverings, cohomology, CW-complexes), but the formalisation strategy will be understandable without knowing the se- mantics of these notions. Ontheprogrammingside,acquaintancewithbasicprogrammingconcepts ishelpful(e.g.,declarations,types,basiccontrolstructures,recursion).Prior exposure to the functional programming paradigm is a bonus. ExercisesEachchapterendswithaselectionofexercisesaroundtheformali- sation of mathematical terminology, theorems, and proofs. Skeleton (cid:12)les and solutions to selected exercises of Chapter 2 and Chapter 3 are provided in the git repository: Source code All source code discussed in these notes is available in a git repository: https://gitlab.com/polywuisch/exploring-formalisation Errata Comments and corrections for these notes can be submitted by email to [email protected]; errata will be collected at https://loeh.app.uni-regensburg.de/exploring-formalisation Further reading These notes are merely a primer in the formalisation of mathematics. To get a deeper understanding of proof assistants and formal- isation it is highly recommended to dive into the literature, tutorials, and larger formalisation projects. • J. Avigad, L. de Moura, S. Kong. Theorem Proving in Lean, Re- lease3.23.0,https://leanprover.github.io/theorem proving in lean/,2021. • J. Avigad, K. Buzzard, R.Y. Lewis, P. Massot. Mathematics in Lean. https://leanprover-community.github.io/mathematics in lean/ • A. Baanen, A. Bentkamp, J. Blanchette, J. H(cid:127)olzl, J. Limperg. The Hitchhiker’sGuidetoLogicalVeri(cid:12)cation,2021StandardEdition,2021. https://cs.brown.edu/courses/cs1951x/static (cid:12)les/main.pdf • Y. Bertot, P. Cast(cid:19)eran. Interactive Theorem Proving and Program De- velopment. Coq’Art: The Calculus of Inductive Constructions, Texts in Theoretical Computer Science, An EATCS Series, Springer, 2004. • K. Buzzard, J. Commelin, P. Massot. Lean perfectoid spaces. https://leanprover-community.github.io/lean-perfectoid-spaces/ • K. Buzzard, M. Pedramfar. The natural number game. https://www.ma.imperial.ac.uk/∼buzzard/xena/natural number game/