multimodal dependent type theory
play

Multimodal Dependent Type Theory Daniel Gratzer 0 G.A. Kavvos 0 - PowerPoint PPT Presentation

Multimodal Dependent Type Theory Daniel Gratzer 0 G.A. Kavvos 0 Andreas Nuyts 1 Lars Birkedal 0 Wednesday May 27 th , 2020 Stockholm University 0 Aarhus University 1 imec-DistriNet, KU Leuven 0 The problem Wed like extend Martin-L of Type


  1. Delayed substitutions A first solution to this problem is simply to give up on finding the right introduction. Make the user tell us! Γ ′ ⊢ M : A Γ ⊢ γ : µ · Γ ′ Γ ⊢ mod µ ( M ) γ : � µ | A � γ The advantage is uniformity 19

  2. Delayed substitutions A first solution to this problem is simply to give up on finding the right introduction. Make the user tell us! Γ ′ ⊢ M : A Γ ⊢ γ : µ · Γ ′ Γ ⊢ mod µ ( M ) γ : � µ | A � γ µ · Γ ′ = precompose every annotation with µ The advantage is uniformity 19

  3. Delayed substitutions A first solution to this problem is simply to give up on finding the right introduction. Make the user tell us! Γ ′ ⊢ M : A Γ ⊢ γ : µ · Γ ′ Γ ⊢ mod µ ( M ) γ : � µ | A � γ The advantage is uniformity .... but we need some way to resolve these substitutions: Γ ⊢ δ 0 : µ · ∆ 0 ∆ 0 ⊢ δ 1 : ∆ 1 ∆ 1 ⊢ M : A Γ ⊢ mod µ ( M ) ( µ · δ 1 ) ◦ δ 0 = mod µ ( M [ δ 1 ]) δ 0 : � µ | A � ( µ · δ 1 ) ◦ δ 0 19

  4. Delayed substitutions A first solution to this problem is simply to give up on finding the right introduction. Make the user tell us! Γ ′ ⊢ M : A Γ ⊢ γ : µ · Γ ′ Γ ⊢ mod µ ( M ) γ : � µ | A � γ The advantage is uniformity .... but we need some way to resolve these substitutions: Γ ⊢ δ 0 : µ · ∆ 0 ∆ 0 ⊢ δ 1 : ∆ 1 ∆ 1 ⊢ M : A Γ ⊢ mod µ ( M ) ( µ · δ 1 ) ◦ δ 0 = mod µ ( M [ δ 1 ]) δ 0 : � µ | A � ( µ · δ 1 ) ◦ δ 0 No more unique normal forms! This prevents us from proving decidability of type-checking. 19

  5. Delayed substitutions: pros and cons The main advantage of delayed substitutions is that it is uniform. • It applies to substructural settings as well [LSR17]. • It scales in a straightforward way to dependent types [Biz+16]. The downside is that it almost surely destroys decidability of typechecking. 20

  6. Avoiding delayed substitutions The remaining approaches (left-division, Fitch-style, MTT) ensure a universal delayed substitution . Suppose for every substitution Γ → µ · ∆, we have the following factorization: µ · δ ′ µ · Γ ′ µ · ∆ ′ η δ Γ Then we can pick always pick η as our delayed substitution! 21

  7. Avoiding delayed substitutions The remaining approaches (left-division, Fitch-style, MTT) ensure a universal delayed substitution . Suppose for every substitution Γ → µ · ∆, we have the following factorization: µ · δ ′ µ · Γ ′ µ · ∆ ′ This makes µ · − into a η right adjoint! δ Γ Then we can pick always pick η as our delayed substitution! 21

  8. Left-division We can require a division operation [Pfe01; Abe08; NVD17; ND18] on modalities in order to make this adjoint exist: µ ≤ ν ◦ ξ ⇐ ⇒ µ/ν ≤ ξ The right adjoint to ν · − is pointwise application of − /ν . 22

  9. Left-division We can require a division operation [Pfe01; Abe08; NVD17; ND18] on modalities in order to make this adjoint exist: µ ≤ ν ◦ ξ ⇐ ⇒ µ/ν ≤ ξ The right adjoint to ν · − is pointwise application of − /ν . The new introduction rule uses this universal solution: Γ /µ ⊢ M : A Γ ⊢ mod µ ( M ) : � µ | A � 22

  10. Left-division: pros and cons When left-division exists, this is completely solid and implementable! [Nuy19]. The issue is that it often doesn’t exist. The only example I know is parametricity/degrees of relatedness. 23

  11. Left-division: pros and cons When left-division exists, this is completely solid and implementable! [Nuy19]. The issue is that it often doesn’t exist. The only example I know is parametricity/degrees of relatedness. 23

  12. The Fitch style • What the left adjoint doesn’t need to respect context extension or the terminal? • We can formally add application of the left adjoint to our grammar for contexts. · | Γ , x : A | Γ , � µ (Fitch-style contexts) Γ , ∆ ::= 24

  13. The Fitch style • What the left adjoint doesn’t need to respect context extension or the terminal? • We can formally add application of the left adjoint to our grammar for contexts. · | Γ , x : A | Γ , � µ (Fitch-style contexts) Γ , ∆ ::= Now we can use this left adjoint in the introduction rule: Γ , � µ ⊢ M : A Γ ⊢ mod µ ( M ) : � µ | A � 24

  14. The variable rules There’s no way to extract x : A from under a lock, so we adapt the variable rule: � �∈ Γ 0 Γ 1 , x : A , Γ 0 ⊢ x : A After all, Γ , � µ represents the application of some functor to Γ. But now we need some way to remove locks , otherwise those variables are gone forever. 25

  15. The rub: the elimination rule for modalities A natural candidate for the elimination rule is to transpose in the other direction: Γ ⊢ M : � µ | A � Γ , � µ ⊢ open( M ) : A 26

  16. The rub: the elimination rule for modalities A natural candidate for the elimination rule is to transpose in the other direction: Γ ⊢ M : � µ | A � Γ , � µ ⊢ open( M ) : A Once again, however, we have a problem with substitutions: • Suppose we have a substitution ∆ → Γ , � µ . • Can we always factor it through unique substitution ∆ ′ , � µ → Γ , � µ ? • In specific cases, substitution is at least admissible . • With multiple modalities or certain modal operations however, it seems impossible. 26

  17. An aside: an open-scope eliminator Fitch-style type theories do not have a pattern matching elimination principle. We can given � µ | A � an η -principle, the only time we can do so today! Γ ⊢ M : � µ | A � Γ ⊢ mod µ (open( M )) = M : � µ | A � I used to think this was very important [GSB19]. No longer so sure [Gra+20]. 27

  18. The Fitch-style: pros and cons The Fitch style works when substitution can be proven admissible [DP01; BGM17; Clo18; Bir+20; GSB19]. Furthermore, there are multiple implementations of Fitch-style type theories. On the other hand... • Restricts the possible modalities (right adjoints), but workable in practice. • There’s a certain asymmetry here: the left adjoints cannot act as types! • The admissibility of substitution is too weak to work as an internal language. • The admissibility approach seems completely intractable for multiple modalities. 28

  19. Our “long march through modal type theory” After this long tour of modal type theories, where do we stand? • If we have only one modality, then we can use a split-context. • If we require no structure on a collection of modalities, we lose normalization • We can require a division, which works nicely if it applies. • If we ask only that a modality is a right adjoint, multiple modalities are still problematic. So, the challenge for MTT is to have a system which is (1.) well-behaved (2.) less restrictive than left-division. 29

  20. Break time Let’s get some coffee... 30

  21. Our Contribution: MTT We introduce MTT: a type theory parameterized by a collection of modalities. • MTT features usual connectives of Martin-L¨ of Type Theory, including a universe. • The user can instantiate MTT with different collections of modalities. • Important results such as canonicity are proven irrespective of the modalities. We have applied MTT to several different situations: • Axiomatic cohesion • Degrees of relatedness • Guarded recursion and warps • Various classic modal type theories 31

  22. Modes and Mode theories MTT is a multi mode type theory, not just multi modal . • Each mode is its own separate type theory, with modalities bridging between them. • As an example, spatial type theory has two modes: sets and spaces. 32

  23. Modes and Mode theories MTT is a multi mode type theory, not just multi modal . • Each mode is its own separate type theory, with modalities bridging between them. • As an example, spatial type theory has two modes: sets and spaces. We follow [LS16; LSR17] and specify our modalities as a mode theory, a 2-category: object ∼ mode morphism ∼ modality 2-cell ∼ natural map between modalities 32

  24. An example: an idempotent comonad The mode theory for an idempotent comonad is generated from the following data: objects: { m } morphisms: { µ : m → m } 2-cells: { ǫ : µ ⇒ 1 } Furthermore, µ ◦ µ = µ and that α = β for any pair of 2-cells. 33

  25. An example: an idempotent comonad The mode theory for an idempotent comonad is generated from the following data: objects: { m } morphisms: { µ : m → m } 2-cells: { ǫ : µ ⇒ 1 } Furthermore, µ ◦ µ = µ and that α = β for any pair of 2-cells. This induces a single modality � µ | −� with the following operations: Γ ⊢ M : � µ | A � @ m Γ ⊢ M : � µ | A � @ m Γ ⊢ extract( M ) : A @ m Γ ⊢ duplicate( M ) : � µ | � µ | A �� @ m 33

  26. An example: an idempotent comonad The mode theory for an idempotent comonad is generated from the following data: objects: { m } morphisms: { µ : m → m } 2-cells: { ǫ : µ ⇒ 1 } Furthermore, µ ◦ µ = µ and that α = β for any pair of 2-cells. A mode annotation . This induces a single modality � µ | −� with the following operations: Γ ⊢ M : � µ | A � @ m Γ ⊢ M : � µ | A � @ m Γ ⊢ extract( M ) : A @ m Γ ⊢ duplicate( M ) : � µ | � µ | A �� @ m 33

  27. MTT, more formally We will now introduce MTT a bit more carefully. Let us fix a mode theory M . MTT is stratified into the following judgments: Γ ctx @ m Γ ⊢ A type @ m Γ ⊢ M : A @ m Γ ⊢ δ : ∆ @ m Each judgment is localized to a mode and each mode contains a copy of MLTT. 34

  28. MTT, more formally We will now introduce MTT a bit more carefully. Let us fix a mode theory M . We’ll mostly ignore these today. MTT is stratified into the following judgments: Γ ctx @ m Γ ⊢ A type @ m Γ ⊢ M : A @ m Γ ⊢ δ : ∆ @ m Each judgment is localized to a mode and each mode contains a copy of MLTT. 34

  29. Modal types Slogan: modalities act like functors between modes. Given a closed type A @ n and µ : n → m , there is a closed type � µ | A � @ m . This doesn’t easily scale to open types: Γ ⊢ A type @ n µ : n → m Γ ⊢ � µ | A � type @ m 35

  30. Modal types Slogan: modalities act like functors between modes. Given a closed type A @ n and µ : n → m , there is a closed type � µ | A � @ m . This doesn’t easily scale to open types: Γ ⊢ A type @ n µ : n → m One of these must Γ ⊢ � µ | A � type @ m live in the wrong mode. 35

  31. Modal types Slogan: modalities act like functors between modes. Given a closed type A @ n and µ : n → m , there is a closed type � µ | A � @ m . This doesn’t easily scale to open types: Γ ⊢ A type @ n µ : n → m One of these must Γ ⊢ � µ | A � type @ m live in the wrong mode. We require additional judgmental structure to make sense of modal types. 35

  32. Fitch-style contexts MTT uses a Fitch-style context so modalities to have an adjoint action on contexts: µ : n → m Γ ctx @ m Γ , � µ ctx @ n While it is not entirely accurate, it is helpful to imagine − , � µ ⊣ � µ | −� . 36

  33. Fitch-style contexts MTT uses a Fitch-style context so modalities to have an adjoint action on contexts: µ : n → m Γ ctx @ m Γ , � µ ctx @ n While it is not entirely accurate, it is helpful to imagine − , � µ ⊣ � µ | −� . Accordingly, the introduction and formation rules are transposition: Γ , � µ ⊢ A type @ n Γ , � µ ⊢ M : A @ n µ : n → m µ : n → m Γ ⊢ � µ | A � type @ m Γ ⊢ mod µ ( M ) : � µ | A � @ m These rules follow other Fitch-style type theories [BGM17; Clo18; Bir+20; GSB19]. 36

  34. Fitch-style contexts with multiple modalities Prior work had one modality, hence one lock. How do we scale to many modalities? Γ ctx @ m ν : o → n µ : n → m Γ ctx @ m Γ = Γ , � 1 ctx @ m Γ , � µ , � ν = Γ , � µ ◦ ν ctx @ o 37

  35. Fitch-style contexts with multiple modalities Prior work had one modality, hence one lock. How do we scale to many modalities? Γ ctx @ m ν : o → n µ : n → m Γ ctx @ m Γ = Γ , � 1 ctx @ m Γ , � µ , � ν = Γ , � µ ◦ ν ctx @ o In fact, � is part of a 2-functor from M coop to contexts and substitutions. Definition Given a 2-cell α : µ ⇒ ν and a term Γ , � ν ⊢ M : A @ m , there is a derived operation ( − ) α such that Γ , � µ ⊢ M α : A α @ m . Secretly, this is built from a modal substitution behaving like a natural transformation. 37

  36. What about variables? Locks allow us to state the formation rule for modalities, but what about variables? With the standard variable rule, we again have a mode error! µ : n → m x : A , � µ ⊢ x : A @ n 38

  37. What about variables? Locks allow us to state the formation rule for modalities, but what about variables? With the standard variable rule, we again have a mode error! µ : n → m x : A , � µ ⊢ x : A @ n A must live in mode m A must live in mode n 38

  38. What about variables? Locks allow us to state the formation rule for modalities, but what about variables? With the standard variable rule, we again have a mode error! µ : n → m x : A , � µ ⊢ x : A @ n • Previous Fitch-style type theories handled this through an elimination rule. • In MTT, we will introduce a final piece of judgmental structure. 38

  39. Variable annotations In addition to locks, each variable in the context will be annotated with a modality. Γ , � µ ⊢ A type @ n µ : n → m Γ ctx @ m Γ , x : ( µ | A ) ctx @ m Another rough intuition: Γ , x : ( µ | A ) ∼ = Γ , x : � µ | A � . 39

  40. Variable annotations In addition to locks, each variable in the context will be annotated with a modality. Γ , � µ ⊢ A type @ n µ : n → m Γ ctx @ m Γ , x : ( µ | A ) ctx @ m Another rough intuition: Γ , x : ( µ | A ) ∼ = Γ , x : � µ | A � . We can use these annotations to give a more sensible variable rule: µ : n → m Γ , x : ( µ | A ) , � µ ⊢ x : A @ n Intuition: this is the counit of the adjunction − , � µ ⊣ � µ | −� . 39

  41. What about 2-cells? This variable rule is a bit restrictive; it requires the annotation and lock to match. We can relax a bit and require only a 2-cell between the annotation and the lock. µ, ν : n → m α : µ ⇒ ν Γ , x : ( µ | A ) , � ν ⊢ x α : A α @ n In fact, this rule is a combination of the ‘counit’ rule and the action of � on 2-cells. 40

  42. Modal induction The final piece of the puzzle is the elimination rule for � µ | A � . • At a high-level this rule let’s us replace x : � µ | A � with y : ( µ | A ). • We must generalize to replacing x : ( ν | � µ | A � ) with y : ( ν ◦ µ | A ). • We rephrase this as a pattern-matching or cut-style rule. 41

  43. Modal induction The final piece of the puzzle is the elimination rule for � µ | A � . • At a high-level this rule let’s us replace x : � µ | A � with y : ( µ | A ). • We must generalize to replacing x : ( ν | � µ | A � ) with y : ( ν ◦ µ | A ). • We rephrase this as a pattern-matching or cut-style rule. Fix ν : m → o , µ : n → m . The elimination rule for µ is as follows: Γ , x : ( ν | � µ | A � ) ⊢ B type 1 @ o Γ , y : ( ν ◦ µ | A ) ⊢ M 1 : B [mod µ ( y ) / x ] @ o Γ , � ν ⊢ M 0 : � µ | A � @ m Γ ⊢ let ν mod µ ( y ) ← M 0 in M 1 : B [ M 0 / x ] @ o 41

  44. Modal induction The final piece of the puzzle is the elimination rule for � µ | A � . • At a high-level this rule let’s us replace x : � µ | A � with y : ( µ | A ). • We must generalize to replacing x : ( ν | � µ | A � ) with y : ( ν ◦ µ | A ). • We rephrase this as a pattern-matching or cut-style rule. Fix ν : m → o , µ : n → m . The elimination rule for µ is as follows: Γ , x : ( ν | � µ | A � ) ⊢ B type 1 @ o The motive Γ , y : ( ν ◦ µ | A ) ⊢ M 1 : B [mod µ ( y ) / x ] @ o Γ , � ν ⊢ M 0 : � µ | A � @ m Γ ⊢ let ν mod µ ( y ) ← M 0 in M 1 : B [ M 0 / x ] @ o 41

  45. Modal induction The final piece of the puzzle is the elimination rule for � µ | A � . • At a high-level this rule let’s us replace x : � µ | A � with y : ( µ | A ). • We must generalize to replacing x : ( ν | � µ | A � ) with y : ( ν ◦ µ | A ). • We rephrase this as a pattern-matching or cut-style rule. Fix ν : m → o , µ : n → m . The elimination rule for µ is as follows: Γ , x : ( ν | � µ | A � ) ⊢ B type 1 @ o Γ , y : ( ν ◦ µ | A ) ⊢ M 1 : B [mod µ ( y ) / x ] @ o The base case Γ , � ν ⊢ M 0 : � µ | A � @ m Γ ⊢ let ν mod µ ( y ) ← M 0 in M 1 : B [ M 0 / x ] @ o 41

  46. Modal induction The final piece of the puzzle is the elimination rule for � µ | A � . • At a high-level this rule let’s us replace x : � µ | A � with y : ( µ | A ). • We must generalize to replacing x : ( ν | � µ | A � ) with y : ( ν ◦ µ | A ). • We rephrase this as a pattern-matching or cut-style rule. Fix ν : m → o , µ : n → m . The elimination rule for µ is as follows: Γ , x : ( ν | � µ | A � ) ⊢ B type 1 @ o Γ , y : ( ν ◦ µ | A ) ⊢ M 1 : B [mod µ ( y ) / x ] @ o The term we pattern Γ , � ν ⊢ M 0 : � µ | A � @ m match on. Γ ⊢ let ν mod µ ( y ) ← M 0 in M 1 : B [ M 0 / x ] @ o 41

  47. Taking stock of MTT It’s easy to feel this is just “one damn rule after another”, but at a high-level: a modality for each a coercion for each morphism in M 2-cell in M modal introduction needs richer we equip variables with modalities contexts and occurences with 2-cells we equip contexts with locks and there is now a mismatch between make modalities ‘right adjoints’ modal annotations and types modal elimination moves from a we must factor locks into the modal type to an annotation variable rule 42

  48. Summary of crucial modal rules Γ , � µ ⊢ A type 1 @ n µ : n → m Γ ctx @ m µ : n → m Γ ctx @ m Γ , � µ ctx @ n Γ , x : ( µ | A ) ctx @ m Γ , � µ ⊢ A type ℓ @ n µ : n → m ν : m → n α : ν ⇒ locks(Γ 1 ) Γ 0 , x : ( ν | A ) , Γ 1 ⊢ x α : A α @ m Γ ⊢ � µ | A � type ℓ @ m Γ , � µ ⊢ M : A @ n µ : n → m Γ ⊢ mod µ ( M ) : � µ | A � @ m µ : n → m ν : m → o Γ , x : ( ν | � µ | A � ) ⊢ B type 1 @ o Γ , � ν ⊢ M 0 : � µ | A � @ m Γ , x : ( ν ◦ µ | A ) ⊢ M 1 : B [mod µ ( x ) / x ] @ o Γ ⊢ let ν mod µ ( x ) ← M 0 in M 1 : B [ M 0 / x ] @ o 43

  49. Modal combinators The mode theory is reflected into MTT as a series of modal combinators: � 1 | A � ≃ A � µ | � ν | A �� ≃ � µ ◦ ν | A � � µ | A � → � ν | A � (For each α : µ ⇒ ν ) � µ | A → B � → ( � µ | A � → � µ | B � ) All of these follow because � is a 2-functor out of M coop : Γ , � 1 = Γ ctx @ m Γ , � µ , � ν = Γ , � µ ◦ ν ctx @ m Γ , � ν ⊢ � α Γ : Γ , � µ @ m 44

  50. Example definitions of modal combinators To get a feel for MTT, let us define some of these combinators. Programs Holes coe[ α : µ ⇒ ν ]( − ) : � µ | A � → � ν | A α � x : (1 | � µ | A � ) ⊢ ? : � ν | A � coe[ α ]( x ) � ? 45

  51. Example definitions of modal combinators To get a feel for MTT, let us define some of these combinators. Programs Holes coe[ α : µ ⇒ ν ]( − ) : � µ | A � → � ν | A α � x : (1 | � µ | A � ) , y : ( µ | A ) ⊢ ? : � ν | A � coe[ α ]( x ) � let mod µ ( y ) ← x in ? 45

  52. Example definitions of modal combinators To get a feel for MTT, let us define some of these combinators. Programs Holes coe[ α : µ ⇒ ν ]( − ) : � µ | A � → � ν | A α � x : (1 | � µ | A � ) , y : ( µ | A ) , � ν ⊢ ? : A coe[ α ]( x ) � let ν mod µ ( y ) ← x in mod ν (?) 45

  53. Example definitions of modal combinators To get a feel for MTT, let us define some of these combinators. Programs Holes coe[ α : µ ⇒ ν ]( − ) : � µ | A � → � ν | A α � coe[ α ]( x ) � let ν mod µ ( y ) ← x in mod ν ( y α ) 45

  54. Example definitions of modal combinators To get a feel for MTT, let us define some of these combinators. Programs Holes coe[ α : µ ⇒ ν ]( − ) : � µ | A � → � ν | A α � coe[ α ]( x ) � let ν mod µ ( y ) ← x in mod ν ( y α ) comp µ,ν ( − ) : � µ ◦ ν | A � → � µ | � ν | A �� x : (1 | � µ ◦ ν | A � ) ⊢ ? : � µ | � ν | A �� comp( x ) � ? 45

  55. Example definitions of modal combinators To get a feel for MTT, let us define some of these combinators. Programs Holes coe[ α : µ ⇒ ν ]( − ) : � µ | A � → � ν | A α � coe[ α ]( x ) � let ν mod µ ( y ) ← x in mod ν ( y α ) comp µ,ν ( − ) : � µ ◦ ν | A � → � µ | � ν | A �� x : ( · · · ) , y : ( µ ◦ ν | A ) ⊢ ? : � µ | � ν | A �� comp( x ) � let mod µ ◦ ν ( y ) ← x in ? 45

  56. Example definitions of modal combinators To get a feel for MTT, let us define some of these combinators. Programs Holes coe[ α : µ ⇒ ν ]( − ) : � µ | A � → � ν | A α � coe[ α ]( x ) � let ν mod µ ( y ) ← x in mod ν ( y α ) comp µ,ν ( − ) : � µ ◦ ν | A � → � µ | � ν | A �� x : ( · · · ) , y : ( µ ◦ ν | A ) , � µ ⊢ ? : � ν | A � comp( x ) � let mod µ ◦ ν ( y ) ← x in mod µ (?) 45

  57. Example definitions of modal combinators To get a feel for MTT, let us define some of these combinators. Programs Holes coe[ α : µ ⇒ ν ]( − ) : � µ | A � → � ν | A α � coe[ α ]( x ) � let ν mod µ ( y ) ← x in mod ν ( y α ) comp µ,ν ( − ) : � µ ◦ ν | A � → � µ | � ν | A �� x : ( · · · ) , y : ( µ ◦ ν | A ) , � µ ◦ ν ⊢ ? : A comp( x ) � let mod µ ◦ ν ( y ) ← x in mod µ (mod ν (?)) 45

  58. Example definitions of modal combinators To get a feel for MTT, let us define some of these combinators. Programs Holes coe[ α : µ ⇒ ν ]( − ) : � µ | A � → � ν | A α � coe[ α ]( x ) � let ν mod µ ( y ) ← x in mod ν ( y α ) comp µ,ν ( − ) : � µ ◦ ν | A � → � µ | � ν | A �� comp( x ) � let mod µ ◦ ν ( y ) ← x in mod µ (mod ν ( y )) 45

  59. Results about MTT A major strength of MTT is that we can prove theorems irrespective of M . Theorem (Consistency) There is no term · ⊢ M : Id B (tt , ff) @ m. Theorem (Canonicity) Subject to a technical restriction, if · ⊢ M : A @ m is a closed term, then the following conditions hold: • If A = B , then · ⊢ M = tt : B @ m or · ⊢ M = ff : B @ m. • If A = Id A 0 ( N 0 , N 1 ) then · ⊢ M = refl( N 0 ) : Id A 0 ( N 0 , N 1 ) @ m. • If A = � µ | A 0 � then · ⊢ M = mod µ ( N ) : � µ | A 0 � @ m for some N. As time permits we’ll return to canonicity, but for now just take it on faith. 46

  60. Example: guarded recursion The other major strength of MTT is that we can use it to model interesting examples! • We’ll be interested in using MTT to model guarded recursion . • Guarded recursion is naturally multimode. • This situation crucially requires the interaction of modalities. 47

  61. Guarded recursion: a brief introduction Guarded recursion uses two modalities to isolate productive and coinductive programs. 48

  62. Guarded recursion: a brief introduction Guarded recursion uses two modalities to isolate productive and coinductive programs. 1. The later modality � tags computation which are available at the next step: next : A → � A l¨ ob : ( � A → A ) → A 2. The always modality � tags computation which do not depend on the time step: extract : � A → A dup : � A ≃ �� A These two modalities interact in a crucial way to give coinductive programs: now : � � A → � A 48

  63. Splitting guarded recursion into 2 modes Previous guarded type theories had a single mode, we opt for 2 modes . t s 49

  64. Splitting guarded recursion into 2 modes Previous guarded type theories had a single mode, we opt for 2 modes . Varies with time t (PSh( ω )). No notion of time s (Set). 49

  65. Splitting guarded recursion into 2 modes Previous guarded type theories had a single mode, we opt for 2 modes . t γ δ s 49

  66. Splitting guarded recursion into 2 modes Previous guarded type theories had a single mode, we opt for 2 modes . t Allow a constant type to γ δ trivially vary over time. s 49

  67. Splitting guarded recursion into 2 modes Previous guarded type theories had a single mode, we opt for 2 modes . t Restrict a varying type γ δ to global elements. s 49

  68. Splitting guarded recursion into 2 modes Previous guarded type theories had a single mode, we opt for 2 modes . � A � � δ ◦ γ | A � t γ δ s 49

  69. Splitting guarded recursion into 2 modes Previous guarded type theories had a single mode, we opt for 2 modes . ℓ � A � � δ ◦ γ | A � t � A � � ℓ | A � Γ A � � γ | A � ∆ A � � δ | A � γ δ s 49

  70. Splitting guarded recursion into 2 modes Previous guarded type theories had a single mode, we opt for 2 modes . ℓ � A � � δ ◦ γ | A � δ ◦ γ ≤ 1 1 = γ ◦ δ t � A � � ℓ | A � 1 ≤ ℓ γ = γ ◦ ℓ Γ A � � γ | A � ∆ A � � δ | A � γ δ s 49

  71. Modal operations The terms for the following operations are all induced by generic combinators: − ⊛ − : � ( A → B ) → � A → � B next : A → � A extract : � A → A dup : � A ≃ �� A now : � � A → � A In particular, next and extract are instances of coercions, while dup and now follow from associativity. 50

  72. What about L¨ ob? • We can use the standard operations on MTT to derive all operations except L¨ ob. • L¨ ob is actually a bit of problem; it’s a modality-specific operation! 51

  73. What about L¨ ob? • We can use the standard operations on MTT to derive all operations except L¨ ob. • L¨ ob is actually a bit of problem; it’s a modality-specific operation! Instead, we have to simply axiomitize L¨ ob: Γ , x : ( ℓ | A 1 ≤ ℓ ) ⊢ M : A @ t Γ ⊢ l¨ ob( x . M ) : A @ t Γ , x : ( ℓ | A 1 ≤ ℓ ) ⊢ M : A @ t Γ ⊢ l¨ ob( x . M ) = let mod ℓ ( x ) ← next(l¨ ob( x . M )) in M : A @ t (NB: A 1 ≤ ℓ moves A from the Γ to Γ , � ℓ ) 51

  74. What about L¨ ob? • We can use the standard operations on MTT to derive all operations except L¨ ob. • L¨ ob is actually a bit of problem; it’s a modality-specific operation! Instead, we have to simply axiomitize L¨ ob: Γ , x : ( ℓ | A 1 ≤ ℓ ) ⊢ M : A @ t Γ ⊢ l¨ ob( x . M ) : A @ t Γ , x : ( ℓ | A 1 ≤ ℓ ) ⊢ M : A @ t Γ ⊢ l¨ ob( x . M ) = let mod ℓ ( x ) ← next(l¨ ob( x . M )) in M : A @ t (NB: A 1 ≤ ℓ moves A from the Γ to Γ , � ℓ ) (NB: We follow Bizjak et al. [Biz+16] and just work in an extensional type theory.) 51

  75. An aside: modality-specific operations It’s not clear yet what the proper formulation of L¨ ob would be. It belongs to a large class of operations which entangle a modality and another connective (in this case, → and � ) which we term modality-specific . Question Is there a reasonable class of modality-specific operations that can be handled uniformly? 52

  76. Programming in Guarded MTT Now that we have these combinators established, we can use them to write guarded programs. Str ′ � l¨ ob( S . ∆( A ) × � S ) A Str : U → U @ s Str( A ) � Γ(Str ′ A ) 53

Recommend


More recommend