Introduction to Type Theory February 2008 Alpha Lernet Summer School Piriapolis, Uruguay. Herman Geuvers Nijmegen & Eindhoven, NL

Similar documents
Γ is usually left implicit: ϕ

The Curry-Howard Isomorphism

Beyond First-Order Logic

The Calculus of Inductive Constructions

Henk Barendregt and Freek Wiedijk assisted by Andrew Polonsky. Radboud University Nijmegen. March 5, 2012

Introduction to Type Theory

Syntax. Notation Throughout, and when not otherwise said, we assume a vocabulary V = C F P.

Type Theory and Constructive Mathematics. Type Theory and Constructive Mathematics Thierry Coquand. University of Gothenburg

Justifying Algorithms for βη-conversion

First-Order Logic First-Order Theories. Roopsha Samanta. Partly based on slides by Aaron Bradley and Isil Dillig

The Church-Rosser Property for -reduction in Typed -Calculi. Herman Geuvers. University of Nijmegen

hal , version 1-21 Oct 2009

185.A09 Advanced Mathematical Logic

Predicate Calculus. Formal Methods in Verification of Computer Systems Jeremy Johnson

Typage et déduction dans le calcul de

Explicit Convertibility Proofs in PTSs

Predicate Calculus. CS 270 Math Foundations of Computer Science Jeremy Johnson

First-Order Theorem Proving and Vampire

Overview. CS389L: Automated Logical Reasoning. Lecture 7: Validity Proofs and Properties of FOL. Motivation for semantic argument method

Realizability and Parametricity in Pure Type Systems

From pre-models to models

TECHNISCHE UNIVERSITEIT EINDHOVEN Faculteit Wiskunde en Informatica. Final examination Logic & Set Theory (2IT61/2IT07/2IHT10) (correction model)

(In)consistency of extensions of Higher Order Logic and Type Theory

Natural deduction for propositional logic via truth tables

Classical First-Order Logic

Propositional and Predicate Logic. jean/gbooks/logic.html

An introduction to classical realizability

If-then-else and other constructive and classical connectives (Or: How to derive natural deduction rules from truth tables)

CSE 1400 Applied Discrete Mathematics Definitions

Type Theory and Univalent Foundation

PROOFS IN PREDICATE LOGIC AND COMPLETENESS; WHAT DECIDABILITY MEANS HUTH AND RYAN 2.3, SUPPLEMENTARY NOTES 2

First-Order Theorem Proving and Vampire. Laura Kovács (Chalmers University of Technology) Andrei Voronkov (The University of Manchester)

Equality and dependent type theory. CIRM, May 31

Realizability and Parametricty in Pure Type Systems

Negation introduction

1. Propositions: Contrapositives and Converses

Lecture 2: Syntax. January 24, 2018

Classical First-Order Logic

Introduction to Logic in Computer Science: Autumn 2006

The Locally Nameless Representation

Lecture 14 Rosser s Theorem, the length of proofs, Robinson s Arithmetic, and Church s theorem. Michael Beeson

On Lists and Other Abstract Data Types in the Calculus of Constructions

Interpreting HOL in the Calculus of Constructions

Modal logics: an introduction

Mathematical Logic. Reasoning in First Order Logic. Chiara Ghidini. FBK-IRST, Trento, Italy

Lambda Calculus. Week 12 The canonical term models for λ. Henk Barendregt, Freek Wiedijk assisted by Andrew Polonsky

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications

Informal Statement Calculus

Introduction to dependent type theory. CIRM, May 30

Dependent type theory

Lecture 2: Self-interpretation in the Lambda-calculus

Peano Arithmetic. CSC 438F/2404F Notes (S. Cook) Fall, Goals Now

Kleene realizability and negative translations

Lecture 1: Logical Foundations

First-Order Logic. 1 Syntax. Domain of Discourse. FO Vocabulary. Terms

Subtyping and Intersection Types Revisited

15414/614 Optional Lecture 3: Predicate Logic

Mathematics 114L Spring 2018 D.A. Martin. Mathematical Logic

λ Slide 1 Content Exercises from last time λ-calculus COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification

TECHNISCHE UNIVERSITEIT EINDHOVEN Faculteit Wiskunde en Informatica. Final exam Logic & Set Theory (2IT61) (correction model)

Part 2: First-Order Logic

An Introduction to Modal Logic III

Herbrand Theorem, Equality, and Compactness

Propositional and Predicate Logic - XIII

CHAPTER 2. FIRST ORDER LOGIC

Marie Duží

Categories, Proofs and Programs

Some Review Problems for Exam 1: Solutions

Typed Arithmetic Expressions

Contents Propositional Logic: Proofs from Axioms and Inference Rules

Theory of Computation

Properties of Relational Logic

HOAS by example What is a Formal System? A Simply Typed Framework What Does it Mean? Canonical LF References HOAS. Randy Pollack

Applied Logic. Lecture 1 - Propositional logic. Marcin Szczuka. Institute of Informatics, The University of Warsaw

Outline. Overview. Syntax Semantics. Introduction Hilbert Calculus Natural Deduction. 1 Introduction. 2 Language: Syntax and Semantics

CMPSCI 601: Tarski s Truth Definition Lecture 15. where

Models of computation

7 RC Simulates RA. Lemma: For every RA expression E(A 1... A k ) there exists a DRC formula F with F V (F ) = {A 1,..., A k } and

1 Functions and Sets. 1.1 Sets and Subsets. Phil 450: The Limits of Logic Jeff Russell, Fall 2014

Advanced Lambda Calculus. Henk Barendregt & Giulio Manzonetto ICIS Faculty of Science Radboud University Nijmegen, The Netherlands

Local Representations of Binding

Semantics and Pragmatics of NLP

ArgoCaLyPso SAT-Inspired Coherent Logic Prover

An Overview of Residuated Kleene Algebras and Lattices Peter Jipsen Chapman University, California. 2. Background: Semirings and Kleene algebras

Motivation. CS389L: Automated Logical Reasoning. Lecture 10: Overview of First-Order Theories. Signature and Axioms of First-Order Theory

Algebraizing Hybrid Logic. Evangelos Tzanis University of Amsterdam Institute of Logic, Language and Computation

Homotopy Type Theory

higher-order logic (e:g:, Church's simple theory of types [5]) P must be a simple type. Although CC types include the types of the simply-typed -calcu

GS03/4023: Validation and Verification Predicate Logic Jonathan P. Bowen Anthony Hall

Mathematical Logic. An Introduction

CS 3110: Proof Strategy and Examples. 1 Propositional Logic Proof Strategy. 2 A Proof Walkthrough

Přednáška 12. Důkazové kalkuly Kalkul Hilbertova typu. 11/29/2006 Hilbertův kalkul 1

Notes on Propositional and First-Order Logic (CPSC 229 Class Notes, January )

PREDICATE LOGIC: UNDECIDABILITY AND INCOMPLETENESS HUTH AND RYAN 2.5, SUPPLEMENTARY NOTES 2

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Parametricity and excluded middle

COMP6463: λ-calculus

Introduction to Logic in Computer Science: Autumn 2007

Syntax of FOL. Introduction to Logic in Computer Science: Autumn Tableaux for First-order Logic. Syntax of FOL (2)

Intensionality, Extensionality, and Proof Irrelevance in Modal Type Theory

Transcription:

Introduction to Type Theory February 2008 Alpha Lernet Summer School Piriapolis, Uruguay Herman Geuvers Nijmegen & Eindhoven, NL Lecture 5: Higher Order Logic and the Calculus of Constructions 1

Church s STT The original motivation of Church to define introduce simple type theory was: to define higher order (predicate) logic In λ he adds the following prop as a basic type : prop prop prop σ : (σ prop) prop (for each type σ) This defines the language of higher order logic. 2

Examples Induction N prop ( λp:n prop.(p 0) ( N (λx:n.(p x P(S x))) N (λx:n.p x)) ) Notation: P:N prop( (P 0) ( x:n.(p x P(S x))) x:n.p x ) Higher order predicates/functions: transitive closure of a relation R λr : A A prop. λx, y : A. ( Q : A A prop. (trans(q) (R Q) Q xy)) of type (A A prop) (A A prop) 3

Derivation rules for Higher Order Logic (following Church) Natural deduction style. Rules are on top of the simple type theory. Judgements are of the form Γ ϕ = ψ 1,...,ψ n Γ is a λ -context Γ ϕ : prop, Γ ψ 1 : prop,..., Γ ψ n : prop Γ is usually left implicit: ϕ 4

(axiom) ϕ if ϕ ( -introduction) ( -elimination) ( -introduction) ( -elimination) (conversion) ϕ ψ ϕ ψ ϕ ψ ϕ ψ ϕ x:σ.ϕ x:σ.ϕ ϕ[t/x] ϕ ψ if x:σ / FV( ) if t : σ if ϕ = β ψ 5

Full Church higher order logic [1940] Church has additional things that we will not consider now: Negation connective with rules Classical logic ϕ ϕ Define other connectives in terms of,, (classically). Choice operator ι σ : (σ prop) σ Rule for ι:!x:σ.p x P(ι σ P) 6

Full Church higher order logic [1940] Church original higher order logic is basically the logic of the theorem prover HOL (Gordon, Melham, Harrison) and of Isabelle-HOL (Paulson, Nipkow). We will here restrict to the basic constructive core (, ) of HOL. 7

The need for a conversion rule P:N prop.(...pc...) -elim (...(λy:n.y > 0)c...) conv (...c > 0...) 8

Definability of other connectives (constructively) ϕ ψ ϕ ψ x:σ.ϕ := α:prop.α := α:prop.(ϕ ψ α) α := α:prop.(ϕ α) (ψ α) α := α:prop.( x:σ.ϕ α) α Idea: The definition of a connective is an encoding of the elimination rule. 9

Existential quantifier x:σ.ϕ := α:prop.( x:σ.ϕ α) α Derivation of the elimination rule in HOL. x:σ.ϕ C [ϕ]. C x / FV(C, ass.) x:σ.ϕ ( x:σ.ϕ C) C C [ϕ]. C x:σ.ϕ C 10

Existential quantifier x:σ.ϕ := α:prop.( x:σ.ϕ α) α Derivation of the introduction rule in HOL. ϕ[t/x] x:σ.ϕ [ x:σ.ϕ α] ϕ[t/x] ϕ[t/x] α α ( x:σ.ϕ α) α x:σ.ϕ 11

Equality Equality is definable in higher order logic: t and q terms are equal if they share the same properties (Leibniz equality) Definition in HOL (for t, q : A): t= A q := P:A prop.(pt Pq) This equality is reflexive and transitive (easy) It is also symmetric(!) Trick: find a smart predicate P Exercise: Prove reflexivity, transitivity and symmetry of = A. 12

Exercise: Proof of symmetry of = A (Trick: take λy:a.y = A t for P.) t = A q P:A prop.(pt Pq) (t = A t) (q = A t) q = A t... t = A t 13

Exercise The transitive closure of a binary relation R on A has been defined as follows. trclos R := λx, y:a. ( Q:A A Prop.(trans(Q) (R Q) (Q x y))). 1. Prove that the transitive closure is transitive. 2. Prove that the transitive closure of R contains R. 14

(axiom) ϕ if ϕ ( -introduction) ( -elimination) ( -introduction) ( -elimination) (conversion) ϕ ψ ϕ ψ ϕ ψ ϕ ψ ϕ x:σ.ϕ x:σ.ϕ ϕ[t/x] ϕ ψ if x:σ / FV( ) if t : σ if ϕ = β ψ 15

Proofs-as-terms Why not introduce a λ-term notation for the derivations? This gives a type theory λhol No lifting of prop to the type level (via T : prop type). Let prop be a new universe of propositional types. Direct representation (shallow embedding) of HOL into the type theory λhol 16

(axiom) ( -introduction) ( -elimination) ( -introduction) ( -elimination) (conversion) x : ϕ, x:ϕ M : ψ λx:ϕ.m : ϕ ψ M : ϕ ψ N : ϕ M Nψ M : ϕ λx:σ.m : x:σ.ϕ M : x:σ.ϕ M t : ϕ[t/x] M : ϕ M : ψ if x:ϕ if x:σ / FV( ) if t : σ if ϕ = β ψ 17

Two levels Now we have two levels of type theories The (simple) type theory describing the language of HOL The type theory for the proof-terms of HOL NB Many rules, many similar rules. We put these levels together into one type theory λhol. Pseudoterms: T ::= Prop Type Type Var (ΠVar:T.T) (λvar:t.t) TT {Prop, Type, Type } is the set of sorts, S. Some of the typing rules are parametrized 18

(axiom) Prop : Type Type : Type (var) Γ A : s Γ, x:a x : A (weak) Γ A : s Γ M : C Γ, x:a M : C 19

(Π) Γ A : s 1 Γ, x:a B : s 2 Γ Πx:A.B : s 2 if (s 1, s 2 ) { (Type, Type), (Prop, Prop), (Type, Prop) } (λ) (app) Γ, x:a M : B Γ Πx:A.B : s Γ λx:a.m : Πx:A.B Γ M : Πx:A.B Γ N : A Γ MN : B[N/x] (conv) Γ M : A Γ M : B Γ B : s if A = β B 20

(Π) Γ A : s 1 Γ, x:a B : s 2 Γ Πx:A.B : s 2 if (s 1, s 2 ) { (Type, Type), (Prop, Prop), (Type, Prop) } The combination (Type,Type) forms the function types A B for A, B:Type. This comprises the unary predicate types and binary relations types: A Prop and A A Prop. Also: higher order predicate types like (A A Prop) Prop. NB A Π-type formed by (Type,Type) is always an -type. (Prop,Prop) forms the propositional types ϕ ψ for ϕ, ψ:prop; implicational formulas. NB A Π-type formed by (Type,Type) is always an -type. (Type,Prop) forms the dependent propositional type Πx:A.ϕ for A:Type, ϕ:prop; universally quantified formulas. 21

Example Deriving irreflexivity from anti-symmetry Rel := λx:type.x X Prop AntiSym := λx:type.λr:(rel X). x, y:x.(rxy) (Ryx) Irrefl := λx:type.λr:(rel X). x:x.(rxx) 22

Derivation in HOL x A y A R xy R y x y A R xy R y x R xx R xx [R xx] R xx R xx x A.R xx [R xx] 23

Derivation in HOL, with terms z : x A y A R xy R y x zx : y A R xy R y x zxx : R xx R xx [q : R xx] zxxq : R xx [q : R xx] zxxqq : λq:(r xx).zxxqq : R xx λx:a.λq:(r xx).zxxqq : x A.R xx Typing judgement in λhol: A:Type, R:A A Prop, z : Πx, y:a.(r xy R y x ) λx:aλq:(r xx).z xxq q : (Πx:A.R xx ) 24

λhol versus HOL Question: is the type theory λhol really isomorphic with HOL? Yes: we can disambiguate the syntax. [No details.] 25

Properties of λhol Uniqueness of types If Γ M : A and Γ M : B, then A= β B. Subject Reduction If Γ M : A and M β N, then Γ N : A. Strong Normalization If Γ M : A, then all β-reductions from M terminate. Proof of SN is a higher order extension of the one for λ2 (using the saturated sets). 26

Decidability Questions Γ M : σ? Γ M :? Γ? : σ TCP TSP TIP For λhol: TIP is undecidable TCP/TSP: simultaneously. The type checking algorithm is close to the one for λp. (In λp we had a judgement of correct context; this form of judgement could also be introduced for λhol) 27

λhol contains λ2 and λ (Π) Γ A : s 1 Γ, x:a B : s 2 Γ Πx:A.B : s 2 if (s 1, s 2 ) { (Type, Type), (Prop, Prop), (Type, Prop) } This rule allows to form -types on the Type-level (one copy of λ ) -types on the Prop-level (second copie of λ ) Πα:Prop.α α: polymorphic types on the Prop-level (one copie of λ2) 28

Extending λhol (Π) Γ A : s 1 Γ, x:a B : s 2 Γ Πx:A.B : s 2 if (s 1, s 2 ) { (Type, Type), (Prop, Prop), (Type, Prop) } Why not extend λhol to include Higher order logic over polymorphic domains? like ΠA : Type.A A Quantification over all domains? like in ΠA : Type.ΠP:A Prop.Πx:A.P x P x Add (s 1, s 2 ) { (Type, Type) } to obtain higher order logic over polymorphic domains system λu Add (s 1, s 2 ) { (Type, Prop) } to allow quantification over all domains system λu 29

Problem λu (λhol + (Type,Type) and (Type,Prop)) is inconsistent (Girard) λu (λhol + (Type,Type)) is inconsistent (Coquand, Hurkens) NB λhol + (Type,Prop) is consistent. Implications λu can t be used as a logic. In λu, there is a closed term M with M : This M can not be in normal form (by some syntactic reasoning) So, λu is not SN 30

Type Checking Type Checking in λu is still decidable: All types (terms of type Prop, Type or Type ) are strongly normalizing Type Γ (MN) = if Type Γ (M) = C and Type Γ (N) = D then else if C β Πx:A.B and A = β D then B[N/x] else false false, In the type synthesis algorithm we only check equality of types 31

Variations Variations on the rules of λhol: There are many type system with (slightly) different rules Many (proofs of) properties are similar Plan: Study these type systems in one general framework: The cube of typed λ-calculi (Barendregt) Pure Type Systems (Terlouw, Berardi) 32

The λ-cube The cube of typed λ-calculi: (forget about Type for the moment) Vary on all possible combinations for R { (Prop, Prop), (Type, Prop), (Type, Type), (Prop, Type) } in the Π-rule: (Π) Γ A : s 1 Γ, x:a B : s 2 Γ Πx:A.B : s 2 if (s 1, s 2 ) R We take (Prop, Prop) in every R 33

λω λ2 λpω λp2 λω λ λpω λp 34

add (Type, Prop) add (Type, Type) (Prop, Prop) add (Prop, Type) 35

(Π) Γ A : s 1 Γ, x:a B : s 2 Γ Πx:A.B : s 2 if (s 1, s 2 ) R System R λ (Prop, Prop) λ2 (system F) (Prop, Prop) (Type, Prop) λp (LF) (Prop, Prop) (Prop, Type) λω (Prop, Prop) (Type, Type) λp2 (Prop, Prop) (Type, Prop) (Prop, Type) λω (system Fω) (Prop, Prop) (Type, Prop) (Type, Type) λp ω (Prop, Prop) (Prop, Type) (Type, Type) λpω (CC) (Prop, Prop) (Type, Prop) (Prop, Type) (Type, Type) 36

Calculus of Constructions λ in this presentation is equivalent to λ as presented before. Similarly for λ2, λp,...this cube also gives a fine structure for the Calculus of Constructions, CC (Coquand and Huet) Polymorphic data types on the Prop-level, e.g. Πα:Prop.α (α α) α. Predicate domains on the Type-level, e.g. N N Prop Logic on the Prop-level, e.g. ϕ ψ := Πα:Prop.(ϕ ψ α) α. Universal quantification (first and higher order), e.g. ΠP:N Prop.Πx:N.P x P x. 37

HOL in CC One can do higher order predicate logic in CC, in a slightly unusual way: propositions and first order sets are both of type Prop propositions and sets are completely mixed Is it faithful to do higher order predicate logic in CC?? Answer: No! There are non-provable formulas of HOL that become inhabited in CC 38

Consider extensionality of propostions: EXT := α, β:prop.(α β) (α = prop β) In CC, this becomes Πα, β:prop.(α β) (α = Prop β) Suppose two base domains A and B and constants a : A, b : B. In HOL, the following formulas are consistent. ϕ := x:a.x = a, ψ := x:b. y:b.x y But in CC, EXT also applies to the base sets A and B. A B (both are non-empty) so A = Prop B So, in CC, ϕ and ψ are inconsistent so so property ψ (of B) also applies to A x:a. y:a.x y contradicting ϕ 39

We have to be careful when doing higher order logic in CC Or: system λpredω (taking the sets and the propositions apart): Sorts: Prop, Set, Type p, Type s Axioms for these sorts: Prop : Type p, Set : Type s Rules R: (Prop, Prop): implication (Set, Prop): first order quantification (Type p, Prop): higher order quantification (Set, Set): function types (Set, Type p ): predicate types (Type p, Type p ): higher order types 40