Automata and Formal Languages - CM0081 Introduction to Agda

Similar documents
ABriefOverviewofAgda A Functional Language with Dependent Types

Lecture slides & distribution files:

Martin-Löf s Type Theory

Martin-L f's Type Theory. B. Nordstr m, K. Petersson and J. M. Smith. Contents. 5.4 The set of functions (Cartesian product of a family of sets) 24

Programming Proofs and Proving Programs. Nick Benton Microsoft Research, Cambridge

On Agda JAIST/AIST WS CVS/AIST Yoshiki Kinoshita, Yoriyuki Yamagata. Agenda

SJTU SUMMER 2014 SOFTWARE FOUNDATIONS. Dr. Michael Clarkson

An Introduction to Programming and Proving in Agda (incomplete draft)

Mathematics for Computer Scientists 2 (G52MC2)

A NEW PROOF-ASSISTANT THAT REVISITS HOMOTOPY TYPE THEORY THE THEORETICAL FOUNDATIONS OF COQ USING NICOLAS TABAREAU

Introduction to dependent types in Coq

Introduction to Homotopy Type Theory

Automata and Formal Languages - CM0081 Introduction

Mathematics for Computer Scientists 2 (G52MC2)

CS3110 Spring 2017 Lecture 10 a Module for Rational Numbers

Intuitionistic Type Theory

Conclusions and further reading

Univalent fibrations in type theory and topology

As Natural as 0, 1, 2. Philip Wadler University of Edinburgh

Coq, a formal proof development environment combining logic and programming. Hugo Herbelin

Computational Higher-Dimensional Type Theory

LOGIC AND DISCRETE MATHEMATICS

Universes. Universes for Data. Peter Morris. University of Nottingham. November 12, 2009

Classical logic, truth tables. Types, Propositions and Problems. Heyting. Brouwer. Conjunction A B A & B T T T T F F F T F F F F.

Proofs are Programs. Prof. Clarkson Fall Today s music: Proof by Paul Simon

The three faces of homotopy type theory. Type theory and category theory. Minicourse plan. Typing judgments. Michael Shulman.

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

Proofs-Programs correspondance and Security

Programming Languages Third Edition

Axiom 3 Z(pos(Z) X(X intersection of Z P(X)))

Proofs are Programs. Prof. Clarkson Fall Today s music: Two Sides to Every Story by Dyan Cannon and Willie Nelson

Com S 541. Programming Languages I

Types Summer School Gothenburg Sweden August Dogma oftype Theory. Everything has a type

Constructive Type Theory and Interactive Theorem Proving. Peter Dybjer Chalmers Tekniska Högskola Göteborg, Sweden

Logical Verification Course Notes. Femke van Raamsdonk Vrije Universiteit Amsterdam

Provably Correct Software

A Prolog-based Proof Tool for Type Theory TA λ and Implicational Intuitionistic-Logic

JOURNAL OF OBJECT TECHNOLOGY

Implementing Mathematics

The Formal Semantics of Programming Languages An Introduction. Glynn Winskel. The MIT Press Cambridge, Massachusetts London, England

CS3110 Spring 2017 Lecture 7 Specifications using types continued

Alonzo a Compiler for Agda

Topic 3: Propositions as types

Programming with Dependent Types Interactive programs and Coalgebras

HOL DEFINING HIGHER ORDER LOGIC LAST TIME ON HOL CONTENT. Slide 3. Slide 1. Slide 4. Slide 2 WHAT IS HIGHER ORDER LOGIC? 2 LAST TIME ON HOL 1

CS3110 Spring 2017 Lecture 9 Inductive proofs of specifications

Formalizing the Halting Problem in a Constructive Type Theory

Chapter 3: Propositional Languages

Introductory logic and sets for Computer scientists

An Annotated Language

Computer Science 190 (Autumn Term, 2010) Semantics of Programming Languages

Computation Club: Gödel s theorem

Towards Reasoning about State Transformer Monads in Agda. Master of Science Thesis in Computer Science: Algorithm, Language and Logic.

CSC 501 Semantics of Programming Languages

CSE 20 DISCRETE MATH. Fall

CS3110 Spring 2017 Lecture 8 Specifications continued

CIS 500: SOFTWARE FOUNDATIONS

Introduction to Coq Proof Assistant

MLW. Henk Barendregt and Freek Wiedijk assisted by Andrew Polonsky. March 26, Radboud University Nijmegen

CSE 20 DISCRETE MATH. Winter

Propositional Calculus. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

Formal Predicate Calculus. Michael Meyling

Typed Lambda Calculus for Syntacticians

INDEPENDENT POSTULATES FOR THE "INFORMAL" PART OF PRINCIPIA MATHEMATICA*

Partiality and Recursion in Interactive Theorem Provers An Overview

Lecture 8: Summary of Haskell course + Type Level Programming

Type Checking and Inference Are Equivalent in Lambda Calculi with Existential Types

Logic and its Applications

Programs with infinite loops: from primitive recursive predicates to the arithmetic hierarchy

4.8 Dependent Types 97

Lambda Calculi With Polymorphism

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

Programming with Universes, Generically

CMPSCI 250: Introduction to Computation. Lecture #1: Things, Sets and Strings David Mix Barrington 22 January 2014

Linear Clause Generation by Tableaux and DAGs

Theorem proving. PVS theorem prover. Hoare style verification PVS. More on embeddings. What if. Abhik Roychoudhury CS 6214

arxiv: v6 [math.lo] 9 Mar 2018

Propositional Calculus: Boolean Functions and Expressions. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

Combining Programming with Theorem Proving

CIS 500: SOFTWARE FOUNDATIONS

Summary of Course Coverage

CS3110 Spring 2017 Lecture 12: DRAFT: Constructive Real Numbers continued

Using Agda to Explore Path-Oriented Models of Type Theory

Faith, Evolution, and Programming Languages. Philip Wadler University of Edinburgh

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27

9/19/12. Why Study Discrete Math? What is discrete? Sets (Rosen, Chapter 2) can be described by discrete math TOPICS

A Modern Perspective on Type Theory

CSCI-GA Scripting Languages

n λxy.x n y, [inc] [add] [mul] [exp] λn.λxy.x(nxy) λmn.m[inc]0 λmn.m([add]n)0 λmn.n([mul]m)1

More Untyped Lambda Calculus & Simply Typed Lambda Calculus

Lisp History. Lisp and Prolog Background. Lisp Use. Lisp Availability

Denotational Semantics. Domain Theory

1.3. Conditional expressions To express case distinctions like

Typed Lambda Calculus

Presented By : Abhinav Aggarwal CSI-IDD, V th yr Indian Institute of Technology Roorkee. Joint work with: Prof. Padam Kumar

Basic Foundations of Isabelle/HOL

COSC252: Programming Languages: Semantic Specification. Jeremy Bolton, PhD Adjunct Professor

Losp for Predicate Calculus

Type Theory. Lecture 2: Dependent Types. Andreas Abel. Department of Computer Science and Engineering Chalmers and Gothenburg University

Types, Categories & Logic

Transcription:

Automata and Formal Languages - CM0081 Introduction to Agda Andrés Sicard-Ramírez Universidad EAFIT Semester 2018-2

Introduction Curry-Howard correspondence Dependent types Constructivism Martin-Löf s type theory Dependently typed functional programming language Agda Dependently typed interactive proof assistant 2/46

Constructive Logic Troelstra and van Dalen [1988, p. 8]: The preceding examples of non-constructive proofs show that the natural constructive reading of A or B and xa(x) as we can decide between A and B and we can construct an x such that A(x) respectively does not agree with all the laws of the classical logic. 3/46

Constructive Logic Natural deduction rules A A (Ax) 4/46

Constructive Logic Natural deduction rules A A (Ax) Γ, A B ( I) Γ A B Γ A Γ A B ( E) Γ B 5/46

Constructive Logic Natural deduction rules A A (Ax) Γ, A B ( I) Γ A B Γ A Γ A B ( E) Γ B Γ A Γ B ( I) Γ A B Γ A B ( E1 ) Γ A Γ A B ( E2 ) Γ B 6/46

Constructive Logic Natural deduction rules A A (Ax) Γ, A B ( I) Γ A B Γ A Γ A B ( E) Γ B Γ A Γ B ( I) Γ A B Γ A B ( E1 ) Γ A Γ A B ( E2 ) Γ B Γ A Γ A B ( I 1 ) Γ B Γ A B ( I 2 ) Γ, A C Γ, B C A B ( E) Γ C 7/46

Constructive Logic Natural deduction rules A A (Ax) Γ, A B ( I) Γ A B Γ A Γ A B ( E) Γ B Γ A Γ B ( I) Γ A B Γ A B ( E1 ) Γ A Γ A B ( E2 ) Γ B Γ A Γ A B ( I 1 ) Γ B Γ A B ( I 2 ) Γ, A C Γ, B C A B ( E) Γ C ( E) A 8/46

Constructive Logic Natural deduction rules A A (Ax) Γ, A B ( I) Γ A B Γ A Γ A B ( E) Γ B Γ A Γ B ( I) Γ A B Γ A B ( E1 ) Γ A Γ A B ( E2 ) Γ B Γ A Γ A B ( I 1 ) Γ B Γ A B ( I 2 ) Γ, A C Γ, B C A B ( E) Γ C Abbreviation: A A ( E) A 9/46

Constructive Logic Example (Ax) B A B A ( E2 ) B A A B A A B (Ax) B A B A ( E1 ) B A B ( I) 10/46

What is a Type? Example Mathematics f Z {True, False} f(x) =... Java int f(boolean b) {... } Haskell f Bool Int f b =... 11/46

What is a Type? Example V = v V (type variables) T = V C N 0 N 1 T T T T T + T (constant types) (the empty type) (the unit type) (function types) (product types) (disjoint union types) 12/46

What is a Type? A type is a set. 13/46

What is a Type? A type is a set. Types as ranges of significance of propositional functions [Russell 1908]. Types are domains of predicates. 14/46

What is a Type? A type is a set. Types as ranges of significance of propositional functions [Russell 1908]. Types are domains of predicates. Example. The mathematical induction principle P (0) ( x.p (x) P (succ(x))) x.p (x) make sense only when P is a predicate over natural numbers (i.e., P N {True, False}). 15/46

What is a Type? Hoare s Notes on Data Structuring [Hoare 1972, pp. 92-93] 16/46

What is a Type? Hoare s Notes on Data Structuring [Hoare 1972, pp. 92-93] Thus there is a high degree of commonality in the use of the concept of type by mathematicians, logicians and programmers. The salient characteristics of the concept of type may be summarised: 1. A type determines the class of values which may be assumed by a variable or expression. 2. Every value belongs to one and only one type. 3. The type of a value denoted by any constant, variable, or expression may be deduced from its form or context, without any knowledge of its value as computed at run time. Continued on next slide 17/46

What is a Type? Hoare s Notes on Data Structuring (continuation) 4. Each operator expects operands of some fixed type, and delivers a result of some fixed type (usually the same). Where the same symbol is applied to several different types (e.g. + for addition of integers as well as reals), this symbol may be regarded as ambiguous, denoting several different actual operators. The resolution of such systematic ambiguity can always be made at compile time. 5. The properties of the values of a type and of the primitive operations defined over them are specified by means of a set of axioms. Continued on next slide 18/46

What is a Type? Hoare s Notes on Data Structuring (continuation) 6. Type information is used in a high-level language both to prevent or detect meaningless constructions in a program, and to determine the method of representing and manipulating data on a computer. 7. The types in which we are interested are those already familiar to mathematicians; namely, Cartesian Products, Discriminated Unions, Sets, Functions, Sequences, and Recursive Structures. 19/46

What is a Type? A type system is a tractable syntactic method for proving the absence of certain program behaviours by classifying phrases according to the kinds of values they compute. [Pierce 2002, p. 1] 20/46

What is a Type? A type system is a tractable syntactic method for proving the absence of certain program behaviours by classifying phrases according to the kinds of values they compute. [Pierce 2002, p. 1] A type is an approximation of a dynamic behaviour that can be derived from the form of an expression. [Kiselyov and Shan 2008, p. 8] 21/46

What is a Type? A type system is a tractable syntactic method for proving the absence of certain program behaviours by classifying phrases according to the kinds of values they compute. [Pierce 2002, p. 1] A type is an approximation of a dynamic behaviour that can be derived from the form of an expression. [Kiselyov and Shan 2008, p. 8] Related readings The Triumph of Types: Principia Mathematica s Impact on Computer Science [Constable 2010]. Against a Universal Definition of Type [Petricek 2015]. 22/46

What is a Type? BHK (Brouwer, Heyting, Kolmogorov) interpretation: A type is a set, a proposition, a problem and a specification. Type A Term a A Interpretation A is a set a is an element of the set A A A is a proposition A is a problem A is a specification a is a proof (construction) of the proposition A a is a method of solving the problem A a is a program than meets the specification A A is true A is solvable A is satisfiable See, e.g., [Martin-Löf 1984]. 23/46

Dependent Types Types that depend on elements of other types. 24/46

Dependent Types Types that depend on elements of other types. Example The type of vectors of length n: A 0 = 1, A n+1 = A A n, where 1 is the unit type and is the product type. 25/46

Dependent Types B(x): Dependent type for x A 26/46

Dependent Types B(x): Dependent type for x A Definition (Dependent function type (Pi types)) B(x) is the type of functions f with f a B(a) if a A. x A Note: If B(x) = B for all x A, then B(x) A B. (Agda notation: (x A) B) x A 27/46

Dependent Types Definition (Dependent sum type (Sigma types)) B(x) is the type of pairs (a, b) with a A and b B(a). x A Note: If B(x) = B for all x A, then B(x) A B. x A 28/46

The Propositions-as-Types Principle The Curry-Howard isomorphism or the Brouwer - Heyting - Kolmogorov - Schönfinkel - Curry - Meredith - Kleene - Feys - Gödel - Läuchli - Kreisel - Tait - Lawvere - Howard - de Bruijn - Scott - Martin-Löf - Girard - Reynolds - Stenlund - Constable - Coquand - Huet - - isomorphism [Sørensen and Urzyczyn 2006, p. viii]. 29/46

The Propositions-as-Types Principle Three correspondence s levels [Wadler 2015]: 1. Propositions as types for each proposition in the logic there is a corresponding type in the programming language and vice versa 30/46

The Propositions-as-Types Principle Three correspondence s levels [Wadler 2015]: 1. Propositions as types for each proposition in the logic there is a corresponding type in the programming language and vice versa 2. Proofs as programs for each proof of a given proposition, there is a program of the corresponding type and vice versa 31/46

The Propositions-as-Types Principle Three correspondence s levels [Wadler 2015]: 1. Propositions as types for each proposition in the logic there is a corresponding type in the programming language and vice versa 2. Proofs as programs for each proof of a given proposition, there is a program of the corresponding type and vice versa 3. Simplification of proofs as evaluation of programs for each way to simplify a proof there is a corresponding way to evaluate a program and vice versa 32/46

The Propositions-as-Types Principle (A proposition is true if the corresponding type is non-empty) Propositional Logic (false) (true) (implication) (conjunction) (disjunction) Dependently typed λ-calculus (empty type) (unit type) (function type) (product type) + disjoint sum type 33/46

The Propositions-as-Types Principle II (A proposition is true if the corresponding type is non-empty) First-Order Logic (false) (true) (implication) (conjunction) (disjunction) x.b(x) (universal quantifier) x.b(x) (existential quantifier) Dependently typed λ-calculus (empty type) (unit type) (function type) (product type) + (disjoint sum type) B(x) (dependent fn. type) x A B(x) (dependent sum type) x A 34/46

Applications of Dependent Types To carry useful information for programs optimisation. 35/46

Applications of Dependent Types To carry useful information for programs optimisation. To reduce the semantic gap between programs and their properties. 36/46

Applications of Dependent Types To carry useful information for programs optimisation. To reduce the semantic gap between programs and their properties. The propositions-as-types-principle: Computational interpretation of logical constants. 37/46

Applications of Dependent Types To carry useful information for programs optimisation. To reduce the semantic gap between programs and their properties. The propositions-as-types-principle: Computational interpretation of logical constants. Unified programing logics (programs, specification and satisfaction relation). 38/46

Dependently Typed Systems (See the Wikipedia article on dependent types for a more complete list) 39/46

Dependently Typed Systems (See the Wikipedia article on dependent types for a more complete list) The ALF/Agda family (Gothenburg - Sweden) ALF Agda Alfa. Graphical interface for Agda AgdaLight. Experimental version of Agda Agda 2. Based on Martin-Löf type theory. Direct manipulation of proofs-objects. Backends to Haskell and JavaScript. Written in Haskell. 40/46

Dependently Typed Systems Cayenne (Gothenburg - Sweden). An Haskell-like language with dependent types. Written in Haskell. Coq (INRIA - France). Based on the Calculus of Inductive Constructions. Tactic-based. Extraction of programs to Objective Caml, Haskell and Scheme. Written in Objective Caml (with a bit of C). DML (USA). An extension of ML with a restricted form of dependent types. Written in Objective Caml. Epigram 2 (England). Based on a closed type theory. Direct manipulation of proofs-objects. The language is in development. NuPrl (Cornell - USA). Based on the Computational Type Theory. Tactic-based. Written in ML. 41/46

Further Reading Agda as a dependently typed proof assistant: Bove, A. and Dybjer, P. [2009]. Dependent Types at Work. In: Ler- Net ALFA Summer School 2008. Ed. by Bove, A., Soares Barbosa, L., Pardo, A. and Sousa Pinto, J. Vol. 5520. Lecture Notes in Computer Science. Springer, pp. 57 99. doi: 10.1007/978-3-642-03153-3_2. Agda as a dependently typed functional programming language: Norell, U. [2009]. Dependently Typed Programming in Agda. In: Advanced Functional Programming (AFP 2008). Ed. by Koopman, P., Plasmeijer, R. and Swierstra, D. Vol. 5832. Lecture Notes in Computer Science. Springer, pp. 230 266. doi: 10.1007/978-3-642-04652-0_5. 42/46

References Bove, A. and Dybjer, P. (2009). Dependent Types at Work. In: LerNet ALFA Summer School 2008. Ed. by Bove, A., Soares Barbosa, L., Pardo, A. and Sousa Pinto, J. Vol. 5520. Lecture Notes in Computer Science. Springer, pp. 57 99. doi: 10.1007/978-3-642-03153-3_2 (cit. on p. 42). Constable, R. L. (2010). The Triumph of Types: Principia Mathematica s Impact on Computer Science. Presented at the Principia Mathematica anniversary symposium (cit. on pp. 20 22). Hoare, C. A. R. (1972). Notes on Data Structuring. In: Structured Programming. Ed. by Dahl, O.-J., Disjkstra, E. W. and Hoare, C. A. R. Academic Press Inc., pp. 83 174 (cit. on pp. 16, 17). Kiselyov, O. and Shan, C. (2008). Interpreting Types as Abstract Values. Formosan Summer School on Logic, Language and Computacion (FLOLAC 2008) (cit. on pp. 20 22). Martin-Löf, P. (1984). Intuitionistic Type Theory. Bibliopolis (cit. on p. 23). 43/46

References Norell, U. (2009). Dependently Typed Programming in Agda. In: Advanced Functional Programming (AFP 2008). Ed. by Koopman, P., Plasmeijer, R. and Swierstra, D. Vol. 5832. Lecture Notes in Computer Science. Springer, pp. 230 266. doi: 10.1007/978-3-642-04652-0_5 (cit. on p. 42). Petricek, T. (2015). Against a Universal Definition of Type. In: Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software (Onward! 2015). ACM, pp. 254 266. doi: 10.1145/2814228.2814249 (cit. on pp. 20 22). Pierce, B. C. (2002). Types and Programming Languages. MIT Press (cit. on pp. 20 22). Russell, B. (1908). Mathematical Logic as based on the Theory of Types. In: American Journal of Mathematics 30.3, pp. 222 262. doi: 10.2307/2369948 (cit. on pp. 13 15). Sørensen, M.-H. and Urzyczyn, P. (2006). Lectures on the Curry-Howard Isomorphism. Vol. 149. Studies in Logic and the Foundations of Mathematics. Elsevier (cit. on p. 29). 44/46

References Troelstra, A. S. and van Dalen, D. (1988). Constructivism in Mathematics. An Introduction. Vol. I. North-Holland (cit. on p. 3). Wadler, P. (2015). Propositions as Types. In: Communications of the ACM 58.12, pp. 75 84 (cit. on pp. 30 32). 45/46

Demo