A novel approach to giving an interpretation of logic inside category theory. This work has been developed as part of my sabbatical Marie Curie fellowship in Leeds.
Presented at the Logic Seminar, School of Mathematics, University of Leeds (2012).
CORCON2014: Does programming really need data structures?
Intuitionistic First-Order Logic: Categorical semantics via the Curry-Howard isomorphism
1. Intuitionistic First-Order Logic
Categorical semantics via the Curry-Howard isomorphism
Marco Benini
M.Benini@leeds.ac.uk
Department of Pure Mathematics
University of Leeds
14th November 2012
2. Introduction
An observation: in part D of P. Johnstone’s Sketches of an Elephant, there
is a categorical semantics for the simply typed λ-calculus. In the very same
class of models, one can give a semantics to the corresponding fragment of
propositional logic.
The problem:
is it possible to do the same for full first-order intuitionistic logic?
2 of 32
3. Introduction
Johstone’s account comes from Lambek and Scott’s Introduction to
Higher-Order Categorical Logic. The considered propositional logic is
minimal logic limited to conjunction and implication.
In Taylor, Practical Foundation of Mathematics, one finds that the treatment
of disjunction requires distributive categories in order to follow the same
pattern as the previous works.
To my knowledge, no categorical semantics appears in literature which
models the full first-order intuitionistic logic AND the corresponding
λ-calculus.
3 of 32
4. The λ-calculus
Definition 1 (Lambda signature)
A λ-signature Σ = 〈S , F , R , Ax〉 is a structure where
1. 〈S , F , R 〉 is a logical signature, i.e.,
1.1 a set S of sort symbols;
1.2 a set F of function symbols, each one decorated as f : s1 × · · · × sn → s0 ,
with s0 , . . . , sn ∈ S;
1.3 a set R of relation symbols, each one decorated as r : s1 × · · · × sn , with
s1 , . . . , sn ∈ S;
2. Ax is the set of axiom symbols, each one decorated as a : A → B where
A, B ∈ λTypes(Σ) and FV(A → B ) = .
We call LTerms(Σ) the collection of logical terms constructed from the
signature Σ, assuming to have a denumerable set of variables Vs for each
s ∈ S.
4 of 32
5. The λ-calculus
Definition 2 (Lambda type)
Fixed a λ-signature Σ, the λ-types on Σ are inductively defined along with
their free variables as follows:
1. 0, 1 ∈ λTypes(Σ) and FV(0) = FV(1) = ;
2. if p : s1 × · · · × sn ∈ R and t1 : s1 , . . . , tn : sn ∈ LTerms(Σ), then
p(t1 , . . . , tn ) ∈ λTypes(Σ) and FV(p(t1 , . . . , tn )) = n=1 FV(ti : si );
i
3. if A, B ∈ λTypes(Σ) then A × B , A + B , A → B ∈ λTypes(Σ) and
FV(A × B ) = FV(A + B ) = FV(A → B ) = FV(A) ∪ FV(B );
4. if x ∈ Vs and A ∈ λTypes(Σ) then ∀x : s. A, ∃x : s. A ∈ λTypes(Σ) and
FV(∀x : s. A) = FV(∃x : s. A) = FV(A) {x : s}.
5 of 32
6. The λ-calculus
Definition 3 (Lambda term)
Fixed a λ-signature Σ = 〈S , F , R , Ax〉, for each type t ∈ λTypes(Σ), we
assume there is a denumerable set Wt of (typed) variables.
A λ-term is inductively defined together with its free variables as:
1. if x ∈ Wt then x : t ∈ λTerms(Σ) and FV(x : t ) = {x : t };
2. if f : A → B ∈ Ax and t : A ∈ λTerms(Σ) then f (t ): B ∈ λTerms(Σ) and
FV(f (t ): B ) = FV(t : A);
3. if s : A, t : B ∈ λTerms(Σ) then 〈s, t 〉 : A × B ∈ λTerms(Σ) and
FV(〈s, t 〉 : A × B ) = FV(s : A) ∪ FV(t : B );
4. if t : A × B ∈ λTypes(Σ) then fst(t ): A ∈ λTerms(Σ),
snd(t ): B ∈ λTerms(Σ) and
FV(fst(t ): A) = FV(snd(t ): B ) = FV(t : A × B ); →
6 of 32
7. The λ-calculus
→ (Lambda term)
5. if t : A ∈ λTerms(Σ) then inlB (t ): A + B ∈ λTerms(Σ),
inrB (t ): B + A ∈ λTerms(Σ) and
FV(inlB (t ): A + B ) = FV(inrB (t ): B + A) = FV(t : A);
6. if s : A + B , t : A → C , r : B → C ∈ λTerms(Σ) then
when(s, t , r ): C ∈ λTerms(Σ) and
FV(when(s, t , r ): C ) = FV(s : A + B ) ∪ FV(t : A → C ) ∪ FV(r : B → C );
7. if x ∈ WA and t : B ∈ λTerms(Σ) then (λx : A. t ): A → B ∈ λTerms(Σ) and
FV((λx : A. t ): A → B ) = FV(t : B ) {x : A};
8. if s : A → B , t : A ∈ λTerms(Σ) then s · t : B ∈ λTerms(Σ) and
FV(s · t : B ) = FV(s : A → B ) ∪ FV(t : A);
9. ∗ : 1 ∈ λTerms(Σ) and FV(∗ : 1) = ;
10. FA : 0 → A ∈ λTerms(Σ) and FV(FA : 0 → A) = ; →
7 of 32
8. The λ-calculus
→ (Lambda term)
11. if x ∈ Vs and t : A ∈ λTerms(Σ) where x : s ∈ FV∗ (t : A), then
allI(λx : s. t ):(∀x : s. A) ∈ λTerms(Σ) and
FV(allI(λx : s. t ):(∀x : s. A)) = FV(t : A);
12. if t :(∀x : s. A) ∈ λTerms(Σ) and r : s ∈ LTerms(Σ) then
allE(t , r ):(A[r /x ]) ∈ λTerms(Σ) and
FV(allE(t , r ):(A[r /x ])) = FV(t :(∀x : s. A));
13. if x ∈ Vs , r : s ∈ LTerms(Σ) and t :(A[r /x ]) ∈ λTerms(Σ) then
exIx (t ):(∃x : s. A) ∈ λTerms(Σ) and
FV(exIx (t ):(∃x : s. A)) = FV(t :(A[r /x ]));
14. if t :(∃x : s. A), ∈ λTerms(Σ) and r : A → B ∈ λTerms(Σ) where
x : s ∈ FV∗ (r : A → B ), then exE(t , (λx : s. r )): B ∈ λTerms(Σ) and
FV(exE(t , (λx : s. r )): B ) = FV(t :(∃x : s. A)) ∪ FV(r : A → B ).
In the previous definition, x : s ∈ FV∗ (t : A) if and only if there is
r ∈ λTypes(Σ) and y ∈ Wr such that x : s ∈ FV(r ) and y : r ∈ FV(t : A).
8 of 32
9. The λ-calculus
Definition 4 (Lambda calculus)
A derivation is inductively defined by the following inference rules, whose
antecedents and consequents are equalities-in-context within a fixed
λ-signature Σ:
(eq0 ) x : A. s =C t y : B . s[r1 /x1 , . . . , rn /xn ] =C t [r1 /x1 , . . . , rn /xn ] where, for
any 1 ≤ i ≤ n, y : B . ri : Ai is a term-in-context;
(x : A. s1 =B1 t1 )
.
.
(eq1 ) . x : A. r [s/y ] =C r [t /y ];
(x : A. sm =Bm tm )
(eq2 ) x : A. x =A x;
(eq3 ) x : A, y : A. x =A y x : A, y : A. y =A x;
(x : A, y : A, z : A. x =A y )
(eq4 ) x : A, y : A, z : A. x =A z;
(x : A, y : A, z : A. y =A z )
→
9 of 32
10. The λ-calculus
→ (Lambda calculus)
(eq5 ) x : A. s =C t x : A. (λy : B . s) =B →C (λy : B . t );
(eq6 ) x : A. r =C t x : A. allI(λy : s. r ) =(∀y : s. C ) allI(λy : s. t );
(eq7 ) x : A. u =C v x : A. exE(t , (λy : s. u )) =C exE(t , (λy : s. v ));
(×0 ) x : 1. x =1 ∗;
(×1 ) x : A, y : B . fst(〈x , y 〉) =A x;
(×2 ) x : A, y : B . snd(〈x , y 〉) =B y ;
(×3 ) z : A × B . 〈fst(z ), snd(z )〉 =A×B z;
(+0 ) x : A. when(inlB (a), t , s) =C t · a;
(+1 ) x : A. when(inrD (b), t , s) =C s · b;
→
10 of 32
11. The λ-calculus
→ (Lambda calculus)
(+2 ) when y : A1 ∈ FV(x1 : A1 + A2 ) ∪ FV(x3 : B1 → C ) ∪ FV(x4 : B2 → C ) and
y : A2 ∈ FV(x2 : A1 + A2 ) ∪ FV(x3 : B1 → C ) ∪ FV(x4 : B2 → C )
x0 : A1 + A2 , x1 : A1 → (B1 + B2 ), x2 : A2 → (B1 + B2 ),
x3 : B1 → C , x4 : B2 → C .
when(when(x0 , x1 , x2 ), x3 , x4 ) =C
=C when(x0 , (λy : A1 . when(x1 · y , x3 , x4 )),
(λy : A2 . when(x2 · y , x3 , x4 ))) ;
(+3 ) x : A, y : 0. FA ·y =A x;
(→0 ) x : A. (λy : C . s) · t =B s[t /y ];
(→1 ) x : A. (λy : C . t · y ) =C →B t where y : C ∈ FV(t : C → B );
(∀0 ) x : A. allE(allI(λz : s. t ), r ) =B [r /z ] t [r /z ];
(∀1 ) x : A. allE(u , r ) =B allE(v , r ) r : s∈LTerms(Σ) x : A. u =(∀z : s. B ) v ;
→
11 of 32
12. The λ-calculus
→ (Lambda calculus)
(∃0 ) x : A. exE(exIz (t ), (λz : s. v )) =B (v [r /z ]) · t;
(∃1 ) x : A. exE(u , (λz : s. r )) =B exE(u , (λz : s. t )) x : A. r =C →B t where
FV(r : C → B ) = FV(t : C → B );
(∃2 ) v :(∃y : s. A). w =B exE(v , (λy : s. (λz : A. w [exIy (z )/v ]))) with
z : A ∈ FV(w : B );
(∃3 ) x : A. exE(exE(a, (λy : s. (λz : D . b))), (λy : s. c )) =C
=C exE(a, (λy : s. (λz : D . exE(b, (λy : s. c )))));
(∃4 ) x : A. exE(a, (λy : s. (λz : C . b[exIy (z )/w ]))) =B b[a/w ] with
z : C ∈ FV(b : B ).
12 of 32
13. Semantics
Definition 5 (Logically distributive category)
Fixed a λ-signature Σ = 〈S , F , R , Ax〉, a category C together with a map
M : λTypes(Σ) → Obj C is said to be logically distributive if it satisfies the
following seven conditions:
1. C has finite products;
2. C has finite co-products;
3. C has exponentiation;
4. C is distributive, i.e., for every A, B , C ∈ Obj C, the arrow
∆ = [1A × ι1 , 1A × ι2 ]: (A × B ) + (A × C ) → A × (B + C ) has an inverse,
where [_, _] is the co-universal arrow of the (A × B ) + (A × C ) co-product,
_ × _ is the product arrow, 1A is the identity arrow on A, and
ι1 : B → B + C, ι2 : C → B + C are the canonical injections of the B + C
co-product.
→
13 of 32
14. Semantics
→ (Logically distributive category)
For every s ∈ S, A ∈ λTypes(Σ), and x ∈ Vs , let
ΣA (x : s): LTerms(Σ)(s) → C be the functor from the discrete category
LTerms(Σ)(s) = t : s | t : s ∈ LTerms(Σ) to C defined by t : s → M (A[t /x ]).
Also, for every s ∈ S, A ∈ λTypes(Σ), and x ∈ Vs , let C(∀x : s. A) be the
subcategory of C whose objects are the vertices of the cones on ΣA (x : s)
such that they are of the form MB for some B ∈ λTypes(Σ) and
x : s ∈ FV(B ). Moreover, the arrows of C(∀x : s. A) , apart identities, are the
arrows in the category of cones over ΣA (x : s) having the objects of
C(∀x : s. A) as domain and M (∀x : s. A) as co-domain. →
14 of 32
15. Semantics
→ (Logically distributive category)
Finally, for every s ∈ S, A ∈ λTypes(Σ), and x ∈ Vs , let C(∃x : s. A) be the
subcategory of C whose objects are the vertices of the co-cones on
ΣA (x : s) such that they are of the form MB for some B ∈ λTypes(Σ) and
x : s ∈ FV(B ). Moreover, the arrows of C(∃x : s. A) , apart identities, are the
arrows in the category of co-cones over ΣA (x : s) having the objects of
C(∃x : s. A) as co-domain and M (∃x : s. A) as domain.
5. All the subcategories C(∀x : s. A) have terminal objects, and all the
subcategories C(∃x : s. A) have initial objects;
→
15 of 32
16. Semantics
→ (Logically distributive category)
6. The M map is such that
6.1 M (0) = 0, the initial object of C;
6.2 M (1) = 1, the terminal object of C;
6.3 M (A × B ) = MA × MB, the binary product in C;
6.4 M (A + B ) = MA + MB, the binary co-prooduct in C;
6.5 M (A → B ) = MB MA , the exponential object in C;
6.6 M (∀x : s. A) is the terminal object in the subcategory C(∀x : s. A) ;
6.7 M (∃x : s. A) is the initial object in the subcategory C(∃x : s. A) ;
7. For every x ∈ Vs , A, B ∈ λTypes(Σ) with x : s ∈ FV(A), MA × M (∃x : s. B )
is an object of C(∃x : s. A×B ) since, if M (∃x : s. B ), {δt }t : s∈LTerms(Σ) is a
co-cone over ΣB (x : s), and there is one by condition (5), then
MA × M (∃x : s. B ), {1MA ×δt }t : s∈LTerms(Σ) is a co-cone over ΣA×B (x : s).
Thus, there is a unique arrow !: M (∃x : s. A × B ) → MA × M (∃x : s. B ) in
C(∃x : s. A×B ) . Our last condition requires that the arrow ! has an inverse.
16 of 32
17. Semantics
Definition 6 (Σ-structure)
Given a λ-signature Σ = 〈S , F , R , Ax〉, a Σ-structure is a triple 〈C, M , MAx 〉
such that C together with M forms a logically distributive category and MAx
is a map from Ax such that MAx (a : A → B ) ∈ HomC (MA, MB ).
17 of 32
18. Semantics
Definition 7 (λ-terms semantics)
Fixed a Σ-structure 〈C, M , MAx 〉, let A ≡ A1 × · · · An , and let
x ≡ x1 : A1 , . . . , xn : An be a context. The semantics of a term-in-context
x . t : B, notation x . t : B , is an arrow in HomC (MA, MB ) inductively defined
as follows:
1. x . xi : Ai = πi , the i-th projector of the product MA = MA1 × · · · × MAn ;
2. if a : C → B ∈ Ax then x . a(t ): B = MAx a ◦ x . t : C ;
3. x . 〈s, t 〉 : B × C = ( x . s : B , x . t : C ) where (_, _) is the universal arrow
of the product MB × MC;
4. x . fst(t ): B = π1 ◦ x . t : B × C where π1 is the first canonical projector
of the product MA × MB;
5. x . snd(t ): C = π2 ◦ x . t : B × C where π2 is the second canonical
projector of the product MA × MB;
→
18 of 32
19. Semantics
→ (λ-terms semantics)
6. x . (λz : C . t ): C → B is the exponential transpose of
x , z : C . t : B : MA × MC → MB;
7. x . s · t : B = ev ◦ ( x . s : C → B , x . t : C ) where ev is the exponential
evaluation arrow;
8. x . inlB (t ): C + B = ι1 ◦ x . t : C with ι1 the first canonical injection of the
co-product MC + MB;
9. x . inrC (t ): C + B = ι2 ◦ x . t : B with ι2 the second canonical injection of
the co-product MC + MB;
→
19 of 32
20. Semantics
→ (λ-terms semantics)
10. calling [_, _] the co-universal arrow of (MA × MC1 ) + (MA × MC2 ), (_, _)
the universal arrow of MA × (MC1 + MC2 ), and noticing that the arrow
∆ : (MA × MC1 ) + (MA × MC2 ) → MA × (MC1 + MC2 ) has an inverse
because C with M is logically distributive
x . when(t , u , v ): B = [ev ◦ ( x . u : C1 → B × 1MC1 ) ,
ev ◦ ( x . v : C2 → B × 1MC2 )] ◦
◦ ∆−1 ◦ (1MA , x . t : C1 + C2 ) ;
11. x . ∗ : 1 =!: MA → 1, the universal arrow of the terminal object;
12. x . FB : 0 → B is the exponential transpose of
(!: 0 → MB ) ◦ (πn+1 : MA × 0 → 0);
→
20 of 32
21. Semantics
→ (λ-terms semantics)
13. x . allI(λz : s. t ):(∀z : s. B ) = β ◦ α where
α ≡ 1MAi1 × · · · × 1MAik : MA → MA with A ≡ Ai1 × · · · × Aik , where
x ≡ {xi1 : Ai1 , . . . , xik : Aik } = FV(t : B ), and β : MA → M (∀z : s. B ) is the
universal arrow from MA to the terminal object in C∀z : s. B ;
14. x . allE(t , r ): B [r /z ] = pr ◦ x . t :(∀z : s. B ) where
pr : M (∀z : s. B ) → M (B [r /z ]) is the r -th projector of the unique cone on
ΣB (z : s) whose vertex is M (∀z : s. B ).
It is worth noticing that pr = w :(∀z : s. B ). allE(w , r ): B [r /z ] ;
15. x . exIz (t ):(∃z : s. B ) = jr ◦ x . t : B [r /z ] where
jr : M (B [r /z ]) → M (∃z : s. B ) is the r -th injection of the unique co-cone
on ΣB (z : s) whose vertex is M (∃z : s. B ).
It is worth noticing that jr = w : B [r /z ]. exIz (w ):(∃z : s. B ) ;
→
21 of 32
22. Semantics
→ (λ-terms semantics)
16. x . exE(t , (λz : s. r )): B = γ ◦ β−1 ◦ (α, x . t :(∃z : s. C ) ) where
16.1 α ≡ 1MAi1 × · · · × 1MAik : MA → MA with A ≡ Ai1 × · · · × Aik , where
x ≡ {xi1 : Ai1 , . . . , xik : Aik } = FV(t :(∃z : s. C )) ∪ FV(r : C → B );
16.2 β : M (∃z : s. A × C ) → MA × M (∃z : s. C ) is the co-universal arrow in the
subcategory C∃z : s. A ×C ;
16.3 γ : M (∃z : s. A × C ) → MB is the co-universal arrow in C∃z : s. A ×C .
22 of 32
23. Soundness
Definition 8 (Validity)
An equality-in-context x . s =A t is valid in the λ-theory T , a set of
equalities-in-context, when, in every logically distributive category C, each
model M of T is also a model of x . s =A t.
A Σ-structure M in C is a model of a theory T when it is a model of each φ
in T .
Finally, M is a model of an equality-in-context x . t =A s if x . t : A = x . s : A .
Theorem 9 (Soundness)
If an equation-in-context x . s =A t is derivable from a λ-theory T , then
x . s =A t is valid in each model of T in every logically distributive category.
23 of 32
24. Completeness
Definition 10 (Syntactical equivalence)
Given a λ-theory T , the syntactical equivalence of two terms-in-context is
defined by fixing the generated equivalence classes. Precisely, the
equivalence class [x : A. t : B ] is defined as the minimal set, composed by
terms-in-context, such that
1. x : A. t : B ∈ [x : A. t : B ]—reflexivity;
2. if T y : D . s =C r , where y : D . s =C r is an equality-in-context, and
y : D . s : C ∈ [x : A. t : B ], then y : D . r : C ∈ [x : A. t : B ]—closure under
provable equivalence;
→
24 of 32
25. Completeness
→ (Syntactical equivalence)
3. if y : D . s : C is a term-in-context and, for some 1 ≤ i < m and
z : Di × Di +1 ∈ FV(s : C ) ∪ y1 : D1 , . . . , ym : Dm , it happens that
y1 : D1 , . . . , yi −1 : Di −1 , z : Di × Di +1 , yi +1 : Di +2 ,
. . . , ym : Dm . s[fst(z )/yi ][snd(z )/yi +1 ]: C ∈ [x : A. t : B ] ,
then y : D . s : C ∈ [x : A. t : B ]—closure under associativity in contexts;
4. if y : D . s : C is a term-in-context and, for some 1 ≤ i < m and
z : Di +1 × Di ∈ FV(s : C ) ∪ y1 : D1 , . . . , ym : Dm , it happens that
y1 : D1 , . . . , yi −1 : Di −1 , z : Di +1 × Di , yi +1 : Di +2 ,
. . . , ym : Dm . s[snd(z )/yi ][fst(z )/yi +1 ]: C ∈ [x : A. t : B ] ,
then y : D . s : C ∈ [x : A. t : B ]—closure under commutativity in contexts;
→
25 of 32
26. Completeness
→ (Syntactical equivalence)
5. if y : D . s : C ∈ [x : A. y : B ] and z : Di ∈ FV(s : C ) ∪ y1 : D1 , . . . , ym : Dm for
some 1 ≤ i ≤ m, then
y1 : D1 , . . . , yi −1 : Di −1 , z : Di , yi +1 : Di +1 , . . . , ym : Dm . s[z /yi ]: C
is in [x : A. t : B ]—closure under α-renaming in contexts.
26 of 32
27. Completeness
Definition 11 (Syntactical category)
Given a λ-theory T , the syntactical category CT has λTypes(Σ) as objects,
where Σ is the λ-signature of T , and the equivalence classes
[x : A. t : B ]: A → B as arrows.
Identities are given by the classes [x : A. x : A]: A → A for each λ-type A,
and composition is given by substitution:
[y : B . s : C ] ◦ [x : A. t : B ] = [x : A. s[t /y ]: C ] .
Moreover, the map MT : λTypes(Σ) → Obj CT is defined as MT A = A.
27 of 32
28. Completeness
Proposition 12
The CT category is logically distributive.
Proposition 13
Given a λ-theory T on the Σ signature, the Σ-structure 〈CT , MT , MAx 〉 on
the corresponding syntactical category is defined by MAx which maps
f : A → B ∈ Ax to [x : A. f (x ): B ].
This Σ-structure is a model for T and, moreover, it satisfies exactly those
equalities-in-context which are provable in T .
28 of 32
29. Completeness
Proposition 14
For every logically distributive category C, there is a biijection between
equivalence classes, modulo natural equivalences, of structure-preserving
functors CT → C and equivalence classes, modulo isomorphisms, of
models of T in C, induced by the map F → F (MT ).
Theorem 15 (Completeness)
If x . s =A t is an equality-in-context valid in every model for T in each
logically distributive category, then T x . s =A t.
29 of 32
30. Soundness and Completeness in Logic
Definition 16 (Valid type)
A λ-type A is valid in the model N = 〈N, N , NAx 〉 when there exists an
arrow 1 → NA in N.
A λ-type A is a logical consequence in the model N of the λ-types
B1 , . . . , Bn when there exists N (B1 × · · · × Bn ) → NA in N.
A λ-type A is a logical consequence of B1 , . . . , Bn when it is a logical
consequence of B1 , . . . , Bn in every model in every logically distributive
category.
30 of 32
31. Soundness and Completeness in Logic
Proposition 17
A λ-type A is a logical consequence of B1 , . . . , Bn if and only if there exists a
term-in-context x : B1 × · · · × Bn . t : A.
Corollary 18
A λ-type A is a logical consequence of B1 , . . . , Bn if and only if there is a
proof of A from the hypotheses B1 , . . . , Bn , when λ-types are interpreted as
logical formulae and λ-terms as logical proofs, according to the
Curry-Howard isomorphism.
31 of 32