SLIDE 1 Multimodal Dependent Type Theory
Daniel Gratzer0 Alex Kavvos0 Andreas Nuyts1 Lars Birkedal0 ICMS 2020
0Aarhus University 1imec-DistriNet, KU Leuven
SLIDE 2 The problem
We’d like extend Martin-L¨
- f Type Theory and apply it to new situations.
- Staged programming [PD01].
- Proof-irrelevance [Pfe01].
- Guarded recursion [Clo+15; BGM17; Gua18].
- Parametric quantification [ND18].
- Exotic models of computation [Bir00].
- (Abstract) topology [Shu18].
- Differential geometry [Wel18].
Let’s extend MLTT to these situations...
1
SLIDE 3 The problem
We’d like extend Martin-L¨
- f Type Theory and apply it to new situations.
- Staged programming [PD01].
- Proof-irrelevance [Pfe01].
- Guarded recursion [Clo+15; BGM17; Gua18].
- Parametric quantification [ND18].
- Exotic models of computation [Bir00].
- (Abstract) topology [Shu18].
- Differential geometry [Wel18].
Let’s extend MLTT to these situations... and use modalities to tame these extensions.
1
SLIDE 4 A tangent: what exactly is a modality?
In general, people use modality to mean many different things:
- 1. Any unary type constructor.
- 2. A unary type constructor which is an internal functor.
- 3. A unary type constructor equipped with a monad structure.
For our work, a modality is essentially a right adjoint.1 This restriction yields a practical syntax and still includes many examples.
1More specifically, a modality is essentially a dependent right adjoint [Bir+20]
2
SLIDE 5 A story of several type theories
Let us consider a representative example of how modal type theories are developed.
- 1. Work on guarded recursion converges towards the Fitch-style [BGM17; Clo18].
- 2. Birkedal et al. [Bir+20] isolate this into paradigmatic type theory.
- 3. Gratzer, Sterling, and Birkedal [GSB19] prove normalization for a similar system.
Each of these type theories build upon each other... but no reuse is possible.
3
SLIDE 6 Our Contribution: MTT
We introduce MTT: a type theory parameterized by a collection of modalities.
- MTT features usual connectives of Martin-L¨
- f 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 [Shu18]
- Parametricity [ND18]
- Guarded recursion [Biz+16]
- And many more...
4
SLIDE 7 Modes and mode theories
MTT is a multimode type theory, not just multimodal.
- 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.
5
SLIDE 8 Modes and mode theories
MTT is a multimode type theory, not just multimodal.
- 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] and specify our modalities as a mode theory, a (strict) 2-category:
morphism ∼ modality 2-cell ∼ coercion (a natural map between modalities)
5
SLIDE 9 An example: an idempotent comonad
The mode theory for an idempotent comonad is generated from the following data:
morphisms: {µ : m → m} 2-cells: {ǫ : µ ⇒ 1} Furthermore, µ ◦ µ = µ and that α = β for any pair of 2-cells.
6
SLIDE 10 An example: an idempotent comonad
The mode theory for an idempotent comonad is generated from the following data:
morphisms: {µ : m → m} 2-cells: {ǫ : µ ⇒ 1} Furthermore, µ ◦ µ = µ and that α = β for any pair of 2-cells. This induces a single modality µ | − with the following coercions: Γ ⊢ M : µ | A @ m Γ ⊢ extract(M) : A @ m Γ ⊢ M : µ | A @ m Γ ⊢ duplicate(M) : µ | µ | A @ m These satisfy the comonad laws.
6
SLIDE 11 An example: an idempotent comonad
The mode theory for an idempotent comonad is generated from the following data:
morphisms: {µ : m → m} 2-cells: {ǫ : µ ⇒ 1} Furthermore, µ ◦ µ = µ and that α = β for any pair of 2-cells. This induces a single modality µ | − with the following coercions: Γ ⊢ M : µ | A @ m Γ ⊢ extract(M) : A @ m Γ ⊢ M : µ | A @ m Γ ⊢ duplicate(M) : µ | µ | A @ m A mode annotation. These satisfy the comonad laws.
6
SLIDE 12
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 Each judgment is localized to a mode and each mode contains a copy of MLTT.
7
SLIDE 13
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.
8
SLIDE 14
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 One of these must live in the wrong mode.
8
SLIDE 15
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 One of these must live in the wrong mode. We require additional judgmental structure to make sense of modal types.
8
SLIDE 16
Fitch-style contexts
MTT uses a Fitch-style context so modalities to have an action on contexts: µ : n → m Γ ctx @ m Γ, µ ctx @ n Intuition: −, µ ⊣ µ | −
9
SLIDE 17
Fitch-style contexts
MTT uses a Fitch-style context so modalities to have an action on contexts: µ : n → m Γ ctx @ m Γ, µ ctx @ n Intuition: −, µ ⊣ µ | − Accordingly, the introduction and formation rules are transposition: µ : n → m Γ, µ ⊢ M : A @ n Γ ⊢ modµ(M) : µ | A @ m Follows the Fitch-style [BGM17; Clo18; Bir+20; GSB19] (whence the notation!)
9
SLIDE 18
Fitch-style contexts with multiple modalities
Prior work had one modality, hence one lock. How do we scale to many modalities? Γ ctx @ m Γ = Γ, 1 ctx @ m ν : o → n µ : n → m Γ ctx @ m Γ, µ, ν = Γ, µ◦ν ctx @ o
10
SLIDE 19
Fitch-style contexts with multiple modalities
Prior work had one modality, hence one lock. How do we scale to many modalities? Γ ctx @ m Γ = Γ, 1 ctx @ m ν : o → n µ : n → m Γ ctx @ m Γ, µ, ν = Γ, µ◦ν ctx @ o In fact, is part of a 2-functor from Mcoop to contexts giving an admissible rule µ, ν : n → m α : µ ⇒ ν Γ, ν ⊢ M : A @ n Γ, µ ⊢ Mα : Aα @ n (NB: −α must be applied to both the term and the type.)
10
SLIDE 20
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
11
SLIDE 21
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
11
SLIDE 22 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.
11
SLIDE 23
Variable annotations
In addition to locks, each variable in the context will be annotated with a modality. µ : n → m Γ ctx @ m Γ, µ ⊢ A type @ n Γ, x : (µ | A) ctx @ m Intuition: Γ, x : (µ | A) is roughly Γ, x : µ | A.
12
SLIDE 24
Variable annotations
In addition to locks, each variable in the context will be annotated with a modality. µ : n → m Γ ctx @ m Γ, µ ⊢ A type @ n Γ, x : (µ | A) ctx @ m Intuition: Γ, x : (µ | A) is roughly Γ, x : µ | A. µ : n → m Γ, x : (µ | A), µ ⊢ x : A @ n Γ ⊢ M0 : µ | A @ m Γ, y : (µ | A) ⊢ M1 : B[modµ(y)/x] @ m Γ ⊢ let modµ(y) ← M0 in M1 : B[M0/x] @ m
12
SLIDE 25
Variable annotations
In addition to locks, each variable in the context will be annotated with a modality. µ : n → m Γ ctx @ m Γ, µ ⊢ A type @ n Γ, x : (µ | A) ctx @ m Intuition: Γ, x : (µ | A) is roughly Γ, x : µ | A. µ : n → m Γ, x : (µ | A), µ ⊢ x : A @ n Γ ⊢ M0 : µ | A @ m Γ, y : (µ | A) ⊢ M1 : B[modµ(y)/x] @ m Γ ⊢ let modµ(y) ← M0 in M1 : B[M0/x] @ m Counit of −, µ ⊣ µ | −
12
SLIDE 26
Variable annotations
In addition to locks, each variable in the context will be annotated with a modality. µ : n → m Γ ctx @ m Γ, µ ⊢ A type @ n Γ, x : (µ | A) ctx @ m Intuition: Γ, x : (µ | A) is roughly Γ, x : µ | A. µ : n → m Γ, x : (µ | A), µ ⊢ x : A @ n Γ ⊢ M0 : µ | A @ m Γ, y : (µ | A) ⊢ M1 : B[modµ(y)/x] @ m Γ ⊢ let modµ(y) ← M0 in M1 : B[M0/x] @ m Shift from Γ, x : µ | A to Γ, x : (µ | A)
12
SLIDE 27
Variable annotations
In addition to locks, each variable in the context will be annotated with a modality. µ : n → m Γ ctx @ m Γ, µ ⊢ A type @ n Γ, x : (µ | A) ctx @ m Intuition: Γ, x : (µ | A) is roughly Γ, x : µ | A. µ, ν : n → m α : µ → ν Γ, x : (µ | A), ν ⊢ xα : Aα @ n Γ ⊢ M0 : µ | A @ m Γ, y : (µ | A) ⊢ M1 : B[modµ(y)/x] @ m Γ ⊢ let modµ(y) ← M0 in M1 : B[M0/x] @ m
12
SLIDE 28
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 morphism in M a coercion for each 2-cell in M modal introduction needs richer contexts we equip contexts with locks and make modalities ‘right adjoints’ we must factor locks into the variable rule we equip variables with modalities and occurences with 2-cells there is now a mismatch between modal annotations and types modal elimination moves from a modal type to an annotation
13
SLIDE 29
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 from the 2-functoriality of .
14
SLIDE 30
Example definitions of modal combinators
To get a feel for MTT, let us define some of these combinators. Programs coe[α : µ ⇒ ν](−) : µ | A → ν | Aα coe[α](x) Holes x : (1 | µ | A) ⊢ : ν | A
15
SLIDE 31
Example definitions of modal combinators
To get a feel for MTT, let us define some of these combinators. Programs coe[α : µ ⇒ ν](−) : µ | A → ν | Aα coe[α](x) let modµ(y) ← x in Holes x : (1 | µ | A), y : (µ | A) ⊢ : ν | A
15
SLIDE 32
Example definitions of modal combinators
To get a feel for MTT, let us define some of these combinators. Programs coe[α : µ ⇒ ν](−) : µ | A → ν | Aα coe[α](x) letν modµ(y) ← x in modν() Holes x : (1 | µ | A), y : (µ | A), ν ⊢ : A
15
SLIDE 33
Example definitions of modal combinators
To get a feel for MTT, let us define some of these combinators. Programs coe[α : µ ⇒ ν](−) : µ | A → ν | Aα coe[α](x) letν modµ(y) ← x in modν(yα) Holes
15
SLIDE 34 Results about MTT
A major strength of MTT is that we can prove theorems irrespective of M. Theorem (Consistency) There is no term · ⊢ M : IdB(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 = IdA0(N0, N1) then · ⊢ M = refl(N0) : IdA0(N0, N1) @ m.
- If A = µ | A0 then · ⊢ M = modµ(N) : µ | A0 @ m for some N.
16
SLIDE 35
Example: axiomatic cohesion
The other major strength of MTT is that we can use it to model interesting examples!
17
SLIDE 36 Axiomatic cohesion: a brief introduction
Axiomatic cohesion uses a handful of modalities to relate spaces and sets
- 1. Semantically, we demand two categories and a collection of functors between
them: E B ⊣ ⊣ ⊣ Γ ∆ Π0 ∇ (Where Π0 preserves finite limits and ∆ and ∇ are full and faithful)
- 2. Type-theoretic approaches have considered only E and the monad induced by
♯ = ∇ ◦ Γ and its left adjoint, the comonad ♭ = ∆ ◦ Γ [Shu18].
18
SLIDE 37
Splitting axiomatic cohesion into 2 modes
It’s more natural with MTT to work with two modes directly. t s
19
SLIDE 38
Splitting axiomatic cohesion into 2 modes
It’s more natural with MTT to work with two modes directly. t s Spaces. Sets.
19
SLIDE 39
Splitting axiomatic cohesion into 2 modes
It’s more natural with MTT to work with two modes directly. t s κ γ δ
19
SLIDE 40
Splitting axiomatic cohesion into 2 modes
It’s more natural with MTT to work with two modes directly. t s κ γ δ ∆A δ | A ΓA γ | A ∇A κ | A
19
SLIDE 41
Splitting axiomatic cohesion into 2 modes
It’s more natural with MTT to work with two modes directly. t s κ γ δ ∆A δ | A ΓA γ | A ∇A κ | A ǫ0 : δ ◦ γ ⇒ 1 η0 : 1 ⇒ γ ◦ δ ǫ1 : γ ◦ κ ⇒ 1 η1 : 1 ⇒ κ ◦ γ ... triangle equalities
19
SLIDE 42
Splitting axiomatic cohesion into 2 modes
It’s more natural with MTT to work with two modes directly. t s κ γ δ ∆A δ | A ΓA γ | A ∇A κ | A ǫ0 : δ ◦ γ ⇒ 1 η0 : 1 ⇒ γ ◦ δ ǫ1 : γ ◦ κ ⇒ 1 η1 : 1 ⇒ κ ◦ γ ... triangle equalities ... force η0, ǫ1 to be isos
19
SLIDE 43
Splitting axiomatic cohesion into 2 modes
It’s more natural with MTT to work with two modes directly. t s κ γ δ ∆A δ | A ΓA γ | A ∇A κ | A ǫ0 : δ ◦ γ ⇒ 1 η0 : 1 ⇒ γ ◦ δ ǫ1 : γ ◦ κ ⇒ 1 η1 : 1 ⇒ κ ◦ γ ... triangle equalities ... force η0, ǫ1 to be isos We cannot capture the leftmost adjoint: it’s not a dependent right adjoint.
19
SLIDE 44 Modal operations
Instantiating MTT gives us a workable cohesive type theory [Shu18]:
- We can derive transposition-type formulas.
(Γ(∆A → B)) → (Aη0 → ∆B)
- Various crisp induction principles are provable.
Γ(IdA(M, N)) ≃ IdΓ(A)(modγ(M), modγ(N))
- And (with funext) we can prove something akin to full and faithfulness.
(A → B) ≃ Γ(∆A → ∆B) Detailed proofs of these results (and more!) are given in the technical report.
20
SLIDE 45 Conclusions
We introduce MTT: a type theory parameterized by a collection of modalities.
- MTT features usual connectives of Martin-L¨
- f 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
https://jozefg.github.io/papers/multimodal-dependent-type-theory.pdf https://jozefg.github.io/papers/type-theory-a-la-mode.pdf
21