1 Introduction: Intensionality and Intensional Recursion

This paper proposes a new theory of intensionality. Intensionality is a notion that dates as early as Frege’s philosophical distinction between sense and denotation, see for example [11]. In the most mathematically general sense, to be ‘intensional’ is to somehow operate at a level finer than some predetermined ‘extensional’ equality. Whereas in mainstream mathematics intensionality is merely a nuisance, it is omnipresent in computer science, where the objects of study are distinct programs and processes describing (often identical) abstract mathematical values. At one end of the spectrum, programs are extensionally equal if they are observationally equivalent, i.e. interchangeable in any context. At the other extreme, computer viruses often make decisions simply on patterns of object code they encounter, disregarding the actual function of what they are infecting; one could say they operate up to syntactic identity.

1.1 Intensionality as a Logical Construct

We are interested in devising a categorical setting in which programs can be viewed in two ways simultaneously, either as black boxes—i.e. extensionally, whatever we define that to mean, but also as white boxes—i.e. intensionally, which should amount to being able to ‘look inside’ a construction and examine its internal workings.

There are many reasons for pursuing this avenue. The main new construct we will introduce will be an abstraction of the notion of Gödel numbering. The immediate achievement of this paper is a categorical language in which we can state many classic theorems from logic and computability that depend on the interplay between extension and intension. This unifying language encompasses all such ‘diagonal constructions’ in a way that makes the ingredients involved in each argument clear. As such, we regard this as an improvement on the classic paper of Lawvere [16].

A more medium-term goal is the quest to prove a logical foundation to computational reflection, in the sense of Brian Cantwell Smith [23]. A reflective program is always able to obtain a complete description of its source code and current state; this allows it to make decisions depending on both its syntax and runtime behaviour. This strand of research quickly ran into impossibility results that demonstrate that reflective features are logically ill-behaved: see e.g. [2] for reflection in untyped \(\lambda \)-calculus, or [25] for a more involved example involving the LISP fexpr construct. Our viewpoint allows us to talk about the notion of intensional recursion, which is more general than ordinary extensional recursion, and seems to correspond to a well-behaved form of reflection. We connect this to a classic result in computability theory, namely Kleene’s Second Recursion Theorem (SRT).

Finally, a more long-term goal is to understand non-functional computation. In this context, non-functional computation means something much more general than just computing with side-effects: we are interested in general higher-order computation acting ‘on syntax.’ Approaches to such forms of computation have hitherto been ad-hoc, see e.g. [18, Sect. 6]. We would like to provide a very general way to add ‘intensional’ features to a pure functional programming language.

1.2 Prospectus

To begin, we introduce in Sect. 2 a known connection between the notion of intension and the necessity modality from modal logic, and the use of modal types in isolating intension from extension. We argue that this connection cannot be fully substantiated in 1-category theory. Hence, we introduce P-categories and explain their use in modelling intensionality.

In Sect. 3 we introduce a new P-categorical construct, the exposure. Exposures ‘turn intensions into extensions’ in a manner inspired by the modality-as-intension interpretation. In Sect. 4 we use exposures to talk about the notion of intensional recursion in terms of intensional fixed points (IFPs).

In Sect. 5 we use IFPs to prove abstract analogues to Tarski’s undefinability theorem and Gödel’s First Incompleteness Theorem. In Sect. 6 we construct a P-category and an endoexposure that substantiate the claim that the abstract versions correspond to the usual theorems.

We then ask the obvious question: where do IFPs come from? In Sect. 7 we generalize Lawvere’s fixed-point theorem to yield IFPs. Then, in Sect. 8, we draw a parallel between Kleene’s First Recursion Theorem (FRT) and Lawvere’s fixed point result, whereas we connect our IFP-yielding result with Kleene’s Second Recursion Theorem. We substantiate this claim in Sect. 9 by constructing a P-category and exposure based on realizability theory.

Finally, in Sect. 10 we provide further evidence for the usefulness of our language by reproducing an abstract version of Rice’s theorem, a classic result in computability theory. We find that this is already substantiated in the P-category constructed in Sect. 9.

2 Modality-as-Intension

All the negative results regarding intensionality and computational reflection have something in common: they invariably apply to some construct that can turn extension into intension. For example, in [2] a contradiction is derived from the assumption that some term Q satisfies \(QM =_{\beta } \ulcorner M \urcorner \) for any M, where the RHS is a Gödel number of M. The moral is that one should not mix intension and extension.

To separate the two, we will use modal types, as first suggested by Davies and Pfenning [10, 22]. In op. cit. the authors use modal types to simulate two-level \(\lambda \)-calculi. In passing, they interpret the modal type \(\Box A\) as the type of ‘intensions of type A’ or ‘code of type A.’ The T axiom \(\Box A \rightarrow A\) may then be read as an interpreter that maps code to values, whereas the 4 axiom \(\Box A \rightarrow \Box \Box A\) corresponds to quoting, but quoting that can only happen when the initial value is already code, and not a ‘runtime,’ live value.

Unfortunately, the available semantics do not corroborate this interpretation. The categorical semantics of the S4 necessity modality—due to Bierman and de Paiva [4]—specify that \(\Box \) is a monoidal comonad \((\Box , \epsilon , \delta )\) on a CCC. The problem is now rather obvious, in that equality in the category is extensional equality: if \(f = g\), then \(\Box f = \Box g\). In modal type theory, this amounts to saying that \(\vdash M = N : A\) implies \(\vdash \mathsf {box\;}M = \mathsf {box\;}N : \Box A\), which is not what we mean by intensionality at all. By definition, ‘intension’ should not be preserved under equality, and in [10] it is clearly stated that there should be no reductions under a \(\mathsf {box\;}(-)\) construct.

To salvage this modality-as-intension interpretation, we have to leave 1-category theory, and move to a framework where we can separate extensional equality—denoted \(\sim \)—and intensional equality—denoted \(\approx \). We will thus use the P-categories of Čubrić, Dybjer and Scott [8]. P-categories are only categories up to a family of partial equivalence relations (PERs). In our setting, the PER will specify extensional equality. All that remains is to devise a construct that (a) behaves like a modality, so that intension and extension stay separate, and (b) unpacks the non-extensional features of an arrow. This will be the starting point of our theory of exposures.

2.1 P-categories and Intensionality

Suppose we have a model of computation or a programming language whose programs are seen as computing functions, and suppose that we are able to compose programs in this language, so that given programs \(\texttt {P}\) (computing f) and \(\texttt {Q}\) (computing g) there is a simple syntactic construction \(\texttt {Q}; \texttt {P}\) (computing \(g \circ f\)). In more elegant cases, like the \(\lambda \)-calculus, composition will be substitution of a term for a free variable. But in most other cases there will be unappealing overhead, involving e.g. some horrible disjoint unions of sets of states. This syntactic overhead almost always ensures that composition of programs is not associative: \((\texttt {R};\texttt {Q});\texttt {P}\) is not syntactically identical to \(\texttt {R};(\texttt {Q};\texttt {P})\), even though they compute the same function.

To model this we will use P-categories, first introduced in [8]. Generally denoted \(\mathfrak {B}, \mathfrak {C}, \dots \), or even \((\mathfrak {B}, \sim )\), P-categories are categories whose hom-sets are not sets, but P-sets: a P-set is a pair \(A = (\left|A \right|, \sim _A)\) of a set \(\left|A \right|\) and a partial equivalence relation (PER)Footnote 1 on \(\left|A \right|\). If \(a \sim _A a'\), then a can be thought of as ‘equal’ to \(a'\). The lack of reflexivity means that there may be some \(a \in \left|A \right|\) such that \(a \not \sim _A a\): these can be thought of as points which are not well-defined. A P-function \(f : A \rightarrow B\) between two P-sets \(A = (\left|A \right|, \sim _A)\) and \(B = (\left|B \right|, \sim _B)\) is a function \(\left|f \right| : \left|A \right| \rightarrow \left|B \right|\) that respects the PER: if \(a \sim _A a'\) then \(\left|f \right|(a) \sim _B \left|f \right|(a')\). We simply write f(a) if \(a \sim _A a\).

Thus, we take each hom-set \(\mathfrak {C}(A, B)\) of a P-category \(\mathfrak {C}\) to be a P-set. We will only write \(f : A \rightarrow B\) if \(f \sim _{\mathfrak {C}(A, B)} f\), i.e. f is a well-defined arrow. Arrows in a P-category are intensional constructions. Two arrows \(f, g : A \rightarrow B\) will be extensionally equal if \(f \sim _{\mathfrak {C}(A, B)} g\). The axioms of category theory will then only hold up to the family of PERs, i.e. \({\sim } = \{\sim _{\mathfrak {C}(A, B)}\}_{A, B \in \mathfrak {C}}\). For example, it may be that \(f \circ (g \circ h) \ne (f \circ g) \circ h\), yet \(f \circ (g \circ h) \sim (f \circ g) \circ h\).

Hence, we regain all the standard equations of 1-categories, up to PERs. Furthermore, the standard notions of terminal objects, products and exponentials all have a P-variant in which the defining equations hold up to \(\sim \). We are unable to expound on P-categories any further, but please refer to [8] for more details.

3 Exposures

We can now formulate the definition of exposures. An exposure is almost a (P-)functor: it preserves identity and compositions, but it only reflects PERs.

Definition 1

An exposure \(Q : (\mathfrak {B}, \sim ) \looparrowright {} (\mathfrak {C}, \sim )\) consists of (a) an object \(QA \in \mathfrak {C}\) for each object \(A \in \mathfrak {B}\), and (b) an arrow \(Qf : QA \rightarrow QB\) in \(\mathfrak {C}\) for each arrow \(f : A \rightarrow B\) in \(\mathfrak {B}\), such that (1) \(Q(id_A) \sim id_{QA}\), and (2) \(Q(g \circ f) \sim Qg \circ Qf\) for any arrows \(f : A \rightarrow B\) and \(g : B \rightarrow C\), and (3) for any \(f, g : A \rightarrow B\), if \(Qf \sim Qg\) then \(f \sim g\).

The identity exposure \(\mathsf {Id}_\mathfrak {B} : \mathfrak {B} \looparrowright {} \mathfrak {B}\) maps every object to itself, and every arrow to itself. Finally, it is easy to see that the composite of two exposures is an exposure.

As exposures give a handle on the internal structure of arrows, they can be used to define intensional equality: if the images of two arrows under the same exposure Q are extensionally equal, then the arrows have the same implementation, so they are intensionally equal. This is an exact interpretation of a slogan of Abramsky [1]: intensions become extensions.

Definition 2

(Intensional Equality). Let there be P-categories \(\mathcal {B}\), \(\mathcal {C}\), and an exposure \(Q : (\mathcal {B}, \sim ) \looparrowright {} (\mathcal {C}, \sim )\). Two arrows \(f, g : A \rightarrow B\) are intensionally equal (up to Q), written \(f \approx g\), just if \(Qf \sim Qg\).

It is obvious then that the last axiom on the definition of exposures means that intensional equality implies extensional equality.

To re-interpret concepts from the modality-as-intension interpretation—such as interpreters, quoting etc.—we shall need a notion of transformation between exposures.

Definition 3

A natural transformation of exposures \(t : F \overset{\bullet }{\looparrowright }G\) where \(F, G: \mathfrak {B} \looparrowright {} \mathfrak {C}\) are exposures, consists of an arrow \(t_A : FA \rightarrow GA\) of \(\mathfrak {C}\) for each object \(A \in \mathfrak {B}\), such that, for every arrow \(f : A \rightarrow B\) of \(\mathfrak {B}\), the following diagram commutes up to \(\sim \):

figure a

3.1 Cartesian Exposures

Bare exposures offer no promises or guarantees regarding intensional equality. For example, it is not a given that \(\pi _1 \circ \langle f, g \rangle \approx f\). However, one may argue that this equality should hold, insofar as there is no grand intensional content in projecting a component. This leads to the following notion:

Definition 4

A exposure \(Q : \mathfrak {B} \looparrowright {} \mathfrak {C}\) where \(\mathfrak {B}\) is a cartesian P-category is itself cartesian just if, for arrows \(f : C \rightarrow A\) and \(g : C \rightarrow B\), we have

$$ \pi _1 \circ \langle f, g \rangle \approx f, \quad \pi _2 \circ \langle f, g \rangle \approx g, \quad \text {and } \langle \pi _1 \circ h, \pi _2 \circ h \rangle \approx h $$

However, this is not enough to formally regain standard equations like \(\langle f, g \rangle \circ h \approx \langle f \circ h, g \circ h \rangle \). We need to also require that exposures ‘extensionally preserve’ products.

Definition 5

A cartesian exposure \(Q : \mathcal {B} \looparrowright {} \mathcal {C}\) of a cartesian P-category \(\mathcal {B}\) in a cartesian P-category \(\mathcal {C}\) is product-preserving whenever the canonical arrows

$$\begin{aligned} \langle Q\pi _1, Q\pi _2 \rangle&: Q(A \times B) \rightarrow QA \times QB \\ {!}_{Q\mathbf {1}}&: Q\mathbf {1} \rightarrow \mathbf {1} \end{aligned}$$

are P-isomorphisms. We write \(m_{A, B} : QA \times QB \xrightarrow {\cong } Q(A \times B)\) and \(m_{0} : \mathbf {1} \xrightarrow {\cong } Q\mathbf {1}\) for their inverses.

Amongst the exposures, then, the ones that are both cartesian and product-preserving are the ones that behave reasonably well in interaction with the product structure. For example, it is an easy calculation to show that

Proposition 1

In the above setting, \(m_{A, B} \circ \langle Qf, Qg \rangle \sim Q\langle f, g \rangle \).

We can now prove that \(\langle f, g \rangle \circ h \approx \langle f \circ h, g \circ h \rangle \):

$$\begin{aligned} Q(\langle f, g \rangle \circ h)&\sim Q(\langle \pi _1 \circ \langle f, g \rangle \circ h, \pi _2 \circ \langle f, g \rangle \circ h \rangle ) \\&\sim m \circ \langle Q(\pi \circ \langle f, g \rangle \circ h), Q(\pi ' \circ \langle f, g \rangle \circ h) \rangle \\&\sim m \circ \langle Q(f \circ h), Q(g \circ h) \rangle \sim Q(\langle f \circ h, g \circ h \rangle ) \end{aligned}$$

3.2 Evaluators, Quotation Devices, and Comonadic Exposures

Using transformations of exposures, we may begin to reinterpret concepts from the modality-as-intension interpretation. Throughout this section, we fix a cartesian P-category \(\mathfrak {B}\), and a cartesian, product-preserving endoexposure \(Q : \mathfrak {B} \looparrowright {} \mathfrak {B}\).

Definition 6

An evaluator is a transformation of exposures \(\epsilon : Q \overset{\bullet }{\looparrowright }{} \textsf {Id}_{\mathfrak {B}}\).

What about quoting? Given a point \(a : \mathbf {1} \rightarrow A\), its quote is defined to be the point \(Q(a) \circ m_0 : \mathbf {1} \rightarrow QA\). We will require the following definition:

Definition 7

A arrow \(\delta : QA \rightarrow Q^2 A\) is a reasonable quoting device just if for any \(a : \mathbf {1} \rightarrow QA\) the following diagram commutes up to \(\sim \):

figure b

A special case of this condition is the equation that holds if a natural transformation of a similar type to \(\delta \) is monoidal, namely \(\delta _\mathbf {1} \circ m_0 \sim Q(m_0) \circ m_0\).

Definition 8

A quoter is a transformation of exposures \(\delta : Q \overset{\bullet }{\looparrowright }Q^2\) such that every component \(\delta _A : QA \rightarrow Q^2 A\) is a reasonable quoting device.

These ingredients finally combine to form a comonadic exposure.

Definition 9

A comonadic exposure \((Q, \epsilon , \delta )\) consists of an endoexposure \(Q: (\mathfrak {B}, \sim ) \looparrowright (\mathfrak {B}, \sim )\), an evaluator \(\epsilon : Q \overset{\bullet }{\looparrowright }{} \mathsf {Id}_\mathfrak {B}\), and a quoter \(\delta : Q \overset{\bullet }{\looparrowright }{} Q^2\), such that the following diagrams commute up to \(\sim \):

figure c

4 Exposures and Intensional Recursion

Armed with the above, we can now speak of both extensional and intensional recursion. Lawvere [16] famously proved a theorem which guarantees that, under certain assumptions which we will discuss in Sect. 7, there exist fixed points of the following sort.

Definition 10

An extensional fixed point (EFP) of an arrow \(t : Y \rightarrow Y\) is a point \(y : \mathbf {1} \rightarrow Y\) such that \(t \circ y \sim y\). If, for a given object Y, every arrow \(t : Y \rightarrow Y\) has a EFP, then we say that Y has EFPs.

In Lawvere’s paper EFPs are a kind of fixed point that oughtn’t exist. In fact, Lawvere shows that—were truth definable—the arrow \(\lnot : \mathbf {2} \rightarrow \mathbf {2}\) representing negation would have a fixed point, i.e. a formula \(\phi \) with \(\lnot \phi \leftrightarrow \phi \) that leads to inconsistency.

EFPs do not encompass fixed points that ought to exist. For example, the diagonal lemma for Peano Arithmetic (henceforth PA) stipulates that for any predicate \(\phi (x)\), there exists a closed formula \(\mathbf {fix}(\phi )\) such that

$$ \textsf {PA} \vdash \mathbf {fix}(\phi ) \leftrightarrow \phi (\ulcorner \mathbf {fix}(\phi ) \urcorner ) $$

The formula \(\mathbf {fix}(\phi )\) occurs asymmetrically: on the left hand side of the bi-implication it appears as a truth value, but on the right hand side it appears under a Gödel numbering, i.e. an assignment \(\ulcorner \cdot \urcorner \) of a numeral to each term and formula of PA. Since exposures map values to their encoding, the following notion encompasses this kind of ‘asymmetric’ fixed point.

Definition 11

Let \(Q : \mathfrak {B} \looparrowright {} \mathfrak {B}\) be a cartesian, product-preserving endoexposure. An intensional fixed point (IFP) of a arrow \(t : QY \rightarrow Y\) is a point \(y : \mathbf {1} \rightarrow Y\) such that

$$ y \sim t \circ Q(y) \circ m_0 $$

An object A has IFPs (w.r.t. Q) if every arrow \(t : QA \rightarrow A\) has a IFP.

This makes intuitive sense: \(y : \mathbf {1} \rightarrow Y\) is extensionally equal to t ‘evaluated’ at the point \(Q(y) \circ m_0 : \mathbf {1} \rightarrow QY\), which is the ‘quoted’ version of y.

5 Consistency, Truth and Provability: Gödel and Tarski

We are now in a position to argue that two well-known theorems from logic can be reduced to very simple algebraic arguments involving exposures. In fact, the gist of both arguments relies on the existence of IFPs for an ‘object of truth values’ in a P-category. The theorems in question are Gödel’s First Incompleteness Theorem and Tarski’s Undefinability Theorem [5, 24].

Suppose that we have some sort of object \(\mathbf {2}\) of ‘truth values.’ This need not be fancy: we require that it has two points \(\top : \mathbf {1} \rightarrow \mathbf {2}\) and \(\bot : \mathbf {1} \rightarrow \mathbf {2}\), standing for true and false respectively. We also require an arrow \(\lnot : \mathbf {2} \rightarrow \mathbf {2}\) which satisfies \(\lnot \circ \top \sim \bot \) and \(\lnot \circ \bot \sim \top \).

A simplified version of Gödel’s First Incompleteness theorem for PA is this:

Theorem 1

(Gödel). If PA is consistent, then there are sentences \(\phi \) of \(\textsf {PA}\) such that neither \(\textsf {PA} \vdash \phi \) nor \(\textsf {PA} \vdash \lnot \phi \).

The proof relies on two constructions: the diagonal lemma, and the fact that provability is definable in the system. The definability of provability amounts to the fact that there is a formula \(\text {Prov}(x)\) with one free variable x such that \(\textsf {PA} \vdash \phi \) if and only if \(\textsf {PA} \vdash \text {Prov}(\ulcorner \phi \urcorner )\). That is: the system can internally talk about its own provability, modulo some Gödel numbering.

It is not then hard to sketch the proof to Gödel’s theorem: take \(\psi \) such that \(\textsf {PA} \vdash \psi \leftrightarrow \lnot \text {Prov}(\ulcorner \psi \urcorner )\). Then \(\psi \) is provable if and only if it is not, so if either \(\textsf {PA} \vdash \psi \) or \(\textsf {PA} \vdash \lnot \psi \) we would observe inconsistency. Thus, if \(\textsf {PA}\) is consistent, neither \(\psi \) nor its negation are provable. It follows that \(\psi \) is neither equivalent to \(\bot \) or to \(\top \). In a way, \(\psi \) has an eerie truth value, neither \(\top \) nor \(\bot \).

Let us represent the provability predicate as an arrow \(p : Q\mathbf {2} \rightarrow \mathbf {2}\) such that \(y \sim \top \) if and only if \(p \circ Q(y) \circ m_0 \sim \top \). Consistency is captured by the following definition:

Definition 12

An object \(\mathbf {2}\) as above is simply consistent just if \(\top \not \sim \bot \).

Armed with this machinery, we can transport the argument underlying Gödel’s proof to our more abstract setting:

Theorem 2

If a \(p : Q\mathbf {2} \rightarrow \mathbf {2}\) is as above, and \(\mathbf {2}\) has IFPs, then one of the following things is true: either (a) there are points of \(\mathbf {2}\) other than \(\top : \mathbf {1} \rightarrow \mathbf {2}\) and \(\bot : \mathbf {1} \rightarrow \mathbf {2}\); or (b) \(\mathbf {2}\) is not simply consistent, i.e. \(\top \sim \bot \).

Proof

As \(\mathbf {2}\) has IFPs, take \(y : \mathbf {1} \rightarrow \mathbf {2}\) such that \(y \sim \lnot \circ p \circ Q(y) \circ m_0\). Now, if \(y \sim \top \), then by the property of p above, \(p \circ Q(y) \circ m_0 \sim \top \), hence \(\lnot \circ p \circ Q(y) \circ m_0 \sim \bot \), hence \(y \sim \bot \). So either \(y \not \sim \top \) or \(\mathbf {2}\) is not simply consistent. Similarly, either \(y \not \sim \bot \) or \(\mathbf {2}\) is not simply consistent.

Tarski’s Undefinability Theorem, on the other hand is the result that truth cannot be defined in arithmetic [24].

Theorem 3

(Tarski). If PA is consistent, then there is no predicate \(\text {True}(x)\) such that \(\textsf {PA} \vdash \phi \leftrightarrow \text {True}(\ulcorner \phi \urcorner )\) for all sentences \(\phi \).

The proof is simple: use the diagonal lemma to obtain a closed \(\psi \) such that \(\textsf {PA} \vdash \psi \leftrightarrow \lnot \text {True}(\ulcorner \psi \urcorner )\), so that \(\textsf {PA} \vdash \psi \leftrightarrow \lnot \psi \), which leads to inconsistency.

Now, a proof predicate would constitute an evaluator \(\epsilon : Q \overset{\bullet }{\looparrowright }{} \textsf {Id}_\mathfrak {B}\): we would have that

$$ \epsilon _\mathbf {2} \circ Q(y) \circ m_0 \sim y \circ \epsilon _\mathbf {1} \circ m_0 \sim y $$

where the last equality is because \(\mathbf {1}\) is terminal. This is actually a more general.

Lemma 1

Let \(Q : \mathfrak {B} \looparrowright {} \mathfrak {B}\) be an endoexposure, and let \(\epsilon : Q \overset{\bullet }{\looparrowright }{} \textsf {Id}_\mathfrak {B}\) be an evaluator. Then, if A has IFPs then it also has EFPs.

Proof

Given \(t : A \rightarrow A\), consider \(t \circ \epsilon _A : QA \rightarrow A\). A IFP for this arrow is a point \(y : \mathbf {1} \rightarrow A\) such that \(y \sim t \circ \epsilon _A \circ Q(y) \circ m_0\). But we may calculate as above to show that \(\epsilon _A \circ Q(y) \circ m_0 \sim y\) and thus \(y \sim t \circ y\).

In proving Tarski’s theorem, we constructed a sentence \(\psi \) such that \(\textsf {PA} \vdash \psi \leftrightarrow \lnot \psi \). This can be captured abstractly by the following definition.

Definition 13

An object \(\mathbf {2}\) as above is fix-consistent just if the arrow \(\lnot : \mathbf {2} \rightarrow \mathbf {2}\) has no EFP; that is, there is no \(y : \mathbf {1} \rightarrow \mathbf {2}\) such that \(\lnot \circ y \sim y\).

Putting these together, we get

Theorem 4

If \(\mathbf {2}\) has IFPs in the presence of an evaluator, then it is not fix-consistent.

6 An Exposure on Arithmetic

We will substantiate the results of the previous section by sketching the construction of a P-category and endoexposure based on a first-order theory. The method is very similar to that of Lawvere [16], and we will also call it the Lindenbaum P-category of the theory. The construction is general, and so is the thesis of this section: an exposure on a Lindenbaum P-category abstractly captures the notion of a well-behaved Gödel ‘numbering’ on the underlying theory.

Let there be a single-sorted first-order theory \(\mathsf {T}\). The objects of the P-category are the formal products of (a) \(\mathbf {1}\), the terminal object, (b) A, the domain, and (c) \(\mathbf {2}\), the object of truth values. Arrows \(\mathbf {1} \rightarrow A\) and \(A \rightarrow A\) are terms with no or one free variable respectively. Arrows \(A^n \rightarrow \mathbf {2}\) and \(\mathbf {1} \rightarrow \mathbf {2}\) are predicates, with n and no free variables respectively. Finally, arrows \(\mathbf {2}^n \rightarrow \mathbf {2}\) can be thought of as logical connectives (e.g. \(\wedge : \mathbf {2} \times \mathbf {2} \rightarrow \mathbf {2}\)).

Two arrows \(s, t : C \rightarrow A\) with codomain A (i.e. two terms of the theory) are related if and only if they are provably equal, i.e. \(s \sim t\) iff \(\textsf {T} \vdash s = t\). Two arrows \(\phi , \psi : C \rightarrow \mathbf {2} \) with codomain \(\mathbf {2}\) are related if and only if they are provably equivalent, i.e. \(\phi \sim \psi \) iff \(\textsf {T} \vdash \phi \leftrightarrow \psi \).

To define an exposure, it suffices to have a Gödel numbering, i.e. a representation of terms and formulas of the theory as elements of its domain A. More precisely, we need a Gödel numbering for which substitution is internally definable. We write \(\ulcorner \phi (x_1, \dots , x_n) \urcorner \) and \(\ulcorner t(a_1, \dots , a_m) \urcorner \) for the Gödel numbers of the formula \(\phi (x_1, \dots , x_n)\) and the term \(t(a_1, \dots , a_m)\) respectively, and we assume that \(\ulcorner \cdot \urcorner \) is injective. Let , , and . Finally, define Q to act component-wise on finite products: this will guarantee that it is cartesian and product-preserving.

The action on arrows is what necessitated that substitution be definable: this amounts to the existence of a term sub(yx) with the property that if \(\phi (x)\) is a predicate and t is a term, then \(\textsf {T} \vdash sub(\ulcorner \phi \urcorner , \ulcorner t \urcorner ) = \ulcorner \phi (t) \urcorner \). Now, given a predicate \(\phi : A \rightarrow \mathbf {2}\) with one free variable, \(Q(\phi ) : A \rightarrow A\) is defined to be the term \(sub(\ulcorner \phi \urcorner , x)\). Given a sentence \(\phi : \mathbf {1} \rightarrow \mathbf {2}\), we define \(Q(\phi ) : \mathbf {1} \rightarrow A\) to be exactly the closed term \(\ulcorner \phi \urcorner \). The action is similar on arrows with codomain A, and component-wise on product arrows. The last axiom of exposures is satisfied: if \(Q\phi \sim Q\psi \), then \(\ulcorner \phi \urcorner = \ulcorner \psi \urcorner \), so that \(\phi = \psi \), by the injectivity of the Gödel numbering.

In this setting, IFPs really are fixpoints of formulas.

7 Where Do IFPs Come From?

In Sect. 4 we mentioned Lawvere’s fixed point theorem. This theorem guarantees the existence of EFPs under the assumption that there is an arrow of this form:

Definition 14

An arrow \(r : X \times A \rightarrow Y\) is weakly-point surjective if, for every \(f : A \rightarrow Y\), there exists a \(x_f : \mathbf {1} \rightarrow X\) such that for all points \(a : \mathbf {1} \rightarrow A\) it is the case that \(r \circ \langle x_f, a \rangle \sim f \circ a\).

So a weak-point surjection is a bit like ‘pointwise cartesian closure,’ in that the effect of all arrows \(A \rightarrow Y\) on points \(\mathbf {1} \rightarrow A\) is representable by some point \(\mathbf {1} \rightarrow X\), w.r.t. r. Lawvere noticed that if the ‘exponential’ X and the domain A coincide, then a simple diagonal argument yields fixpoints for all arrows \(Y \rightarrow Y\).

Theorem 5

(Lawvere). If \(r : A \times A \rightarrow Y\) is a weak-point surjection, then every arrow \(t : Y \rightarrow Y\) has an extensional fixed point (EFP).

Proof

Let . Then there exists a \(x_f : \mathbf {1} \rightarrow A\) such that \(r \circ \langle x_f, a \rangle \sim f \circ a\) for all \(a : \mathbf {1} \rightarrow A\). We compute that \(r \circ \langle x_f, x_f \rangle \sim \ t \circ r \circ \langle id_A, id_A \rangle \circ x_f \sim \ t \circ r \circ \langle x_f, x_f \rangle \), so that \(r \circ \langle x_f, x_f \rangle \) is a EFP of t.

Can we adapt Lawvere’s result to IFPs? The answer is positive, and rather straightforward once we embellish the statement with appropriate occurrences of Q. We also need a reasonable quoting device.

Theorem 6

Let Q be a monoidal exposure, and let \(\delta _A : QA \rightarrow Q^2 A\) be a reasonable quoting device. If \(r : QA \times QA \rightarrow Y\) is a weak-point surjection then every arrow \(t : QY \rightarrow Y\) has an intensional fixed point.

Proof

Let . Then there exists a \(x_f : \mathbf {1} \rightarrow QA\) such that \(r \circ \langle x_f, a \rangle \sim f \circ a\) for all \(a : \mathbf {1} \rightarrow QA\). We compute that

so that \(r \circ \langle x_f, x_f \rangle \) is a IFP of t.

In the next section, we shall see that this is a true categorical analogue of Kleene’s Second Recursion Theorem (SRT).

8 The Recursion Theorems

In fact, the theorem we just proved in Sect. 7 is strongly reminiscent of a known theorem in (higher order) computability theory, namely a version of Kleene’s First Recursion Theorem (FRT).

Let us fix some notation. We write \(\simeq \) for Kleene equality: we write \(e \simeq e'\) to mean either that both expressions e and \(e'\) are undefined, if either both are undefined, or both are defined and of equal value. Let \(\phi _0\), \(\phi _1\), \(\dots \) be an enumeration of the partial recursive functions. We will also require the s-m-n theorem from computability theory. Full definitions and statements may be found in the book by Cutland [9].

Theorem 7

(First Recursion Theorem). Let \(\mathcal {PR}\) be the set of unary partial recursive functions, and let \(F : \mathcal {PR} \rightarrow \mathcal {PR}\) be an effective operation. Then \(F : \mathcal {PR} \rightarrow \mathcal {PR}\) has a fixed point.

Proof

That \(F : \mathcal {PR} \rightarrow \mathcal {PR}\) is an effective operation means that there is a partial recursive \(f : \mathbb {N} \times \mathbb {N} \rightharpoonup {} \mathbb {N}\) such that \(f(e, x) \simeq F(\phi _e)(x)\). Let \(d \in \mathbb {N}\) a code for the partial recursive function , where \(S : \mathbb {N} \times \mathbb {N} \rightharpoonup {} \mathbb {N}\) is the s-1-1 function of the s-m-n theorem. Then, by the s-m-n theorem, and the definitions of \(d \in \mathbb {N}\) and f,

$$ \phi _{S(d, d)}(x) \simeq \phi _d(d, x) \simeq f(S(d, d), x) \simeq F(\phi _{S(d,d)})(x) $$

so that \(\phi _{S(d, d)}\) is a fixed point of \(F : \mathcal {PR} \rightarrow \mathcal {PR}\).

Lawvere’s theorem is virtually identical to a point-free version of this proof. Yet, one cannot avoid noticing that we have proved more than that for which we bargained. The \(f : \mathbb {N} \times \mathbb {N} \rightharpoonup {} \mathbb {N}\) in the proof above has the special property that it is extensional, in the sense that

$$ \phi _e = \phi _{e'} \quad \Longrightarrow \quad \forall x \in \mathbb {N}.\ f(e, x) = \phi (e', x) $$

However, the step which yields the fixed point argument holds for any such f, not just the extensional ones. This fact predates the FRT, and was shown by Kleene in 1938 [14].

Theorem 8

(Second Recursion Theorem). For any partial recursive \(f: \mathbb {N} \times \mathbb {N} \rightharpoonup \mathbb {N}\), there exists \(e \in \mathbb {N}\) such that \(\phi _e(y) \simeq f(e, y)\) for all \(y \in \mathbb {N}\).

This is significantly more powerful than the FRT, as f(ey) can make arbitrary decisions depending on the source code e, irrespective of the function \(\phi _e\) of which it is the source code. Moreover, it is evident that the function \(\phi _e\) has access to its own code, allowing for a certain degree of reflection. Even if f is extensional, hence defining an effective operation, the SRT grants us more power than the FRT: for example, before recursively calling e on some points, f(ey) could ‘optimise’ e depending on what y is, hence ensuring that the recursive call will run faster than e itself would. This line of thought is common in the partial evaluation community, see e.g. [12].

In the sequel we argue that our fixed point theorem involving exposures is a generalisation of Lawvere’s theorem, in the exact same way that the SRT is a non-extensional generalisation of the FRT. In order to do so, we define a P-category and an exposure based on realizability theory, and claim that the FRT and the SRT are instances of the general theorems in that particular P-category.

9 An Exposure on Assemblies

Our second example of an exposure will come from realizability, where the basic objects are assemblies. An assembly is a set to every element of which we have associated a set of realizers. The elements of the set can be understood as elements of a datatype, and the set of realizers of each such element as the machine-level representations of it. For example, if realizers range in the natural numbers, then assemblies and functions between them which are partial recursive on the level of realizers yield a category where ‘everything is computable.’

In practice, the generalisation from natural numbers to an arbitrary partial combinatory algebra (PCA) is made. A PCA is an arbitrary, untyped ‘universe’ corresponding to some notion of computability or realizability. There are easy tricks with which one may encode various common ‘first-order’ datatypes, such as booleans, integers, etc. as well as all partial recursive functions (up to the encoding of integers). These methods can be found [3, 17, 20, 21].

Definition 15

A partial combinatory algebra (PCA) \((A, \cdot )\) consists of a set A, its carrier, and a partial binary operation \(\cdot : A \times A \rightharpoonup A\) such that there exist \(\mathbf {K}, \mathbf {S} \in A\) with the properties that

$$ \mathbf {K} \cdot x\downarrow , \quad \mathbf {K} \cdot x \cdot y \simeq y, \quad \mathbf {S} \cdot x \cdot y\downarrow , \quad \mathbf {S} \cdot x \cdot y \cdot z \simeq x \cdot z \cdot (y \cdot z) $$

for all \(x, y, z \in A\).

The simplest example of a PCA, corresponding to classical computability, is \(K_1\), also known as Kleene’s first model. Its carrier is \(\mathbb {N}\), and .

Definition 16

An assembly X on a PCA A consists of a set \(\left|X \right|\) and, for each \(x \in \left|X \right|\), a non-empty subset \(\left\| x\right\| _X\) of A. If \(a \in \left\| x\right\| _X\), we say that a realizes x.

Definition 17

For two assemblies X and Y, a function \(f : \left|X \right| \rightarrow \left|Y \right|\) is said to be tracked by \(r \in A\) just if, for all \(x \in \left|X \right|\) and \(a \in \left\| x \right\| _X\), we have \(r \cdot a \downarrow \) and \(r \cdot a \in \left\| f(x) \right\| _Y\).

Now: for each PCA A, we can define a category \(\mathbf {Asm}(A)\), with objects all assemblies X on A, and morphisms \(f : X \rightarrow Y\) all functions \(f : \left|X \right| \rightarrow \left|Y \right|\) that are tracked by some \(r \in A\).

Theorem 9

Assemblies and ‘trackable’ morphisms between them form a category \(\mathbf {Asm}(A)\) that is cartesian closed, has finite coproducts, and a natural numbers object.

We only mention one other construction that we shall need. Given an assembly X, the lifted assembly \(X_\bot \) is defined to be

for some chosen element of the PCA \(\overline{0}\). Elements of \(X_\bot \) are either elements of X, or the undefined value \(\bot \). Realizers of \(x \in \left|X \right|\) are ‘computations’ \(r \in A\) which, when run (i.e. given the dummy value \(\overline{0}\) as argument) return a realizer of x. A computation that does not halt when run represents the undefined value.Footnote 2

9.1 Passing to a P-category

The lack of intensionality in the category \(\mathbf {Asm}(A)\) is blatantly obvious. To elevate a function \(f : \left|X \right| \rightarrow \left|Y \right|\) to a morphism \(f : X \rightarrow Y\), we only require that there exists a ‘witness’ \(r \in A\) that realizes it, and then we forget about this witness entirely. To mend this, we define a P-category.

The P-category \(\mathfrak {Asm}(A)\) of assemblies on A is defined to have all assemblies X on A as objects, and pairs \((f : \left|X \right| \rightarrow \left|Y \right|, r \in A)\) where r tracks f as arrows. We define \((f, r) \sim (g, s)\) just if \(f = g\), i.e. when the underlying function is the same. The composition of \((f, p) : X \rightarrow Y\) and \((g, q) : Y \rightarrow Z\) is \((g \circ f, \mathbf {B} \cdot q \cdot p)\) where \(\mathbf {B}\) is a combinator in the PCA such that \(\mathbf {B} \cdot f \cdot g \cdot x \simeq f \cdot (g \cdot x)\) for any \(f, g, x \in A\). The identity \(id_X : X \rightarrow X\) is defined to be \((id_{\left|X \right|}, \mathbf {I}) : X \rightarrow X\), where \(\mathbf {I}\) is a combinator in the PCA such that \(\mathbf {I} \cdot x \simeq x\) for all \(x \in A\).

Much in the same way as before—but now up to the PER \(\sim \)—we can show

Theorem 10

\(\mathfrak {Asm}(A)\) is a cartesian closed P-category with a natural numbers object \(\mathbb {N}\).

We can now define an exposure \(\Box : \mathfrak {Asm}(A) \looparrowright {} \mathfrak {Asm}(A)\). For an assembly \(X \in \mathfrak {Asm}(A)\), let \(\Box X\) be the assembly defined by

Given \((f, r) : X \rightarrow Y\), we define \(\Box (f, r) = (f_r, r) : \Box X \rightarrow \Box Y \) where \(f_r : \left|\Box X \right| \rightarrow \left|\Box Y \right|\) is defined by . Thus, under the exposure each element \((x, a) \in \left|\Box X \right|\) carries with it its own unique realizer a. The image of (fr) under \(\Box \) shows not only what f does to an element of its domain, but also how r acts on the realizer of that element.

It is long but straightforward to check that

Theorem 11

\(\Box : {\mathfrak {Asm}}(A) \looparrowright {} {\mathfrak {Asm}}(A)\) is a cartesian, product-preserving, and comonadic endoexposure.

9.2 Kleene’s Recursion Theorems, Categorically

Let us concentrate on the category \(\mathfrak {Asm}(K_1)\). Arrows \(\mathbb {N} \rightarrow \mathbb {N}_\bot \) are easily seen to correspond to partial recursive functions. It is not hard to produce a weak-point surjection \(r_E : \mathbb {N} \times \mathbb {N} \rightarrow \mathbb {N}_\bot ^{\mathbb {N}}\), and hence to invoke Lawvere’s theorem to show that every arrow \(\mathbb {N}_\bot ^{\mathbb {N}} \rightarrow \mathbb {N}_\bot ^{\mathbb {N}}\) has an extensional fixed point. Now, by Longley’s generalised Myhill-Shepherdson theorem [17, 19], arrows \(\mathbb {N}_\bot ^{\mathbb {N}} \rightarrow \mathbb {N}_\bot ^{\mathbb {N}}\) correspond to effective operations. Hence, in this context Lawvere’s theorem corresponds to the simple diagonal argument that we used to show the FRT.Footnote 3

Let us look at arrows of type \(\Box (\mathbb {N}_\bot ^{\mathbb {N}}) \rightarrow \mathbb {N}_\bot ^{\mathbb {N}}\). These correspond to ‘non-functional’ transformations, mapping functions to functions, but without respecting extensionality. As every natural number indexes a partial recursive function, these arrows really correspond to all partial recursive functions (up to some tagging and encoding). It is not hard to see that \(\Box \mathbb {N}\) is P-isomorphic to \(\mathbb {N}\), and that one can build a weak-point surjection of type \(\Box \mathbb {N} \times \Box \mathbb {N} \rightarrow \mathbb {N}_\bot ^{\mathbb {N}}\), so that by our theorem, every arrow of type \(\Box (\mathbb {N}_\bot ^{\mathbb {N}}) \rightarrow \mathbb {N}_\bot ^{\mathbb {N}}\) has an intensional fixed point. This is exactly Kleene’s SRT!

10 Rice’s Theorem

To further illustrate the applicability of the language of exposure, we state and prove an abstract version of Rice’s theorem. Rice’s theorem is a result in computability which states that no computer can decide any non-trivial property of a program by looking at its code. A short proof relies on the SRT.

Theorem 12

(Rice). Let \(\mathcal {F}\) be a non-trivial set of partial recursive functions, and let be the set of indices of functions in that set. Then \(A_\mathcal {F}\) is undecidable.

Proof

Suppose \(A_\mathcal {F}\) is decidable. The fact \(\mathcal {F}\) is non-trivial means that there is some \(a \in \mathbb {N}\) such that \(\phi _a \in \mathcal {F}\) and some \(b \in \mathbb {N}\) such that \(\phi _b \not \in \mathcal {F}\). Consequently, \(a \in A_\mathcal {F}\) and \(b \not \in A_\mathcal {F}\).

Define \(f(e, x) \simeq \mathbf {if }\, e \in A_\mathcal {F} \,\, \mathbf { then } \, \phi _b(x) \,\, \mathbf { else } \,\, \phi _a(x)\). By Church’s thesis, \(f : \mathbb {N} \times \mathbb {N} \rightarrow \mathbb {N}\) is partial recursive. Use the SRT to obtain \(e \in \mathbb {N}\) such that \(\phi _e(x) \simeq f(e, x)\). Now, either \(e \in A_\mathcal {F}\) or not. If it is, \(\phi _e(x) \simeq f(e, x) \simeq \phi _b(x)\), so that \(\phi _e \not \in \mathcal {F}\), a contradiction. A similar phenomenon occurs if \(e \not \in A_\mathcal {F}\).

Constructing the function f in the proof required three basic elements: (a) the ability to evaluate either \(\phi _a\) or \(\phi _b\) given a and b; (b) the ability to decide which one to use depending on the input; and (c) intensional recursion. For (a), we shall need evaluators, for (b) we shall need that the truth object \(\mathbf {2}\) is a weak coproduct of two copies of \(\mathbf {1}\), and for (c) we shall require IFPs.

Theorem 13

Let \(\mathbf {2}\) is a simply consistent ‘truth object’ which also happens to be a weak coproduct of two copies of \(\mathbf {1}\), with injections \(\top : \mathbf {1} \rightarrow \mathbf {2}\) and \(\bot : \mathbf {1} \rightarrow \mathbf {2}\). Furthermore, suppose that A has EFPs. If \(f : A \rightarrow \mathbf {2}\) is such that for all \(x : \mathbf {1} \rightarrow A\), either \(f \circ x \sim \top \) or \(f \circ x \sim \bot \), then f is trivial, in the sense that either \(f \circ x \sim \top \) for all \(x : \mathbf {1} \rightarrow A\), or \(f \circ x \sim \bot \) for all \(x : \mathbf {1} \rightarrow A\).

Proof

Suppose there are two such distinct \(a, b : \mathbf {1} \rightarrow A\) such that \(f \circ a \sim \top \) and \(f \circ b \sim \bot \). Let and let \(y : \mathbf {1} \rightarrow A\) be its EFP. Now, either \(f \circ y \sim \top \) or \(f \circ y \sim \bot \). In the first case, we can calculate that \(\top \sim \ f \circ [b, a] \circ f \circ y \sim \ f \circ [b, a] \circ \top \sim \ f \circ b \sim \ \bot \) so that \(\mathbf {2}\) is not simply consistent. A similar situation occurs if \(f \circ y \sim \bot \).

Needless to say that the premises of this theorem are easily satisfied in our exposure on assemblies from Sect. 9 if we take \(A = {\mathbb {N}_\bot }^\mathbb {N}\) and \(\mathbf {2}\) to be the lifted coproduct \((\mathbf {1} + \mathbf {1})_\bot \).

11 Conclusion

We have modelled intensionality with P-categories, and introduced a new construct that abstractly corresponds to Gödel numbers. This led us to an immediate unification of many ‘diagonal arguments’ in logic and computability, as well as a new perspective on the notion of intensional recursion. Our approach is clearer and more systematic than the one in [16].

Many questions are left open. We are currently working on the medium-term goal of a safe, reflective programming language based on modal type theory. The basics are there, but there are many questions: what operations should be available at modal types; with how much expressivity would the language be endowed for each possible set; and what are the applications?

On the more technical side, it is interesting to note that we have refrained from a categorical proof of the diagonal lemma for PA. All our attempts were inelegant, and we believe that this is because arithmetic is fundamentally untyped: \(Q(\mathbf {2})\) has many more points than ‘all Gödel numbers of predicates.’ In contrast, our approach using exposures is typed, which sets it apart from all previous attempts at capturing such arguments categorically, including the very elegant work of Cockett and Hofstra [6, 7]. The approach in op. cit. is based on Turing categories, in which every object is a retract of some very special objects—the Turing objects. In the conclusion of [6] this is explicitly mentioned as an ‘inherent limitation.’ Only time will tell which approach is more encompassing.

Finally, it would be interesting to study the meaning of exposure in examples not originating in logic and computability, but in other parts of mathematics. Can we find examples of exposures elsewhere? Are they of any use?