polymorphic lambda calculus type theory week 09 2006 04 10 0
overview the course ↔ 1st order propositional logic simple type theory λ → 1st order predicate logic ↔ type theory with dependent types λP ↔ 2nd order propositional logic polymorphic type theory λ 2 1
� � the lambda cube λω λC � � � � � � � � � � � � � � � � � � � � � � λ 2 λP 2 λω λPω polymorphism � � � � � � � � � � � � � � � � � � � � � � λ → dependence λP 2
polymorphism quantification over types we had functions/quantification over the elements of a type fun n : nat => . . . forall n : nat, . . . λn : nat . · · · Π n : nat . · · · we now add functions/quantification over the types themselves fun A : Set => . . . forall A : Set, . . . λA : ∗ . · · · Π A : ∗ . · · · 3
dependent types versus polymorphism • dependent types types can take terms as an argument • polymorphism terms can take types as an argument 4
the polymorphic identity natid identity function on the natural numbers λn : nat . n Definition natid : nat -> nat := fun n : nat => n. Check (natid 0). Eval compute in (natid 0). 5
boolid identity function on the booleans λb : bool . b Definition boolid : bool -> bool := fun b : bool => b. Check (boolid true). Eval compute in (boolid true). 6
polyid polymorphic identity function λA : ∗ . λx : A. x Π A : ∗ . A → A : Definition polyid : forall A : Set, A -> A := fun A : Set => fun x : A => x. Check (polyid nat 0). Check (polyid bool true). Eval compute in (polyid nat 0). Eval compute in (polyid bool true). 7
lists natlist Inductive natlist : Set := natnil : natlist | natcons : nat -> natlist -> natlist. 3 , 1 , 4 , 1 , 5 , 9 , 2 , 6 8
natlist_dep generalizing natlist to a dependent type Inductive natlist_dep : (nat -> Set) := natnil_dep : (natlist_dep O) | natcons_dep : forall n : nat, nat -> (natlist_dep n) -> (natlist_dep (S n)). 9
boollist Inductive boollist : Set := boolnil : boollist | boolcons : bool -> boollist -> boollist. F, T, F, F, F, T, T, F 10
polylist generalizing natlist to a polymorphic type Inductive polylist (A : Set) : Set := polynil : (polylist A) | polycons : A -> (polylist A) -> (polylist A). polylist : forall A : Set, Set polylist : Set -> Set polynil : forall A : Set, (polylist A) polycons : forall A : Set, A -> (polylist A) -> (polylist A) 11
examples of polymorphic lists 3 , 1 polycons nat 3 (polycons nat 1 (polynil nat)) F, T polycons bool false (polycons bool true (polynil bool)) 12
. . . and now in stereo! Inductive polylist_dep (A : Set) : nat -> Set := polynil_dep : (polylist_dep A O) | polycons_dep : forall n : nat, A -> (polylist_dep A n) -> (polylist_dep A (S n)). 13
. . . and even more polymorphic! Inductive polylist’ : Type := polynil’ : polylist’ | polycons’ : forall A : Set, A -> polylist’ -> polylist’. polycons’ nat 3 (polycons’ bool true polynil’) 14
λ 2 terms ∗ , � x , y , z , . . . MN λx : M. N Π x : M. N 15
rules axiom ⊢ ∗ : � Γ ⊢ M : Π x : A. B Γ ⊢ N : A application Γ ⊢ MN : B [ x := N ] Γ , x : A ⊢ M : B Γ ⊢ Π x : A. B : s abstraction Γ ⊢ λx : A. M : Π x : A. B Γ ⊢ A : s Γ , x : A ⊢ B : ∗ product Γ ⊢ Π x : A. B : ∗ 16
rules (continued) Γ ⊢ A : B Γ ⊢ C : s weakening Γ , x : C ⊢ A : B Γ ⊢ A : s variable Γ , x : A ⊢ x : A Γ ⊢ B ′ : s Γ ⊢ A : B conversion Γ ⊢ A : B ′ with B = β B ′ 17
the three product rules both systems Γ ⊢ A : ∗ Γ , x : A ⊢ B : ∗ Γ ⊢ Π x : A. B : ∗ only in λP Γ ⊢ A : ∗ Γ , x : A ⊢ B : � Γ ⊢ Π x : A. B : � nat → ∗ only in λ 2 Γ ⊢ A : � Γ , x : A ⊢ B : ∗ Γ ⊢ Π x : A. B : ∗ Π a : ∗ . a → a 18
minimal second order propositional logic formulas a b c . . . A → B ⊥ ⊤ ¬ A A ∧ B A ∨ B ∀ a. A ∃ a. A 19
rules for → → introduction [ A x ] . . . B I [ x ] → A → B → elimination . . . . . . A → B A E → B 20
rules for ∀ ∀ introduction . . . B I ∀ ∀ a. B a not a free variable in any open assumption variable condition: ∀ elimination . . . ∀ a. B E ∀ B [ a := A ] 21
Curry-Howard-de Bruijn → introduction versus abstraction rule [ A x ] . . . B I [ x ] → A → B Γ , x : A ⊢ M : B Γ ⊢ Π x : A. B : ∗ Γ ⊢ λx : A. M : Π x : A. B 22
→ elimination versus application rule . . . . . . A → B A E → B Γ ⊢ M : Π x : A. B Γ ⊢ N : A Γ ⊢ MN : B [ x := N ] 23
∀ introduction versus abstraction rule . . . B I ∀ ∀ a. B Γ , a : ∗ ⊢ M : B Γ ⊢ Π a : ∗ . B : ∗ Γ ⊢ λa : ∗ . M : Π a : ∗ . B 24
∀ elimination versus application rule . . . ∀ a. B E ∀ B [ a := A ] Γ ⊢ M : Π a : ∗ . B Γ ⊢ A : ∗ Γ ⊢ MA : B [ a := A ] 25
detours and reduction detour elimination for → [ A x ] . . . . . . A . − → . B . . . I [ x ] → . A → B A E → B B 26
detour elimination for ∀ . . . . . . ∗ B − → I ∀ B [ a := A ] ∀ a. B E ∀ B [ a := A ] ∗ replace a everywhere by A 27
typing the proof term of a detour . . . . . . . . Γ , x : A ⊢ M : B Γ ⊢ Π x : A. B : s . Γ ⊢ λx : A. M : Π x : A. B Γ ⊢ N : A Γ ⊢ ( λx : A. M ) N : B [ x := N ] 28
examples activities logic type theory natural deduction type derivations on paper ↓ ↑ → in Coq 29
example 1 ( ∀ b. b ) → a 30
example 2 a → ∀ b. ( b → a ) 31
example 3 a → ∀ b. (( a → b ) → b ) 32
impredicativity Russell’s paradox Cantor: power set is bigger than the set itself naive set theory P ( Set ) ⊆ Set { x | x �∈ x } ∈ { x | x �∈ x } � { x | x �∈ x } �∈ { x | x �∈ x } inconsistent 33
impredicativity λ 2 is impredicative bool : ∗ ⊢ ∗ → bool : ∗ P ( Set ) ∈ Set ⊢ (Π A : ∗ . A ) : ∗ Coq Prop is impredicative, Set is predicative (forall A : Prop, A) : Prop (forall A : Set , A) : Type 34
λ 2 is inconsistent with classical mathematics bool : ∗ ⊢ Π A : ∗ . ( A → bool ) : ∗ ‘set of functions that map each set into a subset of that set’ A ∈ Set P ( A ) ∈ Set U := � U = P ( U ) × . . . 35
the paradox A ∈ Set P ( A ) ∈ Set U := � if u ∈ U then for each A ∈ Set holds that u ( A ) ∈ P ( A ) in particular u ( U ) ∈ P ( U ) X := { u ∈ U | u �∈ u ( U ) } ∈ P ( U ) take some x ∈ U such that x ( U ) = X x ∈ x ( U ) ⇔ x ∈ X ⇔ x �∈ x ( U ) 36
Recommend
More recommend