Certified Reasoning on Real Numbers and Objects in Co-Inductive Type
Total Page:16
File Type:pdf, Size:1020Kb
Universita` degli Studi di Udine Dipartimento di Matematica e Informatica Dottorato di Ricerca in Informatica Institut National Polytechnique de Lorraine Ecole´ Nationale Superieure´ des Mines, Nancy Laboratoire Lorraine de Recherche en Informatique et ses Applications Doctorat de Recherche en Informatique Ph.D. Thesis Certified Reasoning on Real Numbers and Objects in Co-inductive Type Theory Candidate: Supervisors: Alberto Ciaffaglione Furio Honsell Pietro Di Gianantonio Claude Kirchner Luigi Liquori °c 2003, Alberto Ciaffaglione Author’s e-mail: ciaff[email protected], Alberto.Ciaff[email protected] Author’s address: Dipartimento di Matematica e Informatica Universit`adegli Studi di Udine via delle Scienze, 206 33100 Udine (Italia) Abstract In this thesis we adopt Formal Methods based on Type Theory for reasoning on the semantics of computer programs. The ultimate goal is their certification, that is, to prove that a fragment of software meets its formal specification. Application areas of our research are the representation of and computation on the Real Numbers and the Object-oriented Languages based on Objects. In our investigation, Coinductive specification and proof principles play an essential role. In the first part of the thesis we deal with Constructive Real Numbers. We construct the reals using streams, i.e. infinite sequences, of signed digits. We work with constructive logic, that is, we develop “algorithmic” mathematics. We implement the Real Numbers in Coq using streams, which are managed using coinductive judgments and corecursive algorithms. Then we introduce a constructive axiomatization and we use it for proving the adequacy of our construction. In the second part of the thesis we approach Object-based Calculi with side-effects, in order to address important properties, such as Type Soundness, formally. We state our investigation focusing on Abadi and Cardelli’s imp&-calculus, which features objects, cloning, dynamic lookup, imperative method update, object types and subsumption. We reformulate imp& using modern encoding techniques, as Higher-Order Abstract Syntax and Coinductive proof systems in Natural Deduction style. Then we formalize imp& in Coq and we prove the Type Soundness. To my parents, Elisa, and Alessia Acknowledgments I wish to thank many people, who helped me in the course of my PhD programme in Udine and Nancy. First of all, I am grateful to my supervisors, Furio Honsell and Pietro Di Giananto- nio in Udine, Claude Kirchner and Luigi Liquori in Nancy, for their guidance, inspiring comments and useful suggestions. I benefited a lot of the collaboration with Marino Miculan, Ivan Scagnetto and Marina Lenisa at the Department of Mathematics and Computer Science in Udine. A special thank to the people of the Protheo group at LORIA, who allowed me to make more profitable my stay in Nancy. And also thanks to Jo¨elleDespeyroux, Bernard Serpette and Yves Bertot, for interesting discussions during the month spent in Sophia Antipolis. Finally, my greatest gratitude is devoted to my family and my girlfriend, for fully supporting me along the years of this adventure. April 30, 2003 Alberto Ciaffaglione Contents Introduction and Overview iii R´esum´e vii I Preliminary reflections 1 1 Formal Methods based on Type Theory 3 1.1 Computational metamodels . 3 1.2 Logical frameworks based on typed ¸-calculus . 4 1.3 The Calculus of (Co)Inductive Constructions . 9 1.4 The proof assistant Coq . 12 1.5 Circularity and Coinduction . 19 2 Focusing on Real Numbers and Objects 25 2.1 Motivations for Real Numbers . 25 2.2 Constructions of the Real Numbers . 27 2.3 Exact computation . 28 2.4 Constructive Mathematics, Computer Science . 29 2.5 Motivations for Objects . 30 2.6 Formal Methods and Objects . 31 II Real Numbers 33 3 A co-inductive model of the Real Numbers in Coq 35 3.1 Real numbers in logical frameworks . 35 3.2 Construction via streams . 36 3.3 Adequacy of the encoding . 41 3.4 Formalization in Coq . 43 3.5 Redundancy and equivalence . 48 3.6 Certification of exact algorithms . 51 3.7 Related work . 57 4 Axiomatizations of Constructive Real Numbers 59 4.1 A minimal constructive axiomatization . 59 4.2 Consistency of the axioms . 63 ii Contents 4.3 Axioms at work . 74 4.4 Equivalent axiomatizations . 76 4.5 Completeness and categoricity . 81 4.6 Conclusion . 82 III Objects 85 5 Abadi and Cardelli’s imp&-calculus 87 5.1 Overview of the calculus . 87 5.2 Examples . 91 5.3 Type Soundness . 94 6 Reformulation of imp& in Natural Deduction 99 6.1 Proof-theoretical choices . 99 6.2 Dynamic and static semantics . 102 6.3 Adequacy . 109 6.4 Preliminary metatheory . 112 6.5 Result typing by coinduction . 113 6.6 Result typing by induction . 119 7 A Type Sound formalization of imp& in Coq 131 7.1 Encoding methodology . 131 7.2 Formalization in Coq . 132 7.3 Metatheory in Coq . 147 7.4 Type Soundness . 151 7.5 Related work . 152 7.6 Conclusion . 152 Bibliography 155 Introduction and Overview Nowadays there is a strong need for dependable Information Technology, because computer science is pervasive throughout all areas of human activity, and computerized systems are ubiquitous. Thus software failures should be avoided, because they may cause serious consequences both to building firms and users, even loss of life in the case of safety-critical applications, as for example car engine management systems, heart pacemakers, radiation therapy machines, nuclear reactor controllers, fly-by-wire aircrafts, and so on. Even if absolute validation is utopian, we can achieve a greater reliability on programs and systems, thus increasing our confidence, through a rigorous analysis based on formal proofs, and using logics validated by mathematical models. This goal is approached in the present thesis by the use of Constructive Type Theory, viz Typed Lambda Calculus. Such a (special-purpose) formal system is an excellent tool for representing formal reasoning, and is the basis of the computational metamodel of Type Theory-based Logical Frameworks (LFs), namely general specification environments where logic-independent reasoning is possible, and which permit to factorize out the differences across object systems. Hence LFs are very useful for encoding generic calculi and logics, for developing prototypes, and then reasoning on specifications and models by formal proofs. LFs are based on the Curry-Howard-de Bruijn (or propositions-as-types) [How80, dB80] analogy, i.e. a close correspondence between types-propositions and ¸terms-proofs. Types can be actually interpreted as propositions, and terms inhabiting types are exactly the proofs of the associated propositions. Hence formal proofs have computational content, because they embed algorithms, and typed functional languages can be seen as languages for proofs. Proceeding further, a proposition is true if the corresponding type is inhabited, thus proof checking reduces to type checking. In the case that type checking is decidable, LFs become a suitable basis for implementing interactive proof assistants (Nuprl, Lego, Coq, Alf, etc.). Interactive proof assistants are systems where “the human provides the intelligence and the automated system does part of the craftsmanship”. They actually allow to combine proof building —which is creative and difficult to automate— with proof checking— which is, on the contrary, routine, and can be an highly error-prone activity for the human mind. Among interactive proof assistants, the semi-automated ones, as for example Coq [INR03], seem a good compromise. The system Coq, which is based on the Calculus of Constructions [CH88], interpreter of the proposition-as-types principle for the higher-order intuitionistic logic, plays a prominent role in the present thesis. Aims of the thesis. In this thesis we adopt Formal Methods based on Type Theory for reasoning on the semantics of computer programs. The ultimate goal is their certification, that is, to prove that a fragment of software meets its formal specification. iv Introduction and Overview Application areas of our research are the representation of and computation on the Real Numbers and the Object-oriented Programming Languages based on Objects. In our investigation, coinductive specification and proof principles play an essential role. Induction and coinduction are different tools for reasoning on circularity, or self ref- erence. The human process of rational and formal reasoning needs the use of circularity, not only when considering computer science, mathematics or logic, but also in many other disciplines. Self reference is pervasive in theoretical computer science, because it is ex- tremely natural and powerful for modeling and studying the behavior and the semantics of computing systems. Among circular phenomena, it is natural to distinguish between inductive and coinductive ones: induction supplies principles for defining and reasoning on circular, finite objects; coinduction is quite well-suited with respect to circular, non well-founded objects. Some researchers capture this distinction from a more abstract point of view, using a categorical terminology: in this perspective, it is possible to state a duality between algebras —involved in the description of abstract data types— and coalgebras —which arise in the analysis of state-based dynamical structures occurring in computer science. Many applicative situations fall in the coalgebraic, or coinductive, area: typically all those phenomena where an infinite amount of information is involved (e.g. never terminating processes, streams, exact real numbers, loops of pointers in the memory, etc). Synopsis. The present document is organized in three distinct parts. The first one supplies the background useful for developing the other two. More precisely, chapter 1 focus on the tools we work with, namely Type Theory-based Logical Frameworks, the proof assistant Coq and coinductive principles. The thesis really starts in chapter 2, where we collect the motivations for the work we carry out in the following chapters. The second part of the thesis deals with constructive real numbers. We construct the reals in chapter 3 using streams, i.e.