Dependently-Typed Montague Semantics in the Proof Assistant Agda-flat

We apply the Agda-ﬂat proof assistant (Vez-zosi, 2019) to computational semantics. Computational semantics in Agda-ﬂat is distinguished from the approach based on Coq (Chatzikyriakidis and Luo, 2014) in that it allows an implementation of the classical, intensional semantic analyses of Montague (1973). That is, it synthesizes the modern dependent type theory and Montague intensional logic traditions in the computational semantics setting. To demonstrate this, we show how to replicate Montague’s analyses in the type theory of Zwanziger (2018), which closely corresponds to the Agda-ﬂat system. Accompanying code type-checks these analyses in Agda-ﬂat.


Introduction
Proof assistants, e.g. Coq (Chatzikyriakidis and Luo, 2014), have been applied in computational semantics to support natural language inference. By translating (declarative) sentences of a natural language into the language of a proof assistant, the problem of whether one natural language sentence implies another is reduced to finding a proof of implication in that proof assistant. Ideally, both the translation and the proof search are automated.
While proof assistants like Coq and the similar system Agda are adequate for implementing most semantic analyses given in the modern dependent type theory tradition (Ranta, 1994), they do not provide an obvious implementation of the classical intensional semantic analyses of Montague (1973). The criterion that a computational semantics system be general enough to capture Montague's analyses has been termed the "Montague Test" (Morrill and Valentín, 2016).
The present work introduces computational semantics in the Agda-flat proof assistant. Agda-flat (Vezzosi, 2019) is a variation on ordinary Agda implementing a so-called comonadic modal dependent type theory. Agda-flat was created by Andrea Vezzosi (c. 2017Vezzosi (c. -2019 as a tool for verifying mathematical theorems in type-theoretical foundations. The logic behind the most recent mode of Agda-flat is essentially similar to CHoTT, which was isolated by Zwanziger (2018) as a natural dependently-typed, optionally hyperintensional analog of Montague's simply-typed intensional logic. As such, Agda-flat passes (the relevant incarnation of) the Montague Test. Furthermore, CHoTT can be used as a readable notation for Agda-flat.
Below, we develop enough of natural language semantics in CHoTT and Agda-flat to pass the Montague Test. In Section 2, we review the type theory CHoTT of Zwanziger (2018), which closely corresponds to the Agda-flat system, and is seen to provide a dependently-typed version of Montague intensional logic. In Section 3, the Montague Test sentences are translated into CHoTT. In Section 4, we discuss the Agda-flat system, and in particular the straightforward rendering of CHoTT sentences therein. Pursuant to the translations given in Section 3, an auxiliary repository is provided type-checking the translations of all Montague Test sentences.

Comonadic Homotopy Type Theory
We review the type theory CHoTT of Zwanziger (2018), which provides a dependently-typed version of the intensional logic IL of Montague (1973). To motivate CHoTT, a preview of the correspondence between CHoTT and IL is given in Subsection 2.1. Furthermore, some context for the development of CHoTT is provided in Subsection 2.2. The technical discussion of CHoTT is in Subsection 2.3.

IL CHoTT
English Gloss t Prop "type of truth values/propositions" xs, ay 5A "type of intensions of terms of type a/A" pα t 5 "the intension of term α/t" qα t 5 "the extension of term α/t" φ φ "necessarily φ"

Cheat Sheet for CHoTT
As any extension of intensional logic should, the type theory CHoTT will include analogs of the intension, extension, and other operators of IL. These are foreshadowed in Table 1. The variant notation from IL follows Shulman (2018), and reflects the essentially independent origins of IL and Shulman's system. Pursuant to the correspondence of Table 1, the translations of the Montague Test sentences given in Section 3 will bear an obvious similarity to those of Montague. There will be a few technical points of divergence between CHoTT and IL, though, discussed in the course of Subsection 2.3. Though these particularities of CHoTT can be justified on technical grounds, it is also worthwhile to understand CHoTT and its relation to IL in the context of the literature.

Provenance of CHoTT
We here review some historical context and justification for CHoTT. A reader less concerned by such matters can skip ahead to Subsection 2.3 for the technical development.
The type theory CHoTT is a "comonadic homotopy type theory", combining a version of Montague's intensional logic ("comonadic type theory") with homotopy type theory (HoTT), a version of dependent type theory. We visit each of these aspects in turn.

Intensional Logic and Comonadic Type Theory
The identification of Montague intensional logic with comonadic type theory dates to joint work of the author (Awodey et al., 2015), and is developed in the M.S. thesis of the author (Zwanziger, 2017), in both syntactic and semantic aspects. Comonadic type theory is a variety of modal type theory which was first treated systematically in the 1990's, with approaches due to Bierman and de Paiva (2000) and Davies and Pfenning (Pfen-ning and Davies, 2001). Montague's intensional logic can thus be understood retrospectively as the original comonadic type theory. However, Montague's syntax lacks β-conversion (AKA λconversion) and the usual rules for quantifiers, an issue addressable within these modern approaches (Zwanziger, 2017). The present paper follows the Davies and Pfenning approach, and and in particular Shulman (2018)'s extension to homotopy type theory.

Homotopy Type Theory
HoTT (Univalent Foundations Program, 2013) is a proposed type-theoretic alternative to axiomatic set theory as a foundation for math. HoTT incorporates dependent type theory, a framework which has been fruitfully applied in natural language semantics since Sundholm (1989) and Ranta (1994).
Recently, dependent type theory has been called "modern type theory" in the context of natural language semantics, to distinguish it from the simplytyped intensional logic of Montague (Chatzikyriakidis and Luo, 2018). Particularly appealing applications of dependent type theory in natural languages semantics, dating to the early work, include the use of the baked-in bounded quantification to model the bounded quantification of natural language (part of the "common nouns-as-types" viewpoint) (Luo, 2012), and a natural approach to dynamic semantics. As for the "homotopy" part, it is argued in Zwanziger (2018) that this provides a natural approach to hyperintensional natural language semantics. As a homotopy type theory, CHoTT includes two notions of equality: definitional equality, written ", and thought of as (hyper)intensional equality, and typal equality, written ", and thought of as an a posteriori equality. In line with this intuition, " is stronger than ". In CHoTT, we find 'intensional' operators which respect only ", not ". Furthermore, this more "granular" intensional equality need not conflate statements with Table 2: The Extensional (´e) and Intensional (´i) Context Rules the same truth conditions. A hyperintensional semantics of CHoTT, inspired by the homotopytheoretic semantics of HoTT, is the subject of other research by the author (Zwanziger, 2019).
In summary, CHoTT and the closely related Agda-flat, while building directly on a separate tradition than intensional logic, do incorporate intensional logic, together with additional features. Furthermore, these extra features have various uses for the natural language semanticist, rather than being peculiarities inflicted on them by the Agda-flat system. That said, since our intention is to make a beeline for formalizing the Montague Test sentences, these modeling advantages will not be pursued below, with the exception of common nouns-as-types.

The System CHoTT
We now turn to delineating the system CHoTT, with a focus on the similarities and differences with IL.
Officially, CHoTT is the fragment of Shulman (2018) consisting of the usual notions of homotopy type theory, together with the comonadic type operator 5, which we think of as an intension type operator performing the role of Montague's xs,´y. In less condensed terms, we have the following: In the tradition of Pfenning and Davies (2001) and Shulman (2018), CHoTT has two variable judgements, u : t5u A and x : A We will say (at variance with prior terminology) that "u is an intensional variable of type A," when u : t5u A and that "x is an extensional variable of type A," when x : A.
Remark 1 Intuitively, having an assumption u : t5u A of an intensional variable of type A is akin to having an assumption x : 5A of an extensional variable of the type of intensions of terms of type A. Indeed, such assumptions will turn out to be interchangeable.
The hypothetical judgements of CHoTT have the form where ∆ represents a list of intensional typed variables, and Γ a list of extensional typed variables. This ∆ | Γ is called the context, and we will have, as usual, that a type appearing in the context may depend only on typed variables to its left. So types in Γ can depend on variables in ∆, but not vice versa.
Due to the two variable judgements, there is a duplication of the rules for context extension and variables, with variants for extensional and intensional variables. These are given in Table 2. In view of Remark 1, the rule Var. i is understood as the principle that an assumption of an intension of a term of type A yields a term of type A. This rule is, naturally, implicated in the derivation of the Montague extension operator, below.
We import the usual homotopy-type-theoretical notions (Univalent Foundations Program, 2013), including ś -and ř -types (analogs of the quantifiers @ and D), type universes and universe polymorphism, "-types, higher inductive types (HITs), and univalence. However, as a simplifying assumption, the typing rules are assumed to manipulate extensional variables only. For instance, the formation rule for ś is  in which x : A is required to be extensional.
Finally, we have a comonad 5 corresponding to Montague's xs,´y, the rules for which appear as Table 3.
Note that the 5-Form. and 5-Intro. (intension operator) rules only apply "in an intensional context", that is, when no extensional variables are present in the context. 1 Thus, in a well-typed term, any intensional operator (5p´q or p´q 5 ) that appears must have been adduced during a phase of the derivation with an intensional context. 2 Since variables within the scope of an intensional operator must receive de re interpretation (Zwanziger, 2017), and only intensional variables occur within the scope of an intensional operator, intensional variables can be motivated as a technical device for keeping track of which locations within a term receive de re interpretation.
The 5-Elim. rule provides a way of substituting a term of type 5A for an intensional variable of type A via an explicit let-notation. This principle is in keeping with Remark 1. Furthermore, it gives a benign way of "substituting into an intensional 1 While IL does not place any similar restriction on the intension operator p p´q, Montague does stipulate a constantdomain Kripke semantics for IL. The analogous Kripke-Montague semantics for CHoTT need not stipulate constant domains. But a type 5A of intensions will, naturally, have a constant domain interpretation regardless. Remark 1 relates extensional variables of type 5A with intensional variables of type A.
2 In the current terminology, then, an intensional context is not, as traditionally, defined by the presence of an intensional operator, but rather a more primitive notion that is prerequisite for the presence of an intensional operator.
context". To illustrate, such a substitution let u 5 :" s in tpu 5 q 5 , in which s receives de re interpretation, does not in general 5-β-reduce to the de dicto form tpsq 5 , and thus avoids the usual pitfall of substitution into intensional contexts. As a corollary, β-conversion (for function types) clearly gives pλx.let u 5 :" x in tpu 5 q 5 qpsq " let u 5 :" s in tpu 5 q 5 , not pλx.let u 5 :" x in tpu 5 q 5 qpsq " tpsq 5 , explaining why β-conversion is benign in CHoTT.
Though 5-Elim. is subtle, the reader may take heart that we can use it to derive an 'extension' operator corresponding to Montague's qp´q, which, again following Shulman (2018), we call p´q 5 . That is, the rule ∆ | Γ $ t : 5B 5-Elim.-Simple ∆ | Γ $ t 5 : B is derivable (Figure 1). As foreshadowed above, this derivation also makes crucial use of the rule Var. i . Furthermore, we have the conversion pt 5 q 5 " t, familiar from Montague. That is, the principle ∆ |¨$ t : B 5-β-Conv.-Simp. ∆ | Γ $ pt 5 q 5 " t : B is derivable, obtained with pt 5 q 5 " let u 5 :" t 5 in u pDef'n. of p´q 5 q " t p5-β-Conv.q as calculation.
It is with all the comonadic rules in concert that Remark 1 is ultimately justified. The reader may confirm, for instance, that the principles

Natural Language Semantics in CHoTT
We now set about rendering the Montague Test sentences in CHoTT.
To illustrate the issues involved, let's examine what will be the translations of the sentence, "John believes that a fish walks." This sentence is traditionally held to have two construals, a de dicto and a de re. These construals are to be represented by believepj, pDpx : f ishq.walkpipxqqq 5 q and Dpx : f ishq.let u 5 :" ipxq in believepj, walkpu 5 q 5 q , respectively. These formulas exhibit several less familiar features which bear discussion, including defined (non-primitive) notation for logic inside HoTT (D), common nouns-as-types (x : f ish) and associated type coercions (i), and the handling of de re with (let-substitutions for) intensional variables.
In Subsection 3.1, we explicate any prerequisite defined notation and associated theory. In Subsection 3.2, we give the CHoTT renderings of the Montague Test sentences.

Defined Notations
We now develop several notions for eventual use in Subsection 3.2. Unless otherwise specified, the definitions of the present subsection are adapted from Chapter 3 of the HoTT Book (Univalent Foundations Program, 2013).

Predicate Logic
Central to the approach of the current section is the use of the type Prop of "propositions" in lieu of Montague's type t of "truth values". Within HoTT, propositions are identified with those types that have at most one term (up to the equality "). Intuitively, such types encode no more (extensional) information than whether they have a term ("are inhabited") or not. In such case, truth is identified with inhabitation. Formally speaking, we have the following definitions: Definition 2 For any type A : U , let isProppAq :" ś x,y:A x " y. When isProppAq is inhabited, we say that A is a proposition, and when such A is inhabited, we say A is true.

Definition 3 Prop :"
ř A:U isProppAq Whereas a sequent of form ∆ | Γ, x : A $ B : U is thought of as a type depending on A, a sequent of form ∆ | Γ, x : A $ P : Prop may be thought of as a predicate on A, rather than a "proposition depending on A". This notion of predicate gives rise to a notion of predicate logic inside type theory with the following constructs: Here, ´ denotes "propositional truncation", as defined in Chapter 3 of the HoTT Book (Univalent Foundations Program, 2013), which quotients any type to a proposition.
To the logic of the HoTT Book, we do add one definition: Definition 5 Let ∆, u : t5u A |¨$ P : Prop.  tendency to conflate truth with inhabitation. In Kripke-Montague semantics, intensions for (the interpretation of) a type A only exist when (the domain interpreting) A at each world is non-empty. So 5A at a world is non-empty (i.e. true) when A is nonempty (i.e. true) at every world. 3

Subtypes and Coercions
We will have reason to view common nouns as types (for the purposes of type-bounded quantification). Yet predicates like "talks" are apt to apply to women, men, donkeys (perhaps), etc. Consequently, "talks" is better interpreted as a predicate on a type of entities subsuming women, men, and donkeys. To accommodate both impulses, we require a notion of subtype and type coercion, which will allow us to write logical forms like, e.g., @px : manq.talkpipxqq for "Every man talks." This motivates our use of the subtypes of HoTT, defined as follows: Definition 6 Let ∆ | Γ, x : A $ P : Prop. Then tx : A | P pxqu :" ř x:A P pxq. Furthermore let i :" π 1 : ř x:A P pxq Ñ A. This tx : A | P pxqu is said to be the subtype of A satisfying property P , and i the inclusion or coercion of tx : A | P pxqu into A.
For readability, we will furthermore coin the following abuse of notation: Convention 7 The type tx : A | P pxqu, where ∆ | Γ, x : A $ P : Prop, may simply be denoted by P , where confusion is unlikely.
3 It would be more satisfying to have simply P :" 5P , but CHoTT is apparently too weak to prove that 5P is a proposition, as desired of P . This gives a hint that CHoTT, despite its advantages, may not be the last word in comonadic type theory.
The formula @px : manq.talkpipxqq is now understood as using Convention 7, as well as a coercion.

The Montague Test Sentences
With the benefit of the foregoing, we now render the Montague Test sentences in CHoTT. We will treat exactly the sentence suite formulated by Morrill and Valentín (2016) in introducing the Montague Test.
We assume a ground type E, together with a number of constants that serve as the translations of natural language terms, detailed in Figure 2. These are simply taken from Dowty et al. (1981), Chapter 7, using the correspondences suggested by Table 1, plus a single important stipulation: wherever the type e appears for Dowty et al., 5E (rather than E) appears for us. This unfortunate technical device is necessitated by our approach to de re readings, which makes use of let-substitution. One can substitute terms of type 5E using let, but not E. 4 The CHoTT forms for the Montague Test sentences are given in Table 4, below. Any reference numbers come from Chapter 7 of Dowty et al. (1981).
Overall, CHoTT formulas of Table 4 closely reflect those given by Montague (1973). To illustrate the similarities and differences, we return, at last, to the translations of "John believes that a fish walks." The de dicto reading is translated as believepj, pDpx : f ishq.walkpipxqqq 5 q .

Agda-flat
We now discuss Agda-flat, and the implementation therein of the Montague Test sentences, as rendered in CHoTT in the previous section.

About Agda-flat
Agda-flat (Vezzosi, 2019) is a proof assistant due to Andrea Vezzosi (c. 2017Vezzosi (c. -2019. It is a branch of the Agda proof assistant (Norell, 2007) which grew out of Vezzosi's work on modal dependent type theory (Nuyts et al., 2017). Agda is similar to other dependently-typed proof assistants, like Coq. Agda-flat adds on a modal operator, 5.
Agda-flat was intended as a proof assistant for mathematical theorems. Early mathematical uses include Licata et al. (2018) and Wellen (2018). The original version of Agda-flat is largely incompatible with linguistic applications, due to its relatively strong proof theory. Amongst other things, one can prove that 5 is idempotent (that is, 55A » 5A), which does not hold in the familiar model of Montague (1973). Following a 2019 request from the author, Vezzosi implemented a new mode, called ("no-flat-split"), with a weaker proof theory. It is this "no-flat-split" mode which corresponds closely to CHoTT, and thus provides a setting for (optionally hyperintensional) Montague semantics.

Installation and Configuration
Agda-flat is available for download at: https: //github.com/agda/agda/tree/flat. Unfortunately, the process of installing Agda and turning on Agda-flat is system-dependent and potentially complex. The Agda Wiki (Agda Collaboration) can provide guidance, and one may wish to avail oneself of a friendly Agda user, including online.
As mentioned in Section 4.1, the "no-flat-split" option is necessary for computational semantics applications. To engage the "no-flat-split" option, place the code {-# OPTIONS --no-flat-split #-} at the beginning of a module.

Use
Agda-flat and CHoTT are similar, with both admitting a 5-operator, and in particular having a way of restricting the 5-Form. and 5-Intro operations. Whereas in CHoTT, this is achieved by restricting these operations to an intensional context, in Agda, the variable contexts are not made explicit, and instead heavy use is made of ś -types. Of necessity, then, the ś -types of Agda-flat are permitted to be of the form ź u:t5u A P , in which an intensional variable is bound. In "Agda notation", however, Agda-flat allows a similar manipulation of intensional variables by the rules for inductive types. Furthermore, 5 is actually defined as an inductive type in Agda-flat, and uses pattern matching instead of an Elim. rule, as for any inductive types in Agda.
That is, 5 is defined as an inductive type by, in pseudo-code, Once the 5 operator is defined, and the above stylistic differences between CHoTT and Agdaflat accounted for, the rendering of CHoTT terms in Agda-flat proceeds as expected.

The Montague Test
The logical forms given in Table 4 are rendered in type-checkable code, available on the GitHub of the author at https://github. com/zwanzigerc/Montague-Test. This repository makes use of the conventions and codebase of the HoTT-Agda library (Brunerie et al.). In addition to the "official" renderings, there are also alternative ones which use the universe Type in lieu of the more complex Prop.
Agda-flat thus satisfies the Montague Test, and is seen to accommodate computational dependently typed Montague semantics.
With the basic setup of intensional computational semantics in Agda-flat achieved, a key goal becomes automation, both of the translation from natural language into Agda-flat, and of proof search. Since Agda is so similar to Coq, it is possible that Agda-flat could be integrated with the translation from Grammatical Framework used in FraCoq (Bernardy and Chatzikyriakidis, 2017). As for proof search, Agda has some limited automation options, such as the command "auto", which should be explored. Ultimately the performance of Agda-flat at natural language inference should be compared to other systems that satisfy the Montague Test, such as CatLog3 (Morrill, 2017).
In summary, CHoTT and the closely related Agda-flat, while building directly on a separate tradition than intensional logic, do incorporate intensional logic, together with additional features. Furthermore, these extra features have various uses for the natural language semanticist, rather than being peculiarities inflicted on them by the Agda-flat system. That said, since our intention is to m Agda-flat (without the assumption of intensional "-induction) is furthermore an appropriate system to implement hyperintensional semantics in the style of Zwanziger (2018). A full discussion of this is deferred to later work.