1. 0/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
Categorical Semantics for Explicit Substitutions
Valeria de Paiva
XIII Summer Workshop in Mathematics
University of Brasilia
(joint work with Eike Ritter and Neil Ghani)
11 February 2021
0 / 31
6. 5/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
xSLAM: eXplicit Substitutions Linear Abstract Machine
Ritter’s PhD thesis on categorical combinators for the
Calculus of Constructions (Cambridge 1992, TCS 1994)
de Paiva’s PhD thesis on models of Linear Logic & linear
lambda-calculus (Cambridge 1991)
Put the two together for Categorical Abstract Machines for
Linear Functional Programming
Project xSLAM Explicit Substitutions for Linear Abstract
Machines (EPSRC 1997-2000)
5 / 31
7. 6/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
xSLAM: eXplicit Substitutions Linear Abstract Machine
Twenty years later
More than 10 papers submitted to conferences
Only two in journals: Linear Explicit Substitutions. (Ghani, de
Paiva, Ritter, 2000) and Relating Categorical Semantics for
Intuitionistic Linear Logic (Maneggia, Maietti, de Paiva, Ritter
2005)
Master’s thesis: An Abstract Machine based on Linear Logic
and Explicit Substitutions. Francisco Alberti, 1997
Two international workshops: Logical Abstract Machines
(Saarbruecken, 1998), Logical Abstract Machines
(Birmingham, 1999)
An international meeting at Dagstuhl: Linear Logic and
Applications (1999)
6 / 31
8. 7/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
xSLAM Project Work
1 E. Ritter. A calculus for Resource allocation. Technical Report, University of Birmingham, 2000.
2 Maietti, de Paiva, Ritter. Linear primitive recursion. manuscript 2000.
3 Maietti, de Paiva, Ritter. Categorical Models for Intuitionistic and Linear Type Theory. FoSSaCS 2000.
4 Cervesato, de Paiva, Ritter. Explicit Substitutions for Linear Logical Frameworks. LFM 1999
5 E. Ritter. Characterising Explicit Substitutions which Preserve Termination. TLCA 1999
6 Ghani, de Paiva, Ritter. Explicit Substitutions for Constructive Necessity. ICALP 1998
7 Ghani, de Paiva, Ritter. Categorical Models for Explicit Substitutions. FoSSaCS 1999.
8 de Paiva, E. Ritter. On Explicit Substitutions and Names. ICALP 1997.
9 Nesi, de Paiva, Ritter. Rewriting Properties of Combinators for Intuitionistic Linear Logic. Higher Order
Algebra, Logic and Term Rewriting, HOA’1993.
10 Maietti, de Paiva and Ritter. Normalization Bounds in Rudimentary Linear Logic ICC, 2002.
11 de Paiva and Eike Ritter. Variations on Linear PCF. WESTAPP, 1999.
7 / 31
10. 9/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
Categorical Models for what?
Explicit substitutions
In computer science, lambda calculi are said to have expli-
cit substitutions if they pay special attention to the forma-
lization of the process of substitution. This is in contrast
to the standard lambda calculus where substitutions are
performed by beta reductions in an implicit manner which
is not expressed within the calculus.
The concept of explicit substitutions has become notorious
(despite a large number of published calculi of explicit
substitutions in the literature with quite di↵erent characteristics)
because the notion often turns up (implicitly and explicitly) in
formal descriptions [...] Wikipedia, Feb 2021
Syntactic calculi, plenty of them. No models?
9 / 31
12. 11/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
What you will NOT see in this talk
Intersection types (idempotent or not)
Evaluation strategies
Dynamic types
Patterns
Proof-nets
Nominal syntax
Geometry of Interaction
explicit substitutions reductions
11 / 31
13. 12/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
Why Categorical Semantics?
Any syntactic calculus worth our attention will have a
categorical semantics
Mathematics as a source of intuition
Showing this for IPL and ILL (works for CS4⇤ too) 12 / 31
14. 13/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
What is a functional language?
Idea: Program as mathematical function transforming inputs into
outputs
Work on inductively defined data structures like lists, trees
) no side e↵ects
) can employ mathematical reasoning and substitute equals for
equals
) function definition and application central part of languages like
ML, Haskell, CAML, OCAML
(usually) Have strong typechecking
) can detect many errors already at compile-time
13 / 31
15. 14/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
Prototypical language -calculus
Terms:
M ::= x | x : A.M | MM
Types:
A ::= G | A ! A
Meaning of terms:
x: Variable (placeholder)
x : A.M: Function expecting input of type A
MM: Function application
Single out well-formed terms (check whether correct kind of
argument supplied)
14 / 31
16. 15/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
Lambda calculus
Judgements ` M : A
, x : A ` x : A
, x : A ` M : B
` x : A.M : A ! B
` M : A ! B ` N : A
` MN : B
To obtain a Turing-complete language, add recursively defined
functions via letrec and add means for defining inductively
defined data structures like lists, trees, etc
Computation done via -reduction
( x : A.M)N M[N/x]
where M[N/x] is M with x replaced by N
15 / 31
17. 16/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
Environment machines
Implementing reduction efficiently is very hard
Traditional solution:
Reduce -terms in an environment
storing bindings of terms for variables separately
) have two kinds of expressions:
Environments hMi /xi i: lists of bindings
Terms: as before plus new closures f ⇤ M
Modified -reduction stores substitution in the environment
( x.t)u ) hu/xi ⇤ t
New rewrite rules to eliminate substitutions
hu/xi ⇤ t )⇤ t[u/x]
Transforming this ‘trick’ of implementation into a logical calculus
) the reason for ‘explicit substitutions’
16 / 31
18. 17/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
The -Calculus (Abadi, Curien, Lévy 1991)
Term constructs:
Terms of the -calculus +
Application of a substitution to a term: f ⇤ t
Start substitution: hi
Parallel and sequential composition: hf , t/xi, f ; g
Typing Rules:
Substitutions are judgements ` f :
0 ✓
` hi : 0
` f : ` t :A
` hf , t/xi : , x : A
` f : ` t : A
` f ⇤ t : A
` f : ` g :
` f ; g :
Key Idea 1: Every -term is equivalent to a -term.
Key Idea 2: Contexts z :A⇥B and x :A, y :B are not equal 17 / 31
19. 18/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
Kesner Summing-up ES (2009)
All explicit substitutions (ES): decomposing implicit
substitutions into atomic steps allows a better understanding
of the execution models of higher-order languages;
-calculus with ES: incorporate substitution operators into the
language, and transforms the equalities of the specification
into a set of rewriting rules;
composition of substitution allows more sophisticated
interactions;
-calculi with ES can be defined either with unary or n-ary
substitutions, by using de Bruijn notation or levels or nominal
logic, or combinators, or director strings or by named variables;
a calculus with ES can be also seen as a term notation for a
logical system where the reduction rules behave like cut
elimination transformations;
Mellies counter-example 1995 shows ‘a flaw in the design of
ES calculi since they are supposed to implement their
underlying calculus (in our case the -calculus) without losing
its good properties’
18 / 31
20. 19/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
Kesner ES (2009)
ways to avoid Mellies counter-example in order to recover the
SN property;
one solution: weak lambda calculi, not good for proof
assistants;
another: terms with explicit weakening constructors;
Her way: a perpetual reduction strategy and normalisation of
“Implicit substitution implies normalisation of Explicit
substitution”IE property;
This extends ideas in [Kes07, Kes08], by the use of
intersection types as well as the use of the Z-property of van
Oostrom [vO] to show confluence.
19 / 31
21. 20/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
What do we want from a Categorical Semantics?
Motivation: What should calculi of explicit substitutions
contain?
What term constructs should we require
What equations should we require
how to discover this for di↵erent logics
Methodology: Extend the Curry Howard correspondence
Category theory as syntax debugging
Internal language gives term constructs & equational theory
Key Ideas:
A model should contain a model of the underlying -calculus
Contexts z :A⇥B and x :A, y :B are isomorphic
20 / 31
23. 22/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
Models of Explicit Substitutions — Indexed Categories
Contexts: Modelled by a cartesian category
Objects are contexts, morphisms are substitutions
Cartesian structure is given by parallel composition
Terms: For every context , define the category D( )
Objects are variable-type pairs x : A
Morphisms (x : A) ! (y : B) are judgements , x : A ` t : B
Re-indexing: ` f : induces a functor D(f ):D( ) ! D( )
Summary: An indexed category is a functor D : Cop ! Cat
22 / 31
24. 23/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
What’s Wrong with Indexed Categories?
Plus Points: Indexed categories induce -equations
hi; h = h Identity of C
h; hi = h Identity of C
hi ⇤ t = t Functoriality of D
(f ; g); h = f ; (g; h) Assoc of C-comp
(f ; g) ⇤ t = f ⇤ (g ⇤ t) Functoriality of D
Lemma: Soundness and completeness
Problem 1: Indexed Categories are inherently non linear
Identities in the fibres require judgements , x : A ` x : A
Problem 2: No syntax for forming substitutions from terms
23 / 31
25. 24/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
Context-Handling Categories
Solution 1: Remove identities by changing codomain to Set
Solution 2: Add two new natural transformations
Defn: Let B be a SMC (CCC) with T ✓ |B|. A linear
(cartesian) context handling category is a functor
L: Bop ! SetsT and for each type, natural isomorphisms
SubA : L( )A ) B( , A) TermA : B( , A) ) L( )A
Yoneda lemma: There exists VarA 2 L(A)A with
TermA(f ) = f ⇤ VarA
Equations: We get the following equations
h(f ⇤ t)/xi = f ; ht/xi Naturality of Sub
ht/xi ⇤ x = t One half of the iso
h(f ⇤ x)/xi = f Other half of the iso
24 / 31
26. 25/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
Adding Type Structure — E-Categories
Context handling categories model the behaviour of explicit
substitutions, eg their formation and application to terms
Types: Since terms are defined on the fibres, modelling type
constructors requires extra structure on the fibres.
Examples: Given types A, B 2 T , there are types
A ! B, A ⇥ B 2 T . In addition there are isomorphisms,
natural in
E(( , A))B
E( )A!B
E( )A ⇥ E( )B
E( A⇥B
Naturality: Equations distribute explicit subs over terms
f ⇤ x.t = x.f ⇤ t f ⇤ (tu) = (f ⇤ t)(f ⇤ u)
Model Collapse: Contexts z :A⇥B and x :A, y :B are
isomorphic 25 / 31
27. 26/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
Adding Linear Type Structure — L-Categories
Functions: As before, given types A, B 2 T , there is a type
A B 2 T and isomorphisms, natural in
E(( , A))B
E( )A B
Tensor: But the following doesn’t give an iso
z :A⌦B ⇠
= x :A, y :B
E(( , A, B))C
E( , A ⌦ B)C
Solution: Demand x :A, y :B ` h(x ⌦ y)/zi :A⌦B has an
inverse.
, x : A, y : B ` f :
, z : A ⌦ B ` let z be x ⌦ y in f :
Key Idea: Category theory guiding the design of the calculus 26 / 31
28. 27/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
Modelling the !-type Constructor
Key Idea: !-arises as the comonad of a monoidal adjunction
between CCCs and SMCCs
Recall: Models of explicit substitutions
E categories model calculi with !, ⇥, 1 types
L categories model calculi with , ⌦, I types
Defn: A !L-category is a monoidal adjunction where C is an
E category, B is an L-category and F, G preserve types.
Crucially: Requires an isomorphism x : A| ⇠
= |z :!A
, x : A| ` f :
| , z :!A ` let z be !x in f :
27 / 31
29. 28/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
Categorical Theorems
Please read the paper, but we have three theorems for E-categories
(CCCs), three for L-categories (SMCCs), two for putting the E-
and L-categories together into a !L-category.
(right defn) Every E-category contains an underlying CCC and
every CCC extends to an E-category, in an iso way;
(soundness) We can model the calculus in an E-category;
(completeness) If for every E-category, the interpretation of
two morphisms f , f 0 is the same, then the equality of the
morphisms is proved by the theory.
Similarly for L-categories.
For !L-categories, we use Barber’s DILL calculus with explicit
substitutions xDILL, described in Linear Explicit Substitutions
28 / 31
30. 29/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
Conclusions
Indexed categories are inherently non linear so we use
presheaves
Explicit substitutions are tricky to model as extensionally they
are equivalent to their underlying -calculus
Our models reflect this by “taking the isomorphisms seriously”
We get a Curry-Howard correspondence justifying our calculus
Other possibilities: replace isomorphisms with
Identities — loose syntax for substitutions
Retracts — loose relationship with usual semantics
29 / 31
31. 30/31
Motivation
Abstract Machines
Our Explicit substitutions
Categorical Semantics
Conclusions
More Conclusions
Maybe more important to have models for explicit
substitutions than for linear ones?
Which fibrations? interesting ones?
Can we model patterns too?
other logics?
Can we say something about the others we skipped?
30 / 31