Categorial Compositionality III: F-(co)algebras and the Systematicity of Recursive Capacities in Human Cognition

Human cognitive capacity includes recursively definable concepts, which are prevalent in domains involving lists, numbers, and languages. Cognitive science currently lacks a satisfactory explanation for the systematic nature of such capacities (i.e., why the capacity for some recursive cognitive abilities–e.g., finding the smallest number in a list–implies the capacity for certain others–finding the largest number, given knowledge of number order). The category-theoretic constructs of initial F-algebra, catamorphism, and their duals, final coalgebra and anamorphism provide a formal, systematic treatment of recursion in computer science. Here, we use this formalism to explain the systematicity of recursive cognitive capacities without ad hoc assumptions (i.e., to the same explanatory standard used in our account of systematicity for non-recursive capacities). The presence of an initial algebra/final coalgebra explains systematicity because all recursive cognitive capacities, in the domain of interest, factor through (are composed of) the same component process. Moreover, this factorization is unique, hence no further (ad hoc) assumptions are required to establish the intrinsic connection between members of a group of systematically-related capacities. This formulation also provides a new perspective on the relationship between recursive cognitive capacities. In particular, the link between number and language does not depend on recursion, as such, but on the underlying functor on which the group of recursive capacities is based. Thus, many species (and infants) can employ recursive processes without having a full-blown capacity for number and language.

p 1 : P → A and p 2 : P → B, jointly expressed as (P, p 1 , p 2 ), such that for every object Z ∈ |C| and pair of morphisms f : Z → A and g : Z → B there exists a unique morphism u : Z → P , also denoted f, g , such that the following diagram commutes: Z f x x p p p p p p p p p p p p p By a straightforward extension, the finite product of n objects A 1 , . . . , A n is (A 1 × · · · × A n , p 1 , . . . , p n ). o o g x x q q q q q q q q q q q q q Z (2) By a straightforward extension, the finite coproduct of n objects A 1 , . . . , A n is (A 1 + · · · + A n , q 1 , . . . , q n ). Not all categories have (all) coproducts.

Definition (Product of morphisms).
A product of morphisms f 1 : A 1 → B 1 and f 2 : A 2 → B 2 is the unique morphism f 1 × f 2 : A 1 × A 2 → B 1 × B 2 such that the following diagram commutes: Such a unique morphism is guaranteed to exist by the definition of products (if the products exist). Finite products of n morphisms, denoted f 1 × · · · × f n : A 1 × · · · × A n → B 1 × · · · × B n , are also defined by a straight-forward extension.

Definition (Coproduct of morphisms).
A coproduct of morphisms f 1 : A 1 → B 1 and f 2 : Categorial compositionality III 8 is the unique morphism f 1 + f 2 : A 1 + A 2 → B 1 + B 2 such that the following diagram commutes: Such a unique morphism is guaranteed to exist by the definition of coproducts (if the coproducts exist).

Definition (Product of functors-pointwise). A pointwise (finite) product of functors F i : C → D,
i ∈ {1, . . . , n} is the functor F 1 × · · · × F n indicated in the following diagram: where F i (C i ) has a set-like structure, and the product in D coincides with the Cartesian product of sets, which is the case for the categories that we use.

Definition (Coproduct of functors-pointwise).
A pointwise (finite) coproduct of functors F i : . . , n} is the functor F 1 + · · · + F n indicated in the following diagram: where F i (C i ) has a set-like structure, and the coproduct in D coincides with the disjoint union of sets, which is the case for the categories that we use. Definition (Cat). The category Cat has small categories for objects and functors for morphisms. (The technical distinction between small categories and otherwise need not concern us here, see [1].) Hence, composition is functor composition.

Definition (Composition of functors). Given functors
Definition (Endofunctor). An endofunctor F : C → C is a functor whose domain and codomain are the same category C.

Definition (Polynomial functor).
A polynomial functor is a constant functor, an identity functor, or a (co)product or composition of polynomial functors. Any polynomial functor is equivalent to one of the where (+)× is the (co)product of functors operator, and I 2 is equivalent to A product of categories is also defined, because it is needed for F -algebras.
Definition (Product of categories). Given categories C and D, the product of categories C × D has pairs (C, D) as objects and pairs (f, g) : (C 1 , D 1 ) → (C 2 , D 2 ) as morphisms, where C and f : C 1 → C 2 are in C, and D and g : D 1 → D 2 are in D. Identity morphisms and composition are component-wise.
It is routine to check that C × D is a category, and that (C × D, F 1 , F 2 ) is a product in Cat, where functors (projections) F 1 and F 2 return the first and second objects (morphisms) of each pair of objects (morphisms) in C × D.
two arguments, mapping pairs of objects and pairs of morphisms from a product of categories C × D to objects and morphisms in a category E. A bifunctor fixed at first-argument object A in C is a functor of where D is an object and g : Definition (Parameterized functor). Given a bifunctor F : C × D → E and an object A in C, a parameterized functor is the functor F A : D → E of the form F (A, −) defined above.
Example (Parameterized functor). An example of a functor F : Set × Set → Set parameterized by A is the polynomial functor  → G between a domain functor F : C → D and a codomain functor G : Definition (Natural isomorphism/natural equivalence). A natural transformation is a natural isomorphism, or natural equivalence if and only if each η A is an isomorphism. That is, for each η A : Natural transformations are morphisms of functors, and so can be composed. Note that isomorphic functor and isofunctor are not the same thing. Isomorphic functors are functors that are isomorphic to each other and the map between them is a natural equivalence. Isofunctors are maps between isomorphic categories. We will provide examples of natural transformations when we investigate the relationship between functors that underlie different recursive domains.

F -algebras, initial algebras, and catamorphisms
Here we provide the definition of a category of F -algebras. Then, we build up category-theoretic models in terms of F -algebras for three recursive domains involving numbers, lists and trees. In each case, we start with a (bi)functor, possibly parameterized by an object identifying the type of the elements to which the corresponding operations apply, yielding a polynomial functor F that specializes to operations pertaining to the respective domains.

Definition (F -algebra).
For an endofunctor F : C → C, an F-algebra is a pair (A, α), where A is an object and α : Example (F -algebra). Let C be the category Set, F : Set → Set be the functor F : S → S × S, f → f × f , A be the set of natural numbers N (so, N ∈ |Set|), and α : N × N → N be the morphism α : (m, n) → m + n. Then, (N, α) is an F -algebra.
F -algebra homomorphisms can be composed, and there are identity F -algebra homomorphisms.
Hence, the collection of F -algebras and F -algebra homomorphisms is a category. Definition (Initial algebra). An initial F-algebra (A, in), hereafter simply called an initial algebra, is an initial object in the category of F -algebras Alg(F ). That is, there exists a unique F -algebra homomorphism from (A, in) to every F -algebra in Alg(F ).
The presence of an initial algebra in a category Alg(F ) depends on the particular functor F , and is not guaranteed to exist in every case.
Proposition. If F : C → C is a polynomial functor, then the category of F -algebras Alg(F ) has an initial algebra.
The following result, due to Lambek [2], is important to our explanation of systematicity.
Lemma (Lambek). Given a functor F : C → C as the basis for a category of F -algebras Alg(F ) with an initial algebra (A, in), then in : Proof. We must show that there exists a morphism h : and h • in = 1 F (A) (left inverse), and that in is unique. Right inverse: Consider the diagram The existence of h : A → F (A) such that the upper inner square commutes is guaranteed, since (F (A), F (in)) is an F -algebra (by endofunctor F ) and (A, in) is an initial algebra in Alg(F ). The arrows in the lower inner square are already given, since F is a functor. Hence the outer square commutes too. Thus, in • h : A → A is an F -algebra homomorphism. 1 A and 1 F (A) also make the outer square commute (see curved arrows). Since (A, in) is an initial algebra, the F -algebra homomorphism Left inverse: From the upper inner commutative square of Diagram 10, we have h Since h is unique (being a catamorphism) and in = h −1 , in must also be unique. That is, in is the unique Examples of initial algebras and associated catamorphisms are given in the subsequent sections. An initial algebra (A, in) in Alg(F ) on a functor F : C → C is an example of a universal construction.
Specifically, it is an instance of a couniversal morphism (see Diagrams 43). That is, given an object  Diagram 9) such that the corresponding diagram commutes.

Numbers
For computation with regard to numbers, we start with the polynomial functor F = K 1 + I : CPO → There is a catamorphism from initial algebra (N, where f : S → S is a unary function, and v ∈ S is a constant. We also define foldN

Proof (by induction).
Proof by induction has a common pattern consisting of a proof for the base case (Base), an inductive assumption for an arbitrary non-base case (Assumption), and a proof of the case that succeeds the assumption case (Induction step). Since we are working in the category CPO, full induction also requires proving the cases that involve the bottom element ⊥ (see [7]). The proofs provided here are easily extended to such cases, so the details are omitted.
Induction step-succ(n): The condition for foldN [I v , f ] to be an F -algebra morphism is indicated by the commutative diagram because the proof is slightly simpler than for foldN
Induction step-succ(n): The two versions differ in their order of evaluation: foldN evaluates its argument before the recursive call, effectively progressing from Zero to argument n ; foldN evaluates its argument after the recursive call, effectively progressing from n to Zero.
We also define two versions of foldn (i.e., fold for numbers) to work directly with natural numbers.
The definitions and proofs (not shown) follow the same patterns as for the two versions of foldN. They

Examples
The initial algebra (N, [zero, succ]) is a model for the natural numbers. For example, the elements Zero, succ(Zero), succ(succ(Zero)) ∈ N correspond to the elements 0, 1, 2 ∈ N, respectively. And, being an initial algebra, the catamorphisms from this algebra provide models for operations over natural numbers. For example, addition of two natural numbers is modeled as plusN : In effect, plusN (m)(−) is a function that adds m to its (−) argument. For example, plusN (succ(Zero))(succ(Zero)) = succ(succ(Zero)), which corresponds to 1 + 1 = 2.

Lists
A list (e.g., constructed from the letters: 's', 'n', 'o', and 'c') can be represented internally by a recursive construction that prepends items to the front of a list (as in "cons"), or by a recursive construction that postpends items to the back of a list (as in "snoc"). (By postpend we mean adding an item to the end of a list to create a new list, in contrast to append, which usually means adding a list to a list to create a new list in a functional programming language.) Each construction is an initial algebra in a particular category of F -algebras based on a specific functor. We provide both functors. Though our focus is the more commonly used prepend construction, the results extend naturally (via a natural isomorphism) to the other version. The presence of multiple constructions raises the question, which we have alluded to in the main text, How does the cognitive system know which algebra to use? The process for constructing/destructing lists is intrinsically linked by a dual relationship between F -algebra and F -coalgebra. This relationship is detailed in the final section.
Prepend version: We start with a polynomial functor F A : CPO → CPO parameterized by an object A in CPO as the basis for a category of algebras Alg(F A ) on functor F A . An initial algebra in this category is a model for lists of objects of type A, and the catamorphisms from this initial algebra are models for recursive computations over such lists. The functor  capacities, which we also discuss in this section. The formal relationship between the two versions is given in the next section, where we also present the relationships between other F -algebras. conditions (see below). If we require a catamorphism that processes lists from the left, then there is such a catamorphism for postpend-constructed lists, which we will call foldL. Since our primary concern is initial algebras and their associated catamorphisms, we will refer to foldr as foldL , by analogy with the naming convection foldN /foldN (foldn/foldn ) for numbers. Our interest in foldl is only expository.
First, we present the definitions for foldl and foldr (foldL ). Then, we show that foldL is a catamorphism, and finally, we present foldL, which is the general catamorphism for postpend-constructed lists.
Proof (by induction). The proof follows the same pattern as the proof that foldN /foldN is a catamorphism: i.e., we first show that foldL exists (Diagram 13 commutes), and then show uniqueness.
Proposition. If f : S × A → S is an arbitrary function, then foldL[I v , f ] is a catamorphism, indicated by the commutative diagram Proof. Reverse the roles of the objects/morphisms associated with the products in the above proof.

Examples
The For further examples, see [7].

Trees
For computation with regard to trees, we start with the polynomial functor all trees T , f is the unary function leaf , and g is the binary function branch. The tuple notation for trees is recursive, e.g., a 1 , a 2 , a 3 is a tree whose left branch is the leaf a 1 , and whose right branch is the (sub)tree whose left branch is the leaf a 2 and right branch is the leaf a 3 , depicted as Proposition. If f : A → S and g : S × S → S are arbitrary functions, T and S are sets, foldT [f, g] : T → S is a catamorphism.

Examples
Computing the sum of the numbers in the leaves of a tree of numbers is the catamorphism given in commutative diagram Computing tree depth (i.e., the number of branches from the root of the tree to the "deepest" leaf) is the catamorphism given in commutative diagram

27
Counting the number of leaves in a tree is the catamorphism given in commutative diagram

Relation between numbers, lists, and trees
Under certain circumstances, operations pertaining to numbers are special cases of operations pertaining to lists, and list operations are special cases of operations pertaining to trees. The precise relationship between these domains is revealed by a category theory treatment of recursion.

Numbers from lists
To compare initial algebras associated with number and with list we must use a common framework. For number, this means using an initial algebra built from the same object L used for lists,

Lists from trees
A list can also be represented as a special kind of tree: i.e., a tree with either left-only, or right-only branches. To represent lists as trees, the formulation for a tree must be modified to yield the equivalent of lists as a special case: essentially, we use a tree where the values are embedded at the roots, instead of the leaves. This modification is straightforward, and achieved using the polynomial functor F A = where: • empty : 1 → T returns an empty tree ; • branch : A × T × T → T ; (a, l, r) → a, l, r returns a tree with root value a ∈ A, left branch l ∈ T and right branch r ∈ T ; , l, r → f (a, l, r); Such trees contain values at their branches, depicted as follows: Just like the comparison of numbers and lists, to compare initial algebras for lists and trees, we require (T, [empty, branchl ] as a common framework. The relationship between tree and list algebras is given by Hence, every catamorphism in list is a catamorphism in tree.

Numbers from trees
Having shown that the initial algebras for numbers and lists, and lists and trees are related by natural transformations, the initial algebras for numbers and trees must also be related by natural transformations, since natural transformations are morphisms in a functor category, and so natural transformations compose as morphisms compose. The initial algebra for number from trees is (T, [empty, branchl a ]), . In this case, items are added (prepended) to the root of the tree.

No natural equivalences
Recall that two functors are related by a natural equivalence whenever every member of a family of morphisms that constitute a natural transformation is an isomorphism. Notice that there is also a natural transformation from the endofunctor for number, F : 1 + S, 1 1 + f to the endofunctor for list, However, in general, the composition of these arrows with the ones in the reverse direction is not an identity, e.g., (1 1 + p 2 ) • (1 1 + 1 1 , 1 S ) = 1 1+A×S : essentially, the information regarding object A is lost.
The same situation applies to the relationships between the other pairs of endofunctors. Therefore, these Categorial compositionality III 32 endofunctors are not related by natural equivalences.

F -coalgebras, final coalgebras, and anamorphisms
F -coalgebra, final coalgebra, and anamorphism are (respectively) dual to F -algebra, initial algebra, and catamorphism. That is, their definitions are obtained by reversing the direction of the arrows in the dual construct. Here, we list the definitions.

Definition (F -coalgebra homomorphism). An F-coalgebra homomorphism
such that the following diagram commutes:

Definition (Final coalgebra).
A final F-coalgebra (A, fin), hereafter also simply called a final algebra, is a final (i.e., terminal) object in the category of F -coalgebras CoAlg(F ). That is, there exists a unique F -coalgebra homomorphism from every F -coalgebra in CoAlg(F ) to (A, fin).
Like initial algebras, the presence of a final coalgebra in a category CoAlg(F ) depends on the particular functor F , and is not guaranteed to exist in every case.
Proposition. If F : C → C is a polynomial functor, then the category of F -coalgebras CoAlg(F ) has a final coalgebra.
A final coalgebra (A, fin) in CoAlg(F ) on a functor F : C → C is an example of a universal construction. Specifically, it is an instance of a universal morphism (see Diagram 42).

Distributive categories and conditional functions
Before presenting specific coalgebras that we use in our explanation of systematicity, we need the definitions of distributive categories and conditional functions (see [5], p66-69, for further details).

Definition (Distributive categories).
A distributive category C is a category with all products and coproducts such that we have natural isomorphisms The associated morphisms are called Distributive categories may be thought of an analogous to the distributive law in arithmetic (and other mathematical structures such as rings and vector spaces).

Definition (Condition function).
In a category C whose objects are sets where p 1 is the usual projection onto the first factor associated with a product.

Lists
We saw how lists are constructed (put together) by initial algebras. Final coalgebras are dual to initial algebras [3]; lists are destructed (pulled apart) by final coalgebras. The resulting data structure is sometimes called a colist (see, e.g., [9]). Hence, the category theory development of final coalgebras for lists derives from the dual definition of initial algebra in the category of F -algebras Alg(F A ) on the The final coalgebra and associated anamorphism are shown in commutative diagram To show that unfoldL (p → I * , f, g ) is indeed an anamorphism, we employ the approximation lemma [7], which is used to prove coalgebraic properties (see also [10]). The approximation lemma affords proofs of coalgebraic properties via induction over the natural numbers. The generic approximation lemma [11] does essentially the same thing for a general class of data structures, including lists and trees.
Proof. First we prove existence (commutativity of Diagram 38), then uniqueness (by case analysis and the approximation lemma). (See also [10,12] for another general method of proving coalgebraic properties, called coinduction, which is dual to induction).

39
There is a corresponding anamorphism for postpend-constructed lists, unfoldL(p → I * , f, g ) : S → L, i.e., for the category of coalgebras on the functor F A : and proof follow unfoldL , but with the arguments associated with the product reversed.

Trees
Like lists, the development of a final coalgebra for trees derives from its dual initial algebra (see [3]).
That is, as the dual of an initial algebra in the category of F -algebras Alg(F A ) on the functor F A : The anamorphism associated with this final coalgebra is called unfoldT (i.e., unfold for trees), defined The final coalgebra and associated anamorphism are indicated in commutative diagram is an anamorphism.
Proof. The proof follows a similar pattern to unfoldL . First we prove existence (commutativity of Diagram 40), then uniqueness (by case analysis and the approximation lemma, using the approx function for trees, see below).

Universal constructions (Co)Universal morphisms
Definition (Universal morphism). Given a functor F : A → C and an object Y ∈ |C|, a universal morphism from F to Y is a pair (A, φ) where A is an object of A, and φ is a morphism in C, such that for every object X ∈ |A| and every morphism f : F (X) → Y , there exists a unique morphism h : X → A, such that φ • F (h) = f , as indicated by commutative diagram Definition (Couniversal morphism). Given an object X ∈ |C| and a functor F : B → C, a couniversal morphism from X to F is a pair (B, ψ) where B is an object of B, and ψ is a morphism in C, such that for every object Y ∈ |B| and every morphism f : X → F (Y ), there exists a unique morphism k : B → Y , such that F (k) • ψ = f , as indicated by commutative diagram

Definition (Universal construction).
A universal construction is either a universal morphism, or (its dual) a couniversal morphism.

Adjunctions
A special kind of universal construction is called an adjunction, or adjoint situation. Our explanations for systematicity with regard to non-recursive domains employed this form of universal construction. Here, we provide definitions for comparison with initial algebras as the basis for our explanation of systematicity with regard to recursive domains.

Definition (Adjunction-unit version).
An adjunction from categories C to D is a triple (F, G, η) : where F : C → D and G : D → C are functors, and η : 1 C