Implementing Reflection in Nuprl
Total Page:16
File Type:pdf, Size:1020Kb
IMPLEMENTING REFLECTION IN NUPRL A Dissertation Presented to the Faculty of the Graduate School of Cornell University in Partial Fulfillment of the Requirements for the Degree of Doctor of Philosophy by Eli Barzilay January 2006 c 2006 Eli Barzilay ALL RIGHTS RESERVED IMPLEMENTING REFLECTION IN NUPRL Eli Barzilay, Ph.D. Cornell University 2006 Reflection is the ability of some entity to describe itself. In a logical context, it is the ability of a logic to reason about itself. Reflection is, therefore, placed at the core of meta-mathematics, making it an important part of formal reasoning; where it revolves mainly around syntax and semantics — the main challenge is in making the syntax of the logic become part of its semantic domain. Given its importance, it is surprising that logical computer systems tend to avoid the subject, or provide poor tools for reflective work. This is in sharp contrast to the area of programming languages, where reflection is well researched and used in a variety of ways where it plays an central role. One factor in making reflection inaccessible in logical systems is the relative difficulty that is immediately encountered when formalizing syntax: dealing with formal syntax means dealing with structures that involve bindings, and in a logical context it seems natural to use the same formal tools to describe syntax — often limiting the usability of such formalizations to specific theories and toy examples. G¨odelnumbers are an example for a reflective formalism that serves its purpose, yet is impractical as a basis for syntactical reasoning in applied systems. In programming languages, there is a simple yet elegant strategy for imple- menting reflection: instead of making a system that describes itself, the system is made available to itself. We name this direct reflection, where the representation of language features via its semantics is actually part of the semantics itself — unlike the usual practice in formal systems of employing indirect reflection. The advan- tages of this approach is the fact that both the system and its reflected counterpart are inherently identical, making for a lightweight implementation. In this work we develop the formal background and the practical capabilities of an applied system, namely Nuprl, that are needed to support direct reflection of its own syntax. Achieving this is a major milestone on the road for a fully reflected logical system. As we shall demonstrate, our results enable dealing with syntactical meta-mathematical content. BIOGRAPHICAL SKETCH Eli Barzilay was born in Israel in the summer of 1970. In 1980 a coincidence made him switch from Astrophysics to Computer Science as his destination. In 1991 he began his academic education in the Mathematics department of Ben-Gurion University, earning a Bachelor of Science in 1994 and a Master of Science in 1997. At that same year he moved to Ithaca, NY, and began a long chapter of his life that ends in this text. In March 2005 he sat down in front of a blank Emacs screen and typed this paragraph. iii For my father, and for Tali. iv ACKNOWLEDGEMENTS I would like to thank my advisor, Robert Constable, for being able to work on an exciting topic; members on my committee, Greg Morrisett, who provided many enjoyable hours of PL flames, and Barry Perlus for opening my eyes in the digital sense; Stuart Allen, who spent months and years working with me; Aleksey Nogin, who provided motivation in both early and late stages of my work. I also thank the Nuprl group as a whole, who provided extensive feedback during many PRL seminars, and off-line discussions. This work was supported by the DoD Multi- disciplinary University Research Initiative (MURI) program administered by the Office of Naval Research under Grant #N00014-01-1-0765, and NSF Innovative Programming technology for embedded systems #CCR-0208536. But most of all I thank my wife, Regina, who deserves more than these words. v TABLE OF CONTENTS 1 Introduction 1 1.1 Reflection and Art . 4 1.2 Accomplishments . 5 1.3 Outline . 7 2 The Scope of Reflection 12 2.1 Reflection Applied to General Languages . 12 2.2 Reflection in Formal Languages . 17 2.3 Case Study: (Pure) Scheme and Nuprl . 23 2.3.1 Syntax . 24 2.3.2 Semantic Values . 26 2.3.3 Evaluation . 28 2.3.4 Quotations (Representations) . 30 2.3.5 Reflection . 33 2.4 Quasi-Quotations . 34 2.5 Exposing Internals vs. Re-Implementation . 37 2.5.1 Re-Implementation . 37 2.5.2 Exposing Internals . 39 2.5.3 Duplicating Information Considered Harmful . 43 3 Implementing Quotation 45 3.1 Syntactic Sequence Notation . 45 3.2 Nuprl Terms . 46 3.2.1 Term Structure . 47 3.2.2 Interaction . 50 3.2.3 Substitution . 52 3.2.4 Term Meaning: Evaluation . 53 3.3 Syntax Representation Options . 55 3.3.1 Quotation Context . 57 3.3.2 Black-Box Quotations . 58 3.3.3 Using Standard Type Definitions . 59 3.3.4 Operator Shifting . 61 3.3.5 Quasi-Quotations . 62 3.3.6 Using Preprocessing . 63 3.3.7 Operator Shifting and Quasi-Quotations . 66 3.4 Operator Shifting Options: Dealing with Bindings . 68 3.4.1 Concrete Bindings . 71 3.4.2 Abstract Bindings . 73 3.5 Technical Details . 74 3.5.1 The ‘rquote’ Parameter . 75 3.5.2 Display Enhancements . 76 vi 3.5.3 Display Forms . 77 3.5.4 Quote-Related Functionality . 85 3.5.5 Reflection Theory . 86 3.6 Usage Sample . 86 4 Semantics of Shifted Terms 89 4.1 Brief Review . 89 4.2 Semantics of Shifted Operators . 91 4.3 Term Definition . 93 4.4 Operations, Assumptions, and Facts . 94 4.4.1 Important Assumptions and Facts . 95 4.5 Definitions of Shifted Operators . 98 4.6 Defining ‘is subst’...........................102 4.6.1 The ‘is subst’ Rule . 104 4.6.2 Justifying the ‘is subst’ Rules . 105 4.7 Relations to HOAS Work . 110 4.7.1 HOAS Problems . 115 4.7.2 Survey of Proposed Solutions . 116 4.7.3 Nominal Techniques . 120 4.7.4 Comparison with the Nuprl Solution . 125 4.8 Conclusion . 127 5 Formalizing Representation 130 5.1 Design Constraints for a Representation Relation . 130 5.2 Definitions, Facts, and Proofs . 131 5.2.1 Term type ............................131 5.2.2 Atom type............................131 5.2.3 RepsFormation relation constructor . 131 5.2.4 RepsFormation monotonic . 132 5.2.5 RepsFormation fixpoint . 132 5.2.6 reps relation . 132 5.2.7 reps induction . 133 5.2.8 reps is RepsFormation fixpoint . 133 5.2.9 reps closed . 134 5.2.10 reps evaluates . 134 5.2.11 reps unique . 134 5.2.12 reps squiggle . 136 5.2.13 mkSubstFunc constructor . 140 5.2.14 mkSubstFunc generates substitutions . 140 5.2.15 mkTerm constructor . 141 5.2.16 sizeof operator . 142 5.2.17 alpha-renaming preserves size . 142 5.2.18 SubstFunc is mkSubstFunc or a projection . 143 5.2.19 Zero size is projection . 149 vii 5.2.20 Positive size is mkSubstFunc . 150 5.2.21 SubstFunc induction . 151 5.2.22 SubstFunc recursion . 153 5.2.23 q — quotation function . 154 5.2.24 q represents atoms . 156 5.2.25 q represents substitutions . 156 5.2.26 q is a representation . 158 5.2.27 Upward HOAS . 159 5.2.28 unq — unquotation function . 160 5.2.29 unq inverse of q . 161 6 Applying Reflection 163 6.1 Motivating Example . 163 6.2 Extended Syntactic Notation . 164 6.3 The ‘reflection’ theory . 168 6.3.1 term part . 168 6.3.2 is subst part . 168 6.3.3 term eq part . 170 6.3.4 TermAuto part . 170 6.3.5 termin/termof part . 174 6.3.6 up/down part . 175 6.3.7 reps part . 180 6.3.8 term subst part . 181 6.4 The ‘tarski’ theory . 187 7 Conclusions and Future Work 189 7.1 Still Needed . 189 7.2 Future Work . 191 A Glossary 194 B Theory Files 199 B.1 Reflection Theory . 199 B.2 Tarski Theory . 210 Bibliography 221 viii LIST OF FIGURES 3.1 Term parts . 47 3.2 Operator Shifting in PLT-Scheme . 66 3.3 Interacting with quoted terms using colors . 87 4.1 A naive HOAS implementation using Nuprl’s ‘term’ type . 114 4.2 Major components in Urban’s formalism; connections to ours . 123 ix Chapter 1 Introduction Reflection is the ability of some entity to describe itself. It is a deep idea in logic, computer science, linguistics, philosophy, art, and more. Reflection has been a source of philosophical discussions for ages, with the liar paradox and variations (e.g., “This sentence is false.”) being the best known example — allegedly orig- inated by the Greek philosopher Eubulides the Megarian in the fourth century B.C.1, studied in the twelfth century under the name of “insolubles” or “insolu- bilia” [67], etc. Reflection is also a very current topic.