Cartesian closed 2-categories and permutation equivalence in higher-order rewriting

We propose a semantics for permutation equivalence in higher-order rewriting. This semantics takes place in cartesian closed 2-categories, and is proved sound and complete.


Introduction
Cartesian closed categories provide semantics for equational theories with variable binding [12,4]. On the other hand, 2-categories with finite products provide semantics for term rewriting [3]. The present paper shows that cartesian closed 2-categories provide semantics for term rewriting with variable binding, as embodied by Brugginks's generalisation [1] of permutation equivalence [16,Chapter 8] to higher-order rewriting [11,19,15,17].
We first define cartesian closed 2-signatures, which generalise higher-order rewrite systems, and organise them into a category Sig. We then construct an adjunction where 2CCCat is the category of small cartesian closed 2-categories. From a given cartesian closed 2-signature S, the functor H constructs a cartesian closed 2-category, whose 2-cells are Bruggink's proof terms modulo permutation equivalence, which we prove is the free cartesian closed 2-category generated by S. We review a number of examples and non-examples, and sketch an extension to deal with the latter.

T. HIRSCHOWITZ
Related work. Our cartesian closed 2-signatures may be seen as a 2-dimensional refinement of cartesian closed sketches [18,5,10]. Bruggink's calculus of permutation equivalence is close in spirit to Hilken's 2-categorical semantics of the simply-typed λ-calculus [8], but technically different and generalised to arbitrary higher-order rewrite systems. Capriotti [2] proposes a semantics of so-called flat permutation equivalence in sesquicategories. More related work is discussed in Section 4.2.

Cartesian closed signatures and categories
We start by recalling the well-known adjunction [12,4] between what we here call (cartesian closed) 1-signatures and cartesian closed categories.
For any set X, define types over X by the grammar: Proposition 2.1. L 0 defines a monad on Set.
Let the set of sequents over a set X be S 0 (X) = L 0 (X) * × L 0 (X), i.e., sequents are pairs of a list of types and a type. The assignment X ↦ S 0 (X) extends to an endofunctor on Set.
Definition 2.2. A 1-signature consists of a set X 0 of sorts, and an S 0 (X 0 )-indexed set X 1 of operations, or equivalently a map X 1 → S 0 (X 0 ).
commutes. Morphisms compose in the obvious way, and we have: Composition of morphisms is associative and unital, and hence 1-signatures and their morphisms form a category Sig 1 .
There is a well-known adjunction between 1-signatures and the category CCCat of small cartesian closed categories (with chosen structure) and (strict) cartesian closed functors, i.e., functors F ∶ C → D preserving binary products, projections, and the terminal object on the nose, and such that, for all objects A, B ∈ C, currying yields an identity.

CARTESIAN CLOSED 2-CATEGORIES AND PERMUTATION EQUIVALENCE 3
The functor W 1 maps any cartesian closed category C to the signature with sorts C 0 , its set of objects, and with operations A 1 , . . . , A n → A the set C( A 1 × . . . × A n , A ), where − denotes the function L 0 (C 0 ) → C 0 defined by induction: (2.1) Conversely, given a 1-signature X, consider the simply-typed λ-calculus with base types in X 0 and constants in X 1 . I.e., for any c ∈ X 1 (G, A) and terms Γ ⊢ M i ∶ A i , for all 1 ≤ i ≤ n, where G = (A 1 , . . . , A n ), we have a term Γ ⊢ c M 1 , . . . , M n ∶ A, representing the application of the constant c to M 1 , . . . , M n . We use special parentheses to avoid ambiguity with term application. Terms modulo βη form a cartesian closed category H 1 (X) with objects all types over X 0 and morphisms A → B all terms of type B with one free variable of type A.
A less often formulated observation, which is useful to us, is that the adjunction H 1 ⊣ W 1 decomposes into two adjunctions as follows. Consider first the endofunctor L 1 on Sig 1 defined on objects by mapping any 1-signature X to the 1-signature with • as sorts the set X 0 , and • as operations Γ ⊢ A the λ-terms Γ ⊢ M ∶ A, with base types in X 0 and constants in X 1 , as sketched above, modulo βη.
On morphisms of 1-signatures X f → Y , let L 1 (f ) substitute constants c ∈ X 1 with f 1 (c). We obtain Proposition 2.4. L 1 is a monad on Sig 1 , with unit and multiplication, say η and µ.
Let now L 1 -Alg be the category of algebras for the monad L 1 and K 1 be the 'free algebra' functor X ↦ (L 1 (X), µ X ).
The functor V 1 maps any cartesian closed category C to the L 1 -algebra with base 1signature (C 0 , C 1 ), defined as follows. First, C 0 is the set of objects of C. It has a canonical L 0 -algebra structure, say h 0 ∶ L 0 (C 0 ) → C 0 , obtained by interpreting type constructors in C as in (2.1). Extending this to contexts G by h 0 (G) = ∏ i h 0 (G i ), let the operations in C 1 (G, A) be the morphisms in C(h 0 (G), h 0 (A)). Beware: the domain and codomain of such an operation are really G and A, not h 0 (G) and h 0 (A). Similarly, interpreting the λ-calculus in C, the 1-signature (C 0 , C 1 ) has a canonical L 1 -algebra structure, say h 1 ∶ L 1 (C 0 , C 1 ) → (C 0 , C 1 ): Any morphism f ∶ X → Y of 1-signatures yields a map f ∶ X → Y , via the dashed arrow (obtained by universal property of pullback) in commute. We obtain: Higher-order rewrite systems. The prime example of a 2-signature is that for the pure λ-calculus: it has a sort t and operations with a reduction rule β over the pair x∶ t t , y∶ t ⊢ a ℓ x , y , x(y)∶ t in L 1 ({t}, {ℓ, a}) . Categorically, this will yield a 2-cell ℓ×t a ev β This is an example of a higher-order rewrite system in the sense of Nipkow [15]. Nipkow's definition is formally different, but his higher-order rewrite systems are in bijection with 2-signatures h∶ X 2 → L 1 (X) such that for all rules r ∈ X 2 , letting • each variable occurring in Γ occurs free in M . These restrictions help dealing with decidability problems on higher-order rewrite systems, whose extension to our setting we leave open.
Let us now anticipate over Adjunction (1.1) and our main results below and state our soundness and completeness theorem. Given a higher-order rewrite system X, i.e., a 2-signature satisfying the above conditions, let R(X) be the following locally-preordered 2-category. It has: • objects are types in L 0 (X 0 ); • morphisms A → B are λ-terms in L 1 (X)(A ⊢ B), modulo βη; • given two parallel morphisms M and N , there is one 2-cell M → N exactly when there is a sequence of reductions M → * N in the usual sense [15].
R(X) and H(X) have the same objects and morphisms. But because our inference rules for forming reductions are the same as deduction rules for proving the existence of a reduction in the usual sense, we may map any reduction P ∶ M → N to the unique reduction M → N in R(X). Conversely, any standard reduction step has a proof, which provides a reduction P . We have proved:

4.2.
Theories with binding. Understanding reduction rules as equations, it is easy to define the free cartesian closed category generated by a 2-signature. This yields the adjunction

T. HIRSCHOWITZ
This adjunction provides a categorical semantics for theories with binding, which is more general than other approaches by Fiore and Hur [7], Hirschowitz and Maggesi [9], and Zsidó [20].
If I understand correctly, the motivation for Fiore and Hur's subtle approach is the will to explain the λ-calculus by strictly less than itself. The present framework does not obey this specification, and instead tends to view the λ-calculus as a universal (parameterised) theory with binding.
We end this section by giving a formal construction of Adjunction (4.1). Cartesian closed categories form a full, reflective subcategory of 2CCCat, via the functor J ∶ 2CCCat → CCCat mapping any cartesian closed 2-category C to the cartesian closed category with: • objects those of C, • morphisms those of C, modulo the congruence generated by f ∼ g iff there exists a 2-cell f → g. Here, J (C) is thought of as the free locally discrete cartesian closed 2-category. Adjunction (4.1) is obtained by composing the adjunctions
Non-examples are given by calculi whose reduction semantics is defined on terms modulo a so-called structural congruence, e.g., CCS [13], or the π-calculus [6,14]. For example, consider the CCS term (a 0) a. In CCS, it is structurally equivalent to (a a) 0, which then reduces to 0 0.
In order to account for this, we would have to consider a 2-signature with reduction rules for structural congruence, here (M 1 M 2 ) M 3 → M 1 (M 2 M 3 ) for associativity, and M N → N M for commutativity. But then, these reductions count as proper reductions, which departs from the desired computational behaviour. For example, the term a a has an infinite reduction sequence, using commutativity.
Anticipating the development in the next sections, a potential solution is to extend 2signatures to 2-theories. For any 2-signature X, let X denote the set of pairs of reduction rules r, s with a common type G ⊢ M → N ∶ A. A 2-theory is a 2-signature X, together with a set of equations between parallel reductions, i.e., a subset X 3 of L(X) (where L is defined in Section 5).
Another possibility would be to define 2-theories to constist of a pair of sets over L 1 (X) , one for structural equations, and the other for proper reduction rules.
The main adjunction announced above (1.1) extends to an adjunction between 2theories and cartesian closed 2-categories. Using equations, we may specify that any reduction M → M using only structural rules be the identity on M , and consider the computational behaviour of a 2-category to consist of its non-invertible 2-cells, as proposed by Hilken [8]. A question is whether for a given calculus this can be done with finitely many equations.

A 2-lambda-calculus
We now begin the construction of Adjunction (1.1). We start in this section by defining a monad L on Sig, which we will use to factor Adjunction (1.1) as is the category of cartesian closed 2-categories, which we define in Section 6.
The left-hand adjunction holds by L being a monad, thus we concentrate in Section 7 on establishing the right-hand one.
But for now, let us define the monad L.
we construct a new 2-signature L(X), whose reduction rules represent reduction sequences in the "higher-order rewrite system" defined by X, modulo permutation equivalence. The 2-signature L(X) has the same base 1-signature (X 0 , X 1 ), and as reduction rules the terms of a 2λ-calculus (in the sense of Hilken [8]) modulo permutation equivalence, which we now define. First, terms, called reductions, are defined by induction in Figure 1. The typing judgement has the shape Γ ⊢ P ∶ M → N ∶ A, where A is a type in L 0 (X 0 ), Γ is a list of pairs of a variable and a type, with no variable appearing more than once, M and N are terms of type Γ ⊢ A modulo βη, and P is a reduction. In the sequel, we often forget the variables in such pairs (Γ ⊢ A), and identify them with sequents in S 0 (X 0 ).
When clear from context, we abbreviate substitutions [M 1 x 1 , . . . , M n x n ] of terms by [M 1 , . . . , M n ]. For a context G, G i denotes its ith type. Also, for (M, N ) ∈ L 1 (X) , we let X(M, N ) be the set of all reduction rules r ∈ X 2 such that a(r) = (M, N ). We write X(Γ ⊢ M, N ∶ A) to indicate the common type of M and N . Similarly, X(G ⊢ A) denotes the set of operations in X 1 above G ⊢ A.

5.2.
Substitution. Next, we define substitution, which has "type" i.e., given a reduction P and a tuple of reductions Q, it produces a reduction of the indicated type, which we denote by P First, observe that we have a form of weakening: for any reduction Γ ⊢ P ∶ M → N ∶ A and x ∉ Γ, we also have Γ, x∶ B ⊢ P ∶ M → N ∶ A. We use this implicitly in the following.
The definition of substitution is a bit tricky: • first we define left whiskering, which has "type" • then we define right whiskering, which has "type" Right whiskering is defined inductively, with ∆ = (x 1 ∶ A 1 , . . . , x n ∶ A n ) and N = (N 1 , . . . , N n ), by:  Figure 3 are bureaucratic: they just say that permutation equivalence is a congruence. The category rules make reductions of a given type Γ ⊢ A into a category. In Figure 4, the beta and eta rules mirror the term-level beta and eta rules. Finally, the lifting rules lift composition of reductions towards toplevel.
So, L(X) has sorts X 0 , operations X 1 , and as reduction rules in L(X)(G ⊢ M, N ∶ A) all reductions G ⊢ P ∶ M → N ∶ A, modulo the equations.
Lemma 5.5. This defines a natural transformation µ∶ L 2 → L, which makes the diagram Similarly, there is a natural transformation η∶ id → L, mapping each r ∈ X(G ⊢ M, N ∶ A) to the reduction G ⊢ r⟪x 1 , . . . , x n ⟫ ∶ M → N ∶ A, and we have: A crucial result is: The case where something actually happens is P = r⟪P 1 , . . . , i.e., the right-hand side. is an isomorphism of categories. Because this family of functors is 2-natural in D, the inverse functors will also be 2-natural.
Similarly, an object 1 of C is terminal iff for all D the unique functor is an isomorphism (where the right-hand 1 is the terminal category).
Definition 6.1. A 2-category with finite products, or fp 2-category, is a 2-category C, equipped with a terminal object and a 2-functor plus, for all A and B, a product diagram In such an fp 2-category C, given objects A and B, an exponential for them is a pair of an object B A and a morphism ev ∶ A × B A → B, such that for all D, the functor is an isomorphism. As above, because this family of functors is 2-natural in D, the inverse functors will also be 2-natural.
Definition 6.2. A cartesian closed 2-category, or cartesian closed 2-category, is an fp 2-category, equipped with a choice of exponentials for all pairs of objects. The category 2CCCat has cartesian closed 2-categories as objects, and stricly structure-preserving functors between them as morphisms.
We observe in particular that this implies preservation of projections and evaluation morphisms.

Main adjunction
7.1. Right adjoint. Given a cartesian closed 2-category C, define V(C) = (C 0 , C 1 , C 2 ) as follows. First, let as in Section 2 (C 0 , C 1 ) = V 1 (C), and recall the canonical L 0 and L 1 -algebra structures h 0 and h 1 . Let then the reduction rules in This signature VC has a canonical L-algebra structure h 2 ∶ L(VC) → VC, which we define by induction over reductions in Figure 2. In the case for λ, ϕ denotes the structure isomorphism C((∏ Γ) × A, B) ≅ C(∏ Γ, B A ).
In order for the definition to make sense as a morphism L(VC) → VC, we have to check its compatibility with the equations. We have first: Proof. By induction on P and the axioms for cartesian closed 2-categories. Proof. We proceed by induction on the proof of the considered equation. The congruence and category rules of Figures 3 and 4 hold because, in C, vertical composition is associative and unital, and equality is a congruence. The beta rule is less easy, so we spell it out. The left-hand reduction is interpreted in C as  and which concludes the proof.
This assignment extends to cartesian closed functors and we have:

The identity at
To show that this yields a 2-category structure, the only non obvious point is the interchange law. We deal with it using the following series of results. First, consider the left whiskering Proof. Consider (ηγ)⟪ηM ⟫ in L(L(X)). Its images by h ○ L(h) and h ○ µ coincide, and are respectively h(γ⟪η(h(M ))⟫) and h(γ⟪M ⟫).
Furthermore, consider any configuration like:  Finally, by a similar argument, we have: Lemma 7.9. The interchange law holds, i.e., for all reduction rules as in Proof. By the previous results, we have Now, let us show cartesian closedness. We have a bijection of hom-sets L 1 (X)(C ⊢ A × B) ≅ L 1 (X)(C ⊢ A) × L 1 (X)(C ⊢ B), given by N ). These are mutually inverse thanks to the beta and eta rules for products in the simply-typed λ-calculus.
This extends to morphisms of L-algebras, so we have constructed a functor F∶ L-Alg → 2CCCat.
(Thanks to the fact that µ(L 0 (η)(A)) = A.) Theorem 7.11. This η L is a natural transformation which is the unit of an adjunction Consider any morphism f ∶ (X, h) → V(C), and let X = F(X, h), (Y, k) = V(X ), and V(C) = (C 0 , C 1 , h 2 ∶ C 2 → C 1 ). We now define a uniquely determined cartesian closed functor f ′ ∶ X → C making the triangle commute.
On objects, it is determined by induction: on sorts by f 0 , and on type constructors by the requirement that f ′ be cartesian closed. On morphisms, it is similarly determined by f 1 and f ′ being cartesian closed. On 2-cells, define f ′ to be f 2 ∶ X 2 (A ⊢ M, N ∶ B) → C(f ′ (A), f ′ (B))(f ′ (M ), f ′ (N )), which is also the only possible choice from f . This indeed makes the above triangle commute, because any r ∈ X 2 (G ⊢ M, N ∶ A) is first mapped to h(r⟪π 1 x, . . . , π n x⟫) ∈ X 2 (∏ G ⊢ M ′ , N ′ ∶ A), and then to h(r⟪π 1 x, . . . , π n x⟫) in C, which, because f is a morphism of L-algebras, is equal to h 2 ((f 2 (r))⟪π 1 x, . . . , π n x⟫), i.e., to f 2 (r).
It thus remains to show that f ′ is cartesian closed, which follows by f being a morphism of L-algebras. For example, to show that binary pairings of reductions are preserved, consider r ∈ X 2 (C ⊢ M 1 , M 2 ∶ A) and s ∈ X 2 (C ⊢ N 1 , N 2 ∶ B). Their product in F(X) is obtained by considering the atomic reductions x∶ C ⊢ r⟪x⟫ ∶ M 1 → M 2 ∶ A and x∶ C ⊢ s⟪x⟫ ∶ N 1 → N 2 ∶ B and taking h(r⟪x⟫, s⟪x⟫), which is mapped by f 2 to f 2 (h(r⟪x⟫, s⟪x⟫)). But, because f is a morphism of L-algebras, this is the same as h 2 ((f 2 (r))⟪x⟫, (f 2 (s))⟪x⟫), which is by definition (i.e., Figure 2) the pairing (f 2 (r), f 2 (s)) in C.