mod les des langages de programmation domaines cat gories
play

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


  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

  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

  3. The simply-typed λ -calculus 3

  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

  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 Γ = ( x 1 : A 1 , ..., x n : A n ) where each x i is a variable and each A i is a simple type. A sequent is a triple x 1 : A 1 , ..., x n : A n ⊢ P : B where x 1 : A 1 , ..., x n : A n is a typing context, P is a λ -term and B is a simple type. 5

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

  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

  8. The set-theoretic interpretation of the λ -calculus 8

  9. Interprétation ensembliste To each atomic type α is associated a set X α Then, one extends the interpretation to every type: ] = Set ([ [ A ] ] [ [ [ α ] ] = X α [ [ A ⇒ B ] ] = [ [ B ] [ A ] ] , [ [ B ] ]) A sequent x 1 : A 1 , ..., x n : A n ⊢ M : B is interpreted as a function [ A 1 ] [ A n ] [ B ] [ ] × · · · × [ ] −→ [ ] 9

  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

  11. Categories and functors 11

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

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

  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

  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 of the original category C . 15

  16. Product category The product A × B of 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

  17. Product category with composition and identities defined as expected: id ( A , B ) � ( A , B ) ( id A , id B ) � ( A , B ) ( A , B ) = ( A , B ) ( f , g ) � ( A ′ , B ′ ) ( f ′ , g ′ ) � ( A ′′ , B ′′ ) ( A , B ) ( f ′ ◦ f , g ′ ◦ g ) � ( A ′′ , B ′′ ) ( A , B ) = 17

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

  19. Functors One requires moreover that F preserves composition [2] FA Ff � FB Fg � FC FA F ( g ◦ f ) � FC = that F preserves the identities [2] Fid A id FA � FA � FA FA FA = 19

  20. Illustration [ orders ] Every ordered set ( X , ≤ ) defines a category [ X , ≤ ] whose objects are the elements of X ⊲ whose hom-sets are defined as ⊲ � if x ≤ y {∗} Hom ( x , y ) = otherwise ∅ In this category, there exists at most one map between two objects 20

  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

  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

  23. Illustration [ monoids ] Key observation: there is a one-to-one relationship ( M , · , e ) �→ Σ ( M , · , e ) between monoids ⊲ categories with one object ∗ ⊲ obtained 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

  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

  25. Transformations A transformation · F −→ G θ : between two functors F , G : A −→ B is a family of morphisms ( θ A : FA −→ GA ) A ∈ Obj ( A ) of the category B indexed by the objects of the category A . 25

  26. � � Natural transformations A transformation : F ⇒ G : A −→ B θ is natural when the diagram θ A � GA FA Ff G f θ B � GB FB commutes for every morphism f : A −→ B . 26

  27. Isomorphism In a category C , a morphism f : A −→ B is called an isomorphism when there exists a morphism g : B −→ A satisfying et g ◦ f = id A f ◦ g = id B . 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

  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 ( A , B ′ ) F ( f , 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

  29. Cartesian categories 29

  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 f A π 1 X A × B π 2 � B g there exists a unique morphism h : X −→ A × B making the diagram f A π 1 X A × B h π 2 � B g commute. 30

  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

  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

  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

  34. � � � � � � � � Cartesian categories In every cartesian category, one finds weakening maps ǫ A : A −→ 1 , ⊲ diagonal maps obtained as δ A : A −→ A × A ⊲ id A A π 1 A A × A δ A π 2 � A id A symmetry maps obtained as γ A , B : A × B −→ B × A ⊲ π 2 B π 1 γ A , B A × B B × A π 2 � A π 1 Exercise: Show that ( − × − ) defines a bifunctor C × C −→ C . 34

  35. Cartesian closed categories First definition 35

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend