Categorical Logic

Jonas Frey April 2, 2017

1 Algebraic theories and Lawvere theories 1.1 Signatures and structures 1 Definition 1.1 A signature is a family Σ = (Σn) of sets. For n ∈ , the n∈N N elements of Σn are called n-ary operations. ♦

Definition 1.2 Let C be a with finite products and Σ a signature. 1.A Σ-structure A in C consists of

• an object A ∈ C (we use the same letter for the structure and the underlying object), and n • for every n ∈ N and f ∈ Σn a morphism fA : A → A. 2.A morphism of Σ-structures A, B is an arrow g : A → B between the underlying objects such that the square

gn An Bn

fA fB g A B

commutes for all n ∈ N and f ∈ Σn. ♦ It is easy to see that morphisms of Σ-structures commute, and we denote the category of Σ-structures in C and their morphisms by Σ-Str(C)2.

1.2 of terms Definition 1.3 The set T (Σ) of terms over Σ is inductively defined as follows.

1These could more precisely be called ‘algebraic signature’, to distinguish them from the ‘first-order signatures’ in the next section, but I simply write signature since it’s shorter. 2 In the course I wrote C-Str(Σ), but now I want the notation to be consistent with [1, Def. 1.2.1]

1 • Variables3 x, y, z, . . . are terms over Σ.

• If f ∈ Σn and t1 . . . tn are terms over Σ, then f(t1 . . . tn) is a term over Σ.

For n ∈ N we write Tn(Σ) ⊆ T (Σ) for the set of terms containing only the variables x1 . . . xn. ♦

Definition 1.4 Given a signature Σ, a Σ-structure A in a finite-product cate- gory C, and a term t ∈ Tn(Σ), the interpretation

n t A : A → A J K of t w.r.t. to A is defined as follows by induction on the structure of t.

n pi • xi A = (A −→ A) (i-th projection for 1 ≤ i ≤ n) J K h t ,..., t i n 1 A n A k fA • f(t1 . . . tn) A = (A −−−−−−−−−−→J K J K A −−→ A) (for f ∈ Σk) ♦ J K Strictly speaking, the notation t A is ambiguous without specifying the n, since we can always view a term in nJ Kvariables as a term in m variables for m ≥ n. In the following the n will always be clear from the context; a more rigorous notation will be introduced in the next section, where we use ‘terms in context’, which are terms with explicit variable declarations. Lemma 1.5 (Substitution Lemma) Let Σ be a signature, and A a Σ-structure. Then for t ∈ Tn(Σ) and u1 . . . un ∈ Tk(Σ) we have

t[u1/x1, . . . , un/xn] A = t A ◦ h u1 A,..., un Ai. J K J K J K J K Proof. By structural induction on t. 

1.3 Algebraic theories and models Definition 1.6 1. An algebraic theory is a pair (Σ,E) where Σ is a signa-

ture, and E = (En ⊆ Tn(Σ) × Tn(Σ))n∈N is a set of families of n-ary equations (a pair (t, u) ∈ En represents an equation t = u).

2.A model of an algebraic theory (Σ,E) in a category C with finite products is a Σ-structure A such that

n t A = u A : A → A J K J K for all n ∈ N and (t, u) ∈ En (in this situation we say that A satisfies the equation t = u).

3. The category Σ-Mod(C) of models of (Σ,E) in C is the full of Σ-Str(C) whose objects are the models of (Σ,E). ♦

3 Formally we assume there is a given countable set {x1, x2, x2,... } of variables, but in practice we often write x, y, z, . . . for variables instead of using subscripts.

2 1.4 Lawvere theories Lawvere4 theories are presentations of algebraic theories as ‘syntactic categories’. They are more canonical than representations of theories via signatures and equations, since e.g. the theory of groups can be represented using different signatures, but the Lawvere theory is unique up to isomorphism of categories. The central fact about Lawvere theories is that in the Lawvere-theoretic presentation, models of a theory (Σ,E) in a finite-product category C corre- spond to finite-product preserving from the associated Lawvere theory L(Σ,E) to C, and morphisms of models correspond to natural transformations between such functors. This is known as functorial semantics.

Definition 1.7 Given an algebraic theory (Σ,E), the binary relation =E is the least binary relation on T (Σ) closed under the following rules.

(ax) If (t, u) ∈ En then t =E u.

(refl) t =E t

(trans) If s =E t and t =E u then s =E u

(sym) If s =E t then t =E s

(cong) If t1 =E u1, . . . tn =E un then s[t1/x1, . . . , tn/xn] =E s[u1/x1, . . . , un/xn]

(subs) If s =E t then s[u1/x1, . . . , un/xn] =E t[u1/x1, . . . , un/xn] We write

T (Σ,E) = T (Σ)/=E and Tn(Σ,E) = Tn(Σ)/=E

for the set of terms (and the terms in n variables) modulo =E. ♦

Intuitively, =E is the least congruence relation on on T (Σ) containing E, or more precisely it is the least equivalence relation on T (Σ) which contains E and is closed under the operations and substitution. It is easy to see that the equations satisfied by a Σ-structure are closed under (refl), (trans), (sym), (cong), and (subs), whence we have the following lemma.

Lemma 1.8 Let (Σ,E) be an algebraic theory, and let A be a model of (Σ,E) in a finite-product category C. Then we have

t =E u ⇒ t A = u A J K J K for all n ∈ and t, u ∈ T (Σ). N n  Definition 1.9 The Lawvere theory L(Σ,E) of an algebraic theory (Σ,E) is the category defined as follows:

4William Lawvere, born 1937, is commonly viewed as the founder of categorical logic.

3 • for each n ∈ N there is an object [n] ∈ L(Σ,E) m • hom([n], [m]) = Tn(Σ,E) for n, m ∈ N

• (u1 . . . un) ◦ (t1 . . . tm) = (u1[~t/~x], . . . , un[~t/~x]) where

(t ...t ) (u ...u ) [k] −−−−−→1 m [m] −−−−−−→1 n [n]

is a composable pair of morphisms and [~t/~x] is short for [t1/x1, . . . , tm/xm]

• id[n] = (x1 . . . xn) ♦

Thus morphisms in L(Σ,E) are tuples of =E-equivalence classes of terms, com- position is simultaneous substitution, and identities are tuples of equivalence classes of variables. Since we are dealing with equivalence classes we have to check if the composition is well-defined, i.e. if substituting equivalent terms into equivalent terms yields equivalent terms. But this follows directly from (cong) and (subs) in Def. 1.7. Associativity and identity laws are easily verified, thus L(Σ,E) is a well-defined category. Moreover we have the following: Lemma 1.10 For every algebraic theory (Σ,E), the Lawvere theory L(Σ,E) has strict finite products.

Proof. [0] is the terminal object, binary product spans are given by

(x ...x ) (x ,...,x ) [m] ←−−−−−−1 m [m + n] −−−−−−−−−−→m+1 m+n [n]. for m, n ∈ N, and the pairing operation is given by h(~t), (~u)i = (~t, ~u):[k] → [m + n] for (~t):[k] → [m] and (~u):[k] → [n].  Here’s the central theorem about Lawvere theories. Theorem 1.11 For every algebraic theory (Σ,E) and finite-product category C, the category Σ-Mod(C) of (Σ,E)-models in C is equivalent to the category FP(L(Σ,E), C) of finite-product preserving functors from L(Σ,E) to C and arbitrary natural transformations between them5.

Proof. The fine print: for simplicity we assume that C has strictly associative and unital finite products, and that the functors in FP(L(Σ,E), C) strictly preserve finite products. By filling in ∼= ∼= suitable ‘coherence isomorphisms’ of the form γA,B : F (A × B) −→ FA × FB and γ1 : F 1 −→ 1, we can obtain a proof that works without these ‘strictness’ assumptions, but this would only obscure the central ideas. We construct a

I : FP(L(Σ,E), C) → Σ-Mod(C)

5 L(Σ,E) Thus FP(L(Σ,E), C) is a full subcategory of the functor category C .

4 as follows. Every (strictly) product preserving F : L(Σ,E) → C gets mapped to the Σ-structure IF whose underlying object is F [1], and where operations f ∈ Σn are interpreted as

F (f(~x):[n]→[1]) fIF = (F [n] −−−−−−−−−−→ F [1]). With this definition we show easily that

t IF = F (t): F [n] → F [1] J K for all t ∈ Tn(Σ) (by induction on t), from which it follows that IF satisfies the equations in E, since for any n ∈ N and (s, t) ∈ En we can argue

s IF = F (s) = F (t) = t IF J K J K where the middle equation holds since we have s and t represent the same morphism in L(Σ,E). We define the morphism part of I by I(η) = η[1] for η : F → G, and to check that this is a morphism of Σ-structures we have to show that

ηn F [n] [1] G[n]

fIF fIG η F [1] G commutes for all f ∈ Σn. This follows from naturality of η since fIF = F (f(~x)), n 6 fIG = G(f(~x)), and η[1] = η[n] . Clearly I preserves composition and identities, thus it is a well-defined func- tor. Furthermore we have

n n η[1] = θ[1] ⇒ η[n] = η[1] = θ[1] = θ[n] for η, θ : F → G which shows that I is faithful. To see that I is full, let F,G ∈ FP(L(Σ,E), C) and let g : F [1] → G[1] be a morphism of Σ-structures. Any η : F → G with η[1] = g must necessarily n satisfy η[n] = g , so we only have to show that this definition is natural, i.e. that gn F [n] G[n]

F (~t) G(~t) gm F [m] G[m] commutes for all t1 . . . tm ∈ Tn(Σ,E). Since any such square can be decomposed into n squares with exponent 1 in the lower row it is sufficient to consider the case m = 1, which is straightforward to prove by induction on the structure of t (using the fact that g is a morphism of Σ-structures).

6 For the last equation note that we generally have ηF × ηb = ηF ×G for natural transfor- mations between strictly finite-product preserving functors.

5 To show that I is essentially surjective, let A be a model of (Σ,E) in C. n We define a functor F : L(Σ,E) → C by F [n] = A and F (t1 . . . tn) = h t1 A,... tn Ai. We leave it to the reader to verify that F is well-defined andJ K preservesJ K finite products, and that IF = A. 

2 First-order logic

Definition 2.1 1.A first-order signature is a pair

fun rel fun rel Σ = (Σ , Σ ) = ((Σn )n∈N, (Σn )n∈N)

fun of families of sets, where the elements of Σn are called n-ary function 7 rel symbols , and the elements of Σn are called n-ary relation symbols. 2. The set of first-order formulas over a first-order signature Σ is inductively defined by the following grammar.

ϕ, ψ ::= t = u | R(t1 . . . tn) | > | ϕ∧ψ | ∃x . ϕ | ⊥ | ϕ∨ψ | ϕ ⇒ ψ | ∀x . ϕ

fun rel where t, u, t1 . . . tn ∈ T (Σ ) and R ∈ Σn . The set of Horn formulas is generated by the initial segment of inductive clauses up to ϕ ∧ ψ, regular formulas also allow ∃ and coherent formulas additionally permit ⊥ and ϕ ∨ ψ. 3. The set FV(ϕ) of free variables of a formula ϕ is defined in the usual way, where ∃ and ∀ bind variables. 4.A formula in context is an expression of the form

x1 . . . xn | ϕ

where x1 . . . xn is a list of variables, and FV(ϕ) ⊆ {x1 . . . xn}. 5.A sequent in context is an expression of the form

x1 . . . xn | ϕ1, . . . , ϕk ` ψ

where FV(ϕ1),..., FV(ϕk), FV(ψ) ⊆ {x1 . . . xn}.

6.A first-order theory is a pair T = (Σ,A) where Σ is a first-order signature, and A is a set of sequents consisting of formulas generated from Σ. The theory T is called a Horn/regular/coherent theory, if all formulas occurring in A are Horn/regular/coherent. ♦

7For algebraic theories we called them n-ary operations, but now I want to get the termi- nology consistent with [1, Def. D1.1.1].

6 2.1 Subobjects Given a first-order signature Σ and interpretations of function and relation symbols as functions and relations on a carrier set M, we can associate to each n formula (x1 . . . xn | ϕ) in n variables its interpretation ϕ ⊆ M which is the set of all valuations of the variables that make ϕ trueJ relativeK to the given interpretations of function and relation symbols. The set ϕ can formally be defined by induction on the structure of ϕ, and this is theJ K starting point of mathematical . In categorical logic we want to generalize this approach from the to other categories, and to do this we need a suitable categorical analogue of the notion of subset. The most obvious choice here (but not the only) is commonly called subobject:

Definition 2.2 Let C be a category.

1.A subobject of an object A in C is simply a monomorphism m : U  C. 2. Given subobjects U −→m A and V −→n A of an object A, we say that ‘m is included in n’ (and write m ≤ n), if there exists a map h : U → V such that nh = m. U h V m n A Since n is monic, such an h is necessarily unique and monic.

3. Since the inclusion relation on subobjects is reflexive and transitive, the subobjects of A form a preorder which we denote by Sub(A).

4. Sub(A) forms a full subcategory of the slice category C/A, and we denote the inclusion functor by I : Sub(A) ,→ C/A. 5. Since pullbacks of monos along arbitrary maps are monos, any morphism f : A → B in C induces a monotone map f ∗ : Sub(B) → Sub(A)

which maps any subobject of B to its pullback along f. We call f ∗ the reindexing map along f. ♦

Lemma 2.3 Let C be a category with pullbacks. Then all preorders Sub(A) have finite meets (a.k.a. greatest lower bounds), and all reindexing maps pre- serve finite meets.

7 Proof. Binary meets m ∧ n of subobjects m, n ∈ Sub(A) are given by pullback as indicated in the following diagram,

∗ • n m •

m∗n m∧n n

• m A and largest elements (“nullary meets”, denoted >) are given by id : A → A. Proofs of pullback preservation are left as an exercise. 

2.2 Regular categories

Definition 2.4 Let C be a category. 1. Given morphisms e : B → A and m : Y → X in C, we say that ‘e is left-orthogonal to m’ (or equivalently that ‘m is right-orthogonal to e’), if for every commutative square

g B Y e m f A X

there exists a unique h : A → Y making the two triangles in

g B Y e h m f A X

commute. 2.A cover (or strong epimorphism) is an epimorphism e : B → A that is left orthogonal to all monomorphisms. ♦

Definition 2.5 A regular category is a category R with finite limits in which 1. every morphism f : A → B factors

A f coim(f) U B im(f)

into a cover coim(f) followed by a mono im(f), and

8 2. covers are stable under pullback, i.e. if e is a cover in a pullback square

f 0 B0 B

e0 e f A0 A

then e0 is a cover as well. ♦

Regular categories come with a notion of structure-preserving functor that we introduce for later use:

Definition 2.6 A regular functor between regular categories Q, R is a functor F : Q → R which preserves finite limits and covers. ♦

When working with regular categories, we use the arrow symbol  for covers, and  for monomorphisms. Lemma 2.7 Let f : A → B in a regular category R. The reindexing map f ∗ has a left adjoint ∃f : Sub(A) → Sub(B), given by ∃f (m : U  A) = im(f ◦m).

coim(fm) • •

m ∃f (m)=im(fm) f A B

Proof. We have to show that im(fm) ≤ n iff m ≤ f ∗n for m ∈ Sub(A) and n ∈ Sub(B). Assume first that im(fm) ≤ n, i.e. there exists an h : V  X with nh = im(fn) as in the following diagram.

coim(fm) U V m im(fm) k h f A B

f ∗n n n∗f W X Then since the lower square is a pullback, there exists a unique k : U → W with (f ∗n)k = m and (n∗f)k = h coim(fm), which means that m ≤ f ∗n in Sub(A). Next assume that m ≤ f ∗n in Sub(A), i.e. there exists k : U → W with (f ∗n)k = m, and consider the following diagram.

coim(fm) U V h m (n∗f)k im(fm) k f A B

f ∗n n n∗f W X

9 By orthogonality of covers and monos applied to the red square there exists a morphism h : V → X making the triangles commute, which implies im(fm) ≤ n in Sub(B). 

Lemma 2.8 (Frobenius law) Let f : A → B in a regular category R. We have ∼ ∗ m ∧ ∃f n = ∃f (f m ∧ n) for all n ∈ Sub(A) and m ∈ Sub(B).

Proof. Consider the following diagram, where the dashed arrow h is induced by the of the pullback square on the right.

• •

h • • m ∗ ∗ f m f m∧n m∧∃f n A B f n coim(fn) ∃f n • •

The left, right and back sides of the cube are pullbacks, whence the front is a pullback by double application of the pullback lemma. This means that h is a ∗ ∗ cover, which exhibits m ∧ ∃f n as image of f ◦ (f m ∧ n). Since ∃f (f m ∧ n) is also the image of f ◦ (f ∗m ∧ n), we conclude that the two are isomorphic as subobjects of B.  Lemma 2.9 (Beck-Chevalley condition for ∃) If

P h A

k f g B C is a pullback square in a regular category R and m ∈ Sub(A), then ∗ ∼ ∗ g (∃f m) = ∃k(h m).

Proof. In the cube

• • u • • m h∗m ∃f m ∗ g (∃f m) P h A k g f B C

10 the dashed arrow is induced by the universal property of the front pullback square. Analogously to the previous proof, the top square is a pullback since ∗ bottom, front, and back are, and hence u is a cover. This exhibits g (∃f m) as image of k ◦ (h∗m), which implies the claimed isomorphism by uniqueness of image factorizations. 

2.3 Interpretation of regular logic in regular categories Interpretation of first-order formulas over a first-order signature Σ is done by structural recursion, and depending on the logical connectives appearing in the formula we have to require certain structure on the underlying category. To start we have to fix a structure M assigning interpretations to the symbols of the signature, and this can be done in any finite-limit category. Definition 2.10 Let Σ be a first-order signature.

1.A Σ-structure M in a finite-limit category C consists of the folloing data. • an object M ∈ C n fun • a morphism fM : M → M for every function symbol f ∈ Σn n rel • a subobject RM ∈ Sub(M ) for every relation symbol R ∈ Σn

2. Given Σ-structures M and N in C, a morphism of Σ-structures from M to N is a map g : M → N in C between the underlying objects such that

gn An Bn

fM fM g A B

fun commutes for all function symbols f ∈ Σn , and

n ∗ n RM ≤ (g ) (RN ) in Sub(M )

rel for all relation symbols R ∈ Σn .

Σ-structures and morphisms of Σ-structures form a category Σ-Str(C). ♦ Definition 2.11 (Interpretation of regular formulas) Let Σ be a first-order signature and let M be a Σ-structure in a regular category R. The interpretation

n x1 . . . xn | ϕ M ∈ Sub(M ) J K of regular formulas in context (x1 . . . xn | ϕ) over Σ is defined by structural recursion as follows.

∗ rel • ~x | R(t1 . . . tk) M = h ~x | t1 M ,..., ~x | tk M i (RM ) where R ∈ Σk J K J K J K ∗ • ~x | t = u M = h ~x | t M , ~x | u M i (δM ) J K J K J K

11 ~x | Γ ` ϕ ~x | Γ, ϕ ` ψ ~x | Γ, ϕ ` ϕ ~x | Γ ` ψ ~x | Γ, ϕ, ϕ ` ψ ~x | Γ ` ψ ~x | Γ, ϕ, ψ∆ ` θ ~x | Γ, ϕ ` ψ ~x | Γ, ϕ ` ψ ~x | Γ, ψ, ϕ, ∆ ` θ ~x | Γ ` ϕ ~x | Γ ` ψ ~x | Γ ` > ~x | Γ ` ϕ ∧ ψ ~x | Γ ` ϕ ~x | Γ ` ϕ ∧ ψ ~x | Γ ` ϕ ∧ ψ ~y | Γ[~t/~x] ` ϕ[~t/~x] ~x | Γ ` ϕ ~x | Γ ` ψ ~x,y | Γ, ϕ ` ψ ~x,y | Γ[y/z] ` ψ[y/z] ~x | Γ, ∃y . ϕ ` ψ ~x,y, z | Γ, y = z ` ψ

Table 1: Rules of regular logic

• ~x | > M = > J K • ~x | ϕ ∧ ψ M = ~x | ϕ M ∧ ~x | ψ M J K J K J K • ~x | ∃y . ϕ M = ∃p ~x,y | ϕ M J K J K In the second clause, δM is the diagonal hid, idi : M → M × M, and in the last clause, p : M n+1 × M → M n is the projection which forgets the last component. ♦

Lemma 2.12 (Substitution Lemma) Let Σ be a first-order signature and M a Σ-structure in a regular category R. Then we have ~ ∗ ~y | ϕ[t/~x] M = h ~y | u1 M ,..., ~y | un M i ~x | ϕ M J K J K J K J K for formulas (x1 . . . xn | ϕ) and terms (~y | u1),..., (~y | un).

Proof. By induction on ϕ.  Definition 2.13 Let Σ be a first-order signature and M a Σ-structure in a regular category R. We say that M satisfies a judgment (x1 . . . xn | ϕ1 . . . ϕk ` ψ) (or equivalently that the judgment is valid in M), if

n ~x | ϕ1 M ∧ · · · ∧ ~x | ϕk M ≤ ~x | ψ M in Sub(M ). J K J K J K We say that M is a model of a regular theory T = (Σ,A), if M satisfies all judgments in A. We denote by T-Mod(R) the full subcategory of Σ-Str(R) on models of T. ♦

12 Theorem 2.14 (Soundness) Let T = (Σ,A) be a regular theory, and let M be a model of T in a regular category R. If a judgment (~x | Γ ` ϕ) can be derived from the judgments in A using the rules of regular logic (Table 1), then it is satisfied in M.

Proof. By induction on the derivation. 

2.4 The syntactic category of a regular theory Syntactic categories of regular theories classify models of regular theories, in the same way that Lawvere theories classify models of algebraic theories. For the definition it is convenient to adapt the notion of α-equivalence familiar from languages with variable binding. Recall that α-equivalence means that we allow to rename bound variables, e.g.

(∀x . ϕ) =α (∀y . ϕ[y/x]) provided that y does not appear free in ϕ. For the definition of syntactic category we extend α-equivalence to the renaming of variables in contexts, i.e.

(~x | ϕ) =α (~y | ϕ[~y/~x]). Intuitively this makes sense since we can view contexts as ‘binding’ the variables they declare. Definition 2.15 The syntactic category reg of a regular theory = (Σ,A) is CT T defined as follows. • Objects are regular formulas-in-context (~x | α) over Σ. • Morphisms from (~x | α) to (~y | β) – where we assume that ~x and ~y are disjoint lists of variables, possibly after α-renaming – are formulas-in- context (~x,~y | φ) such that the judgments – (~x,~y | φ ` α ∧ β) – (~x,~y, y~0 | φ, φ[y~0/~y] ` ~y = y~0)8 – (~x | α ` ∃~y. φ) are derivable from A. We identify (~x,~y | φ) and (~x,~y | ψ) as morphisms from (~x | α) to (~y | β), if the judgments (~x,~y | φ ` ψ) and (~x,~y | ψ ` φ) are derivable from A. • The compositions of morphisms

(~x,~y| φ) (~y,~z| ψ) (~x | α) −−−−−→ (~y | β) −−−−−→ (~z | γ)

is given by (~x,~z| ∃~y. φ∧ψ) (~x | α) −−−−−−−−−→ (~z | γ).

8 ~0 0 0 ~y = y is short for y1 = y1 ∧ · · · ∧ yn = yn.

13 • The identity morphism of (~x | α) is given by

(~x,x~0| α ∧ ~x=~x0) (~x | α) −−−−−−−−−−→ (x~0 | α[~x0/~x]).

Here we replaced formula-in-context (~x | α) by the α-equivalent formula (x~0 | α[x~0/~x]) in the codomain, to make the contexts disjoint. ♦

The following theorems – for whose proofs we refer to [1, Sec. D1.4] – state the central properties of reg. CT Theorem 2.16 reg is a regular category. CT Theorem 2.17 (Completeness) reg contains a ‘generic model’ M of sat- CT T isfying precisely the regular formulas that can be derived from A. Thus, formulas that are satisfied by all models of T are derivable from A.

Theorem 2.18 For every regular category R there is an equivalence of cate- gories Reg( reg, ) ' -Mod( ), CT R T R where Reg( reg, ) is the category of regular functors F : reg → , and arbi- CT R CT R trary natural transformations between them.

2.5 The internal language of a regular category

The ‘internal language’ of a regular category R is a many-sorted first order language which contains sort symbols for all objects of R, function symbols for all morphisms of R, and relation symbols for all subobjects in R. Before defining it formally we have to introduce many-sorted signatures. Definition 2.19 A many-sorted first-order signature is a triple

fun rel fun rel  Σ = (Σ0, Σ , Σ ) = Σ0, (Σ~ )~ ∗ , (Σα )~ ∗ S,T S∈Σ0 ,T ∈Σ0 S∈Σ0 where

• elements of · · · ∈ Σ0 are called sorts, • elements of Σfun are called function symbols of arity S ×· · ·×S → T , S1...Sn,T 1 n • elements of Σrel are called relation symbols of arity S × · · · × S . ♦ S1...Sn 1 n To take the presence of multiple sorts into account, we have to adapt the defi- nitions of contexts, terms, and formulas. Definition 2.20 Let Σ be a many-sorted first-order signature.

1.A variable-context (over Σ) is a list x1 : S1, . . . , xn : Sn where Si ∈ Σ0 for 1 ≤ i ≤ n (in practice we will often omit the sort declarations when they are irrelevant or easily inferred).

14 2. Terms-in-context over Σ are inductively defined by the rules

~x : S~ | t1 : T1 . . . ~x : S~ | tk : Tk

x1 : S1, . . . , xn : Sn | xi : Si ~x : S~ | f(t1 . . . tk): U where in the first rule we assume 1 ≤ i ≤ n, and in the second rule f ∈ Σfun . T1...Tk,U 3. The definition of formulas-in-context is as before, except that we have to check for sorts for atomic formulas, i.e.

• if (~x : S~ | t1 : T1),..., (~x : S~ | tn : Tn) are terms in context and R ∈ Σrel then (~x : S~ | R(t . . . t )) is a formula in context, and T1...Tn 1 n • if (~x : S~ | t : T ), (~x : S~ | u : T ) are terms in context, then (~x : S~ | t = u) is a formula in context. ♦

Definition 2.21 Let Σ be a many-sorted first-order signature. A Σ-structure M in a finite-limit category C consists of

• objects SM ∈ C for all sorts S ∈ Σ0,

• morphisms fM : S1,M × · · · × Sn,M → TM for all function symbols f ∈ Σfun , and S1...Sn,T

• subobjects RM ∈ Sub(S1,M × · · · × Sn,M ) for all relation symbols R ∈ Σrel . ♦ S1...Sn Adaptation of interpretation of formulas from the single-sorted to the many- sorted case is straightforward. We can now define the signature of the internal language.

Definition 2.22 (Signature of the internal language) Let C be a finite- limit category. The many-sorted signature Σ(C) is defined as follows.

• Σ(C)0 = obj(C) • Σ( )fun = hom(A × · · · × A ,B) C A1...An,B 1 n • Σ( )rel = Sub(A × · · · × A ) ♦ C A1...An 1 n

This signature comes with a canonical structure in C: Definition 2.23 Let C be a finite-limit category. The Σ(C)-structure M(C) in C is given as follows.

• AM(C) = A for A ∈ Σ(C)0 • f = f for f ∈ Σ( )fun M(C) C A1...An,B

15 • R = R for R ∈ Σ( )rel ♦ M(C) C A1...An The point about defining this signature and interpretation is that we can use logical reasoning in category theoretic proofs. To this end we introduce the following terminology.

Definition 2.24 Let R be a regular category. We say that a judgment (~x | Γ ` ϕ) consisting of regular formulas over Σ(R) holds in R, if the structure M(R) satisfies the judgment. ♦

We will demonstrate the use of the internal language in some examples.

Definition 2.25 Let f : A → B in a regular category C. The graph of f is the subobject hid,fi Grf = (A −−−→ A × B) ∈ Sub(A × B). ♦

Lemma 2.26 Let f : A → B in a regular category R. Then 1. (a, a0 | fa = fa0 ` a = a0) holds in R iff f is a monomorphism, ∼ 2. Grf = a, b | fa = b J K 3. (b | ` ∃a . fa = b) holds in R iff f is a cover. Proof. For the first claim, note that we have a, a0 | fa = fa0 = ker(f) and 0 0 a, a | a = a = δA It can be shown diagrammaticallyJ thatK a morphism is monicJ iff its kernelK is contained in the diagonal. The second claim follows since

f A B

Grf δB f×B A × B B × B is a pullback. 3rd: TODO  0 0 Lemma 2.27 Let f : A → B in R. The judgments (a, b, b | Grf (a, b), Grf (a, b ) ` 0 b = b ) and (a | ` ∃b . Grf (a, b)) hold in R Proof. TODO  This shows that graphs are ‘functional relations’. Conversely we have the fol- lowing.

Lemma 2.28 Let R ∈ Sub(A × B) in a regular category R. If the judgments (a, b, b0 | R(a, b),R(a, b0) ` b = b0) and (a | ` ∃b . R(a, b)) hold in R, then there ∼ exists a morphism f : A → B with R = Grf .

Proof. TODO 

16 2.6 Coherent logic and coherent categories Coherent logic is the extension of regular logic by disjunction ∨ and falsity ⊥, subject to the rules

~x | Γ, ϕ ` θ ~x | Γ, ψ ` θ ~x | Γ, ϕ ∨ ψ ` θ ~x | Γ, ϕ ∨ ψ ` θ ~x | Γ, ϕ ` θ (2.1) ~x | Γ, ϕ ∨ ψ ` θ ~x | Γ, ⊥ ` θ ~x | Γ, ψ ` θ extending the rules of regular logic in Table1. Coherent logic can be modeled in coherent categories, which are defined as follows.

Definition 2.29 A coherent category is a regular category R in which all sub- object lattices Sub(A) have finite joins (denoted by ⊥ for the least element and ∨ for binary joins), and all inverse image maps f ∗ : Sub(A) → Sub(B) for f : B → A preserve them. ♦

The interpretation of regular formulas (Def. 2.11) is extended to coherent for- mulas via the following clauses. • ~x | ⊥ = ⊥ J K • ~x | ϕ ∨ ψ = ~x | ϕ ∨ ~x | ψ J K J K J K To show that this interpretation is sound w.r.t. the rules (2.1), we need the following lemma which says that subobject lattices in coherent categories are distributive.

Lemma 2.30 We have m ∧ (n ∨ u) =∼ (m ∧ n) ∨ (m ∧ u) for m, n, u ∈ Sub(A) in a coherent category R. Proof. We have

m ∧ (n ∨ u) =∼ m ◦ m∗(n ∨ u) =∼ m ◦ (m∗(n) ∨ m∗(u)) m∗(−) preserves ∨ by assumption =∼ m ◦ m∗(n) ∨ m ◦ m∗(u) m ◦ (−) preserves ∨ as left adjoint to m∗(−) ∼ (m ∧ n) ∨ (m ∧ u) =  Using this lemma, we can show that the interpretation of coherent logic in coherent categories is sound w.r.t. the given rules, and we can define theories and models just as for regular logic. The construction of syntactic categories and internal language also carries over directly.

17 2.7 First order logic and Heyting categories To obtain full first order logic we have to introduce the connectives ⇒ and ∀, which come with the following rules. ~x,y | Γ ` ϕ ~x | Γ, ϕ ` ψ ~x | Γ ` ∀y . ϕ ~x | Γ ` ϕ ⇒ ψ These rules axiomatize intuitionistic first order logic – to obtain classical first order logic, we have to furthermore postulate either of the following rules (which are equivalent in presence of the other rules) ~x | Γ ` ¬¬ϕ ~x | Γ, ¬ϕ ` ϕ ~x | Γ ` ϕ ~x | Γ ` ϕ ~x | Γ ` ϕ ∨ ¬ϕ where ¬ϕ ≡ ϕ ⇒ ⊥ is the usual encoding of negation in intuitionistic logic. The categorical counterpart of intuitionistic first order logic is given by Heyt- ing categories, defined as follows.

Definition 2.31 A Heyting category is a coherent category H in which for every f : B → A, the reindexing map f ∗ : Sub(A) → Sub(B) has a right adjoint ∀f : Sub(B) → Sub(A). ♦ We have the following lemmas. Lemma 2.32 (Beck-Chevalley condition for ∀) If

P h A

k f g B C is a pullback square in a Heyting category H and m ∈ Sub(A), then ∗ ∼ ∗ g ∀f m = ∀kh m in Sub(B). Proof. Using the Beck-Chevalley condition for ∃ (Lem. 2.9) we have ∗ n ≤ ∀kh m k∗n ≤ h∗m ∗ ∃hk n ≤ m ∗ f ∃gn ≤ m

∃gn ≤ ∀f m ∗ n ≤ g ∀f m for arbitary n ∈ Sub(B), from which the claim follows by the Yoneda lemma.  Definition 2.33 A Heyting algebra is a preorder (H, ≤) with finite meets and joins and a binary operation (− ⇒ −): H ×H → H (called Heyting application) satisfying a ∧ b ≤ c iff a ≤ b ⇒ c for a, b, c ∈ H.

18 (This condition determines the Heyting implication operation uniquely, and im- plies that ⇒ is antimonotone in its first variable, and monotone in the second.)♦

In other words, a Heyting algebra is a posetal cartesian closed category with coproducts.

Lemma 2.34 The subobject lattices Sub(A) of a Heyting category H are Heyt- ing algebras, and the reindexing maps preserve Heyting application.

Proof. For n, u ∈ Sub(A) we set

∗ n ⇒ u := ∀nn u.

Then we have m ∧ n ≤ u n ◦ n∗m ≤ u n∗m ≤ n∗u ∗ m ≤ ∀nn u for arbitary m ∈ Sub(A), which shows that Sub(A) is a Heyting algebra. Now let f : B → A and consider the pullback square

g Q P

m n f B A of f and n. We have

f ∗(n ⇒ u) ∼ ∗ ∗ = f ∀nn u ∼ ∗ ∗ = ∀mg n u ∼ ∗ ∗ = ∀mm f u =∼ m ⇒ f ∗u =∼ f ∗n ⇒ f ∗u which shows that Heyting implication is stable under reindexing.  Now the interpretation of formulas extends to full first order logic with the clauses • ~x | ϕ ⇒ ψ = ~x | ϕ ⇒ ~x | ψ J K J K J K • ~x | ∀y . ϕ = ∀p ~x,y | ϕ J K J K where in the second clause, p is the appropriate projection (just as for ∃). We define structures, theories, and models just as in the regular and coherent case and get analogous soundness and completeness results. The internal language also works the same way.

19 3 Cartesian closed categories and the λ-calculus

Definition 3.1 A category C with finite products is called cartesian closed, if either of the following equivalent conditions hold.

1. For all B ∈ B, the functor (− × B): C → C has a right adjoint. B B B 2. For all B,C ∈ C there exists an object C and an arrow εC : C ×B → C such that for every f : A × B → C there exists a unique Λf : A → CB B with εC ◦ (Λ × B) = f.

Λf A CB

Λf×B A × B CB × B

B εC f C ♦

c Definition 3.2 A λ-signature is a pair Σ = (Σ0, Σ ) where

• Σ0 is a set of base-types, generating a set τ(Σ0) of types via the grammar

A, B ::= X | 1 | A × B | A ⇒ B (X ∈ Σ0)

c c • Σ = (ΣA)A∈τ(Σ0) is a family of sets of typed constants. ♦

Definition 3.3 Given a λ-signature Σ, a Σ-structure M in a cartesian closed category C consists is given by the following data:

• an assignment of objects XM ∈ C to base types X ∈ Σ0, extending to an interpretation of types via the inductive clauses

– X M = XM for X ∈ Σ0 J K – 1 M = 1 J K – A × B M = A M × B M J K J K J K A M – A ⇒ B M = B JM K J K J K c • for each A ∈ τ(Σ0) and c ∈ ΣA an arrow cM : 1 → A M ♦ J K The typing-rules in Table2 generate the well-typed terms-in-context over a fixed λ-signature Σ. These terms-in-context (a.k.a. typing judgments) are of the form ∆ | t : B, where ∆ ≡ x1 : A1 ··· xn : An is a context of typed variables as usual, and A1 ··· An,B ∈ τ(Σ0). Given a λ-signature Σ and a Σ-structure M in a cartesian closed category C, we inductively define the interpretation ∆ M of contexts ∆ ≡ x1 : A1 ··· xn : An by J K

20 c c ∈ ΣA x1 : A1 . . . xn : An | xi : Ai ∆ | ? : 1 ∆ | c : A ∆, x : A | t : B ∆ | t : A ⇒ B ∆ | u : A ∆ | λx . t : A ⇒ B ∆ | tu : B ∆ | t : A ∆ | u : B ∆ | t : A × B ∆ | t : A × B ∆ | (t, u): A × B ∆ | fst(t): A ∆ | snd(t): B

Table 2: Typing rules for the simply typed λ-calculus.

•  M = 1 (empty context) J K • ∆, x : A M = ∆ M × A M J K J K J K The interpretation

∆ | t : A M : ∆ M → A M J K J K J K of well-typed terms ∆ | t : A is then given by the following inductive clauses.

• x1 : A1 . . . xn : An | xi : Ai M = pi J K ! • ∆ | ∗ : 1 M = ( ∆ M −→ 1) J K J K ! cM c • ∆ | c : A M = ( ∆ M −→ 1 −−→ A M ) for c ∈ ΣA J K J K J K • ∆ | λx . t : A ⇒ B M = Λ( ∆, : A | t : B M ) J K J K A M • ∆ | tu : B = εJ K ◦ h ∆ | t : A ⇒ B , ∆ | u : A i M B M M M J K J K J K J K

• ∆ | (t, u): A × B M = h ∆ | t : A M , ∆ | u : B M i J K J K J K • ∆ | fst(t): A M = p1 ◦ ∆ | t : A × B M J K J K • ∆ | snd(t): B M = p2 ◦ ∆ | t : A × B M J K J K Lemma 3.4 (Substitution Lemma) Given a λ-signature Σ and a Σ-structure M in a cartesian closed category C, we have ~ ∆ | u[t/~x]: B M = x1 : A1 . . . xn : An | u M ◦ h ∆ | ti M | 1 ≤ i ≤ ni J K J K J K for terms-in-context ∆ | t : A (1 ≤ i ≤ n) and x : A . . . x : A | u : B. i i 1 1 n n  Definition 3.5 Given a λ-signature Σ, a Σ-structure M in a cartesian closed category C, and terms-in-context ∆ | t : A and ∆ | u : A, we write

∆ | t =M u : A as a shorthand for ∆ | t : A M = ∆ | u : A M . ♦ J K J K

21 Theorem 3.6 Given a λ-signature Σ and a Σ-structure M in a cartesian closed category C, the relation =M on well-typed terms is closed under the following rules (written without types and contexts):

• s =M t ⇒ s[~u/~x] =M t[~u/~x]

• s =M t ⇒ λx . s =M λx . t

0 0 0 0 • s =M s , t =M t ⇒ st =M s t

0 0 0 0 • s =M s , t =M t ⇒ (s, t) =M (s , t )

• s =M t ⇒ fst(s) =M fst(t), snd(s) =M snd(t)

• t =M ?

• (λx . t)x =M t

• (λx . tx) =M t (x∈ / FV(t))

• fst(t, u) =M t

• snd(t, u) =M u

• (fst(t), snd(t)) =M t

Definition 3.7 A λ-theory is a pair T = (Σ,E) where Σ is a λ-signature, and E is a set of equations ∆ | t = u : A in context. A model of a λ-theory T = (Σ,E) in a cartesian closed category C is a Σ- structure M in C such that ∆ | t =M u : A for all equations ∆ | t = u : A in E. ♦

3.1 The internal language of a cartesian closed category As for regular categories (Section 2.5), the internal language of cartesian closed category C is given by a maximal choice of signature together with a canonical interpretation. More precisely, we have the following.

Definition 3.8 Let C be a cartesian closed category. The λ-signature Σ(C) = c (Σ(C)0, Σ(C) ) and the Σ(C)-structure M(C) are mutually inductively defined as follows.

• Σ(C)0 = obj(C) c • Σ(C)A = hom(1, A M( )) for A ∈ τ(Σ(C)0) J K C

• XM(C) = X for all X ∈ Σ(C)0 c • fM(C) = f for all A ∈ τ(Σ(C)0) and f ∈ Σ(C)A ♦ TODO: syntactic categories, completeness

22 4 and higher order logic

Definition 4.1 A is a category E which has

1. finite limits, 2. exponentials (i.e. E is cartesian closed), and

3.a subobject classifier, i.e. a pointed object 1 −→t Ω such that for every object m A and subobject U  A there exists a unique χm : A → Ω making

U 1

m t χ A m Ω

a pullback. ♦

In condition 3 we call χm the classifying map of m. The condition on the sub- object classifier says that for every A there is a bijection between isomorphism classes of subobjects of A and arrows A → Ω. This observation leads to an alternative characterization of toposes. Lemma 4.2 A category E with finite limits and exponentials is a topos, iff the functor |Sub| : Eop → Set, which sends each A ∈ E to the set of isomorphism classes of subobjects9 of A, is representable.

Proof. If E is a topos, then

∗ ˆt : hom(−, Ω) → |Sub|, ˆtA(f) = f t is a natural isomorphism. Conversely, assume that |Sub| is representable, i.e. there exists an object Ω and a subobject m : U  Ω such that the induced natural transformation (via Yoneda) mˆ : |Sub| → hom(−, Ω) is a natural isomorphism. To show that m : U  Ω constitutes a subobject classifier it suffices to check that U is terminal. To see this let A ∈ E and consider the composition

(−◦m) ˆ hom(A, U) hom(A, Ω) −→tA |Sub|(A).  ∼=

∗ ∼ An arrow f : A → Ω factors through m precisely if f t = idA, i.e. ˆtA(f) = idA, and by this condition f is uniquely determined since ˆt is a natural iso.  9Thus, |Sub|(A) is the set of isomorphism classes of the preorder Sub(A) of subobjects introduced in 2.2-3.

23 4.1 Presheaf toposes

We already know that presheaf categories Cb on small categories C have finite limits and exponentials. To show that they are toposes it remains to find a subobject classifier. Its definition will be derived via the Yoneda lemma, making use of the fact that we have canonical representatives of subobjects in presheaf toposes, given by subfunctors: Definition 4.3 Let C be a small category, and F Cop → Set a presheaf. A subfunctor of F is a family (U(C) ⊆ F (C))C∈C of subsets of the values of F such that for all f : C → D in C and x ∈ U(D) we have F (f)(x) ∈ U(C). ♦ op Any subfunctor (U(C) ⊆ F (C))C∈C of a presheaf F : C → Set gives rise to a presheaf U : Cop → Set together with a monic natural transformation ιU : U  F where U(f) = F (f)|U(D) for f : C → D and the components of ιU are subset inclusions. Conversely, given a subobject η : G → F of F , we can define a subfunctor U by setting

U(C) = im(ηC ) = {η(x) | x ∈ G(C)} ⊆ F (C) for C ∈ C. It is easy to see that these constructions establish a bijection between |Sub|(F ) and the subfunctors of F , i.e. the equivalence classes in |Sub|(F ) each contain a unique element whose components are subset inclusions. Of special interest in this section are subfunctors of representable functors

op YC = hom(−,C): C → Set for objects C ∈ C. By definition, a subfunctor of YC is a family

( SD ⊆ hom(D,C))D∈C 0 of sets of arrows satisfying hk ∈ SD0 whenever h ∈ SD and k : D → D in C. By taking the union of the fibers of such a subfunctor, we arrive at the notion of a sieve on C. Definition 4.4 Given an object C in a small category C,A sieve on C is a set S ⊆ mor(C) of morphisms such that cod(f) = C for all f ∈ S, and hf ∈ S whenever (f : D → C) ∈ S and h : D0 → D in C. We denote the set of sieves on C by Siev(C). ♦ Since sieves are just reformulations of subfunctors of YC, we do in particular have a bijection between |Sub|(YC) and Siev(C). Putting things together, we derive the formula for the subobject classifier Ω: Cop → Set in Cb as follows. ∼ Ω(C) = Nat(YC, Ω) by the Yoneda lemma =∼ |Sub|(YC) by the universal property of Ω =∼ Siev(C). This gives us the object part of Ω, and extending it to morphisms in the obvious way, we obtain the following description of the subobject classifier in Cb.

24 Table 3: Rules of equational higher order logic

Theorem 4.5 For small C, the presheaf category Cb has a subobject classifier Ω: Cop → Set given by Ω(C) = Siev(C) Ω(f : C → D)(S ∈ Siev(D)) = {h ∈ mor(C) | cod(h) = C, fh ∈ S}.

Thus is a topos. Cb 

4.2 Interpreting higher order logic in toposes In the following we introduce a system of higher order logic as a kind of sequent calculus on certain typed λ-terms. These terms are defined over λ-signatures containing special symbols, called higher order signatures.

c Definition 4.6 A higher order signature is a λ-signature Σ = (Σ0, Σ ) (Def 3.2) where

• there is a special base type Ω ∈ Σ0, and

c • for every A ∈ τ(Σ0) there is a constant (=A) ∈ ΣA×A⇒Ω. ♦ The semantic counterpart of higher order signatures are higher order Σ-structures. Before giving the precise definition we introduce a terminology and notation that will be handy in the following. Definition 4.7 For f : A → B in a topos E we call morphism

p2 f A pfq = Λ(1 × A −→ A −→ B) : 1 → B the name of f. ♦

Definition 4.8 If Σ is a higher order signature, a higher order Σ-structure in a topos E is a Σ-structure M in E such that

• Ω M = Ω J K • for A ∈ τ(Σ0) we have

A × A (=A) = eq : 1 → Ω M M , M p A M q J K J K J K J K where eqB : B × B → Ω is the classifying map of δB : B  B × B for B ∈ B. ♦ Grammatically, higher order logic can be understood as a kind of logic where, contrary to first order logic, terms and formulas are defined mutually inductively. While in first order logic terms are defined first, and formulas are then defined

25 incorporating the terms, in higher order logic terms can be defined out of for- mulas, typically using a construct like ‘set comprehension’, which forms a term {x : A | ϕ} : PA of power type out of a formula ϕ possibly containing a free variable x : A. The ‘equational higher order logic’ which we use here is a simplified im- plementation of this idea which gets around two mutually inductively defined syntactic classes by identifying formulas with terms of a type Ω of propositions. Moreover, power types are not primitive but defined using function space and Ω as PA ≡ A → Ω, thus intuitively λ-abstractions (λx : A . ϕ) over terms ϕ of type Ω can be under- stood as set comprehensions. Following the principle that terms of type Ω are formulas, the rules of equa- tional higher order logic – given in Table3 – are defined as derivation rules on judgments (~x | ϕ1 . . . ϕn ` ψ) consisting of terms (~x | ϕ1 : Ω),..., (~x | ϕn : Ω), (~x | ψ : Ω).

5 Existence and choice in toposes

Definition 5.1 An object U in a finite-limit category C is called subterminal, if its terminal projection U → 1 is a monomorphism. ♦

Definition 5.2 Let E be a topos.

1. We say that E satisfies the axiom of choice (AC), if every epimorphism e : B → A splits (i.e. has a right inverse). 2. We say that E satisfies ‘supports split’ (SS), if all epis B → U split, where U is subterminal. ♦

References

[1] P.T. Johnstone. Sketches of an elephant: a topos theory compendium. Vol. 2, volume 44 of Oxford Logic Guides. The Clarendon Press Oxford University Press, Oxford, 2002.

26