Semantics of multimodal adjoint type theory

We show that contrary to appearances, Multimodal Type Theory (MTT) over a 2-category M can be interpreted in any M -shaped diagram of categories having, and functors preserving, M -sized limits, without the need for extra left adjoints. This is achieved by a construction called “co-dextriﬁcation” that co-freely adds left adjoints to any such diagram, which can then be used to interpret the “context lock” functors of MTT. Furthermore, if any of the functors in the diagram have right adjoints, these can also be internalized in type theory as negative modalities in the style of FitchTT. We introduce the name Multimodal Adjoint Type Theory (MATT) for the resulting combined general modal type theory. In particular, we can interpret MATT in any ﬁnite diagram of toposes and geometric morphisms, with positive modalities for inverse image functors and negative modalities for direct image functors.


Introduction
Modal type theories involve type-forming operations, such as the classical ✷ (necessity) and ♦ (possibility), whose introduction and elimination rules modify the accessibility of previous hypotheses.The increasing number of modal type theories has led to a need for general frameworks that can be instantiated to any new example, to avoid having to develop the metatheory of each new modal type theory from scratch.
After [26,27], each instantiation of a general modal type theory is determined by a 2-category M, the "mode theory".Its objects denote "modes", its morphisms generate modal operators relating types at different modes, and its 2-cells govern their interaction.However, the "LSR" theory of [26,27] is only simply typed, its definitional equality is ill-behaved, and it uses awkward global context operations.
The more recent frameworks MTT [12] and FitchTT [11] resolve these problems: they are dependently typed, with a well-behaved definitional equality, and only ever extend the context; all indications suggest their implementability [10,40].However, their naïve semantics requires the functors interpreting the modal operators to have additional left adjoints ("context locks"), which are not visible internally in the syntax.
We will show that this defect is, for the most part, only apparent.Namely, from any suitable M-shaped diagram of categories, we construct a new diagram whose functors all do have left adjoints, enabling an interpretion of MTT and FitchTT.Moreover, the types in the new diagram are induced from the original Γ ⊢ p a ∶ A Γ | ∆ ⊢ q mod(a) ∶ µ⊡A ones, so this interpretation directly yields information about the original diagram.We call this the codextrification, since it makes existing functors into right adjoints and has a "cofree" universal property.
To explain the co-dextrification, consider first split-context modal type theories, e.g. as in [33,37,43].As an example, let M have two objects and one morphism µ ∶ p → q; we want to interpret modal type theory in a diagram of two categories and a functor C µ ∶ C p → C q .The split-context theory has ordinary p-judgments Γ ⊢ p J , but q-judgments Γ | ∆ ⊢ q J with the context split into a p-part Γ and a q-part ∆, where ∆ can depend on Γ.We consider the types in Γ to implicitly have C µ applied.The modal rules then rearrange these context parts: Figure 1a shows the split-context introduction rule for the µ-modality.
For general M, there is no obvious way to split the context by restricting dependency.Instead, the spiritual generalizations of split-context theories, sometimes called left-division theories (e.g.[32,31]), annotate each context variable with a morphism of M that is implicitly applied to it, and the modal rules modify these annotations.In our simple example, each variable in a q-context is annotated with µ or 1 q , and the operation Γ/µ deletes the 1 q -annotated variables and uses the others to form a p-context.For more general M, when defining Γ/ν, each annotated variable x ∶ µ A in Γ is replaced by zero or more variables annotated by a family of morphisms ̺ i equipped with 2-cells α i ∶ µ ⇒ ν • ̺ i forming a left multi-lifting, i.e. such that for any β ∶ µ ⇒ ν • σ there is a unique i and factorization of β through α i by some ̺ i ⇒ σ.
Unfortunately, a fully general M may not have all left multi-liftings.In LSR, each rule application is instead allowed to choose any morphism ̺ with α ∶ µ ⇒ ν • ̺; the problems of LSR stem from the non-uniqueness of such a choice.MTT and FitchTT solve this by delaying the choice of 2-cells, treating (−)/µ as a constructor of contexts rather than an operation on them that computes.(It is then sometimes written as Γ. µ or Γ.{µ}, but I see no reason not to stick with Γ/µ.) Figure 1b shows µ⊡(−) is "right adjoint" to (−)/µ, so the semantics of these theories appears to require the modality functors to have left adjoints.This contrasts with how we interpreted the split-context theory in a comma category, creating a new left adjoint.Some work [38,24] tried to generalize this by mimicking annotated contexts in semantics, but this was complicated and difficult.Instead, we change perspective: rather than regarding an object of (C q ↓ C µ ) as an object Γ ∈ C p together with an object Γ⊲∆ ∈ C q that depends on C µ (Γ), we regard it as an object ∆ ∈ C q together with a "specified value of ∆/µ" in C p , and a weakening substitution from ∆ to C µ (∆/µ).How a context is built from annotated types -like the fact that it is built from types at all -is a property of syntax that doesn't need to be reflected in semantics.We can now generalize to any M: each C q is an oplax limit of the C p over a slice 2-category.
It remains to specify how to extend such a context by a type, i.e. how do we compute (Γ, x ∶ µ A)/ν in terms of Γ/ν and A? Instead of choosing one pair (̺, α) as in LSR, or a universal family of them as in a multi-lifting theory, we use all of them.More precisely, we define (Γ, x ∶ µ A)/ν to be the extension of Γ/ν by the limit of x ∶ ̺ A over all such (̺, α).It is unclear whether this can be done syntactically, but semantically it is unproblematic.When a left multi-lifting exists, this limit reduces to the product of x ∶ ̺ A over the elements of the multi-lifting.And if there are no such ̺, the limit is a terminal object and A is simply deleted, as happens to ∆ in Figure 1a.This is the essential idea of co-dextrification.It is formally similar to Hofmann's "right adjoint splitting" [15] for strict pullbacks, suggesting it can similarly be regarded as a sort of coherence theorem.
The co-dextrification does require each C p to have, and each C µ to preserve, limits of the size of M. This is unproblematic if M is finite, but modal operators often come in adjoint pairs (e.g. as geometric morphisms of topoi), and as soon as M contains a generic adjunction it is infinite.Fortunately, if some C µ has a right adjoint, that adjoint automatically lifts to a dependent right adjoint of C µ .Thus, it suffices to apply co-dextrification over a smaller 2-category L that generates M by adding some right adjoints.
The resulting type theory represents the morphisms in L by positive modalities as in MTT, but their right adjoints by negative modalities as in FitchTT.(For a particular L, such a combination appeared in [5].)The positive elimination rules also restrict which morphisms of M can appear as "framings": this would be problematic for internalizing functoriality, except for the stronger elimination rule of the negative modalities.We call this theory Multimodal Adjoint Type Theory (MATT).If we regard L, rather than M, as the fundamental parameter of MATT, then it restores the symmetry of [26,27] in which each morphism (of L) generates a positive/negative pair of modalities that are automatically adjoint.

Acknowledgement
I am extremely grateful to Daniel Gratzer, for many long and illuminating conversations about modal type theories, for many concrete suggestions about MATT (including the name), and for careful reading and bugfixes.Dan Licata also contributed useful ideas to some of these conversations.
Although our semantics will have a mode theory with right adjoints added freely, it is simpler to formulate syntax using an arbitrary 2-category M equipped with placeholders for the necessary restrictions.Definition 2.1 An adjoint mode theory is a 2-category M equipped with four classes of morphisms in M called tangible, sharp, transparent, and sinister, such that • Every identity morphism is transparent and sharp.
• If µ ∶ p → q is sharp and ν ∶ q → r is transparent, then ν • µ ∶ p → r is tangible.(Thus, every transparent or sharp morphism, and in particular every identity morphism, is tangible.) MATT over an adjoint mode theory M is MTT [12] over M with a few modifications.We write x ∶ µ A in place of x ∶ (µ | A), and µ⊡A in place of ⟨µ | A⟩.We will show the most important MTT rules, but we omit technical details of substitutions.We now list the substantive modifications.
(1) The modalities annotating variables in contexts must be tangible.Tangibility of identities yields ordinary type theories at each mode.The context rules are shown in Figure 2, along with a substitution rule that combines functoriality and naturality (the other substitution rules are more ordinary), and the variable-use rule in Figure 3 along with the rule for substituting keys into variables.2(2) The modalities µ that annotate domains of function-types (x ∶ µ A) → B must be sharp.Sharpness of identities yields ordinary function-types, and tangibility of sharp morphisms is required for the formation and introduction rules.All the rules are shown in Figure 4. (3) The modalities µ that generate positive modal operators µ⊡A must be sharp, and the "framing" modality in its elimination rule must be transparent.The rules for positive modal operators are shown in Figure 5.The elimination rule requires both transparent morphisms, and composites of transparent and sharp morphisms, to be tangible.(4) Every sinister morphism generates a negative modal operator.These are not in MTT.Their rules are shown in Figure 6; they simplify those of [11] by using right adjoints instead of parametric ones.
Remark 2.2 If µ is both sharp and sinister, the formation and introduction rules of µ A are identical to those of µ † ⊡A.Daniel Gratzer has shown that µ A actually satisfies all the rules of µ † ⊡A, while conversely if µ is transparent then µ † ⊡A satisfies all the rules of µ A except definitional η-conversion.
The flexibility in choosing the tangible, sharp, transparent, and sinister morphisms allows us to compare MATT easily to other modal type theories.
(i) If M is any 2-category, and we take all morphisms to be tangible, sharp, and transparent, but none to be sinister, then MATT reduces to MTT. (ii) For any 2-category L, let M = L[ † L] be obtained by formally adjoining a left adjoint † µ to each µ in L. We take only identities to be tangible, sharp, and transparent, and the sinister morphisms to be these left adjoints † µ; then MATT reduces to FitchTT [11] over L with actual left adjoints.(iii) The closest match with theories such as [27,37,31] occurs when M = L[L † ] is obtained by formally adjoining a right adjoint µ † to each morphism µ of L. In this case we take the tangible, sharp, and sinister morphisms to be the image of L in L[L † ]; thus all the modal operators come in adjoint pairs.Different theories make different choices about transparency: in [37] only identities are transparent, while in [31] the transparent morphisms are also the image of L. But in fact, if a morphism is both sinister and tangible, then it "might as well" be transparent, in that elimination rules with it as framing can be deduced from those with identity framing; the proof follows [37, Lemma 5.1].
Our semantics in the co-dextrification will apply to the following case.We take this image L to be the transparent morphisms, S to be the sinister morphisms, and the tangible and sharp morphisms to be those that are isomorphic to one of the form µ • ν † where µ ∈ L and ν ∈ S.This choice of tangible and sharp morphisms appears necessitated by our semantics (see Lemma 5.5), and L is then the largest class of transparent morphisms satisfying the composition axiom.

Assumption 2.4 We always consider L[S † ] to be an adjoint mode theory as in Example 2.3.
Example 2.5 We can regard Two-Level Type Theory [1] as an instance of MATT with two modes, f for (fibrant/inner) types and e for (non-fibrant/outer) exotypes, and an isomorphism ι ∶ e ∼ = f.We let all the morphisms be tangible, but we take only identities as sharp and transparent, and only the morphism ι ∶ e → f as sinister.Then ι − is the coercion from types to exotypes (c in [1]), with a bijection between terms of types A and ι A. Allowing ι to be sharp would produce fibrant replacements ι⊡A, which are inconsistent [1, §2.7] with univalence for fibrant types and UIP for exotypes.Inspecting the proof shows that the same conclusion would follow if we had modal function-types Remark 2.6 It seems likely that normalization for MTT [10] extends to MATT.But to deduce decidability of type-checking from this requires decidability of equality for M, whereas L[S † ] can fail to have decidable equality even if L does [7].However, we can hope that L[S † ] will have decidable equality if L is, say, locally finite (this is true for for 1-categories [6]).

Natural models of MATT
We now generalize the modal natural models of [12] to MATT.We first recall some definitions.
• A natural model [2] is a representable morphism τ ∶ Tm → Ty in a presheaf category PD.Thus Shulman for any A ∈ Ty(Γ) we have an object Γ ⊲ A ∈ D, a morphism p A ∶ Γ ⊲ A → Γ, and a pullback square where よ∶ D → PD denotes the Yoneda embedding.A natural model is equivalent to a category with families.We refer to Γ ⊲ A as the comprehension of A, and p A as its type projection.
has a terminal object.We write its action on morphisms and 2-cells as D µ and D α respectively.
• A modal natural model [12,Definition 5.4] is a modal context structure D with a morphism τ p ∶ Tm p → Ty p in each presheaf category PD p , such that for any µ ∶ p → q in M, the transformation An adjoint modal natural model D has positive modalities if for any sharp µ ∶ p → q we have: (i) For any Γ ∈ D q and A ∈ Ty p (D µ (Γ)), we have a type µ⊡A ∈ Ty q (Γ) and a map j µ Γ,A ∶ Γ ⊲ µ A → Γ ⊲ (µ⊡A) over Γ, all varying naturally in Γ. (ii) For any transparent ̺ ∶ q → r and Γ ∈ D r with A ∈ Ty p (D ̺•µ (Γ)), define the dashed map ℓ below by the universal property of pullbacks and full-faithfulness of よ: Then for any commutative square as below there is a chosen diagonal filler, natural in Γ:

Co-dextrification
Assumption 4.1 For all of this section, let L be an arbitrary 2-category, let C ∶ L → Cat be a pseudofunctor, and let κ be an infinite regular cardinal such that L is κ-small, each category C p has κ-small limits, and each functor C µ ∶ C p → C q preserves κ-small limits.Often, κ will be ω.
Definition 4.2 For r ∈ L, let L r denote the lax slice 2-category: By postcomposition, we have a 2-functor L − ∶ L → 2-Cat, with projection functors π r ∶ L r → L.
(The notation is abusive, as Γ α depends not just on α but on the decomposition of its codomain as a composite.)Proof.The functorial action is by composition: Proof.The limits, and colimits in (i), are defined pointwise.For (ii), an oplax limit is the category of coalgebras for a finitely continuous comonad on a product category (see [42] C σ (Γ).
Moreover, if in the above condition we take µ = ̟ with (σ, β) = (1 r , 1 ̟ ), then the left-hand vertical composite becomes θ ν,(̺,α) , which is fully general; thus all the components of θ are determined by θ ̟,(1r,1̟) .Now, given ϑ ∶ ∆ ̟ → Γ, for any ν and (σ, β) we have a composite The above compatibility condition follows from the axioms of Definition 4.3, so we have a map To give θ µ is equivalent to give θ µ ∶ Γ → R ̟•µ (∆ µ ).We will define C ̟ (∆) ∈ C s as the limit of a diagram of objects R ̟•µ (∆ µ ), so that a map Γ → C ̟ (∆) is determined by maps θ µ satisfying a cone condition that is equivalent to (4.10).We start by writing down the naturality square for the transformation R ̟⊳α of Lemma 4.8 at θ µ , and composing it with the adjunction unit We also transpose (4.10) across L ̟•ν ⊣ R ̟•ν to obtain an equivalent condition as at left below: 12) The left-bottom composite in (4.11) is equal to the top-right composite at left in (4.12).Thus, we can replace this part of the square at left in (4.12) by the top-right composite in (4.11) to obtain the equivalent condition at right in (4.12).Now we define C ̟ (∆) to be the limit in C s of the diagram consisting of the objects R ̟•µ (∆ µ ), for all µ ∶ p → r, and the cospans Proof.Let ̟ ∶ r → s and Γ ∈ C r ; we must show that C ̟ (Γ) 1s ∼ = C ̟ (Γ 1s ).Since L s = L 1s preserves κsmall limits, C ̟ (Γ) 1s is the limit of the diagram consisting of the objects (R ̟•µ (Γ µ )) 1s , for all µ ∶ p → r, and the analogous cospans.And by definition of R ̟•µ , each of these objects is the limit A similar argument applies to the apices of the cospans, so C ̟ (Γ) 1s is the limit of the diagram consisting of the objects C ̟•µ (Γ µ ), for all µ ∶ p → r, and the cospans However, there is a canonical such object where µ = 1 r , and for any other ) in which the right-hand leg is an identity.Thus, the limit of this diagram is isomorphic to C ̟ (Γ 1s ).✷ Lemma 4. 15 The functors R r ∶ C r → C r are lax natural, by doctrinal adjunction [20].✷

MATT in the co-dextrification
We now show that for suitable C , the co-dextrification C models MATT over L[S † ] (recall Assumption 2.4).In fact, we use only its abstract properties; this makes our arguments cleaner and more general.

Adjoint modal pre-models
Recall that a natural pseudo-model [39, Appendix A] is a strict natural transformation τ ∶ Tm → Ty between groupoid-valued pseudofunctors Tm, Ty ∶ D op → Gpd that has discrete fibers and is representable.Example 5.2 If C ∶ L → Cat is a pseudofunctor such that each C p is locally cartesian closed with κ-small limits, each functor C µ preserves κ-small limits, and C µ has a right adjoint if µ ∈ S, then the co-dextrification C extends it to an adjoint modal pre-model.Remark 5.3 If each L p is an identity, then Definition 5.1 is just a modal context structure C ∶ L[L † ] coop → Cat consisting of locally cartesian closed natural pseudo-models such that C µ has a right adjoint when µ ∈ S. In this case, the results we will prove in this section specialize to a more ordinary version of [29] for the modal case, when the lock functors already exist but we need to strictify the type formers.

Lemma 5.4 In an adjoint modal pre-model, if
Proof.The pullbacks of maps in the image of R p are a left-exact-reflective subcategory of C p /C; the reflection L /C applies L p and pulls back to C. For any h ∶ D → C, morphisms h → g * (f ) in C p /C are equivalent to morphisms g * (h) → f in C p /B.By assumption on f , any such morphism factors through L /B (g * (h)), which is g * (L /C (h)) by left-exactness of L p .Thus, it also corresponds to a map L /C (h) → g * (f ).Taking h = g * (f ) we conclude that g * (f ) ∼ = L /C (g * (f )) and hence lies in the subcategory.✷

The left adjoint splitting
The left adjoint splitting [29] of a natural pseudo-model (D, τ ) is τ !∶ Tm !→ Ty !where: Given an adjoint modal pre-model, we define τ !p = (L p ) * τ !p .Thus, an element A ∈ Ty !p (Γ) consists of an object V A ∈ C p , a type E A ∈ Ty p (V A ), and a morphism ⌜A⌝ ∶ L p Γ → V A , or equivalently ⌜A⌝ ∶ Γ → R p V A .Proof.The tangible morphisms in L[S † ] are µ • ν † , for µ ∶ q → r in L and ν ∶ q → p in S. Thus, we must show that in this case and this has a right adjoint C µ • R q • C ν † .Finally, restriction along any functor with a right adjoint preserves representability. ✷ ) is an adjoint modal pre-model, then for any of the type constructors considered in [29], if (C , τ ) has weakly stable structure, then ( C , τ ! ) has strictly stable structure.
Proof.Since L p preserves finite limits, any weakly stable or pseudo-stable structure on τ p lifts to (L p ) * τ p .Therefore, by [29], ((L p ) * τ p ) ! has strictly stable structure.If we identify C p with the image of R p , then Ty !⊆ ((L p ) * Ty p ) ! consists of the types whose local universes lie in C p .By Lemma 5.4, C p is closed under all the local universe manipulations of [29]; hence τ ! is closed under the strictly stable structure.✷ For the modal type formers, the "weakly stable" structure exists on C alone; thus we name its structure.Proof.Suppose we have µ ∶ q → r in L and ν ∶ q → p in S, and also Γ ∈ C r and A ∈ Ty Applying L r to the defining pullback (5.6) of Γ ⊲ µ•ν † A, and using pseudonaturality and the fact that L q R q ∼ = 1, we have a pullback (5.13) Thus, Definition 5.10 says L r ( p A ) is type-exponentiable, hence the pushforward of B along it is a type projection; it remains to construct a local universe making it strictly stable.Let V Π(A,B) be the universal object with maps ) along it is represented by a type E Π(A,B) ∈ Ty q (V Π(A,B) ).Now the bottom map in (5.13) and A,B) .Together, these data define Π(A, B) ∈ Ty !p (Γ), such that 11 is defined by applying R q to this and pulling back along the unit Γ → R q L q Γ.Thus, Lemma 5.11 impliesthe desired universal property of Π(A, B). ✷

Positive modalities
Definition 5.14 In a natural pseudo-model, a map f ∶ Γ → ∆ is anodyne if for any B ∈ Ty(∆) and any g ∶ Γ → ∆ ⊲ B lifting f , there exists a diagonal filler: A map is stably anodyne if any pullback of it is anodyne.
Definition 5.15 A modal pre-model C has positive pre-modalities if for any sharp µ ∶ p → q and Γ ∈ C p with A ∈ Ty p (Γ), there exists µ□A ∈ Ty q (C µ Γ) and a map Proof.Suppose given B ∈ Ty !p (∆) = Ty !p (L p ∆), and a commutative square as at left below.
It suffices to find a filler for the outer rectangle at left above; and by adjunction, this is equivalent to finding a filler in the square at right above.But such a filler exists precisely because L p θ is anodyne.✷ Theorem 5.17 Proof.The sharp morphisms in Suppose given these and also Γ ∈ C r and which we will sometimes denote also by ⌜A⌝).Composing this with the lax naturality constraint of R, we get whose adjunct L r Γ → V (µ•ν † )⊡A we take as ⌜(µ•ν † )⊡A⌝.Finally, we define j µ•ν † Γ,A to make the diagram in Figure 7a commute.This uses the universal property of the front rectangle as a pullback.Since i µ•ν † V A ,E A is fixed along with the local universe, this definition of j is strictly stable.This completes Definition 3.4(i).Note that the left-hand square in back above is also a pullback (defining Γ ⊲ µ•ν † A), but the right-hand one is not: it is naturality of the lax constraint for R.However, since L r inverts this constraint, that square also becomes a pullback upon application of L r .Thus, L r (j , and suppose we have A ∈ Ty p ( C ̺•µ•ν † (Γ)).(Thus, the Γ in the preceding proof of part (i) is now C ̺ (Γ).)We first observe that in an adjoint modal pre-model, the construction of ℓ in Definition 3.4 is equivalent to the diagram in Figure 7b, in which the map k and the square ( * ) are defined by the diagram in Figure 7c.Then ( * ) is a pullback, so ℓ is a pullback of AdjTT [43] CoTT [43] Idempotent monad Totally connected topos no Parametric TT [32] Idempotent comonad Local topos (Example 6.10) • Johnstone's topos [18] • κ-condensed sets [35,3] • Cohesive topos [23,36] no no no yes Spatial TT [37], Crisp TT [25] Idem

Geometric realization no
Table 1 Instantiations of MATT and their semantics Theorem 6.5 Let L be a finite 2-category and E ∶ L coop → T opos a pseudofunctor.Then the codextrification E models extensional MATT over L[L † ], with positive and negative modalities representing inverse image and direct image functors respectively, and extensional MLTT at each mode.✷ Remark 6.6 Theorem 6.5 does not state explicitly how to extract conclusions about E from the interpretation of MATT in E .We will not try to make this precise here, but the idea is that E p can be viewed as a "presentation" of E p via the reflector L p ∶ E p → E p , and that the interpretation of MATT respects this "quotient".For instance, the anodyne context morphisms (Definition 5.14) in E p are precisely those that are inverted by L p ; thus MATT is "unable to distinguish" contexts that present the same object of E p .One way to make this more precise is using Quillen model categories.
We end by discussing some examples of simple classes of diagrams in T opos, to explore the flexibility and the limits of Theorems 6.3 and 6.5.As we will see, in some cases extra left adjoints already exist, so that co-dextrification is not necessary; but even in this case, some coherence results like those of section 5 are often still needed (see Remark 5.3).Table 1 summarizes some of the following examples, along with whether left adjoints already exist, and pointers to related theories in the literature.Example 6.7 If L consists of two objects p, q and one nonidentity morphism µ ∶ p → q, then a functor L coop → T opos is a single geometric morphism.The resulting instance of MATT has two modes related by an adjoint pair of modalities µ⊡ and µ .It is related to the split-context theory AdjTT of [43], and can be interpreted in any geometric morphism.
In particular, there is a unique geometric morphism from any topos E to Set.The resulting instance of MATT combines the usual internal language of E at one mode with the classical world of Set at another mode, with a "discrete objects" modality µ⊡ taking any set to an object of E , having a right adjoint "global sections" modality µ .This allows us to use the internal logic of E but also make "external" statements when needed, e.g. to study the cohomology of E , or "global" structures that do not lift to arbitrary slices.In the language of Lawvere [22], terms at mode q would be called "variable quantities", while those at at mode p would be "constant quantities".Since the functor Set → E does not in general have a left adjoint, such an interpretation for a general topos is impossible without co-dextrification.(When this functor does have a left adjoint, one says that E is locally connected.) The composite sending A to µ⊡(µ A) is then a comonad on one mode, while the one sending B to µ (µ⊡A) is a monad on the other.The 2-categories freely generated by a monad or a comonad are infinite, but if a monad or comonad decomposes through a geometric morphism in this way we can internalize it in MATT without needing infinite limits.Such a comonad decomposes if and only if it preserves finite limits; indeed the category of coalgebras for a finitely continuous comonad on a topos is again a topos.(If we also identify an object with its cofree coalgebra, so we only need one mode of syntactic types, we obtain something like the CoTT of [43].)The category of algebras for a finitely continuous monad on a topos need not be a topos; but if the topos is Boolean, then it can be induced by some geometric morphism [17].And for a general finitely continuous monad on a topos, the category of algebras is at least locally cartesian closed by [21] on slice categories, so Theorem 6.3 can still be applied.Example 6.8 Let L be the 2-category freely generated by an adjunction µ ⊣ ν.Then in L[L † ] we have µ † ∼ = ν by uniqueness of adjoints, so L[L † ] is generated (up to equivalence) by an adjoint triple µ ⊣ ν ⊣ ν † .Since L is countably infinite, we can interpret MATT over this L[L † ] in any adjoint triple of functors between toposes (or more general categories) whose left adjoint preserves countable limits (the right adjoints do automatically, of course).We would generally prefer to represent the adjoint triple with the modalities µ⊡ , µ , and ν , since µ has stronger rules than the equivalent ν⊡ .
Example 6.9 By contrast, the 2-category L freely generated by a strictly reflective adjunction (i.e. whose counit is an identity) is finite.It has two modes p and q, morphisms µ ∶ p → q and ν ∶ q → p such that µ•ν = 1 q , and a 2-cell η ∶ 1 p ⇒ ν •µ such that η⊲ν = 1 ν and µ⊳η = 1 µ .This determines all the composites, so no additional data are needed.A pseudofunctor L → Cat is a non-strictly reflective adjunction, whose counit is an isomorphism.Thus we can interpret MATT over this L in an arbitrary reflective adjunction between toposes, giving a modal type theory for a topos equipped with a subtopos.If the inclusion functor has a further right adjoint, we have a coreflective adjunction in T opos, and we can interpret MATT over L[L † ] with ν sinister.The induced geometric morphism from the larger topos to the smaller one is then called totally connected.For instance, the "topos of trees" used in guarded recursion theory (presheaves on (N, ≤)) is totally connected over Set; the modal type theories that it models are discussed in [12, §9] and [11,§VI].(In this topos, the left adjoint happens to already have a further left adjoint, so co-dextrification is not required to interpret modal type theory.)Example 6.10 Taking L to be the opposite of the one from Example 6.9, we can interpret MATT in an arbitrary coreflective adjunction between toposes.This is the same as a connected geometric morphism, such as that from sheaves on some connected space to Set.
If the right adjoint has a further right adjoint, so that we can interpret MATT over L[L † ], the geometric morphism is called local.This property rarely holds for the topos of sheaves on a space (a "little topos"), but it often does for toposes whose objects can be interpreted as some kind of space ("big toposes").Big toposes are a natural home for synthetic topology.One is Johnstone's topological topos [18], whose objects are a sort of sequential convergence space; the internal language of this topos is used for instance in [8].A related topos is κ-condensed sets [35], which has been advocated for the study of algebraic objects equipped with topology.(When κ is inaccessible, these are also called pyknotic sets [3].The category of all "condensed sets" is locally cartesian closed but not a topos.) Many local toposes are also cohesive, meaning that the leftmost adjoint of their adjoint triple has a further left adjoint.This left adjoint is not usually finitely continuous, so it cannot be represented internally as a judgmental modality with co-dextrification, although it can be introduced axiomatically as in [37,31].When it exists, co-dextrification is not needed to interpret the other modalities.But Johnstone's topological topos and κ-condensed sets are not cohesive, so co-dextrification is necessary in those cases.
Non-cohesive local toposes turn out to have many advantages.One clear advantage is that they can include non-locally-connected spaces, which arise naturally in many parts of mathematics.In addition, they often do a better job of faithfully encoding topological notions such as unions of closed sets, constructions of cell complexes (including geometric realization of simplicial sets), and cohomology.In [9] such a topos was used to represent the Kleene-Kreisel functionals and model principles of intutionism.Example 6.11We can simplify the mode theory of Example 6.10 by removing the mode corresponding to the base topos.Then L has one mode p and a single idempotent comonad µ ∶ p → p, and is again finite.Thus, MATT over this L can be interpreted in any topos that is connected over some base, with the base topos visible as the modal types for the comonad µ⊡ .This instantiation of MATT is similar to the split-context "crisp type theory" used in [25] to construct universes in cubical sets.
If the topos is additionally local, the comonad has a right adjoint monad, and we can interpret MATT over L[L † ].This is similar to the split-context "spatial type theory" of [37], which was conjectured to be interpretable in any local topos; we have thus established this for a related lock-based theory.Note that although examples like Johnstone's topological topos and pyknotic sets require co-dextrification, the intended model of [37] is cohesive and hence does not.Example 6.12 Applying the same simplification to Example 6.9, we obtain a 2-category L with one mode and an idempotent monad, for which L[L † ] can be interpreted in any topos that is totally connected over some base.This is related to the left-lifting theory of [32], which is interpreted in a topos of "bridge/path cubical sets" that is totally connected over ordinary cubical sets.(The left adjoint in this case also has a further pair of left adjoints.)Example 6.13 If L is a meet-semilattice, regarded as a monoidal poset and thereby a one-object 2category, we obtain an instance of MATT that is similar to the left-lifting theory of [31].In many of their examples each "focus" is cohesive, hence the further left adjoints needed for locks already exist.This includes the situation of "differential cohesion" studied in [14], as well as other related situations.But there are related examples in which not all foci are cohesive, such as simplicial objects in the topological topos, or simplicial pyknotic sets, and for these we require co-dextrification.Example 6.14 The left-lifting theory of [34] is similar to MATT over the 2-category generated by an idempotent endomorphism that is both a monad and a comonad and adjoint to itself.This means we can represent its modality negatively, and use it as its own lock functor in semantics, thereby interpreting this instance of MATT in any topos equipped with such an endofunctor.Unfortunately, the intended model of [34] is an (∞, 1)-topos without an evident 1-categorical analogue, so it is not covered by this paper.Example 6.15By [18, Theorem 8.1], there is a geometric morphism S ∶ E → sSet from Johnstone's topological topos E to the topos sSet of simplicial sets, whose direct image S * is the total singular complex (suitably generalized) and whose inverse image S * is geometric realization.Since both E and sSet are local over Set, this allows us to reason formally about geometric realization using an instance of MATT with three modes -say t for the topological topos, s for simplicial sets, and d for discrete sets -with sinister coreflective adjunctions relating d to both t and s, and a sinister morphism σ ∶ s → t for the geometric realization adjunction.As E is not cohesive (though sSet is), and geometric realization is not a right adjoint, this would be impossible without co-dextrification.Using [18,Theorem 8.2], we can do something similar for geometric realization of "simplicial spaces", i.e. simplicial objects of E .

Conclusion and future work
We have shown that, contrary to appearances, general modal type theories formulated with "context locks" following [12,11] can be interpreted in diagrams of categories without requiring additional left adjoints to interpret the locks.This significantly expands the potential semantics of such theories, strengthening the argument that they are a good general approach to modal dependent type theories.In addition, we have formulated MATT, a general context-lock modal type theory that unifies the positive modalities of [12] with the negative ones of [11], and shown that it is the natural type theory to interpret in our semantics.
We have, however, left many open questions for future research, such as the following.(i) Can the assumption of κ-small limits be weakened, specifically when κ > ω? (ii) It is known [39] that intensional dependent type theory can be interpreted in any (∞, 1)-topos.Can intensional MATT be interpreted in any diagram of (∞, 1)-topoi?(iii) Is there a full "internal language correspondence" relating MATT to suitable diagrams of categories?E.g. do adjoint modal natural models have a homotopy theory that presents diagrams of categories?(iv) Does MATT satisfy normalization, and which (L, S) are decidable?(See Remark 2.6.)(v) Is there a general modal dependent type theory using left multi-liftings, and can it be interpreted in the co-dextrification?Can it be generalized to cases where left multi-liftings do not exist?(vi) In [27], simple modal type theories were unified with substructural ones.Is there a context-lock approach to substructurality?Can it be unified with modal dependent type theory?

Example 2 . 3
Let L be any 2-category and S a class of morphisms in it, and let M = L[S † ] be the result of freely adjoining a right adjoint µ † for every morphism µ in S. We identify L with its image in L[S † ].
and write Γ ⊲ 1 A as Γ ⊲ A. Definition 3.2 Let M be an adjoint mode theory.A modal context structure D ∶ M coop → Cat is an adjoint modal natural model if we have a morphism τ p ∶ Tm p → Ty p in each PD p such that (D µ ) * τ p is representable for all tangible µ. (Since identities are tangible, each D p is still a natural model.)Definition 3.3 (See [12, §5.2.1])A Π-structure on an adjoint modal natural model D consists of, for any sharp µ ∶ p → q, and any Γ ∈ D q and A ∈ Ty p

Lemma 4 . 4
The categories C p are the action on objects of a modal context structure C ∶ L coop → Cat .
consists of θ µ satisfying (4.12), hence maps θ µ satisfying (4.10).✷ Corollary 4.13 We have a 2-functor C ∶ L[L † ] coop → Cat, with C µ † = C µ .In particular, considering only the right adjoints, we have a pseudofunctor C ∶ L → Cat .✷ We call this pseudofunctor C the co-dextrification of C .Lemma 4.14 The functors L r ∶ C r → C r are a pseudonatural transformation of pseudofunctors L → Cat.

Definition 5 . 1
Let L be a 2-category with a class S of morphisms.An adjoint modal pre-model is:(i) A modal context structure C ∶ L[L † ] coop → Cat, such that each C p is locally cartesian closed.As before, we write its action on morphisms as C µ , and we writeC µ = C µ † .(ii) A pseudofunctor C ∶ L[S † ] → Cat ,with action on morphisms C µ .(iii) A pseudonatural transformation L ∶ C → C between pseudofunctors L → Cat .To be covariant on L, we take the right adjoints in C but the left adjoints in C ; thus C µ (L p (Γ)) ∼ = L q ( C µ (Γ)).(iv) Each functor L p ∶ C p → C p preserves finite limits and has a fully faithful right adjoint R p .(v) Each category C p is a natural pseudo-model (C p , τ p ).

Definition 5 . 8 A
modal pre-model over an adjoint mode theory M is a pseudofunctor C ∶ M → Cat such that each C p is a natural pseudo-model.5.3 Π-structureDefinition 5.9 A morphism δ Γ → ∆ in a natural pseudo-model is type-exponentiable if for any B ∈ Ty(Γ), the pushforward of Γ ⊲ B along δ is isomorphic to a type projection ∆ ⊲ Π(f, B) → ∆.Definition 5.10 A modal pre-model C has pre-Π-structure if for any sharp µ ∶ p → q in M and any Γ ∈ C p and A ∈ Ty p (Γ), any pullback of C µ p A ∶ C µ (Γ ⊲ A) → C µ Γ is type-exponentiable.Lemma 5.11 Let L ∶ A ⇄ B ∶ R be an adjunction where L preserves pullbacks.Let f ∶ A → B be in A , g ∶ C → LA in B, and suppose that the pushforward (Lf ) * g ∶ (Lf ) * C → LB of g along Lf exists in B. Then the pullback of R((Lf ) * C) to B is a pushforward along f of the pullback of Rg to B. Proof.This is a fairly straightforward diagram chase.✷ Theorem 5.12 If ( C , C ) is an adjoint modal pre-model over (L, S) such that C has pre-Π-structure over L[S † ], then ( C , τ ! ) has Π-structure over L[S † ].
If ( C , C ) is an adjoint modal pre-model over (L, S) such that C has positive pre-modalities over L[S † ], then ( C , τ ! ) has positive modalities over L[S † ].

Fig. 7 .
Fig. 7. Positive modalities in an adjoint modal pre-model Tm f → Ty f and τ e ∶ Tm e → Ty e , and that τ f is a pullback of τ e .Let D ∶ M coop → Cat be constant at C , but where D f = C is equipped with τ f while D e = C is equipped with τ e .This is an adjoint modal natural model with negative modalities, since the assumption that τ f is a pullback of τ e says exactly that the identity functor (C , τ e ) → (C , τ f ) has a dependent right adjoint.
µ⊡A) ℓ p B Definition 3.5 (See [11, Definition 4]) An adjoint modal natural model D has negative modalities if for any sinister µ ∶ p → q, the functor D µ † has a dependent right adjoint [4], i.e. there is a pullback square (D µ † ) * Tm q Tm p (D µ † ) * Ty q Ty p .(D µ † ) * τq τp Example 3.6 Let M be the adjoint mode theory for Two-Level Type Theory from Example 2.5, and let C be a two-level model as in [1, Definition 2.8].If we ignore universes, this means it has two natural models τ f ∶ stably anodyne; hence L s (ℓ) is anodyne.Thus the fillers required by (ii) exist; we make them strictly stable as in [29, Lemmas 3.4.1.4and3.4.3.2].✷