Bicategorical type theory: semantics and syntax

We develop semantics and syntax for bicategorical type theory. Bicategorical type theory features contexts, types, terms, and directed reductions between terms. This type theory is naturally interpreted in a class of structured bicategories. We start by developing the semantics, in the form of comprehension bicategories. Examples of comprehension bicategories are plentiful; we study both specific examples as well as classes of examples constructed from other data. From the notion of comprehension bicategory, we extract the syntax of bicategorical type theory, that is, judgment forms and structural inference rules. We prove soundness of the rules by giving an interpretation in any comprehension bicategory. The semantic aspects of our work are fully checked in the Coq proof assistant, based on the UniMath library.


Introduction
In recent years, efforts have been made to develop directed type theory.Roughly, directed type theory should correspond to Martin-Löf type theory (MLTT) as ∞-categories correspond to ∞groupoids.Besides theoretical interest in directed type theory, it is hoped that such a type theory can serve as a framework for synthetic directed homotopy theory and synthetic ∞-category theory.Applications of those, in turn, include reasoning about concurrent processes (Fajstrup et al., 2016).
Several proposals for syntax for directed type theory have been given (reviewed in Section 2. 3.2), but are ad-hoc and are not always semantically justified.The semantic aspects of directed type theory are particularly underdeveloped; a general notion of model of a directed type theory is still lacking.Indeed these proposals often provide an interpretation of their syntax in categories.They either employ pre-existing 1-categorical semantical tools, thus forcing them to interpret their syntax into a 1-category of categories, as in the work by North (2019), or, in the absence of 2-categorical tools, give an ad-hoc interpretation of their syntax into the 2category of categories, as done by Licata and Harper (2011).We rectify this situation by providing a 2-categorical semantical structure.
Specifically, in this work we introduce comprehension bicategories as a suitable mathematical structure for higher-dimensional (directed) type theory.Approaching the development of directed type theory from the semantic side, we extract from this the core syntax-judgment forms and structural inference rules -of a two-dimensional dependent type theory that can accommodate directed type theory.We also give a soundness proof of our structural rules.In future work, we will equip our syntax and semantics with variances and type and term formers for directed type theory.
To motivate our approach, we analyze in Section 1.1 how higher-groupoidal structure arises in MLTT through an interplay of judgmental equality and typal identity.Our analysis thus leads to the desiderata listed in Section 1.2.In Section 1.3 we discuss the foundations we work in, and aspects of the computer formalization of some of our results.

Judgmental and Typal Higher Dimensions
The judgment forms of traditional MLTT specify types, contexts, terms, and judgmental equality (conversion) between types and terms.There is, prima facie, nothing higher-dimensional about these judgments, and an interpretation of types as sets and terms as elements of sets seems perfectly adequate.In this sense, Martin-Löf type theory is 1-dimensional.However, MLTT is often said to be ∞-dimensional.The higher dimensions are generated by the identity type, which internalizes the judgmental equality; specifically, the well-known reflexivity rule generates a typal identity from a judgmental equality.Since the identity type can be iterated, judgmental equality then also becomes available for terms of the identity type itself.This mutual interaction between judgmental equality and typal identity provides the infrastructure to "lift" judgmental equality to higher dimensions without extending the judgmental structure of MLTT.The tower of types ( , Id , Id Id , . . .) then can be given the structure of an ∞-groupoid, as shown by Van den Berg and Garner (2011) and Lumsdaine (2010).
When developing a directed type theory, with models in ∞-categories, the analogous ingredients are the following: I1: A judgment of directed reductions between types and terms, analogous to judgmental equality; I2: A type former for homomorphisms between terms, analogous to identity types; I3: A notion of model in which to interpret the judgments and type formers.
In the present work, we propose a judgmental framework (I1), and a suitable general notion of semantics (I3), for higher-dimensional and directed type theory.In a separate work we will expand this core by a system of variances suitable for accommodating a type former akin to North's hom-types (I2), to build a fully functional higher-dimensional type theory.

Deriving Syntax from Semantics
Previous work on higher-dimensional and directed type theory -reviewed in detail in Section 2 -has focused on syntax (I1/I2).Licata andHarper (2012, 2011) and Nuyts (2015) devise judgmental structure for higher-dimensional and directed type theory.North (2019) devises a type former for directed homomorphisms between terms, on top of the judgmental structure of MLTT.None of these works propose a general definition of model of directed type theory.Garner (2009) defines a notion of higher-dimensional model, but considers only undirected type theory.
Our approach is different from that of previous work on directed and higher-dimensional type theory.Specifically, we choose to approach the challenge from the other direction: we start by devising a suitable categorical structure for directed type theory, and extract a syntax from it.
We refine the ingredients above to the following list of desiderata for our work: D1: A system of inference rules for dependent types with directed reductions; D2: A definition of mathematical structures suitable for the mathematical modelling of the syntactic rules; D3: An interpretation of the inference rules in such a mathematical structure; D4: A syntax for type and term formers on top of D1; D5: A semantic structure for the interpretation of type and term formers.
In the present work, we achieve desiderata D1, D2, and D3.The study of variances and type and term constructors will be reported on elsewhere.In Section 2, we refer back to these desiderata for describing related work.
The semantics we propose are described in Section 5, and the extracted syntax is described in Section 8.Both our syntax and semantics are quite general; for instance, our reductions are proof-relevant -like those considered by Licata andHarper (2012, 2011), and unlike judgmental equality in MLTT, which is proof-irrelevant.Syntax and semantics could reasonably be simplified or specialized.Crucially, our work provides a framework to modify syntax and semantics in lockstep, with a clear mechanism to analyze changes to the syntax on the semantic side and vice versa.We suggest some possible variants in Section 10.

Foundations and Formalization in UniMath
The main results presented here are agnostic to foundations: they can be formalized in both set theory and type theory.
However, some of the notions we employ can economically be formulated using dependent types.In particular, we work with cloven (Grothendieck) fibrations of (bi)categories, whose formulation in set theory usually relies on postulating equality of objects.Using dependent types, a formulation of such concepts can be given that avoids any reasoning about equality of objects; instead, these concepts are formulated in terms of fibers.For this reason, we use type-theoretic language throughout the paper; see also, e. g., Remark 25.
We carefully distinguish data and property; in particular, we postulate entities in categories (e. g., limits) to be explicitly given as data rather than to merely exist.We do not rely on any choice axioms or on excluded middle.
The results of Sections 3 to 7 of this work are checked in Coq (Coq Development Team, 2022), based on the UniMath library (Voevodsky et al., 2022) of univalent mathematics.In univalent mathematics, we distinguish strict (bi)categories and univalent (bi)categories (Ahrens et al., 2021, Section 4).Our definitions are agnostic to this difference; hence, our definition of bicategory (Definition 1) does not make a commitment to either strictness or univalence.Specific examples can then be strict (such as Example 11) or univalent (such as Example 49); see also Remark 2.
Our code has been integrated into UniMath in commit 840ac16.The computer-checked definitions and results are accompanied by a link (e. g., bicat) to the corresponding definition in an HTML version of that commit.The code written specifically for this work comprises approximately 33,600 lines of code; specifically, the coqwc tool counts as follows: We build upon an existing library of (bi)category theory by Ahrens et al. (2015Ahrens et al. ( , 2021)), and use heavily the displayed machinery, developed for 1-categories by Ahrens and Lumsdaine (2019) and extended to bicategories by Ahrens et al. (2021).In particular, the formalized notions of cloven Grothendieck fibration we are using (in the 1-categorical case) and developing (in the bicategorical case) are based on displayed (bi)categories; we can thus discuss these notions without postulating equality of objects.
The syntax presented in Section 8 and its interpretation given in Section 9 are not computerchecked; we therefore give these constructions in more detail in the paper.

Synopsis
In Section 2 we review related work.In Section 3 we review (displayed) bicategories and functors.
In Section 4 we define cloven global and local (op/iso)fibrations of bicategories, and we use these notions to define comprehension bicategories.In Section 5 we discuss some examples of comprehension bicategories.In Section 6 we discuss Street (op)fibrations internal to bicategories, which form our main examples of comprehension bicategories.In Section 7 we define display map bicategories, and we show how any display map bicategory gives rise to a comprehension bicategory.
In Section 8 we present structural type-theoretic rules for the syntax of a two-dimensional type theory, which we call BTT.In Section 9 we give an interpretation of BTT in any comprehension bicategory.In Section 10 we discuss variations of BTT and the semantic structures these variations correspond to.In Section 11 we explain the difference between terms in BTT and terms in other approaches to directed type theory.

Version History
A shorter version of this paper was published in the proceedings of Logic in Computer Science under a different name (Ahrens et al., 2022).Compared to that shorter version, the following material has been added in the present version: • We provide more instantiations of Example 57.In particular, we show that several bicategories of structured categories have pullbacks (Example 19).• We give more detail on the specific comprehension bicategory given by functors into the 1category of strict categories, in Example 44.We also present a formalization of that example.• We introduce display map bicategories and show that any display map bicategory gives rise to a comprehension bicategory.• We present the type theory BTT in more detail, and specify more of its type-theoretic rules.
• We give more detail in the interpretation of the rules of BTT in any comprehension bicategory.
Furthermore, compared to the short version, we have added the definition of weak comprehension bicategory (see Definition 38 and Remark 40), where the comprehension is not required to preserve (op)cartesian cells.Our interpretation of BTT works in any such weak comprehension bicategory.

Related Work
In this section, we review work with a similar goal to ours, as well as work we rely on.We pay particular attention to the desiderata outlined in Section 1.2 and to the difference between judgmental and typal dimensions.

Non-dependent type theories
The following works satisfy a non-dependent variant of D1, together with suitable adaptations of D2 and D3.However, due to the absence of type dependency, they do not immediately compare to our work.Seely (1987) presents a syntax for a two-dimensional simply-typed lambda calculus, consisting of types, terms, and reductions between terms.Seely then constructs a 2-category out of that syntax.Tabareau (2011) frames aspect-oriented programming in a 2-categorical way, developing a lambda calculus that provides an internal language for 2-categories.Hirschowitz (2013) constructs a 2-adjunction between 2-signatures for lambda calculi (where such signatures specify types, terms, and reductions) and the category of Cartesian closed 2-categories.Fiore and Saville (2019) construct an internal language for cartesian closed bicategories; the result is a class (parametrized by a notion of signature for constants) of simple 2-dimensional type theories or lambda calculi.This last work shares one aspect with ours that the others do not: it uses (weak) bicategorical structure, rather than (strict) 2-categorical structure.

Theories for Higher Categories
There is a body of work on designing type theories for -groupoids and -categories.In these type theories, one works, semantically speaking, within one fixed ∞-groupoid (or -category).Compare this to, e. g., Martin-Löf type theory, where one manipulates ∞-groupoids (types and identity types) and ∞-functors (functions) between them.Analogously, in our type theory, each type can be thought of as a category.Despite these different goals, we mention some of the work in this area.
Brunerie (2016) constructs a type theory whose models are weak ∞-groupoids.Benjamin et al. (2021) (see also the work by Finster and Mimram (2017)) design a type theory whose models are precisely -categories à la Grothendieck-Maltsiniotis. Finster et al. (2022) study meta-theoretic properties of a language for strictly unital ∞-categories.There are also computer tools implementing such type theories, see, e. g., the work by Bar et al. (2018) and Reutter and Vicary (2019).

Theories with Dependent Types
In this section we review work on higher-dimensional and directed type theory with dependent types.We start with a review of work on undirected type theory.

Undirected Type Theory
The idea of considering higher-dimensional interpretations of type theory stems from Hofmann and Streicher's groupoid interpretation of Martin-Löf type theory by Hofmann and Streicher (1994).This interpretation is generalized to stacks (poset-indexed groupoids satisfying a sheaf condition) in order to prove the independence of several logical principles by Coquand et al. (2017).It is furthermore generalized, from different angles, to higher dimensions, see, e. g., work by Van den Berg and Garner (2011), Lumsdaine (2010), and Kapulkin and Lumsdaine (2021).All of this work considers the Martin-Löf identity type, which is undirected.Licata and Harper (2012) develop a two-dimensional dependent type theory with a judgment for equivalences Γ ⊢ : ≃ between terms , : .These equivalences are postulated to have (strict) inverses.The authors give an interpretation of types as groupoids: terms are (interpreted as) objects in the interpreting groupoid, and equivalences are morphisms, necessarily invertible.No general notion of semantic structure is discussed; this work hence satisfies an undirected version of D1, but not D2.Coraglia and Di Liberti (2021) introduce judgmental theories and calculi for them as a general framework to present and study deductive systems.They instantiate their framework to obtain a type theory that describes an internal language of 2-toposes (Coraglia and Di Liberti, 2021, Section 5.3); however, they only consider a one-dimensional type theory à la Martin-Löf, and thus their work does not satisfy D1. Garner (2009) studies a typal two-dimensional type theory à la Martin-Löf: the forms of judgment are the same as in Martin-Löf type theory.Garner calls a type "discrete" if it satisfies identity reflection (that is, if any identity : = between elements , : induces a judgmental equality ≡ .Rules are then added that turn any identity type into a discrete type, effectively making every type into a 1-type, in the sense of the h-levels of homotopy type theory.Garner defines a notion of two-dimensional model based on (strict) comprehension 2-categories.Exploiting the restriction to 1-truncated types, a sound and complete interpretation of that two-dimensional type theory in any model is then given.The Martin-Löf identity type is undirected; correspondingly, Garner defines their comprehension 2-categories to consist of locally groupoidal 2-categories.Thus, Garner's work satisfies D1 for undirected reductions, using the identity type for this purpose.Garner also considers type constructors such as dependent pair types and dependent product types, thus satisfying D4 and D5 in this case.a

Directed Type Theory
Licata and Harper (2011) (see also (Licata, 2011, Chapter 7)) also design a directed twodimensional type theory and give an interpretation for it in the strict 2-category of categories.Their syntax has a judgment for substitutions between contexts, written Γ ⊢ : Δ, and transformations between parallel substitutions.An important aspect of their work is variance of contexts/types, built into the judgments.The type formers there have a certain variancecovariance or contravariance -in each of the arguments.They do not define a general notion of model for their theory; this work hence satisfies D1, but not D2.
Nuyts (Nuyts, 2015, Section 1.3.1)observes that the type theory developed by Licata and Harper (2011) does not allow for a non-trivial Martin-Löf identity type -any such type would coincide with the directed transformations.Nuyts thus attempts to generalize the treatment of variance by Licata and Harper, and designs a directed type theory with additional variances, such as isovariance and invariance.Nuyts does not provide any interpretation of their syntax, and thus no proof of (relative) consistency; the work hence does not satisfy D2.
North (2019) develops a type former for directed types of morphisms, resulting in a typal higher-dimensional directed type theory based on the judgments of MLTT.North's work thus does not satisfy D1.The model given by North is in the 2-category of categories, similar to the model by Licata and Harper (2011).Shulman (2012), in unfinished work, aims to develop 2-categorical logic, including a twodimensional notion of topos and a suitable internal language for such toposes.Specifically, Shulman sketches two internal languages for 2-toposes.The first language (Shulman, 2011) is undirected, consisting only of types and terms.The second language (Shulman, 2010) is only described in a short sketch; it is a kind of directed type theory featuring, in particular, variances.Our work is similar to Shulman's in the sense that both start from a (bi)categorical notion and extract a language from it, with the goal of developing a precise correspondence between extensions of the syntax and additional structure on the semantics.Unfortunately, Shulman's work is unfinished, which makes a more complete evaluation difficult.However, it contains several ideas that have influenced the present work.For instance, Shulman (2019) emphasizes the usefulness of restricting to (op)fibrations instead of considering all 1-cells when constructing bicategories of arrows -we do this in our main examples of comprehension bicategory, Examples 45 and 57.
Riehl and Shulman (2017) design a simplicial type theory (STT) featuring a directed interval type, as a synthetic theory of (∞, 1)-categories.As a notion of model, they introduce "comprehension categories with shapes" (Riehl and Shulman, 2017, Def. A.5).These are (1-categorical) towers of fibrations accounting for several layers of contexts.Further work on STT was done, among others, by Weaver and Licata (2020) and Buchholtz and Weinberger (2021).STT is not higher-dimensional in the sense of Licata and Harper (2011) or the present work; in particular, a Garner also relies on Hermida's (Hermida, 1999) slightly incomplete definition of fibration of 2-categories; see Buckley's work (Buckley, 2014, Remark 2. 1.9) for details.We have not checked if Garner's work extends to Buckley's corrected definition of 2-fibration.
reductions, both in the tope layer and in the type layer, are undirected.This work thus does not satisfy D1.
Summary In the present work, we define bicategorical semantics for the interpretation of types, terms, and reductions, and derive from it a system of inference rules; our work thus satisfies D1, D2, and D3.We do not handle D4 and D5 in this work.
Among the described related work, our work is closest to work by Licata andHarper (2011) andGarner (2009).Compared to Licata and Harper (2011), we add a general definition of "model" of a directed two-dimensional type theory, and provide many examples of models.Compared to Garner (2009), we cover directed reductions, and provide many instances of our general definition of model.Compared to both works, we do not handle type and term formers.

Preliminaries
Here, we sketch some definitions used later on.Many would be very long if given in full; instead, we try to convey some intuition while pointing to the formalized definitions.As a reference for bicategory theory, see Bénabou (1967).We use here the vocabulary and notation introduced by Ahrens et al. (2021).
Remark 2. We do not generally require that our bicategories (and displayed bicategories, see Definition 4) are univalent in the sense of Ahrens et al. (2021).
Sometimes it is still interesting to assume that a given (displayed) bicategory is univalent; in such cases, fibrations are better behaved, since lifts can be shown to be actually unique rather than just essentially unique (see, for instance, Proposition 26).Whenever we state such a result, the assumption on the (displayed) bicategory to be univalent is stated explicitly.
We denote by Cat the bicategory of categories, and by Grpd the bicategory of groupoids.The bicategory B op has the same objects as B, but 1-cells from to in B op are 1-cells : → in B. The 2-cells in B op are 2-cells in B. The bicategory B co has the same objects and 1-cells as B, but 2-cells from to in B co are the same as 2-cells from to in B.
We build complicated bicategories from simpler ones by adding structure at all dimensions.The additional structure should come with its own composition and identity, which should lie suitably over composition and identity of the original bicategory.This idea is formalized in the notion of displayed bicategory -a layer of data over a base bicategory -and the resulting total bicategory -the bicategory of pairs ( , ) of a cell in the base and a cell "over" .We also obtain a pseudofunctor from the total bicategory into the base, given at all dimensions by the first projection.
Definition 4 ( (Ahrens et al., 2021, Def. 6.1), disp_bicat).Let B be a bicategory.A displayed bicategory D over B consists of ( 1) for any : B 0 , a type D of objects over ; (2) for any : → and : D and : D , a type − → of 1-cells over ; (3) for any : ⇒ and : − → and : − → , a set = ⇒ of 2-cells over ; together with suitably typed composition (over composition in B) and identity (over identity in B) for both 1-and 2-cells.These operations are subject to "axioms over axioms in B".Definition 6 (disp_subbicat).Suppose that we have a bicategory B, a predicate 0 on the 0-cells (by which we mean a proposition 0 ( ) for every 0-cell ), and a predicate 1 on the 1cells.Furthermore, we assume that 1 is closed under identity and composition; that is, 1 (id( )) holds for every satisfying 0 and that for all : → and : → between 0-cells satisfying 0 we have 1 ( • ) if we have both 1 ( ) and 1 ( ).Then we define a displayed bicategory SubBicat( 0 , 1 ) on B such that • the type of displayed objects over is 0 ( ); • the type of displayed 1-cells over : → is 1 ( ); and • the type of displayed 2-cells over : ⇒ is the unit type.
The total bicategory of this bicategory selects 0-cells and 1-cells from the original bicategory B. Its objects are objects : B such that 0 ( ), its 1-cells are 1-cells : → in B such that 1 ( ), and its 2-cells are the same as 2-cells : ⇒ in B. The projection pseudofunctor : SubBicat( 0 , 1 ) → B is the inclusion.
Remark 7. Note that Definition 6 is defined slightly differently in the formalization.In disp_subbicat, we do not require that 0 and 1 are propositions.Instead, we only require b Note that → is used for both 1-cells and function types.
this in the theorem is_univalent_2_subbicat that shows the univalence of this displayed bicategory.
We instantiate Definition 6 to define bicategories of categories with a certain structure.
Example 8 (StructuredCategories.v).We define the following displayed bicategories over Cat: • D Terminal where 0 (C) says that C has a terminal object and 1 ( ) says that preserves terminal objects.We denote its total bicategory by Cat Terminal .• D BinProd where 0 (C) says that C has binary products and 1 ( ) says that preserves binary products.We denote its total bicategory by Cat BinProd .• D Pullback where 0 (C) says that C has pullbacks and 1 ( ) says that preserves pullbacks.
We denote its total bicategory by Cat Pullback .• D FinLim where 0 (C) says that C has finite limits and 1 ( ) says that preserves finite limits.We denote its total bicategory by Cat FinLim .• D Initial where 0 (C) says that C has an initial object and 1 ( ) says that preserves initial objects.We denote its total bicategory by Cat Initial .• D BinSum where 0 (C) says that C has binary coproducts and 1 ( ) says that preserves binary coproducts.We denote its total bicategory by Cat BinSum .
The above examples can be defined using Definition 6 assuming that the categories involved are univalent, since then the type families 0 and 1 stating a choice of limits are indeed predicates.
For non-univalent categories, one could consider instead the truncated predicates stating mere existence of limits.The total bicategories of the displayed bicategories in Example 8 are bicategories of categories with certain (co)limits.In addition, we can combine the structure of these by taking the product of the suitable displayed bicategories.Note that we could use similar methods to construct bicategories of extensive categories, regular categories, exact categories, and (pre)toposes.
The following (displayed) bicategories are used: Example 9 (trivial_displayed_bicat). Given bicategories B 1 and B 2 , we define a displayed bicategory B 1 +B 2 over B 1 as follows: • The displayed 0-cells over : The total bicategory is Example 10 (cod_disp_bicat).Let B be a bicategory.Define a displayed bicategory B ↓ over B as follows: • The displayed objects over : B are 1-cells → .
In the next example, we write StrictCat for the bicategory of strict categories and StrictCat for the category of strict categories.
• The displayed 1-cells over : The associated projection pseudofunctor : Example 12 (disp_bicat_of_opcleaving).We define a displayed bicategory OpCleav over Cat as follows: • The displayed objects over C : Cat are displayed categories D over together with an opcleaving.
• The displayed 2-cells over : ⇒ from : D 1 − → D 2 to : D 1 − → D 2 are displayed natural transformations from to over .
The associated projection pseudofunctor : ∫ OpCleav → Cat maps any opcleaving to its codomain category.
The idea of displayed (bi)categories transfers to functors: • for all displayed morphisms : − → , a displayed 1-cell • coherence isomorphisms for identity and composition of displayed 1-cells, over the analogous isomorphisms in the base; • satisfying suitable equations over the corresponding equations in the base.

We denote by
Remark 14.The square of pseudofunctors induced by over commutes up to judgmental equality.
Furthermore, we need pullbacks and products in bicategories.
In Definition 15 it is irrelevant if we postulate data to be given explicitly or to merely exist, provided the bicategory B is univalent: Remark 17.There are different notions of pullback in bicategories depending on whether • and • are postulated to be related up to an equality, invertible 2-cell or even just a 2-cell.In Definition 15, the square commutes up to invertible 2-cell.One could also define strict pullbacks: this is done similarly to Definition 15, but all involved squares must commute up to equality rather than just up to invertible 2-cell.
The bicategory Cat also has pullbacks, and they are given by iso-comma categories.These are defined as follows: given categories C 1 , C 2 , and C 3 , and functors : C 1 → C 3 and : C 2 → C 3 , we define the iso-comma category / ≃ • Its objects consist of objects : C 1 and : C 2 together with an isomorphism : ( ) → ( ) • The morphisms from ( 1 , 1 , 1 ) to ( 2 , 2 , 2 ) consists of morphisms : 1 → 2 and ℎ : 1 → 2 such that the following diagram commutes: The category / ≃ together with the functors ≃ 1 , ≃ 2 and natural isomorphism ≃ is universal among such data, making it the pullback of and .
Example 19 (LimitsStructuredCategories.v).The bicategories defined in Example 8 all have pullbacks as well.This is because taking the iso-comma category preserves the desired (co)limits and the projections and pairing functors preserve them.
As a special case of pullbacks in the presence of terminal objects, we can define products in bicategories (has_binprod_ump).If B has chosen products, we write × for the product of and , and we denote the projections by 1 : × → and 2 : × → .
Notation 20.In the following, given a cloven fibration, we notate the pullback (or reindexing) of along by * .Given a cloven opfibration, we notate the pushforward of along by ! .

Comprehension Bicategories
In this section, we define the notion of global cleaving and local (op)cleavings of bicategories.Afterwards, we use these notions to define comprehension bicategories.We are guided by Buckley (2014), where local and global fibrations are defined, and we add definitions for local cloven isoand opfibrations.However, there is an important difference: while Buckley works in a set-theoretic setting, we reformulate the definitions in a type-theoretic setting using the displayed technology developed by Ahrens et al. (2021) and reviewed in Section 3 -see also Remark 25.
Throughout this section, we assume that B is a bicategory and D is a displayed bicategory over B.
Definition 21 ( (Buckley, 2014, Def. 3.1.1),cartesian_1cell).Let : → be a 1-cell in B, and let : − → be a displayed 1-cell over in D. A cartesian structure on consists of the following data.Note that we draw diagrams in the displayed category on the left side and diagrams in the base category on the right side.
Proposition 26 (isaprop_cartesian_1cell). Suppose that D is a univalent displayed bicategory over B, and let be a displayed 1-cell  Next we look at local cleavings and opcleavings.A 2-cell is opcartesian if and only if it is opcartesian in the 1-categorical sense for the hom-functor.However, in the formalization we give the following direct definition not relying on hom-categories, and prove the characterization via hom-categories afterwards (opcartesian_2cell_weq_opcartesian).Similarly, we give an unfolded definition of local opcleaving.
Being an opcartesian 2-cell is always a property.The notion of cartesian 2-cells is analogous.
Definition 30 (local_opcleaving).A local opcleaving on D is given by, for every : ⇒ Example 36 (FunctorsIntoCatCleaving.v).The displayed bicategory IndexedCat has a global cleaving and a local opcleaving.To construct these, we first observe that a displayed 1cell and only if it is a natural isomorphism.Now we construct a global cleaving for IndexedCat as follows: whenever we have functors : C 1 → C 2 and : C 2 → StrictCat, then we also get a functor Every displayed 2-cell in IndexedCat is opcartesian.To find local opcartesian lifts, suppose that we have functors 1 , 2 : C 1 → C 2 , 1 : C 1 → StrictCat and 2 : C 2 → StrictCat, and natural transformations : 1 ⇒ 2 and : 1 ⇒ 1 • 2 .Our goal is to construct a natural transformation 1 ⇒ 2 • 2 , and for the desired transformation we take • ( ⊲ 2 ).Hence, IndexedCat has a local opcleaving.
Example 37 (OpFibrationCleaving.v).The displayed bicategory OpCleav has a global cleaving and a local opcleaving.Given a functor : C 1 → C 2 and a displayed category D 2 over C 2 , we construct a displayed category * (D 2 ) over C 1 : • The displayed objects over : C 1 are displayed objects in D 2 over ( ).
• The displayed morphisms over : → from to are displayed morphisms over Note that * (D 2 ) inherits any opcleaving from D 2 .In addition, we have a displayed functor over from * (D 2 ) to D 2 that preserves cartesian morphisms.
Opcartesian 2-cells in OpCleav correspond to displayed natural transformations of which all components are opcartesian.We form local lifts pointwise.Since displayed 1-cells in OpCleav preserve cartesian morphisms, cartesian 2-cells are preserved under both left and right whiskering.
Similarly, we can show that the displayed bicategory Cleav has a global and a local cleaving (FibrationCleaving.v).We finish this section by defining comprehension bicategories.Examples of those are given in Section 5.

Definition 38 (comprehension_bicat).
A weak comprehension bicategory is given by a bicategory B, a displayed bicategory D over B, and a displayed pseudofunctor over the identity on B as pictured below, satisfying the following properties (see also Proposition 33): (1) D is equipped with a cloven global fibration; (2) D has a cloven local opfibration; (3) opcartesian 2-cells of D are preserved under both left and right whiskering.
Remark 39.Recall from Remarks 14, 28, and 32 that the displayed pseudofunctor : D → B ↓ of Definition 38 gives rise to a strictly commuting diagram of pseudofunctors with the structure of a global fibration and local opfibration in the sense of Buckley (2014).
Remark 40.In the definition of comprehension categories, one usually requires that the functor preserves cartesian morphisms.The analogous requirement for comprehension bicategories is that the pseudofunctor preserves both cartesian 1-cells and opcartesian 2-cells -this is condition 4 in Definition 38.
We have factored out this requirement, since for our interpretation of the language BTT (introduced in Section 8), we do not need this condition; that is, we can interpret BTT in any weak comprehension bicategory.The reason has to do with how we interpret terms of the language BTT in a (weak) comprehension bicategory.Traditionally, in a comprehension category, terms of MLTT are interpreted as sections of projections.Specifically, every type in context Γ gives rise, in the interpretation, to a morphism : Γ. → Γ in the arrow category.A term of type in context Γ in MLTT is then interpreted as a section of .
In our setting, terms of BTT will be interpreted differently.Instead of interpreting BTT terms as sections of projections, we interpret them as morphisms over the identity.More concretely, in a bicategory D displayed over B, a term in context Γ of type with source of BTT is interpreted as a morphism from to over the identity of Γ.
In the 1-categorical case, these two ways of interpreting terms are equivalent in many examples.The reason is that, in practice, most comprehension categories are full, which means that is fully faithful, and that every fiber has a terminal object.From these two assumptions, one can conclude that these two ways of interpreting terms are actually equivalent.However, in the bicategorical setting, these two ways are often not equivalent: for example, in the comprehension bicategory of displayed categories with opcleavings, i.e. opfibrations (Examples 12, 37, and 45).There, morphisms over the identity are required to preserve opcartesian morphisms, but such a requirement is not present for sections of the projection.If one were to include MLTT style terms (which are interpreted as sections of projections) in BTT, then to give an interpretation one would also need that preserves cartesian 1-cells and opcartesian 2-cells in order to interpret substitution.This is why we present here both definitions.
In short, all the examples presented in Section 5 are comprehension bicategories; the interpretation of BTT given in Section 8 only requires a weak comprehension bicategory.
Remark 41.Contravariant and isovariant comprehension bicategories are defined analogously with the notions of (iso)cleaving and (iso)cartesian taking the place of opcleaving and opcartesian in Items 2 and 3 of Definition 38.Some of our examples of comprehension bicategories can similarly be equipped with a contravariant and isovariant comprehension structure.

Examples of Comprehension Bicategories
In this section, we give several (classes of) instances of comprehension bicategories.In some of these instances, we recognize structures studied previously in the context of higher-dimensional and directed type theory.
Example 42 (trivial_comprehension_bicat).Suppose we have a bicategory B with products.Then we have the following comprehension bicategory

B
The displayed pseudofunctor : B +B → B ↓ sends the object 2 over 1 to the product projection Example 42 corresponds roughly to the semantics studied by Fiore and Saville ( 2019), but without the type formers.
Another example of a comprehension bicategory comes from locally groupoidal bicategories, such as Grpd.
Example 43 (locally_grpd_comprehension_bicat).Let B be a locally groupoidal bicategory with pullbacks.Then we get the following comprehension bicategory Since every 2-cell is opcartesian in B ↓ if B is locally groupoidal, the displayed bicategory B ↓ has a local opcleaving.
Example 43 models undirected reductions between terms.It is thus related to the groupoid model of type theory by Hofmann and Streicher (1994) and to the definition of comprehension 2category by Garner (2009).A more detailed comparison to Garner's comprehension 2-categories is given in Remark 65.
We can also consider directed versions of this example by using categories instead of groupoids.

StrictCat
To define , we use the Grothendieck construction.Specifically, from a functor : C → StrictCat we construct a category ∫ as follows (1) The objects of ∫ are pairs ( , ) where : C and : ( ).
Note that we also have a projection 1 : Example 44 is related to the interpretations given by Licata and Harper (2011) and North (2019) in their works on directed type theories, albeit without considering type formers.However, their notion of term, in both the syntax and the interpretation, is different from ours; see Section 10 for details.
In Example 44, contexts are categories and types over a context C are cloven split opfibrations on C. We also consider a version of this interpretation where there are more types: instead of looking at only those opfibrations that are split, all opfibrations are considered.

Cat
The pseudofunctor sends a displayed category D over C to the functor 1 : Similarly, we can define a contravariant comprehension bicategory (cleaving_contravariant_comprehension_bicat) using cleavings instead of opcleavings.

Internal Street (Op)Fibrations
In this section, we discuss Street (op)fibrations internal to a fixed bicategory B. Note that B ↓ comes equipped with a cloven global fibration if B has pullbacks.However, to obtain a local (op)cleaving, we used that B is locally groupoidal in Example 35.This assumption is avoided in Example 37 where B = Cat: instead of looking at arbitrary functors, one only considers the opfibrations.We can generalize this idea to arbitrary bicategories by using internal Street (op)fibrations (Buckley, 2014).
The displayed bicategory OpCleav has a local opcleaving where the desired lifts are constructed pointwise.To generalize this to arbitrary bicategories, we need to adjust this definition so that we can lift arbitrary 2-cells.Furthermore, the notion of cloven Grothendieck opfibration of categories is stricter than appropriate for bicategories.If we have → and an object over , then a cloven Grothendieck fibration gives an object strictly living over , while a Street fibration only gives an object living weakly over (i.In Cat, internal Street fibrations are the same as Street fibrations of categories.However, the notion of internal Street fibrations can be applied in a wider variety of settings: for example, one could also look at internal Street fibrations in the bicategories from Example 8 or in presheaves or stacks valued in Cat.A classical result on internal Street (op)fibrations is that they are closed under taking pullbacks, see Gray (1966) and Street (1980).

Display Map Bicategories
In this section, we introduce "display map bicategories" as a convenient way to build comprehension bicategories.
Let B be a bicategory with pullbacks.We aim to construct a displayed bicategory SOpFib(B) of Street opfibrations over B with both a global cleaving and a local opcleaving.The construction should be done in a modular and general way, since using the same techniques we aim to construct a displayed bicategory SFib(B) of Street fibrations over B with a global and local cleaving.One can imagine more examples, such as the intersection of Street opfibrations with discrete or fully faithful 1-cells.
The common pattern among all these examples is that the displayed bicategory actually represents a subbicategory of the arrow bicategory of B. In the 1-categorical case, such examples are captured by display map categories (Taylor, 1999).We adapt that notion to the bicategorical setting.
However, there is a difference between the 1-categorical and the bicategorical case.A display map category on a 1-category C is a full subcategory of the arrow category on C satisfying some requirements.Such a notion would not be useful in the bicategorical case, since neither SOpFib(B) nor SFib(B) are full subbicategories of B ↓ .Indeed, the 1-cells in SOpFib(B) and SFib(B) are required to preserve (op)cartesian cells, which is not required in B ↓ .As such, to obtain a notion of display map bicategory that captures these two examples, some care is needed in the definition of display map bicategories.
For that reason, our notion of display map bicategory comes in three different flavors.c  Definition 48 (disp_map_bicat).Let B be a bicategory.A display map bicategory on B consists of ( 1) a predicate on the 1-cells of B, and (2) a choice of pullbacks along 1-cells satisfying such that (3) if a morphism satisfies , then it is an internal Street opfibration, and ( 4) is closed under pullback.
Given a display map bicategory B, a display map of B is a 1-cell of B together with a proof of the predicate .
We also define notions of contravariant display map bicategory and isovariant display map bicategory: for the former, condition (3) above is replaced by the condition that the display maps are required to be internal Street fibrations, while for the latter, condition (3) is omitted.The reason for this terminology is that every display map bicategory of a given variance gives rise to a comprehension bicategory with the same variance.
Example 49 (sopfib_disp_map_bicat_is_covariant).Let B be a locally univalent bicategory with pullbacks.Since B has pullbacks, pullbacks exist along all 1-cells, and in particular, along Street opfibrations.In addition, Street opfibrations are closed under pullbacks by Proposition 47. Hence we have a display map bicategory in which the predicate says that a 1-cell is an internal Street opfibration.
Remark 50.Note that in Example 49, we assume B to be locally univalent.This is to guarantee that the notion of being a Street opfibration is actually a proposition as required in Definition 48.However, we expect that this assumption can be dropped by suitably truncating the notion of Street opfibration.Example 52 (discrete_sopfib_disp_map_bicat_is_covariant).Let B be a bicategory with pullbacks.Since both faithful and conservative 1-cells are closed under pullbacks, discrete 1-cells are as well.Hence, we get a display map bicategory of discrete Street opfibrations.d In the formalization, we actually use unfolded versions of these definitions, and we prove these two versions are equivalent.

Analogously, one can define a contravariant display map bicategory of
Every display map bicategory gives rise to a displayed bicategory as follows.
Definition 53 (disp_map_bicat_to_disp_bicat).Let B be a bicategory and let D be a display map bicategory on B. We define a displayed bicategory D over B as follows: • The objects over : are pairs : B and : → such that is a display map; • The 1-cells over : 1 → 2 from 1 : 1 → 1 to 2 : 2 → 2 are pairs of a 1-cell : 1 → 2 and an invertible 2-cell • 2 ⇒ 1 • such that preserves opcartesian 2-cells; • The 2-cells are as in Example 10.
Similarly, every contravariant display map bicategory gives rise to a displayed bicategory.However, the 1-cells are required to preserve cartesian 2-cells.For isovariant display map bicategories, we do not make any restriction on the 1-cells.This way, we obtain displayed bicategories SOpFib(B) and SFib(B) over a bicategory B with pullbacks.In SOpFib(B), 2-cells are the same as 2-cells in B → .However, 1-cells are a bit different: while 1-cells in B → are squares Using Example 54, we can generalize the example of (op)fibrations to arbitrary display map bicategories.We discuss the interest in this generalization in Remark 59.
Problem 55.Given a display map bicategory D on a bicategory B, to define a comprehension bicategory.
Construction 56 (for Problem 55; disp_map_bicat_comprehension_bicat).From bicategory B and a display map bicategory D on B, we construct the comprehension bicategory Similarly, we get a contravariant comprehension bicategory from a contravariant display map bicategory, and an isovariant comprehension bicategory from an isovariant display map bicategory.We can instantiate Example 56 to internal Street opfibrations to get the following comprehension bicategory.
Example 58.By Example 57 any bicategory with pullbacks, thus in particular any bicategory of stacks (Street, 1982), gives rise to a comprehension bicategory.
Remark 59. Recall from Section 2.3.1 that Coquand et al. (2017) constructed models of MLTT in stacks valued in groupoids.Using those models, they proved the independence of countable choice in univalent foundations.
With our comprehension bicategories of stacks (not just ones valued in groupoids), one could follow Coquand et al. (2017) and study the validity and independence of logical principles in directed type theory.
Note that we can specialize Example 57 to each of the examples given in Example 8.This is because we showed in Example 19 that those bicategories have pullbacks.In the case of Cat Terminal , we get a comprehension bicategory in which • the "contexts" are categories with a terminal object; and • the "types" are cloven opfibrations of categories which preserve terminal objects.
Similarly, we can instantiate this to the other categories mentioned in Example 8.

The Type Theory BTT
In this section, we extract a core syntax for two-dimensional type theory from our semantic model.We call the resulting type theory Bicategorical Type Theory (BTT).In Section 9, we prove soundness of our syntax by giving an interpretation of the syntax in any weak comprehension bicategory.
The syntax extracted here is maximally general, in the sense that it reflects the structure of a general comprehension bicategory.In Section 10, we propose several orthogonal simplifications to the syntax, along with the corresponding semantic structure and properties.As such, our syntax and semantics are to be viewed as a framework to study different semantic structures and their corresponding internal languages, rather than as one particular pair of syntax and semantics.
In Section 8.1 we present the judgment forms of BTT, as well as the rules extracted from the bicategories of contexts and of types, respectively.In Sections 8.2 and 8.3 we present the comprehension and substitution rules, respectively.
For reasons of space we omit here several rules, namely the naturality rules in Figures 8 and 9, and the coherencies of trifunctors.Such rules, written out in the "linear" syntax used here, would take up several lines and would be difficult to understand.Consequently, the syntax presented here is not complete.The presentation of the complete syntax and a suitable completeness theorem is left for future work.

Judgments and Basic Rules
BTT features contexts, substitutions, types, generalized terms, and reductions between terms.As befits the bicategorical semantics, judgmental equality is only postulated between parallel reductions.
We often abbreviate the above judgments and write, e. g., just : ′ instead of Γ | ⊢ : ′ : .For these judgments, we have rules that express the bicategorical structure of contexts and types.Rules are given in Figure 1 for the bicategory of contexts, and in Figure 2 for the bicategory of types.
We also introduce symbols which read like judgments but stand for several judgments, using the composition and identities introduced in Figures 1 and 2.
We also require that ℓ and form an adjoint equivalence.This can be specified by formulating the usual triangle equalities as equality judgments.(4) Γ | ∼ ⊢ : stands for the following four judgments.
• Γ | ⊢ : Rules for the bicategory of contexts Remark 61.By abuse of notation, we write several topically related rules that share all the same hypotheses as one rule with several conclusions.These rules then also share the same name, e. g., extend-con-Ty.When referring to a rule by name, it will be clear from the context which of the possible rules we refer to.The names of inference rules in the text are hyperlinks to the corresponding rules (e. g., map).The equality ≡ is assumed to be a congruence for every other constructor and judgment.For brevity, we have not recorded here the resulting rules.When parentheses are omitted, everything is associated to the left: that is, stands for (( ) ).Note also that in several rules in which it is necessary to re-associate several four or more terms or substitutions, we have written instead of a long composition of whiskered associators •,•,• in the interest of readability.

Comprehension Structure
Comprehension, that is, context extension, is extracted from the pseudofunctor .The rules for comprehension are given in Figure 3.There are some notable differences to comprehension in MLTT.First, the rule extend-con-Tm, which forms a substitution, comes together with a reduction that expresses the commutativity of a triangle.Second, we also have a rule extend-con-Red that extends a substitution with a reduction.Since reductions are proof-relevant, this rule comes with a coherency on the commutativity.

Substitution Structure
Substitution is given, in the semantics, by the global and local (op)cleaving structure.We reflect this into the syntax as explicit substitution, as was also used, e. g., by Fiore and Saville (2019); Licata and Harper (2012) in their respective settings.
The rules for substitution are given in Figures 4, 5, 6, 7, 8, and 9.We distinguish them based on whether we need the global cleaving or the local opcleaving to interpret them.There are several important observations to be made about these rules.First, in line with our truly bicategorical approach, we do not assume the comprehension bicategory is split.In particular, no equality between [id] and is postulated.Instead, there is an equivalence between them (see sub-id and sub-comp), and terms of these types are transported along the equivalence.

Figure 3. Rules for comprehension
Remark 62.For contravariant comprehension bicategories (Remark 41), the rule map would be in the opposite direction, while for isovariant comprehension bicategories, this rule would be restricted to isomorphisms in the base.
Remark 63.Using the Grothendieck construction, we can view the rules from the perspective of fiber bicategories.If : E → B has a global cleaving and a local opcleaving, and furthermore opcartesian 2-cells are preserved under whiskering, then we obtain a trifunctor B op → Bicat, which sends every : B to the fiber of along .The rules given in Figure 4 say that any 1-cell in the base gives rise to a pseudofunctor.For example, the rules sub-ty, sub-tm, and sub--red represent the actions on objects, 1-cells, and 2-cells, respectively, while sub-pres-id and sub-pres-comp represent the invertible 2-cells that witness the preservation of the identity and composition of 1-cells.The other rules in that table are the coherence laws of pseudofunctors: for example, sub-red-pres-id is the preservation of identity 2-cells.
Figures 5 and 6 give pseudonatural equivalences expressing that the assignment of the previously mentioned pseudofunctor is actually pseudofunctorial: the identity and composition are preserved up to pseudonatural equivalence.For example, the rules sub-id and tm-sub-id in Figure 5 represent the action on objects and the naturality squares.On the other hand, sub--red-id, sub-id-pres-id, and sub-id-pres-comp are the usual coherencies of pseudonatural transformations.
The rules of Figure 7 state that we obtain a pseudonatural transformation from a 2-cell in the base.The action on objects and 1-cells is given by map and rew-tm, respectively, while rew-red, rew-pres-id, and rew-pres-comp describe the usual coherencies of pseudonatural transformations.The remaining rules can be found in Figure 8.In this figure, four invertible modifications are described: map-id and map-comp describe the preservation of identity and composition,  respectively, while map-lwhisker and map-rwhisker describe the preservation of both left and right whiskering.Note that we left out the naturality conditions of these modifications.In addition, two additional coherencies are required which express that all this data together forms a trifunctor.We do not write them down, but instead, we refer the reader to Definition 3. 3.1 of Gurski (2006).
Remark 64.A similar rule to map of Figure 7 appears in work of Johnstone (1993).There, it is shown that a 1-cell in a 2-category is an internal fibration in a sense similar to our Definition 46 if and only if a specific functor given by precomposition with has a semi-oplax right adjoint satisfying some properties, assuming that pullbacks along exist.In Lemma 2.5 of Johnstone (1993), another equivalent characterization of being a fibration is given assuming that pullbacks Figure 6.Rules for global substitution (preservation of composition) The naturality rules for map-comp, map-lwhisker, and map-rwhisker have been omitted. of exist.This characterization uses several operations and compatibility requirements.One of The naturality rules for sub-comp-map-id-r, sub-comp-map-id-l, and sub-comp-map-assoc have been omitted.We assume that pullbacks along are given; in particular, we have * and * .The characterization of being a fibration entails, in particular, that for every 2-cell : ⇒ there is a 1-cell ˆ ( ) : * → * .This takes place in a 2-category, though Johnstone claims that such a characterization would also hold in a bicategory.Modulo this difference, this operation is expressed by rule map of Figure 7.

Soundness: Interpretation in Comprehension Bicategories
In this section, we give an interpretation of BTT in any weak comprehension bicategory.To this end, we fix a comprehension bicategory D B ↓ over B. We interpret the judgments as follows.
Regarding the "bicategorical" rules of Figures 1 and 2, each rule is analogous to one of the operations or laws of a bicategory -see, for instance, Definition 3.1 of Ahrens et al. (2021).This also indicates how it is interpreted.

Comprehension
In this section, we interpret the rules related to comprehension of Figure 3. Suppose that we have a context Γ : B and a type over Γ.Its image ( ) in B ↓ gives rise to an object Γ. : B and a 1-cell Γ. : Γ. → Γ which interprets extend-con-Ty.For a 1-cell from to over the identity, the resulting 1-cell ( ) is part of a triangle Γ. Γ.
Γ ( ) which commutes up to invertible 2-cell.This yields the interpretation of the rules in extendcon-Tm.Furthermore, a reduction : ′ is mapped by to a 2-cell from ( ) to ( ′ ) in B ↓ , and this is how we interpret extend-con-Red.The rules extend-con-id and extend-concomp are interpreted by the identitor and compositor of , respectively, while the remaining rules in Figure 3 are satisfied because they translate to the laws that express that this data forms a pseudofunctor.

Global Substitution
Next, we interpret the rules for global substitution of Figure 4 (in Sections 9. 2.1, 9.2.2, 9.2.3, and 9.2.4), and the rules regarding preservation of identity under global substitution of Figure 5 (in Sections 9. 2.6, 9.2.5, and 9.2.7).The interpretation of the rules regarding preservation of composition of Figure 6 is analogous to that of Figure 5 and is not spelled out.
The interpretation of the rule sub-ty is given directly by the global cleaving.The interpretation of the other rules require more explanation.

Interpretation of sub-tm
To interpret sub-tm, we assume that we have a substitution : Δ → Γ between contexts Δ and Γ.
We also assume that we have types , over Γ and a morphism : → over 1 Γ .This situation is encapsulated in the following diagram, using the notation introduced in Definition 27.Overall, we can summarize the construction with the following diagram. [

Interpretation of sub-red
To interpret sub-red, we assume that we have a substitution : Δ → Γ and types and in context Γ.We also assume that we have 1-cells , ′ : → over 1 Γ and a 2-cell : ⇒ ′ .Consider the following diagram. [ Our goal is to construct a 2-cell from [ ] to [ ′ ] over the identity on Δ.The source and target, respectively, were constructed by factoring a 1-cell via a cartesian 1-cell, as follows. [ we use Item 2 of Definition 21.More specifically, it suffices to construct • a 2-cell from 1 Δ to 1 Δ , and • a 2-cell from to ′ .
For the first of the two, we take the identity 2-cell 1 1 Δ .For the second, we take the composition of 2-cells shown in the following diagram.

′
The interpretation of the rules sub-red-id and sub-red-comp follows from the uniqueness of factorization 2-cells.

Interpretation of sub-pres-id
The rules sub-pres-id and sub-pres-comp are interpreted similarly, and we show the interpretation of sub-pres-id.Suppose that we have a substitution : Δ → Γ and a type in context Γ.We consider two morphisms: the identity on [ ] and 1 [ ].These are illustrated in the following diagram. [ To do so, we first recall the construction of To construct the desired invertible 2-cell, we again use Item 2 of Definition 21.As such, we need to construct the following: With those in place, we define Sub I ( ) −1 := E( , ).For , we take the identity, while for , we take the following composition.

.4 Interpretation of sub-pres-lunitor
The remaining laws stating equalities of 2-cells, such as sub-pres-comp and sub-id-pres-id, are all proven in a similar way.Our goal is to prove an equality = with 1-cells and 2-cells as in the diagram below: Here and ′ live over and ′ , respectively, while and live over and , respectively.To prove the equality, we take the following steps.

Interpretation of sub-comp
To interpret sub-comp, we suppose that we have substitutions ′ : Θ → Δ and : Δ → Γ, and a type in Γ. Hence we have the following diagram.

Interpretation of tm-sub-id
Next we interpret tm-sub-id, and for that, we suppose that we have a context Γ, types and over Γ, and a 1-cell : → over 1 Γ .We need to construct an invertible 2-cell from sub −1 id • [1 Γ ] • sub id to , and for that, it suffices to construct an invertible 2-cell from [1 Γ ] • sub id to sub id • .Recall that we defined sub id to be 1 Γ ( ), and recall that we defined [1 Γ ] as follows.
[ ] 1 Γ ( ) By composing the two invertible 2-cells depicted in this diagram, we get the desired invertible 2-cell.The rule tm-sub-comp is interpreted analogously.

Local Substitution
Next we interpret the rules in Figure 7 (in Sections 9. 3.1 and 9.3.2), Figure 8 (in Sections 9. 3.3 and 9.3.4),and Figure 9 (in Section 9.3.5).For the interpretation, we use the local opcleaving.
To construct , we first note that by construction of [ ′ ], we have the following invertible 2-cell.

Interpretation of map-id
To interpret map-id, we assume that we have a 1-cell : Δ → Γ and a type in context Γ.Our goal is to construct an invertible 2-cell between the following compositions.
The desired 2-cell is then defined to be E( , ).For we take 1 1 Δ .
To construct , we first note that by construction of map , the following triangle commutes up to an invertible 2-cell : map • ′ ( ) ( ( )).
[ ] Next we recall that ( ( )) was constructed as the following pushforward.
We interpret map-comp similarly.

Interpretation of map-lwhisker
To interpret map-lwhisker and map-rwhisker, we use the same idea, and we need to use that we assumed that opcartesian 2-cells are closed under whiskering.We give the precise details for map-lwhisker.Suppose we have a 1-cell : Θ → Δ, a 2-cell : ′ ⇒ ′′ where ′ , ′′ : Δ → Γ, and a type in context Γ.Our goal is to construct an invertible 2-cell from map ( ⊳ ) to sub −1 comp ( , ′ ) • (map ) [ ] • sub comp ( , ′′ ).Since map was constructed as a cartesian factorization, it suffices to construct: (1) An invertible 2-cell from 1 Δ to 1 Δ • 1 Δ • 1 Δ ; and However, note that most of our comprehension bicategories are not full.Furthermore, this syntactic modification would still leave a difference between the interpretations of terms given by Licata and Harper, and North, on the one hand, and our interpretation on the other hand.Specifically, in Example 45, terms are interpreted as functors that preserve opcartesian cells; by the Grothendieck construction, terms can equivalently be interpreted as pseudonatural transformations.In contrast, terms are interpreted as lax natural transformations by others (North, 2019;Licata and Harper, 2011).Hence, there is a mismatch between how terms are interpreted in comprehension bicategories compared to other interpretations.
We can analyze this mismatch more closely, and suggest a potential way of reconciling it, by looking again at the intended interpretation of two-dimensional and directed type theory in categories via the opcleaving model.Taking this mismatch seriously leads us in the direction of directed type theory, where there can be different flavors of terms.For example, in work by Nuyts (2015) terms can be used isovariantly, covariantly, and contravariantly.In the opcleaving model (Example 45), these different notions of terms would correspond to different kinds of natural transformations: pseudonatural transformations, lax natural transformations, and oplax natural transformations.
To reconcile this difference, one would need to modify the syntax and the definition of comprehension bicategory.In the syntax, one would need to add a term judgment for every kind of term present in directed type theory.Accordingly, one would also add the corresponding operations like substitution.The notion of comprehension bicategory would also require slight modifications for this purpose; one necessary requirement would be that preserves both cartesian 1-cells and opcartesian 2-cells.The reason for this change, is that this would be necessary to interpret substitution of a certain class of terms.More precisely, in the opfibration model, lax transformations can be identified with sections of the projections ∫ D → C. To interpret substitution for these, we need that certain squares in the arrow bicategory are pullbacks; to guarantee that, one requires that preserves cartesian 1-cells.
It is an open problem to develop categorical semantics for type theories that feature terms with different variances.

Conclusion
We have introduced the notion of comprehension bicategory, inspired by the notion of comprehension category.From this semantic notion, we have extracted a two-dimensional core syntax for dependent types, terms, and reductions, and an interpretation of that syntax in comprehension bicategories.In future work, we hope to accompany this soundness result with a completeness result.
Our work is very general.We hope that it gives future investigations into two-dimensional and directed type theories a firm foundation.For instance, as outlined in Section 1.1, in future work we will extend our structural rules with variances and a suitable hom-type former à la North (2019).

Acknowledgements
We gratefully acknowledge the work by the Coq development team in providing the Coq proof assistant and surrounding infrastructure, as well as their support in keeping UniMath compatible with Coq.We are very grateful to Dan Licata and Bob Harper for their help in understanding their interpretation and how it relates to our framework.We thank the anonymous referees of the short version, and of the present long version, as well as editor Richard Garner, for their insightful comments and helpful advice.This work was partially funded by EPSRC under agreement number EP/T000252/1.This material is based upon work supported by the Air Force Office of Scientific Research under award number FA9550-21-1-0334.This research was supported by the NWO

Definition 5 (
(Ahrens et al., 2021, Def.6.2), total_bicat).Given a displayed bicategory D over B, we define the total bicategory ∫ D to have, as cells at dimension , pairs ( , ) where is a cell of B at dimension and is a cell of D over , with the obvious source and target.We define the projection pseudofunctor : ∫ D → B to be given, on any cell, by ( , ) ↦ → .

Problem 23 .
Given two cartesian 1-cells : → and ′ : ′ → , to construct an adjoint equivalence : → ′ over the identity and an invertible 2-cell from to • ′ .Construction 24 (for Problem 23; EquivalenceBetweenCartesian.v).The 1-cells of the adjoint equivalence are constructed as cartesian factorizations (first item of Definition 21).In that way, we also obtain the desired invertible 2-cell.Remark 25.Recall that a displayed 1-cell : − → in D gives rise to the 1-cell ( , ) in the total bicategory ∫ D. The definition of cartesian structure on in D of Definition 21 gives rise to a notion of cartesian structure for ( , ) in ∫ D. By expressing the definition of cartesian 1-cell in the displayed bicategory (instead of in the resulting projection : ∫ D → B), we can postulate that a lift in ∫ D lies definitionally over a given cell in B, not just modulo an invertible 2-cell.
in D over in B. Then the type of cartesian 1-cell structures on is a proposition.Definition 27 (global_cleaving).A global cleaving on D is a choice, for any : → in B and : D , of (1) a displayed object over ; (2) a displayed 1-cell : − → ; (3) a cartesian structure on .Given a global cleaving on D, we use the notation [ ] := and ( ) := to denote the choice given by the cleaving.Remark 28.The notion of global cleaving as in Definition 27 gives rise to a notion of cloven fibration on the total bicategory ∫ D.
Definition 29 (is_opcartesian_2cell).Suppose we have 1-cells , : → , a 2-cell : ⇒ , and displayed objects and over and , respectively.Given displayed 1-cells : − → and : − → and a displayed 2-cell : = ⇒ , we say that is 2-opcartesian (or just opcartesian) if for all 1-cells ℎ : → , displayed 1-cells ℎ : ℎ − → , 2-cells : ⇒ ℎ, and displayed 2-cells and : − → , a displayed 1-cell : − → and an opcartesian 2-cell : = ⇒ .The notions of local cleaving and local isocleaving are defined analogously.Remark 31.Every displayed bicategory on a univalent bicategory has a local isocleaving.The construction is the same as for categories (Ahrens and Lumsdaine, 2019, Construction 5.12).Remark 32.The notions of opcartesian 2-cell and of local opcleaving as in Definition 30 give rise to notions of opcartesian 2-cell and of cloven local opfibration on the total bicategory ∫ D. Note that one can construct a local isocleaving from either a local cleaving or a local opcleaving.Proposition 33 (CleavingOfBicatIsAProp.v).Suppose that B is a univalent bicategory and D is a univalent displayed bicategory over D. Then the types of local (resp.global) (op)cleavings on D are propositions.Now let us look at some examples of these notions.Example 34 (TrivialCleaving.v).The trivial displayed bicategory B 1 +B 2 over B 1 comes equipped with a cloven global fibration.Cartesian 1-cells in B 1 +B 2 correspond to adjoint equivalences in B 2 .As such, we can take the identity 1-cell as the global lift.In addition, B 1 +B 2 also has both a cloven local fibration and a cloven local opfibration.Example 35 (CodomainCleaving.v).Suppose that B is a locally groupoidal bicategory with pullbacks.Since cartesian 1-cells in B ↓ correspond to pullback squares, we can construct a global cleaving for B ↓ by taking pullbacks.Note that all 2-cells in B ↓ are cartesian, because B is locally groupoidal, and thus B ↓ also has a local cleaving and a local opcleaving.

A 1 -
e., up to an isomorphism).More information can be found in work byLoregian and Riehl (Loregian and Riehl, 2020, Example 4.1.2).Definition 46 (internal_sfib).Let : → be a 1-cell in a bicategory B. Then is an internal Street fibration if • For every : B, the functor * : B( , ) → B( , ) of hom-categories is a Street fibration.•For every : → , the following square is a morphism of Street fibrations: cell is called an internal Street opfibration if it is an internal Street fibration in B co (internal_ sopfib ).
Street fibrations.There are other examples of display map bicategories as well, for instance discrete Street opfibrations.To define those, we first need the notion of discrete morphisms.d Definition 51.A 1-cell : → in a bicategory B is called • (faithful_ 1cell ) faithful if for every object , the functor * : B( , ) → B( , ) given by postcomposition with is faithful; • (conservative_ 1cell ) conservative if for every object , the functor * : B( , ) → B( , ) is conservative; • (discrete_ 1cell ) discrete if for every object , the functor * : B( , ) → B( , ) is faithful and conservative.
to invertible 2-cell, 1-cells in SOpFib(B) have the additional requirement that whiskering with preserves opcartesian 2-cells.Similarly, we can define the bicategory SFib(B) where the objects are internal Street fibrations and where the 1-cells preserve cartesian 2-cells.Now we can construct the desired cleavings.Example 54 (DisplayMapBicatCleaving.v).Let B be a bicategory and let D be a display map bicategory.As in Example 35, cartesian 1-cells are the same as pullback squares.Hence, we can construct a global cleaving for D using pullbacks and Proposition 47.To construct a local opcleaving for D, we use that it is contained in SOpFib(B), and then we can use the same construction as for SFib(B) (Buckley, 2014, Example 3.4.6).Similarly, given a contravariant display map bicategory, one obtains both a global and a local cleaving.However, from an isovariant display map bicategory, one only gets a global cleaving and a local isocleaving.One can instantiate Example 54 to internal Street opfibrations to obtain a global cleaving and a local opcleaving for SOpFib(B) if B has pullbacks.

Figure 2 .
Figure 2. Rules for the the bicategory of types

Figure 4 .
Figure 4. Rules for global substitution

Figure 5 .
Figure 5. Rules for global substitution (preservation of identity)

Figure 8 .
Figure 8.Some rules for local substitution (preservation)
They will yield, in Section 7, many examples of comprehension bicategories, see Example 57 and Remark 59.The examples of Street opfibrations internal to bicategories of stacks are particularly interesting (see Remark 59).