Modles des langages de programmation Domaines, catgories, jeux - - PowerPoint PPT Presentation

mod les des langages de programmation domaines cat gories
SMART_READER_LITE
LIVE PREVIEW

Modles des langages de programmation Domaines, catgories, jeux - - PowerPoint PPT Presentation

Modles des langages de programmation Domaines, catgories, jeux Programme de cette seconde sance: Modle ensembliste du lambda-calcul ; Catgories cartsiennes fermes 1 Synopsis 1 the simply-typed -calculus, 2 the


slide-1
SLIDE 1

Modèles des langages de programmation Domaines, catégories, jeux Programme de cette seconde séance: Modèle ensembliste du lambda-calcul ; Catégories cartésiennes fermées

1

slide-2
SLIDE 2

Synopsis

1 — the simply-typed λ-calculus, 2 — the set-theoretic model of the λ-calculus, 3 — categories and functors 4 — cartesian categories 5 — cartesian closed categories 6 — interprétation of the simply-typed λ-calculus in a ccc

2

slide-3
SLIDE 3

The simply-typed λ-calculus

3

slide-4
SLIDE 4

The pure λ-calculus

Terms M ::= x | M N | łx. M The β-reduction: (λx.M) N −→ M [x := N] The η-expansion: M −→ λx. (M x) Remark: every term is considered up to renaming ≡α of the bound variables, typically: λx.λy.x ≡α λz.λy.z

4

slide-5
SLIDE 5

The simply-typed λ-calculus

The simple types A, B are constructed by the grammar: A, B ::= α | A ⇒ B. A typing context Γ is a finite sequence Γ = (x1 : A1, ..., xn : An) where each xi is a variable and each Ai is a simple type. A sequent is a triple x1 : A1, ..., xn : An ⊢ P : B where x1 : A1, ..., xn : An is a typing context, P is a λ-term and B is a simple type.

5

slide-6
SLIDE 6

The simply-typed λ-calculus

Variable x : A ⊢ x : A Abstraction Γ, x : A ⊢ P : B Γ ⊢ λx.P : A ⇒ B Application Γ ⊢ P : A ⇒ B ∆ ⊢ Q : A Γ, ∆ ⊢ PQ : B Weakening Γ ⊢ P : B Γ, x : A ⊢ P : B Contraction Γ, x : A, y : A ⊢ P : B Γ, z : A ⊢ P[x, y ← z] : B Exchange Γ, x : A, y : B, ∆ ⊢ P : C Γ, y : B, x : A, ∆ ⊢ P : C

6

slide-7
SLIDE 7

Subject reduction

A λ-term P is simply typed when there exists a sequent Γ ⊢ P : A which may be obtained by a derivation tree. One establishes that the set of simply typed λ-terms is closed under β-réduction: Subject Reduction: If Γ ⊢ P : A and P −→β Q, then Γ ⊢ Q : A.

7

slide-8
SLIDE 8

The set-theoretic interpretation of the λ-calculus

8

slide-9
SLIDE 9

Interprétation ensembliste

To each atomic type α is associated a set Xα Then, one extends the interpretation to every type: [ [α] ] = Xα [ [A ⇒ B] ] = [ [B] ][

[A] ] = Set ([

[A] ], [ [B] ]) A sequent x1 : A1, ..., xn : An ⊢ M : B is interpreted as a function [ [A1] ] × · · · × [ [An] ] −→ [ [B] ]

9

slide-10
SLIDE 10

Soundness theorem

Theorem. The interpretation provides an invariant of λ-terms modulo β and η. ⊲ if Γ ⊢ (λx.M) : A ⇒ B and ∆ ⊢ N : A, then [ [Γ, ∆ ⊢ (λx.M)N : B] ] = [ [Γ, ∆ ⊢ M[x := N] : B] ] ⊲ if Γ ⊢ M : A ⇒ B then [ [Γ ⊢ (λx.Mx) : A ⇒ B] ] = [ [Γ ⊢ M : A ⇒ B] ]

10

slide-11
SLIDE 11

Categories and functors

11

slide-12
SLIDE 12

Categories

A category C is given by [0] a class of objects [1] a set Hom(A, B) of morphisms f : A −→ B for every pair of objects (A, B) [2] a composition law ◦ : Hom(B, C) × Hom(A, B) −→ Hom(A, C) [2] an identity morphism idA : A −→ A for every object A,

12

slide-13
SLIDE 13

Categories

satisfying the following properties: [3] the composition law ◦ is associative: ∀f ∈ Hom(A, B) ∀g ∈ Hom(B, C) ∀h ∈ Hom(C, D) f ◦ (g ◦ h) = (f ◦ g) ◦ h [3] the morphisms id are neutral elements ∀ f ∈ Hom(A, B) f ◦ idA = f = idB ◦ f

13

slide-14
SLIDE 14

Examples

  • 1. the category Set of sets and functions
  • 2. the category Ord of partial orders and monotone functions
  • 3. the category Dom of domains and continuous functions
  • 4. the category Coh of coherence spaces and linear maps
  • 5. every partial order
  • 6. every monoid

14

slide-15
SLIDE 15

Opposite category

The opposite of a category C is the category noted C op whose morphisms f : A −→ B are defined as the morphisms f : B −→ A

  • f the original category C.

15

slide-16
SLIDE 16

Product category

The product A × B

  • f two categories

A B is the category ⊲ whose objects are the pairs (A, B) of objects of A and B, ⊲ whose morphisms (A, B) −→ (A′, B′) are the pairs of morphisms f : A −→ A′ g : B −→ B′

16

slide-17
SLIDE 17

Product category

with composition and identities defined as expected: (A, B)

id(A,B) (A, B)

= (A, B)

(idA,idB)

(A, B)

(A, B)

(f,g) (A′, B′) (f ′,g′) (A′′, B′′)

= (A, B) (f ′◦f,g′◦g)

(A′′, B′′)

17

slide-18
SLIDE 18

Functors

A functor between categories F : C −→ D is defined as the following data: [0] an object FA of D for every object A of C, [1] a function FA,B : HomC(A, B) −→ HomD(FA, FB) for every pair of objects (A, B) of the category C.

18

slide-19
SLIDE 19

Functors

One requires moreover [2] that F preserves composition FA Ff FB Fg FC = FA F(g◦f) FC [2] that F preserves the identities FA

FidA

FA

= FA

idFA

FA

19

slide-20
SLIDE 20

Illustration [ orders ]

Every ordered set (X, ≤) defines a category [X, ≤] ⊲ whose objects are the elements of X ⊲ whose hom-sets are defined as Hom(x, y) =

  • {∗}

if x ≤ y ∅

  • therwise

In this category, there exists at most one map between two objects

20

slide-21
SLIDE 21

Illustration [ orders ]

Exercise: given two ordered sets (X, ≤) (Y , ≤) a functor F : [X, ≤] −→ [Y , ≤] is the same thing as a monotonic function F : (X, ≤) −→ (Y , ≤) between the underlying ordered sets.

21

slide-22
SLIDE 22

Illustration [ monoids ]

A monoid (M, ·, e) is a set M equipped with a binary operation · : M × M −→ M and a neutral element e : {∗} −→ M satisfying the two properties below: Associativity law ∀x, y, z ∈ M, (x · y) · z = x · (y · z) Unit law ∀x ∈ M, x · e = x = e · x.

22

slide-23
SLIDE 23

Illustration [ monoids ]

Key observation: there is a one-to-one relationship (M, ·, e) → Σ (M, ·, e) between ⊲ monoids ⊲ categories with one object ∗

  • btained by defining Σ(M, ·, e) as the category with unique hom-set

Σ(M, ·, e) (∗, ∗) = M and composition law and unit defined as g ◦ f = g · f id ∗ = e

23

slide-24
SLIDE 24

Illustration [ monoids ]

Key observation: given two monoids (M, ·, e) (N, •, u) a functor F : Σ (M, ·, e) −→ Σ (N, •, u) is the same thing as a homomorphism f : (M, ·, e) −→ (N, •, u) between the underlying monoids. Recall that a homomorphism is a function f such that ∀x, y ∈ M, f(x · y) = f(x) • f(y) f(e) = u

24

slide-25
SLIDE 25

Transformations

A transformation θ : F

·

−→ G between two functors F, G : A −→ B is a family of morphisms (θA : FA −→ GA)A∈Obj(A)

  • f the category B indexed by the objects of the category A.

25

slide-26
SLIDE 26

Natural transformations

A transformation θ : F ⇒ G : A −→ B is natural when the diagram FA

Ff

  • θA

GA

G f

  • FB

θB

GB

commutes for every morphism f : A −→ B.

26

slide-27
SLIDE 27

Isomorphism

In a category C, a morphism f : A −→ B is called an isomorphism when there exists a morphism g : B −→ A satisfying g ◦ f = idA et f ◦ g = idB.

  • Exercise. Show that g ◦ f : A −→ C is an isomorphism when f : A −→ B

and g : B −→ C are isomorphisms.

  • Exercise. Show that every functor F : C −→ D transports an isomor-

phism of C into an isomorphism of D.

27

slide-28
SLIDE 28

Bifunctors

A bifunctor F from C and D to E is given by: ⊲ a functor F(A, −) : D −→ E for every object A of the category C ⊲ a functor F(−, B) : C −→ E for every object B of the category D such that the diagram F(A, B) F(A,g)

F(f,B)

  • F(A, B′)

F( f,B′)

  • F(A′, B) F(A′,g) F(A′, B′)

commutes for all morphisms f : A −→ A′ in C and g : B −→ B′ in D.

28

slide-29
SLIDE 29

Cartesian categories

29

slide-30
SLIDE 30

Products

The product of two objects A and B in a category C is an object A × B equipped with two morphisms π1 : A × B −→ A π2 : A × B −→ B such that for every diagram A X

f

  • g
  • A × B

π1

  • π2

B

there exists a unique morphism h : X −→ A × B making the diagram A X

h

  • f
  • g
  • A × B

π1

  • π2

B

commute.

30

slide-31
SLIDE 31

Illustrations

  • 1. The cartesian product in the category Set,
  • 2. The lub a ∧ b of two elements a and b in an ordered set (X, ),
  • 3. The cartesian product in the category Dom,

31

slide-32
SLIDE 32

Terminal object

An object 1 is terminal in a category C when Hom(A, 1) is a singleton for all objects A. One may consider 1 as the nullary product in C. Example 1. the singleton {∗} in the categories Set and Dom, Example 2. the maximum of an ordered set (X, )

32

slide-33
SLIDE 33

Cartesian category

A cartesian category is a category C equipped with a product A × B for all pairs A, B of objects, and of a terminal object 1

33

slide-34
SLIDE 34

Cartesian categories

In every cartesian category, one finds ⊲ weakening maps ǫA : A −→ 1, ⊲ diagonal maps δA : A −→ A × A

  • btained as

A A

δA

  • idA
  • idA
  • A × A

π1

  • π2

A

⊲ symmetry maps γA,B : A × B −→ B × A

  • btained as

B A × B

γA,B

  • π2
  • π1
  • B × A

π1

  • π2

A

Exercise: Show that (− × −) defines a bifunctor C × C −→ C.

34

slide-35
SLIDE 35

Cartesian closed categories First definition

35

slide-36
SLIDE 36

Ccc

A cartesian closed category is a cartesian category (C, ×, 1) together with the following data for all objects A and B: ⊲

  • f an object A ⇒ B

  • f a morphism evalA,B : A × (A ⇒ B) −→ B

such that for every object X and morphism f : A × X −→ B there exists a unique morphism h : X −→ A ⇒ B making the diagram A × (A ⇒ B)

evalA,B

B

A × X

A×h

  • f
  • commute.

36

slide-37
SLIDE 37

Cartesian closed category Second definition

37

slide-38
SLIDE 38

Adjunction

An adjunction is a triple consisting of two functors L : A −→ B R : B −→ A and a family of bijections φA,B : HomB(LA, B) HomA(A, RB) natural in A and B, for all pairs of objects A, B of A and B. LA

B

−→ B A

A

−→ RB φA,B One writes L ⊣ R and one says that L is left adjoint to R.

38

slide-39
SLIDE 39

Example: the free vector space

Set

L

Vect

R

  • where

A = Set : the category of sets and functions B = Vect : the category of vector spaces on a field k R : the « forgetful » functor V → U(V) L : the « free vector space » functor X → kX kX :=

  • x∈X

λx x | λx ∈ k null almost everywhere.

  • 39
slide-40
SLIDE 40

Illustration: the free monoid

Set

L

Mon

R

  • where

A = Set : the category of sets and functions B = Mon : the category of monoids and homomorphisms, R : the « forgetful » functor M → U(M). L : the « free monoid » functor A → A∗. A :=

  • n∈N

An

40

slide-41
SLIDE 41

What does natural bijection φ exactly mean?

By φ natural, one means that the two families of sets HomB(LA, B) HomA(A, RB) define functors HomB(L−, −) : A op × B −→ Set HomA(−, R−) : A op × B −→ Set and that the family of bijections φ defines a natural transformation φ : HomB(L−, −) HomA(−, R−) : A op × B −→ Set between them.

41

slide-42
SLIDE 42

What does natural bijection φ exactly mean?

Natural in A and B thus means that every commutative diagram LA

g

B

hB

  • LA′

LhA

  • f

B′

is transformed into a commutative diagram A

φA,B(g)

RB

RhB

  • A′

hA

  • φA′,B′( f)

RB′

42

slide-43
SLIDE 43

Cartesian exponentiation

Consider an object A in a cartesian category(C, ×, 1). A cartesian exponentiation of A is a pair consisting of a functor (A ⇒ −) : C −→ C and of a family of bijections φA,B,C : Hom(A × B, C) −→ Hom(B, A ⇒ C) natural in B and C. In other words, it is an adjunction between the functors A × − ⊣ A ⇒ −

43

slide-44
SLIDE 44

What natural bijection means in that case

Naturality in B and C means that the family of bijections φA,B,C : Hom(A × B, C) −→ Hom(B, A ⇒ C) transforms every commutative diagram A × B

g

C

hC

  • A × B′

A×hB

  • f

C′

into a commutative diagram B

φA,B,C(g)

A ⇒ C

A⇒hC

  • B′

hB

  • φA,B′,C′( f)

A ⇒ C′

44

slide-45
SLIDE 45

Cartesian closed category

Definition. A cartesian closed category (ccc) is a cartesian category (C, ×, 1) equipped with a cartesian exponentation A × B −→ C B −→ A ⇒ C φA,B,C for every object A of the category.

45

slide-46
SLIDE 46

Parameter theorem

We have seen that the cartesian product defines a bifoncteur A, B → A × B : C × C −→ C in every cartesian category. In the same way, Parameter theorem [MacLane] The family of cartesian exponentiations (A ⇒ −)A : C −→ C defines a unique bifunctor A, B → A ⇒ B : C op × C −→ C such that the bijections φA,B,C are natural in A, B, C.

46

slide-47
SLIDE 47

Parameter theorem

Here, natural in A, B, C means that the family of bijections (φA,B,C)A,B,C : Hom(A × B, C) −→ Hom(B, A ⇒ C) transforms every commutative diagram A × B

g

C

hC

  • A′ × B′

hA×hB

  • f

C′

in a commutative diagram: B

φA,B,C(g)

A ⇒ C

hA⇒hC

  • B′

hB

  • φA′,B′,C′( f)

A′ ⇒ C′

47

slide-48
SLIDE 48

Interpretation of the simply-typed λ-calculus in a CCC

48

slide-49
SLIDE 49

The simply-typed λ-calculus

The simple types A, B are constructed by the grammar: A, B ::= α | A ⇒ B. A typing context Γ is a finite sequence Γ = (x1 : A1, ..., xn : An) where each xi is a variable and each Ai is a simple type. A sequent is a triple x1 : A1, ..., xn : An ⊢ P : B where x1 : A1, ..., xn : An is a typing context, P is a λ-term and B is a simple type.

49

slide-50
SLIDE 50

The simply-typed λ-calculus

Variable x : A ⊢ x : A Abstraction Γ, x : A ⊢ P : B Γ ⊢ λx.P : A ⇒ B Application Γ ⊢ P : A ⇒ B ∆ ⊢ Q : A Γ, ∆ ⊢ PQ : B Weakening Γ ⊢ P : B Γ, x : A ⊢ P : B Contraction Γ, x : A, y : A ⊢ P : B Γ, z : A ⊢ P[x, y ← z] : B Exchange Γ, x : A, y : B, ∆ ⊢ P : C Γ, y : B, x : A, ∆ ⊢ P : C

50

slide-51
SLIDE 51

Interpretation of the λ-calculus

Step 1. We suppose given a function ξ : α → ξ(α) which associates an object ξ(α) to every type variable α. Step 2. Every type A is then interpreted as an object [ [A] ]

  • f the cartesian closed category by structural induction:

[ [α] ] = ξ(α) [ [A × B] ] = [ [A] ] × [ [B] ] [ [A ⇒ B] ] = [ [A] ] ⇒ [ [B] ]

51

slide-52
SLIDE 52

Interpretation of the λ-calculus

Step 3. Every sequent x1 : A1 , . . . , xn : An ⊢ t : B is interpreted as a morphism [ [t] ] : [ [A1] ] × · · · × [ [An] ] −→ [ [B] ] by structural induction on the derivation tree which produced it.

52

slide-53
SLIDE 53

The logical rules

⊲ Variable: [ [A] ]

id [

[A] ]

[

[A] ] ⊲ Lambda: A × Γ

f

B

becomes Γ

φA,Γ,B( f)

A ⇒ B

⊲ Application: Γ

f

A

and ∆

g

A ⇒ B

become Γ × ∆

f×g

A × (A ⇒ B)

evalA,B

B

53

slide-54
SLIDE 54

The structural rules

⊲ Contraction: A × A × Γ

f

B

becomes A × Γ

δA×Γ

A × A × Γ

f

B

⊲ Weakening: Γ

f

B

becomes A × Γ

εA×Γ

1 × Γ ∼ Γ

f

B

⊲ Permutation: Γ × A × B × ∆

f

B

becomes Γ × B × A × ∆

Γ×γA,B×∆

Γ × A × B × ∆

f

B

54

slide-55
SLIDE 55

Soundness theorem

Theorem. In every cartesian closed category C, the interpretation [ [−] ] is an invariant modulo β, η. ⊲ If Γ ⊢ (λx.M) : A ⇒ B and ∆ ⊢ N : A, then [ [Γ, ∆ ⊢ (λx.M)N : B] ] = [ [Γ, ∆ ⊢ M[x := N] : B] ] ⊲ If Γ ⊢ M : A ⇒ B then [ [Γ ⊢ (λx.Mx) : A ⇒ B] ] = [ [Γ ⊢ M : A ⇒ B] ] Exercise. Establish the soundness theorem.

55