formalisation in constructive type theory of barendregt s
play

Formalisation in Constructive Type Theory of Barendregts Variable - PowerPoint PPT Presentation

Formalisation in Constructive Type Theory of Barendregts Variable Convention for Generic Structures with Binders Ernesto Copello 1 Nora Szasz 2 lvaro Tasistro 2 1 Department of Computer Science The University of Iowa, USA 2 Facultad de


  1. Formalisation in Constructive Type Theory of Barendregt’s Variable Convention for Generic Structures with Binders Ernesto Copello 1 Nora Szasz 2 Álvaro Tasistro 2 1 Department of Computer Science The University of Iowa, USA 2 Facultad de Ingeniería Universidad ORT Uruguay June 22, 2018 1

  2. Outline • We introduce a universe of regular datatypes with variable binding information with: – a first-order named syntax interpretion – usual formation and elimination operators – operations and predicates specific to variables (swapping, free variables, fresh binders, etc) – an α -equivalence relation based on name-swapping. – iteration and induction principles which capture the Barendregt’s Variable Convention • We instantiate λ -Calculus and System F, deriving: – almost free substitution operations and α -conversion lemmas – substitution composition lemma • The whole work is carried out in Constructive Type Theory and machine-checked by the system Agda. 1

  3. Regular Trees Types with Binders • Functor datatype: introduces the codes of functors. • � _ � function: gives the interpretation of codes. • µ datatype: represents the fixpoint of some given F functor. mutual data Functor : Set 1 where � _ � : Functor → Set → Set � |1| � _ = ⊤ |1| : Functor � |R| � A = A |R| : Functor � |E| B � _ = B |E| : Set → Functor � |Ef| F � _ = µ F |Ef| : Functor → Functor � F |+| G � A = � F � A ⊎ � G � A _|+|_ : Functor → Functor → Functor � F |x| G � A = � F � A × � G � A _|x|_ : Functor → Functor → Functor � |v| S � _ = V |v| : Sort → Functor � |B| S G � A = V |B| : Sort → Functor → Functor × � G � A data µ ( F : Functor) : Set where � _ � : � F � ( µ F ) → µ F 2

  4. Regular Trees Types with Binders • Functor datatype: introduces the codes of functors. • � _ � function: gives the interpretation of codes. • µ datatype: represents the fixpoint of some given F functor. mutual data Functor : Set 1 where � _ � : Functor → Set → Set � |1| � _ = ⊤ |1| : Functor � |R| � A = A |R| : Functor � |E| B � _ = B |E| : Set → Functor � |Ef| F � _ = µ F |Ef| : Functor → Functor � F |+| G � A = � F � A ⊎ � G � A _|+|_ : Functor → Functor → Functor � F |x| G � A = � F � A × � G � A _|x|_ : Functor → Functor → Functor � |v| S � _ = V |v| : Sort → Functor � |B| S G � A = V |B| : Sort → Functor → Functor × � G � A data µ ( F : Functor) : Set where � _ � : � F � ( µ F ) → µ F 2

  5. Regular Trees Types with Binders • Functor datatype: introduces the codes of functors. • � _ � function: gives the interpretation of codes. • µ datatype: represents the fixpoint of some given F functor. mutual data Functor : Set 1 where � _ � : Functor → Set → Set � |1| � _ = ⊤ |1| : Functor � |R| � A = A |R| : Functor � |E| B � _ = B |E| : Set → Functor � |Ef| F � _ = µ F |Ef| : Functor → Functor � F |+| G � A = � F � A ⊎ � G � A _|+|_ : Functor → Functor → Functor � F |x| G � A = � F � A × � G � A _|x|_ : Functor → Functor → Functor � |v| S � _ = V |v| : Sort → Functor � |B| S G � A = V |B| : Sort → Functor → Functor × � G � A data µ ( F : Functor) : Set where � _ � : � F � ( µ F ) → µ F 2

  6. Regular Trees Types with Binders • Functor datatype: introduces the codes of functors. • � _ � function: gives the interpretation of codes. • µ datatype: represents the fixpoint of some given F functor. mutual data Functor : Set 1 where � _ � : Functor → Set → Set � |1| � _ = ⊤ |1| : Functor � |R| � A = A |R| : Functor � |E| B � _ = B |E| : Set → Functor � |Ef| F � _ = µ F |Ef| : Functor → Functor � F |+| G � A = � F � A ⊎ � G � A _|+|_ : Functor → Functor → Functor � F |x| G � A = � F � A × � G � A _|x|_ : Functor → Functor → Functor � |v| S � _ = V |v| : Sort → Functor � |B| S G � A = V |B| : Sort → Functor → Functor × � G � A data µ ( F : Functor) : Set where � _ � : � F � ( µ F ) → µ F 2

  7. Lambda Calculus Example λ F : Functor � M,N :- λ F = |v| Sort λ TermVars � x |+| |R| |x| |R| � | M N |+| |B| Sort λ TermVars |R| � | λ x . M λ Term : Set λ Term = µ λ F v : V → λ Term v = � _ � ◦ inj 1 _ · _ : λ Term → λ Term → λ Term M · N = � inj 2 (inj 1 ( M , N )) � Ż : V → λ Term → λ Term Ż n M = � inj 2 (inj 2 ( n , M )) � 3

  8. System F Example tyF : Functor � t,r :- tyF = |v| SortFTypeVars � α |+| |R| |x| |R| � | t → r |+| |B| SortFTypeVars |R| � | ∀ α . t tF : Functor � M,N :- tF = |v| SortFTermVars � x |+| |R| |x| |R| � | M N |+| |Ef| tyF |x| |B| SortFTermVars |R| � | λ x : t . M |+| |R| |x| |Ef| tyF � | M t |+| |B| SortFTypeVars |R| � | Λ α . M FType : Set FType = µ tyF FTerm : Set FTerm = µ tF 4

  9. System F Example tyF : Functor � t,r :- tyF = |v| SortFTypeVars � α |+| |R| |x| |R| � | t → r |+| |B| SortFTypeVars |R| � | ∀ α . t tF : Functor � M,N :- tF = |v| SortFTermVars � x |+| |R| |x| |R| � | M N |+| |Ef| tyF |x| |B| SortFTermVars |R| � | λ x : t . M |+| |R| |x| |Ef| tyF � | M t |+| |B| SortFTypeVars |R| � | Λ α . M FType : Set FType = µ tyF FTerm : Set FTerm = µ tF 4

  10. System F Example tyF : Functor � t,r :- tyF = |v| SortFTypeVars � α |+| |R| |x| |R| � | t → r |+| |B| SortFTypeVars |R| � | ∀ α . t tF : Functor � M,N :- tF = |v| SortFTermVars � x |+| |R| |x| |R| � | M N |+| |Ef| tyF |x| |B| SortFTermVars |R| � | λ x : t . M |+| |R| |x| |Ef| tyF � | M t |+| |B| SortFTypeVars |R| � | Λ α . M FType : Set FType = µ tyF FTerm : Set FTerm = µ tF 4

  11. Lambda Calculus Fold Instantiation Example λ F : Functor varsaux : � λ F � N → N � M,N :- λ F = |v| Sort λ TermVars varsaux (inj 1 _) = 1 � x |+| |R| |x| |R| varsaux (inj 2 (inj 1 ( m , n ))) = m + n � | M N |+| |B| Sort λ TermVars |R| � | λ x . varsaux (inj 2 (inj 2 (_ , m ))) = m M vars : µ λ F → N vars = fold λ F varsaux vars function could also be defined generically (for any functor). 5

  12. Fold with Context( µ C ) and a Functorial Return Type( µ H ) Fold instance • adds a c extra argument of type µ C , used by the folded function f as an explicit invariant context through the entire fold operation • the µ H type of the result is an instance of our universe (instead of an arbitrary set as in fold ). foldCtx : { C H : Functor}( F : Functor) → ( µ C → � F � ( µ H ) → µ H ) → µ C → µ F → µ H foldCtx F f c = fold F ( f c ) 6

  13. Lambda Calculus Example: Naive Substitution We derive the naive substitution for the λ -calculus from previous fold instance. Using the cF functor descriptor for the context argument, representing the pair formed by the variable to be replaced and the substituted term. cF = |v| Sort λ TermVars |x| |Ef| λ F substaux : µ cF → � λ F � ( µ λ F) → µ λ F substaux _ (inj 2 (inj 1 ( t 1 , t 2 ))) = t 1 · t 2 substaux _ (inj 2 (inj 2 ( y , t ))) = Ż y t ? substaux � x , N � (inj 1 y ) with x =v y ... | yes _ = N ... | no _ = v y _[_ ≔ _] n : λ Term → V → λ Term → λ Term M [ x ≔ N ] n = foldCtx λ F substaux � x , N � M 7

  14. Primitive Induction fih function receives a predicate P : µ F → Set ,and returns a predicate � G � ( µ F ) → Set , representing P holding in all µ F recursive positions in an element of type � G � ( µ F ). fih : { F : Functor}( G : Functor)( P : µ F → Set) → � G � ( µ F ) → Set fih |1| P tt = ⊤ fih |R| = P e P e fih (|E| B ) = ⊤ P e fih (|Ef| G ) = ⊤ P e fih ( G 1 |+| G 2 ) P (inj 1 e ) = fih G 1 P e fih ( G 1 |+| G 2 ) P (inj 2 e ) = fih G 2 P e fih ( G 1 |x| G 2 ) P ( e 1 , e 2 ) = fih G 1 P e 1 × fih G 2 P e 2 fih (|v| S ) = ⊤ P x fih (|B| S G ) P ( x , e ) = fih G P e 8

  15. Primitive Induction foldmapFh : { F : Functor}( G : Functor)( P : µ F → Set) → (( e : � F � ( µ F )) → fih F P e → P � e � ) → ( x : � G � ( µ F )) → fih G P x foldmapFh |1| P hi tt = tt foldmapFh { F } |R| = hi e (foldmapFh { F } F P hi e ) P hi � e � foldmapFh (|E| B ) = tt P hi b foldmapFh (|Ef| F ) = tt P hi b foldmapFh ( G 1 |+| G 2 ) P hi (inj 1 e ) = foldmapFh G 1 P hi e foldmapFh ( G 1 |+| G 2 ) P hi (inj 2 e ) = foldmapFh G 2 P hi e foldmapFh ( G 1 |x| G 2 ) P hi ( e 1 , e 2 ) = foldmapFh G 1 P hi e 1 , foldmapFh G 2 P foldmapFh (|v| S ) = tt P hi n foldmapFh (|B| S G ) P hi ( x , e ) = foldmapFh G P hi e foldInd : ( F : Functor)( P : µ F → Set) → (( e : � F � ( µ F )) → fih F P e → P � e � ) → ( e : µ F ) → P e foldInd F P hi e = foldmapFh { F } |R| P hi e 9

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