polymorphic lambda calculus type theory week 09 2006 04 10 0 - - PowerPoint PPT Presentation

polymorphic lambda calculus
SMART_READER_LITE
LIVE PREVIEW

polymorphic lambda calculus type theory week 09 2006 04 10 0 - - PowerPoint PPT Presentation

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


slide-1
SLIDE 1

polymorphic lambda calculus

type theory week 09 2006 04 10

slide-2
SLIDE 2
  • verview

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

slide-3
SLIDE 3

the lambda cube

λω λC λ2

  • polymorphism

λP2

  • λω

λPω λ→

dependence

  • λP
  • 2
slide-4
SLIDE 4

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

slide-5
SLIDE 5

dependent types versus polymorphism

  • dependent types

types can take terms as an argument

  • polymorphism

terms can take types as an argument

4

slide-6
SLIDE 6

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

slide-7
SLIDE 7

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

slide-8
SLIDE 8

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

slide-9
SLIDE 9

lists

natlist

Inductive natlist : Set := natnil : natlist | natcons : nat -> natlist -> natlist. 3, 1, 4, 1, 5, 9, 2, 6

8

slide-10
SLIDE 10

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

slide-11
SLIDE 11

boollist

Inductive boollist : Set := boolnil : boollist | boolcons : bool -> boollist -> boollist. F, T, F, F, F, T, T, F

10

slide-12
SLIDE 12

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

slide-13
SLIDE 13

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

slide-14
SLIDE 14

. . . 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

slide-15
SLIDE 15

. . . and even more polymorphic!

Inductive polylist’ : Type := polynil’ : polylist’ | polycons’ : forall A : Set, A -> polylist’ -> polylist’. polycons’ nat 3 (polycons’ bool true polynil’)

14

slide-16
SLIDE 16

λ2

terms

∗, x, y, z, . . . MN λx : M. N Πx : M. N

15

slide-17
SLIDE 17

rules

⊢ ∗ : axiom Γ ⊢ M : Πx : A. B Γ ⊢ N : A Γ ⊢ MN : B[x := N] application Γ, x : A ⊢ M : B Γ ⊢ Πx : A. B : s Γ ⊢ λx : A. M : Πx : A. B abstraction Γ ⊢ A : s Γ, x : A ⊢ B : ∗ Γ ⊢ Πx : A. B : ∗ product

16

slide-18
SLIDE 18

rules (continued)

Γ ⊢ A : B Γ ⊢ C : s Γ, x : C ⊢ A : B weakening Γ ⊢ A : s Γ, x : A ⊢ x : A variable Γ ⊢ A : B Γ ⊢ B′ : s Γ ⊢ A : B′ conversion with B =β B′

17

slide-19
SLIDE 19

the three product rules

both systems Γ ⊢ A : ∗ Γ, x : A ⊢ B : ∗ Γ ⊢ Πx : A. B : ∗

  • nly in λP

Γ ⊢ A : ∗ Γ, x : A ⊢ B : Γ ⊢ Πx : A. B : nat → ∗

  • nly in λ2

Γ ⊢ A : Γ, x : A ⊢ B : ∗ Γ ⊢ Πx : A. B : ∗ Πa : ∗. a → a

18

slide-20
SLIDE 20

minimal second order propositional logic

formulas

a b c . . . A → B ⊥ ⊤ ¬A A ∧ B A ∨ B ∀a. A ∃a. A

19

slide-21
SLIDE 21

rules for →

→ introduction [Ax] . . . B A → B I[x]→ → elimination . . . A → B . . . A B E→

20

slide-22
SLIDE 22

rules for ∀

∀ introduction . . . B ∀a. B I∀ variable condition: a not a free variable in any open assumption ∀ elimination . . . ∀a. B B[a := A] E∀

21

slide-23
SLIDE 23

Curry-Howard-de Bruijn

→ introduction versus abstraction rule

[Ax] . . . B A → B I[x]→ Γ, x : A ⊢ M : B Γ ⊢ Πx : A. B : ∗ Γ ⊢ λx : A. M : Πx : A. B

22

slide-24
SLIDE 24

→ elimination versus application rule

. . . A → B . . . A B E→ Γ ⊢ M : Πx : A. B Γ ⊢ N : A Γ ⊢ MN : B[x := N]

23

slide-25
SLIDE 25

∀ introduction versus abstraction rule

. . . B ∀a. B I∀ Γ, a : ∗ ⊢ M : B Γ ⊢ Πa : ∗. B : ∗ Γ ⊢ λa : ∗. M : Πa : ∗. B

24

slide-26
SLIDE 26

∀ elimination versus application rule

. . . ∀a. B B[a := A] E∀ Γ ⊢ M : Πa : ∗. B Γ ⊢ A : ∗ Γ ⊢ MA : B[a := A]

25

slide-27
SLIDE 27

detours and reduction

detour elimination for →

[Ax] . . . B A → B I[x]→ . . . A B E→

− →

. . . A . . . B

26

slide-28
SLIDE 28

detour elimination for ∀

. . . B ∀a. B I∀ B[a := A] E∀

− →

. . . ∗ B[a := A] ∗ replace a everywhere by A

27

slide-29
SLIDE 29

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

slide-30
SLIDE 30

examples

activities

logic type theory natural deduction type derivations

  • n paper

↓ ↑ in Coq →

29

slide-31
SLIDE 31

example 1

(∀b. b) → a

30

slide-32
SLIDE 32

example 2

a → ∀b. (b → a)

31

slide-33
SLIDE 33

example 3

a → ∀b. ((a → b) → b)

32

slide-34
SLIDE 34

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

slide-35
SLIDE 35

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

slide-36
SLIDE 36

λ2 is inconsistent with classical mathematics

bool : ∗ ⊢ ΠA : ∗. (A → bool) : ∗ ‘set of functions that map each set into a subset of that set’ U :=

A∈Set P(A) ∈ Set

U = P(U) × . . .

35

slide-37
SLIDE 37

the paradox

U :=

A∈Set P(A) ∈ Set

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