<<

We shall introduce in a uniform way the eight Lambda calculi typed a la Church Lambda λ →, λ2, λω, λω, λP, λPω, and λPω.

Part III

Typing a la Church The last one is often called λ the calculus of constructions. The eight systems form a cube as Based on materials provided by H. P. Barendregt follows:

Lambda calculus 3 1 3 2

Each edge → represents the inclusion ⊆ . This cube will be referred to as the λ-cube. λω λPω

As we have seen, the systems λ → and λ 2 can be given also a la Curry. A Curry version exists also for λω λ2 λP2 and something similar can be probably given for its weaker version λω.

λω λPω

On the other hand, no natural Curry versions of the systems λ P , λ P 2 , λ P ω and λ C seem possible. λ → λP

Lambda calculus 3 3 Lambda calculus 3 4 λ → Before we define the systems of the λ-cube in a uniform way, we introduce the systems λ → λ in the similar way as the Curry (x : A)∈ Γ and 2 (start rule) systems have been presented. Then it turns out that two of the systems Γ | − x : A of the λ-cube are equivalent to them. Γ | − M : (A → B) Γ | − N : A (→ −elimination) Γ | − (MN) : B Definition. λ → − Church .

T = V | T → T •Types Γ, x : A | − M : B Λ = Λ Λ λ Λ (→ −introduction) •Pseudoterms T V | T T | V : T. Γ | − (λx : A.M ) : (A → B) Γ = •Bases { x 1 : A 1 , K , xn : An } with all x i ∈ distinct and all Ai T. λ → = •Contraction Rule ( x : A.M )N β M[x : N] Where the basis Γ , x : A stands for Γ ∪ { x : A } and it is •Type assignment Γ | − M : A is defined as follows: necessary that the x does not occur in Γ. The letters A, B denote arbitrary types and M,N arbitrary pseudoterms.

Lambda calculus 3 5 Lambda calculus 3 6

The system λ2-Church Examples. •Types T = V | T → T | ∀VT | − (λa : A.a) : (A → A) Λ = Λ Λ Λ λ Λ Λ Λ b : B | − (λa : A.b) : (A → B) •Pseudoterms T V | T T | TT | V : T T | V T b : A | − ((λa : A.a)b) : A c : A,b : B | − (λa : A.b)c : B Γ = •Bases { x 1 : A 1 , K , xn : An } with all | − (λa : A.λb : B.a) : (A → B → A) A ∈ T xi distinct and i

•Contraction rules (λa : A.M )N →β M[a := N]

(Λα.M )A →β M[α := A] •Type assignment Γ | − M : A is defined as follows :

Lambda calculus 3 7 Lambda calculus 3 8 λ2 Examples. (x : A)∈ Γ | − (λa : α.a) : (α → α) (start rule) Γ | − x : A | − (Λαλa : α.a) : (∀α.α → α) − Λαλ α → Γ | − M : (A → B) Γ | − N : A | ( a : .a)A : (A A) (→ −elimination) − Λαλ α Γ | − (MN) : B b : A | − (Λαλa : α.a)Ab : A Γ, x : A | − M : B (→ −introduction) For more advanced,check that the following reduction holds Γ | − (λx : A.M ) : (A → B) | − (Λαλαλa : α.a)Ab → (λa : A.a)b → b Γ | − M : (∀α.A) | − (Λβλa : (∀α.α).a((∀α.α) → β)a) : (∀β.(∀α.α) → β) (∀ − elimination) B ∈ T Γ | − MB : A[α := B] For less advanced − Λββλλ ∀α α αβ ∀β ∀α α → β Γ | − M : A | ( a : ( . ). ) : ( .( . ) ) (∀ − introduction) α ∉ FV (Γ) Γ | − (Λα.M ) : (∀α.A) Without a proof: Church-Rosser property holds for the reduction of pseudoterms in λ2. Lambda calculus 3 9 Lambda calculus 3 10

Dependency. In λ → and λ 2 one has also abstraction for the two types of Types are dependent on terms and vice versa. There are four cases: dependence. For the two examples above terms depending on terms λm : A.Fm : A → B terms depending on types types depending on terms Λα.Gα : ∀α.α → α types depending on types The systems λ ω and λP. The first two sorts of dependency are presented in λ → and λ2. In λ → , we have We shall show the remaining two dependencies: in particular with → F : A B M : A ⇒ FM : B types FA in λ ω depending on types and FM in λ P depending on Here FM is a depending on a term, in particular on M. terms.

In λ , we have 2 We will also have function abstractions for these dependencies both ∀α α → α → G : . A a type ⇒ GA : A A in λ ω and λ P . Hence for G ≡ Λ αλα λ a : α . a , we have GA a term depending on the type A.

Lambda calculus 3 11 Lambda calculus 3 12 The system λ ω : Types depending on types. ≡ λα ∗ α → α α → α Now, we can write f : . for the f above. But we is a natural example of a type depending on a type α. have to ask, where this f live. Neither on the level of terms, nor We would like to define a term f = λα ∈ T.α → α with a new among the types. form of abstraction such that f ( α ) = α → α . This will be possible in λ ω . To do this, it is not possible to define types in an It is necessary to introduce a new class K, the elements of which are informal metalanguage as we have done so far. It is necessary called kinds. generate the type by the system itself. K = ∗ |K → K Hence Kinds and constructors. ∗, ∗ → ∗, ∗ → ∗ → ∗,K are kinds and Informally, take a constant ∗ such that σ :∗ corresponds to σ ∈ T. K = {∗, ∗ → ∗, ∗ → ∗ → ∗,K } The informal statement α,β∈ T ⇒ (α → β)∈ T It is necessary to introduce one more class such that k : corresponds to k ∈ K . If | − k : and | − F : k , then F is called a constructor of Now be comes the formal kind k. Each element of T will be a constructor of kind ∗. α :∗, β :∗ | −(α → β) :∗

Lambda calculus 3 13 Lambda calculus 3 14

Example.

We shall show later on that

Definition. Types and terms of λω : | − (λα :∗.α → α) : (∗ → ∗) 1424 434 f •Sorts ∗ , two constants selected from C. Hence the above function f is a constructor of kind ∗ → ∗ . •Class K = ∗ | K → K the elements are called kinds. •A set of pseudoexpressions T

Although the types and terms can be kept separate, we will T = V | C |TT | λV :T |T → T consider them as a subset of one general set T of pseudo- expressions. where V is an infinite collection of variables and C of constants.

Lambda calculus 3 15 Lambda calculus 3 16 Statements, bases - a motivation Definition. Contexts for λω. As terms and types belong to the same set T , the definition of statement is modified accordingly, bases have both types of variables (i) A statement of λ ω is of form M : A with M , A∈T. as subjects and have to become linearly ordered. That is why we call them contexts. (ii) A is a finite linearly ordered set of statements with distinct variables as subjects. We shall denote them by Γ, ∆. The reason is that in λ ω one wants to derive K α :∗, x : α | − x : α (iii) <> denotes the empty context. If Γ = < x : A , , x : A > α :∗ | − (λx : α.x) : (α → α) 1 1 K n n then Γ = < > , y : B x1 : A1 ,K, xn : An , y : B But not x : α, α :∗ | − x : α Γ − x : α | − (λα :∗.x) : (∗ → α) (iv) The (type) assignment | λ ω M : A is derived by the following axioms and rules. The letter s ranges over sorts.

in which α occurs both free and bound.

Lambda calculus 3 17 Lambda calculus 3 18

λω <>| − ∗ : (axiom) Γ | − A : s x ∉Γ Examples. (start rule) Γ, x : A | −x : A α ∗ β ∗ − α → β ∗ Γ | − A : B Γ | − C : s : , : | λω : (weakening rule) x ∉ Γ Γ, x : C | − A : B α :∗,β :∗, x : (α → β) | −λω x : (α → β) α ∗ β ∗ − λ α → β α → β → α → β Γ | − A : s Γ | − B : s : , : | λω ( x : ( ).x) : (( ) ( )) (type/kind formation) Γ | − (A → B) : s Γ | − F : (A → B) Γ | − a : A (application rule) ≡ λβ ∗ β → β Γ | − Fa : B Put D : . . Then the following hold. Γ, x : A | − b : B Γ | − (A → B) : s (abstraction rule) − ∗ → ∗ Γ | − (λx : A.b) : (A → B) | λω D : ( )

α :∗ | −λω (λx : Dα.x) : D(Dα) Γ | − A : B Γ | − B´: s B = B´ (conversion rule) β Γ | − A : B´

Lambda calculus 3 19 Lambda calculus 3 20 Cartesian products.

Suppose that for each a:A a type B is given such that there is The system λP: Types depending on terms. a an element b a : B a . Then we may want to form the function

n λ A → B is an intuitive example of a type depending on a term. In a : A.ba order to formalize this dependence in λP, we need to extend the class K of kinds as follows: that should have as a type the cartesian product if A is a type and k ∈ K then A → k ∈ K. ∏ a : A.Ba of types B ´s. In particular A → ∗ is a kind and if f : A → ∗ and a ∈ A, a one has fa :∗. Once these product types are allowed, the type constructor → can be eliminated. We can write

The fa is a type depending on a term. Moreover, we (A → B) ≡ ∏ a : A.B have function abstraction for this dependency. where a is a variable not occuring in B.

Lambda calculus 3 21 Lambda calculus 3 22

Assignment rules for λP.

Types and terms of λP. Statements of the form M : A with M , A ∈ T and contexts are defined as for λω. (i) The set T of pseudo-expressions of λP is defined as follows ≡ λ Π T V | C |TT | V :T.T | V :T.T Contexts are finite linearly ordered sequences of statements.

Where V is the set of all variables and C that of constants. No distinction between type variables and term variables is Sorts are two constants denoted by ∗ and . Again, the letter s made. ranges over the set of sorts.

(ii) Among the constants C two elements are called ∗ and . The notion | − is defined by the following axiom and rules.

Lambda calculus 3 23 Lambda calculus 3 24 λP

<>| − ∗ : (axiom) Γ | − A : s x ∉Γ Exercises. (start-rule) Γ, x : A | − x : A

Γ | − A : B Γ | − C : s A :∗ | − (A → ∗) : (weakening rule) x ∉Γ Γ, x : C | − A : B A :∗, P : A → ∗, a : A | − Pa :∗ Γ | − A :∗ Γ, x : A | − B : s ∗ → ∗ − → ∗ (type/kind formation) A : , P : A , a : A | Pa : Γ | − (Πx : A.B) : s A :∗, P : A → ∗ | − (Πa : A.Pa → ∗) : Γ − Π Γ − ∗ → ∗ − λ λ Π → (application rule) | F : ( x : A.B) | a : A A : , P : A | ( a : A x : Pa.x) : ( a : A.(Pa Pa)) Γ | − Fa : B[x := a] Γ, x : A | − b : B Γ | − (Πx : A.B) : s (abstraction rule) Γ | − (λx : A.b) : (Πx : A.B) Γ − Γ − = (conversion rule) | A : B | B´: s B β B´ Γ | − A : B´

Lambda calculus 3 25 Lambda calculus 3 26

λP and Logic. ( of λP) To guarantee that the implication has the right properties, one ⊃ ⊃ assumes e and i such that Systems similar to λP have been introduced by ⊃ ϕψ ϕ ⊃ ψ → ϕ → ψ N. G. De Bruijn in the 1970s and 1980s in order to represent e :T( ) T T mathematical and their proofs. ⊃ ϕψ ϕ → ψ → ϕ ⊃ ψ i : (T T ) T( )

Now for representation of implicational logic Idea. Assume that there is a set prop closed under implication. we choose to work in context Γ consisting of This can be done by context prop

Γ ≡ < ∗ → → > Γ 0 prop : , Imp : prop prop prop 0 T : prop → ∗ •We shall write ϕ ⊃ ψ for Imp ϕψ. ⊃ Πϕ Πψ ϕ ⊃ ψ → ϕ → ψ e : : prop : prop.T( ) T T •A variable T : prop → ∗ is declared and ϕ : prop ⊃ : Πϕ : propΠψ : prop.(Tϕ → Tψ) → T(ϕ ⊃ ψ) is declared to be valid if T ϕ is inhabited. i

Lambda calculus 3 27 Lambda calculus 3 28 Example. Simplified notation. prop ∗ We want to show that ϕ ⊃ ϕ is valid for all . We LL need to show that its translation as a type T ( ϕ ⊃ ϕ ) is inhabited. ⊃ LLL → We have T LLL I (identity)

⊃ ϕψ Then for e one can use ϕ : prop T : prop → ∗ (context) λx : (ϕ → ψ)λy : ϕ.xy Tϕ :∗ (application) (assumption) x :Tϕ 1 ⊃ ϕψ 1 and for i λ ϕ ϕ → ϕ (abstraction) ( x :T .x) : (T T ) λx : (ϕ → ψ).x ⊃ ϕϕ λ ϕ ϕ → ϕ (context, application) ( i ( x :T .x)) :T( ) Hence In this way the { → , ∀ } fragment of (manysorted, constructive) Γ − ⊃ ϕϕ λ ϕ ϕ → ϕ prop | λP ( i ( x :T .x)) :T( ) logic can be interpreted in λP. A predicate on a type with the domain A is represented as the statement P : (A → ∗).

Lambda calculus 3 29 Lambda calculus 3 30

One defines Pa for a:A to be valid, if it is inhabited. Quantification is translated as follows The system λP deserved its name because predicate logic can be interpreted in it. ∀x ∈ A.Px LL > Πx : A.Px The method interprets Example.

propositions, formulas types Formula LL (∀x ∈ A∀y ∈ A.Pxy) → (∀x ∈ A.Pxx) proofs LLLLLLLL terms inhabiting the types is valid, since its translation is inhabited:

A :∗, P : A → A → ∗ | − (λz : (Πx : AΠy : A.Pxy)λx : A.zxx) : The method is often called propositions as types paradigm and it is used for formulating results in the foundations of mathematics. ([Πx : AΠY : A.Pxy] → [Πx : A.Pxx])

Lambda calculus 3 31 Lambda calculus 3 32 (iii) OnT the notions of β-conversions and β-reductions are Systems of the λ-cube: A uniform definition. defined by the following contraction rule (λx : A.B)C → B[x := C] (i) The setT of pseudo-expressions of λP is defined as follows (iv) A statement is of the form A : B where A , B ∈ T. We call A the subject and B the predicate of the statement A:B. T ≡ V | C |TT | λV :T.T | Π V :T.T A declaration is a statement with a variable as the subject and with a pseudo-expression as the predicate. Where V is the set of all variables and C that of constants. No distinction between type variables and term variables is made. We use A,B,C,…a,b,c,… for pseudo-terms and x,y,z,… for (v) A pseudo-context is a finite ordered sequence of declarations, all variables. with distinct subjects. The empty pseudo-context is denoted by <> (usually we do not write it). Given a pseudo-context Γ =< x : A , , x : A > (ii) Two constants are selected and denoted by∗ and . 1 1 K n n They are called sorts. The letter s ranges over the set of sorts. its is defined as follows: Γ = < > , x : B x1 : A1 ,K, xn : An , x : B .

Lambda calculus 3 33 Lambda calculus 3 34

Systems of the λ-cube 1. General axiom and rules. <>| − ∗ : (vi) The notion Γ | − A : B states that A:B can be derived from (axiom) Γ | − A : s the pseudo-context Γ, in this case we say that A and B are legal x ∉Γ expressions and Γ is a legal pseudo-context. The notion is (start-rule) Γ, x : A | − x : A axiomatized by the rules of type assignment. Γ | − A : B Γ | − C : s (weakening rule) x ∉ Γ Γ, x : C | − A : B Γ | − F : (Πx : A.B) Γ | − a : A The rules are divided into two groups: (application rule) Γ | − Fa : B[x := a] a) general axiom and rules valid for all systems of λ-cube, Γ, x : A | − b : B Γ | − (Πx : A.B) : s (abstraction rule) b) the specific rules differentiating the eight systems (usually Γ | − (λx : A.b) : (Πx : A.B) parametrized Π-introduction rules).

Γ | − A : B Γ | − B´: s B =β B´ (conversion rule) Γ | − A : B´

Lambda calculus 3 35 Lambda calculus 3 36 2. The specific rules. Γ − Γ − | A : s1 , x : A | B : s2 System Set of specific rules (s1 , s2 ) rule Γ − Π | ( x : A.B) : s2 λ → ( ∗∗∗ , ∗ ) λ2 ( ∗∗∗ , ∗ ) ( , ∗ ) We select four specific rules λP ( ∗ , ∗ ) ( ∗ , ) (∗, ∗), (∗, ), ( , ∗), ( , ) λP2 ( ∗ , ∗ ) ( , ∗ ) (∗ , ) λω ( ∗∗∗ , ∗ ) ( , ) And the eight systems of λ-cube consist of the general rules λω ( ∗∗∗ , ∗∗∗ ) ( , ∗ ) ( , ) together with a specific subsets of the above specific rules. λPω ( ∗∗∗ ,∗ ) ( , ∗ ) ( , ) λ ω = λ The sets of specific rules for the eight systems are depicted in the P C ( ∗ , ∗ ) ( , ∗∗∗ ) ( ∗ , ) ( , ) table below.

Lambda calculus 3 37 Lambda calculus 3 38

λ-cube System related system names and λ → λτ Simply λω λ ω [Church 1940] P [Barendregt 1984] [Hindley and Seldin 1986] λ2 F Second order (typed) lambda calculus [Girard 1972] λ2 λP2 [Reynolds 1974] λP AUT − QE, LF [de Bruin 1970] [Harper et al. 1987] λP2 [Longo and Moggi 1988] λω λPω λω POLYREC [Renardel de Lavalette 1991] λω Fω [Girard 1972] λ → λP λPω CC Calculus of constructions [Coquand and Huet]

Lambda calculus 3 39 Lambda calculus 3 40 Remarks. (ii) Terms depending on types and types depending on types in λ → .

(i) Impredicativity. The expression λx : A.x is a term depending on type A A → A is a type depending on the type A (Πα :∗.(α → α)) but in λ → we have no function abstraction for these dependencies. in λ2 as a cartesian product of types, will be a type, too. So

(iii) Note that in λ → and even in λ 2 and λω one has no − Πα ∗ α → α ∗ | ( : .( )) : types depending on terms. The types are given beforehand. Thus the right-hand side of the cube is essentially more difficult than the but since it is a product over all possible types α, left-hand side because of the mixture of types and terms. including ( Π α : ∗ .( α → α )) itself, there is an essential impredicativity here.

Lambda calculus 3 41 Lambda calculus 3 42

λ → λ Equivalence of both versions of and 2. Lemma. Γ − ∗ Recall the definition A → B ≡ Π x : A . B where x is not in A, B. Consider λ → in the λ-cube. If | A : in this system, then A is built up from the set{B | (B :∗)∈ Γ} using only → as defined above. Notice that application rule in the λ-cube implies the ( → − eliminatio n) rule: Proof. Γ | − F : (A → B) ≡ Πx : A.B Γ | − a : A By induction on the generation of | −. Γ | − (Fa) : B[x := a] ≡ B

Since x does not occur in B. It follows that if we have To show that both versions of λ2 are the same, we have to define A :∗, B :∗,a : A,b : B | −M : C :∗ ∀α.A ≡ Πα :∗.A in λ → in λ-cube then Λα.M ≡ λα :∗.M a : A,b : B | −M : C is derivable in the original system λ → . The notation Γ | − M : C :∗ in the λ-cube. . stands for the conjunction Γ | − M : C and Γ | − C :∗. Lambda calculus 3 43 Lambda calculus 3 44 Examples. (b) In λ2 one can derive (a) in λ → one can derive

α :∗ | − (λa : α.a) : (α → α) A :∗ | − (Πx : A.A) :∗ | − (λα :∗λa : α.a) : (Πα :∗.(α → α)) :∗ A :∗ | − (λa : A.a) : (Πx : A.A) A :∗ | − (λα :∗λa : α.a)A : (A → A) A :∗, B :∗,b : B | − (λa : A.b) : (A → B) A :∗,b : A | − (λα :∗λa : α.a)Ab : A where (A → B) ≡ (Πx : A.B)

Notice that for the last line the following reduction holds: A :∗,b : A | − ((λa : A.a)b) : A A :∗, B :∗,c : A,b : B | − ((λa : A.a)b) : A (λα :∗λa : α.a)Ab → (λa : A.a)b A :∗, B :∗ | − (λa : Aλb : B.a) : (A → (B → A)) :∗ → b

Lambda calculus 3 45 Lambda calculus 3 46

(c) In λ ω one can derive e.g. Connection of λ2 with second-order propositional logic. | − (λα :∗ .α → α) : (∗ → ∗) : Exercise. {( λα : ∗ . α → α ) is a constructor mapping types into types} | −λ (λβ :∗λa : (Πα :∗.a).a((Πα :∗.α) → β)a) : (Πβ :∗.(Πα :∗.α) → β) 2 1424444444 434444444 142444 43444 subject predicate Proof.

∗ ∗ α ∗ α ∗ : x :∗ ∗ : ( , ) Simplification: put ⊥ ≡ ( Π α : ∗ . α ) which is the definition of the ( , ) : x : second-order falsum. Using this, we may write (Πx : α.α) :∗ (Πx :∗.∗) : 1424 434 142 43 α → α ∗ → ∗ | − (λβ :∗λa : ⊥.aβ) : (Πβ :∗.⊥ → β) (λα :∗.α → α) : (∗ → ∗) : 1424 434 1424 434 subject predicate Similarly one can derive The predicate (type) considered as a proposition says: ex falso β :∗ | − (λα :∗.α → α)β :∗ sequitur quodlibet („anything follows from a false statement“) β ∗ β − λ β λα ∗ α → α β and the subject (term) is its proof. : , x : | ( y : .x) : ( : . )

Lambda calculus 3 47 Lambda calculus 3 48 (d) λP-Propositions as types.

the following can be derived:

Higher-order constructors. A :∗ | − (A → ∗) : They are formed in the following way {If A is a type considered as a set, then A → ∗ is the kind of predicates on A.} α :∗, f :∗ → ∗ | − f ( fα) :∗ α :∗ | − (λf :∗ → ∗. f ( fa)) : (∗ → ∗) → ∗ (i) if A is a non-empty set, a ∈ A and P is a predicate on A, then Pa is a type considered as a proposition which is true if inhabited, otherwise false.

A :∗, P : (A → ∗), a : A | − Pa :∗

Lambda calculus 3 49 Lambda calculus 3 50

(vi) A type considered as a (true) proposition. (ii) if P is a binary predicate on the set A, then ∀ a ∈ A Paa is a proposition. A :∗, P : A → ∗, Q :∗ | − ((Πa : A.Pa → Q) → (Πa : A.Pa) → Q) :∗ A :∗, P : (A → A → ∗) | − (Πa : A.Paa) :∗ We have proved that the type on the right hand is a proposition, to be (iii) if P and Q are two unary predicates on a set A, then the true, we have to assume that A is non-empty. predicate P considered as a set is included in Q. ∗ → ∗ ∗ − A : , P : A , Q : , a0 : A | A :∗, P : A → ∗, Q : A → ∗ | − (Πa : A.(Pa → Qa)) :∗ λ Π → λ Π ( x : ( a : A.Pa Q) y : ( a : A.Pa).xa0 ( ya0 )Q) : (Πx : (Πa : A.Pa → Q)Πy : (Πa : A.Pa).Q) (iv) proposition stating the reflexivity of inclusion. 1424444444 434444444 (Πa:A.Pa→Q)→(Πa:A.Pa)→Q A :∗, P : A → ∗ | −(Πa : A(Pa → Pa)) :∗ This proposition as a type states that proposition (v) „proof“ of the reflexivity of inclusion. (∀a ∈ A.Pa → Q) → (∀a ∈ A.Pa) → Q A :∗, P : A → ∗ | − (λa : A λx : Pa.x) : (Πa : A.(Pa → Pa)) : ∗ 14244 4344 subject is true in non-empty structures A. Lambda calculus 3 51 Lambda calculus 3 52 (e) λω - conjunction

The second-order definition of conjuntion is defined as follows α & β ≡ Πγ :∗.(α → β → γ) → γ, The subject of the following assignment is a proof that {it is definable already in λ2}, but in λω can be derived α ∗ β ∗ −α β ∗ : , : | & : ANDαβ → α Let is a tautology. AND ≡ λα :∗ λβ :∗.α &β and K ≡ λα :∗ λβ :∗ λx : α λy :β.x α :∗, β :∗ | − (λx : ANDαβ.xα(Kαβ)) : (ANDαβ → α) : ∗ then | − AND : (∗ → ∗ → ∗) | − K : (Πα :∗ Πβ :∗ .α → β → α)

Note that while α&β and K can be derived already in λ2, AND cannot.

Lambda calculus 3 53 Lambda calculus 3 54

(g) λPω gives the following derivation.

(f) λP2 is corresponding to second-order predicate logic.

A :∗ | − (λP : A → A → ∗ λa : A .Paa) : ((A → A → ∗) → (A → ∗)) : In it the following can be derived

∗ → ∗ − λ → ⊥ → ∗ This constructor assigns to a binary predicate P on A its diagonalization. A : , P : A | ( a : A. Pa ) : (A ) The same can be done uniformly in A. A :∗, P : A → A → ∗ | − [(Πa : A Πb : A .Pab → Pba → ⊥) → → (Πa : A .Paa → ⊥)]: ∗ | − (λA :∗ λP : A → A → ∗ λa : A .Paa) : Π ∗ Π → → ∗ Π ∗ The proposition states that a binary relation that is asymetric ( A : P : A A a : A . ) : is irreflexive.

Lambda calculus 3 55 Lambda calculus 3 56 (h) λPω = λC The calculus of constructions. Exercises.

a) Define ¬ ≡ λα : ∗ . α → ⊥ . Construct a term M such that in (i) A constructor can be derived that assigns to a type A and to λω a predicate P on A the of P. α :∗, β :∗ | − M : ((α → β) → (¬β → ¬α))

| − (λA :∗ λP : A → ∗ λa : A .Pa → ⊥) : b) Find an expression M such that in λP2, we have (ΠA :∗ .(A → ∗) → (A → ∗)) : A :∗, P : (A → A → ∗) | − (ii) Universal quantification done uniformly: M :[(Πa : A Πb : A .Pab → Pba → ⊥) → (Πa : A Paa → ⊥)]:∗

Let ALL ≡ ( λ A : ∗ λ P : A → ∗ . Π a : A . Pa ) then c) Find a term M such that in λC, we have

A :∗, P : A → ∗ | − ALL AP :∗ and (ALL AP) =β (Πa : A .Pa) A :∗, P : A → ∗, a : A | −M : (ALL AP → Pa)

Lambda calculus 3 57 Lambda calculus 3 58

The pure types systems are based on the same set of pseudoterms as systems of the λ-cube. Pure Type systems: A generalization of the λ-cube. T = V | C |TT | λV :TT | ΠV :TT

• Many systems of typed lambda calculus a la Church can be seen as Pure Definition. The specification of a Pure consists of a Type Systems. triple S = (S, A, R) where • One of the successes of the notion of Pure Type Systems is concerned with Logic: eight logical systems are shown to be in correspondence with • S is a subset of C, the elements of S are called sorts. the systems on the λ-cube. • A is a set of axioms of the form • The general setting of Pure Type systems makes it easier to give the c : s required proof with c ∈C and s ∈ S. R is a set of rules of the form ∈ (s1 , s2 , s3 ) with s1 , s2 , s3 S.

Lambda calculus 3 59 Lambda calculus 3 60 Thw set of variables V is stratified according to sorts into disjoint ∈ = ∪ ∈ infinite subsets V s for each sort s S . Hence V { V s | s S }. s s s Definition. The members of V s are denoted x , y , z , K

The given by specification S = (S, A, R) is Arbitrary variables are still denoted by x,y,z,… if necessary one denoted by λS = λ(S, A, R). Its properties are defined as follows. ≡ s ∈ writes x x for x Vs . •Statements and contexts are defined as for the λ-cube Γ − •The notion of type derivations | λ S A : B is defined by the The first version of λ2 can be understood as following axioms and rules

x,y,z,… ranging over V ∗ and α, β, γ, K over V

Lambda calculus 3 61 Lambda calculus 3 62

λ(S, A, R) if (c : s)∈ A <>| − c : s The side condition ( B = β B ´) is not decidable. However it can (axioms) be replaced by the decidable condition Γ | − A : s if x≡ sx ∉ Γ → → (start) Γ, x : A | − x : A B´ B or B B´

Γ | − A : B Γ | − C : s s with no effect on the set of derivable statements. (weakening) if x≡ x ∉ Γ Γ, x : C | − A : B Γ − Γ − Definition. | A : s1 , x : A | B : s2 (s , s , s )∈ R (product) Γ − Π 1 2 3 | ( x : A.B) : s3 (i) The rule ( s 1 , s 2 ) is an abbreviati on for ( s 1 , s2 , s2 ). In the Γ | − F : (Πx : A.B) Γ | − a : A λ-cube only systems with rules of this simple form are used. (application) Γ | − Fa : B[x := a] Γ, x : A | − b : B Γ | − (Πx : A.B) : s (ii) The Pure type system is full if (abstraction) Γ | − (λx : A.b) : (Πx : A.B) R = S × S = {(s , s ) | s , s ∈ S}. Γ − Γ − = 1 2 1 2 (conversion) | A : B | B´: s B β B´ Γ | − A : B´

Lambda calculus 3 63 Lambda calculus 3 64 Examples. The system of higher order logic [Church 1940] can be described as follows. S ∗, λ → A ∗ : S ∗, ,∆ R (∗,∗) λHOL A ∗ : , : ∆ R (∗,∗), ( ,∗), ( , ) S ∗, The system below is a subsystem of λ → An λ2 A ∗ : . interesting conjecture of de Bruijn states that ∗ ∗ ∗ R ( , ),( , ) mathematics from before the year 1800 can all be formalized in it. S ∗, S ∗, ,∆ λC A ∗ : λPAL A ∗ : R (∗,∗),( ,∗),(∗, ),( , ) R ( , ,∆), (∗,∆,∆) ( ,∆,∆) It is a full system.

Lambda calculus 3 65 Lambda calculus 3 66

Substitution lemma. Definition. Legal contexts and legal pseudoterms. Assume Γ, x : A,∆ | − B : C Let Γ be a pseudocontext and A a pseudoterm. and Γ | − D : A (i) Γ is called legal if Γ |- P:Q for some pseudoterms P,Q. (ii) A pseudoterm A is called legal if there is a pseudocontext Then Γ,∆ [x := D] | − B [x := D]: C [x := D] Γ and pseudoterm B such that Γ|-A:B or Γ|-B:A.

Thinning lemma. Transitivity lemma. ∆ Γ ⊆ ∆ Let Γ and ∆ be contexts of which Γ is legal. Then Let Γ and be legal contexts and . Then

[Γ | − ∆ and ∆ | − A : B] ⇒ Γ | − A : B Γ | − A : B ⇒ ∆ | − A : B

Lambda calculus 3 67 Lambda calculus 3 68 Generation lemma

(i) Γ | − c : C ⇒ ∃s ∈ S [C =β s & (c : s)∈ A] Subject reduction . (ii) Γ | − x : C ⇒ ∃s ∈ S ∃B =β C [Γ | − B : s & (x : B)∈ Γ & x≡ sx] Γ | − A : B & A →>β A´ ⇒ Γ | − A´: B Γ − Π ∃ ∈ Γ − (iii) | ( x : A.B) : C ⇒ (s1 , s2 , s3 ) R [ | A : s1 & Γ, x : A | − B : s & C = s ] 2 β 3 Condensing lemma.

(iv) Γ | − (λx : A.b) : C ⇒ ∃s ∈ S ∃B [Γ | − (Πx : A.B) : s & If x is not free in ∆, B, C, then Γ, x : A | − b : B & (C = (Πx : A.B)] β Γ, x : A,∆ | − B : C ⇒ Γ,∆ | − B : C

(v) Γ | − (Fa) : C ⇒ ∃A, B [Γ | − F : (Πx : A.B)&

Γ | − a : A& C =β B [x := a]]

Lambda calculus 3 69 Lambda calculus 3 70

Definition. Simply sorted systems. Definition. Strong normalization for the λ-cube.

Let λS = λ(S,A,R) be a Pure type system. λS is called Let λS be a Pure type system. We call it strongly normalizing and singly sorted if write λS |= SN if all legal terms of λS are SN, i.e ∈ ≡ Γ − (i) (c1 : s1 ), (c2 : s2 ) A ⇒ s1 s2 | A : B ⇒ SN(A)& SN(B)

(ii) (s , s , s ), (s , s , s ´)∈ R ⇒ s ≡ s ´ 1 2 3 1 2 3 3 3 Theorem. Strong normalization for the λ-cube. Uniqueness of types for singly sorted Pure type systems. For all systems in the λ-cube, we have the following Let λS be a singly sorted Pure type system. Then (i) Γ | − A : B ⇒ SN(A)& SN(B) Γ − Γ − = | A : B1 & | A : B2 ⇒ B1 β B2 − (ii) x1 : A1 ,K, xn : An | B : C ⇒ A1 ,K, An , B, C are SN

Lambda calculus 3 71 Lambda calculus 3 72 Representing logics. Eight systems of intuitionistic logic correspond in some sense •All these systems are minimal logics, the only logical operators are to the systems in the λ-cube: there are four systems of → and ∀. propositional logic and four systems of many sorted predicate • However, for the second- and higher-order systems, the operators logic. ¬, &, ∨ and ∃ are all definable. PROP propositional logic • Weakly higher-order logics have variables for higher-order PROP2 second-order propositional logic propositions or predicates but no quantification over them. PROP ω weakly higher-order proposition logic • A higher-order propositions have lower order propositions as PROPω higher-order proposition logic . PRED predicate logic PRED2 second-order predicate logic • All the above logics are intuitionistic. The classical versions of PREDω weakly higher-ordered predicate logic the logics in the upper plane of the logic-cube (see below) are obtained by adding as axiom ∀α.¬¬α → α. PREDω higher-order predicate logic • The systems form a cube as shown below.

Lambda calculus 3 73 Lambda calculus 3 74

PROPω PREDω

PROP2 PRED2 Each system L i on the logic-cube corresponds to the λ system i on the corresponding vertex. The edges of the logic-cube represent inclusions of the systems in the same way as on the λ-cube. PROPω PREDω

PROP PRED

This cube will be referred as logic-cube.

Lambda calculus 3 75 Lambda calculus 3 76 Propositions as types: the idea. In fact an inhabitant of A in λP can be found canonically from a proof of A in PRED. Different proofs of A are interpreted as different terms of type A . A formula in the logic L i on the logic-cube can be interpreted as a type A in the corresponding λ on the i λ-cube . Soundness can be shown all systems L with respect to the λ i corresponding systems i of the λ-cube . The transition A a A Completness.

Is called propositions-as-types interpretation of Li . Completness is defined naturally: if A is a formula of the Soundness. λ logic L i such that the type A is inhabited in i , then A The propositions-as-types interpretation satisfies the is provable in Li . following soundness result: For the proposition logics it is trivially true. Completnes If A is provable in PRED, then A is inhabited in λP was proved for PRED with respect to λP. For PREDω with respect to λC fails.

Lambda calculus 3 77 Lambda calculus 3 78